From 77abfd0529f85a4fb1d975566c58a5f60a663737 Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Tue, 27 Sep 2022 11:10:28 +0200 Subject: [PATCH] Perp liq: Fix base position liquidation amount computation It was wrong for quote weights != 1. --- .../mango-v4/src/instructions/perp_liq_base_position.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/programs/mango-v4/src/instructions/perp_liq_base_position.rs b/programs/mango-v4/src/instructions/perp_liq_base_position.rs index 59cf3d1b7..70feab58b 100644 --- a/programs/mango-v4/src/instructions/perp_liq_base_position.rs +++ b/programs/mango-v4/src/instructions/perp_liq_base_position.rs @@ -112,7 +112,8 @@ pub fn perp_liq_base_position( // and increased by `base * price * (1 - liq_fee) * quote_init_asset_weight` let quote_asset_weight = I80F48::ONE; let health_per_lot = cm!(price_per_lot - * (quote_asset_weight - perp_market.init_asset_weight - perp_market.liquidation_fee)); + * (quote_asset_weight * (I80F48::ONE - perp_market.liquidation_fee) + - perp_market.init_asset_weight)); // number of lots to transfer to bring health to zero, rounded up let base_transfer_for_zero: i64 = cm!(-liqee_init_health / health_per_lot) @@ -141,7 +142,8 @@ pub fn perp_liq_base_position( // and reduced by `base * price * (1 + liq_fee) * quote_init_liab_weight` let quote_liab_weight = I80F48::ONE; let health_per_lot = cm!(price_per_lot - * (perp_market.init_liab_weight - quote_liab_weight + perp_market.liquidation_fee)); + * (perp_market.init_liab_weight * (I80F48::ONE + perp_market.liquidation_fee) + - quote_liab_weight)); // (negative) number of lots to transfer to bring health to zero, rounded away from zero let base_transfer_for_zero: i64 = cm!(liqee_init_health / health_per_lot)