trident_sdk/
types.rs

1use alloy_primitives::{Address, U256};
2use alloy_provider::network::Ethereum;
3use alloy_provider::{Network, Provider};
4use std::marker::PhantomData;
5use tides_core_types::TidesChainId;
6use trident_types::core::FixedBytes32;
7
8pub struct DepositInEvmChainWithApprovalResponse<N: Network = Ethereum> {
9    pub approval_tx_receipt: N::ReceiptResponse,
10    pub deposit_tx_receipt: N::ReceiptResponse,
11}
12
13/// Represents a spend request where the balance is located in an EVM chain, and
14/// the spend is done on a destination chain which is also an EVM chain.
15#[derive(Debug, Clone, Eq, PartialEq)]
16pub struct EvmToEvmSpendRequest<
17    'a,
18    S: alloy_signer::Signer + ?Sized,
19    DP: Provider<DN> + ?Sized,
20    DN: Network = Ethereum,
21> {
22    pub source_signer: &'a S,
23    pub source_chain_id: TidesChainId,
24    pub source_token: Address,
25    pub source_token_amount: U256,
26    /// Optional source fees. Otherwise, pick the one suggested by the attester.
27    pub source_max_fees: Option<U256>,
28
29    pub destination_provider: &'a DP,
30    pub destination_chain_id: TidesChainId,
31    pub destination_recipient: Address,
32
33    /// Can be kept empty. It's useful only in case the source token maps to multiple
34    /// destination tokens (eg: eth-USDT mapping to arbitrum-USDT & arbitrum-USDT0)
35    pub destination_token: Option<Address>,
36
37    /// Optional callback.
38    pub destination_callback: Option<EvmDestinationCallback>,
39
40    /// Optional caller, if not provided defaults to source_signer.address().
41    pub destination_caller: Option<Address>,
42
43    /// Optional spend intent max validity height, if not provided the client will infer it.
44    pub max_block_height: Option<u64>,
45
46    /// Optional salt, if not provided the client will generate one.
47    pub salt: Option<FixedBytes32>,
48
49    /// Optional salt, otherwise will be inferred.
50    pub _phantoms: PhantomData<DN>,
51}
52
53impl<'a, S, DP, DN> EvmToEvmSpendRequest<'a, S, DP, DN>
54where
55    DP: Provider<DN>,
56    S: alloy_signer::Signer + ?Sized,
57    DN: Network,
58{
59    pub fn new(
60        source_signer: &'a S,
61        source_chain_id: TidesChainId,
62        source_token: Address,
63        source_token_amount: U256,
64        destination_provider: &'a DP,
65        destination_chain_id: TidesChainId,
66        destination_recipient: Address,
67    ) -> Self {
68        Self {
69            source_signer,
70            source_chain_id,
71            source_token,
72            source_token_amount,
73            source_max_fees: None,
74            destination_provider,
75            destination_chain_id,
76            destination_recipient,
77            destination_token: None,
78            destination_callback: None,
79            destination_caller: None,
80            max_block_height: None,
81            salt: None,
82            _phantoms: PhantomData,
83        }
84    }
85
86    pub fn with_destination_token(mut self, destination_token: Address) -> Self {
87        self.destination_token = Some(destination_token);
88        self
89    }
90
91    pub fn with_destination_callback(
92        mut self,
93        destination_callback: EvmDestinationCallback,
94    ) -> Self {
95        self.destination_callback = Some(destination_callback);
96        self
97    }
98
99    /// Defines the chain's source fees.
100    pub fn with_source_chain_max_fees(mut self, max_fees: U256) -> Self {
101        self.source_max_fees = Some(max_fees);
102        self
103    }
104
105    /// If provided, sets the spend intent's max validity height.
106    pub fn with_max_block_height(mut self, max_block_height: u64) -> Self {
107        self.max_block_height = Some(max_block_height);
108        self
109    }
110
111    pub fn with_destination_caller(mut self, destination_caller: Address) -> Self {
112        self.destination_caller = Some(destination_caller);
113        self
114    }
115
116    pub fn with_salt(mut self, salt: impl Into<FixedBytes32>) -> Self {
117        self.salt = Some(salt.into());
118        self
119    }
120}
121
122/// TODO: implement https://github.com/tides-protocol/tides-core/issues/72
123#[derive(Clone, Debug, Eq, PartialEq)]
124pub struct EvmDestinationCallback;
125
126impl EvmDestinationCallback {
127    pub(crate) fn to_vec(&self) -> Vec<u8> {
128        Vec::new()
129    }
130}
131
132#[derive(Debug, Clone)]
133pub struct EvmToEvmSpendResponse<N: Network = Ethereum> {
134    pub destination_token: Address,
135    pub applied_fees: U256,
136    pub max_block_height: u64,
137    pub delivery_tx_receipt: N::ReceiptResponse,
138}