Skip to content

Commit

Permalink
review tool change minDelay
Browse files Browse the repository at this point in the history
  • Loading branch information
laisolizq committed Dec 5, 2024
1 parent 959a81a commit 8fa4f45
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 97 deletions.
2 changes: 1 addition & 1 deletion tools/changeDelayTimelock/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
change_delay_output.json
change_delay_output-*
change_delay_timelock.json
9 changes: 1 addition & 8 deletions tools/changeDelayTimelock/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ npm i
- `timeLockDelay`: timelockDelay (by defalult `timeLockDelay` == current `minDelay`)
- `timelockSalt(optional)`: timelock salt
- `predecessor(optional)`: timelock predecessor
- `deployerPvtKey`: private key deployer
- First option will load `deployerPvtKey`. Otherwise, `process.env.MNEMONIC` will be loaded from the `.env` file
- `maxFeePerGas`: set custom gas
- `maxPriorityFeePerGas`: set custom gas
- `multiplierGas`: set custom gas
- `sendSchedule`: true to send schedule tx
- `sendExecute`: true to send execute tx
- A network should be selected when running the script
- examples: `--network sepolia` or `--network mainnet`
- This uses variables set in `hardhat.config.ts`
Expand All @@ -36,7 +29,7 @@ cp ./tools/changeDelayTimelock/change_delay_timelock.json.example ./tools/change
- Set your parameters
- Run tool:
```
npx hardhat run ./tools/changeDelayTimelock/changeDelayTimelock.ts --network sepolia
npx hardhat run ./tools/changeDelayTimelock/changeDelayTimelock.ts --network localhost
```


84 changes: 3 additions & 81 deletions tools/changeDelayTimelock/changeDelayTimelock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,60 +10,14 @@ import {ethers, network, upgrades} from "hardhat";
import { PolygonZkEVMTimelock } from "../../typechain-types";

const parameters = require("./change_delay_timelock.json");
const pathOutputJson = path.resolve(__dirname, "./change_delay_output.json");
const dateStr = new Date().toISOString();
const pathOutputJson = path.resolve(__dirname, `./change_delay_output-${dateStr}.json`);

async function main() {

const outputJson = {} as any;

// Load provider
let currentProvider = ethers.provider;
if (parameters.multiplierGas || parameters.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 (parameters.maxPriorityFeePerGas && parameters.maxFeePerGas) {
console.log(
`Hardcoded gas used: MaxPriority${parameters.maxPriorityFeePerGas} gwei, MaxFee${parameters.maxFeePerGas} gwei`
);
const FEE_DATA = new ethers.FeeData(
null,
ethers.parseUnits(parameters.maxFeePerGas, "gwei"),
ethers.parseUnits(parameters.maxPriorityFeePerGas, "gwei")
);

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

// Load deployer
let deployer;
if (parameters.deployerPvtKey) {
deployer = new ethers.Wallet(parameters.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();
}


const timelockContractFactory = await ethers.getContractFactory("PolygonZkEVMTimelock", deployer);
const timelockContractFactory = await ethers.getContractFactory("PolygonZkEVMTimelock");
const timelockContract = (await timelockContractFactory.attach(
parameters.timelockContractAddress
)) as PolygonZkEVMTimelock;
Expand Down Expand Up @@ -118,34 +72,6 @@ async function main() {
parameters: parameters.newMinDelay
}

if(parameters.sendSchedule) {
const txScheduled = await timelockContract.schedule(
operation.target,
operation.value,
operation.data,
operation.predecessor,
operation.salt,
timelockDelay,
);
await txScheduled.wait();
console.log("SEND SCHEDULE")
}
if (parameters.sendSchedule && parameters.sendExecute) {
await wait(timelockDelay);
}
if(parameters.sendExecute) {
const txExecute = await timelockContract.execute(
operation.target,
operation.value,
operation.data,
operation.predecessor,
operation.salt
);
await txExecute.wait();
console.log("SEND EXECUTE")
console.log("newMinDelay: ", await timelockContract.getMinDelay())
}

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

Expand All @@ -166,10 +92,6 @@ function genOperation(target: any, value: any, data: any, predecessor: any, salt
};
}

function wait(seconds: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, seconds * 1000));
}

main().catch((e) => {
console.error(e);
process.exit(1);
Expand Down
8 changes: 1 addition & 7 deletions tools/changeDelayTimelock/change_delay_timelock.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,5 @@
"newMinDelay": 1800,
"timeLockDelay": "",
"predecessor": "",
"timelockSalt": "",
"deployerPvtKey": "",
"maxFeePerGas": "",
"maxPriorityFeePerGas": "",
"multiplierGas": "",
"sendSchedule": false,
"sendExecute": false
"timelockSalt": ""
}

0 comments on commit 8fa4f45

Please sign in to comment.