forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ethereum-optimism#7203 from ethereum-optimism/harr…
…y/deploy-periphery Deployment script for contracts-periphery and faucet
- Loading branch information
Showing
6 changed files
with
146 additions
and
2 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/contracts-bedrock/periphery-deploy-config/optimism-goerli.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"faucetAdmin": "0xf2C22a95bBA6F35545269183D8d1751a27F047F6" | ||
} |
112 changes: 112 additions & 0 deletions
112
packages/contracts-bedrock/scripts/DeployPeriphery.s.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import { console2 as console } from "forge-std/console2.sol"; | ||
|
||
import { Deployer } from "./Deployer.sol"; | ||
import { PeripheryDeployConfig } from "./PeripheryDeployConfig.s.sol"; | ||
|
||
import { ProxyAdmin } from "src/universal/ProxyAdmin.sol"; | ||
import { Proxy } from "src/universal/Proxy.sol"; | ||
|
||
import { Faucet } from "src/periphery/faucet/Faucet.sol"; | ||
|
||
/// @title DeployPeriphery | ||
/// @notice Script used to deploy periphery contracts. | ||
contract DeployPeriphery is Deployer { | ||
PeripheryDeployConfig cfg; | ||
|
||
/// @notice The name of the script, used to ensure the right deploy artifacts | ||
/// are used. | ||
function name() public pure override returns (string memory) { | ||
return "DeployPeriphery"; | ||
} | ||
|
||
function setUp() public override { | ||
super.setUp(); | ||
|
||
string memory path = string.concat(vm.projectRoot(), "/periphery-deploy-config/", deploymentContext, ".json"); | ||
cfg = new PeripheryDeployConfig(path); | ||
|
||
console.log("Deploying from %s", deployScript); | ||
console.log("Deployment context: %s", deploymentContext); | ||
} | ||
|
||
/// @notice Deploy all of the periphery contracts | ||
function run() public { | ||
console.log("Deploying all periphery contracts"); | ||
|
||
deployProxies(); | ||
deployImplementations(); | ||
|
||
initializeFaucet(); | ||
} | ||
|
||
/// @notice Deploy all of the proxies | ||
function deployProxies() public { | ||
deployProxyAdmin(); | ||
|
||
deployFaucetProxy(); | ||
} | ||
|
||
/// @notice Deploy all of the implementations | ||
function deployImplementations() public { | ||
deployFaucet(); | ||
} | ||
|
||
/// @notice Modifier that wraps a function in broadcasting. | ||
modifier broadcast() { | ||
vm.startBroadcast(); | ||
_; | ||
vm.stopBroadcast(); | ||
} | ||
|
||
/// @notice Deploy the ProxyAdmin | ||
function deployProxyAdmin() public broadcast returns (address addr_) { | ||
ProxyAdmin admin = new ProxyAdmin{ salt: keccak256(bytes("ProxyAdmin")) }({ | ||
_owner: msg.sender | ||
}); | ||
require(admin.owner() == msg.sender); | ||
|
||
save("ProxyAdmin", address(admin)); | ||
console.log("ProxyAdmin deployed at %s", address(admin)); | ||
addr_ = address(admin); | ||
} | ||
|
||
/// @notice Deploy the FaucetProxy | ||
function deployFaucetProxy() public broadcast returns (address addr_) { | ||
address proxyAdmin = mustGetAddress("ProxyAdmin"); | ||
Proxy proxy = new Proxy{ salt: keccak256(bytes("FaucetProxy")) }({ | ||
_admin: proxyAdmin | ||
}); | ||
|
||
address admin = address(uint160(uint256(vm.load(address(proxy), OWNER_KEY)))); | ||
require(admin == proxyAdmin); | ||
|
||
save("FaucetProxy", address(proxy)); | ||
console.log("FaucetProxy deployed at %s", address(proxy)); | ||
|
||
addr_ = address(proxy); | ||
} | ||
|
||
/// @notice Deploy the faucet contract. | ||
function deployFaucet() public broadcast returns (address) { | ||
Faucet faucet = new Faucet{ salt: keccak256(bytes("Faucet")) }(cfg.faucetAdmin()); | ||
require(faucet.ADMIN() == cfg.faucetAdmin()); | ||
|
||
save("Faucet", address(faucet)); | ||
console.log("Faucet deployed at %s", address(faucet)); | ||
|
||
return address(faucet); | ||
} | ||
|
||
/// @notice Initialize the Faucet | ||
function initializeFaucet() public broadcast { | ||
ProxyAdmin proxyAdmin = ProxyAdmin(mustGetAddress("ProxyAdmin")); | ||
address faucetProxy = mustGetAddress("FaucetProxy"); | ||
address faucet = mustGetAddress("Faucet"); | ||
|
||
proxyAdmin.upgrade({ _proxy: payable(faucetProxy), _implementation: faucet }); | ||
require(Faucet(payable(faucetProxy)).ADMIN() == Faucet(payable(faucet)).ADMIN()); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
packages/contracts-bedrock/scripts/PeripheryDeployConfig.s.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import { Script } from "forge-std/Script.sol"; | ||
import { console2 as console } from "forge-std/console2.sol"; | ||
import { stdJson } from "forge-std/StdJson.sol"; | ||
|
||
/// @title PeripheryDeployConfig | ||
/// @notice Represents the configuration required to deploy the periphery contracts. 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. | ||
contract PeripheryDeployConfig is Script { | ||
string internal _json; | ||
|
||
address public faucetAdmin; | ||
|
||
constructor(string memory _path) { | ||
console.log("PeripheryDeployConfig: reading file %s", _path); | ||
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; | ||
} | ||
|
||
faucetAdmin = stdJson.readAddress(_json, "$.faucetAdmin"); | ||
} | ||
} |