@@ -7,19 +7,29 @@ import { stdJson } from "forge-std/StdJson.sol";
77import { Executables } from "scripts/Executables.sol " ;
88import { Process } from "scripts/libraries/Process.sol " ;
99import { Chains } from "scripts/Chains.sol " ;
10+ import { Config, Fork, ForkUtils } from "scripts/Config.sol " ;
1011
1112/// @title DeployConfig
1213/// @notice Represents the configuration required to deploy the system. It is expected
1314/// to read the file from JSON. A future improvement would be to have fallback
1415/// values if they are not defined in the JSON themselves.
1516contract DeployConfig is Script {
17+ using stdJson for string ;
18+ using ForkUtils for Fork;
19+
20+ /// @notice Represents an unset offset value, as opposed to 0, which denotes no-offset.
21+ uint256 constant NULL_OFFSET = type (uint256 ).max;
22+
1623 string internal _json;
1724
1825 address public finalSystemOwner;
1926 address public superchainConfigGuardian;
2027 uint256 public l1ChainID;
2128 uint256 public l2ChainID;
2229 uint256 public l2BlockTime;
30+ uint256 public l2GenesisDeltaTimeOffset;
31+ uint256 public l2GenesisEcotoneTimeOffset;
32+ uint256 public l2GenesisFjordTimeOffset;
2333 uint256 public maxSequencerDrift;
2434 uint256 public sequencerWindowSize;
2535 uint256 public channelTimeout;
@@ -94,6 +104,11 @@ contract DeployConfig is Script {
94104 l1ChainID = stdJson.readUint (_json, "$.l1ChainID " );
95105 l2ChainID = stdJson.readUint (_json, "$.l2ChainID " );
96106 l2BlockTime = stdJson.readUint (_json, "$.l2BlockTime " );
107+
108+ l2GenesisDeltaTimeOffset = _readOr (_json, "$.l2GenesisDeltaTimeOffset " , NULL_OFFSET);
109+ l2GenesisEcotoneTimeOffset = _readOr (_json, "$.l2GenesisEcotoneTimeOffset " , NULL_OFFSET);
110+ l2GenesisFjordTimeOffset = _readOr (_json, "$.l2GenesisFjordTimeOffset " , NULL_OFFSET);
111+
97112 maxSequencerDrift = stdJson.readUint (_json, "$.maxSequencerDrift " );
98113 sequencerWindowSize = stdJson.readUint (_json, "$.sequencerWindowSize " );
99114 channelTimeout = stdJson.readUint (_json, "$.channelTimeout " );
@@ -161,6 +176,18 @@ contract DeployConfig is Script {
161176 useInterop = _readOr (_json, "$.useInterop " , false );
162177 }
163178
179+ function fork () public view returns (Fork fork_ ) {
180+ // let env var take precedence
181+ fork_ = Config.fork ();
182+ if (fork_ == Fork.NONE) {
183+ // Will revert if no deploy config can be found either.
184+ fork_ = latestGenesisFork ();
185+ console.log ("DeployConfig: using deploy config fork: %s " , fork_.toString ());
186+ } else {
187+ console.log ("DeployConfig: using env var fork: %s " , fork_.toString ());
188+ }
189+ }
190+
164191 function l1StartingBlockTag () public returns (bytes32 ) {
165192 try vm.parseJsonBytes32 (_json, "$.l1StartingBlockTag " ) returns (bytes32 tag ) {
166193 return tag;
@@ -215,6 +242,17 @@ contract DeployConfig is Script {
215242 customGasTokenAddress = _token;
216243 }
217244
245+ function latestGenesisFork () internal view returns (Fork) {
246+ if (l2GenesisFjordTimeOffset == 0 ) {
247+ return Fork.FJORD;
248+ } else if (l2GenesisEcotoneTimeOffset == 0 ) {
249+ return Fork.ECOTONE;
250+ } else if (l2GenesisDeltaTimeOffset == 0 ) {
251+ return Fork.DELTA;
252+ }
253+ revert ("DeployConfig: no supported fork active at genesis " );
254+ }
255+
218256 function _getBlockByTag (string memory _tag ) internal returns (bytes32 ) {
219257 string [] memory cmd = new string [](3 );
220258 cmd[0 ] = Executables.bash;
@@ -225,15 +263,20 @@ contract DeployConfig is Script {
225263 }
226264
227265 function _readOr (string memory json , string memory key , bool defaultValue ) internal view returns (bool ) {
228- return vm.keyExists (json, key) ? stdJson .readBool (json, key) : defaultValue;
266+ return vm.keyExistsJson (json, key) ? json .readBool (key) : defaultValue;
229267 }
230268
231269 function _readOr (string memory json , string memory key , uint256 defaultValue ) internal view returns (uint256 ) {
232- return vm.keyExists (json, key) ? stdJson. readUint (json, key) : defaultValue;
270+ return ( vm.keyExistsJson (json, key) && ! _isNull (json, key)) ? json. readUint ( key) : defaultValue;
233271 }
234272
235273 function _readOr (string memory json , string memory key , address defaultValue ) internal view returns (address ) {
236- return vm.keyExists (json, key) ? stdJson.readAddress (json, key) : defaultValue;
274+ return vm.keyExistsJson (json, key) ? json.readAddress (key) : defaultValue;
275+ }
276+
277+ function _isNull (string memory json , string memory key ) internal pure returns (bool ) {
278+ string memory value = json.readString (key);
279+ return (keccak256 (bytes (value)) == keccak256 (bytes ("null " )));
237280 }
238281
239282 function _readOr (
@@ -245,6 +288,6 @@ contract DeployConfig is Script {
245288 view
246289 returns (string memory )
247290 {
248- return vm.keyExists (json, key) ? stdJson .readString (json, key) : defaultValue;
291+ return vm.keyExists (json, key) ? json .readString (key) : defaultValue;
249292 }
250293}
0 commit comments