From e5e2ff90e80987eecc898068e2fa9a685d419c92 Mon Sep 17 00:00:00 2001 From: zkbenny Date: Tue, 6 Feb 2024 15:57:54 +0800 Subject: [PATCH] set validator for ethereum --- examples/scroll/scripts/4_setValidator.js | 4 +-- script/deploy_arbitrator.js | 37 ++++++++++++++++++++++- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/examples/scroll/scripts/4_setValidator.js b/examples/scroll/scripts/4_setValidator.js index 88397c0..8509127 100644 --- a/examples/scroll/scripts/4_setValidator.js +++ b/examples/scroll/scripts/4_setValidator.js @@ -6,8 +6,8 @@ const { task, types } = require('hardhat/config'); require('dotenv').config(); task('setValidator', 'Set validator for zkLink') - .addParam('validator', 'Validator Address', undefined, types.string, true) - .addParam('active', 'Whether to activate the validator address', true, types.boolean, true) + .addParam('validator', 'Validator Address', undefined, types.string) + .addOptionalParam('active', 'Whether to activate the validator address', true, types.boolean) .setAction(async (taskArgs, hre) => { const validatorAddr = taskArgs.validator; const isActive = taskArgs.active; diff --git a/script/deploy_arbitrator.js b/script/deploy_arbitrator.js index 5de3fa2..61c8920 100644 --- a/script/deploy_arbitrator.js +++ b/script/deploy_arbitrator.js @@ -1,6 +1,12 @@ const fs = require('fs'); const { getImplementationAddress } = require('@openzeppelin/upgrades-core'); -const { verifyContractCode, createOrGetDeployLog, ChainContractDeployer, getDeployTx } = require('./utils'); +const { + verifyContractCode, + createOrGetDeployLog, + ChainContractDeployer, + getDeployTx, + readDeployContract, +} = require('./utils'); const logName = require('./deploy_log_name'); const { task, types } = require('hardhat/config'); @@ -114,3 +120,32 @@ task('upgradeArbitrator', 'Upgrade arbitrator') fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); } }); + +task('setValidatorForEthereum', 'Set validator for ethereum') + .addParam('validator', 'Validator Address', undefined, types.string) + .addOptionalParam('active', 'Whether to activate the validator address', true, types.boolean) + .setAction(async (taskArgs, hardhat) => { + const validatorAddr = taskArgs.validator; + const isActive = taskArgs.active; + console.log(`The validator: address: ${validatorAddr}, active: ${isActive}`); + + const arbitratorAddr = readDeployContract(logName.DEPLOY_ARBITRATOR_LOG_PREFIX, logName.DEPLOY_LOG_ARBITRATOR); + if (arbitratorAddr === undefined) { + console.log('The arbitrator address not exist'); + return; + } + console.log(`The arbitrator address: ${arbitratorAddr}`); + + const ethGatewayAddr = readDeployContract(logName.DEPLOY_ETH_GATEWAY_LOG_PREFIX, logName.DEPLOY_GATEWAY); + if (ethGatewayAddr === undefined) { + console.log('The eth gateway address not exist'); + return; + } + console.log(`The eth gateway address: ${ethGatewayAddr}`); + + const arbitrator = await hardhat.ethers.getContractAt('Arbitrator', arbitratorAddr); + let tx = await arbitrator.setValidator(ethGatewayAddr, validatorAddr, isActive, '0x'); + console.log(`The tx hash: ${tx.hash} , waiting confirm...`); + await tx.wait(); + console.log(`The tx confirmed`); + });