Skip to content

Commit

Permalink
Merge pull request #355 from 0xPolygonHermez/feature/fixUpgradePPInfo
Browse files Browse the repository at this point in the history
fix pp info upgrade
  • Loading branch information
krlosMata authored Nov 5, 2024
2 parents 99a473b + f9c1d0d commit c8659e6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 44 deletions.
30 changes: 17 additions & 13 deletions deployment/testnet/prepareTestnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const argv = yargs(process.argv.slice(2))
const pathDeployParameters = path.join(__dirname, argv.input);
const deployParameters = require(argv.input);

const pathCreateRollupParameters = path.join(__dirname, argv.createRollupInput);
const createRollupParameters = require(argv.createRollupInput);

async function main() {
Expand Down Expand Up @@ -133,19 +134,22 @@ 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);
if (createRollupParameters.gasTokenAddress == "deploy") {
/*
* 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();
createRollupParameters.gasTokenAddress = gasTokenContract.target;
console.log("#######################\n");
console.log("gas token deployed to:", gasTokenContract.target);
fs.writeFileSync(pathCreateRollupParameters, JSON.stringify(createRollupParameters, null, 1));
}

fs.writeFileSync(pathDeployParameters, JSON.stringify(deployParameters, null, 1));
}
Expand Down
17 changes: 9 additions & 8 deletions deployment/v2/4_createRollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,13 @@ async function main() {
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}`);
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 @@ -391,9 +389,12 @@ async function main() {
};
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 &&
if (
gasTokenAddress !== ethers.ZeroAddress &&
ethers.isAddress(gasTokenAddress) &&
(sovereignParams.sovereignWETHAddress === ethers.ZeroAddress || !ethers.isAddress(sovereignParams.sovereignWETHAddress))) {
(sovereignParams.sovereignWETHAddress === ethers.ZeroAddress ||
!ethers.isAddress(sovereignParams.sovereignWETHAddress))
) {
const wethObject = genesis.genesis.find(function (obj) {
return obj.contractName == "WETH";
});
Expand Down
4 changes: 2 additions & 2 deletions docker/scripts/v2/create_rollup_parameters_docker.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"adminZkEVM": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"forkID": 11,
"consensusContract": "PolygonPessimisticConsensus",
"gasTokenAddress": "deployed",
"gasTokenAddress": "deploy",
"deployerPvtKey": "",
"maxFeePerGas": "",
"maxPriorityFeePerGas": "",
Expand All @@ -21,4 +21,4 @@
"sovereignWETHAddressIsNotMintable": false,
"globalExitRootUpdater": "0xB55B27Cca633A73108893985350bc26B8A00C43a"
}
}
}
36 changes: 15 additions & 21 deletions upgrade/upgradePessimistic/upgradePessimistic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {utils} from "ffjavascript";
import * as dotenv from "dotenv";
dotenv.config({path: path.resolve(__dirname, "../../.env")});
import {ethers, upgrades} from "hardhat";
import {PolygonRollupManager, PolygonZkEVM} from "../../typechain-types";
import {PolygonRollupManager} from "../../typechain-types";

const pathOutputJson = path.join(__dirname, "./upgrade_output.json");

Expand Down Expand Up @@ -165,34 +165,28 @@ async function main() {

// Decode the scheduleData for better readability
const timelockTx = timelockContractFactory.interface.parseTransaction({data: scheduleData});
const paramsArray = timelockTx?.fragment.inputs;
const objectDecoded = {};
const paramsArray = timelockTx?.fragment.inputs as any;
const objectDecoded = {} as any;

for (let i = 0; i < paramsArray?.length; i++) {
const currentParam = paramsArray[i];
objectDecoded[currentParam.name] = timelockTx?.args[i];

if (currentParam.name == "payloads") {
// for each payload
const payloads = timelockTx?.args[i];
for (let j = 0; j < payloads.length; j++) {
const data = payloads[j];
const decodedProxyAdmin = proxyAdmin.interface.parseTransaction({
data,
});
if (currentParam.name == "data") {
const decodedProxyAdmin = proxyAdmin.interface.parseTransaction({
data: timelockTx?.args[i],
});
const objectDecodedData = {} as any;
const paramsArrayData = decodedProxyAdmin?.fragment.inputs as any;

const resultDecodeProxyAdmin = {};
resultDecodeProxyAdmin.signature = decodedProxyAdmin?.signature;
resultDecodeProxyAdmin.selector = decodedProxyAdmin?.selector;
objectDecodedData.signature = decodedProxyAdmin?.signature;
objectDecodedData.selector = decodedProxyAdmin?.selector;

const paramsArrayData = decodedProxyAdmin?.fragment.inputs;

for (let n = 0; n < paramsArrayData?.length; n++) {
const currentParam = paramsArrayData[n];
resultDecodeProxyAdmin[currentParam.name] = decodedProxyAdmin?.args[n];
}
objectDecoded[`decodePayload_${j}`] = resultDecodeProxyAdmin;
for (let j = 0; j < paramsArrayData?.length; j++) {
const currentParam = paramsArrayData[j];
objectDecodedData[currentParam.name] = decodedProxyAdmin?.args[j];
}
objectDecoded["decodedData"] = objectDecodedData;
}
}

Expand Down

0 comments on commit c8659e6

Please sign in to comment.