diff --git a/packages/contracts/tasks/whitelist.ts b/packages/contracts/tasks/whitelist.ts index 181957d309597..da59d0c036c45 100644 --- a/packages/contracts/tasks/whitelist.ts +++ b/packages/contracts/tasks/whitelist.ts @@ -1,5 +1,6 @@ 'use strict' +import fs from 'fs' import { ethers } from 'ethers' import { task } from 'hardhat/config' import * as types from 'hardhat/internal/core/params/argumentTypes' @@ -10,7 +11,19 @@ import { predeploys } from '../src/predeploys' // Add accounts the the OVM_DeployerWhitelist // npx hardhat whitelist --address 0x.. task('whitelist') - .addParam('address', 'Address to whitelist', undefined, types.string) + .addOptionalParam('address', 'Address to whitelist', undefined, types.string) + .addOptionalParam( + 'addressFile', + 'File containing addresses to whitelist separated by a newline', + undefined, + types.string + ) + .addOptionalParam( + 'whitelistMode', + '"enable" if you want to add the address(es) from the whitelist, "disable" if you want remove the address(es) from the whitelist', + 'enable', + types.string + ) .addOptionalParam('transactionGasPrice', 'tx.gasPrice', undefined, types.int) .addOptionalParam( 'useLedger', @@ -38,11 +51,23 @@ task('whitelist') ) .addOptionalParam( 'contractAddress', - 'Address of Ownable contract', + 'Address of DeployerWhitelist contract', predeploys.OVM_DeployerWhitelist, types.string ) .setAction(async (args) => { + if (args.whitelistMode !== 'enable' && args.whitelistMode !== 'disable') { + throw new Error(`Whitelist mode must be either "enable" or "disable"`) + } + + if (args.address === undefined && args.addressPath === undefined) { + throw new Error(`Must provide either address or address-path`) + } + + if (args.address !== undefined && args.addressPath !== undefined) { + throw new Error(`Cannot provide both address and address-path`) + } + const provider = new ethers.providers.JsonRpcProvider(args.contractsRpcUrl) let signer: ethers.Signer if (!args.useLedger) { @@ -72,11 +97,26 @@ task('whitelist') throw new Error(`Incorrect key. Owner ${owner}, Signer ${addr}`) } - const res = await deployerWhitelist.setWhitelistedDeployer( - args.address, - true, - { gasPrice: args.transactionGasPrice } - ) - await res.wait() - console.log(`Whitelisted ${args.address}`) + const addresses = [] + if (args.address !== undefined) { + addresses.push(args.address) + } else { + const addressFile = fs.readFileSync(args.addressPath, 'utf8') + for (const line of addressFile.split('\n')) { + if (line !== '') { + addresses.push(line) + } + } + } + + for (const address of addresses) { + console.log(`Changing whitelist status for address: ${address}`) + console.log(`New whitelist status: ${args.whitelistMode}`) + const res = await deployerWhitelist.setWhitelistedDeployer( + address, + args.whitelistMode === 'enable' ? true : false, + { gasPrice: args.transactionGasPrice } + ) + await res.wait() + } })