@@ -7,19 +7,28 @@ 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 { Fork } 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+
19+ /// @notice Represents an unset offset value, as opposed to 0, which denotes no-offset.
20+ uint256 constant NULL_OFFSET = type (uint256 ).max;
21+
1622 string internal _json;
1723
1824 address public finalSystemOwner;
1925 address public superchainConfigGuardian;
2026 uint256 public l1ChainID;
2127 uint256 public l2ChainID;
2228 uint256 public l2BlockTime;
29+ uint256 public l2GenesisDeltaTimeOffset;
30+ uint256 public l2GenesisEcotoneTimeOffset;
31+ uint256 public l2GenesisFjordTimeOffset;
2332 uint256 public maxSequencerDrift;
2433 uint256 public sequencerWindowSize;
2534 uint256 public channelTimeout;
@@ -94,6 +103,11 @@ contract DeployConfig is Script {
94103 l1ChainID = stdJson.readUint (_json, "$.l1ChainID " );
95104 l2ChainID = stdJson.readUint (_json, "$.l2ChainID " );
96105 l2BlockTime = stdJson.readUint (_json, "$.l2BlockTime " );
106+
107+ l2GenesisDeltaTimeOffset = _readOr (_json, "$.l2GenesisDeltaTimeOffset " , NULL_OFFSET);
108+ l2GenesisEcotoneTimeOffset = _readOr (_json, "$.l2GenesisEcotoneTimeOffset " , NULL_OFFSET);
109+ l2GenesisFjordTimeOffset = _readOr (_json, "$.l2GenesisFjordTimeOffset " , NULL_OFFSET);
110+
97111 maxSequencerDrift = stdJson.readUint (_json, "$.maxSequencerDrift " );
98112 sequencerWindowSize = stdJson.readUint (_json, "$.sequencerWindowSize " );
99113 channelTimeout = stdJson.readUint (_json, "$.channelTimeout " );
@@ -161,6 +175,17 @@ contract DeployConfig is Script {
161175 useInterop = _readOr (_json, "$.useInterop " , false );
162176 }
163177
178+ function latestGenesisFork () public view returns (Fork) {
179+ if (l2GenesisFjordTimeOffset == 0 ) {
180+ return Fork.FJORD;
181+ } else if (l2GenesisEcotoneTimeOffset == 0 ) {
182+ return Fork.ECOTONE;
183+ } else if (l2GenesisDeltaTimeOffset == 0 ) {
184+ return Fork.DELTA;
185+ }
186+ revert ("DeployConfig: no supported fork active at genesis " );
187+ }
188+
164189 function l1StartingBlockTag () public returns (bytes32 ) {
165190 try vm.parseJsonBytes32 (_json, "$.l1StartingBlockTag " ) returns (bytes32 tag ) {
166191 return tag;
@@ -225,15 +250,20 @@ contract DeployConfig is Script {
225250 }
226251
227252 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;
253+ return vm.keyExistsJson (json, key) ? json .readBool (key) : defaultValue;
229254 }
230255
231256 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;
257+ return ( vm.keyExistsJson (json, key) && ! _isNull (json, key)) ? json. readUint ( key) : defaultValue;
233258 }
234259
235260 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;
261+ return vm.keyExistsJson (json, key) ? json.readAddress (key) : defaultValue;
262+ }
263+
264+ function _isNull (string memory json , string memory key ) internal pure returns (bool ) {
265+ string memory value = json.readString (key);
266+ return (keccak256 (bytes (value)) == keccak256 (bytes ("null " )));
237267 }
238268
239269 function _readOr (
@@ -245,6 +275,6 @@ contract DeployConfig is Script {
245275 view
246276 returns (string memory )
247277 {
248- return vm.keyExists (json, key) ? stdJson .readString (json, key) : defaultValue;
278+ return vm.keyExists (json, key) ? json .readString (key) : defaultValue;
249279 }
250280}
0 commit comments