Skip to content

Commit

Permalink
program: allow limit orders to have explicit zero auction duration pa…
Browse files Browse the repository at this point in the history
…ssed in params (#373)

* program: dont enforce min auction for limit orders

* still force limit orders to have min auction duration

* add comment

* CHANGELOG
  • Loading branch information
crispheaney authored Feb 24, 2023
1 parent 0f698f9 commit 60f6490
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixes

- ts-sdk: fix resolvePerpBankrupcty to work with all perp market indexes
- program: allow limit orders to have explicit zero auction duration passed in params ([#373](https://github.com/drift-labs/protocol-v2/pull/373))

### Breaking

Expand Down
24 changes: 17 additions & 7 deletions programs/drift/src/controller/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,20 +382,30 @@ fn get_auction_params(
return Ok((0_i64, 0_i64, 0_u8));
}

let auction_duration = params
.auction_duration
.unwrap_or(0)
.max(min_auction_duration);

if params.order_type == OrderType::Limit {
return match (params.auction_start_price, params.auction_end_price) {
(Some(auction_start_price), Some(auction_end_price)) => {
return match (
params.auction_start_price,
params.auction_end_price,
params.auction_duration,
) {
(Some(auction_start_price), Some(auction_end_price), Some(auction_duration)) => {
let auction_duration = if auction_duration == 0 {
auction_duration
} else {
// if auction is non-zero, force it to be at least min_auction_duration
auction_duration.min(min_auction_duration)
};
Ok((auction_start_price, auction_end_price, auction_duration))
}
_ => Ok((0_i64, 0_i64, 0_u8)),
};
}

let auction_duration = params
.auction_duration
.unwrap_or(0)
.max(min_auction_duration);

let (auction_start_price, auction_end_price) =
match (params.auction_start_price, params.auction_end_price) {
(Some(auction_start_price), Some(auction_end_price)) => {
Expand Down
12 changes: 12 additions & 0 deletions programs/drift/src/validation/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,18 @@ fn validate_limit_order_auction_params(order: &Order) -> DriftResult {
)?;

validate_auction_params(order)?;
} else {
validate!(
order.auction_start_price == 0,
ErrorCode::InvalidOrder,
"limit order without auction can not have an auction start price"
)?;

validate!(
order.auction_end_price == 0,
ErrorCode::InvalidOrder,
"limit order without auction can not have an auction end price"
)?;
}

Ok(())
Expand Down

0 comments on commit 60f6490

Please sign in to comment.