From 63e3606007158701f47c2532dd585c7d13741271 Mon Sep 17 00:00:00 2001 From: Danil Date: Mon, 29 Jul 2024 14:33:49 +0200 Subject: [PATCH] Deploy upgrader (#644) Signed-off-by: Danil --- ...dges.toml => config-deploy-l2-config.toml} | 0 ...edBridgeOnL2.sol => DeployL2Contracts.sol} | 56 ++++++++++++++++--- 2 files changed, 49 insertions(+), 7 deletions(-) rename l1-contracts/deploy-script-config-template/{config-initialize-shared-bridges.toml => config-deploy-l2-config.toml} (100%) rename l1-contracts/deploy-scripts/{InitializeSharedBridgeOnL2.sol => DeployL2Contracts.sol} (77%) diff --git a/l1-contracts/deploy-script-config-template/config-initialize-shared-bridges.toml b/l1-contracts/deploy-script-config-template/config-deploy-l2-config.toml similarity index 100% rename from l1-contracts/deploy-script-config-template/config-initialize-shared-bridges.toml rename to l1-contracts/deploy-script-config-template/config-deploy-l2-config.toml diff --git a/l1-contracts/deploy-scripts/InitializeSharedBridgeOnL2.sol b/l1-contracts/deploy-scripts/DeployL2Contracts.sol similarity index 77% rename from l1-contracts/deploy-scripts/InitializeSharedBridgeOnL2.sol rename to l1-contracts/deploy-scripts/DeployL2Contracts.sol index 8ca7fce03..906ae831c 100644 --- a/l1-contracts/deploy-scripts/InitializeSharedBridgeOnL2.sol +++ b/l1-contracts/deploy-scripts/DeployL2Contracts.sol @@ -23,6 +23,7 @@ contract DeployL2Script is Script { uint256 eraChainId; address l2SharedBridgeImplementation; address l2SharedBridgeProxy; + address forceDeployUpgraderAddress; } struct ContractsBytecodes { @@ -31,6 +32,7 @@ contract DeployL2Script is Script { bytes l2StandardErc20Bytecode; bytes l2SharedBridgeBytecode; bytes l2SharedBridgeProxyBytecode; + bytes forceDeployUpgrader; } function run() public { @@ -41,6 +43,28 @@ contract DeployL2Script is Script { deploySharedBridge(); deploySharedBridgeProxy(); initializeChain(); + deployForceDeployer(); + + saveOutput(); + } + + function runDeploySharedBridge() public { + initializeConfig(); + loadContracts(); + + deployFactoryDeps(); + deploySharedBridge(); + deploySharedBridgeProxy(); + initializeChain(); + + saveOutput(); + } + + function runDefaultUpgrader() public { + initializeConfig(); + loadContracts(); + + deployForceDeployer(); saveOutput(); } @@ -64,11 +88,14 @@ contract DeployL2Script is Script { contracts.l2SharedBridgeProxyBytecode = Utils.readHardhatBytecode( "/../l2-contracts/artifacts-zk/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.json" ); + contracts.forceDeployUpgrader = Utils.readHardhatBytecode( + "/../l2-contracts/artifacts-zk/contracts/ForceDeployUpgrader.sol/ForceDeployUpgrader.json" + ); } function initializeConfig() internal { string memory root = vm.projectRoot(); - string memory path = string.concat(root, "/script-config/config-initialize-shared-bridges.toml"); + string memory path = string.concat(root, "/script-config/config-deploy-l2-contracts.toml"); string memory toml = vm.readFile(path); config.bridgehubAddress = toml.readAddress("$.bridgehub"); config.governance = toml.readAddress("$.governance"); @@ -80,13 +107,14 @@ contract DeployL2Script is Script { function saveOutput() internal { vm.serializeAddress("root", "l2_shared_bridge_implementation", config.l2SharedBridgeImplementation); - string memory toml = vm.serializeAddress("root", "l2_shared_bridge_proxy", config.l2SharedBridgeProxy); + vm.serializeAddress("root", "l2_shared_bridge_proxy", config.l2SharedBridgeProxy); + string memory toml = vm.serializeAddress("root", "l2_default_upgrader", config.forceDeployUpgraderAddress); string memory root = vm.projectRoot(); - string memory path = string.concat(root, "/script-out/output-initialize-shared-bridges.toml"); + string memory path = string.concat(root, "/script-out/output-deploy-l2-contracts.toml"); vm.writeToml(toml, path); } - function deployFactoryDeps() public { + function deployFactoryDeps() internal { bytes[] memory factoryDeps = new bytes[](3); factoryDeps[0] = contracts.l2StandardErc20FactoryBytecode; factoryDeps[1] = contracts.l2StandardErc20Bytecode; @@ -94,7 +122,7 @@ contract DeployL2Script is Script { Utils.publishBytecodes(factoryDeps, config.chainId, config.bridgehubAddress, config.l1SharedBridgeProxy); } - function deploySharedBridge() public { + function deploySharedBridge() internal { bytes[] memory factoryDeps = new bytes[](1); factoryDeps[0] = contracts.beaconProxy; @@ -112,7 +140,21 @@ contract DeployL2Script is Script { }); } - function deploySharedBridgeProxy() public { + function deployForceDeployer() internal { + bytes[] memory factoryDeps = new bytes[](0); + config.forceDeployUpgraderAddress = Utils.deployThroughL1({ + bytecode: contracts.forceDeployUpgrader, + constructorargs: "", + create2salt: "", + l2GasLimit: Utils.MAX_PRIORITY_TX_GAS, + factoryDeps: factoryDeps, + chainId: config.chainId, + bridgehubAddress: config.bridgehubAddress, + l1SharedBridgeProxy: config.l1SharedBridgeProxy + }); + } + + function deploySharedBridgeProxy() internal { address l2GovernorAddress = AddressAliasHelper.applyL1ToL2Alias(config.governance); bytes32 l2StandardErc20BytecodeHash = L2ContractHelper.hashL2Bytecode(contracts.beaconProxy); @@ -143,7 +185,7 @@ contract DeployL2Script is Script { }); } - function initializeChain() public { + function initializeChain() internal { L1SharedBridge bridge = L1SharedBridge(config.l1SharedBridgeProxy); Utils.executeUpgrade({