Skip to content

Commit

Permalink
check SC scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
invocamanman committed Jan 26, 2024
1 parent b1d01f1 commit d4714dd
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 35 deletions.
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,16 @@
"dockerv2:v1ToV2:contracts": "sudo ./docker/scripts/v1ToV2/deploy-dockerv2.sh",
"saveDeployment:sepolia": "mkdir -p deployments/sepolia_$(date +%s) && cp -r deployment/v2/deploy_*.json deployments/sepolia_$(date +%s) && cp .openzeppelin/sepolia.json deployments/sepolia_$(date +%s) && cp deployment/v2/genesis.json deployments/sepolia_$(date +%s) && cp deployment/v2/create_rollup_output.json deployments/sepolia_$(date +%s)",
"testnetPol:upgradeV2:sepolia": "npx hardhat run upgrade/upgradeToV2/testnet/deployTestnetPol.ts --network sepolia",
"upgradev2:timelock:goerli": "npx hardhat run upgrade/upgradeToV2/upgradeToV2.ts --network goerli && saveUpgradeV2:goerli",
"upgradev2:timelock:sepolia": "npx hardhat run upgrade/upgradeToV2/upgradeToV2.ts --network sepolia && saveUpgradeV2:sepolia",
"testnetPol:upgradeV2:goerli": "npx hardhat run upgrade/upgradeToV2/testnet/deployTestnetPol.ts --network goerli",
"upgradev2:timelock:goerli": "npx hardhat run upgrade/upgradeToV2/upgradeToV2.ts --network goerli && npm run saveUpgradeV2:goerli",
"upgradev2:timelock:sepolia": "npx hardhat run upgrade/upgradeToV2/upgradeToV2.ts --network sepolia && npm run saveUpgradeV2:sepolia",
"verify:upgradeV2:sepolia": "npx hardhat run upgrade/upgradeToV2/verifyContracts.ts --network sepolia",
"verify:upgradeV2:goerli": "npx hardhat run upgrade/upgradeToV2/verifyContracts.ts --network goerli",
"upgradev2L2:timelock:zkevmDevnet": "npx hardhat run upgrade/upgradeToV2/upgradeL2ToV2.ts --network zkevmDevnet",
"saveUpgradeV2:sepolia": "mkdir -p upgrade/upgradeToV2/sepolia_$(date +%s) && cp -r upgrade/upgradeToV2/upgrade_*.json upgrade/upgradeToV2/sepolia_$(date +%s) && cp -r upgrade/upgradeToV2/deploy_*.json upgrade/upgradeToV2/sepolia_$(date +%s) && cp .openzeppelin/sepolia.json upgrade/upgradeToV2/sepolia_$(date +%s)",
"saveUpgradeV2:goerli": "mkdir -p upgrade/upgradeToV2/goerli_$(date +%s) && cp -r upgrade/upgradeToV2/upgrade_*.json upgrade/upgradeToV2/goerli_$(date +%s) && cp -r upgrade/upgradeToV2/deploy_*.json upgrade/upgradeToV2/goerli_$(date +%s) && cp .openzeppelin/goerli.json upgrade/upgradeToV2/goerli_$(date +%s)"
"saveUpgradeV2:goerli": "mkdir -p upgrade/upgradeToV2/goerli_$(date +%s) && cp -r upgrade/upgradeToV2/upgrade_*.json upgrade/upgradeToV2/goerli_$(date +%s) && cp -r upgrade/upgradeToV2/deploy_*.json upgrade/upgradeToV2/goerli_$(date +%s) && cp .openzeppelin/goerli.json upgrade/upgradeToV2/goerli_$(date +%s)",
"upgradev2L2:timelock:polygonZKEVMTestnet": "npx hardhat run upgrade/upgradeToV2/upgradeL2ToV2.ts --network polygonZKEVMTestnet",
"upgradev2L2:timelock:polygonZKEVMMainnet": "npx hardhat run upgrade/upgradeToV2/upgradeL2ToV2.ts --network polygonZKEVMMainnet"

}
}
16 changes: 13 additions & 3 deletions upgrade/upgradeToV2/upgradeL2ToV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import fs = require("fs");
import * as dotenv from "dotenv";
dotenv.config({path: path.resolve(__dirname, "../../.env")});
import {ethers, upgrades} from "hardhat";
import {PolygonZkEVMTimelock} from "../../typechain-types";

