Skip to content

Commit

Permalink
Update create rollup script with last fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ignasirv committed Nov 22, 2024
1 parent 5351b0b commit 59ce85c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 19 deletions.
74 changes: 56 additions & 18 deletions tools/createNewRollup/createNewRollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ async function main() {
isVanillaClient,
sovereignParams,
} = createRollupParameters;

const supportedConsensus = ["PolygonZkEVMEtrog", "PolygonValidiumEtrog", "PolygonPessimisticConsensus"];

if (!supportedConsensus.includes(consensusContractName)) {
throw new Error(
`Consensus contract ${consensusContractName} not supported, supported contracts are: ${supportedConsensus}`
);
}

// Check consensus compatibility
if (isVanillaClient) {
if (consensusContractName !== "PolygonPessimisticConsensus") {
Expand All @@ -70,6 +79,7 @@ async function main() {
"sovereignWETHAddress",
"sovereignWETHAddressIsNotMintable",
"globalExitRootUpdater",
"globalExitRootRemover",
];
for (const parameterName of mandatorySovereignParams) {
if (typeof sovereignParams[parameterName] === undefined || sovereignParams[parameterName] === "") {
Expand Down Expand Up @@ -146,19 +156,21 @@ async function main() {
}

// Check chainID
const rollupID = await rollupManagerContract.chainIDToRollupID(chainID);
if(Number(rollupID) !== 0) {
let rollupID = await rollupManagerContract.chainIDToRollupID(chainID);
if (Number(rollupID) !== 0) {
throw new Error(`Rollup with chainID ${chainID} already exists`);
}
// Check rollupTypeId
const rollupType = await rollupManagerContract.rollupTypeMap(createRollupParameters.rollupTypeId);
const consensusContractAddress = rollupType[0];
const verifierType = rollupType[3];
if(consensusContractName === "PolygonPessimisticConsensus") {
expect(verifierType).to.be.equal(1);
} else {
expect(verifierType).to.be.equal(0);
const verifierType = Number(rollupType[3]);
if (consensusContractName === "PolygonPessimisticConsensus" && verifierType !== 1) {
throw new Error(`Verifier type should be 1 for ${consensusContractName}`);
}
if (consensusContractName !== "PolygonPessimisticConsensus" && verifierType !== 0) {
throw new Error(`Verifier type should be 0 for ${consensusContractName}`);
}

// Grant role CREATE_ROLLUP_ROLE to deployer
const CREATE_ROLLUP_ROLE = ethers.id("CREATE_ROLLUP_ROLE");
if ((await rollupManagerContract.hasRole(CREATE_ROLLUP_ROLE, deployer.address)) == false)
Expand All @@ -172,7 +184,7 @@ async function main() {

// Create new rollup
const txDeployRollup = await rollupManagerContract.createNewRollup(
createRollupParameters.rollupTypeId,
createRollupParameters.rollupTypeId,
chainID,
rollupAdminAddress,
trustedSequencer,
Expand All @@ -189,14 +201,43 @@ async function main() {
console.log("#######################\n");
console.log(`Created new ${consensusContractName} Rollup:`, createdRollupAddress);

// Update rollupId
rollupID = await rollupManagerContract.chainIDToRollupID(chainID);

const polygonConsensusFactory = (await ethers.getContractFactory(consensusContractName, deployer)) as any;
const dataAvailabilityProtocol = createRollupParameters.dataAvailabilityProtocol || "PolygonDataCommittee";
if (consensusContractName.includes("PolygonValidiumEtrog") && dataAvailabilityProtocol === "PolygonDataCommittee") {
// deploy data committee
const PolygonDataCommitteeContract = (await ethers.getContractFactory("PolygonDataCommittee", deployer)) as any;
let polygonDataCommittee = await upgrades.deployProxy(PolygonDataCommitteeContract, [], {
unsafeAllow: ["constructor"],
});
await polygonDataCommittee?.waitForDeployment();

// Load data commitee
const PolygonValidiumContract = (await polygonConsensusFactory.attach(
createdRollupAddress
)) as PolygonValidiumEtrog;
// add data commitee to the consensus contract
if ((await PolygonValidiumContract.admin()) == deployer.address) {
await (
await PolygonValidiumContract.setDataAvailabilityProtocol(polygonDataCommittee?.target as any)
).wait();

// // Setup data commitee to 0
// await (await polygonDataCommittee?.setupCommittee(0, [], "0x")).wait();
} else {
await (await polygonDataCommittee?.transferOwnership(rollupAdminAddress)).wait();
}

outputJson.polygonDataCommitteeAddress = polygonDataCommittee?.target;
}

// Assert admin address
expect(await upgrades.erc1967.getAdminAddress(createdRollupAddress)).to.be.equal(rollupManagerContract.target);
expect(await upgrades.erc1967.getImplementationAddress(createdRollupAddress)).to.be.equal(
consensusContractAddress
);
expect(await upgrades.erc1967.getImplementationAddress(createdRollupAddress)).to.be.equal(consensusContractAddress);

// Search added global exit root on the logs
const polygonConsensusFactory = (await ethers.getContractFactory(consensusContractName, deployer)) as any;
let globalExitRoot;
for (const log of receipt?.logs) {
if (log.address == createdRollupAddress) {
Expand All @@ -212,9 +253,7 @@ async function main() {
// Get bridge instance
const bridgeFactory = await ethers.getContractFactory("PolygonZkEVMBridgeV2", deployer);
const bridgeContractAddress = await rollupManagerContract.bridgeAddress();
const rollupBridgeContract = bridgeFactory.attach(
bridgeContractAddress
) as PolygonZkEVMBridgeV2;
const rollupBridgeContract = bridgeFactory.attach(bridgeContractAddress) as PolygonZkEVMBridgeV2;
if (
ethers.isAddress(createRollupParameters.gasTokenAddress) &&
createRollupParameters.gasTokenAddress !== ethers.ZeroAddress
Expand All @@ -228,9 +267,7 @@ async function main() {
`Invalid gas token address, no ERC20 token deployed at the selected gas token network ${createRollupParameters.gasTokenAddress}`
);
}
const wrappedData = await rollupBridgeContract.wrappedTokenToTokenInfo(
createRollupParameters.gasTokenAddress
);
const wrappedData = await rollupBridgeContract.wrappedTokenToTokenInfo(createRollupParameters.gasTokenAddress);
if (wrappedData.originNetwork != 0n) {
// Wrapped token
gasTokenAddress = wrappedData.originTokenAddress;
Expand Down Expand Up @@ -259,6 +296,7 @@ async function main() {
sovereignWETHAddress: sovereignParams.sovereignWETHAddress,
sovereignWETHAddressIsNotMintable: sovereignParams.sovereignWETHAddressIsNotMintable,
globalExitRootUpdater: sovereignParams.globalExitRootUpdater,
globalExitRootRemover: sovereignParams.globalExitRootRemover,
};
genesis = await updateVanillaGenesis(genesis, chainID, initializeParams);
// Add weth address to deployment output if gas token address is provided and sovereignWETHAddress is not provided
Expand Down
3 changes: 2 additions & 1 deletion tools/createNewRollup/create_new_rollup.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"bridgeManager": "0xC7899Ff6A3aC2FF59261bD960A8C880DF06E1041",
"sovereignWETHAddress": "0x0000000000000000000000000000000000000000",
"sovereignWETHAddressIsNotMintable": false,
"globalExitRootUpdater": "0xB55B27Cca633A73108893985350bc26B8A00C43a"
"globalExitRootUpdater": "0xB55B27Cca633A73108893985350bc26B8A00C43a",
"globalExitRootRemover": "0xB55B27Cca633A73108893985350bc26B8A00C43a"
}
}

0 comments on commit 59ce85c

Please sign in to comment.