Skip to content

Commit 72f7bb6

Browse files
authored
Improve configuration and tasks (#469)
Reorganize some actions as Hardhat tasks. Cleanup and refactor CLI.
1 parent 79da240 commit 72f7bb6

35 files changed

+475
-352
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"rules": {
99
"prefer-const": "warn",
1010
"no-extra-semi": "off",
11-
"@typescript-eslint/no-extra-semi": "warn",
11+
"@typescript-eslint/no-extra-semi": "off",
1212
"@typescript-eslint/no-inferrable-types": "warn",
1313
"@typescript-eslint/no-empty-function": "warn",
1414
"no-only-tests/no-only-tests": "error"

cli/commands/airdrop.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import consola from 'consola'
21
import inquirer from 'inquirer'
32
import fs from 'fs'
43
import PQueue from 'p-queue'
@@ -111,7 +110,7 @@ const loadRecipients = (path: string): Array<AirdropRecipient> => {
111110
logger.fatal(`Error loading address "${address}" please review the input file`)
112111
process.exit(1)
113112
}
114-
results.push({ address, amount: weiAmount as any, txHash })
113+
results.push({ address, amount: weiAmount, txHash })
115114
}
116115
return results
117116
}

cli/commands/contracts/curation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export const curationCommand = {
8080
},
8181
})
8282
},
83-
handler: (argv: CLIArgs): void => {
83+
handler: (): void => {
8484
yargs.showHelp()
8585
},
8686
}

cli/commands/contracts/disputeManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export const disputeManagerCommand = {
234234
},
235235
})
236236
},
237-
handler: (argv: CLIArgs): void => {
237+
handler: (): void => {
238238
yargs.showHelp()
239239
},
240240
}

cli/commands/contracts/ens.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { logger } from '../../logging'
77

88
export const registerTestName = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<void> => {
99
const name = cliArgs.name
10-
const testRegistrar = cli.contracts.ITestRegistrar
10+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
11+
const testRegistrar = (cli.contracts as any).ITestRegistrar
1112
const normalizedName = name.toLowerCase()
1213
const labelNameFull = `${normalizedName}.${'eth'}`
1314
const labelHashFull = utils.namehash(labelNameFull)
@@ -67,7 +68,7 @@ export const ensCommand = {
6768
},
6869
})
6970
},
70-
handler: (argv: CLIArgs): void => {
71+
handler: (): void => {
7172
yargs.showHelp()
7273
},
7374
}

cli/commands/contracts/ethereumDIDRegistry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const handleAccountMetadata = async (ipfs: string, path: string): Promise<string
3333
return IPFS.ipfsHashToBytes32(metaHash)
3434
}
3535

36-
export const setAttribute = async (cli: CLIEnvironment, cliArgs: CLIArgs) => {
36+
export const setAttribute = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<void> => {
3737
const metadataPath = cliArgs.metadataPath
3838
const ipfsEndpoint = cliArgs.ipfs
3939
const ethereumDIDRegistry = cli.contracts.IEthereumDIDRegistry
@@ -83,7 +83,7 @@ export const ethereumDIDRegistryCommand = {
8383
},
8484
})
8585
},
86-
handler: (argv: CLIArgs): void => {
86+
handler: (): void => {
8787
yargs.showHelp()
8888
},
8989
}

cli/commands/contracts/gns.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as fs from 'fs'
21
import yargs, { Argv } from 'yargs'
32
import { parseGRT } from '@graphprotocol/common-ts'
43

cli/commands/contracts/gsr-gdai.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
12
import yargs, { Argv } from 'yargs'
23
import { parseGRT } from '@graphprotocol/common-ts'
34

@@ -7,23 +8,23 @@ import { loadEnv, CLIArgs, CLIEnvironment } from '../../env'
78

89
export const setGSR = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<void> => {
910
const account = cliArgs.account
10-
const gdai = cli.contracts.GDAI
11+
const gdai = (cli.contracts as any).GDAI
1112

1213
logger.log(`Setting GSR to ${account}...`)
1314
await sendTransaction(cli.wallet, gdai, 'setGSR', [account])
1415
}
1516

