diff --git a/src/deposit/error.cairo b/src/deposit/error.cairo index 54dc0916..8d4fe9c8 100644 --- a/src/deposit/error.cairo +++ b/src/deposit/error.cairo @@ -5,7 +5,6 @@ mod DepositError { const EMPTY_DEPOSIT_AMOUNTS: felt252 = 'empty_deposit_amounts'; const EMPTY_DEPOSIT: felt252 = 'empty_deposit'; const EMPTY_DEPOSIT_AMOUNTS_AFTER_SWAP: felt252 = 'empty deposit amount after swap'; - const INVALID_POOL_VALUE_FOR_DEPOSIT: felt252 = 'invalid pool value for deposit'; fn MIN_MARKET_TOKENS(received: u256, expected: u256) { @@ -14,4 +13,10 @@ mod DepositError { data.append(expected.try_into().expect('u256 into felt failed')); panic(data) } + + fn INVALID_POOL_VALUE_FOR_DEPOSIT(pool_value: u256) { + let mut data = array!['invalid pool value for deposit']; + data.append(pool_value.try_into().expect('u256 into felt failed')); + panic(data) + } } diff --git a/src/deposit/execute_deposit_utils.cairo b/src/deposit/execute_deposit_utils.cairo index 90022aae..05f3b80e 100644 --- a/src/deposit/execute_deposit_utils.cairo +++ b/src/deposit/execute_deposit_utils.cairo @@ -315,9 +315,8 @@ fn execute_deposit_helper( true, ); - //TODO add the pool_value_info.pool in the error message if pool_value_info.pool_value < Zeroable::zero() { - panic_with_felt252(DepositError::INVALID_POOL_VALUE_FOR_DEPOSIT) + DepositError::INVALID_POOL_VALUE_FOR_DEPOSIT(pool_value_info.pool_value.mag); } let mut mint_amount = 0; @@ -327,7 +326,7 @@ fn execute_deposit_helper( ); if pool_value == Zeroable::zero() && market_tokens_supply > 0 { - panic_with_felt252(DepositError::INVALID_POOL_VALUE_FOR_DEPOSIT) + DepositError::INVALID_POOL_VALUE_FOR_DEPOSIT(pool_value_info.pool_value.mag); } (*params.event_emitter) diff --git a/src/exchange/deposit_handler.cairo b/src/exchange/deposit_handler.cairo index 2fa297a3..c128c4d5 100644 --- a/src/exchange/deposit_handler.cairo +++ b/src/exchange/deposit_handler.cairo @@ -202,7 +202,7 @@ mod DepositHandler { deposit.account, 0, //starting_gas keys::user_initiated_cancel(), - array!['Cancel Deposit'] //TODO should be empty string + array![''] ); global_reentrancy_guard::non_reentrant_after(data_store); diff --git a/src/order/order_utils.cairo b/src/order/order_utils.cairo index 25f0b065..9aa1ff9e 100644 --- a/src/order/order_utils.cairo +++ b/src/order/order_utils.cairo @@ -238,9 +238,10 @@ mod OrderUtils { // validate swap path markets market_utils::validate_swap_path(data_store, params.swap_path); + let key = nonce_utils::get_next_key(data_store); let mut order = Order { - key: 0, + key: key, order_type: params.order_type, decrease_position_swap_type: params.decrease_position_swap_type, account, @@ -273,8 +274,6 @@ mod OrderUtils { ); gas_utils::validate_execution_fee(data_store, estimated_gas_limit, order.execution_fee); - let key = nonce_utils::get_next_key(data_store); - order.touch(); base_order_utils::validate_non_empty_order(@order); diff --git a/src/withdrawal/withdrawal_utils.cairo b/src/withdrawal/withdrawal_utils.cairo index a040daa1..425f5d42 100644 --- a/src/withdrawal/withdrawal_utils.cairo +++ b/src/withdrawal/withdrawal_utils.cairo @@ -138,47 +138,31 @@ fn create_withdrawal( market_utils::validate_swap_path(data_store, params.long_token_swap_path); market_utils::validate_swap_path(data_store, params.short_token_swap_path); + let key = nonce_utils::get_next_key(data_store); let mut withdrawal = Withdrawal { - key: 0, - account: contract_address_const::<0>(), - receiver: contract_address_const::<0>(), - callback_contract: contract_address_const::<0>(), - ui_fee_receiver: contract_address_const::<0>(), - market: contract_address_const::<0>(), - long_token_swap_path: Default::default(), - short_token_swap_path: Default::default(), - market_token_amount: 0, - min_long_token_amount: 0, - min_short_token_amount: 0, - updated_at_block: 0, - execution_fee: 0, - callback_gas_limit: 0, + key: key, + account: account, + receiver: params.receiver, + callback_contract: params.callback_contract, + ui_fee_receiver: params.ui_fee_receiver, + market: params.market, + long_token_swap_path: params.long_token_swap_path, + short_token_swap_path: params.short_token_swap_path, + market_token_amount: market_token_amount, + min_long_token_amount: params.min_long_token_amount, + min_short_token_amount: params.min_short_token_amount, + updated_at_block: get_block_timestamp(), + execution_fee: params.execution_fee, + callback_gas_limit: params.callback_gas_limit, }; - withdrawal.account = account; - withdrawal.receiver = params.receiver; - withdrawal.callback_contract = params.callback_contract; - withdrawal.ui_fee_receiver = params.ui_fee_receiver; - withdrawal.market = params.market; - withdrawal.long_token_swap_path = params.long_token_swap_path; - withdrawal.short_token_swap_path = params.short_token_swap_path; - withdrawal.market_token_amount = market_token_amount; - withdrawal.min_long_token_amount = params.min_long_token_amount; - withdrawal.min_short_token_amount = params.min_short_token_amount; - withdrawal.updated_at_block = get_block_timestamp(); - withdrawal.execution_fee = params.execution_fee; - withdrawal.callback_gas_limit = params.callback_gas_limit; - callback_utils::validate_callback_gas_limit(data_store, withdrawal.callback_gas_limit); let estimated_gas_limit = gas_utils::estimate_execute_withdrawal_gas_limit( data_store, withdrawal ); gas_utils::validate_execution_fee(data_store, estimated_gas_limit, params.execution_fee); - let key = nonce_utils::get_next_key(data_store); - // assign generated key to withdrawal - withdrawal.key = key; // store withdrawal data_store.set_withdrawal(key, withdrawal);