Liquidator: bankruptcy requires borrows
This commit is contained in:
parent
24524d7cd5
commit
af5f622bd8
|
@ -111,7 +111,7 @@ pub fn maybe_liquidate_account(
|
||||||
let health_cache =
|
let health_cache =
|
||||||
new_health_cache_(&mango_client.context, account_fetcher, &account).expect("always ok");
|
new_health_cache_(&mango_client.context, account_fetcher, &account).expect("always ok");
|
||||||
let maint_health = health_cache.health(HealthType::Maint);
|
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 {
|
if maint_health >= 0 && !is_bankrupt {
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
|
@ -132,7 +132,7 @@ pub fn maybe_liquidate_account(
|
||||||
let health_cache =
|
let health_cache =
|
||||||
new_health_cache_(&mango_client.context, account_fetcher, &account).expect("always ok");
|
new_health_cache_(&mango_client.context, account_fetcher, &account).expect("always ok");
|
||||||
let maint_health = health_cache.health(HealthType::Maint);
|
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
|
// find asset and liab tokens
|
||||||
let mut tokens = account
|
let mut tokens = account
|
||||||
|
|
|
@ -558,8 +558,6 @@ impl HealthCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn has_borrows(&self) -> bool {
|
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 spot_borrows = self.token_infos.iter().any(|ti| ti.balance.is_negative());
|
||||||
let perp_borrows = self
|
let perp_borrows = self
|
||||||
.perp_infos
|
.perp_infos
|
||||||
|
|
Loading…
Reference in New Issue