Skip to content

Commit

Permalink
fix: hyperchain migration fixes (#395)
Browse files Browse the repository at this point in the history
Co-authored-by: Stanislav Bezkorovainyi <[email protected]>
  • Loading branch information
kelemeno and StanislavBreadless authored Apr 24, 2024
1 parent 6139b72 commit 5016910
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 9 deletions.
64 changes: 59 additions & 5 deletions l1-contracts/src.ts/hyperchain-upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import type { Deployer } from "./deploy";
import type { ITransparentUpgradeableProxy } from "../typechain/ITransparentUpgradeableProxy";
import { ITransparentUpgradeableProxyFactory } from "../typechain/ITransparentUpgradeableProxyFactory";

import { L1SharedBridgeFactory } from "../typechain";
import { L1SharedBridgeFactory, StateTransitionManagerFactory } from "../typechain";

import { Interface } from "ethers/lib/utils";
import { ADDRESS_ONE } from "./utils";
import { ADDRESS_ONE, getAddressFromEnv } from "./utils";
import type { L2CanonicalTransaction, ProposedUpgrade, VerifierParams } from "./utils";

import {
Expand Down Expand Up @@ -231,7 +231,7 @@ async function integrateEraIntoBridgehubAndUpgradeL2SystemContract(deployer: Dep
const stateTransitionManager = deployer.stateTransitionManagerContract(deployer.deployWallet);

if (deployer.verbose) {
console.log("registering Era in stateTransitionManager");
console.log("Registering Era in stateTransitionManager");
}
const registerData = stateTransitionManager.interface.encodeFunctionData("registerAlreadyDeployedHyperchain", [
deployer.chainId,
Expand All @@ -240,7 +240,7 @@ async function integrateEraIntoBridgehubAndUpgradeL2SystemContract(deployer: Dep
await deployer.executeUpgrade(deployer.addresses.StateTransition.StateTransitionProxy, 0, registerData);
const bridgehub = deployer.bridgehubContract(deployer.deployWallet);
if (deployer.verbose) {
console.log("registering Era in Bridgehub");
console.log("Registering Era in Bridgehub");
}
const tx = await bridgehub.createNewChain(
deployer.chainId,
Expand All @@ -253,7 +253,9 @@ async function integrateEraIntoBridgehubAndUpgradeL2SystemContract(deployer: Dep
);

await tx.wait();

if (deployer.verbose) {
console.log("Setting L1Erc20Bridge data in shared bridge");
}
const sharedBridge = L1SharedBridgeFactory.connect(
deployer.addresses.Bridges.SharedBridgeProxy,
deployer.deployWallet
Expand All @@ -262,6 +264,58 @@ async function integrateEraIntoBridgehubAndUpgradeL2SystemContract(deployer: Dep
deployer.addresses.Bridges.ERC20BridgeProxy,
]);
await deployer.executeUpgrade(deployer.addresses.Bridges.SharedBridgeProxy, 0, data1);
if (process.env.CHAIN_ETH_NETWORK != "hardhat") {
if (deployer.verbose) {
console.log("Initializing l2 bridge in shared bridge");
}
const data2 = sharedBridge.interface.encodeFunctionData("initializeChainGovernance", [
deployer.chainId,
deployer.addresses.Bridges.L2SharedBridgeProxy,
]);
await deployer.executeUpgrade(deployer.addresses.Bridges.SharedBridgeProxy, 0, data2);
}
if (deployer.verbose) {
console.log("Setting validators in hyperchain");
}
// we have to set it via the STM
const stm = StateTransitionManagerFactory.connect(
deployer.addresses.StateTransition.DiamondProxy,
deployer.deployWallet
);
const data3 = stm.interface.encodeFunctionData("setValidator", [
deployer.chainId,
deployer.addresses.ValidatorTimeLock,
true,
]);
await deployer.executeUpgrade(deployer.addresses.StateTransition.StateTransitionProxy, 0, data3);

if (deployer.verbose) {
console.log("Setting validators in validator timelock");
}

// adding to validator timelock
const validatorOneAddress = getAddressFromEnv("ETH_SENDER_SENDER_OPERATOR_COMMIT_ETH_ADDR");
const validatorTwoAddress = getAddressFromEnv("ETH_SENDER_SENDER_OPERATOR_BLOBS_ETH_ADDR");
const validatorTimelock = deployer.validatorTimelock(deployer.deployWallet);
const txRegisterValidator = await validatorTimelock.addValidator(deployer.chainId, validatorOneAddress, {
gasPrice,
});
const receiptRegisterValidator = await txRegisterValidator.wait();
if (deployer.verbose) {
console.log(
`Validator registered, gas used: ${receiptRegisterValidator.gasUsed.toString()}, tx hash: ${
txRegisterValidator.hash
}`
);
}

const tx3 = await validatorTimelock.addValidator(deployer.chainId, validatorTwoAddress, {
gasPrice,
});
const receipt3 = await tx3.wait();
if (deployer.verbose) {
console.log(`Validator 2 registered, gas used: ${receipt3.gasUsed.toString()}`);
}
}

async function upgradeL2Bridge(deployer: Deployer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Command } from "commander";
import { artifacts } from "hardhat";
import type { BigNumberish } from "ethers";
import { ethers, Wallet } from "ethers";
import { formatUnits, Interface, parseUnits } from "ethers/lib/utils";
import { formatUnits, Interface, parseUnits, defaultAbiCoder } from "ethers/lib/utils";
import {
computeL2Create2Address,
provider,
Expand Down Expand Up @@ -52,7 +52,7 @@ async function create2DeployFromL1(
REQUIRED_L2_GAS_PRICE_PER_PUBDATA,
factoryDeps,
wallet.address,
{ value: expectedCost, gasPrice }
{ value: expectedCost.mul(5), gasPrice }
);
}

Expand Down Expand Up @@ -125,7 +125,7 @@ export async function deploySharedBridgeImplOnL2ThroughL1(deployer: Deployer, ch
const l2SharedBridgeImplAddress = computeL2Create2Address(
deployer.deployWallet,
L2_SHARED_BRIDGE_IMPLEMENTATION_BYTECODE,
"0x",
defaultAbiCoder.encode(["uint256"], [deployer.chainId]),
ethers.constants.HashZero
);
deployer.addresses.Bridges.L2SharedBridgeImplementation = l2SharedBridgeImplAddress;
Expand All @@ -143,7 +143,7 @@ export async function deploySharedBridgeImplOnL2ThroughL1(deployer: Deployer, ch
chainId,
deployer.deployWallet,
L2_SHARED_BRIDGE_IMPLEMENTATION_BYTECODE,
"0x",
defaultAbiCoder.encode(["uint256"], [deployer.chainId]),
ethers.constants.HashZero,
priorityTxMaxGasLimit,
gasPrice,
Expand Down

0 comments on commit 5016910

Please sign in to comment.