diff options
| author | Adam Soltys <[email protected]> | 2026-08-14 00:02:06 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-08-14 00:02:06 -0700 |
| commit | 5abf76764c445b742a50080ebb97c313531d5962 (patch) | |
| tree | 7a9f531971e93102dfd2c4d49ecf872299e893a0 /src/ark/lightning.js | |
| parent | b7a8fc0254d6e08013e3672b8da09b508057ec93 (diff) | |
| download | coinosv3-5abf76764c445b742a50080ebb97c313531d5962.tar.gz coinosv3-5abf76764c445b742a50080ebb97c313531d5962.zip | |
Pay what the route costs: sends quote the network fee up front (zero between coinos wallets), lock exactly that, and a refunded miss retries with one more sat
Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014tE4U5nEjGTQy8PwYqamfv
Diffstat (limited to 'src/ark/lightning.js')
| -rw-r--r-- | src/ark/lightning.js | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/ark/lightning.js b/src/ark/lightning.js index bbfe958..dab2d6d 100644 --- a/src/ark/lightning.js +++ b/src/ark/lightning.js @@ -92,6 +92,19 @@ export function lnSendFee(amountSat, fees, inputs, tip) { export const lnReceiveFee = (amountSat, fees) => (fees.baseFeeSat || 0) + Math.ceil((amountSat * (fees.ppm || 0)) / 1_000_000); +// Ask the quote service what the network will charge to deliver this payment +// (it runs askrene against the ASP's own CLN). The wallet locks +// amount + schedule fee + this on the HTLC and the server hands the whole +// surplus to CLN as the routing budget, so this number is the user's entire +// network cost — 0 between wallets on this ASP and to direct peers. +export async function fetchLnRouteFee(quoteUrl, invoice, amountSat) { + const r = await fetch(`${quoteUrl}?invoice=${encodeURIComponent(invoice)}&amount_msat=${amountSat * 1000}`); + if (!r.ok) throw new Error(`quote failed: ${r.status}`); + const d = await r.json(); + if (d.error) throw new Error(d.error); + return d.feeSat | 0; +} + // --------------------------------------------------------------------------- // pay (HTLC-out) // --------------------------------------------------------------------------- |
