From 091c0ced8b81d2e8f53ff4fbb28331a802afdf71 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Thu, 4 Apr 2024 14:01:33 +0000 Subject: [PATCH] Bump boltz-client, fix fee calculation (#68) * Bump boltz-client, fix fee calculation * Cargo fmt --- cli/Cargo.lock | 2 +- lib/Cargo.lock | 2 +- lib/Cargo.toml | 4 +--- lib/src/wallet.rs | 15 +++++++-------- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/cli/Cargo.lock b/cli/Cargo.lock index 01f81aa..4577c4a 100644 --- a/cli/Cargo.lock +++ b/cli/Cargo.lock @@ -286,7 +286,7 @@ dependencies = [ [[package]] name = "boltz-client" version = "0.1.3" -source = "git+https://github.com/hydra-yse/boltz-rust?branch=yse-breez-latest#ff836fe766421738e7f05cbed8a2fbe65245ef03" +source = "git+https://github.com/SatoshiPortal/boltz-rust?rev=e55b8439f3311be7fcd18ec14a5747d0f3dbd74f#e55b8439f3311be7fcd18ec14a5747d0f3dbd74f" dependencies = [ "bip39", "bitcoin 0.31.1", diff --git a/lib/Cargo.lock b/lib/Cargo.lock index 04f9518..fc282b2 100644 --- a/lib/Cargo.lock +++ b/lib/Cargo.lock @@ -238,7 +238,7 @@ dependencies = [ [[package]] name = "boltz-client" version = "0.1.3" -source = "git+https://github.com/hydra-yse/boltz-rust?branch=yse-breez-latest#ff836fe766421738e7f05cbed8a2fbe65245ef03" +source = "git+https://github.com/SatoshiPortal/boltz-rust?rev=e55b8439f3311be7fcd18ec14a5747d0f3dbd74f#e55b8439f3311be7fcd18ec14a5747d0f3dbd74f" dependencies = [ "bip39", "bitcoin 0.31.1", diff --git a/lib/Cargo.toml b/lib/Cargo.toml index facd0d7..82d2d8c 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -10,9 +10,7 @@ crate-type = ["staticlib", "cdylib", "lib"] [dependencies] anyhow = "1.0.80" bip39 = { version = "2.0.0", features = ["serde"] } -#boltz-client = "0.1.2" -#boltz-client = { git = "https://github.com/SatoshiPortal/boltz-rust", rev = "61592bcf0ad2e9bd68c593bc87c5a487805b6d00" } -boltz-client = { git = "https://github.com/hydra-yse/boltz-rust", branch = "yse-breez-latest" } +boltz-client = { git = "https://github.com/SatoshiPortal/boltz-rust", rev = "e55b8439f3311be7fcd18ec14a5747d0f3dbd74f" } log = "0.4.20" lwk_common = "0.3.0" lwk_signer = "0.3.0" diff --git a/lib/src/wallet.rs b/lib/src/wallet.rs index c3b3b38..50eaae3 100644 --- a/lib/src/wallet.rs +++ b/lib/src/wallet.rs @@ -305,17 +305,16 @@ impl Wallet { let (onchain_amount_sat, invoice_amount_sat) = match (req.onchain_amount_sat, req.invoice_amount_sat) { (Some(onchain_amount_sat), None) => { - // TODO Calculate correct fees, once these PRs are merged and published - // https://github.com/SatoshiPortal/boltz-rust/pull/31 - // https://github.com/SatoshiPortal/boltz-rust/pull/32 - - // TODO Until above is fixed, this is only an approximation (using onchain instead of invoice amount to calc. fees) - let fees_boltz = lbtc_pair.fees.reverse_boltz(onchain_amount_sat); let fees_lockup = lbtc_pair.fees.reverse_lockup(); let fees_claim = CLAIM_ABSOLUTE_FEES; // lbtc_pair.fees.reverse_claim_estimate(); - let fees_total = fees_boltz + fees_lockup + fees_claim; + let p = lbtc_pair.fees.percentage; - Ok((onchain_amount_sat, onchain_amount_sat + fees_total)) + let temp_recv_amt = onchain_amount_sat; + let invoice_amt_minus_service_fee = temp_recv_amt + fees_lockup + fees_claim; + let invoice_amount_sat = + (invoice_amt_minus_service_fee as f64 * 100.0 / (100.0 - p)).ceil() as u64; + + Ok((onchain_amount_sat, invoice_amount_sat)) } (None, Some(invoice_amount_sat)) => { let fees_boltz = lbtc_pair.fees.reverse_boltz(invoice_amount_sat);