From 3cdd67c7403155b73960e662c2ff01ef681c1b87 Mon Sep 17 00:00:00 2001 From: lil perp Date: Mon, 23 Jan 2023 19:18:15 -0500 Subject: [PATCH] program: enforce min order size when trading against amm (#334) * program: enforce min order size when trading against amm * CHANGELOG --- CHANGELOG.md | 2 ++ programs/drift/src/controller/orders.rs | 8 ++++++-- programs/drift/src/state/perp_market.rs | 2 +- sdk/src/math/orders.ts | 4 ++-- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc7012fa7..a4b7ed081 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Features +- program: enforce min order size when trading against amm ([#334](https://github.com/drift-labs/protocol-v2/pull/334)) + ### Fixes ### Breaking diff --git a/programs/drift/src/controller/orders.rs b/programs/drift/src/controller/orders.rs index 9a62ba88b..8b1664427 100644 --- a/programs/drift/src/controller/orders.rs +++ b/programs/drift/src/controller/orders.rs @@ -1513,10 +1513,14 @@ pub fn fulfill_perp_order_with_amm( } }; - if base_asset_amount == 0 { + if base_asset_amount < market.amm.min_order_size { // if is an actual swap (and not amm jit order) then msg! if override_base_asset_amount.is_none() { - msg!("Amm cant fulfill order"); + msg!( + "Amm cant fulfill order. base asset amount {} market.amm.min_order_size {}", + base_asset_amount, + market.amm.min_order_size + ); } return Ok((0, 0)); } diff --git a/programs/drift/src/state/perp_market.rs b/programs/drift/src/state/perp_market.rs index 9a91f03e8..14df5ae90 100644 --- a/programs/drift/src/state/perp_market.rs +++ b/programs/drift/src/state/perp_market.rs @@ -477,7 +477,7 @@ impl Default for AMM { funding_period: 0, order_step_size: 0, order_tick_size: 0, - min_order_size: 0, + min_order_size: 1, max_position_size: 0, volume_24h: 0, long_intensity_volume: 0, diff --git a/sdk/src/math/orders.ts b/sdk/src/math/orders.ts index ad8a4d330..a081f13d1 100644 --- a/sdk/src/math/orders.ts +++ b/sdk/src/math/orders.ts @@ -165,12 +165,12 @@ export function isFillableByVAMM( ): boolean { return ( (isAuctionComplete(order, slot) && - !calculateBaseAssetAmountForAmmToFulfill( + calculateBaseAssetAmountForAmmToFulfill( order, market, oraclePriceData, slot - ).eq(ZERO)) || + ).gte(market.amm.minOrderSize)) || isOrderExpired(order, ts) ); }