github.com/ethereum-optimism/optimism@v1.7.2/packages/contracts-bedrock/scripts/Config.sol (about)

     1  // SPDX-License-Identifier: MIT
     2  pragma solidity ^0.8.0;
     3  
     4  import { Vm } from "forge-std/Vm.sol";
     5  import { Chains } from "scripts/Chains.sol";
     6  
     7  /// @title Config
     8  /// @notice Contains all env var based config. Add any new env var parsing to this file
     9  ///         to ensure that all config is in a single place.
    10  library Config {
    11      /// @notice Foundry cheatcode VM.
    12      Vm private constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code")))));
    13  
    14      /// @notice Returns the path on the local filesystem where the deployment artifact is
    15      ///         written to disk after doing a deployment.
    16      function deploymentOutfile() internal view returns (string memory _env) {
    17          _env = vm.envOr(
    18              "DEPLOYMENT_OUTFILE", string.concat(vm.projectRoot(), "/deployments/", _getDeploymentContext(), "/.deploy")
    19          );
    20      }
    21  
    22      /// @notice Returns the path on the local filesystem where the deploy config is
    23      function deployConfigPath() internal view returns (string memory _env) {
    24          _env = vm.envOr(
    25              "DEPLOY_CONFIG_PATH", string.concat(vm.projectRoot(), "/deploy-config/", _getDeploymentContext(), ".json")
    26          );
    27      }
    28  
    29      /// @notice Returns the chainid from the EVM context or the value of the CHAIN_ID env var as
    30      ///         an override.
    31      function chainID() internal view returns (uint256 _env) {
    32          _env = vm.envOr("CHAIN_ID", block.chainid);
    33      }
    34  
    35      /// @notice Returns the value of the env var CONTRACT_ADDRESSES_PATH which is a JSON key/value
    36      ///         pair of contract names and their addresses. Each key/value pair is passed to `save`
    37      ///         which then backs the `getAddress` function.
    38      function contractAddressesPath() internal view returns (string memory _env) {
    39          _env = vm.envOr("CONTRACT_ADDRESSES_PATH", string(""));
    40      }
    41  
    42      /// @notice Returns the deployment context which was only useful in the hardhat deploy style
    43      ///         of deployments. It is now DEPRECATED and will be removed in the future.
    44      function deploymentContext() internal view returns (string memory _env) {
    45          _env = vm.envOr("DEPLOYMENT_CONTEXT", string(""));
    46      }
    47  
    48      /// @notice The CREATE2 salt to be used when deploying the implementations.
    49      function implSalt() internal view returns (string memory _env) {
    50          _env = vm.envOr("IMPL_SALT", string("ethers phoenix"));
    51      }
    52  
    53      /// @notice Returns the path that the state dump file should be written to or read from
    54      ///         on the local filesystem.
    55      function stateDumpPath(string memory _name) internal view returns (string memory _env) {
    56          _env = vm.envOr(
    57              "STATE_DUMP_PATH", string.concat(vm.projectRoot(), "/", _name, "-", vm.toString(block.chainid), ".json")
    58          );
    59      }
    60  
    61      /// @notice Returns the sig of the entrypoint to the deploy script. By default, it is `run`.
    62      ///         This was useful for creating hardhat deploy style artifacts and will be removed in a future release.
    63      function sig() internal view returns (string memory _env) {
    64          _env = vm.envOr("SIG", string("run"));
    65      }
    66  
    67      /// @notice Returns the name of the file that the forge deployment artifact is written to on the local
    68      ///         filesystem. By default, it is the name of the deploy script with the suffix `-latest.json`.
    69      ///         This was useful for creating hardhat deploy style artifacts and will be removed in a future release.
    70      function deployFile(string memory _sig) internal view returns (string memory _env) {
    71          _env = vm.envOr("DEPLOY_FILE", string.concat(_sig, "-latest.json"));
    72      }
    73  
    74      /// @notice Returns the private key that is used to configure drippie.
    75      function drippieOwnerPrivateKey() internal view returns (uint256 _env) {
    76          _env = vm.envUint("DRIPPIE_OWNER_PRIVATE_KEY");
    77      }
    78  
    79      /// @notice The context of the deployment is used to namespace the artifacts.
    80      ///         An unknown context will use the chainid as the context name.
    81      ///         This is legacy code and should be removed in the future.
    82      function _getDeploymentContext() private view returns (string memory) {
    83          string memory context = deploymentContext();
    84          if (bytes(context).length > 0) {
    85              return context;
    86          }
    87  
    88          uint256 chainid = Config.chainID();
    89          if (chainid == Chains.Mainnet) {
    90              return "mainnet";
    91          } else if (chainid == Chains.Goerli) {
    92              return "goerli";
    93          } else if (chainid == Chains.OPGoerli) {
    94              return "optimism-goerli";
    95          } else if (chainid == Chains.OPMainnet) {
    96              return "optimism-mainnet";
    97          } else if (chainid == Chains.LocalDevnet || chainid == Chains.GethDevnet) {
    98              return "devnetL1";
    99          } else if (chainid == Chains.Hardhat) {
   100              return "hardhat";
   101          } else if (chainid == Chains.Sepolia) {
   102              return "sepolia";
   103          } else if (chainid == Chains.OPSepolia) {
   104              return "optimism-sepolia";
   105          } else {
   106              return vm.toString(chainid);
   107          }
   108      }
   109  }