From 2c47e27799f9e4240578b1660dc63808cae639ab Mon Sep 17 00:00:00 2001 From: redhdx Date: Sat, 14 Sep 2024 10:42:05 +0800 Subject: [PATCH] feature(op-node): add DeployUpgrades.s.sol --- .../scripts/DeployUpgrades.s.sol | 42 +++++++++++--- .../scripts/UpgradeHelper.sol | 55 +++++++++++++++++++ 2 files changed, 89 insertions(+), 8 deletions(-) create mode 100644 packages/contracts-bedrock/scripts/UpgradeHelper.sol diff --git a/packages/contracts-bedrock/scripts/DeployUpgrades.s.sol b/packages/contracts-bedrock/scripts/DeployUpgrades.s.sol index 591eca7d0..3d5ad9e1e 100644 --- a/packages/contracts-bedrock/scripts/DeployUpgrades.s.sol +++ b/packages/contracts-bedrock/scripts/DeployUpgrades.s.sol @@ -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. @@ -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(); @@ -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 // //////////////////////////////////////////////////////////////// @@ -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); } diff --git a/packages/contracts-bedrock/scripts/UpgradeHelper.sol b/packages/contracts-bedrock/scripts/UpgradeHelper.sol new file mode 100644 index 000000000..861d7464e --- /dev/null +++ b/packages/contracts-bedrock/scripts/UpgradeHelper.sol @@ -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"); + } + +}