diff --git a/programs/mango-v4/src/instructions/perp_liq_force_cancel_orders.rs b/programs/mango-v4/src/instructions/perp_liq_force_cancel_orders.rs index f001cf78b..04b74b7dd 100644 --- a/programs/mango-v4/src/instructions/perp_liq_force_cancel_orders.rs +++ b/programs/mango-v4/src/instructions/perp_liq_force_cancel_orders.rs @@ -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(()); } diff --git a/programs/mango-v4/src/instructions/serum3_liq_force_cancel_orders.rs b/programs/mango-v4/src/instructions/serum3_liq_force_cancel_orders.rs index 62e9c81c6..e4089d01e 100644 --- a/programs/mango-v4/src/instructions/serum3_liq_force_cancel_orders.rs +++ b/programs/mango-v4/src/instructions/serum3_liq_force_cancel_orders.rs @@ -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 diff --git a/programs/mango-v4/src/instructions/token_force_close_borrows_with_token.rs b/programs/mango-v4/src/instructions/token_force_close_borrows_with_token.rs index 00beb6cce..f32d5b6b1 100644 --- a/programs/mango-v4/src/instructions/token_force_close_borrows_with_token.rs +++ b/programs/mango-v4/src/instructions/token_force_close_borrows_with_token.rs @@ -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