Skip to content

Commit

Permalink
update tool getRollupData & grantRole
Browse files Browse the repository at this point in the history
  • Loading branch information
laisolizq committed Jan 30, 2025
1 parent 2fd1ed1 commit 5c9b600
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 88 deletions.
3 changes: 3 additions & 0 deletions tools/getRollupData/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
create_rollup_output*
deploy_output.json
rollupDataParams.json
54 changes: 54 additions & 0 deletions tools/getRollupData/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Get Rollup Data
Script to get rollup data.

## Install
```
npm i
```

## Setup
- Config file `rollupDataParams.json`:
- `polygonRollupManagerAddress`: rollupManager address,
- `rollupID`: rollup ID
- A network should be selected when running the script
- examples: `--network sepolia` or `--network mainnet`
- This uses variables set in `hardhat.config.ts`
- Which uses some environment variables that should be set in `.env`
> All paths are from root repository
## Usage
> All commands are done from root repository.
- Copy configuration file:
```
cp tools/getRollupData/rollupDataParams.json.example tools/getRollupData/rollupDataParams.json
```
- Set your parameters
- Run tool:
```
npx hardhat run tools/getRollupData/getRollupData.ts --network <network>
```
- Output:
- `deploy_output.json`:
```
{
"polygonRollupManagerAddress": "0xA51c1fc2f0D1a1b8494Ed1FE312d7C3a78Ed91C0",
"polygonZkEVMBridgeAddress": "0x124fBB77374f2D2F0d716973C23Ab06AE49ACde5",
"polygonZkEVMGlobalExitRootAddress": "0x610178dA211FEF7D417bC0e6FeD39F05609AD788",
"polTokenAddress": "0x5FbDB2315678afecb367f032d93F642f64180aa3",
"deploymentRollupManagerBlockNumber": 43
}
```
- `create_rollup_output_X`:
```
{
"genesis": "0x0000000000000000000000000000000000000000000000000000000000000000",
"createRollupBlockNumber": 49,
"rollupAddress": "0x1F708C24a0D3A740cD47cC0444E9480899f3dA7D",
"consensusContract": "0.0.1",
"rollupID": 1,
"L2ChainID": 1001,
"gasTokenAddress": "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0"
}
```
59 changes: 34 additions & 25 deletions tools/getRollupData/getRollupData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {ethers, upgrades} from "hardhat";
const getRollupParams = require("./rollupDataParams.json");
import {PolygonRollupManager} from "../../typechain-types";
const pathOutputJson = path.join(__dirname, "./deploy_output.json");
const pathCreateRollupOutput = path.join(__dirname, "./create_rollup_output.json");
const pathCreateRollupOutput = path.join(__dirname, "./create_rollup_output");

