Skip to content

Commit

Permalink
feature(op-node): add DeployUpgrades.s.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
redhdx committed Sep 14, 2024
1 parent a3277e8 commit 2c47e27
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 8 deletions.
42 changes: 34 additions & 8 deletions packages/contracts-bedrock/scripts/DeployUpgrades.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { LibStateDiff } from "scripts/libraries/LibStateDiff.sol";
import { EIP1967Helper } from "test/mocks/EIP1967Helper.sol";
import { ForgeArtifacts } from "scripts/ForgeArtifacts.sol";
import { Process } from "scripts/libraries/Process.sol";
import { UpgradeHelper } from "scripts/UpgradeHelper.sol";

/// @title Deploy
/// @notice Script used to deploy a bedrock system. The entire system is deployed within the `run` function.
Expand Down Expand Up @@ -99,6 +100,9 @@ contract Deploy is Deployer {
/// @notice Internal function containing the deploy logic.
function _run() internal virtual {
console.log("start of L1 Deploy!");
// TODO just for local poc, remove it
deployProxyAdmin();
console.log("set up ProxyAdmin!");
setupSuperchain();
console.log("set up superchain!");
setupOpChain();
Expand Down Expand Up @@ -158,6 +162,28 @@ contract Deploy is Deployer {
addr_ = address(setter);
}

/// @notice Deploy the UpgradeHelper contract, used for upgrades.
function deployUpgradeHelper() public broadcast returns (address addr_) {
console.log("Deploying UpgradeHelper");
UpgradeHelper upgradeHelper = new UpgradeHelper{ salt: _implSalt() }();
console.log("UpgradeHelper deployed at: %s", address(upgradeHelper));
string memory version = upgradeHelper.version();
console.log("UpgradeHelper version: %s", version);
save("UpgradeHelper", address(upgradeHelper));
addr_ = address(upgradeHelper);
}

/// @notice Deploy the ProxyAdmin
function deployProxyAdmin() public broadcast returns (address addr_) {
console.log("Deploying ProxyAdmin");
ProxyAdmin admin = new ProxyAdmin({ _owner: msg.sender });
require(admin.owner() == msg.sender);
console.log("adminOwner is %s", admin.owner());
save("ProxyAdmin", address(admin));
console.log("ProxyAdmin deployed at %s", address(admin));
addr_ = address(admin);
}

////////////////////////////////////////////////////////////////
// Proxy Deployment Functions //
////////////////////////////////////////////////////////////////
Expand All @@ -167,14 +193,14 @@ contract Deploy is Deployer {
/// @return addr_ The address of the deployed proxy contract.
function deployERC1967Proxy(string memory _name) public returns (address addr_) {
uint256 chainid = block.chainid;
address proxyAdmin;
if (chainid == Chains.BscTestnet) {
proxyAdmin = Constants.BSCTESTNET_PROXY_ADMIN;
} else if (chainid == Chains.BscMainnet) {
proxyAdmin = Constants.BSCMAINNET_PROXY_ADMIN;
} else if (chainid == Chains.BscQAnet) {
proxyAdmin = Constants.BSCQANET_PROXY_ADMIN;
}
address proxyAdmin = mustGetAddress("ProxyAdmin");
// if (chainid == Chains.BscTestnet) {
// proxyAdmin = Constants.BSCTESTNET_PROXY_ADMIN;
// } else if (chainid == Chains.BscMainnet) {
// proxyAdmin = Constants.BSCMAINNET_PROXY_ADMIN;
// } else if (chainid == Chains.BscQAnet) {
// proxyAdmin = Constants.BSCQANET_PROXY_ADMIN;
// }
console.log("proxyAdmin is %s", proxyAdmin);
addr_ = deployERC1967ProxyWithOwner(_name, proxyAdmin);
}
Expand Down
55 changes: 55 additions & 0 deletions packages/contracts-bedrock/scripts/UpgradeHelper.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import { VmSafe } from "forge-std/Vm.sol";
import { Script } from "forge-std/Script.sol";

import { console2 as console } from "forge-std/console2.sol";
import { stdJson } from "forge-std/StdJson.sol";

import { Deployer } from "scripts/Deployer.sol";

import { Proxy } from "src/universal/Proxy.sol";
import { L1StandardBridge } from "src/L1/L1StandardBridge.sol";
import { StandardBridge } from "src/universal/StandardBridge.sol";
import { OptimismPortal } from "src/L1/OptimismPortal.sol";
import { L1CrossDomainMessenger } from "src/L1/L1CrossDomainMessenger.sol";
import { L2OutputOracle } from "src/L1/L2OutputOracle.sol";
import { OptimismMintableERC20Factory } from "src/universal/OptimismMintableERC20Factory.sol";
import { SuperchainConfig } from "src/L1/SuperchainConfig.sol";
import { SystemConfig } from "src/L1/SystemConfig.sol";
import { ResourceMetering } from "src/L1/ResourceMetering.sol";
import { Constants } from "src/libraries/Constants.sol";
import { L1ERC721Bridge } from "src/L1/L1ERC721Bridge.sol";
import { ProtocolVersions, ProtocolVersion } from "src/L1/ProtocolVersions.sol";
import { StorageSetter } from "src/universal/StorageSetter.sol";
import { ProxyAdmin } from "src/universal/ProxyAdmin.sol";
import { Predeploys } from "src/libraries/Predeploys.sol";
import { Chains } from "scripts/Chains.sol";
import { Config } from "scripts/Config.sol";

import { ChainAssertions } from "scripts/ChainAssertions.sol";
import { Types } from "scripts/Types.sol";
import { LibStateDiff } from "scripts/libraries/LibStateDiff.sol";
import { EIP1967Helper } from "test/mocks/EIP1967Helper.sol";
import { ForgeArtifacts } from "scripts/ForgeArtifacts.sol";
import { Process } from "scripts/libraries/Process.sol";

/// @title Upgrade
/// @notice Upgrade used to help upgrade opBNB contracts.
contract UpgradeHelper {

/// @notice Semantic version.
/// @custom:semver 1.0.0
string public constant version = "1.0.1";

function upgrade(address payable _proxyAdmin, address payable[] calldata _proxys, address[] calldata _implementations) public {
require(_proxys.length == _implementations.length, "proxy length not equal impl");
bytes memory _innerCallData = abi.encodeCall(SuperchainConfig.initialize, (_proxyAdmin, false));
(bool success, bytes memory data) = _proxyAdmin.delegatecall(
abi.encodeWithSignature("upgradeAndCall(address,address,bytes)", _proxys[0], _implementations[0], _innerCallData)
);
require(success, "superchainconfig upgrade failed");
}

}

0 comments on commit 2c47e27

Please sign in to comment.