const pathOutputJson = path.join(__dirname, "./upgrade_outputL2.json");
const deployParameters = require("./deploy_parameters.json");
Expand All @@ -17,7 +18,6 @@ async function main() {
upgrades.silenceWarnings();

const salt = upgradeParameters.timelockSalt || ethers.ZeroHash;
const timelockDelay = deployParameters.minDelayTimelock;
const currentBridgeAddress = deployOutputParameters.polygonZkEVMBridgeAddress;

// Load provider
Expand Down Expand Up @@ -73,11 +73,20 @@ async function main() {

// Import OZ upgrades
await upgrades.forceImport(currentBridgeAddress as string, PreviousBridgeFactory, "transparent" as any);

const proxyAdmin = await upgrades.admin.getInstance();

// Assert correct admin
expect(await upgrades.erc1967.getAdminAddress(currentBridgeAddress as string)).to.be.equal(proxyAdmin.target);

// Check current timelock address and delay
const timelockL2Address = await proxyAdmin.owner();

// load timelock
const timelockContractFactory = await ethers.getContractFactory("PolygonZkEVMTimelock", deployer);
const timelockContractFactory = await ethers.getContractFactory("PolygonZkEVMTimelock");
const timelockContract = (await timelockContractFactory.attach(timelockL2Address)) as PolygonZkEVMTimelock;
const timelockDelay = timelockContract.getMinDelay();

console.log("timelockAddress: ", timelockContract.target, {timelockDelay});

// prapare upgrades
const polygonZkEVMBridgeFactory = await ethers.getContractFactory("PolygonZkEVMBridgeV2", deployer);
Expand Down Expand Up @@ -125,6 +134,7 @@ async function main() {
const outputJson = {
scheduleData,
executeData,
timelockL2Address,
};
fs.writeFileSync(pathOutputJson, JSON.stringify(outputJson, null, 1));
}
Expand Down
55 changes: 26 additions & 29 deletions upgrade/upgradeToV2/upgradeToV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import fs = require("fs");
import * as dotenv from "dotenv";
dotenv.config({path: path.resolve(__dirname, "../../.env")});
import {ethers, upgrades} from "hardhat";
import {PolygonZkEVM} from "../../typechain-types";

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

Expand All @@ -17,30 +18,6 @@ const upgradeParameters = require("./upgrade_parameters.json");
async function main() {
upgrades.silenceWarnings();

/*
* Check deploy parameters
* Check that every necessary parameter is fullfilled
*/
const mandatoryDeploymentParameters = [
"admin",
"trustedAggregator",
"trustedAggregatorTimeout",
"pendingStateTimeout",
"zkEVMOwner",
"chainID",
];

for (const parameterName of mandatoryDeploymentParameters) {
if (deployParameters[parameterName] === undefined || deployParameters[parameterName] === "") {
throw new Error(`Missing parameter: ${parameterName}`);
}
}

const {admin, trustedAggregator, trustedAggregatorTimeout, pendingStateTimeout, zkEVMOwner, chainID} =
deployParameters;

const emergencyCouncilAddress = zkEVMOwner;

/*
* Check upgrade parameters
* Check that every necessary parameter is fullfilled
Expand All @@ -54,7 +31,6 @@ async function main() {
}

const {realVerifier, newForkID, timelockDelay, polTokenAddress} = upgradeParameters;

const salt = upgradeParameters.timelockSalt || ethers.ZeroHash;

/*
Expand All @@ -79,6 +55,26 @@ async function main() {
const currentPolygonZkEVMAddress = deployOutputParameters.polygonZkEVMAddress;
const currentTimelockAddress = deployOutputParameters.timelockContractAddress;

// Load onchain parameters
const polygonZkEVMFactory = await ethers.getContractFactory("PolygonZkEVM");
const polygonZkEVMContract = (await polygonZkEVMFactory.attach(currentPolygonZkEVMAddress)) as PolygonZkEVM;

const admin = await polygonZkEVMContract.admin();
const trustedAggregator = await polygonZkEVMContract.trustedAggregator();
const trustedAggregatorTimeout = await polygonZkEVMContract.trustedAggregatorTimeout();
const pendingStateTimeout = await polygonZkEVMContract.pendingStateTimeout();
const chainID = await polygonZkEVMContract.chainID();
const emergencyCouncilAddress = await polygonZkEVMContract.owner();

console.log(
{admin},
{trustedAggregator},
{trustedAggregatorTimeout},
{pendingStateTimeout},
{chainID},
{emergencyCouncilAddress}
);

// Load provider
let currentProvider = ethers.provider;
if (deployParameters.multiplierGas || deployParameters.maxFeePerGas) {
Expand Down Expand Up @@ -129,6 +125,9 @@ async function main() {

const proxyAdmin = await upgrades.admin.getInstance();

// Assert correct admin
expect(await upgrades.erc1967.getAdminAddress(currentPolygonZkEVMAddress as string)).to.be.equal(proxyAdmin.target);

// deploy new verifier
let verifierContract;
if (realVerifier === true) {
Expand All @@ -146,7 +145,6 @@ async function main() {

// load timelock
const timelockContractFactory = await ethers.getContractFactory("PolygonZkEVMTimelock", deployer);
const timelockContract = timelockContractFactory.attach(currentTimelockAddress);

// prapare upgrades

Expand Down Expand Up @@ -282,7 +280,7 @@ async function main() {
pendingStateTimeout,
trustedAggregatorTimeout,
admin,
timelockContract.target,
currentTimelockAddress,
emergencyCouncilAddress,
newPolygonZkEVMContract.target,
verifierContract.target,
Expand Down Expand Up @@ -321,12 +319,11 @@ async function main() {
executeData,
verifierAddress: verifierContract.target,
newPolygonZKEVM: newPolygonZkEVMContract.target,
timelockContractAdress: currentTimelockAddress,
};
fs.writeFileSync(pathOutputJson, JSON.stringify(outputJson, null, 1));
}

// TODO script verify contracts

main().catch((e) => {
console.error(e);
process.exit(1);
Expand Down

0 comments on commit d4714dd

Please sign in to comment.