signet-zenith 0.16.2

Types for the zenith smart contracts
Documentation
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
#![allow(clippy::too_many_arguments)]
#![allow(missing_docs)]
use alloy::primitives::{Address, Bytes, FixedBytes, U256};
use std::borrow::Cow;

mod mint {
    alloy::sol!(
        #[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
        function mint(address to, uint256 amount);
    );
}
pub use mint::mintCall;

mod zenith {
    use super::*;

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

    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
        }
    }
}

mod passage {
    use super::*;

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

    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::DisallowedEnter {}
    impl Copy for Passage::FailedCall {}
    impl Copy for Passage::InsufficientBalance {}
    impl Copy for Passage::SafeERC20FailedOperation {}
    impl Copy for Passage::AddressEmptyCode {}

    impl Copy for Passage::PassageEvents {}

    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
        }
    }

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

        /// Get if the token has been configured to allow or disallow enters.
        pub const fn can_enter(&self) -> bool {
            self.canEnter
        }
    }
}

mod orders {
    use super::*;
    use IOrders::Output;
    use ISignatureTransfer::TokenPermissions;

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

    alloy::sol! {
       struct PermitBatchWitnessTransferFrom {
           TokenPermissions[] permitted;
           address spender;
           uint256 nonce;
           uint256 deadline;
           Output[] outputs;
       }
    }

    impl Copy for IOrders::Input {}
    impl Copy for IOrders::Output {}
    impl Copy for Orders::Sweep {}
    impl Copy for Orders::InsufficientBalance {}
    impl Copy for Orders::AddressEmptyCode {}
    impl Copy for Orders::LengthMismatch {}
    impl Copy for Orders::OrderExpired {}
    impl Copy for Orders::OutputMismatch {}
    impl Copy for Orders::SafeERC20FailedOperation {}

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

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

    impl IOrders::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 From<&IOrders::Input> for TokenPermissions {
        fn from(input: &IOrders::Input) -> TokenPermissions {
            TokenPermissions { token: input.token, amount: input.amount }
        }
    }

    impl From<IOrders::Input> for TokenPermissions {
        fn from(input: IOrders::Input) -> TokenPermissions {
            TokenPermissions { token: input.token, amount: input.amount }
        }
    }

    impl From<TokenPermissions> for IOrders::Input {
        fn from(perm: TokenPermissions) -> IOrders::Input {
            IOrders::Input { token: perm.token, amount: perm.amount }
        }
    }

    impl From<&IOrders::Output> for TokenPermissions {
        fn from(output: &IOrders::Output) -> TokenPermissions {
            TokenPermissions { token: output.token, amount: output.amount }
        }
    }

    impl From<IOrders::Output> for TokenPermissions {
        fn from(output: IOrders::Output) -> TokenPermissions {
            TokenPermissions { token: output.token, amount: output.amount }
        }
    }

    impl Orders::Order {
        /// Get the inputs of the order.
        #[allow(clippy::missing_const_for_fn)] // false positive
        pub fn inputs(&self) -> &[IOrders::Input] {
            &self.inputs
        }

        /// Get the outputs of the order.
        #[allow(clippy::missing_const_for_fn)] // false positive
        pub fn outputs(&self) -> &[IOrders::Output] {
            &self.outputs
        }

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

    impl<'a> From<&'a Orders::Order> for Cow<'a, Orders::Order> {
        fn from(order: &'a Orders::Order) -> Self {
            Cow::Borrowed(order)
        }
    }

    impl Orders::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 Orders::Filled {
        pub const fn outputs(&self) -> &[IOrders::Output] {
            self.outputs.as_slice()
        }
    }

    impl Default for Orders::Order {
        fn default() -> Self {
            Self { inputs: Vec::new(), outputs: Vec::new(), deadline: U256::ZERO }
        }
    }

    impl Orders::Order {
        /// Add an input to the Order and return the modified Order.
        pub fn with_input(mut self, input: IOrders::Input) -> Self {
            self.inputs.push(input);
            self
        }

