From fcb7de1048dbbd15b3d9af9ef8595cf683d40b3f Mon Sep 17 00:00:00 2001 From: boufni95 Date: Tue, 28 Jul 2026 18:10:39 +0000 Subject: [PATCH] fix swap fees +miner fees --- src/services/main/adminManager.ts | 5 +++-- src/services/main/watchdog.ts | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/services/main/adminManager.ts b/src/services/main/adminManager.ts index dbde290dd..48bf7f5a7 100644 --- a/src/services/main/adminManager.ts +++ b/src/services/main/adminManager.ts @@ -320,9 +320,9 @@ export class AdminManager { this.swaps.PayInvoiceSwap("admin", req.swap_operation_id, req.sat_per_v_byte, async (addr, amt) => { const tx = await this.lnd.PayAddress(addr, amt, req.sat_per_v_byte, "", { useProvider: false, from: 'system' }) this.log("paid admin invoice swap", { swapOpId: req.swap_operation_id, txId: tx.txid }) - await this.storage.metricsStorage.AddRootOperation("chain_payment", tx.txid, amt, true) - // Fetch the full transaction hex for potential refunds + // Fetch the full transaction hex for potential refunds, and include miner fees + // in the root op so watchdog can fully neutralize the on-chain spend. let lockupTxHex: string | undefined let chainFeeSats = 0 try { @@ -333,6 +333,7 @@ export class AdminManager { this.log("Warning: Could not fetch transaction hex for refund purposes:", err.message) } + await this.storage.metricsStorage.AddRootOperation("chain_payment", tx.txid, amt + chainFeeSats, true) await this.storage.paymentStorage.SetInvoiceSwapTxId(req.swap_operation_id, tx.txid, chainFeeSats, lockupTxHex) this.log("saved admin swap txid", { swapOpId: req.swap_operation_id, txId: tx.txid }) res(tx.txid) diff --git a/src/services/main/watchdog.ts b/src/services/main/watchdog.ts index 663c93a1f..23cf481bf 100644 --- a/src/services/main/watchdog.ts +++ b/src/services/main/watchdog.ts @@ -143,7 +143,11 @@ export class Watchdog { const pb = await this.rugPullTracker.CheckProviderBalance() const providerBalance = pb.prevBalance || pb.balance const { newReceived, newSpent, pendingChange } = await this.handleRootOperations() - const opsTotal = newReceived + pendingChange - newSpent + // Root ops move LND without touching user balances. Neutralize them so watchdog + // doesn't treat admin spend/receive as unexplained drift vs users: + // LND already reflects the move, so add spent back and subtract received. + // pendingChange restores unconfirmed change outputs excluded from confirmed wallet balance. + const opsTotal = newSpent + pendingChange - newReceived return { totalExternal: totalLndBalance + providerBalance + feesPaidForLiquidity + opsTotal } }