Skip to content

Commit

Permalink
program: enforce min order size when trading against amm (#334)
Browse files Browse the repository at this point in the history
* program: enforce min order size when trading against amm

* CHANGELOG
  • Loading branch information
crispheaney authored Jan 24, 2023
1 parent 6d87997 commit 3cdd67c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions programs/drift/src/controller/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion programs/drift/src/state/perp_market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/math/orders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
Expand Down

0 comments on commit 3cdd67c

Please sign in to comment.