Commit c561e1da authored by Maurelian's avatar Maurelian Committed by GitHub

Merge pull request #8428 from ethereum-optimism/ctb/flexible-deploy-addresses

contracts-bedrock: flexible deploy script addresses
parents c74620d4 d981ae87
...@@ -59,6 +59,11 @@ For all information about working on and contributing to Optimism's smart contra ...@@ -59,6 +59,11 @@ For all information about working on and contributing to Optimism's smart contra
The smart contracts are deployed using `foundry` with a `hardhat-deploy` compatibility layer. When the contracts are deployed, The smart contracts are deployed using `foundry` with a `hardhat-deploy` compatibility layer. When the contracts are deployed,
they will write a temp file to disk that can then be formatted into a `hardhat-deploy` style artifact by calling another script. they will write a temp file to disk that can then be formatted into a `hardhat-deploy` style artifact by calling another script.
The addresses in the `deployments` directory will be read into the script based on the backend's chain id.
To manually define the set of addresses used in the script, set the `CONTRACT_ADDRESSES_PATH` env var to a path on the local
filesystem that points to a JSON file full of key value pairs where the keys are names of contracts and the
values are addresses. This works well with the JSON files in `superchain-ops`.
### Configuration ### Configuration
Create or modify a file `<network-name>.json` inside of the [`deploy-config`](./deploy-config/) folder. Create or modify a file `<network-name>.json` inside of the [`deploy-config`](./deploy-config/) folder.
......
...@@ -54,6 +54,9 @@ import { LibStateDiff } from "scripts/libraries/LibStateDiff.sol"; ...@@ -54,6 +54,9 @@ import { LibStateDiff } from "scripts/libraries/LibStateDiff.sol";
/// To add a new contract to the system, add a public function that deploys that individual contract. /// To add a new contract to the system, add a public function that deploys that individual contract.
/// Then add a call to that function inside of `run`. Be sure to call the `save` function after each /// Then add a call to that function inside of `run`. Be sure to call the `save` function after each
/// deployment so that hardhat-deploy style artifacts can be generated using a call to `sync()`. /// deployment so that hardhat-deploy style artifacts can be generated using a call to `sync()`.
/// The `CONTRACT_ADDRESSES_PATH` environment variable can be set to a path that contains a JSON file full of
/// contract name to address pairs. That enables this script to be much more flexible in the way
/// it is used.
contract Deploy is Deployer { contract Deploy is Deployer {
DeployConfig public cfg; DeployConfig public cfg;
......
...@@ -116,6 +116,32 @@ abstract contract Deployer is Script { ...@@ -116,6 +116,32 @@ abstract contract Deployer is Script {
vm.writeJson("{}", tempDeploymentsPath); vm.writeJson("{}", tempDeploymentsPath);
} }
console.log("Storing temp deployment data in %s", tempDeploymentsPath); console.log("Storing temp deployment data in %s", tempDeploymentsPath);
// Load addresses from a JSON file if the CONTRACT_ADDRESSES_PATH environment variable
// is set. Great for loading addresses from `superchain-registry`.
string memory addresses = vm.envOr("CONTRACT_ADDRESSES_PATH", string(""));
if (bytes(addresses).length > 0) {
console.log("Loading addresses from %s", addresses);
_loadAddresses(addresses);
}
}
/// @notice Populates the addresses to be used in a script based on a JSON file.
/// The format of the JSON file is the same that it output by this script
/// as well as the JSON files that contain addresses in the `superchain-ops`
/// repo. The JSON key is the name of the contract and the value is an address.
function _loadAddresses(string memory _path) internal {
string[] memory commands = new string[](3);
commands[0] = "bash";
commands[1] = "-c";
commands[2] = string.concat("jq -cr < ", _path);
string memory json = string(vm.ffi(commands));
string[] memory keys = vm.parseJsonKeys(json, "");
for (uint256 i; i < keys.length; i++) {
string memory key = keys[i];
address addr = stdJson.readAddress(json, string.concat("$.", key));
save(key, addr);
}
} }
/// @notice Call this function to sync the deployment artifacts such that /// @notice Call this function to sync the deployment artifacts such that
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment