Commit 5d0d7ec6 authored by Kelvin Fichter's avatar Kelvin Fichter

feat: update whitelist task for multiple addresses

parent b9ee2d7f
'use strict' 'use strict'
import fs from 'fs'
import { ethers } from 'ethers' import { ethers } from 'ethers'
import { task } from 'hardhat/config' import { task } from 'hardhat/config'
import * as types from 'hardhat/internal/core/params/argumentTypes' import * as types from 'hardhat/internal/core/params/argumentTypes'
...@@ -10,7 +11,19 @@ import { predeploys } from '../src/predeploys' ...@@ -10,7 +11,19 @@ import { predeploys } from '../src/predeploys'
// Add accounts the the OVM_DeployerWhitelist // Add accounts the the OVM_DeployerWhitelist
// npx hardhat whitelist --address 0x.. // npx hardhat whitelist --address 0x..
task('whitelist') 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('transactionGasPrice', 'tx.gasPrice', undefined, types.int)
.addOptionalParam( .addOptionalParam(
'useLedger', 'useLedger',
...@@ -38,11 +51,23 @@ task('whitelist') ...@@ -38,11 +51,23 @@ task('whitelist')
) )
.addOptionalParam( .addOptionalParam(
'contractAddress', 'contractAddress',
'Address of Ownable contract', 'Address of DeployerWhitelist contract',
predeploys.OVM_DeployerWhitelist, predeploys.OVM_DeployerWhitelist,
types.string types.string
) )
.setAction(async (args) => { .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) const provider = new ethers.providers.JsonRpcProvider(args.contractsRpcUrl)
let signer: ethers.Signer let signer: ethers.Signer
if (!args.useLedger) { if (!args.useLedger) {
...@@ -72,11 +97,26 @@ task('whitelist') ...@@ -72,11 +97,26 @@ task('whitelist')
throw new Error(`Incorrect key. Owner ${owner}, Signer ${addr}`) throw new Error(`Incorrect key. Owner ${owner}, Signer ${addr}`)
} }
const res = await deployerWhitelist.setWhitelistedDeployer( const addresses = []
args.address, if (args.address !== undefined) {
true, addresses.push(args.address)
{ gasPrice: args.transactionGasPrice } } else {
) const addressFile = fs.readFileSync(args.addressPath, 'utf8')
await res.wait() for (const line of addressFile.split('\n')) {
console.log(`Whitelisted ${args.address}`) 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()
}
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment