mega_system_contracts/lib.rs
1//! System contracts for the `MegaETH` EVM.
2//!
3//! This crate provides bytecode constants for system contracts used by mega-evm.
4//! When building from the repository with Foundry installed, the build script validates that
5//! the pre-generated constants match the compiled Solidity source.
6//! When building from a published crate (without Foundry), the pre-generated constants are used
7//! directly.
8
9#![cfg_attr(not(feature = "std"), no_std)]
10#![warn(missing_docs)]
11// `not(test)`: dev-dependencies (e.g. `serde_json`, used only by integration tests) are linked
12// into test builds but not referenced by the library crate, which would otherwise trip this lint.
13#![cfg_attr(not(test), warn(unused_crate_dependencies))]
14#![deny(unused_must_use)]
15
16pub use alloy_primitives;
17
18/// Oracle contract bytecode and interface.
19///
20/// Bytecode constants are pre-generated from the versioned artifacts in the `artifacts/`
21/// directory.
22/// Interface bindings are generated from the Solidity source.
23pub mod oracle {
24 include!("generated/oracle_artifacts.rs");
25
26 alloy_sol_types::sol!("contracts/interfaces/IOracle.sol");
27}
28
29/// `KeylessDeploy` contract bytecode and interface.
30///
31/// Bytecode constants are pre-generated from the versioned artifacts in the `artifacts/`
32/// directory.
33/// Interface bindings are generated from the Solidity source.
34pub mod keyless_deploy {
35 include!("generated/keyless_deploy_artifacts.rs");
36
37 alloy_sol_types::sol!("contracts/interfaces/IKeylessDeploy.sol");
38}
39
40/// `MegaAccessControl` contract bytecode and interface.
41///
42/// Bytecode constants are pre-generated from the versioned artifacts in the `artifacts/`
43/// directory.
44/// Interface bindings are generated from the Solidity source.
45#[allow(missing_docs)]
46pub mod access_control {
47 include!("generated/access_control_artifacts.rs");
48
49 alloy_sol_types::sol!(
50 #[sol(all_derives)]
51 "contracts/interfaces/IMegaAccessControl.sol"
52 );
53}
54
55/// `MegaLimitControl` contract bytecode and interface.
56///
57/// Bytecode constants are pre-generated from the versioned artifacts in the `artifacts/`
58/// directory.
59/// Interface bindings are generated from the Solidity source.
60pub mod limit_control {
61 include!("generated/limit_control_artifacts.rs");
62
63 alloy_sol_types::sol!("contracts/interfaces/IMegaLimitControl.sol");
64}
65
66/// `SequencerRegistry` contract bytecode and interface.
67///
68/// Bytecode constants are pre-generated from the versioned artifacts in the `artifacts/`
69/// directory.
70/// Interface bindings are generated from the Solidity source.
71#[allow(missing_docs)]
72pub mod sequencer_registry {
73 include!("generated/sequencer_registry_artifacts.rs");
74
75 alloy_sol_types::sol!(
76 #[sol(all_derives)]
77 "contracts/interfaces/ISequencerRegistry.sol"
78 );
79
80 /// Flat storage slot constants for `SequencerRegistry`.
81 pub mod storage_slots {
82 use alloy_primitives::U256;
83
84 /// Storage slot for `_currentSystemAddress`.
85 pub const CURRENT_SYSTEM_ADDRESS: U256 = U256::ZERO;
86
87 /// Storage slot for `_currentSequencer`.
88 pub const CURRENT_SEQUENCER: U256 = U256::from_limbs([1, 0, 0, 0]);
89
90 /// Storage slot for `_admin`.
91 pub const ADMIN: U256 = U256::from_limbs([2, 0, 0, 0]);
92
93 /// Storage slot for `_pendingAdmin`.
94 pub const PENDING_ADMIN: U256 = U256::from_limbs([3, 0, 0, 0]);
95
96 /// Storage slot for `_initialSystemAddress`.
97 pub const INITIAL_SYSTEM_ADDRESS: U256 = U256::from_limbs([4, 0, 0, 0]);
98
99 /// Storage slot for `_initialSequencer`.
100 pub const INITIAL_SEQUENCER: U256 = U256::from_limbs([5, 0, 0, 0]);
101
102 /// Storage slot for `_initialFromBlock`.
103 pub const INITIAL_FROM_BLOCK: U256 = U256::from_limbs([6, 0, 0, 0]);
104
105 /// Storage slot for `_pendingSystemAddress`.
106 pub const PENDING_SYSTEM_ADDRESS: U256 = U256::from_limbs([7, 0, 0, 0]);
107
108 /// Storage slot for `_systemAddressActivationBlock`.
109 pub const SYSTEM_ADDRESS_ACTIVATION_BLOCK: U256 = U256::from_limbs([8, 0, 0, 0]);
110
111 /// Storage slot for `_pendingSequencer`.
112 pub const PENDING_SEQUENCER: U256 = U256::from_limbs([9, 0, 0, 0]);
113
114 /// Storage slot for `_sequencerActivationBlock`.
115 pub const SEQUENCER_ACTIVATION_BLOCK: U256 = U256::from_limbs([10, 0, 0, 0]);
116
117 // Slots 11 (`_systemAddressHistory`) and 12 (`_sequencerHistory`) are Solidity
118 // dynamic arrays. By the standard layout, the slot itself stores `array.length` and
119 // element `i` lives at `keccak256(bytes32(slot)) + i`. Concretely:
120 //
121 // `_systemAddressHistory[0]` is at
122 // `keccak256(bytes32(uint256(11)))`
123 // = `0x0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01db9`
124 // `_sequencerHistory[0]` is at
125 // `keccak256(bytes32(uint256(12)))`
126 // = `0xdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8c7`
127 //
128 // Rust never reads or writes these arrays directly — `systemAddressAt` and
129 // `sequencerAt` are on-chain getters that iterate them — so there is no flat slot
130 // constant.
131
132 /// Storage slot for `_minRotationDelay` (v2.0.0+). Appended after the two dynamic
133 /// arrays at slots 11/12, so 13 is the first free flat slot.
134 pub const MIN_ROTATION_DELAY: U256 = U256::from_limbs([13, 0, 0, 0]);
135 }
136}