From cf7d52c6d2f4248601c4a1bdf378db0454a2c2be Mon Sep 17 00:00:00 2001 From: TaprootFreak <142087526+TaprootFreak@users.noreply.github.com> Date: Mon, 2 Mar 2026 20:05:11 +0100 Subject: [PATCH] fix: correct withdrawal fee lookup and Lightning withdrawal amount (#3316) Fix getWithdrawalFee to access the correct CCXT property path (networks[key].withdraw.fee instead of networks[key].fee) and restore fee handling in Binance Lightning withdrawal to send invoice amount + fee as required by Binance API. --- .../exchange/services/exchange.service.ts | 2 +- .../adapters/actions/binance.adapter.ts | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/integration/exchange/services/exchange.service.ts b/src/integration/exchange/services/exchange.service.ts index 632f4fc122..3e988598a2 100644 --- a/src/integration/exchange/services/exchange.service.ts +++ b/src/integration/exchange/services/exchange.service.ts @@ -228,7 +228,7 @@ export abstract class ExchangeService extends PricingProvider implements OnModul const fees = await this.callApi((e) => e.fetchDepositWithdrawFees([token])); const tokenFees = fees[token]; - return tokenFees?.networks?.[network]?.fee ?? tokenFees?.withdraw?.fee ?? 0; + return (tokenFees?.networks?.[network] as any)?.withdraw?.fee ?? tokenFees?.withdraw?.fee ?? 0; } // --- Helper Methods --- // diff --git a/src/subdomains/core/liquidity-management/adapters/actions/binance.adapter.ts b/src/subdomains/core/liquidity-management/adapters/actions/binance.adapter.ts index d01d5964eb..c2805ef2a9 100644 --- a/src/subdomains/core/liquidity-management/adapters/actions/binance.adapter.ts +++ b/src/subdomains/core/liquidity-management/adapters/actions/binance.adapter.ts @@ -57,12 +57,16 @@ export class BinanceAdapter extends CcxtExchangeAdapter { const asset = order.pipeline.rule.targetAsset.dexName; const network = this.exchangeService.mapNetwork(Blockchain.LIGHTNING) || undefined; const balance = await this.exchangeService.getAvailableBalance(asset); + const withdrawalFee = await this.exchangeService.getWithdrawalFee(asset, network); - const amount = Util.floor(Math.min(order.maxAmount, balance * 0.99, BINANCE_LIGHTNING_MAX_WITHDRAWAL_BTC), 8); + const amount = Util.floor( + Math.min(order.maxAmount, balance - withdrawalFee, BINANCE_LIGHTNING_MAX_WITHDRAWAL_BTC), + 8, + ); if (amount <= 0) throw new OrderNotProcessableException( - `${this.exchangeService.name}: not enough balance for ${asset} (balance: ${balance}, min. requested: ${order.minAmount}, max. requested: ${order.maxAmount})`, + `${this.exchangeService.name}: not enough balance for ${asset} (balance: ${balance}, fee: ${withdrawalFee}, min. requested: ${order.minAmount}, max. requested: ${order.maxAmount})`, ); const amountSats = LightningHelper.btcToSat(amount); @@ -78,8 +82,14 @@ export class BinanceAdapter extends CcxtExchangeAdapter { order.inputAsset = asset; order.outputAsset = asset; - // Send only the invoice amount — Binance deducts the fee from the balance separately - const response = await this.exchangeService.withdrawFunds(asset, amount, invoice.pr, undefined, network); + // Binance requires: withdrawal amount = invoice BTC value + withdrawal fee + const response = await this.exchangeService.withdrawFunds( + asset, + amount + withdrawalFee, + invoice.pr, + undefined, + network, + ); return response.id; }