Skip to content

feat: add calculate send all fee for onchain#68

Merged
ovitrif merged 2 commits intomainfrom
feat/calculate-send-all-fee
Mar 2, 2026
Merged

feat: add calculate send all fee for onchain#68
ovitrif merged 2 commits intomainfrom
feat/calculate-send-all-fee

Conversation

@ben-kaufman
Copy link
Copy Markdown

@ben-kaufman ben-kaufman commented Mar 2, 2026

Summary

  • Add OnchainPayment::calculate_send_all_fee() as the fee-estimation counterpart of
    send_all_to_address(), allowing callers to preview the mining fee for a drain transaction
    before broadcasting.
  • Supports retain_reserves flag to match send_all_to_address behavior (anchor channel
    reserve handling).
  • Add integration tests validating estimated fee matches actual fee after broadcast.

Motivation

calculate_total_fee() fails when called with amount_sats equal to the total UTXO value,
because the internal ExactRetainingReserve validation adds a fee buffer that exceeds the
available value. The existing InsufficientFunds fallback in calculate_total_fee also fails
because it forwards the caller's specific utxos_to_spend, which conflicts with BDK's
drain_wallet() mode.

calculate_send_all_fee solves this by directly using AllRetainingReserve /
AllDrainingReserve with utxos_to_spend: None, matching how send_all_to_address builds
the actual transaction.

Integration

Test plan

  • calculate_send_all_fee_matches_actual — funds a node, estimates fee, sends via
    send_all_to_address, asserts estimated fee equals actual fee
  • onchain_send_all_retains_reserve — verifies retain vs drain fee estimation with open
    anchor channels
  • Validates error cases: zero balance, wrong-network address
  • rely on CI + e2e in bitkit-ios and bitkit-android

Copy link
Copy Markdown
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.

LGTM 👏🏻

Thanks for adding the tests, makes it much better to validate and learn about the setup at the same time.

Plus it proves older changes as well as the new changes work as expected.

Comment thread tests/integration_tests_rust.rs
…ll-fee

# Conflicts:
#	Package.swift
#	bindings/python/pyproject.toml
@ovitrif ovitrif changed the title feat: add OnchainPayment::calculate_send_all_fee() feat: add calculate send all fee for onchain Mar 2, 2026
@ovitrif ovitrif merged commit 3f4c563 into main Mar 2, 2026
1 check passed
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.

2 participants