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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#![allow(clippy::too_many_arguments)]
#![allow(missing_docs)]
use alloy_primitives::{Address, Bytes, FixedBytes, U256};
use alloy_sol_types::sol;

sol!(
    #[sol(rpc)]
    #[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    Zenith,
    "abi/Zenith.json"
);

sol!(
    #[sol(rpc)]
    #[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    Passage,
    "abi/Passage.json"
);

sol!(
    #[sol(rpc)]
    #[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    RollupOrders,
    "abi/RollupOrders.json"
);

sol!(
    #[sol(rpc)]
    #[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    Transactor,
    "abi/Transactor.json"
);

sol!(
    #[sol(rpc)]
    #[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    RollupPassage,
    "abi/RollupPassage.json"
);

// Zenith types
impl Copy for Zenith::BlockHeader {}
impl Copy for Zenith::BlockSubmitted {}
impl Copy for Zenith::SequencerSet {}
impl Copy for Zenith::BadSignature {}
impl Copy for Zenith::OneRollupBlockPerHostBlock {}
impl Copy for Zenith::OnlySequencerAdmin {}
impl Copy for Zenith::IncorrectHostBlock {}

impl Zenith::BlockSubmitted {
    /// Get the sequencer address that signed the block.
    pub const fn sequencer(&self) -> Address {
        self.sequencer
    }

    /// Get the chain id of the rollup.
    pub const fn rollup_chain_id(&self) -> u64 {
        self.rollupChainId.as_limbs()[0]
    }

    /// Get the gas limit of the block
    pub const fn gas_limit(&self) -> u64 {
        self.gasLimit.as_limbs()[0]
    }

    /// Get the reward address of the block.
    pub const fn reward_address(&self) -> Address {
        self.rewardAddress
    }

    /// Get the block data hash, i.e. the committment to the data of the block.
    pub const fn block_data_hash(&self) -> FixedBytes<32> {
        self.blockDataHash
    }

    /// Convert the BlockSubmitted event to a BlockHeader with the given host
    /// block number.
    pub const fn to_header(self, host_block_number: U256) -> Zenith::BlockHeader {
        Zenith::BlockHeader::from_block_submitted(self, host_block_number)
    }
}

impl Zenith::BlockHeader {
    /// Create a BlockHeader from a BlockSubmitted event with the given host
    /// block number
    pub const fn from_block_submitted(
        host_block_submitted: Zenith::BlockSubmitted,
        host_block_number: U256,
    ) -> Zenith::BlockHeader {
        Zenith::BlockHeader {
            rollupChainId: host_block_submitted.rollupChainId,
            hostBlockNumber: host_block_number,
            gasLimit: host_block_submitted.gasLimit,
            rewardAddress: host_block_submitted.rewardAddress,
            blockDataHash: host_block_submitted.blockDataHash,
        }
    }

    /// Get the host block number of the block
    pub const fn host_block_number(&self) -> u64 {
        self.hostBlockNumber.as_limbs()[0]
    }

    /// Get the chain ID of the block (discarding high bytes).
    pub const fn chain_id(&self) -> u64 {
        self.rollupChainId.as_limbs()[0]
    }

    /// Get the gas limit of the block (discarding high bytes).
    pub const fn gas_limit(&self) -> u64 {
        self.gasLimit.as_limbs()[0]
    }

    /// Get the reward address of the block.
    pub const fn reward_address(&self) -> Address {
        self.rewardAddress
    }

    /// Get the block data hash, i.e. the committment to the data of the block.
    pub const fn block_data_hash(&self) -> FixedBytes<32> {
        self.blockDataHash
    }
}

// Passage types
impl Copy for Passage::EnterConfigured {}
impl Copy for Passage::Withdrawal {}
impl Copy for Passage::OnlyTokenAdmin {}
impl Copy for Passage::Enter {}
impl Copy for Passage::EnterToken {}

impl Copy for Passage::PassageEvents {}

impl Clone for Passage::PassageEvents {
    fn clone(&self) -> Self {
        *self
    }
}

impl Passage::EnterToken {
    /// Get the chain ID of the event (discarding high bytes), returns `None`
    /// if the event has no associated chain id.
    pub const fn rollup_chain_id(&self) -> u64 {
        self.rollupChainId.as_limbs()[0]
    }

    /// Get the token address of the event.
    pub const fn token(&self) -> Address {
        self.token
    }

    /// Get the recipient of the event.
    pub const fn recipient(&self) -> Address {
        self.rollupRecipient
    }

