Token bankruptcy: Separate checks (#629)

This makes it easier to debug, since we know what value did not match
the requirements.
This commit is contained in:
Christian Kamm 2023-07-03 10:25:02 +02:00 committed by GitHub
parent 81cc4ffe42
commit 34e41b6719
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -69,8 +69,10 @@ pub fn token_liq_bankruptcy(
// In particular, a very negative perp hupnl does not allow token bankruptcy to happen,
// and if the perp hupnl is positive, we need to liquidate that before dealing with token
// bankruptcy!
require_gt!(I80F48::ZERO, initial_liab_native);
require_gt!(I80F48::ZERO, liqee_liab_health_balance);
// guaranteed positive
let mut remaining_liab_loss = (-initial_liab_native).min(-liqee_liab_health_balance);
require_gt!(remaining_liab_loss, I80F48::ZERO);
// We pay for the liab token in quote. Example: SOL is at $20 and USDC is at $2, then for a liab
// of 3 SOL, we'd pay 3 * 20 / 2 * (1+fee) = 30 * (1+fee) USDC.