Skip to content

Commit

Permalink
fix: merge issue
Browse files Browse the repository at this point in the history
  • Loading branch information
FabienCoutant committed Sep 26, 2023
1 parent a0e1110 commit c4ea571
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/market/market_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use satoru::price::price::{Price, PriceTrait};
use satoru::utils::calc;
use satoru::utils::span32::Span32;
use satoru::position::position::Position;
use satoru::utils::i128::{I128Store, I128Serde, I128Div, I128Mul, I128Default};
use satoru::utils::i128::{I128Store, I128Serde, I128Div, I128Mul};

/// Struct to store the prices of tokens of a market.
/// # Params
Expand Down
21 changes: 11 additions & 10 deletions src/position/decrease_position_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use satoru::position::{
position_utils, decrease_position_collateral_utils, decrease_position_swap_utils,
position_utils::{UpdatePositionParams, DecreasePositionCache}
};
use satoru::utils::i128::u128_to_i128;
use satoru::utils::calc::to_signed;
use satoru::data::{data_store::{IDataStoreDispatcher, IDataStoreDispatcherTrait}, keys};
use satoru::utils::precision;
use satoru::market::market_utils;
Expand Down Expand Up @@ -57,7 +57,7 @@ fn decrease_position(ref params: UpdatePositionParams) -> DecreasePositionResult
cache
.collateral_token_price =
market_utils::get_cached_token_price(
params.order.initial_collateral_token, params.market, @cache.prices
params.order.initial_collateral_token, params.market, cache.prices
);

// cap the order size to the position size
Expand Down Expand Up @@ -104,7 +104,7 @@ fn decrease_position(ref params: UpdatePositionParams) -> DecreasePositionResult
position_collateral_amount: params.position.collateral_amount
- params.order.initial_collateral_delta_amount,
realized_pnl_usd: cache.estimated_realized_pnl_usd,
open_interest_delta: -u128_to_i128(params.order.size_delta_usd),
open_interest_delta: to_signed(params.order.size_delta_usd, false),
};

let (will_be_sufficient, mut estimated_remaining_collateral_usd) =
Expand Down Expand Up @@ -137,8 +137,9 @@ fn decrease_position(ref params: UpdatePositionParams) -> DecreasePositionResult
// should be added back to the estimated_remaining_collateral_usd

estimated_remaining_collateral_usd +=
u128_to_i128(
params.order.initial_collateral_delta_amount * cache.collateral_token_price.min
to_signed(
params.order.initial_collateral_delta_amount * cache.collateral_token_price.min,
false
);

params.order.initial_collateral_delta_amount = 0;
Expand All @@ -153,8 +154,8 @@ fn decrease_position(ref params: UpdatePositionParams) -> DecreasePositionResult

if ((estimated_remaining_collateral_usd
+ cache
.estimated_remaining_pnl_usd) < u128_to_i128(
params.contracts.data_store.get_u128(keys::min_collateral_usd())
.estimated_remaining_pnl_usd) < to_signed(
params.contracts.data_store.get_u128(keys::min_collateral_usd()), false
)) {
params
.contracts
Expand Down Expand Up @@ -273,13 +274,13 @@ fn decrease_position(ref params: UpdatePositionParams) -> DecreasePositionResult
params.position.market,
params.position.collateral_token,
params.position.is_long,
-u128_to_i128(cache.initial_collateral_amount - params.position.collateral_amount)
to_signed(cache.initial_collateral_amount - params.position.collateral_amount, true)
);

position_utils::update_open_interest(
params,
-u128_to_i128(params.order.size_delta_usd),
-u128_to_i128(values.size_delta_in_tokens)
to_signed(params.order.size_delta_usd, true),
to_signed(values.size_delta_in_tokens, true)
);

// affiliate rewards are still distributed even if the order is a liquidation order
Expand Down
2 changes: 1 addition & 1 deletion src/position/position_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use satoru::mock::referral_storage::{IReferralStorageDispatcher, IReferralStorag
use satoru::utils::traits::ContractAddressDefault;
use satoru::order::base_order_utils::ExecuteOrderParamsContracts;
use satoru::price::price::{Price, PriceTrait};
use satoru::utils::{calc, precision, i128::{I128Store, I128Serde, I128Div, I128Mul}};
use satoru::utils::{calc, precision, i128::{I128Store, I128Serde, I128Div, I128Mul, I128Default}};
use satoru::referral::referral_utils;
use satoru::order::order_vault::{IOrderVaultDispatcher, IOrderVaultDispatcherTrait};

Expand Down
2 changes: 1 addition & 1 deletion src/pricing/position_pricing_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use satoru::mock::referral_storage::{IReferralStorageDispatcher, IReferralStorag
use satoru::utils::{calc, precision};
use satoru::pricing::error::PricingError;
use satoru::referral::referral_utils;
use satoru::utils::i128::{I128Store, I128Serde, I128Div, I128Mul, I128Default};
use satoru::utils::i128::{I128Store, I128Serde, I128Div, I128Mul};
/// Struct used in get_position_fees.
#[derive(Drop, starknet::Store, Serde)]
struct GetPositionFeesParams {
Expand Down
6 changes: 2 additions & 4 deletions src/tests/position/test_decrease_position_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ use satoru::order::{
order_vault::{IOrderVaultDispatcher, IOrderVaultDispatcherTrait},
base_order_utils::ExecuteOrderParamsContracts
};
use satoru::referral::referral_storage::interface::{
IReferralStorageDispatcher, IReferralStorageDispatcherTrait
};
use satoru::mock::referral_storage::{IReferralStorageDispatcher, IReferralStorageDispatcherTrait};

use satoru::position::{
position::Position, decrease_position_utils, position_utils::UpdatePositionParams
};
Expand Down Expand Up @@ -158,7 +157,6 @@ fn create_new_update_position_params(
min_output_amount: 10,
updated_at_block: 1,
is_long: false,
should_unwrap_native_token: false,
is_frozen: false
};

Expand Down

0 comments on commit c4ea571

Please sign in to comment.