Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/services/main/adminManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion src/services/main/watchdog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}

Expand Down
Loading