Skip to content

Commit

Permalink
Remove system address from final genesis state
Browse files Browse the repository at this point in the history
Update deploy scripts with more checks

Improve upgrade presimistic script
  • Loading branch information
ignasirv committed Nov 5, 2024
1 parent f1227e4 commit ddfd159
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 57 deletions.
15 changes: 15 additions & 0 deletions deployment/testnet/prepareTestnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,21 @@ async function main() {
}

deployParameters.polTokenAddress = polTokenContract.target;

/*
* Deployment gasToken address
* A erc20 is deployed in this testnet in case it's wanted to deploy a rollup that uses this token as the gas token
*/
const gasTokenName = "Gas Token";
const gasTokenSymbol = "GAS";

const gasTokenFactory = await ethers.getContractFactory("ERC20", deployer);
const gasTokenContract = await gasTokenFactory.deploy(gasTokenName, gasTokenSymbol);
await gasTokenContract.waitForDeployment();
deployParameters.gasTokenAddress = gasTokenContract.target;
console.log("#######################\n");
console.log("gas token deployed to:", gasTokenContract.target);

fs.writeFileSync(pathDeployParameters, JSON.stringify(deployParameters, null, 1));
}

Expand Down
31 changes: 23 additions & 8 deletions deployment/v2/4_createRollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import fs = require("fs");
import * as dotenv from "dotenv";
dotenv.config({path: path.resolve(__dirname, "../../.env")});
import {ethers, upgrades} from "hardhat";
import {HardhatEthersSigner} from "@nomicfoundation/hardhat-ethers/signers";
const {create2Deployment} = require("../helpers/deployment-helpers");

const pathGenesis = path.join(__dirname, "./genesis.json");
const pathGenesisSovereign = path.join(__dirname, "./genesis_sovereign.json");
import {processorUtils, Constants} from "@0xpolygonhermez/zkevm-commonjs";

const createRollupParameters = require("./create_rollup_parameters.json");
let genesis = require("./genesis.json");
let genesis = require(pathGenesis);
const deployOutput = require("./deploy_output.json");
import "../helpers/utils";
import updateVanillaGenesis from "./utils/updateVanillaGenesis";

const pathOutputJson = path.join(__dirname, "./create_rollup_output.json");
const deployParameters = require("./deploy_parameters.json");

import {
PolygonRollupManager,
Expand Down Expand Up @@ -263,12 +263,19 @@ async function main() {
) as PolygonZkEVMBridgeV2;
if (
createRollupParameters.gasTokenAddress &&
createRollupParameters.gasTokenAddress != "" &&
createRollupParameters.gasTokenAddress != ethers.ZeroAddress
createRollupParameters.gasTokenAddress !== "" &&
createRollupParameters.gasTokenAddress !== ethers.ZeroAddress
) {
// If gas token address is "deployed" use the one from deploy parameters, erc20 deployed at prepare testnet script
if(createRollupParameters.gasTokenAddress == "deployed") {
createRollupParameters.gasTokenAddress = deployParameters.gasTokenAddress;
}
// Get token metadata
gasTokenMetadata = await polygonZkEVMBridgeContract.getTokenMetadata(createRollupParameters.gasTokenAddress);

// If gas token metadata includes `0x124e4f545f56414c49445f454e434f44494e47 (NOT_VALID_ENCODING)` means there is no erc20 token deployed at the selected gas token network
if(gasTokenMetadata.includes("124e4f545f56414c49445f454e434f44494e47")) {
throw new Error(`Invalid gas token address, no ERC20 token deployed at the selected gas token network ${createRollupParameters.gasTokenAddress}`);
}
const wrappedData = await polygonZkEVMBridgeContract.wrappedTokenToTokenInfo(
createRollupParameters.gasTokenAddress
);
Expand Down Expand Up @@ -375,7 +382,6 @@ async function main() {
rollupID: rollupID,
gasTokenAddress,
gasTokenNetwork,
globalExitRootManager: Constants.ADDRESS_GLOBAL_EXIT_ROOT_MANAGER_L2,
polygonRollupManager: ethers.ZeroAddress,
gasTokenMetadata,
bridgeManager: sovereignParams.bridgeManager,
Expand All @@ -384,6 +390,15 @@ async function main() {
globalExitRootUpdater: sovereignParams.globalExitRootUpdater,
};
genesis = await updateVanillaGenesis(genesis, chainID, initializeParams);
// Add weth address to deployment output if gas token address is provided and sovereignWETHAddress is not provided
if ( gasTokenAddress !== ethers.ZeroAddress &&
ethers.isAddress(gasTokenAddress) &&
(sovereignParams.sovereignWETHAddress === ethers.ZeroAddress || !ethers.isAddress(sovereignParams.sovereignWETHAddress))) {
const wethObject = genesis.genesis.find(function (obj) {
return obj.contractName == "WETH";
});
outputJson.WETHAddress = wethObject.address;
}
} else {
if (consensusContract === "PolygonPessimisticConsensus") {
// Add the first batch of the created rollup
Expand Down Expand Up @@ -463,7 +478,7 @@ async function main() {

// Rewrite updated genesis in case of vanilla client
if (isVanillaClient) {
fs.writeFileSync(pathGenesis, JSON.stringify(genesis, null, 1));
fs.writeFileSync(pathGenesisSovereign, JSON.stringify(genesis, null, 1));
}
fs.writeFileSync(pathOutputJson, JSON.stringify(outputJson, null, 1));
}
Expand Down
8 changes: 6 additions & 2 deletions deployment/v2/utils/deployment-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ const padTo32Bytes = (value) => {
const hexValue = value.startsWith("0x") ? value.slice(2) : value; // Remove '0x'
return "0x" + hexValue.padStart(64, "0"); // Pad to 64 hex digits
};

const padTo20Bytes = (value) => {
const hexValue = value.startsWith("0x") ? value.slice(2) : value; // Remove '0x'
return "0x" + hexValue.padStart(40, "0"); // Pad to 40 hex digits
};
export {
padTo32Bytes
padTo32Bytes,
padTo20Bytes
}
Loading

0 comments on commit ddfd159

Please sign in to comment.