zksync_web3_rs/zks_wallet/requests/
deposit_request.rs

1use crate::types::{Address, U256};
2
3use crate::zks_utils::{
4    DEPOSIT_GAS_PER_PUBDATA_LIMIT, ETHER_L1_ADDRESS, RECOMMENDED_DEPOSIT_L1_GAS_LIMIT,
5    RECOMMENDED_DEPOSIT_L2_GAS_LIMIT,
6};
7
8fn default_gas_limit() -> U256 {
9    RECOMMENDED_DEPOSIT_L1_GAS_LIMIT.into()
10}
11
12fn default_l2_gas_limit() -> U256 {
13    RECOMMENDED_DEPOSIT_L2_GAS_LIMIT.into()
14}
15
16fn default_gas_per_pubdata_byte() -> U256 {
17    DEPOSIT_GAS_PER_PUBDATA_LIMIT.into()
18}
19
20#[derive(Clone, Debug)]
21pub struct DepositRequest {
22    pub amount: U256,
23    pub to: Option<Address>,
24    pub l2_gas_limit: U256,
25    pub gas_per_pubdata_byte: U256,
26    pub operator_tip: U256,
27    pub gas_price: Option<U256>,
28    pub gas_limit: U256,
29    pub token: Address,
30    pub bridge_address: Option<Address>,
31}
32
33impl DepositRequest {
34    pub fn new(amount: U256) -> Self {
35        Self {
36            amount,
37            to: None,
38            l2_gas_limit: default_l2_gas_limit(),
39            gas_per_pubdata_byte: default_gas_per_pubdata_byte(),
40            operator_tip: 0_i32.into(),
41            gas_price: None,
42            gas_limit: default_gas_limit(),
43            token: ETHER_L1_ADDRESS,
44            bridge_address: None,
45        }
46    }
47
48    pub fn amount(&self) -> &U256 {
49        &self.amount
50    }
51
52    pub fn to(mut self, address: Address) -> Self {
53        self.to = Some(address);
54        self
55    }
56
57    pub fn l2_gas_limit(mut self, value: Option<U256>) -> Self {
58        self.l2_gas_limit = match value {
59            Some(l2_gas_limit) => l2_gas_limit,
60            None => default_l2_gas_limit(),
61        };
62        self
63    }
64
65    pub fn gas_per_pubdata_byte(mut self, value: Option<U256>) -> Self {
66        self.gas_per_pubdata_byte = match value {
67            Some(gas_per_pubdata_byte) => gas_per_pubdata_byte,
68            None => default_gas_per_pubdata_byte(),
69        };
70        self
71    }
72
73    pub fn operator_tip(mut self, operator_tip: U256) -> Self {
74        self.operator_tip = operator_tip;
75        self
76    }
77
78    pub fn gas_price(mut self, value: Option<U256>) -> Self {
79        self.gas_price = value;
80        self
81    }
82
83    pub fn gas_limit(mut self, value: Option<U256>) -> Self {
84        self.gas_limit = match value {
85            Some(gas_limit) => gas_limit,
86            _ => default_gas_limit(),
87        };
88        self
89    }
90
91    pub fn token(mut self, token: Option<Address>) -> Self {
92        self.token = match token {
93            Some(address) => address,
94            _ => ETHER_L1_ADDRESS,
95        };
96        self
97    }
98
99    pub fn bridge_address(mut self, bridge_address: Option<Address>) -> Self {
100        self.bridge_address = bridge_address;
101        self
102    }
103}