zksync_web3_rs/eip712/
meta.rs

1use super::{rlp_append_option, PaymasterParams};
2use crate::zks_utils::DEFAULT_GAS_PER_PUBDATA_LIMIT;
3use ethers::{
4    types::{Bytes, U256},
5    utils::rlp::Encodable,
6};
7use serde::{Deserialize, Serialize};
8
9#[derive(Serialize, Deserialize, Clone, Debug)]
10#[serde(rename_all(serialize = "camelCase", deserialize = "camelCase"))]
11pub struct Eip712Meta {
12    pub gas_per_pubdata: U256,
13    pub factory_deps: Vec<Vec<u8>>,
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub custom_signature: Option<Bytes>,
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub paymaster_params: Option<PaymasterParams>,
18}
19
20impl Eip712Meta {
21    pub fn new() -> Self {
22        Self::default()
23    }
24
25    pub fn gas_per_pubdata<T>(mut self, gas_per_pubdata: T) -> Self
26    where
27        T: Into<U256>,
28    {
29        self.gas_per_pubdata = gas_per_pubdata.into();
30        self
31    }
32
33    pub fn factory_deps<T>(mut self, factory_deps: T) -> Self
34    where
35        T: Into<Vec<Vec<u8>>>,
36    {
37        self.factory_deps = factory_deps.into();
38        self
39    }
40
41    pub fn custom_signature<T>(mut self, custom_signature: T) -> Self
42    where
43        T: Into<Bytes>,
44    {
45        self.custom_signature = Some(custom_signature.into());
46        self
47    }
48
49    pub fn paymaster_params(mut self, paymaster_params: PaymasterParams) -> Self {
50        self.paymaster_params = Some(paymaster_params);
51        self
52    }
53}
54
55impl Default for Eip712Meta {
56    fn default() -> Self {
57        Self {
58            gas_per_pubdata: DEFAULT_GAS_PER_PUBDATA_LIMIT.into(),
59            factory_deps: Default::default(),
60            custom_signature: Default::default(),
61            paymaster_params: Default::default(),
62        }
63    }
64}
65
66impl Encodable for Eip712Meta {
67    fn rlp_append(&self, stream: &mut ethers::utils::rlp::RlpStream) {
68        // 12
69        stream.append(&self.gas_per_pubdata);
70        // 13
71        stream.begin_list(self.factory_deps.len());
72        for dep in self.factory_deps.iter() {
73            stream.append(dep);
74        }
75        // 14
76        rlp_append_option(stream, self.custom_signature.clone().map(|v| v.to_vec()));
77        // 15
78        rlp_append_option(stream, self.paymaster_params.clone());
79    }
80}