    /// Get the amount of the event.
    pub const fn amount(&self) -> U256 {
        self.amount
    }
}

impl Passage::Enter {
    /// Get the chain ID of the event (discarding high bytes), returns `None`
    /// if the event has no associated chain id.
    pub const fn rollup_chain_id(&self) -> u64 {
        self.rollupChainId.as_limbs()[0]
    }

    /// Get the recipient of the event.
    pub const fn recipient(&self) -> Address {
        self.rollupRecipient
    }

    /// Get the amount of the event.
    pub const fn amount(&self) -> U256 {
        self.amount
    }
}

impl Passage::Withdrawal {
    /// Get the token address of the request.
    pub const fn token(&self) -> Address {
        self.token
    }

    /// Get the recipient of the request.
    pub const fn recipient(&self) -> Address {
        self.recipient
    }

    /// Get the amount of the request.
    pub const fn amount(&self) -> U256 {
        self.amount
    }
}

// RollupOrders types

impl Copy for RollupOrders::Input {}
impl Copy for RollupOrders::Output {}
impl Copy for RollupOrders::Sweep {}

impl Clone for RollupOrders::RollupOrdersEvents {
    fn clone(&self) -> Self {
        match self {
            RollupOrders::RollupOrdersEvents::Order(event) => {
                RollupOrders::RollupOrdersEvents::Order(event.clone())
            }
            RollupOrders::RollupOrdersEvents::Sweep(event) => {
                RollupOrders::RollupOrdersEvents::Sweep(*event)
            }
            RollupOrders::RollupOrdersEvents::Filled(event) => {
                RollupOrders::RollupOrdersEvents::Filled(event.clone())
            }
        }
    }
}

impl RollupOrders::Input {
    pub const fn token(&self) -> Address {
        self.token
    }

    pub const fn amount(&self) -> u64 {
        self.amount.as_limbs()[0]
    }
}

impl RollupOrders::Output {
    pub const fn token(&self) -> Address {
        self.token
    }

    pub const fn amount(&self) -> u64 {
        self.amount.as_limbs()[0]
    }

    pub const fn recipient(&self) -> Address {
        self.recipient
    }

    pub const fn chain_id(&self) -> u32 {
        self.chainId
    }
}

impl RollupOrders::Order {
    /// Get the inputs of the order.
    pub fn inputs(&self) -> &[RollupOrders::Input] {
        &self.inputs
    }

    /// Get the outputs of the order.
    pub fn outputs(&self) -> &[RollupOrders::Output] {
        &self.outputs
    }

    /// Get the deadline of the order.
    pub const fn deadline(&self) -> u64 {
        self.deadline.as_limbs()[0]
    }
}

impl RollupOrders::Sweep {
    pub const fn recipient(&self) -> Address {
        self.recipient
    }

    pub const fn token(&self) -> Address {
        self.token
    }

    pub const fn amount(&self) -> u64 {
        self.amount.as_limbs()[0]
    }
}

impl RollupOrders::Filled {
    pub fn outputs(&self) -> &[RollupOrders::Output] {
        self.outputs.as_slice()
    }
}

// Transactor
impl Copy for Transactor::GasConfigured {}

impl Clone for Transactor::TransactorEvents {
    fn clone(&self) -> Self {
        match self {
            Transactor::TransactorEvents::Transact(event) => {
                Transactor::TransactorEvents::Transact(event.clone())
            }
            Transactor::TransactorEvents::GasConfigured(event) => {
                Transactor::TransactorEvents::GasConfigured(*event)
            }
        }
    }
}

impl Transactor::Transact {
    pub const fn rollup_chain_id(&self) -> u64 {
        self.rollupChainId.as_limbs()[0]
    }

    pub const fn sender(&self) -> Address {
        self.sender
    }

    pub const fn to(&self) -> Address {
        self.to
    }

    pub const fn data(&self) -> &Bytes {
        &self.data
    }

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

    pub fn max_fee_per_gas(&self) -> u128 {
        self.maxFeePerGas.to::<u128>()
    }

    pub fn gas(&self) -> u128 {
        self.gas.to::<u128>()
    }
}

// RollupPassage
impl Copy for RollupPassage::Exit {}
impl Copy for RollupPassage::ExitToken {}

impl Copy for RollupPassage::RollupPassageEvents {}

impl Clone for RollupPassage::RollupPassageEvents {
    fn clone(&self) -> Self {
        *self
    }
}