github.com/ethereum-optimism/optimism@v1.7.2/packages/contracts-bedrock/scripts/DeployConfig.s.sol (about) 1 // SPDX-License-Identifier: MIT 2 pragma solidity 0.8.15; 3 4 import { Script } from "forge-std/Script.sol"; 5 import { console2 as console } from "forge-std/console2.sol"; 6 import { stdJson } from "forge-std/StdJson.sol"; 7 import { Executables } from "scripts/Executables.sol"; 8 import { Chains } from "scripts/Chains.sol"; 9 10 // Global constant for the `useFaultProofs` slot in the DeployConfig contract, which can be overridden in the testing 11 // environment. 12 bytes32 constant USE_FAULT_PROOFS_SLOT = bytes32(uint256(63)); 13 14 /// @title DeployConfig 15 /// @notice Represents the configuration required to deploy the system. It is expected 16 /// to read the file from JSON. A future improvement would be to have fallback 17 /// values if they are not defined in the JSON themselves. 18 contract DeployConfig is Script { 19 string internal _json; 20 21 address public finalSystemOwner; 22 address public superchainConfigGuardian; 23 uint256 public l1ChainID; 24 uint256 public l2ChainID; 25 uint256 public l2BlockTime; 26 uint256 public maxSequencerDrift; 27 uint256 public sequencerWindowSize; 28 uint256 public channelTimeout; 29 address public p2pSequencerAddress; 30 address public batchInboxAddress; 31 address public batchSenderAddress; 32 uint256 public l2OutputOracleSubmissionInterval; 33 int256 internal _l2OutputOracleStartingTimestamp; 34 uint256 public l2OutputOracleStartingBlockNumber; 35 address public l2OutputOracleProposer; 36 address public l2OutputOracleChallenger; 37 uint256 public finalizationPeriodSeconds; 38 bool public fundDevAccounts; 39 address public proxyAdminOwner; 40 address public baseFeeVaultRecipient; 41 uint256 public baseFeeVaultMinimumWithdrawalAmount; 42 address public l1FeeVaultRecipient; 43 uint256 public l1FeeVaultMinimumWithdrawalAmount; 44 address public sequencerFeeVaultRecipient; 45 uint256 public sequencerFeeVaultMinimumWithdrawalAmount; 46 uint256 public sequencerFeeVaultWithdrawalNetwork; 47 string public governanceTokenName; 48 string public governanceTokenSymbol; 49 address public governanceTokenOwner; 50 uint256 public l2GenesisBlockGasLimit; 51 uint256 public l2GenesisBlockBaseFeePerGas; 52 uint256 public gasPriceOracleOverhead; 53 uint256 public gasPriceOracleScalar; 54 bool public enableGovernance; 55 uint256 public eip1559Denominator; 56 uint256 public eip1559Elasticity; 57 uint256 public faultGameAbsolutePrestate; 58 uint256 public faultGameGenesisBlock; 59 bytes32 public faultGameGenesisOutputRoot; 60 uint256 public faultGameMaxDepth; 61 uint256 public faultGameSplitDepth; 62 uint256 public faultGameMaxDuration; 63 uint256 public faultGameWithdrawalDelay; 64 uint256 public preimageOracleMinProposalSize; 65 uint256 public preimageOracleChallengePeriod; 66 uint256 public systemConfigStartBlock; 67 uint256 public requiredProtocolVersion; 68 uint256 public recommendedProtocolVersion; 69 uint256 public proofMaturityDelaySeconds; 70 uint256 public disputeGameFinalityDelaySeconds; 71 uint256 public respectedGameType; 72 bool public useFaultProofs; 73 bool public usePlasma; 74 uint256 public daChallengeWindow; 75 uint256 public daResolveWindow; 76 uint256 public daBondSize; 77 uint256 public daResolverRefundPercentage; 78 79 function read(string memory _path) public { 80 console.log("DeployConfig: reading file %s", _path); 81 try vm.readFile(_path) returns (string memory data) { 82 _json = data; 83 } catch { 84 require(false, string.concat("Cannot find deploy config file at ", _path)); 85 } 86 87 finalSystemOwner = stdJson.readAddress(_json, "$.finalSystemOwner"); 88 superchainConfigGuardian = stdJson.readAddress(_json, "$.superchainConfigGuardian"); 89 l1ChainID = stdJson.readUint(_json, "$.l1ChainID"); 90 l2ChainID = stdJson.readUint(_json, "$.l2ChainID"); 91 l2BlockTime = stdJson.readUint(_json, "$.l2BlockTime"); 92 maxSequencerDrift = stdJson.readUint(_json, "$.maxSequencerDrift"); 93 sequencerWindowSize = stdJson.readUint(_json, "$.sequencerWindowSize"); 94 channelTimeout = stdJson.readUint(_json, "$.channelTimeout"); 95 p2pSequencerAddress = stdJson.readAddress(_json, "$.p2pSequencerAddress"); 96 batchInboxAddress = stdJson.readAddress(_json, "$.batchInboxAddress"); 97 batchSenderAddress = stdJson.readAddress(_json, "$.batchSenderAddress"); 98 l2OutputOracleSubmissionInterval = stdJson.readUint(_json, "$.l2OutputOracleSubmissionInterval"); 99 _l2OutputOracleStartingTimestamp = stdJson.readInt(_json, "$.l2OutputOracleStartingTimestamp"); 100 l2OutputOracleStartingBlockNumber = stdJson.readUint(_json, "$.l2OutputOracleStartingBlockNumber"); 101 l2OutputOracleProposer = stdJson.readAddress(_json, "$.l2OutputOracleProposer"); 102 l2OutputOracleChallenger = stdJson.readAddress(_json, "$.l2OutputOracleChallenger"); 103 finalizationPeriodSeconds = stdJson.readUint(_json, "$.finalizationPeriodSeconds"); 104 fundDevAccounts = stdJson.readBool(_json, "$.fundDevAccounts"); 105 proxyAdminOwner = stdJson.readAddress(_json, "$.proxyAdminOwner"); 106 baseFeeVaultRecipient = stdJson.readAddress(_json, "$.baseFeeVaultRecipient"); 107 baseFeeVaultMinimumWithdrawalAmount = stdJson.readUint(_json, "$.baseFeeVaultMinimumWithdrawalAmount"); 108 l1FeeVaultRecipient = stdJson.readAddress(_json, "$.l1FeeVaultRecipient"); 109 l1FeeVaultMinimumWithdrawalAmount = stdJson.readUint(_json, "$.l1FeeVaultMinimumWithdrawalAmount"); 110 sequencerFeeVaultRecipient = stdJson.readAddress(_json, "$.sequencerFeeVaultRecipient"); 111 sequencerFeeVaultMinimumWithdrawalAmount = stdJson.readUint(_json, "$.sequencerFeeVaultMinimumWithdrawalAmount"); 112 sequencerFeeVaultWithdrawalNetwork = stdJson.readUint(_json, "$.sequencerFeeVaultWithdrawalNetwork"); 113 governanceTokenName = stdJson.readString(_json, "$.governanceTokenName"); 114 governanceTokenSymbol = stdJson.readString(_json, "$.governanceTokenSymbol"); 115 governanceTokenOwner = stdJson.readAddress(_json, "$.governanceTokenOwner"); 116 l2GenesisBlockGasLimit = stdJson.readUint(_json, "$.l2GenesisBlockGasLimit"); 117 l2GenesisBlockBaseFeePerGas = stdJson.readUint(_json, "$.l2GenesisBlockBaseFeePerGas"); 118 gasPriceOracleOverhead = stdJson.readUint(_json, "$.gasPriceOracleOverhead"); 119 gasPriceOracleScalar = stdJson.readUint(_json, "$.gasPriceOracleScalar"); 120 enableGovernance = stdJson.readBool(_json, "$.enableGovernance"); 121 eip1559Denominator = stdJson.readUint(_json, "$.eip1559Denominator"); 122 eip1559Elasticity = stdJson.readUint(_json, "$.eip1559Elasticity"); 123 systemConfigStartBlock = stdJson.readUint(_json, "$.systemConfigStartBlock"); 124 requiredProtocolVersion = stdJson.readUint(_json, "$.requiredProtocolVersion"); 125 recommendedProtocolVersion = stdJson.readUint(_json, "$.recommendedProtocolVersion"); 126 127 useFaultProofs = stdJson.readBool(_json, "$.useFaultProofs"); 128 proofMaturityDelaySeconds = stdJson.readUint(_json, "$.proofMaturityDelaySeconds"); 129 disputeGameFinalityDelaySeconds = stdJson.readUint(_json, "$.disputeGameFinalityDelaySeconds"); 130 respectedGameType = stdJson.readUint(_json, "$.respectedGameType"); 131 132 faultGameAbsolutePrestate = stdJson.readUint(_json, "$.faultGameAbsolutePrestate"); 133 faultGameMaxDepth = stdJson.readUint(_json, "$.faultGameMaxDepth"); 134 faultGameSplitDepth = stdJson.readUint(_json, "$.faultGameSplitDepth"); 135 faultGameMaxDuration = stdJson.readUint(_json, "$.faultGameMaxDuration"); 136 faultGameGenesisBlock = stdJson.readUint(_json, "$.faultGameGenesisBlock"); 137 faultGameGenesisOutputRoot = stdJson.readBytes32(_json, "$.faultGameGenesisOutputRoot"); 138 faultGameWithdrawalDelay = stdJson.readUint(_json, "$.faultGameWithdrawalDelay"); 139 140 preimageOracleMinProposalSize = stdJson.readUint(_json, "$.preimageOracleMinProposalSize"); 141 preimageOracleChallengePeriod = stdJson.readUint(_json, "$.preimageOracleChallengePeriod"); 142 143 usePlasma = _readOr(_json, "$.usePlasma", false); 144 daChallengeWindow = _readOr(_json, "$.daChallengeWindow", 1000); 145 daResolveWindow = _readOr(_json, "$.daResolveWindow", 1000); 146 daBondSize = _readOr(_json, "$.daBondSize", 1000000000); 147 daResolverRefundPercentage = _readOr(_json, "$.daResolverRefundPercentage", 0); 148 } 149 150 function l1StartingBlockTag() public returns (bytes32) { 151 try vm.parseJsonBytes32(_json, "$.l1StartingBlockTag") returns (bytes32 tag) { 152 return tag; 153 } catch { 154 try vm.parseJsonString(_json, "$.l1StartingBlockTag") returns (string memory tag) { 155 return _getBlockByTag(tag); 156 } catch { 157 try vm.parseJsonUint(_json, "$.l1StartingBlockTag") returns (uint256 tag) { 158 return _getBlockByTag(vm.toString(tag)); 159 } catch { } 160 } 161 } 162 revert("l1StartingBlockTag must be a bytes32, string or uint256 or cannot fetch l1StartingBlockTag"); 163 } 164 165 function l2OutputOracleStartingTimestamp() public returns (uint256) { 166 if (_l2OutputOracleStartingTimestamp < 0) { 167 bytes32 tag = l1StartingBlockTag(); 168 string[] memory cmd = new string[](3); 169 cmd[0] = Executables.bash; 170 cmd[1] = "-c"; 171 cmd[2] = string.concat("cast block ", vm.toString(tag), " --json | ", Executables.jq, " .timestamp"); 172 bytes memory res = vm.ffi(cmd); 173 return stdJson.readUint(string(res), ""); 174 } 175 return uint256(_l2OutputOracleStartingTimestamp); 176 } 177 178 /// @notice Allow the `usePlasma` config to be overridden in testing environments 179 function setUsePlasma(bool _usePlasma) public { 180 usePlasma = _usePlasma; 181 } 182 183 function _getBlockByTag(string memory _tag) internal returns (bytes32) { 184 string[] memory cmd = new string[](3); 185 cmd[0] = Executables.bash; 186 cmd[1] = "-c"; 187 cmd[2] = string.concat("cast block ", _tag, " --json | ", Executables.jq, " -r .hash"); 188 bytes memory res = vm.ffi(cmd); 189 return abi.decode(res, (bytes32)); 190 } 191 192 function _readOr(string memory json, string memory key, bool defaultValue) internal view returns (bool) { 193 return vm.keyExists(json, key) ? stdJson.readBool(json, key) : defaultValue; 194 } 195 196 function _readOr(string memory json, string memory key, uint256 defaultValue) internal view returns (uint256) { 197 return vm.keyExists(json, key) ? stdJson.readUint(json, key) : defaultValue; 198 } 199 }