Skip to content

Commit

Permalink
Merge pull request #1290 from getlipa/fix/create-swaps-with-long-live…
Browse files Browse the repository at this point in the history
…d-fee-params-as-default

Default to long lived lsp fee params for swaps
  • Loading branch information
gcomte authored Dec 3, 2024
2 parents 7241991 + e3422e5 commit 46324f1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
6 changes: 2 additions & 4 deletions src/onchain/channel_closes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ use breez_sdk_core::{
use perro::{ensure, invalid_input, MapToError};
use std::sync::Arc;

const TWO_WEEKS: u32 = 2 * 7 * 24 * 60 * 60;

pub struct ChannelClose {
support: Arc<Support>,
swap: Arc<Swap>,
Expand Down Expand Up @@ -196,8 +194,8 @@ impl ChannelClose {
lsp_fee_params: Option<OpeningFeeParams>,
) -> std::result::Result<String, RedeemOnchainError> {
let lsp_fee_params = lsp_fee_params.unwrap_or(
self.support
.query_lsp_fee_params(Some(TWO_WEEKS))
self.swap
.query_lsp_fee_params()
.map_err(|e| RedeemOnchainError::ServiceConnectivity { err: e.to_string() })?,
);

Expand Down
22 changes: 18 additions & 4 deletions src/onchain/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,27 @@ impl Swap {
///
/// Parameters:
/// * `lsp_fee_params` - the lsp fee parameters to be used if a new channel needs to
/// be opened. Can be obtained using [`LightningNode::calculate_lsp_fee`](crate::LightningNode::calculate_lsp_fee).
/// be opened. Can be obtained using [`Swap::calculate_lsp_fee_for_amount`].
///
/// Requires network: **yes**
pub fn create(
&self,
lsp_fee_params: Option<OpeningFeeParams>,
) -> std::result::Result<SwapAddressInfo, ReceiveOnchainError> {
let lsp_fee_params = match lsp_fee_params {
Some(param) => param,
None => self.query_lsp_fee_params().map_err(|_e| {
ReceiveOnchainError::ServiceConnectivity {
err: "Could not retrieve lsp fee params".to_string(),
}
})?,
};
let swap_info = self
.support
.rt
.handle()
.block_on(self.support.sdk.receive_onchain(ReceiveOnchainRequest {
opening_fee_params: lsp_fee_params,
opening_fee_params: Some(lsp_fee_params),
}))?;
let rate = self.support.get_exchange_rate();

Expand Down Expand Up @@ -199,8 +207,7 @@ impl Swap {
sats_per_vbyte: u32,
lsp_fee_param: Option<OpeningFeeParams>,
) -> Result<String> {
let lsp_fee_param =
lsp_fee_param.unwrap_or(self.support.query_lsp_fee_params(Some(TWO_WEEKS))?);
let lsp_fee_param = lsp_fee_param.unwrap_or(self.query_lsp_fee_params()?);

let swap_address_info = self
.create(Some(lsp_fee_param.clone()))
Expand Down Expand Up @@ -292,6 +299,13 @@ impl Swap {
.collect())
}

/// Query the long living LSP fee params that the LSP offers.
///
/// Requires network: **yes**
pub fn query_lsp_fee_params(&self) -> Result<OpeningFeeParams> {
self.support.query_lsp_fee_params(Some(TWO_WEEKS))
}

/// Calculate the actual LSP fee for the given amount of a swap.
/// If the already existing inbound capacity is enough, no new channel is required.
///
Expand Down

0 comments on commit 46324f1

Please sign in to comment.