        /// Add an output to the Order and return the modified Order.
        pub fn with_output(mut self, output: IOrders::Output) -> Self {
            self.outputs.push(output);
            self
        }

        /// Set the deadline of the Order and return the modified Order.
        pub fn with_deadline(mut self, deadline: u64) -> Self {
            self.deadline = U256::from(deadline);
            self
        }
    }
}

mod transactor {
    use super::*;

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

    impl Copy for Transactor::GasConfigured {}

    impl Transactor::Transact {
        /// Get the chain ID of the event (discarding high bytes).
        pub const fn rollup_chain_id(&self) -> u64 {
            self.rollupChainId.as_limbs()[0]
        }

        /// Get the host sender that triggered the event.
        pub const fn host_sender(&self) -> Address {
            self.sender
        }

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

        /// Get the data of the transact.
        pub const fn data(&self) -> &Bytes {
            &self.data
        }

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

        /// Get the max fee per gas of the transact.
        pub fn max_fee_per_gas(&self) -> u128 {
            self.maxFeePerGas.to::<u128>()
        }

        /// Get the gas limit of the transact.
        pub fn gas(&self) -> u128 {
            self.gas.to::<u128>()
        }
    }
}

mod rollup_passage {

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

    impl Copy for RollupPassage::Exit {}
    impl Copy for RollupPassage::ExitToken {}
    impl Copy for RollupPassage::AddressEmptyCode {}
    impl Copy for RollupPassage::InsufficientBalance {}
    impl Copy for RollupPassage::SafeERC20FailedOperation {}

    impl Copy for RollupPassage::RollupPassageEvents {}
}

mod bundle_helper {
    use super::*;

    use ISignatureTransfer::{PermitBatchTransferFrom, TokenPermissions};
    use UsesPermit2::Permit2Batch;

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

    impl From<&RollupOrders::Output> for IOrders::Output {
        fn from(output: &RollupOrders::Output) -> IOrders::Output {
            IOrders::Output {
                token: output.token,
                amount: output.amount,
                recipient: output.recipient,
                chainId: output.chainId,
            }
        }
    }

    impl From<RollupOrders::Output> for IOrders::Output {
        fn from(output: RollupOrders::Output) -> IOrders::Output {
            IOrders::Output {
                token: output.token,
                amount: output.amount,
                recipient: output.recipient,
                chainId: output.chainId,
            }
        }
    }

    impl From<RollupOrders::Permit2Batch> for Permit2Batch {
        fn from(permit: HostOrders::Permit2Batch) -> Permit2Batch {
            Permit2Batch {
                permit: permit.permit.into(),
                owner: permit.owner,
                signature: permit.signature,
            }
        }
    }

    impl From<&RollupOrders::Permit2Batch> for Permit2Batch {
        fn from(permit: &HostOrders::Permit2Batch) -> Permit2Batch {
            Permit2Batch {
                permit: (&permit.permit).into(),
                owner: permit.owner,
                signature: permit.signature.clone(),
            }
        }
    }

    impl From<&RollupOrders::PermitBatchTransferFrom> for PermitBatchTransferFrom {
        fn from(permit: &HostOrders::PermitBatchTransferFrom) -> PermitBatchTransferFrom {
            PermitBatchTransferFrom {
                permitted: permit.permitted.iter().map(TokenPermissions::from).collect(),
                nonce: permit.nonce,
                deadline: permit.deadline,
            }
        }
    }

    impl From<RollupOrders::PermitBatchTransferFrom> for PermitBatchTransferFrom {
        fn from(permit: HostOrders::PermitBatchTransferFrom) -> PermitBatchTransferFrom {
            PermitBatchTransferFrom {
                permitted: permit.permitted.into_iter().map(TokenPermissions::from).collect(),
                nonce: permit.nonce,
                deadline: permit.deadline,
            }
        }
    }

