Skip to content

fix: cap spending max at quoted lsp fee balance - #1179

Draft
jvsena42 wants to merge 2 commits into
masterfrom
fix/899-max-transfer-to-spending
Draft

fix: cap spending max at quoted lsp fee balance#1179
jvsena42 wants to merge 2 commits into
masterfrom
fix/899-max-transfer-to-spending

Conversation

@jvsena42

Copy link
Copy Markdown
Member

Fixes #899

This PR fixes the maximum Savings → Spending transfer failing with an insufficient funds error.

Description

Sizing a max transfer takes two LSP fee quotes. The first prices the whole available balance and yields the balance left after fees; the second re-prices at that lower balance and comes back cheaper, because the Blocktank service fee grows with the client balance. The spending max was then derived from the available balance minus that second, cheaper quote — producing a client balance higher than the one the quote actually priced.

The order built at that max therefore costs more than the user has. In the reported case the gap was a single satoshi: the order came to 265,727 against a spendable balance of 265,726. Confirming it fell past the drain shortcut and attempted an ordinary send it could not fund, surfacing the raw Lightning error.

The max is now capped at the balance the fee was quoted for, which is always affordable because the second quote never exceeds the first. The same sizing path backs the hardware wallet transfer limits, so both are covered.

Preview

QA Notes

Reproducing needs the whole on-chain balance transferred at once — the gap only appears at exactly Max.

Manual Tests

  • 1. Transfer → Spending → tap Max → Continue → swipe to confirm: the order funds instead of showing an insufficient funds error.
  • 2. regression: Transfer → Spending → tap ¼ → Continue → swipe to confirm: still funds normally.
  • 3. regression: on-chain balance above the LSP max channel size → Transfer → Spending: Max still caps at the LSP limit rather than collapsing to zero.
  • 4. Hardware wallet → Transfer To Spending → Max → Continue: the amount is accepted and the order funds.

Automated Checks

  • Unit test added in TransferViewModelTest.kt: reproduces the reported quote pair and asserts the max stays within what the order will cost. Confirmed it fails against master without the fix.
  • Local just compile, just test, and just lint all pass, with only pre-existing detekt findings in untouched files.

jvsena42 and others added 2 commits August 24, 2026 15:07
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Unable to transfer max amount to spending

1 participant