Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 49 additions & 9 deletions packages/contracts/tasks/whitelist.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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',
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
}
})