Audit fixes (#613)
* TokenForceCloseBorrows: Respect reduce-only flag * ForceCancelOrders: Readability of early-out condition
This commit is contained in:
parent
c68b1b22cf
commit
b5c9f6d039
|
@ -23,10 +23,10 @@ pub fn perp_liq_force_cancel_orders(
|
|||
// Early return if if liquidation is not allowed or if market is not in force close
|
||||
//
|
||||
let liquidatable = account.check_liquidatable(&health_cache)?;
|
||||
if account.fixed.is_operational()
|
||||
&& liquidatable != CheckLiquidatable::Liquidatable
|
||||
&& !perp_market.is_force_close()
|
||||
{
|
||||
let can_force_cancel = !account.fixed.is_operational()
|
||||
|| liquidatable == CheckLiquidatable::Liquidatable
|
||||
|| perp_market.is_force_close();
|
||||
if !can_force_cancel {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
|
|
@ -60,14 +60,12 @@ pub fn serum3_liq_force_cancel_orders(
|
|||
let health_cache =
|
||||
new_health_cache(&account.borrow(), &retriever).context("create health cache")?;
|
||||
|
||||
{
|
||||
let liquidatable = account.check_liquidatable(&health_cache)?;
|
||||
if account.fixed.is_operational()
|
||||
&& liquidatable != CheckLiquidatable::Liquidatable
|
||||
&& !serum_market.is_force_close()
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
let liquidatable = account.check_liquidatable(&health_cache)?;
|
||||
let can_force_cancel = !account.fixed.is_operational()
|
||||
|| liquidatable == CheckLiquidatable::Liquidatable
|
||||
|| serum_market.is_force_close();
|
||||
if !can_force_cancel {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
health_cache
|
||||
|
|
|
@ -56,6 +56,12 @@ pub fn token_force_close_borrows_with_token(
|
|||
// account constraint #2
|
||||
require!(liab_bank.is_force_close(), MangoError::TokenInForceClose);
|
||||
|
||||
// We might create asset borrows, so forbid asset tokens that don't allow them.
|
||||
require!(
|
||||
!asset_bank.are_borrows_reduce_only(),
|
||||
MangoError::TokenInReduceOnlyMode
|
||||
);
|
||||
|
||||
// account constraint #3
|
||||
// only allow combination of asset and liab token,
|
||||
// where liqee's health would be guaranteed to not decrease
|
||||
|
|
Loading…
Reference in New Issue