@@ -5,7 +5,7 @@ import { Script } from "forge-std/Script.sol";
55import { console2 as console } from "forge-std/console2.sol " ;
66import { Deployer } from "scripts/Deployer.sol " ;
77
8- import { Config, OutputMode, Fork, LATEST_FORK } from "scripts/Config.sol " ;
8+ import { Config, OutputMode, OutputModeUtils, Fork, ForkUtils , LATEST_FORK } from "scripts/Config.sol " ;
99import { Artifacts } from "scripts/Artifacts.s.sol " ;
1010import { DeployConfig } from "scripts/DeployConfig.s.sol " ;
1111import { Predeploys } from "src/libraries/Predeploys.sol " ;
@@ -45,6 +45,9 @@ struct L1Dependencies {
4545/// 2. A contract must be deployed using the `new` syntax if there are immutables in the code.
4646/// Any other side effects from the init code besides setting the immutables must be cleaned up afterwards.
4747contract L2Genesis is Deployer {
48+ using ForkUtils for Fork;
49+ using OutputModeUtils for OutputMode;
50+
4851 uint256 public constant PRECOMPILE_COUNT = 256 ;
4952
5053 uint80 internal constant DEV_ACCOUNT_FUND_AMT = 10_000 ether ;
@@ -106,21 +109,7 @@ contract L2Genesis is Deployer {
106109 /// Sets the precompiles, proxies, and the implementation accounts to be `vm.dumpState`
107110 /// to generate a L2 genesis alloc.
108111 function runWithStateDump () public {
109- Fork fork = Config.fork ();
110- if (fork == Fork.NONE) {
111- // Will revert if no deploy config can be found either.
112- fork = latestDeployConfigGenesisFork ();
113- console.log ("L2Genesis: using deploy config fork: %d " , uint256 (fork));
114- } else {
115- console.log ("L2Genesis: using env var fork: %d " , uint256 (fork));
116- }
117- runWithOptions (Config.outputMode (), fork, artifactDependencies ());
118- }
119-
120- function latestDeployConfigGenesisFork () internal returns (Fork) {
121- DeployConfig cfg = DeployConfig (address (uint160 (uint256 (keccak256 (abi.encode ("optimism.deployconfig " ))))));
122- cfg.read (Config.deployConfigPath ());
123- return cfg.latestGenesisFork ();
112+ runWithOptions (Config.outputMode (), cfg.fork (), artifactDependencies ());
124113 }
125114
126115 /// @notice Alias for `runWithStateDump` so that no `--sig` needs to be specified.
@@ -141,7 +130,7 @@ contract L2Genesis is Deployer {
141130
142131 /// @notice Build the L2 genesis.
143132 function runWithOptions (OutputMode _mode , Fork _fork , L1Dependencies memory _l1Dependencies ) public {
144- console.log ("L2Genesis: outputMode: %d , fork: %d " , uint256 ( _mode), uint256 ( _fork));
133+ console.log ("L2Genesis: outputMode: %s , fork: %s " , _mode. toString ( ), _fork. toString ( ));
145134 vm.startPrank (deployer);
146135 vm.chainId (cfg.l2ChainID ());
147136
@@ -154,32 +143,33 @@ contract L2Genesis is Deployer {
154143 }
155144 vm.stopPrank ();
156145
157- if (_mode == OutputMode.ALL || _fork == Fork.DELTA && _mode == OutputMode.LATEST) {
158- writeGenesisAllocs (Config.stateDumpPath ("-delta " ));
159- }
160- if (_fork == Fork.DELTA) {
146+ if (writeForkGenesisAllocs (_fork, Fork.DELTA, _mode)) {
161147 return ;
162148 }
163149
164150 activateEcotone ();
165151
166- if (_mode == OutputMode.ALL || _fork == Fork.ECOTONE && _mode == OutputMode.LATEST) {
167- writeGenesisAllocs (Config.stateDumpPath ("-ecotone " ));
168- }
169- if (_fork == Fork.ECOTONE) {
152+ if (writeForkGenesisAllocs (_fork, Fork.ECOTONE, _mode)) {
170153 return ;
171154 }
172155
173156 activateFjord ();
174157
175- if (_mode == OutputMode.ALL || _fork == Fork.FJORD && _mode == OutputMode.LATEST) {
176- writeGenesisAllocs (Config.stateDumpPath ("-fjord " ));
177- }
178- if (_fork == Fork.FJORD) {
158+ if (writeForkGenesisAllocs (_fork, Fork.FJORD, _mode)) {
179159 return ;
180160 }
181161 }
182162
163+ function writeForkGenesisAllocs (Fork _latest , Fork _current , OutputMode _mode ) internal returns (bool isLatest_ ) {
164+ if (_mode == OutputMode.ALL || _latest == _current && _mode == OutputMode.LATEST) {
165+ string memory suffix = string .concat ("- " , _current.toString ());
166+ writeGenesisAllocs (Config.stateDumpPath (suffix));
167+ }
168+ if (_latest == _current) {
169+ isLatest_ = true ;
170+ }
171+ }
172+
183173 /// @notice Give all of the precompiles 1 wei
184174 function dealEthToPrecompiles () internal {
185175 console.log ("Setting precompile 1 wei balances " );
0 commit comments