diff --git a/programs/manifest/src/program/processor/batch_update.rs b/programs/manifest/src/program/processor/batch_update.rs index 64862e67e..c91cff48c 100644 --- a/programs/manifest/src/program/processor/batch_update.rs +++ b/programs/manifest/src/program/processor/batch_update.rs @@ -210,11 +210,8 @@ pub(crate) fn process_batch_update( "Invalid cancel hint sequence number index {}", hinted_cancel_index, )?; - dynamic_account.cancel_order_by_index( - trader_index, - hinted_cancel_index, - &global_trade_accounts_opts, - )?; + dynamic_account + .cancel_order_by_index(hinted_cancel_index, &global_trade_accounts_opts)?; } }; diff --git a/programs/manifest/src/program/processor/global_clean.rs b/programs/manifest/src/program/processor/global_clean.rs index f1421c57d..6b2953a27 100644 --- a/programs/manifest/src/program/processor/global_clean.rs +++ b/programs/manifest/src/program/processor/global_clean.rs @@ -131,11 +131,7 @@ pub(crate) fn process_global_clean( // Should drop global, but cancel_order_by_index actually does not need to // borrow in this case. - market_dynamic_account.cancel_order_by_index( - maker_index, - order_index, - &global_trade_accounts, - )?; + market_dynamic_account.cancel_order_by_index(order_index, &global_trade_accounts)?; // The global account itself only accounting on remove_order is that it // tracks unclaimed gas deposits for informational purposes and this is diff --git a/programs/manifest/src/state/market.rs b/programs/manifest/src/state/market.rs index c65c1e3dc..30f14d133 100644 --- a/programs/manifest/src/state/market.rs +++ b/programs/manifest/src/state/market.rs @@ -1099,11 +1099,7 @@ impl< } if index_to_remove != NIL { // Cancel order by index will update balances. - self.cancel_order_by_index( - trader_index, - index_to_remove, - global_trade_accounts_opts, - )?; + self.cancel_order_by_index(index_to_remove, global_trade_accounts_opts)?; return Ok(()); } } @@ -1114,38 +1110,12 @@ impl< pub fn cancel_order_by_index( &mut self, - trader_index: DataIndex, order_index: DataIndex, global_trade_accounts_opts: &[Option; 2], ) -> ProgramResult { let DynamicAccount { fixed, dynamic } = self.borrow_mut(); - let resting_order: &RestingOrder = - get_helper::>(dynamic, order_index).get_value(); - let is_bid: bool = resting_order.get_is_bid(); - let amount_atoms: u64 = if is_bid { - (resting_order - .get_price() - .checked_quote_for_base(resting_order.get_num_base_atoms(), true) - .unwrap()) - .into() - } else { - resting_order.get_num_base_atoms().into() - }; - - // Update the accounting for the order that was just canceled. - if resting_order.is_global() { - let global_trade_accounts_opt: &Option = if is_bid { - &global_trade_accounts_opts[1] - } else { - &global_trade_accounts_opts[0] - }; - remove_from_global(&global_trade_accounts_opt)? - } else { - update_balance(dynamic, trader_index, !is_bid, true, amount_atoms)?; - } - remove_order_from_tree_and_free(fixed, dynamic, order_index, is_bid)?; - + remove_and_update_balances(fixed, dynamic, order_index, global_trade_accounts_opts)?; Ok(()) } }