diff --git a/tasks/deployment/accounts.ts b/tasks/deployment/accounts.ts index da30366b5..d26102beb 100644 --- a/tasks/deployment/accounts.ts +++ b/tasks/deployment/accounts.ts @@ -10,22 +10,22 @@ task('migrate:accounts', '[localhost] Creates protocol accounts and saves them i throw new Error('This task can only be run on localhost network') } - const { graphConfig, getNamedAccounts, getDeployer } = hre.graph({ + const { graphConfig, getDeployer } = hre.graph({ graphConfig: taskArgs.graphConfig, }) console.log('> Generating addresses') const deployer = await getDeployer() - const { + const [ + , arbitrator, governor, authority, availabilityOracle, pauseGuardian, allocationExchangeOwner, - } = await getNamedAccounts() - console.log(await getNamedAccounts()) + ] = await hre.ethers.getSigners() console.log(`- Deployer: ${deployer.address}`) console.log(`- Arbitrator: ${arbitrator.address}`) diff --git a/tasks/deployment/ownership.ts b/tasks/deployment/ownership.ts index c5a872806..83b4e6485 100644 --- a/tasks/deployment/ownership.ts +++ b/tasks/deployment/ownership.ts @@ -23,10 +23,10 @@ task( console.log(`- Governor: ${governor.address}`) const txs: ContractTransaction[] = [] - txs.push(await contracts.GraphToken.connect(governor.signer).acceptOwnership()) - txs.push(await contracts.Controller.connect(governor.signer).acceptOwnership()) - txs.push(await contracts.GraphProxyAdmin.connect(governor.signer).acceptOwnership()) - txs.push(await contracts.SubgraphNFT.connect(governor.signer).acceptOwnership()) + txs.push(await contracts.GraphToken.connect(governor).acceptOwnership()) + txs.push(await contracts.Controller.connect(governor).acceptOwnership()) + txs.push(await contracts.GraphProxyAdmin.connect(governor).acceptOwnership()) + txs.push(await contracts.SubgraphNFT.connect(governor).acceptOwnership()) await Promise.all(txs.map((tx) => tx.wait())) console.log('Done!') diff --git a/tasks/deployment/unpause.ts b/tasks/deployment/unpause.ts index fa5767de5..7f0b71f57 100644 --- a/tasks/deployment/unpause.ts +++ b/tasks/deployment/unpause.ts @@ -12,7 +12,7 @@ task('migrate:unpause', 'Unpause protocol') const { governor } = await getNamedAccounts() console.log('> Unpausing protocol') - const tx = await contracts.Controller.connect(governor.signer).setPaused(false) + const tx = await contracts.Controller.connect(governor).setPaused(false) await tx.wait() console.log('Done!') }) diff --git a/tasks/gre.ts b/tasks/gre.ts index f2a062747..41028e958 100644 --- a/tasks/gre.ts +++ b/tasks/gre.ts @@ -5,9 +5,9 @@ import { lazyFunction, lazyObject } from 'hardhat/plugins' import { getAddressBook } from '../cli/address-book' import { loadContracts } from '../cli/contracts' import { getItemValue, readConfig } from '../cli/config' -import { Account, GREOptions, NamedAccounts } from './type-extensions' +import { GREOptions, NamedAccounts } from './type-extensions' import fs from 'fs' -import { Signer, VoidSigner } from 'ethers' +import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers' // Graph Runtime Environment (GRE) extensions for the HRE extendEnvironment((hre: HardhatRuntimeEnvironment) => { @@ -33,36 +33,40 @@ extendEnvironment((hre: HardhatRuntimeEnvironment) => { 'allocationExchangeOwner', ] - const getTestAccounts = async (): Promise => { - const accounts = [] - const signers: Signer[] = await hre.ethers.getSigners() + const getTestAccounts = async (): Promise => { + // Get list of privileged accounts we don't want as test accounts + const namedAccounts = await getNamedAccounts() + const blacklist = namedAccountList.map((a) => { + const account = namedAccounts[a] as SignerWithAddress + return account.address + }) + blacklist.push((await getDeployer()).address) - // Skip deployer and named accounts - for (let i = namedAccountList.length + 1; i < signers.length; i++) { - accounts.push({ signer: signers[i], address: await signers[i].getAddress() }) - } - return accounts + // Get signers and filter out blacklisted accounts + let signers: SignerWithAddress[] = await hre.ethers.getSigners() + signers = signers.filter((s) => { + return !blacklist.includes(s.address) + }) + + return signers } - // Returns void signers. Upgrades to signer on loca networks. const getNamedAccounts = async (): Promise => { - const namedAccounts = namedAccountList.reduce((acc, name) => { + const namedAccounts = namedAccountList.reduce(async (accountsPromise, name) => { + const accounts = await accountsPromise const address = getItemValue(readConfig(graphConfigPath, true), `general/${name}`) - - if (chainId === '1337') { - const signer = hre.ethers.provider.getSigner(address) - acc[name] = { signer, address: address } - } else { - const signer = new VoidSigner(address) - acc[name] = { signer, address: signer.address } - } - - return acc - }, {} as NamedAccounts) + accounts[name] = await hre.ethers.getSigner(address) + return accounts + }, Promise.resolve({} as NamedAccounts)) return namedAccounts } + const getDeployer = async () => { + const signer = hre.ethers.provider.getSigner(0) + return hre.ethers.getSigner(await signer.getAddress()) + } + return { addressBook: lazyObject(() => getAddressBook(addressBookPath, chainId)), graphConfig: lazyObject(() => readConfig(graphConfigPath, true)), @@ -71,10 +75,7 @@ extendEnvironment((hre: HardhatRuntimeEnvironment) => { ), getNamedAccounts: lazyFunction(() => getNamedAccounts), getTestAccounts: lazyFunction(() => getTestAccounts), - getDeployer: lazyFunction(() => async () => { - const signer = hre.ethers.provider.getSigner(0) - return { signer, address: await signer.getAddress() } - }), + getDeployer: lazyFunction(() => getDeployer), } } }) diff --git a/tasks/type-extensions.d.ts b/tasks/type-extensions.d.ts index 400be724f..5dbaa09ab 100644 --- a/tasks/type-extensions.d.ts +++ b/tasks/type-extensions.d.ts @@ -1,4 +1,4 @@ -import { Signer } from 'ethers' +import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers' import { AddressBook } from '../cli/address-book' import { NetworkContracts } from '../cli/contracts' @@ -7,18 +7,13 @@ export interface GREOptions { graphConfig?: string } -export interface Account { - readonly signer: Signer - readonly address: string -} - export interface NamedAccounts { - arbitrator: Account - governor: Account - authority: Account - availabilityOracle: Account - pauseGuardian: Account - allocationExchangeOwner: Account + arbitrator: SignerWithAddress + governor: SignerWithAddress + authority: SignerWithAddress + availabilityOracle: SignerWithAddress + pauseGuardian: SignerWithAddress + allocationExchangeOwner: SignerWithAddress } declare module 'hardhat/types/runtime' { @@ -28,8 +23,8 @@ declare module 'hardhat/types/runtime' { graphConfig: any addressBook: AddressBook getNamedAccounts: () => Promise - getTestAccounts: () => Promise - getDeployer: () => Promise + getTestAccounts: () => Promise + getDeployer: () => Promise } } }