Skip to content

Commit

Permalink
allow place with usdc borrow, block withdraw with other liab
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbigz committed Feb 27, 2024
1 parent 31465b1 commit efcb288
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions programs/drift/src/math/margin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,12 +578,21 @@ pub fn meets_place_order_margin_requirement(
return Err(ErrorCode::InsufficientCollateral);
}

if calculation.get_num_of_liabilities()? > 1 {
validate!(
!calculation.with_isolated_liability,
ErrorCode::IsolatedAssetTierViolation,
"User attempting to increase number of liabilities above 1 with a isolated tier liability"
)?;
if calculation.with_isolated_liability {
if !user.is_reduce_only() {
validate!(
calculation.num_perp_liabilities <= 1,
ErrorCode::IsolatedAssetTierViolation,

Check warning on line 585 in programs/drift/src/math/margin.rs

View check run for this annotation

Codecov / codecov/patch

programs/drift/src/math/margin.rs#L581-L585

Added lines #L581 - L585 were not covered by tests
"User attempting to increase number of liabilities above 1 with a isolated tier liability"
)?;

validate!(
calculation.num_spot_liabilities == 0 ||
(calculation.num_spot_liabilities == 1 && user.get_quote_spot_position().balance_type == SpotBalanceType::Borrow),
ErrorCode::IsolatedAssetTierViolation,

Check warning on line 592 in programs/drift/src/math/margin.rs

View check run for this annotation

Codecov / codecov/patch

programs/drift/src/math/margin.rs#L589-L592

Added lines #L589 - L592 were not covered by tests
"User attempting to increase number of liabilities above 1 with a isolated tier liability"
)?;
}
}

Ok(())
Expand Down

0 comments on commit efcb288

Please sign in to comment.