Skip to content

program: make it easer to fill min order size orders #1799

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 7 additions & 6 deletions programs/drift/src/controller/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2178,12 +2178,13 @@ pub fn fulfill_perp_order_with_amm(
};

// 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
};
let amm_size_threshold = if !user.orders[order_index].reduce_only
&& 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!
Expand Down
6 changes: 3 additions & 3 deletions programs/drift/src/validation/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ fn validate_limit_order(
order,
market.amm.order_step_size,
market.amm.min_order_size,
order.reduce_only,
order.reduce_only || order.is_jit_maker(),
)?;

if order.price == 0 && !order.has_oracle_price_offset() {
Expand Down Expand Up @@ -339,7 +339,7 @@ fn validate_base_asset_amount(
order: &Order,
step_size: u64,
min_order_size: u64,
reduce_only: bool,
reduce_only_or_jit_maker: bool,
) -> DriftResult {
if order.base_asset_amount == 0 {
msg!("Order base_asset_amount cant be 0");
Expand All @@ -355,7 +355,7 @@ fn validate_base_asset_amount(
)?;

validate!(
reduce_only || order.base_asset_amount >= min_order_size,
reduce_only_or_jit_maker || order.base_asset_amount >= min_order_size,
ErrorCode::InvalidOrderMinOrderSize,
"Order base_asset_amount ({}) < min_order_size ({})",
order.base_asset_amount,
Expand Down
Loading