spark_rust/wallet/internal_handlers/traits/
ssp.rs

1use crate::{
2    error::SparkSdkError,
3    signer::traits::SparkSigner,
4    wallet::handlers::{cooperative_exit::CoopExitRequestId, fees::SparkFeeEstimate},
5};
6use bitcoin::{Address, Network, Transaction};
7use serde::{Deserialize, Serialize};
8use tonic::async_trait;
9
10#[derive(Debug, Serialize, Deserialize)]
11pub(crate) struct SwapLeaf {
12    pub(crate) leaf_id: String,
13    pub(crate) raw_unsigned_refund_transaction: String,
14    pub(crate) adaptor_added_signature: String,
15}
16
17// TODO: standardize
18#[derive(Debug, Serialize, Deserialize)]
19pub(crate) struct CreateInvoiceVariables {
20    network: String,
21    amount_sats: u64,
22    payment_hash: String,
23    memo: String,
24    expiry_secs: u64,
25}
26
27#[derive(Debug, Serialize, Deserialize)]
28pub(crate) struct InitiateCooperativeExitResponse {
29    pub(crate) request_id: CoopExitRequestId,
30    pub(crate) connector_tx: Transaction,
31}
32
33#[async_trait]
34pub(crate) trait SspInternalHandlers<S: SparkSigner + Send + Sync> {
35    async fn create_invoice_with_ssp(
36        &self,
37        amount_sats: u64,
38        payment_hash: String,
39        expiry_secs: i32,
40        memo: Option<String>,
41        network: Network,
42    ) -> Result<(String, i64), SparkSdkError>;
43
44    async fn request_swap_leaves_with_ssp(
45        &self,
46        adaptor_pubkey: String,
47        total_amount_sats: u64,
48        target_amount_sats: u64,
49        fee_sats: u64,
50        user_leaves: Vec<SwapLeaf>,
51    ) -> Result<(String, Vec<SwapLeaf>), SparkSdkError>;
52
53    async fn complete_leaves_swap_with_ssp(
54        &self,
55        adaptor_secret_key: String,
56        user_outbound_transfer_external_id: String,
57        leaves_swap_request_id: String,
58    ) -> Result<String, SparkSdkError>;
59
60    async fn initiate_cooperative_exit_with_ssp(
61        &self,
62        leaf_external_ids: Vec<String>,
63        address: &Address,
64    ) -> Result<InitiateCooperativeExitResponse, SparkSdkError>;
65
66    async fn complete_cooperative_exit_with_ssp(
67        &self,
68        user_outbound_transfer_external_id: String,
69        coop_exit_request_id: CoopExitRequestId,
70    ) -> Result<CoopExitRequestId, SparkSdkError>;
71
72    async fn request_lightning_send_with_ssp(
73        &self,
74        encoded_invoice: String,
75        idompotency_key: String,
76    ) -> Result<String, SparkSdkError>;
77
78    async fn get_lightning_receive_fee_estimate_with_ssp(
79        &self,
80        amount_sats: u64,
81    ) -> Result<SparkFeeEstimate, SparkSdkError>;
82
83    async fn get_lightning_send_fee_estimate_with_ssp(
84        &self,
85        invoice: String,
86    ) -> Result<SparkFeeEstimate, SparkSdkError>;
87
88    async fn get_cooperative_exit_fee_estimate_with_ssp(
89        &self,
90        leaf_external_ids: Vec<String>,
91        on_chain_address: String,
92    ) -> Result<SparkFeeEstimate, SparkSdkError>;
93
94    async fn get_leaves_swap_fee_estimate_with_ssp(
95        &self,
96        total_amount_sats: u64,
97    ) -> Result<SparkFeeEstimate, SparkSdkError>;
98}