    impl From<&crate::bindings::orders::ISignatureTransfer::TokenPermissions> for TokenPermissions {
        fn from(perm: &HostOrders::TokenPermissions) -> TokenPermissions {
            TokenPermissions { token: perm.token, amount: perm.amount }
        }
    }

    impl From<crate::bindings::orders::ISignatureTransfer::TokenPermissions> for TokenPermissions {
        fn from(perm: HostOrders::TokenPermissions) -> TokenPermissions {
            TokenPermissions { token: perm.token, amount: perm.amount }
        }
    }
}

mod permit2 {
    use alloy::primitives::{address, Address, U256};

    /// The canonical Permit2 contract address deployed on all supported chains.
    pub const PERMIT2_ADDRESS: Address = address!("0x000000000022D473030F116dDEE9F6B43aC78BA3");

    alloy::sol! {
        /// Minimal ERC20 interface for balance and allowance checks.
        #[sol(rpc)]
        interface IERC20 {
            function balanceOf(address account) external view returns (uint256);
            function allowance(address owner, address spender) external view returns (uint256);
        }
    }

    alloy::sol! {
        /// Permit2 interface for nonce validation.
        #[sol(rpc)]
        interface IPermit2 {
            function nonceBitmap(address owner, uint256 wordPos) external view returns (uint256);
        }
    }

    impl<P, N> IPermit2::IPermit2Instance<P, N> {
        /// Convert a nonce to its bitmap position (word position and bit
        /// position within the word).
        pub fn nonce_to_bitmap_position(&self, nonce: U256) -> (U256, u8) {
            let word_pos = nonce >> 8;
            let bit_pos = (nonce & U256::from(0xFF)).saturating_to::<u8>();
            (word_pos, bit_pos)
        }
    }
}

pub use permit2::{IPermit2, IERC20, PERMIT2_ADDRESS};
pub use zenith::Zenith;

/// Contract Bindings for the RollupOrders contract.
#[allow(non_snake_case)]
pub mod RollupOrders {
    pub use super::orders::IOrders::*;
    pub use super::orders::ISignatureTransfer::*;
    pub use super::orders::Orders::*;
    pub use super::orders::PermitBatchWitnessTransferFrom;
    pub use super::orders::UsesPermit2::*;

    pub use super::orders::Orders::OrdersCalls as RollupOrdersCalls;
    pub use super::orders::Orders::OrdersErrors as RollupOrdersErrors;
    pub use super::orders::Orders::OrdersEvents as RollupOrdersEvents;
    pub use super::orders::Orders::OrdersInstance as RollupOrdersInstance;
}

/// Contract Bindings for the HostOrders contract.
#[allow(non_snake_case)]
pub mod HostOrders {
    pub use super::orders::Orders::*;

    pub use super::orders::IOrders::*;
    pub use super::orders::ISignatureTransfer::*;
    pub use super::orders::UsesPermit2::*;

    pub use super::orders::Orders::OrdersCalls as HostOrdersCalls;
    pub use super::orders::Orders::OrdersErrors as HostOrdersErrors;
    pub use super::orders::Orders::OrdersEvents as HostOrdersEvents;
    pub use super::orders::Orders::OrdersInstance as HostOrdersInstance;
}

/// Contract Bindings for the Passage contract.
#[allow(non_snake_case)]
pub mod Passage {
    pub use super::passage::Passage::*;

    pub use super::passage::ISignatureTransfer::*;
    pub use super::passage::UsesPermit2::*;
}

pub use transactor::Transactor;

/// Contract Bindings for the RollupPassage contract.
#[allow(non_snake_case)]
pub mod RollupPassage {
    pub use super::rollup_passage::RollupPassage::*;

    pub use super::rollup_passage::ISignatureTransfer::*;
    pub use super::rollup_passage::UsesPermit2::*;
}

/// Contract Bindings for the BundleHelper contract.
#[allow(non_snake_case)]
pub mod BundleHelper {
    pub use super::bundle_helper::BundleHelper::*;
    pub use super::bundle_helper::IOrders;
    pub use super::bundle_helper::Zenith::BlockHeader;
}