From 79252576d1bd24bc74fe1b7fc9cc3d4d68a1c8a0 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 11 Mar 2026 23:01:00 -0700 Subject: try to cpfp piggyback on in flight withdrawals --- lib/payments.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'lib/payments.ts') diff --git a/lib/payments.ts b/lib/payments.ts index cc5551ce..d936314b 100644 --- a/lib/payments.ts +++ b/lib/payments.ts @@ -849,7 +849,7 @@ export const sendOnchain = async (params) => { } } - fee = totalIn - total; + fee = totalIn - total - (p2aVout >= 0 ? P2A_VALUE : 0); } const amount = total - change; @@ -1219,19 +1219,16 @@ export const build = async ({ aid, amount, address, feeRate, subtract, user }) = let bumpReserve = 0; let parentVsize = 0; - // Check if confirmed UTXOs can cover this send — if not, fall back to CPFP+send + // Piggyback on an unconfirmed parent via CPFP if one exists if (isBitcoin) { - const confirmedUtxos = await node.listUnspent(1); - const confirmedTotal = confirmedUtxos.reduce((sum, u) => sum + sats(u.amount), 0); - if (confirmedTotal < amount + P2A_VALUE) { - const balance = await getBalance(aid); + try { let ourfee = Math.round(amount * config.fee[type]); const creditBal = await getCredit(aid, type); const covered = Math.min(creditBal, ourfee); ourfee -= covered; const cpfp = await buildCpfpSend({ address, amount: amount - ourfee, feeRate, fees }); return { ...cpfp, feeRate, ourfee, fees, inputs: [], subtract, signed: true }; - } + } catch {} } try { -- cgit v1.2.3