From 4ba2b07418cf9e9d801afc0dfc07b5642fdf2412 Mon Sep 17 00:00:00 2001 From: David Caseria Date: Fri, 20 Sep 2024 18:31:14 -0400 Subject: [PATCH] Fix melt change amount --- crates/cdk/src/wallet/mod.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/cdk/src/wallet/mod.rs b/crates/cdk/src/wallet/mod.rs index f77c1021..e89f13a8 100644 --- a/crates/cdk/src/wallet/mod.rs +++ b/crates/cdk/src/wallet/mod.rs @@ -1391,6 +1391,11 @@ impl Wallet { return Err(Error::UnknownQuote); }; + let proofs_total = Amount::try_sum(proofs.iter().map(|p| p.amount))?; + if proofs_total < quote_info.amount + quote_info.fee_reserve { + return Err(Error::InsufficientFunds); + } + let ys = proofs .iter() .map(|p| p.y()) @@ -1410,7 +1415,7 @@ impl Wallet { active_keyset_id, count, self.xpriv, - quote_info.fee_reserve, + proofs_total - quote_info.amount, )?; let melt_response = self