Skip to content

Commit 7822b31

Browse files
authored
Merge pull request #3317 from DFXswiss/develop
Release: develop -> main
2 parents 8846c09 + cf7d52c commit 7822b31

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

src/integration/exchange/services/exchange.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ export abstract class ExchangeService extends PricingProvider implements OnModul
228228
const fees = await this.callApi((e) => e.fetchDepositWithdrawFees([token]));
229229
const tokenFees = fees[token];
230230

231-
return tokenFees?.networks?.[network]?.fee ?? tokenFees?.withdraw?.fee ?? 0;
231+
return (tokenFees?.networks?.[network] as any)?.withdraw?.fee ?? tokenFees?.withdraw?.fee ?? 0;
232232
}
233233

234234
// --- Helper Methods --- //

src/subdomains/core/liquidity-management/adapters/actions/binance.adapter.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,16 @@ export class BinanceAdapter extends CcxtExchangeAdapter {
5757
const asset = order.pipeline.rule.targetAsset.dexName;
5858
const network = this.exchangeService.mapNetwork(Blockchain.LIGHTNING) || undefined;
5959
const balance = await this.exchangeService.getAvailableBalance(asset);
60+
const withdrawalFee = await this.exchangeService.getWithdrawalFee(asset, network);
6061

61-
const amount = Util.floor(Math.min(order.maxAmount, balance * 0.99, BINANCE_LIGHTNING_MAX_WITHDRAWAL_BTC), 8);
62+
const amount = Util.floor(
63+
Math.min(order.maxAmount, balance - withdrawalFee, BINANCE_LIGHTNING_MAX_WITHDRAWAL_BTC),
64+
8,
65+
);
6266

6367
if (amount <= 0)
6468
throw new OrderNotProcessableException(
65-
`${this.exchangeService.name}: not enough balance for ${asset} (balance: ${balance}, min. requested: ${order.minAmount}, max. requested: ${order.maxAmount})`,
69+
`${this.exchangeService.name}: not enough balance for ${asset} (balance: ${balance}, fee: ${withdrawalFee}, min. requested: ${order.minAmount}, max. requested: ${order.maxAmount})`,
6670
);
6771

6872
const amountSats = LightningHelper.btcToSat(amount);
@@ -78,8 +82,14 @@ export class BinanceAdapter extends CcxtExchangeAdapter {
7882
order.inputAsset = asset;
7983
order.outputAsset = asset;
8084

81-
// Send only the invoice amount — Binance deducts the fee from the balance separately
82-
const response = await this.exchangeService.withdrawFunds(asset, amount, invoice.pr, undefined, network);
85+
// Binance requires: withdrawal amount = invoice BTC value + withdrawal fee
86+
const response = await this.exchangeService.withdrawFunds(
87+
asset,
88+
amount + withdrawalFee,
89+
invoice.pr,
90+
undefined,
91+
network,
92+
);
8393

8494
return response.id;
8595
}

0 commit comments

Comments
 (0)