-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5eeba3
commit 98253b4
Showing
3 changed files
with
166 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} |