spark_rust/wallet/handlers/
fees.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{
4    error::SparkSdkError, signer::traits::SparkSigner,
5    wallet::internal_handlers::traits::ssp::SspInternalHandlers, SparkSdk,
6};
7
8/// Fee estimation data returned by Lightspark's Spark Service Provider. This is a generic struct that is used for Lightning, Cooperative Exit, and Leaves Swap fee estimations.
9#[derive(Debug, Serialize, Deserialize)]
10pub struct SparkFeeEstimate {
11    /// The estimated fees in sats.
12    pub fees: u64,
13}
14
15impl<S: SparkSigner + Send + Sync + Clone + 'static> SparkSdk<S> {
16    pub async fn get_lightning_receive_fee_estimate(
17        &self,
18        amount: u64,
19    ) -> Result<SparkFeeEstimate, SparkSdkError> {
20        self.get_lightning_receive_fee_estimate_with_ssp(amount)
21            .await
22    }
23
24    pub async fn get_lightning_send_fee_estimate(
25        &self,
26        invoice: String,
27    ) -> Result<SparkFeeEstimate, SparkSdkError> {
28        self.get_lightning_send_fee_estimate_with_ssp(invoice).await
29    }
30
31    pub async fn get_cooperative_exit_fee_estimate(
32        &self,
33        leaf_ids: Vec<String>,
34        on_chain_address: String,
35    ) -> Result<SparkFeeEstimate, SparkSdkError> {
36        self.get_cooperative_exit_fee_estimate_with_ssp(leaf_ids, on_chain_address)
37            .await
38    }
39
40    pub async fn get_leaves_swap_fee_estimate(
41        &self,
42        total_amount_sats: u64,
43    ) -> Result<SparkFeeEstimate, SparkSdkError> {
44        self.get_leaves_swap_fee_estimate_with_ssp(total_amount_sats)
45            .await
46    }
47}