1617
export const setRate = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<void> => {
1718
const amount = parseGRT(cliArgs.amount)
18-
const gsr = cli.contracts.GSRManager
19+
const gsr = (cli.contracts as any).GSRManager
1920

2021
logger.log(`Setting rate to ${amount}...`)
2122
await sendTransaction(cli.wallet, gsr, 'setRate', [amount])
2223
}
2324

2425
export const join = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<void> => {
2526
const amount = parseGRT(cliArgs.amount)
26-
const gsr = cli.contracts.GSRManager
27+
const gsr = (cli.contracts as any).GSRManager
2728

2829
logger.log(`Reminder - you must call approve on the GSR before`)
2930
logger.log(`Joining GSR with ${cliArgs.amount} tokens...`)
@@ -33,15 +34,15 @@ export const join = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<void>
3334
export const mint = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<void> => {
3435
const amount = parseGRT(cliArgs.amount)
3536
const account = cliArgs.account
36-
const gdai = cli.contracts.GDAI
37+
const gdai = (cli.contracts as any).GDAI
3738

3839
logger.log(`Minting ${cliArgs.amount} GDAI for user ${account}...`)
3940
await sendTransaction(cli.wallet, gdai, 'mint', [account, amount])
4041
}
4142

4243
export const burn = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<void> => {
4344
const amount = parseGRT(cliArgs.amount)
44-
const gdai = cli.contracts.GDAI
45+
const gdai = (cli.contracts as any).GDAI
4546

4647
logger.log(`Burning ${cliArgs.amount} GDAI...`)
4748
await sendTransaction(cli.wallet, gdai, 'burn', [amount])
@@ -50,7 +51,7 @@ export const burn = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<void>
5051
export const transfer = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<void> => {
5152
const amount = parseGRT(cliArgs.amount)
5253
const account = cliArgs.account
53-
const gdai = cli.contracts.GDAI
54+
const gdai = (cli.contracts as any).GDAI
5455

5556
logger.log(`Transferring ${cliArgs.amount} tokens to user ${account}...`)
5657
await sendTransaction(cli.wallet, gdai, 'transfer', [account, amount])
@@ -59,7 +60,7 @@ export const transfer = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<v
5960
export const approve = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<void> => {
6061
const amount = parseGRT(cliArgs.amount)
6162
const account = cliArgs.account
62-
const gdai = cli.contracts.GDAI
63+
const gdai = (cli.contracts as any).GDAI
6364

6465
logger.log(`Approving ${cliArgs.amount} GDAI for user ${account} to spend...`)
6566
await sendTransaction(cli.wallet, gdai, 'approve', [account, amount])

cli/commands/contracts/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { stakingCommand } from './staking'
1111
import { anyCommand } from './any'
1212
import { governanceCommand } from './governance'
1313

14-
import { CLIArgs } from '../../env'
1514
import { disputeManagerCommand } from './disputeManager'
1615

1716
export const contractsCommand = {
@@ -31,7 +30,7 @@ export const contractsCommand = {
3130
.command(disputeManagerCommand)
3231
.command(governanceCommand)
3332
},
34-
handler: (argv: CLIArgs): void => {
33+
handler: (): void => {
3534
yargs.showHelp()
3635
},
3736
}

cli/commands/contracts/serviceRegistry.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const register = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<v
1212
logger.log(`Registering indexer ${cli.walletAddress} with url ${url} and geoHash ${geoHash}`)
1313
await sendTransaction(cli.wallet, serviceRegistry, 'register', [url, geoHash])
1414
}
15-
export const unregister = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<void> => {
15+
export const unregister = async (cli: CLIEnvironment): Promise<void> => {
1616
const serviceRegistry = cli.contracts.ServiceRegistry
1717

1818
logger.log(`Unregistering indexer ${cli.walletAddress}`)
@@ -52,11 +52,11 @@ export const serviceRegistryCommand = {
5252
command: 'unregister',
5353
describe: 'Unregister an indexer in the service registry',
5454
handler: async (argv: CLIArgs): Promise<void> => {
55-
return unregister(await loadEnv(argv), argv)
55+
return unregister(await loadEnv(argv))
5656
},
5757
})
5858
},
59-
handler: (argv: CLIArgs): void => {
59+
handler: (): void => {
6060
yargs.showHelp()
6161
},
6262
}

cli/commands/contracts/staking.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const closeAllocation = async (cli: CLIEnvironment, cliArgs: CLIArgs): Pr
5252
await sendTransaction(cli.wallet, staking, 'close', [allocationID])
5353
}
5454

55-
export const collect = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<void> => {
55+
export const collect = async (): Promise<void> => {
5656
logger.log(
5757
`COLLECT NOT IMPLEMENTED. NORMALLY CALLED FROM PROXY ACCOUNT. plan is to
5858
implement this in the near future when we start adding some more
@@ -243,8 +243,8 @@ export const stakingCommand = {
243243
demandOption: true,
244244
})
245245
},
246-
handler: async (argv: CLIArgs): Promise<void> => {
247-
return collect(await loadEnv(argv), argv)
246+
handler: async (): Promise<void> => {
247+
return collect()
248248
},
249249
})
250250
.command({

cli/commands/proxy/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import yargs, { Argv } from 'yargs'
22

3-
import { CLIArgs } from '../../env'
4-
53
import { setAdminCommand } from './admin'
64
import { listCommand } from './list'
75
import { upgradeCommand } from './upgrade'
@@ -12,7 +10,7 @@ export const proxyCommand = {
1210
builder: (yargs: Argv): yargs.Argv => {
1311
return yargs.command(listCommand).command(upgradeCommand).command(setAdminCommand)
1412
},
15-
handler: (argv: CLIArgs): void => {
13+
handler: (): void => {
1614
yargs.showHelp()
1715
},
1816
}

cli/config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ function isAddressBookRef(value: string): boolean {
2828
function parseAddressBookRef(addressBook: AddressBook, value: string): string {
2929
const ref: string = ABRefMatcher.exec(value as string)[1]
3030
const [contractName, contractAttr] = ref.split('.')
31+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3132
const entry = addressBook.getEntry(contractName) as { [key: string]: any }
3233
return entry[contractAttr]
3334
}
3435

35-
export function readConfig(path: string) {
36+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
37+
export function readConfig(path: string): any {
3638
const file = fs.readFileSync(path, 'utf8')
3739
return YAML.parse(file)
3840
}

cli/contracts.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { providers, Signer } from 'ethers'
2+
3+
import { AddressBook } from './address-book'
4+
import { logger } from './logging'
5+
import { getContractAt } from './network'
6+
7+
import { EpochManager } from '../build/types/EpochManager'
8+
import { DisputeManager } from '../build/types/DisputeManager'
9+
import { Staking } from '../build/types/Staking'
10+
import { ServiceRegistry } from '../build/types/ServiceRegistry'
11+
import { Curation } from '../build/types/Curation'
12+
import { RewardsManager } from '../build/types/RewardsManager'
13+
import { GNS } from '../build/types/GNS'
14+
import { GraphProxyAdmin } from '../build/types/GraphProxyAdmin'
15+
import { GraphToken } from '../build/types/GraphToken'
16+
import { Controller } from '../build/types/Controller'
17+
import { BancorFormula } from '../build/types/BancorFormula'
18+
import { IENS } from '../build/types/IENS'
19+
import { IEthereumDIDRegistry } from '../build/types/IEthereumDIDRegistry'
20+
21+
export interface NetworkContracts {
22+
EpochManager: EpochManager
23+
DisputeManager: DisputeManager
24+
Staking: Staking
25+
ServiceRegistry: ServiceRegistry
26+
Curation: Curation
27+
RewardsManager: RewardsManager
28+
GNS: GNS
29+
GraphProxyAdmin: GraphProxyAdmin
30+
GraphToken: GraphToken
31+
Controller: Controller
32+
BancorFormula: BancorFormula
33+
IENS: IENS
34+
IEthereumDIDRegistry: IEthereumDIDRegistry
35+
}
36+
37+
export const loadContracts = (
38+
addressBook: AddressBook,
39+
signerOrProvider?: Signer | providers.Provider,
40+
): NetworkContracts => {
41+
const contracts = {}
42+
for (const contractName of addressBook.listEntries()) {
43+
const contractEntry = addressBook.getEntry(contractName)
44+
try {
45+
const contract = getContractAt(contractName, contractEntry.address)
46+
contracts[contractName] = contract
47+
if (signerOrProvider) {
48+
contracts[contractName] = contracts[contractName].connect(signerOrProvider)
49+
}
50+
} catch (err) {
51+
logger.warn(`Could not load contract ${contractName} - ${err.message}`)
52+
}
53+
}
54+
return contracts as NetworkContracts
55+
}

cli/defaults.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Options } from 'yargs'
2-
import { utils, Overrides } from 'ethers'
2+
import { Overrides } from 'ethers'
33

44
export const local = {
55
mnemonic: 'myth like bonus scare over problem client lizard pioneer submit female collect',

cli/env.ts

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import { utils, BigNumber, Contract, Wallet } from 'ethers'
1+
import { utils, BigNumber, Wallet, Overrides } from 'ethers'
22
import { Argv } from 'yargs'
33

44
import { logger } from './logging'
55
import { getAddressBook, AddressBook } from './address-book'
66
import { defaultOverrides } from './defaults'
7-
import { getContractAt } from './network'
87
import { getProvider } from './utils'
8+
import { loadContracts, NetworkContracts } from './contracts'
99

1010
const { formatEther } = utils
1111

12+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1213
export type CLIArgs = { [key: string]: any } & Argv['argv']
1314

1415
export interface CLIEnvironment {
@@ -18,31 +19,11 @@ export interface CLIEnvironment {
1819
walletAddress: string
1920
wallet: Wallet
2021
addressBook: AddressBook
21-
contracts: { [key: string]: Contract }
22+
contracts: NetworkContracts
2223
argv: CLIArgs
2324
}
2425

25-
export const loadContracts = (
26-
addressBook: AddressBook,
27-
wallet?: Wallet,
28-
): { [key: string]: Contract } => {
29-
const contracts = {}
30-
for (const contractName of addressBook.listEntries()) {
31-
const contractEntry = addressBook.getEntry(contractName)
32-
try {
33-
const contract = getContractAt(contractName, contractEntry.address)
34-
contracts[contractName] = contract
35-
if (wallet) {
36-
contracts[contractName] = contracts[contractName].connect(wallet)
37-
}
38-
} catch (err) {
39-
logger.warn(`Could not load contract ${contractName} - ${err.message}`)
40-
}
41-
}
42-
return contracts
43-
}
44-
45-
export const displayGasOverrides = () => {
26+
export const displayGasOverrides = (): Overrides => {
4627
const r = { gasPrice: 'auto', gasLimit: 'auto', ...defaultOverrides }
4728
if (r['gasPrice']) {
4829
r['gasPrice'] = r['gasPrice'].toString()

cli/network.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export const sendTransaction = async (
105105
sender: Signer,
106106
contract: Contract,
107107
fn: string,
108+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
108109
params?: Array<any>,
109110
overrides?: Overrides,
110111
): Promise<providers.TransactionReceipt> => {
@@ -168,8 +169,6 @@ export const deployProxy = async (
168169
)
169170
}
170171

171-
export const deployProxyAndAccept = async () => {}
172-
173172
export const deployContract = async (
174173
name: string,
175174
args: Array<ContractParam>,
@@ -349,7 +348,7 @@ export const linkLibraries = (
349348

350349
if (libraries) {
351350
if (artifact.linkReferences) {
352-
for (const [fileName, fileReferences] of Object.entries(artifact.linkReferences)) {
351+
for (const fileReferences of Object.values(artifact.linkReferences)) {
353352
for (const [libName, fixups] of Object.entries(fileReferences)) {
354353
const addr = libraries[libName]
355354
if (addr === undefined) {

0 commit comments

Comments
 (0)