Skip to content

Commit

Permalink
program: flip auction flag when trigger order adds auction
Browse files Browse the repository at this point in the history
  • Loading branch information
crispheaney committed Dec 18, 2023
1 parent 06664a9 commit 8beb3f2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 8 additions & 0 deletions programs/drift/src/controller/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2579,6 +2579,10 @@ pub fn trigger_order(
state.min_perp_auction_duration,
)?;

if user.orders[order_index].has_auction() {
user.increment_open_auctions();

Check warning on line 2583 in programs/drift/src/controller/orders.rs

View check run for this annotation

Codecov / codecov/patch

programs/drift/src/controller/orders.rs#L2582-L2583

Added lines #L2582 - L2583 were not covered by tests
}

let direction = user.orders[order_index].direction;
let base_asset_amount = user.orders[order_index].base_asset_amount;

Expand Down Expand Up @@ -4570,6 +4574,10 @@ pub fn trigger_spot_order(
state.default_spot_auction_duration,
)?;

if user.orders[order_index].has_auction() {
user.increment_open_auctions();

Check warning on line 4578 in programs/drift/src/controller/orders.rs

View check run for this annotation

Codecov / codecov/patch

programs/drift/src/controller/orders.rs#L4577-L4578

Added lines #L4577 - L4578 were not covered by tests
}

let direction = user.orders[order_index].direction;
let base_asset_amount = user.orders[order_index].base_asset_amount;

Expand Down
8 changes: 6 additions & 2 deletions programs/drift/src/state/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,15 @@ impl User {
self.open_orders = self.open_orders.saturating_add(1);
self.has_open_order = self.open_orders > 0;
if is_auction {
self.open_auctions = self.open_auctions.saturating_add(1);
self.has_open_auction = self.open_auctions > 0;
self.increment_open_auctions();
}
}

pub fn increment_open_auctions(&mut self) {
self.open_auctions = self.open_auctions.saturating_add(1);
self.has_open_auction = self.open_auctions > 0;
}

pub fn decrement_open_orders(&mut self, is_auction: bool) {
self.open_orders = self.open_orders.saturating_sub(1);
self.has_open_order = self.open_orders > 0;
Expand Down

0 comments on commit 8beb3f2

Please sign in to comment.