From 66c6ae1cff552e8fd0a93c4c2e8a1a389d163075 Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Mon, 22 Apr 2024 14:10:01 +0200 Subject: [PATCH] liquidator: fix rebalance loops selling 100% with flash loan swap fee charged on top meant creating a borrow --- bin/liquidator/src/rebalance.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/liquidator/src/rebalance.rs b/bin/liquidator/src/rebalance.rs index 7a867587d..0472e300c 100644 --- a/bin/liquidator/src/rebalance.rs +++ b/bin/liquidator/src/rebalance.rs @@ -498,8 +498,11 @@ impl Rebalancer { if amount > dust_threshold { // Sell + + // To avoid creating a borrow when paying flash loan fees, sell only a fraction + let input_amount = amount * I80F48::from_num(0.99); let (txsig, route) = self - .token_swap_sell(token_mint, amount.to_num::()) + .token_swap_sell(token_mint, input_amount.to_num::()) .await?; let out_token = self .mango_client