DeployConfig.s.sol 7.33 KB
Newer Older
Mark Tyneway's avatar
Mark Tyneway committed
1
// SPDX-License-Identifier: MIT
2
pragma solidity ^0.8.0;
Mark Tyneway's avatar
Mark Tyneway committed
3 4 5 6

import { Script } from "forge-std/Script.sol";
import { console2 as console } from "forge-std/console2.sol";
import { stdJson } from "forge-std/StdJson.sol";
7
import { Executables } from "./Executables.sol";
8
import { Chains } from "./Chains.sol";
Mark Tyneway's avatar
Mark Tyneway committed
9 10

/// @title DeployConfig
11 12 13
/// @notice Represents the configuration required to deploy the system. It is expected
///         to read the file from JSON. A future improvement would be to have fallback
///         values if they are not defined in the JSON themselves.
Mark Tyneway's avatar
Mark Tyneway committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
contract DeployConfig is Script {
    string internal _json;

    address public finalSystemOwner;
    address public portalGuardian;
    uint256 public l1ChainID;
    uint256 public l2ChainID;
    uint256 public l2BlockTime;
    uint256 public maxSequencerDrift;
    uint256 public sequencerWindowSize;
    uint256 public channelTimeout;
    address public p2pSequencerAddress;
    address public batchInboxAddress;
    address public batchSenderAddress;
    uint256 public l2OutputOracleSubmissionInterval;
    int256 internal _l2OutputOracleStartingTimestamp;
    uint256 public l2OutputOracleStartingBlockNumber;
    address public l2OutputOracleProposer;
    address public l2OutputOracleChallenger;
    uint256 public finalizationPeriodSeconds;
    address public proxyAdminOwner;
    address public baseFeeVaultRecipient;
    address public l1FeeVaultRecipient;
    address public sequencerFeeVaultRecipient;
    string public governanceTokenName;
    string public governanceTokenSymbol;
    address public governanceTokenOwner;
    uint256 public l2GenesisBlockGasLimit;
    uint256 public l2GenesisBlockBaseFeePerGas;
    uint256 public gasPriceOracleOverhead;
    uint256 public gasPriceOracleScalar;
    uint256 public eip1559Denominator;
    uint256 public eip1559Elasticity;
47 48
    uint256 public faultGameAbsolutePrestate;
    uint256 public faultGameMaxDepth;
49
    uint256 public faultGameMaxDuration;
50
    uint256 public systemConfigStartBlock;
51 52
    uint256 public requiredProtocolVersion;
    uint256 public recommendedProtocolVersion;
Mark Tyneway's avatar
Mark Tyneway committed
53 54

    constructor(string memory _path) {
55
        console.log("DeployConfig: reading file %s", _path);
56 57 58 59 60 61
        try vm.readFile(_path) returns (string memory data) {
            _json = data;
        } catch {
            console.log("Warning: unable to read config. Do not deploy unless you are not using config.");
            return;
        }
Mark Tyneway's avatar
Mark Tyneway committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92

        finalSystemOwner = stdJson.readAddress(_json, "$.finalSystemOwner");
        portalGuardian = stdJson.readAddress(_json, "$.portalGuardian");
        l1ChainID = stdJson.readUint(_json, "$.l1ChainID");
        l2ChainID = stdJson.readUint(_json, "$.l2ChainID");
        l2BlockTime = stdJson.readUint(_json, "$.l2BlockTime");
        maxSequencerDrift = stdJson.readUint(_json, "$.maxSequencerDrift");
        sequencerWindowSize = stdJson.readUint(_json, "$.sequencerWindowSize");
        channelTimeout = stdJson.readUint(_json, "$.channelTimeout");
        p2pSequencerAddress = stdJson.readAddress(_json, "$.p2pSequencerAddress");
        batchInboxAddress = stdJson.readAddress(_json, "$.batchInboxAddress");
        batchSenderAddress = stdJson.readAddress(_json, "$.batchSenderAddress");
        l2OutputOracleSubmissionInterval = stdJson.readUint(_json, "$.l2OutputOracleSubmissionInterval");
        _l2OutputOracleStartingTimestamp = stdJson.readInt(_json, "$.l2OutputOracleStartingTimestamp");
        l2OutputOracleStartingBlockNumber = stdJson.readUint(_json, "$.l2OutputOracleStartingBlockNumber");
        l2OutputOracleProposer = stdJson.readAddress(_json, "$.l2OutputOracleProposer");
        l2OutputOracleChallenger = stdJson.readAddress(_json, "$.l2OutputOracleChallenger");
        finalizationPeriodSeconds = stdJson.readUint(_json, "$.finalizationPeriodSeconds");
        proxyAdminOwner = stdJson.readAddress(_json, "$.proxyAdminOwner");
        baseFeeVaultRecipient = stdJson.readAddress(_json, "$.baseFeeVaultRecipient");
        l1FeeVaultRecipient = stdJson.readAddress(_json, "$.l1FeeVaultRecipient");
        sequencerFeeVaultRecipient = stdJson.readAddress(_json, "$.sequencerFeeVaultRecipient");
        governanceTokenName = stdJson.readString(_json, "$.governanceTokenName");
        governanceTokenSymbol = stdJson.readString(_json, "$.governanceTokenSymbol");
        governanceTokenOwner = stdJson.readAddress(_json, "$.governanceTokenOwner");
        l2GenesisBlockGasLimit = stdJson.readUint(_json, "$.l2GenesisBlockGasLimit");
        l2GenesisBlockBaseFeePerGas = stdJson.readUint(_json, "$.l2GenesisBlockBaseFeePerGas");
        gasPriceOracleOverhead = stdJson.readUint(_json, "$.gasPriceOracleOverhead");
        gasPriceOracleScalar = stdJson.readUint(_json, "$.gasPriceOracleScalar");
        eip1559Denominator = stdJson.readUint(_json, "$.eip1559Denominator");
        eip1559Elasticity = stdJson.readUint(_json, "$.eip1559Elasticity");
93
        systemConfigStartBlock = stdJson.readUint(_json, "$.systemConfigStartBlock");
94

95
        if (block.chainid == Chains.LocalDevnet || block.chainid == Chains.GethDevnet) {
96 97
            faultGameAbsolutePrestate = stdJson.readUint(_json, "$.faultGameAbsolutePrestate");
            faultGameMaxDepth = stdJson.readUint(_json, "$.faultGameMaxDepth");
98
            faultGameMaxDuration = stdJson.readUint(_json, "$.faultGameMaxDuration");
99 100 101 102 103 104 105
            requiredProtocolVersion = stdJson.readUint(_json, "$.requiredProtocolVersion");
            recommendedProtocolVersion = stdJson.readUint(_json, "$.recommendedProtocolVersion");
        }

        if (block.chainid == Chains.Goerli || block.chainid == Chains.Sepolia) {
            requiredProtocolVersion = stdJson.readUint(_json, "$.requiredProtocolVersion");
            recommendedProtocolVersion = stdJson.readUint(_json, "$.recommendedProtocolVersion");
106
        }
Mark Tyneway's avatar
Mark Tyneway committed
107 108 109 110 111 112 113
    }

    function l1StartingBlockTag() public returns (bytes32) {
        try vm.parseJsonBytes32(_json, "$.l1StartingBlockTag") returns (bytes32 tag) {
            return tag;
        } catch {
            try vm.parseJsonString(_json, "$.l1StartingBlockTag") returns (string memory tag) {
Mark Tyneway's avatar
Mark Tyneway committed
114
                return _getBlockByTag(tag);
Mark Tyneway's avatar
Mark Tyneway committed
115 116
            } catch {
                try vm.parseJsonUint(_json, "$.l1StartingBlockTag") returns (uint256 tag) {
Mark Tyneway's avatar
Mark Tyneway committed
117
                    return _getBlockByTag(vm.toString(tag));
118
                } catch { }
Mark Tyneway's avatar
Mark Tyneway committed
119 120
            }
        }
121
        revert("l1StartingBlockTag must be a bytes32, string or uint256 or cannot fetch l1StartingBlockTag");
Mark Tyneway's avatar
Mark Tyneway committed
122 123 124 125 126 127
    }

    function l2OutputOracleStartingTimestamp() public returns (uint256) {
        if (_l2OutputOracleStartingTimestamp < 0) {
            bytes32 tag = l1StartingBlockTag();
            string[] memory cmd = new string[](3);
128
            cmd[0] = Executables.bash;
Mark Tyneway's avatar
Mark Tyneway committed
129
            cmd[1] = "-c";
130
            cmd[2] = string.concat("cast block ", vm.toString(tag), " --json | ", Executables.jq, " .timestamp");
Mark Tyneway's avatar
Mark Tyneway committed
131 132 133 134 135
            bytes memory res = vm.ffi(cmd);
            return stdJson.readUint(string(res), "");
        }
        return uint256(_l2OutputOracleStartingTimestamp);
    }
Mark Tyneway's avatar
Mark Tyneway committed
136 137 138

    function _getBlockByTag(string memory _tag) internal returns (bytes32) {
        string[] memory cmd = new string[](3);
139
        cmd[0] = Executables.bash;
Mark Tyneway's avatar
Mark Tyneway committed
140
        cmd[1] = "-c";
141
        cmd[2] = string.concat("cast block ", _tag, " --json | ", Executables.jq, " -r .hash");
Mark Tyneway's avatar
Mark Tyneway committed
142 143 144
        bytes memory res = vm.ffi(cmd);
        return abi.decode(res, (bytes32));
    }
Mark Tyneway's avatar
Mark Tyneway committed
145
}