1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
use crate::types::{Address, U256};

use crate::zks_utils::{
    DEPOSIT_GAS_PER_PUBDATA_LIMIT, ETHER_L1_ADDRESS, RECOMMENDED_DEPOSIT_L1_GAS_LIMIT,
    RECOMMENDED_DEPOSIT_L2_GAS_LIMIT,
};

fn default_gas_limit() -> U256 {
    RECOMMENDED_DEPOSIT_L1_GAS_LIMIT.into()
}

fn default_l2_gas_limit() -> U256 {
    RECOMMENDED_DEPOSIT_L2_GAS_LIMIT.into()
}

fn default_gas_per_pubdata_byte() -> U256 {
    DEPOSIT_GAS_PER_PUBDATA_LIMIT.into()
}

#[derive(Clone, Debug)]
pub struct DepositRequest {
    pub amount: U256,
    pub to: Option<Address>,
    pub l2_gas_limit: U256,
    pub gas_per_pubdata_byte: U256,
    pub operator_tip: U256,
    pub gas_price: Option<U256>,
    pub gas_limit: U256,
    pub token: Address,
    pub bridge_address: Option<Address>,
}

impl DepositRequest {
    pub fn new(amount: U256) -> Self {
        Self {
            amount,
            to: None,
            l2_gas_limit: default_l2_gas_limit(),
            gas_per_pubdata_byte: default_gas_per_pubdata_byte(),
            operator_tip: 0_i32.into(),
            gas_price: None,
            gas_limit: default_gas_limit(),
            token: ETHER_L1_ADDRESS,
            bridge_address: None,
        }
    }

    pub fn amount(&self) -> &U256 {
        &self.amount
    }

    pub fn to(mut self, address: Address) -> Self {
        self.to = Some(address);
        self
    }

    pub fn l2_gas_limit(mut self, value: Option<U256>) -> Self {
        self.l2_gas_limit = match value {
            Some(l2_gas_limit) => l2_gas_limit,
            None => default_l2_gas_limit(),
        };
        self
    }

    pub fn gas_per_pubdata_byte(mut self, value: Option<U256>) -> Self {
        self.gas_per_pubdata_byte = match value {
            Some(gas_per_pubdata_byte) => gas_per_pubdata_byte,
            None => default_gas_per_pubdata_byte(),
        };
        self
    }

    pub fn operator_tip(mut self, operator_tip: U256) -> Self {
        self.operator_tip = operator_tip;
        self
    }

    pub fn gas_price(mut self, value: Option<U256>) -> Self {
        self.gas_price = value;
        self
    }

    pub fn gas_limit(mut self, value: Option<U256>) -> Self {
        self.gas_limit = match value {
            Some(gas_limit) => gas_limit,
            _ => default_gas_limit(),
        };
        self
    }

    pub fn token(mut self, token: Option<Address>) -> Self {
        self.token = match token {
            Some(address) => address,
            _ => ETHER_L1_ADDRESS,
        };
        self
    }

    pub fn bridge_address(mut self, bridge_address: Option<Address>) -> Self {
        self.bridge_address = bridge_address;
        self
    }
}