aboutsummaryrefslogtreecommitdiffstats
path: root/lib/nwc.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/nwc.ts')
-rw-r--r--lib/nwc.ts10
1 files changed, 8 insertions, 2 deletions
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,