Skip to content

Commit

Permalink
program: check if user has room for open order before placing order t…
Browse files Browse the repository at this point in the history
…o derisk lp position
  • Loading branch information
crispheaney committed Feb 21, 2024
1 parent 7c6fe6a commit 372a969
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
24 changes: 13 additions & 11 deletions programs/drift/src/controller/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2953,17 +2953,19 @@ pub fn burn_user_lp_shares_for_risk_reduction(

drop(market);

controller::orders::place_perp_order(
state,
user,
user_key,
perp_market_map,
spot_market_map,
oracle_map,
clock,
params,
PlaceOrderOptions::default().explanation(OrderActionExplanation::DeriskLp),
)?;
if user.has_room_for_new_order() {

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

View check run for this annotation

Codecov / codecov/patch

programs/drift/src/controller/orders.rs#L2956

Added line #L2956 was not covered by tests
controller::orders::place_perp_order(
state,
user,
user_key,

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

View check run for this annotation

Codecov / codecov/patch

programs/drift/src/controller/orders.rs#L2960

Added line #L2960 was not covered by tests
perp_market_map,
spot_market_map,
oracle_map,
clock,
params,
PlaceOrderOptions::default().explanation(OrderActionExplanation::DeriskLp),

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

View check run for this annotation

Codecov / codecov/patch

programs/drift/src/controller/orders.rs#L2965-L2966

Added lines #L2965 - L2966 were not covered by tests
)?;
}

Ok(())
}
Expand Down
10 changes: 10 additions & 0 deletions programs/drift/src/state/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,16 @@ impl User {

Ok(())
}

pub fn has_room_for_new_order(&self) -> bool {
for order in self.orders.iter() {
if order.status == OrderStatus::Init {
return true;

Check warning on line 417 in programs/drift/src/state/user.rs

View check run for this annotation

Codecov / codecov/patch

programs/drift/src/state/user.rs#L414-L417

Added lines #L414 - L417 were not covered by tests
}
}

false

Check warning on line 421 in programs/drift/src/state/user.rs

View check run for this annotation

Codecov / codecov/patch

programs/drift/src/state/user.rs#L421

Added line #L421 was not covered by tests
}
}

#[zero_copy(unsafe)]
Expand Down

0 comments on commit 372a969

Please sign in to comment.