From 0f3574007b9e426fa0e6cd19643d4b0626ee529e Mon Sep 17 00:00:00 2001 From: zarboq Date: Mon, 24 Jun 2024 13:25:49 +0200 Subject: [PATCH] feat: fix key field in Order and Withdrawal --- src/order/order_utils.cairo | 5 ++- src/withdrawal/withdrawal_utils.cairo | 46 +++++++++------------------ 2 files changed, 17 insertions(+), 34 deletions(-) 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);