-
Notifications
You must be signed in to change notification settings - Fork 100
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
bigz/update-spot-tvl-invariant-check #525
Changes from 5 commits
4b9bd45
4dda906
3e303cd
a7e7eac
360acb8
2b58568
2058677
61e7de5
180baf9
b9cef29
70e0633
ea9715d
cabd9b3
dfddf20
21570f3
89f2ed8
986ad5d
fed9249
be29a11
c1e80a2
9b2d776
fb06394
edddbef
1942913
b63374d
d010ef6
2beb7ac
2818f8a
53e203b
4eab9ee
4316e65
a32d487
9469385
38e9104
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -252,7 +252,7 @@ pub fn update_spot_balances( | |
} | ||
} | ||
|
||
if let SpotBalanceType::Borrow = update_direction { | ||
if force_round_up && update_direction == &SpotBalanceType::Borrow { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we change the name for force_round_up to better capture when it should be on/off? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dont we need to change fulfill_with_external_market for spot to use this? |
||
let deposit_token_amount = get_token_amount( | ||
spot_market.deposit_balance, | ||
spot_market, | ||
|
@@ -293,13 +293,15 @@ pub fn transfer_spot_balances( | |
return Ok(()); | ||
} | ||
|
||
validate!( | ||
spot_market.deposit_balance >= from_spot_balance.balance(), | ||
ErrorCode::InvalidSpotMarketState, | ||
"spot_market.deposit_balance={} lower than individual spot balance={}", | ||
spot_market.deposit_balance, | ||
from_spot_balance.balance() | ||
)?; | ||
if from_spot_balance.balance_type() == &SpotBalanceType::Deposit { | ||
validate!( | ||
spot_market.deposit_balance >= from_spot_balance.balance(), | ||
ErrorCode::InvalidSpotMarketState, | ||
"spot_market.deposit_balance={} lower than individual spot balance={}", | ||
spot_market.deposit_balance, | ||
from_spot_balance.balance() | ||
)?; | ||
} | ||
|
||
update_spot_balances( | ||
token_amount.unsigned_abs(), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -252,7 +252,7 @@ pub fn get_max_withdraw_for_market_with_token_amount( | |
max_withdraw_amount.safe_add(borrow_limit) | ||
} | ||
|
||
pub fn validate_spot_balances(spot_market: &SpotMarket) -> DriftResult<u64> { | ||
pub fn validate_spot_balances(spot_market: &SpotMarket) -> DriftResult<i64> { | ||
let depositors_amount: u64 = get_token_amount( | ||
spot_market.deposit_balance, | ||
spot_market, | ||
|
@@ -266,13 +266,13 @@ pub fn validate_spot_balances(spot_market: &SpotMarket) -> DriftResult<u64> { | |
)? | ||
.cast()?; | ||
|
||
validate!( | ||
depositors_amount >= borrowers_amount, | ||
ErrorCode::SpotMarketBalanceInvariantViolated, | ||
"depositors_amount={} less than borrowers_amount={}", | ||
depositors_amount, | ||
borrowers_amount | ||
)?; | ||
// validate!( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delete |
||
// depositors_amount >= borrowers_amount, | ||
// ErrorCode::SpotMarketBalanceInvariantViolated, | ||
// "depositors_amount={} less than borrowers_amount={}", | ||
// depositors_amount, | ||
// borrowers_amount | ||
// )?; | ||
|
||
let revenue_amount: u64 = get_token_amount( | ||
spot_market.revenue_pool.scaled_balance, | ||
|
@@ -281,7 +281,9 @@ pub fn validate_spot_balances(spot_market: &SpotMarket) -> DriftResult<u64> { | |
)? | ||
.cast()?; | ||
|
||
let depositors_claim = depositors_amount - borrowers_amount; | ||
let depositors_claim = depositors_amount | ||
.cast::<i64>()? | ||
.safe_sub(borrowers_amount.cast()?)?; | ||
|
||
validate!( | ||
revenue_amount <= depositors_amount, | ||
|
@@ -299,11 +301,11 @@ pub fn validate_spot_balances(spot_market: &SpotMarket) -> DriftResult<u64> { | |
pub fn validate_spot_market_vault_amount( | ||
spot_market: &SpotMarket, | ||
vault_amount: u64, | ||
) -> DriftResult<u64> { | ||
) -> DriftResult<i64> { | ||
let depositors_claim = validate_spot_balances(spot_market)?; | ||
|
||
validate!( | ||
vault_amount >= depositors_claim, | ||
vault_amount.cast::<i64>()? >= depositors_claim, | ||
ErrorCode::SpotMarketVaultInvariantViolated, | ||
"spot market vault ={} holds less than remaining depositor claims = {}", | ||
vault_amount, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be nice to remove if not intentional