From 77580333fd52ae96e4a1beb5a9806911db24d649 Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Fri, 3 Nov 2023 15:12:46 +0100 Subject: [PATCH 1/2] program: amm fill step size --- programs/drift/src/controller/orders.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/programs/drift/src/controller/orders.rs b/programs/drift/src/controller/orders.rs index 44add256b..feb737a5c 100644 --- a/programs/drift/src/controller/orders.rs +++ b/programs/drift/src/controller/orders.rs @@ -1735,6 +1735,7 @@ pub fn fulfill_perp_order_with_amm( liquidity_split: AMMLiquiditySplit, ) -> DriftResult<(u64, u64)> { let position_index = get_position_index(&user.perp_positions, market.market_index)?; + let existing_base_asset_amount = user.perp_positions[position_index].base_asset_amount; // Determine the base asset amount the market can fill let (base_asset_amount, limit_price, fill_price) = match override_base_asset_amount { @@ -1742,7 +1743,6 @@ pub fn fulfill_perp_order_with_amm( (override_base_asset_amount, limit_price, override_fill_price) } None => { - let existing_base_asset_amount = user.perp_positions[position_index].base_asset_amount; let (base_asset_amount, limit_price) = calculate_base_asset_amount_for_amm_to_fulfill( &user.orders[order_index], market, @@ -1761,7 +1761,15 @@ pub fn fulfill_perp_order_with_amm( } }; - if base_asset_amount < market.amm.min_order_size { + // if user position is less than min order size, step size is the threshold + let amm_size_threshold = + if existing_base_asset_amount.unsigned_abs() > market.amm.min_order_size { + market.amm.min_order_size + } else { + market.amm.order_step_size + }; + + if base_asset_amount < amm_size_threshold { // if is an actual swap (and not amm jit order) then msg! if override_base_asset_amount.is_none() { msg!( From b8a9382f0bcbfbcb5282be48bbe5919bfe8a76b9 Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Fri, 3 Nov 2023 15:16:58 +0100 Subject: [PATCH 2/2] CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b749df6c4..c17723863 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixes +- program: allow amm to fill step size ([#672](https://github.com/drift-labs/protocol-v2/pull/672)) + ### Breaking ## [2.42.0] - 2023-10-26