diff --git a/libs/sdk-core/src/breez_services.rs b/libs/sdk-core/src/breez_services.rs index f387d1b7f..3a5282157 100644 --- a/libs/sdk-core/src/breez_services.rs +++ b/libs/sdk-core/src/breez_services.rs @@ -1,3 +1,4 @@ +use std::cmp::min; use std::fs::OpenOptions; use std::io::Write; use std::str::FromStr; @@ -841,6 +842,8 @@ impl BreezServices { /// minus the expected fees. /// This is possible since the route to the swapper node is known in advance and is expected /// to consist of maximum 3 hops. + /// + /// Deprecated. Please use [BreezServices::onchain_payment_limits] instead. pub async fn max_reverse_swap_amount(&self) -> SdkResult { // fetch the last hop hints from the swapper let last_hop = self.btc_send_swapper.last_hop_for_payment().await?; @@ -921,10 +924,20 @@ impl BreezServices { pub async fn onchain_payment_limits(&self) -> SdkResult { let fee_info = self.btc_send_swapper.fetch_reverse_swap_fees().await?; - Ok(OnchainPaymentLimitsResponse { - min_sat: fee_info.min, - max_sat: fee_info.max, - }) + debug!("Reverse swap pair info: {fee_info:?}"); + let max_amt_current_channels = self.max_reverse_swap_amount().await?; + debug!("Max send amount possible with current channels: {max_amt_current_channels:?}"); + + let composite_max = min(fee_info.max, max_amt_current_channels.total_sat); + let (min_sat, max_sat) = match composite_max < fee_info.min { + true => { + warn!("Reverse swap max < min, setting limits to zero because no reverse swap is possible"); + (0, 0) + } + false => (fee_info.min, composite_max), + }; + + Ok(OnchainPaymentLimitsResponse { min_sat, max_sat }) } /// Supersedes [BreezServices::fetch_reverse_swap_fees] diff --git a/libs/sdk-core/src/models.rs b/libs/sdk-core/src/models.rs index 9a183bc81..9219a6e41 100644 --- a/libs/sdk-core/src/models.rs +++ b/libs/sdk-core/src/models.rs @@ -1014,7 +1014,13 @@ pub struct PrepareOnchainPaymentRequest { #[derive(Serialize)] pub struct OnchainPaymentLimitsResponse { + /// Minimum amount that can be sent. This value is influenced by + /// - what can be sent given the available channels and balance + /// - the lower limit of what the reverse swap service accepts as a send amount pub min_sat: u64, + /// Maximum amount that can be sent. This value is influenced by + /// - what can be sent given the available channels and balance + /// - the upper limit of what the reverse swap service accepts as a send amount pub max_sat: u64, } diff --git a/libs/sdk-flutter/lib/bridge_generated.dart b/libs/sdk-flutter/lib/bridge_generated.dart index 70d7c1d29..15a126241 100644 --- a/libs/sdk-flutter/lib/bridge_generated.dart +++ b/libs/sdk-flutter/lib/bridge_generated.dart @@ -1177,7 +1177,14 @@ class NodeState { } class OnchainPaymentLimitsResponse { + /// Minimum amount that can be sent. This value is influenced by + /// - what can be sent given the available channels and balance + /// - the lower limit of what the reverse swap service accepts as a send amount final int minSat; + + /// Maximum amount that can be sent. This value is influenced by + /// - what can be sent given the available channels and balance + /// - the upper limit of what the reverse swap service accepts as a send amount final int maxSat; const OnchainPaymentLimitsResponse({