Skip to content
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 @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- sdk: fix to getMaxTradeSizeUSDCForPerp which was previously overshooting max allowed size due to IMF factor
- program: add existing position fields to order records ([#1614](https://github.com/drift-labs/protocol-v2/pull/1614))
- program: check limit price after applying buffer in trigger limit order ([#1648](https://github.com/drift-labs/protocol-v2/pull/1648))
- program: check limit price when setting auction for limit order ([#1650](https://github.com/drift-labs/protocol-v2/pull/1650))

### Breaking

Expand Down
26 changes: 24 additions & 2 deletions programs/drift/src/state/order_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl OrderParams {
if is_oracle_offset_oracle {
msg!(
"Updating oracle limit auction start price to {}",
new_auction_start_price
auction_start_price_offset
);
self.auction_start_price = Some(auction_start_price_offset);
} else {
Expand All @@ -216,7 +216,7 @@ impl OrderParams {
if is_oracle_offset_oracle {
msg!(
"Updating oracle limit auction start price to {}",
new_auction_start_price
auction_start_price_offset
);
self.auction_start_price = Some(auction_start_price_offset);
} else {
Expand All @@ -243,6 +243,28 @@ impl OrderParams {
}
}

let worst_price = if is_oracle_offset_oracle {
oracle_price_offset as i64
} else {
self.price as i64
};

if self.direction == PositionDirection::Long {
if let Some(auction_start_price) = self.auction_start_price {
self.auction_start_price = Some(auction_start_price.min(worst_price));
}
if let Some(auction_end_price) = self.auction_end_price {
self.auction_end_price = Some(auction_end_price.min(worst_price));
}
} else {
if let Some(auction_start_price) = self.auction_start_price {
self.auction_start_price = Some(auction_start_price.max(worst_price));
}
if let Some(auction_end_price) = self.auction_end_price {
self.auction_end_price = Some(auction_end_price.max(worst_price));
}
}

let auction_duration_before = self.auction_duration;
let new_auction_duration = get_auction_duration(
self.auction_end_price
Expand Down
Loading