async function main() {
const RollupManagerFactory = await ethers.getContractFactory("PolygonRollupManager");
Expand All @@ -22,7 +22,6 @@ async function main() {
const polygonZkEVMBridgeAddress = await rollupManager.bridgeAddress();
const polygonZkEVMGlobalExitRootAddress = await rollupManager.globalExitRootManager();
const polTokenAddress = await rollupManager.pol();

// FIlter first rollup ID ( the one on migration)
const filterInit = rollupManager.filters.Initialized(undefined);
const eventsInit = await rollupManager.queryFilter(filterInit, 0, "latest");
Expand All @@ -31,7 +30,12 @@ async function main() {
// Filter first initialization (deployment)
const filter = rollupManager.filters.AddExistingRollup(1);
const eventsAddRollup = await rollupManager.queryFilter(filter, 0, "latest");
const upgradeToULxLyBlockNumber = eventsAddRollup[0].blockNumber;
let upgradeToULxLyBlockNumber;
if (eventsAddRollup.length > 0) {
upgradeToULxLyBlockNumber = eventsAddRollup[0].blockNumber;
} else {
console.log("No event AddExistingRollup");
}
const deployOutput = {
polygonRollupManagerAddress: rollupManager.target,
polygonZkEVMBridgeAddress,
Expand All @@ -40,7 +44,7 @@ async function main() {
deploymentRollupManagerBlockNumber,
upgradeToULxLyBlockNumber,
};
fs.writeFileSync(pathOutputJson, JSON.stringify(deployOutput, null, 1));
await fs.writeFileSync(pathOutputJson, JSON.stringify(deployOutput, null, 1));

const filter2 = rollupManager.filters.CreateNewRollup(
getRollupParams.rollupID,
Expand All @@ -50,31 +54,36 @@ async function main() {
undefined
);
const eventsCreateNewRollup = await rollupManager.queryFilter(filter2, 0, "latest");
const {rollupID, rollupAddress, chainID, gasTokenAddress, rollupTypeID} = eventsCreateNewRollup[0].args;

const filter3 = rollupManager.filters.AddNewRollupType(
rollupTypeID,
undefined,
undefined,
undefined,
undefined,
undefined
);
if (eventsCreateNewRollup.length > 0) {
const {rollupID, rollupAddress, chainID, gasTokenAddress, rollupTypeID} = eventsCreateNewRollup[0].args;

const filter3 = rollupManager.filters.AddNewRollupType(
rollupTypeID,
undefined,
undefined,
undefined,
undefined,
undefined
);

const eventsAddRollupType = await rollupManager.queryFilter(filter3, 0, "latest");
const {forkID, genesis, description} = eventsAddRollupType[0].args;
const eventsAddRollupType = await rollupManager.queryFilter(filter3, 0, "latest");
const {forkID, genesis, description} = eventsAddRollupType[0].args;

// Add the first batch of the created rollup
const outputCreateRollup = {} as any;
outputCreateRollup.genesis = genesis;
outputCreateRollup.createRollupBlockNumber = eventsCreateNewRollup[0].blockNumber;
outputCreateRollup.rollupAddress = rollupAddress;
outputCreateRollup.consensusContract = description;
outputCreateRollup.rollupID = Number(rollupID);
outputCreateRollup.L2ChainID = Number(chainID);
outputCreateRollup.gasTokenAddress = gasTokenAddress;
// Add the first batch of the created rollup
const outputCreateRollup = {} as any;
outputCreateRollup.genesis = genesis;
outputCreateRollup.createRollupBlockNumber = eventsCreateNewRollup[0].blockNumber;
outputCreateRollup.rollupAddress = rollupAddress;
outputCreateRollup.consensusContract = description;
outputCreateRollup.rollupID = Number(rollupID);
outputCreateRollup.L2ChainID = Number(chainID);
outputCreateRollup.gasTokenAddress = gasTokenAddress;

fs.writeFileSync(pathCreateRollupOutput, JSON.stringify(outputCreateRollup, null, 1));
await fs.writeFileSync(`${pathCreateRollupOutput}_${rollupID}.json`, JSON.stringify(outputCreateRollup, null, 1));
} else {
console.log("No event AddNewRollupType");
}
}

main().catch((e) => {
Expand Down
2 changes: 2 additions & 0 deletions tools/grantRole/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
grantRoleOutput.json
grantRole.json
62 changes: 62 additions & 0 deletions tools/grantRole/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Get Rollup Data
Script to get rollup data.

## Install
```
npm i
```

## Setup
- Config file `grantRole.json`:
- `roleName`:
- "ADD_ROLLUP_TYPE_ROLE"
- "OBSOLETE_ROLLUP_TYPE_ROLE"
- "CREATE_ROLLUP_ROLE"
- "ADD_EXISTING_ROLLUP_ROLE"
- "UPDATE_ROLLUP_ROLE"
- "TRUSTED_AGGREGATOR_ROLE"
- "TRUSTED_AGGREGATOR_ROLE_ADMIN"
- "SET_FEE_ROLE"
- "STOP_EMERGENCY_ROLE"
- "EMERGENCY_COUNCIL_ROLE"
- `accountToGrantRole`: address to grantRole
- `polygonRollupManagerAddress`: rollupManager address
- `timelockDelay`: timelock delay
- A network should be selected when running the script
- examples: `--network sepolia` or `--network mainnet`
- This uses variables set in `hardhat.config.ts`
- Which uses some environment variables that should be set in `.env`
> All paths are from root repository
## Usage
> All commands are done from root repository.
- Copy configuration file:
```
cp ./tools/grantRole/grantRole.json.example ./tools/grantRole/grantRole.json
```
- Set your parameters
- Run tool:
```
npx hardhat run tools/grantRole/grantRole.ts --network <network>
```
- Output:
- `granRoleOutput.json`:
```
{
"scheduleData": "0x01d5062a000000000000000000000000a51c1fc2f0d1a1b8494ed1fe312d7c3a78ed91c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e1000000000000000000000000000000000000000000000000000000000000000442f2ff15dac75d24dbb35ea80e25fab167da4dea46c1915260426570db84f184891f5f590000000000000000000000000a51c1fc2f0d1a1b8494ed1fe312d7c3a78ed91c000000000000000000000000000000000000000000000000000000000",
"executeData": "0x134008d3000000000000000000000000a51c1fc2f0d1a1b8494ed1fe312d7c3a78ed91c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000442f2ff15dac75d24dbb35ea80e25fab167da4dea46c1915260426570db84f184891f5f590000000000000000000000000a51c1fc2f0d1a1b8494ed1fe312d7c3a78ed91c000000000000000000000000000000000000000000000000000000000",
"decodedScheduleData": {
"target": "0xA51c1fc2f0D1a1b8494Ed1FE312d7C3a78Ed91C0",
"value": "0",
"data": "0x2f2ff15dac75d24dbb35ea80e25fab167da4dea46c1915260426570db84f184891f5f590000000000000000000000000a51c1fc2f0d1a1b8494ed1fe312d7c3a78ed91c0",
"decodedData": {
"role": "0xac75d24dbb35ea80e25fab167da4dea46c1915260426570db84f184891f5f590",
"account": "0xA51c1fc2f0D1a1b8494Ed1FE312d7C3a78Ed91C0"
},
"predecessor": "0x0000000000000000000000000000000000000000000000000000000000000000",
"salt": "0x0000000000000000000000000000000000000000000000000000000000000000",
"delay": "3600"
}
}
```
6 changes: 1 addition & 5 deletions tools/grantRole/grantRole.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,5 @@
"roleName": "roleName",
"accountToGrantRole": "0xaddress",
"polygonRollupManagerAddress": "0xaddress",
"timelockDelay": 3600,
"deployerPvtKey": "",
"maxFeePerGas": "",
"maxPriorityFeePerGas": "",
"multiplierGas": ""
"timelockDelay": 3600
}
60 changes: 6 additions & 54 deletions tools/grantRole/grantRole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,59 +54,11 @@ async function main() {
}
const roleID = ethers.id(roleName);

// 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);
const timelockContractFactory = await ethers.getContractFactory("PolygonZkEVMTimelock");

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

const operation = genOperation(
polygonRollupManagerAddress,
Expand Down Expand Up @@ -142,8 +94,8 @@ async function main() {

// Decode the scheduleData for better readibility
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];
Expand All @@ -153,8 +105,8 @@ async function main() {
const decodedRollupManagerData = PolgonRollupManagerFactory.interface.parseTransaction({
data: timelockTx?.args[i],
});
const objectDecodedData = {};
const paramsArrayData = decodedRollupManagerData?.fragment.inputs;
const objectDecodedData = {} as any;
const paramsArrayData = decodedRollupManagerData?.fragment.inputs as any;

for (let j = 0; j < paramsArrayData?.length; j++) {
const currentParam = paramsArrayData[j];
Expand Down
8 changes: 4 additions & 4 deletions tools/updateRollup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ npm i
```

## Setup
- Config file
- Config file `updateRollup.json`:
- `rollupAddress`: rollup address of the rollup that is going to be updated
- `newRollupTypeID`: select which is the `rollupTypeID` to upgrade
- `upgradeData`: data necessary to perform the upgrade (default to `0x`)
Expand All @@ -27,7 +27,7 @@ npm i
## Usage
> All commands are done from root repository.
### Call 'addNewRollupType' from an EOA
### Call 'updateRollup' from an EOA
- Copy configuration file:
```
cp ./tools/updateRollup/updateRollup.json.example ./tools/updateRollup/updateRollup.json
Expand All @@ -37,7 +37,7 @@ cp ./tools/updateRollup/updateRollup.json.example ./tools/updateRollup/updateRol
- Run tool:
- Standrad transaction:
```
npx hardhat run ./tools/updateRollup/updateRollup.ts --network sepolia
npx hardhat run ./tools/updateRollup/updateRollup.ts --network <network>
```

### Generate 'updateRollup' data to the Timelock SC
Expand All @@ -50,7 +50,7 @@ cp ./tools/updateRollup/updateRollup.json.example ./tools/updateRollup/updateRol
- Set your parameters
- Run tool:
```
npx hardhat run ./tools/updateRollup/updateRollupTimelock.ts --network sepolia
npx hardhat run ./tools/updateRollup/updateRollupTimelock.ts --network <network>
```
- Output:
- scheduleData
Expand Down

0 comments on commit 5c9b600

Please sign in to comment.