diff --git a/examples/zklinkNova/hardhat.config.js b/examples/zklinkNova/hardhat.config.js index 0832738..290f0b6 100644 --- a/examples/zklinkNova/hardhat.config.js +++ b/examples/zklinkNova/hardhat.config.js @@ -1,6 +1,7 @@ require('@nomicfoundation/hardhat-toolbox'); require('./scripts/getTxStatus'); require('./scripts/decodeRawTx'); +require('./scripts/printGovernanceCall'); const BaseConfig = require('../../hardhat.base.config'); diff --git a/examples/zklinkNova/scripts/printGovernanceCall.js b/examples/zklinkNova/scripts/printGovernanceCall.js new file mode 100644 index 0000000..4138689 --- /dev/null +++ b/examples/zklinkNova/scripts/printGovernanceCall.js @@ -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]), + ); +}