Skip to content
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

program: check if user has room for open order before placing order t… #899

Merged
merged 3 commits into from
Feb 23, 2024
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 @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixes

- program: handle derisk lp when orders array full ([#899](https://github.com/drift-labs/protocol-v2/pull/899))
- program: invalid borrow in get_referrer_info when maker is refferer ([#900](https://github.com/drift-labs/protocol-v2/pull/900))

### Breaking
Expand Down
24 changes: 13 additions & 11 deletions programs/drift/src/controller/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2960,17 +2960,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() {
controller::orders::place_perp_order(
state,
user,
user_key,
perp_market_map,
spot_market_map,
oracle_map,
clock,
params,
PlaceOrderOptions::default().explanation(OrderActionExplanation::DeriskLp),
)?;
}

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;
}
}

false
}
}

#[zero_copy(unsafe)]
Expand Down
Loading