Skip to content

Commit 16a1387

Browse files
authored
Simplify GRE account logic (#655)
* fix: simplify GRE account management Signed-off-by: Tomás Migone <[email protected]>
1 parent 35aa936 commit 16a1387

File tree

5 files changed

+46
-50
lines changed

5 files changed

+46
-50
lines changed

tasks/deployment/accounts.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ task('migrate:accounts', '[localhost] Creates protocol accounts and saves them i
1010
throw new Error('This task can only be run on localhost network')
1111
}
1212

13-
const { graphConfig, getNamedAccounts, getDeployer } = hre.graph({
13+
const { graphConfig, getDeployer } = hre.graph({
1414
graphConfig: taskArgs.graphConfig,
1515
})
1616

1717
console.log('> Generating addresses')
1818

1919
const deployer = await getDeployer()
20-
const {
20+
const [
21+
,
2122
arbitrator,
2223
governor,
2324
authority,
2425
availabilityOracle,
2526
pauseGuardian,
2627
allocationExchangeOwner,
27-
} = await getNamedAccounts()
28-
console.log(await getNamedAccounts())
28+
] = await hre.ethers.getSigners()
2929

3030
console.log(`- Deployer: ${deployer.address}`)
3131
console.log(`- Arbitrator: ${arbitrator.address}`)

tasks/deployment/ownership.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ task(
2323
console.log(`- Governor: ${governor.address}`)
2424

2525
const txs: ContractTransaction[] = []
26-
txs.push(await contracts.GraphToken.connect(governor.signer).acceptOwnership())
27-
txs.push(await contracts.Controller.connect(governor.signer).acceptOwnership())
28-
txs.push(await contracts.GraphProxyAdmin.connect(governor.signer).acceptOwnership())
29-
txs.push(await contracts.SubgraphNFT.connect(governor.signer).acceptOwnership())
26+
txs.push(await contracts.GraphToken.connect(governor).acceptOwnership())
27+
txs.push(await contracts.Controller.connect(governor).acceptOwnership())
28+
txs.push(await contracts.GraphProxyAdmin.connect(governor).acceptOwnership())
29+
txs.push(await contracts.SubgraphNFT.connect(governor).acceptOwnership())
3030

3131
await Promise.all(txs.map((tx) => tx.wait()))
3232
console.log('Done!')

tasks/deployment/unpause.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ task('migrate:unpause', 'Unpause protocol')
1212
const { governor } = await getNamedAccounts()
1313

1414
console.log('> Unpausing protocol')
15-
const tx = await contracts.Controller.connect(governor.signer).setPaused(false)
15+
const tx = await contracts.Controller.connect(governor).setPaused(false)
1616
await tx.wait()
1717
console.log('Done!')
1818
})

tasks/gre.ts

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { lazyFunction, lazyObject } from 'hardhat/plugins'
55
import { getAddressBook } from '../cli/address-book'
66
import { loadContracts } from '../cli/contracts'
77
import { getItemValue, readConfig } from '../cli/config'
8-
import { Account, GREOptions, NamedAccounts } from './type-extensions'
8+
import { GREOptions, NamedAccounts } from './type-extensions'
99
import fs from 'fs'
10-
import { Signer, VoidSigner } from 'ethers'
10+
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
1111

1212
// Graph Runtime Environment (GRE) extensions for the HRE
1313
extendEnvironment((hre: HardhatRuntimeEnvironment) => {
@@ -33,36 +33,40 @@ extendEnvironment((hre: HardhatRuntimeEnvironment) => {
3333
'allocationExchangeOwner',
3434
]
3535

36-
const getTestAccounts = async (): Promise<Account[]> => {
37-
const accounts = []
38-
const signers: Signer[] = await hre.ethers.getSigners()
36+
const getTestAccounts = async (): Promise<SignerWithAddress[]> => {
37+
// Get list of privileged accounts we don't want as test accounts
38+
const namedAccounts = await getNamedAccounts()
39+
const blacklist = namedAccountList.map((a) => {
40+
const account = namedAccounts[a] as SignerWithAddress
41+
return account.address
42+
})
43+
blacklist.push((await getDeployer()).address)
3944

40-
// Skip deployer and named accounts
41-
for (let i = namedAccountList.length + 1; i < signers.length; i++) {
42-
accounts.push({ signer: signers[i], address: await signers[i].getAddress() })
43-
}
44-
return accounts
45+
// Get signers and filter out blacklisted accounts
46+
let signers: SignerWithAddress[] = await hre.ethers.getSigners()
47+
signers = signers.filter((s) => {
48+
return !blacklist.includes(s.address)
49+
})
50+
51+
return signers
4552
}
4653

47-
// Returns void signers. Upgrades to signer on loca networks.
4854
const getNamedAccounts = async (): Promise<NamedAccounts> => {
49-
const namedAccounts = namedAccountList.reduce((acc, name) => {
55+
const namedAccounts = namedAccountList.reduce(async (accountsPromise, name) => {
56+
const accounts = await accountsPromise
5057
const address = getItemValue(readConfig(graphConfigPath, true), `general/${name}`)
51-
52-
if (chainId === '1337') {
53-
const signer = hre.ethers.provider.getSigner(address)
54-
acc[name] = { signer, address: address }
55-
} else {
56-
const signer = new VoidSigner(address)
57-
acc[name] = { signer, address: signer.address }
58-
}
59-
60-
return acc
61-
}, {} as NamedAccounts)
58+
accounts[name] = await hre.ethers.getSigner(address)
59+
return accounts
60+
}, Promise.resolve({} as NamedAccounts))
6261

6362
return namedAccounts
6463
}
6564

65+
const getDeployer = async () => {
66+
const signer = hre.ethers.provider.getSigner(0)
67+
return hre.ethers.getSigner(await signer.getAddress())
68+
}
69+
6670
return {
6771
addressBook: lazyObject(() => getAddressBook(addressBookPath, chainId)),
6872
graphConfig: lazyObject(() => readConfig(graphConfigPath, true)),
@@ -71,10 +75,7 @@ extendEnvironment((hre: HardhatRuntimeEnvironment) => {
7175
),
7276
getNamedAccounts: lazyFunction(() => getNamedAccounts),
7377
getTestAccounts: lazyFunction(() => getTestAccounts),
74-
getDeployer: lazyFunction(() => async () => {
75-
const signer = hre.ethers.provider.getSigner(0)
76-
return { signer, address: await signer.getAddress() }
77-
}),
78+
getDeployer: lazyFunction(() => getDeployer),
7879
}
7980
}
8081
})

tasks/type-extensions.d.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Signer } from 'ethers'
1+
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
22
import { AddressBook } from '../cli/address-book'
33
import { NetworkContracts } from '../cli/contracts'
44

@@ -7,18 +7,13 @@ export interface GREOptions {
77
graphConfig?: string
88
}
99

10-
export interface Account {
11-
readonly signer: Signer
12-
readonly address: string
13-
}
14-
1510
export interface NamedAccounts {
16-
arbitrator: Account
17-
governor: Account
18-
authority: Account
19-
availabilityOracle: Account
20-
pauseGuardian: Account
21-
allocationExchangeOwner: Account
11+
arbitrator: SignerWithAddress
12+
governor: SignerWithAddress
13+
authority: SignerWithAddress
14+
availabilityOracle: SignerWithAddress
15+
pauseGuardian: SignerWithAddress
16+
allocationExchangeOwner: SignerWithAddress
2217
}
2318

2419
declare module 'hardhat/types/runtime' {
@@ -28,8 +23,8 @@ declare module 'hardhat/types/runtime' {
2823
graphConfig: any
2924
addressBook: AddressBook
3025
getNamedAccounts: () => Promise<NamedAccounts>
31-
getTestAccounts: () => Promise<Account[]>
32-
getDeployer: () => Promise<Account>
26+
getTestAccounts: () => Promise<SignerWithAddress[]>
27+
getDeployer: () => Promise<SignerWithAddress>
3328
}
3429
}
3530
}

0 commit comments

Comments
 (0)