From c6dfa3eff743096e83945bd302e7df0381f59c1d Mon Sep 17 00:00:00 2001 From: TaprootFreak <142087526+TaprootFreak@users.noreply.github.com> Date: Mon, 2 Mar 2026 21:11:29 +0100 Subject: [PATCH] fix: add 1% routing reserve to Lightning liquidity check (#3318) Lightning payments require ~1% extra balance for routing fees. The liquidity check did not account for this, causing orders to pass optimizeByLiquidity but fail at getLndRoutes (HTTP 500), resulting in an endless retry loop without creating a new LM pipeline. Apply a 0.99 factor to available balance before comparing, so the system correctly detects insufficient liquidity. --- .../supporting/dex/services/dex-lightning.service.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/subdomains/supporting/dex/services/dex-lightning.service.ts b/src/subdomains/supporting/dex/services/dex-lightning.service.ts index 00ae7b45bc..2109f0454e 100644 --- a/src/subdomains/supporting/dex/services/dex-lightning.service.ts +++ b/src/subdomains/supporting/dex/services/dex-lightning.service.ts @@ -8,6 +8,8 @@ import { LiquidityOrderRepository } from '../repositories/liquidity-order.reposi @Injectable() export class DexLightningService { + private static readonly ROUTING_RESERVE_FACTOR = 0.99; // 1% reserve for routing fees + private readonly lightningClient: LightningClient; constructor( @@ -21,7 +23,7 @@ export class DexLightningService { const pendingAmount = await this.getPendingAmount(); const availableAmount = await this.lightningClient.getAvailableBalance(); - return [inputAmount, availableAmount - pendingAmount]; + return [inputAmount, availableAmount * DexLightningService.ROUTING_RESERVE_FACTOR - pendingAmount]; } private async getPendingAmount(): Promise {