Liquidator: bankruptcy requires borrows

This commit is contained in:
Christian Kamm 2022-08-16 08:14:45 +02:00
parent 24524d7cd5
commit af5f622bd8
2 changed files with 2 additions and 4 deletions

View File

@ -111,7 +111,7 @@ pub fn maybe_liquidate_account(
let health_cache =
new_health_cache_(&mango_client.context, account_fetcher, &account).expect("always ok");
let maint_health = health_cache.health(HealthType::Maint);
let is_bankrupt = !health_cache.has_liquidatable_assets();
let is_bankrupt = !health_cache.has_liquidatable_assets() && health_cache.has_borrows();
if maint_health >= 0 && !is_bankrupt {
return Ok(false);
@ -132,7 +132,7 @@ pub fn maybe_liquidate_account(
let health_cache =
new_health_cache_(&mango_client.context, account_fetcher, &account).expect("always ok");
let maint_health = health_cache.health(HealthType::Maint);
let is_bankrupt = !health_cache.has_liquidatable_assets();
let is_bankrupt = !health_cache.has_liquidatable_assets() && health_cache.has_borrows();
// find asset and liab tokens
let mut tokens = account

View File

@ -558,8 +558,6 @@ impl HealthCache {
}
pub fn has_borrows(&self) -> bool {
// AUDIT: Can we really guarantee that liquidation/bankruptcy resolution always leaves
// non-negative balances?
let spot_borrows = self.token_infos.iter().any(|ti| ti.balance.is_negative());
let perp_borrows = self
.perp_infos