Add zero-amount Receive Chain Swap (#538)

Add support for Zero-Amount Receive Chain Swaps
This commit is contained in:
ok300
2024-12-09 16:10:52 +00:00
committed by GitHub
parent 790dfa91be
commit cfc883ae00
20 changed files with 571 additions and 60 deletions

View File

@@ -8,6 +8,7 @@ use boltz_client::{
elements::secp256k1_zkp::{MusigPartialSignature, MusigPubNonce},
network::{electrum::ElectrumConfig, Chain},
util::secrets::Preimage,
Amount,
};
use log::info;
use url::Url;
@@ -179,6 +180,23 @@ impl Swapper for BoltzSwapper {
Ok((pair_outgoing, pair_incoming))
}
fn get_zero_amount_chain_swap_quote(&self, swap_id: &str) -> Result<Amount, PaymentError> {
self.client
.get_quote(swap_id)
.map(|r| Amount::from_sat(r.amount))
.map_err(Into::into)
}
fn accept_zero_amount_chain_swap_quote(
&self,
swap_id: &str,
server_lockup_sat: u64,
) -> Result<(), PaymentError> {
self.client
.accept_quote(swap_id, server_lockup_sat)
.map_err(Into::into)
}
/// Get a submarine pair information
fn get_submarine_pairs(&self) -> Result<Option<SubmarinePair>, PaymentError> {
Ok(self.client.get_submarine_pairs()?.get_lbtc_to_btc_pair())

View File

@@ -8,6 +8,7 @@ use boltz_client::{
SubmarineClaimTxResponse, SubmarinePair,
},
network::Chain,
Amount,
};
use tokio::sync::{broadcast, watch};
@@ -40,6 +41,19 @@ pub trait Swapper: Send + Sync {
/// Get the current rate, limits and fees for both swap directions
fn get_chain_pairs(&self) -> Result<(Option<ChainPair>, Option<ChainPair>), PaymentError>;
/// Get the quote for a Zero-Amount Receive Chain Swap.
///
/// If the user locked-up funds in the valid range this will return that amount. In all other
/// cases, this will return an error.
fn get_zero_amount_chain_swap_quote(&self, swap_id: &str) -> Result<Amount, PaymentError>;
/// Accept a specific quote for a Zero-Amount Receive Chain Swap
fn accept_zero_amount_chain_swap_quote(
&self,
swap_id: &str,
server_lockup_sat: u64,
) -> Result<(), PaymentError>;
/// Get a submarine pair information
fn get_submarine_pairs(&self) -> Result<Option<SubmarinePair>, PaymentError>;