Skip to content

Commit

Permalink
add printGovernanceCall
Browse files Browse the repository at this point in the history
  • Loading branch information
zkbenny committed Jul 27, 2024
1 parent 25c9b93 commit 178fec9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/zklinkNova/hardhat.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require('@nomicfoundation/hardhat-toolbox');
require('./scripts/getTxStatus');
require('./scripts/decodeRawTx');
require('./scripts/printGovernanceCall');

const BaseConfig = require('../../hardhat.base.config');

Expand Down
30 changes: 30 additions & 0 deletions examples/zklinkNova/scripts/printGovernanceCall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const { ethers } = require('ethers');
const { task, types } = require('hardhat/config');

task('printSetValidator', 'Print the operation data of setValidator')
.addParam('zkLink', 'The zkLink address', undefined, types.string)
.addParam('validator', 'The validator address', undefined, types.string)
.addOptionalParam('active', 'The validator active status', true, types.boolean)
.setAction(async (taskArgs, hre) => {
const targetAddress = taskArgs.zkLink;
const validatorAddress = taskArgs.validator;
const active = taskArgs.active;
const zkLink = await hre.ethers.getContractFactory('ZkLink');
const callData = zkLink.interface.encodeFunctionData('setValidator', [validatorAddress, active]);
const governance = await hre.ethers.getContractFactory('Governance');
printOperation(governance, targetAddress, 0, callData);
});

function printOperation(governance, targetAddress, value, callData) {
const operation = {
calls: [{ target: targetAddress, value: value, data: callData }],
predecessor: ethers.ZeroHash,
salt: ethers.hexlify(ethers.randomBytes(32)),
};
console.log('Operation:', operation);
console.log('Schedule operation: ', governance.interface.encodeFunctionData('scheduleTransparent', [operation, 0]));
console.log(
`Execute operation value: ${value}, calldata`,
governance.interface.encodeFunctionData('execute', [operation]),
);
}

0 comments on commit 178fec9

Please sign in to comment.