Skip to content

Commit

Permalink
fix: fix key field in Order and Withdrawal (#676)
Browse files Browse the repository at this point in the history
feat: fix key field in Order and Withdrawal

Co-authored-by: sparqet <[email protected]>
  • Loading branch information
zarboq and sparqet authored Jun 24, 2024
1 parent 7e70a2e commit 000ded5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 34 deletions.
5 changes: 2 additions & 3 deletions src/order/order_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
46 changes: 15 additions & 31 deletions src/withdrawal/withdrawal_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 000ded5

Please sign in to comment.