Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

program: amm fill step size #672

Merged
merged 3 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ 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))
- program: add add update_liquidation_margin_buffer_ratio ([#695](https://github.com/drift-labs/protocol-v2/pull/695))
- program: account for fee pool when settling positive pnl ([#687](https://github.com/drift-labs/protocol-v2/pull/687))
- sdk: fix bug which incorrectly calculated leverage after trade for a market with no position but short orders open
Expand Down
12 changes: 10 additions & 2 deletions programs/drift/src/controller/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1735,14 +1735,14 @@ 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 {
Some(override_base_asset_amount) => {
(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,
Expand All @@ -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!(
Expand Down
Loading