Skip to content

Commit

Permalink
add is_position_liquidable in reader
Browse files Browse the repository at this point in the history
  • Loading branch information
sparqet committed Jul 3, 2024
1 parent 60d3d1e commit c79897a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
24 changes: 24 additions & 0 deletions src/reader/reader.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,16 @@ trait IReader<TContractState> {
is_long: bool,
prices: MarketPrices
) -> (u64, bool, i256, u256);

fn is_position_liquidable(
self: @TContractState,
data_store: IDataStoreDispatcher,
referral_storage: IReferralStorageDispatcher,
position: Position,
market: Market,
prices: MarketPrices,
should_validate_min_collateral_usd: bool,
) -> (bool, felt252);
}

#[starknet::contract]
Expand Down Expand Up @@ -856,6 +866,20 @@ mod Reader {
);
(latest_adl_block, should_enabled_ald, pnl_to_pool_factor, max_pnl_factor)
}

fn is_position_liquidable(
self: @ContractState,
data_store: IDataStoreDispatcher,
referral_storage: IReferralStorageDispatcher,
position: Position,
market: Market,
prices: MarketPrices,
should_validate_min_collateral_usd: bool
) -> (bool, felt252) {
position_utils::is_position_liquiditable(
data_store, referral_storage, position, market, prices, should_validate_min_collateral_usd
)
}
}
}

12 changes: 6 additions & 6 deletions tests/integration/test_long_integration.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3713,8 +3713,8 @@ fn test_long_liquidation() {
short_token_price: Price { min: 1, max: 1, },
};

let (is_liquiditable, reason) = position_utils::is_position_liquiditable(
data_store, referal_storage, first_position, market, market_prices, false
let (is_liquiditable, reason) = reader.is_position_liquidable(
data_store, referal_storage, first_position, market, market_prices, true
);

assert(is_liquiditable == true, 'Position is liquidable');
Expand All @@ -3727,8 +3727,8 @@ fn test_long_liquidation() {
short_token_price: Price { min: 1, max: 1, },
};

let (is_liquiditable, reason) = position_utils::is_position_liquiditable(
data_store, referal_storage, first_position, market, market_prices, false
let (is_liquiditable, reason) = reader.is_position_liquidable(
data_store, referal_storage, first_position, market, market_prices, true
);

assert(is_liquiditable == false, 'Position is not liquidable');
Expand Down Expand Up @@ -4637,8 +4637,8 @@ fn test_long_leverage_liquidation() {
short_token_price: Price { min: 1, max: 1, },
};

let (is_liquiditable, reason) = position_utils::is_position_liquiditable(
data_store, referal_storage, first_position, market, market_prices, false
let (is_liquiditable, reason) = reader.is_position_liquidable(
data_store, referal_storage, first_position, market, market_prices, true
);
// position x10 leverage is liquidable at 3000$, position x1 leverage is not liquidable at 3000$
assert(is_liquiditable == true, 'Position is liquidable');
Expand Down

0 comments on commit c79897a

Please sign in to comment.