From 9225b8ddea10c15487271a7e4a4c9b26598fc45b Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 25 Nov 2026 09:25:18 -0700 Subject: nwc: floor the default routing fee cap at 5 sats 1% rounds to zero below 50 sats, which rejected small zaps whose route costs a sat. Unused fee is refunded. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VMan6SEnsbshZrUDtTsxAX --- lib/nwc.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/nwc.ts b/lib/nwc.ts index 21bab0a7..1b306e1b 100644 --- a/lib/nwc.ts +++ b/lib/nwc.ts @@ -59,6 +59,12 @@ const methods = [ ]; const week = 7 * 24 * 60 * 60; + +// Fee cap for a connection with no max fee of its own: 1% of the amount, but +// never under 5 sats. Plain 1% rounds to 0 below 50 sats, and a 0 cap rejects +// any zap whose route costs a single sat. Unused fee is refunded. +const defaultMaxFee = (amount: number) => + Math.max(5, Math.ceil(amount * 0.01)); const nwcEventMaxAgeSeconds = 5 * 60; // Tolerated clock skew for future-dated events. Events further ahead than this // are rejected so a captured, future-dated signed event can't be replayed later. @@ -704,7 +710,7 @@ const handle = (method, params, ev, app, user) => // payment had settled; see issue #80). const p = await sendLightning({ amount, - fee: max_fee || Math.round(amount * 0.01), + fee: max_fee || defaultMaxFee(amount), user, pr, memo: JSON.stringify(metadata), @@ -877,7 +883,7 @@ const handle = (method, params, ev, app, user) => try { const p = await sendLightning({ amount, - fee: app.max_fee || Math.round(amount * 0.01), + fee: app.max_fee || defaultMaxFee(amount), user, pr, memo: metadata ? JSON.stringify(metadata) : undefined, -- cgit v1.2.3