Skip to content

Commit

Permalink
Feat: Implement the function in the market_utils library keep-starkne…
Browse files Browse the repository at this point in the history
…t-strange#3 (keep-starknet-strange#463)

* 10 functions done

* almost finished, debug next

* debug time

* debuging

* pushing recent changes/ still bug because missing functions

* debuging finished

* adding comments on functions

* almost clean

* Emit bug

* programm compile 🎉

* resolving last test

* All test passed

* resolve request

* 1 test failed because of max swap path lenght exceed test

* resolving failed test

* resolve

* solving

* compilation resolved

---------

Co-authored-by: Michel <105498726+Sk8erboi84@users.noreply.github.com>
  • Loading branch information
2 people authored and StarkFishinator committed Oct 5, 2023
1 parent 7edd22d commit 4b6d214
Show file tree
Hide file tree
Showing 8 changed files with 1,122 additions and 463 deletions.
1 change: 0 additions & 1 deletion src/event/event_emitter.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,6 @@ trait IEventEmitter<TContractState> {
next_pool_value: u128
);

/// Emits the `UiFeeFactorUpdated` event.
fn emit_ui_fee_factor_updated(
ref self: TContractState, account: ContractAddress, ui_fee_factor: u128
);
Expand Down
61 changes: 56 additions & 5 deletions src/market/error.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,69 @@ mod MarketError {
'empty_addr_market_balance_val';
const EMPTY_ADDRESS_TOKEN_BALANCE_VAL: felt252 = 'empty_addr_token_balance_val';
const INVALID_MARKET_TOKEN_BALANCE: felt252 = 'invalid_market_token_balance';
const INVALID_MARKET_TOKEN_BALANCE_FOR_COLLATERAL_AMOUNT: felt252 =
'invalid_mkt_tok_bal_collat_amnt';
const INVALID_MARKET_TOKEN_BALANCE_FOR_CLAIMABLE_FUNDING: felt252 =
'invalid_mkt_tok_bal_claim_fund';
const EmptyAddressInMarketTokenBalanceValidation: felt252 = 'EmptyAddressMarketBalanceVal';
const INVALID_POSITION_MARKET: felt252 = 'invalid_position_market';
const INVALID_COLLATERAL_TOKEN_FOR_MARKET: felt252 = 'invalid_coll_token_for_market';
const UNABLE_TO_GET_OPPOSITE_TOKEN: felt252 = 'unable_to_get_opposite_token';
const EMPTY_MARKET: felt252 = 'empty_market';
const DISABLED_MARKET: felt252 = 'disabled_market';
const COLLATERAL_ALREADY_CLAIMED: felt252 = 'collateral_already_claimed';

fn DISABLED_MARKET(is_market_disabled: bool) {
panic(array!['minimum_position_size', is_market_disabled.into()])
}

fn EMPTY_MARKET_TOKEN_SUPPLY(supply: u128) {
panic(array!['empty_market_token_supply', supply.into()])
}

fn INVALID_MARKET_COLLATERAL_TOKEN(market: ContractAddress, token: ContractAddress) {
panic(array!['invalid_market_collateral_token', market.into(), token.into()])
}

fn UNABLE_TO_GET_FUNDING_FACTOR_EMPTY_OPEN_INTEREST(total_open_interest: u128) {
panic(array!['unable_to_get_funding_factor', total_open_interest.into()])
}

fn MAX_SWAP_PATH_LENGTH_EXCEEDED(token_swap_path_length: u32, max_swap_path_length: u128) {
panic(
array![
'max_swap_path_length_exceeded',
token_swap_path_length.into(),
max_swap_path_length.into()
]
)
}

fn PNL_EXCEEDED_FOR_LONGS(is_pnl_factor_exceeded_for_longs: bool) {
panic(array!['pnl_exceeded_for_longs', is_pnl_factor_exceeded_for_longs.into()])
}

fn PNL_EXCEEDED_FOR_SHORTS(is_pnl_factor_exceeded_for_shorts: bool) {
panic(array!['pnl_exceeded_for_shorts', is_pnl_factor_exceeded_for_shorts.into()])
}

fn UI_FEE_FACTOR_EXCEEDED(ui_fee_factor: u128, max_ui_fee_factor: u128) {
panic(array!['ui_fee_factor_exceeded', ui_fee_factor.into(), max_ui_fee_factor.into()])
}

fn INVALID_MARKET_TOKEN_BALANCE_FOR_COLLATERAL_AMOUNT(balance: u128, collateral_amount: u128) {
panic(array!['invalid_market_token_balance', balance.into(), collateral_amount.into()])
}

fn INVALID_MARKET_TOKEN_BALANCE_FOR_CLAIMABLE_FUNDING(
balance: u128, claimable_funding_fee_amount: u128
) {
panic(
array![
'invalid_market_token_balance', balance.into(), claimable_funding_fee_amount.into()
]
)
}

fn UNABLE_TO_GET_BORROWING_FACTOR_EMPTY_POOL_USD(pool_usd: u128) {
panic(array!['unable_to_get_borrowing_factor', pool_usd.into()])
}

fn MAX_OPEN_INTEREST_EXCEDEED(open_interest: u128, max_open_interest: u128) {
panic(array!['max_open_interest_exceeded', open_interest.into(), max_open_interest.into()])
}
Expand Down
Loading

0 comments on commit 4b6d214

Please sign in to comment.