Skip to content

Commit

Permalink
Merge pull request ethereum-optimism#7203 from ethereum-optimism/harr…
Browse files Browse the repository at this point in the history
…y/deploy-periphery

Deployment script for contracts-periphery and faucet
  • Loading branch information
OptimismBot authored Sep 21, 2023
2 parents b245c0a + 97afc2e commit adf55b3
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 2 deletions.
2 changes: 1 addition & 1 deletion op-bindings/bindings/mips_more.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion op-bindings/bindings/preimageoracle_more.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/contracts-bedrock/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ fs_permissions = [
{ access='read-write', path='./.resource-metering.csv' },
{ access='read-write', path='./deployments/' },
{ access='read', path='./deploy-config/' },
{ access='read', path='./periphery-deploy-config/' },
{ access='read', path='./broadcast/' },
{ access='read', path = './forge-artifacts/' },
{ access='write', path='./semver-lock.json' },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"faucetAdmin": "0xf2C22a95bBA6F35545269183D8d1751a27F047F6"
}
112 changes: 112 additions & 0 deletions packages/contracts-bedrock/scripts/DeployPeriphery.s.sol
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 packages/contracts-bedrock/scripts/PeripheryDeployConfig.s.sol
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");
}
}

0 comments on commit adf55b3

Please sign in to comment.