Skip to content

Commit

Permalink
add update Rollup
Browse files Browse the repository at this point in the history
  • Loading branch information
invocamanman committed Feb 21, 2024
1 parent f5eeba3 commit 98253b4
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 1 deletion.
2 changes: 1 addition & 1 deletion contracts/v2/lib/PolygonRollupBaseEtrog.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import "./PolygonConstantsBase.sol";
* The aggregators will be able to verify the sequenced state with zkProofs and therefore make available the withdrawals from L2 network.
* To enter and exit of the L2 network will be used a PolygonZkEVMBridge smart contract that will be deployed in both networks.
*/
contract PolygonRollupBaseEtrog is
abstract contract PolygonRollupBaseEtrog is
Initializable,
PolygonConstantsBase,
IPolygonZkEVMVEtrogErrors,
Expand Down
11 changes: 11 additions & 0 deletions tools/updateRollup/updateRollup.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"rollupAddress": "0xaddress",
"newRollupTypeID": 1,
"upgradeData": "0x",
"polygonRollupManagerAddress": "0xaddress",
"timelockDelay": 0,
"deployerPvtKey": "",
"maxFeePerGas": "",
"maxPriorityFeePerGas": "",
"multiplierGas": ""
}
154 changes: 154 additions & 0 deletions tools/updateRollup/updateRollup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/* eslint-disable no-await-in-loop, no-use-before-define, no-lonely-if */
/* eslint-disable no-console, no-inner-declarations, no-undef, import/no-unresolved */
import {expect} from "chai";
import path = require("path");
import fs = require("fs");

import * as dotenv from "dotenv";
dotenv.config({path: path.resolve(__dirname, "../../.env")});
import {ethers} from "hardhat";

const addRollupParameters = require("./updateRollup.json");

const pathOutputJson = path.join(__dirname, "./updateRollupOutput.json");
import "../../deployment/helpers/utils";

async function main() {
const outputJson = {} as any;

/*
* Check deploy parameters
* Check that every necessary parameter is fullfilled
*/
const mandatoryDeploymentParameters = [
"rollupAddress",
"newRollupTypeID",
"upgradeData",
"polygonRollupManagerAddress",
"timelockDelay",
];

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

const {rollupAddress, newRollupTypeID, upgradeData, polygonRollupManagerAddress, timelockDelay} =
addRollupParameters;

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

// Load provider
let currentProvider = ethers.provider;
if (addRollupParameters.multiplierGas || addRollupParameters.maxFeePerGas) {
if (process.env.HARDHAT_NETWORK !== "hardhat") {
currentProvider = ethers.getDefaultProvider(
`https://${process.env.HARDHAT_NETWORK}.infura.io/v3/${process.env.INFURA_PROJECT_ID}`
) as any;
if (addRollupParameters.maxPriorityFeePerGas && addRollupParameters.maxFeePerGas) {
console.log(
`Hardcoded gas used: MaxPriority${addRollupParameters.maxPriorityFeePerGas} gwei, MaxFee${addRollupParameters.maxFeePerGas} gwei`
);
const FEE_DATA = new ethers.FeeData(
null,
ethers.parseUnits(addRollupParameters.maxFeePerGas, "gwei"),
ethers.parseUnits(addRollupParameters.maxPriorityFeePerGas, "gwei")
);

currentProvider.getFeeData = async () => FEE_DATA;
} else {
console.log("Multiplier gas used: ", addRollupParameters.multiplierGas);
async function overrideFeeData() {
const feedata = await ethers.provider.getFeeData();
return new ethers.FeeData(
null,
((feedata.maxFeePerGas as bigint) * BigInt(addRollupParameters.multiplierGas)) / 1000n,
((feedata.maxPriorityFeePerGas as bigint) * BigInt(addRollupParameters.multiplierGas)) / 1000n
);
}
currentProvider.getFeeData = overrideFeeData;
}
}
}

// Load deployer
let deployer;
if (addRollupParameters.deployerPvtKey) {
deployer = new ethers.Wallet(addRollupParameters.deployerPvtKey, currentProvider);
} else if (process.env.MNEMONIC) {
deployer = ethers.HDNodeWallet.fromMnemonic(
ethers.Mnemonic.fromPhrase(process.env.MNEMONIC),
"m/44'/60'/0'/0/0"
).connect(currentProvider);
} else {
[deployer] = await ethers.getSigners();
}

console.log("Using with: ", deployer.address);

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

// Load Rollup manager
const PolgonRollupManagerFactory = await ethers.getContractFactory("PolygonRollupManager", deployer);

const operation = genOperation(
polygonRollupManagerAddress,
0, // value
PolgonRollupManagerFactory.interface.encodeFunctionData("updateRollup", [
rollupAddress,
newRollupTypeID,
upgradeData,
]),
ethers.ZeroHash, // predecesoor
salt // salt
);

// Schedule operation
const scheduleData = timelockContractFactory.interface.encodeFunctionData("schedule", [
operation.target,
operation.value,
operation.data,
operation.predecessor,
operation.salt,
timelockDelay,
]);
// Execute operation
const executeData = timelockContractFactory.interface.encodeFunctionData("execute", [
operation.target,
operation.value,
operation.data,
operation.predecessor,
operation.salt,
]);

console.log({scheduleData});
console.log({executeData});

outputJson.scheduleData = scheduleData;
outputJson.executeData = executeData;

fs.writeFileSync(pathOutputJson, JSON.stringify(outputJson, null, 1));
}

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

// OZ test functions
function genOperation(target: any, value: any, data: any, predecessor: any, salt: any) {
const id = ethers.solidityPackedKeccak256(
["address", "uint256", "bytes", "uint256", "bytes32"],
[target, value, data, predecessor, salt]
);
return {
id,
target,
value,
data,
predecessor,
salt,
};
}

0 comments on commit 98253b4

Please sign in to comment.