Skip to content

fix: handle dust change in max transfer to spending#748

Merged
ovitrif merged 13 commits intomasterfrom
fix/dust-on-max-transfer
Feb 12, 2026
Merged

fix: handle dust change in max transfer to spending#748
ovitrif merged 13 commits intomasterfrom
fix/dust-on-max-transfer

Conversation

@jvsena42
Copy link
Member

@jvsena42 jvsena42 commented Jan 29, 2026

Fixes #745

This PR fixes the "insufficient funds" error that occurs when transferring the maximum balance to spending.

Description

When users tried to transfer their full on-chain balance to Lightning (spending), they would sometimes encounter an "insufficient funds" error even though they had enough sats. This happened because:

  1. Fee estimation mismatch - The LSP fee was estimated using maxSendable amount, but order creation uses a different clientBalance value. Since lspBalance depends on clientBalanceSat, this caused off-by-few-sats discrepancies.

  2. Dust change handling - When the remaining change after the transfer would be below the dust limit (546 sats), the transaction would fail because Bitcoin nodes reject dust outputs.

Changes:

  • Implements two-pass fee estimation to match actual order creation logic
  • Adds dust detection that automatically uses sendAll when remaining change would be below dust limit

Reference: iOS fix PR #416

Preview

Screen_recording_20260129_085609.webm
not-dust.webm

QA Notes

1. MAX transfer to spending

  1. Have on-chain balance (e.g., 5000 sats)
  2. Go to Transfer > To Spending
  3. Press MAX button
  4. Tap Continue
  5. Verify amounts add up correctly on confirm screen
  6. Swipe to transfer
  7. Verify transfer succeeds without "Insufficient funds" error

2. Near-dust change scenarios

  1. Set up a balance where MAX transfer would leave 500-600 sats change
  2. Transfer MAX to spending
  3. Verify sendAll is used (no dust output created)

3. Regression - Partial transfers

  1. Transfer a partial amount (not MAX) to spending
  2. Verify transfer works normally
  3. Verify remaining on-chain balance is correct

@jvsena42 jvsena42 self-assigned this Jan 29, 2026
@claude

This comment has been minimized.

@jvsena42 jvsena42 requested a review from ovitrif January 29, 2026 12:08
@claude

This comment has been minimized.

@claude

This comment has been minimized.

@jvsena42 jvsena42 marked this pull request as draft February 9, 2026 10:27
@jvsena42

This comment was marked as resolved.

@jvsena42 jvsena42 marked this pull request as ready for review February 10, 2026 10:20
@claude

This comment has been minimized.

claude[bot]

This comment was marked as resolved.

ovitrif

This comment was marked as resolved.

@jvsena42 jvsena42 marked this pull request as draft February 12, 2026 11:00
@jvsena42 jvsena42 marked this pull request as ready for review February 12, 2026 12:06
@jvsena42 jvsena42 requested a review from ovitrif February 12, 2026 12:06
@jvsena42 jvsena42 marked this pull request as draft February 12, 2026 12:09
@jvsena42 jvsena42 marked this pull request as ready for review February 12, 2026 12:12
@jvsena42
Copy link
Member Author

Tests after refactor. Couldn't use 5k sats because it was below the min allowed after fees

Screen_recording_20260212_090344.webm
Screen_recording_20260212_091045.webm

Copy link
Collaborator

@ovitrif ovitrif left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utAck

LGTM :shipit:

@ovitrif ovitrif merged commit d7fb638 into master Feb 12, 2026
16 checks passed
@ovitrif ovitrif deleted the fix/dust-on-max-transfer branch February 12, 2026 15:50
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.

MAX transfer to spending causes insufficient error

2 participants