Skip to content

Commit 47e85b8

Browse files
committed
mobile/swaps: use receive amount to back-calculate claim tx fee rate
1 parent b79f32c commit 47e85b8

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

mobile/swaps.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func CreateClaimTransaction(endpoint string, id string, claimLeaf string, refund
6666
return nil
6767
}
6868

69-
func CreateReverseClaimTransaction(endpoint string, id string, claimLeaf string, refundLeaf string, privateKey string, servicePubKey string, preimageHex string, transactionHex string, lockupAddress string, destinationAddress string, feeRate int32, isTestnet bool) error {
69+
func CreateReverseClaimTransaction(endpoint string, id string, claimLeaf string, refundLeaf string, privateKey string, servicePubKey string, preimageHex string, transactionHex string, lockupAddress string, destinationAddress string, feeRate int32, receiveAmount int64, isTestnet bool) error {
7070
var toCurrency = boltz.CurrencyBtc
7171
var network *boltz.Network
7272
if isTestnet {
@@ -112,7 +112,7 @@ func CreateReverseClaimTransaction(endpoint string, id string, claimLeaf string,
112112
return fmt.Errorf("Error constructing lockup tx %s", err)
113113
}
114114

115-
vout, _, err := lockupTransaction.FindVout(network, lockupAddress)
115+
vout, inputValue, err := lockupTransaction.FindVout(network, lockupAddress)
116116
if err != nil {
117117
return fmt.Errorf("Error finding vout %s", err)
118118
}
@@ -122,7 +122,16 @@ func CreateReverseClaimTransaction(endpoint string, id string, claimLeaf string,
122122
return fmt.Errorf("Error decoding preimage hex string: %w", err)
123123
}
124124

125-
satPerVbyte := float64(feeRate)
125+
var satPerVbyte float64
126+
if receiveAmount > 0 && inputValue > uint64(receiveAmount) {
127+
// Use fee budget approach: back-calculate the rate from the desired
128+
// receive amount so the claim tx output matches exactly.
129+
// 111 vbytes is the cooperative Taproot claim size estimate.
130+
feeBudget := inputValue - uint64(receiveAmount)
131+
satPerVbyte = float64(feeBudget) / 111.0
132+
} else {
133+
satPerVbyte = float64(feeRate)
134+
}
126135
claimTransaction, _, err := boltz.ConstructTransaction(
127136
network,
128137
boltz.CurrencyBtc,

0 commit comments

Comments
 (0)