breez_sdk_liquid/swapper/
mod.rsuse anyhow::Result;
use boltz_client::{
boltz::{
ChainPair, CreateChainRequest, CreateChainResponse, CreateReverseRequest,
CreateReverseResponse, CreateSubmarineRequest, CreateSubmarineResponse, ReversePair,
SubmarineClaimTxResponse, SubmarinePair,
},
network::Chain,
Amount,
};
use maybe_sync::{MaybeSend, MaybeSync};
use mockall::automock;
use sdk_common::utils::Arc;
use tokio::sync::{broadcast, watch};
use crate::{
error::{PaymentError, SdkError},
prelude::{Direction, SendSwap, Swap, Utxo},
};
pub(crate) use subscription_handler::*;
pub(crate) mod boltz;
pub(crate) mod subscription_handler;
#[automock]
#[sdk_macros::async_trait]
pub trait Swapper: MaybeSend + MaybeSync {
async fn create_chain_swap(
&self,
req: CreateChainRequest,
) -> Result<CreateChainResponse, PaymentError>;
async fn create_send_swap(
&self,
req: CreateSubmarineRequest,
) -> Result<CreateSubmarineResponse, PaymentError>;
async fn get_chain_pair(&self, direction: Direction)
-> Result<Option<ChainPair>, PaymentError>;
async fn get_chain_pairs(&self)
-> Result<(Option<ChainPair>, Option<ChainPair>), PaymentError>;
async fn get_zero_amount_chain_swap_quote(&self, swap_id: &str) -> Result<Amount, SdkError>;
async fn accept_zero_amount_chain_swap_quote(
&self,
swap_id: &str,
server_lockup_sat: u64,
) -> Result<(), PaymentError>;
async fn get_submarine_pairs(&self) -> Result<Option<SubmarinePair>, PaymentError>;
async fn get_submarine_preimage(&self, swap_id: &str) -> Result<String, PaymentError>;
async fn get_send_claim_tx_details(
&self,
swap: &SendSwap,
) -> Result<SubmarineClaimTxResponse, PaymentError>;
async fn claim_send_swap_cooperative(
&self,
swap: &SendSwap,
claim_tx_response: SubmarineClaimTxResponse,
refund_address: &str,
) -> Result<(), PaymentError>;
async fn create_receive_swap(
&self,
req: CreateReverseRequest,
) -> Result<CreateReverseResponse, PaymentError>;
async fn get_reverse_swap_pairs(&self) -> Result<Option<ReversePair>, PaymentError>;
async fn create_claim_tx(
&self,
swap: Swap,
claim_address: Option<String>,
) -> Result<crate::prelude::Transaction, PaymentError>;
async fn estimate_refund_broadcast(
&self,
swap: Swap,
refund_address: &str,
fee_rate_sat_per_vb: Option<f64>,
is_cooperative: bool,
) -> Result<(u32, u64), SdkError>;
async fn create_refund_tx(
&self,
swap: Swap,
refund_address: &str,
utxos: Vec<Utxo>,
broadcast_fee_rate_sat_per_vb: Option<f64>,
is_cooperative: bool,
) -> Result<crate::prelude::Transaction, PaymentError>;
async fn broadcast_tx(&self, chain: Chain, tx_hex: &str) -> Result<String, PaymentError>;
async fn check_for_mrh(
&self,
invoice: &str,
) -> Result<Option<(String, boltz_client::bitcoin::Amount)>, PaymentError>;
async fn get_bolt12_invoice(
&self,
offer: &str,
amount_sat: u64,
) -> Result<String, PaymentError>;
}
pub trait SwapperStatusStream: MaybeSend + MaybeSync {
fn start(
self: Arc<Self>,
callback: Box<dyn SubscriptionHandler>,
shutdown: watch::Receiver<()>,
);
fn track_swap_id(&self, swap_id: &str) -> Result<()>;
fn subscribe_swap_updates(&self) -> broadcast::Receiver<boltz_client::boltz::SwapStatus>;
}
#[sdk_macros::async_trait]
pub(crate) trait ProxyUrlFetcher: MaybeSend + MaybeSync + 'static {
async fn fetch(&self) -> Result<&Option<String>>;
}