From 99398ef93f804df6bb3703f40d2a121737121c44 Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Wed, 4 Dec 2024 17:25:37 -0500 Subject: [PATCH] skip placing order instead of erroring out if base asset amount is 0 --- programs/drift/src/controller/orders.rs | 64 ++++++++++++------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/programs/drift/src/controller/orders.rs b/programs/drift/src/controller/orders.rs index 0de95ec3a..93959f80b 100644 --- a/programs/drift/src/controller/orders.rs +++ b/programs/drift/src/controller/orders.rs @@ -947,30 +947,32 @@ pub fn modify_order( let order_params = merge_modify_order_params_with_existing_order(&existing_order, &modify_order_params)?; - if order_params.market_type == MarketType::Perp { - place_perp_order( - state, - &mut user, - user_key, - perp_market_map, - spot_market_map, - oracle_map, - clock, - order_params, - PlaceOrderOptions::default(), - )?; - } else { - place_spot_order( - state, - &mut user, - user_key, - perp_market_map, - spot_market_map, - oracle_map, - clock, - order_params, - PlaceOrderOptions::default(), - )?; + if let Some(order_params) = order_params { + if order_params.market_type == MarketType::Perp { + place_perp_order( + state, + &mut user, + user_key, + perp_market_map, + spot_market_map, + oracle_map, + clock, + order_params, + PlaceOrderOptions::default(), + )?; + } else { + place_spot_order( + state, + &mut user, + user_key, + perp_market_map, + spot_market_map, + oracle_map, + clock, + order_params, + PlaceOrderOptions::default(), + )?; + } } Ok(()) @@ -979,7 +981,7 @@ pub fn modify_order( fn merge_modify_order_params_with_existing_order( existing_order: &Order, modify_order_params: &ModifyOrderParams, -) -> DriftResult { +) -> DriftResult> { let order_type = existing_order.order_type; let market_type = existing_order.market_type; let direction = modify_order_params @@ -991,11 +993,9 @@ fn merge_modify_order_params_with_existing_order( let base_asset_amount = base_asset_amount.saturating_sub(existing_order.base_asset_amount_filled); - validate!( - base_asset_amount > 0, - ErrorCode::InvalidOrder, - "modify order lead to 0 base asset amount" - )?; + if base_asset_amount == 0 { + return Ok(None); + } base_asset_amount } @@ -1047,7 +1047,7 @@ fn merge_modify_order_params_with_existing_order( (None, None, None) }; - Ok(OrderParams { + Ok(Some(OrderParams { order_type, market_type, direction, @@ -1065,7 +1065,7 @@ fn merge_modify_order_params_with_existing_order( auction_duration, auction_start_price, auction_end_price, - }) + })) } pub fn fill_perp_order(