Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Commit 0736541

Browse files
Merge pull request #1008 from MutinyWallet/fix-fedimint-sweep-max-fee
Fix the fedimint sweep fee for max balance
2 parents 51bb7b9 + 83bd1eb commit 0736541

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

mutiny-core/src/federation.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ impl<S: MutinyStorage> FederationClient<S> {
571571
}
572572
}
573573
};
574-
inv.fees_paid = Some(outgoing_payment.fee.sats_round_down());
574+
inv.fees_paid = Some(sats_round_up(&outgoing_payment.fee));
575575

576576
self.maybe_update_after_checking_fedimint(inv.clone())
577577
.await?;
@@ -617,6 +617,10 @@ impl<S: MutinyStorage> FederationClient<S> {
617617
}
618618
}
619619

620+
fn sats_round_up(amount: &Amount) -> u64 {
621+
Amount::from_msats(amount.msats + 999).sats_round_down()
622+
}
623+
620624
// Get a preferred gateway from a federation
621625
fn get_gateway_preference(
622626
gateways: Vec<fedimint_ln_common::LightningGatewayAnnouncement>,

mutiny-core/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,7 @@ impl<S: MutinyStorage> MutinyWallet<S> {
12321232
);
12331233

12341234
let fees = fedimint_client.gateway_fee().await?;
1235+
// FIXME: this is still producing off by one. check round down
12351236
let amt = max_spendable_amount(current_balance, &fees)
12361237
.map_or(Err(MutinyError::InsufficientBalance), Ok)?;
12371238
log_debug!(self.logger, "max spendable: {}", amt);
@@ -1276,9 +1277,10 @@ impl<S: MutinyStorage> MutinyWallet<S> {
12761277
);
12771278
}
12781279

1280+
let total_fees = first_invoice_res.fees_paid.unwrap_or(0) + fee;
12791281
Ok(FedimintSweepResult {
1280-
amount: first_invoice_amount,
1281-
fees: Some(first_invoice_res.fees_paid.unwrap_or(0) + fee),
1282+
amount: current_balance - total_fees,
1283+
fees: Some(total_fees),
12821284
})
12831285
}
12841286

0 commit comments

Comments
 (0)