Skip to content

Commit d52644a

Browse files
committed
fix: ensure toolshed core components dont import hardhat runtime
Signed-off-by: Tomás Migone <[email protected]>
1 parent 7715ce2 commit d52644a

File tree

9 files changed

+134
-66
lines changed

9 files changed

+134
-66
lines changed

packages/hardhat-graph-protocol/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# hardhat-graph-protocol
22

3+
## 0.1.16
4+
5+
### Patch Changes
6+
7+
- Updated dependencies
8+
- @graphprotocol/toolshed@0.5.0
9+
310
## 0.1.15
411

512
### Patch Changes

packages/hardhat-graph-protocol/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hardhat-graph-protocol",
3-
"version": "0.1.15",
3+
"version": "0.1.16",
44
"publishConfig": {
55
"access": "public"
66
},
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import {
2+
getAccounts as getAccountsToolshed,
3+
getArbitrator,
4+
getDeployer,
5+
getGateway, getGovernor, getPauseGuardian, getSubgraphAvailabilityOracle, getTestAccounts,
6+
TEN_MILLION,
7+
} from '@graphprotocol/toolshed'
8+
import { setGRTBalance } from '@graphprotocol/toolshed/hardhat'
9+
10+
import type { Addressable } from 'ethers'
11+
import type { HardhatEthersProvider } from '@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider'
12+
import type { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers'
13+
14+
type Accounts = {
15+
getAccounts: () => ReturnType<typeof getAccountsToolshed>
16+
getDeployer: (accountIndex?: number) => ReturnType<typeof getDeployer>
17+
getGovernor: (accountIndex?: number) => ReturnType<typeof getGovernor>
18+
getArbitrator: (accountIndex?: number) => ReturnType<typeof getArbitrator>
19+
getPauseGuardian: (accountIndex?: number) => ReturnType<typeof getPauseGuardian>
20+
getSubgraphAvailabilityOracle: (accountIndex?: number) => ReturnType<typeof getSubgraphAvailabilityOracle>
21+
getGateway: (accountIndex?: number) => ReturnType<typeof getGateway>
22+
getTestAccounts: () => ReturnType<typeof getTestAccounts>
23+
}
24+
25+
export function getAccounts(provider: HardhatEthersProvider, chainId: number, grtTokenAddress: string | Addressable): Accounts {
26+
return {
27+
getAccounts: async () => {
28+
const accounts = await getAccountsToolshed(provider)
29+
for (const account of Object.values(accounts)) {
30+
if (typeof account === 'object' && 'address' in account) {
31+
await setBalanceIfLocal(provider, chainId, grtTokenAddress, account)
32+
} else if (Array.isArray(account)) {
33+
for (const testAccount of account) {
34+
await setBalanceIfLocal(provider, chainId, grtTokenAddress, testAccount)
35+
}
36+
}
37+
}
38+
return accounts
39+
},
40+
getDeployer: async (accountIndex?: number) => {
41+
const account = await getDeployer(provider, accountIndex)
42+
await setBalanceIfLocal(provider, chainId, grtTokenAddress, account)
43+
return account
44+
},
45+
getGovernor: async (accountIndex?: number) => {
46+
const account = await getGovernor(provider, accountIndex)
47+
await setBalanceIfLocal(provider, chainId, grtTokenAddress, account)
48+
return account
49+
},
50+
getArbitrator: async (accountIndex?: number) => {
51+
const account = await getArbitrator(provider, accountIndex)
52+
await setBalanceIfLocal(provider, chainId, grtTokenAddress, account)
53+
return account
54+
},
55+
getPauseGuardian: async (accountIndex?: number) => {
56+
const account = await getPauseGuardian(provider, accountIndex)
57+
await setBalanceIfLocal(provider, chainId, grtTokenAddress, account)
58+
return account
59+
},
60+
getSubgraphAvailabilityOracle: async (accountIndex?: number) => {
61+
const account = await getSubgraphAvailabilityOracle(provider, accountIndex)
62+
await setBalanceIfLocal(provider, chainId, grtTokenAddress, account)
63+
return account
64+
},
65+
getGateway: async (accountIndex?: number) => {
66+
const account = await getGateway(provider, accountIndex)
67+
await setBalanceIfLocal(provider, chainId, grtTokenAddress, account)
68+
return account
69+
},
70+
getTestAccounts: async () => {
71+
const accounts = await getTestAccounts(provider)
72+
for (const account of accounts) {
73+
await setBalanceIfLocal(provider, chainId, grtTokenAddress, account)
74+
}
75+
return accounts
76+
},
77+
}
78+
}
79+
80+
async function setBalanceIfLocal(provider: HardhatEthersProvider, chainId: number, grtTokenAddress: string | Addressable, account: HardhatEthersSigner) {
81+
if ([1337, 31337].includes(chainId)) {
82+
await setGRTBalance(provider, grtTokenAddress, account.address, TEN_MILLION)
83+
}
84+
}

packages/hardhat-graph-protocol/src/gre.ts

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
/* eslint-disable no-case-declarations */
22
import path from 'path'
33

4-
import {
5-
getAccounts,
6-
getArbitrator,
7-
getDeployer,
8-
getGateway,
9-
getGovernor,
10-
getPauseGuardian,
11-
getSubgraphAvailabilityOracle,
12-
getTestAccounts,
13-
} from '@graphprotocol/toolshed'
144
import { loadGraphHorizon, loadSubgraphService } from '@graphprotocol/toolshed/deployments'
155
import { logDebug, logError } from './logger'
166
import { getAddressBookPath } from './config'
@@ -22,6 +12,7 @@ import { lazyFunction } from 'hardhat/plugins'
2212
import type { HardhatConfig, HardhatRuntimeEnvironment, HardhatUserConfig } from 'hardhat/types'
2313
import type { GraphDeployments } from '@graphprotocol/toolshed/deployments'
2414
import type { GraphRuntimeEnvironmentOptions } from './types'
15+
import { getAccounts } from './accounts'
2516

2617
export const greExtendConfig = (config: HardhatConfig, userConfig: Readonly<HardhatUserConfig>) => {
2718
const userPath = userConfig.paths?.graph
@@ -79,6 +70,7 @@ export const greExtendEnvironment = (hre: HardhatRuntimeEnvironment) => {
7970
greDeployments.subgraphService = loadSubgraphService(addressBookPath, chainId, provider)
8071
break
8172
default:
73+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
8274
logError(`Skipping deployment ${deployment} - Reason: unknown deployment`)
8375
break
8476
}
@@ -90,25 +82,15 @@ export const greExtendEnvironment = (hre: HardhatRuntimeEnvironment) => {
9082
}
9183

9284
// Accounts
93-
const grtTokenAddress = greDeployments?.horizon?.contracts?.GraphToken?.target
94-
const accounts = {
95-
getAccounts: async () => getAccounts(provider, grtTokenAddress),
96-
getDeployer: async (accountIndex?: number) => getDeployer(provider, accountIndex, grtTokenAddress),
97-
getGovernor: async (accountIndex?: number) => getGovernor(provider, accountIndex, grtTokenAddress),
98-
getArbitrator: async (accountIndex?: number) => getArbitrator(provider, accountIndex, grtTokenAddress),
99-
getPauseGuardian: async (accountIndex?: number) => getPauseGuardian(provider, accountIndex, grtTokenAddress),
100-
getSubgraphAvailabilityOracle: async (accountIndex?: number) => getSubgraphAvailabilityOracle(provider, accountIndex, grtTokenAddress),
101-
getGateway: async (accountIndex?: number) => getGateway(provider, accountIndex, grtTokenAddress),
102-
getTestAccounts: async () => getTestAccounts(provider, grtTokenAddress),
103-
}
85+
const accounts = getAccounts(provider, chainId, greDeployments.horizon?.contracts?.GraphToken?.target)
10486

10587
logDebug('GRE initialized successfully!')
10688

10789
return {
10890
...greDeployments,
10991
provider,
11092
chainId,
111-
accounts: accounts,
93+
accounts,
11294
}
11395
})
11496
}

packages/horizon/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"hardhat": "^2.22.18",
5656
"hardhat-contract-sizer": "^2.10.0",
5757
"hardhat-gas-reporter": "^1.0.8",
58-
"hardhat-graph-protocol": "workspace:^0.1.15",
58+
"hardhat-graph-protocol": "workspace:^0.1.16",
5959
"hardhat-secure-accounts": "^1.0.5",
6060
"lint-staged": "^15.2.2",
6161
"prettier": "^3.2.5",

packages/subgraph-service/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"hardhat": "^2.22.18",
5757
"hardhat-contract-sizer": "^2.10.0",
5858
"hardhat-gas-reporter": "^1.0.8",
59-
"hardhat-graph-protocol": "workspace:^0.1.15",
59+
"hardhat-graph-protocol": "workspace:^0.1.16",
6060
"hardhat-secure-accounts": "^1.0.5",
6161
"json5": "^2.2.3",
6262
"lint-staged": "^15.2.2",

packages/toolshed/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# @graphprotocol/toolshed
22

3+
## 0.5.0
4+
5+
### Minor Changes
6+
7+
- Ensure toolshed core components dont import hardhat runtime
8+
9+
### Patch Changes
10+
11+
- @graphprotocol/horizon@0.3.2
12+
- @graphprotocol/subgraph-service@0.3.4
13+
314
## 0.4.2
415

516
### Patch Changes

packages/toolshed/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@graphprotocol/toolshed",
3-
"version": "0.4.2",
3+
"version": "0.5.0",
44
"publishConfig": {
55
"access": "public"
66
},
Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
import { setGRTBalance } from '../hardhat'
2-
import { TEN_MILLION } from './constants'
3-
import { toBeHex } from 'ethers'
4-
5-
import type { Addressable } from 'ethers'
61
import type { HardhatEthersProvider } from '@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider'
72
import type { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers'
83

@@ -34,43 +29,43 @@ export type GraphAccounts = {
3429
test: HardhatEthersSigner[]
3530
}
3631

37-
export async function getAccounts(provider: HardhatEthersProvider, grtTokenAddress?: string | Addressable): Promise<GraphAccounts> {
32+
export async function getAccounts(provider: HardhatEthersProvider): Promise<GraphAccounts> {
3833
return {
39-
deployer: await getDeployer(provider, GraphAccountIndex.Deployer, grtTokenAddress),
40-
governor: await getGovernor(provider, GraphAccountIndex.Governor, grtTokenAddress),
41-
arbitrator: await getArbitrator(provider, GraphAccountIndex.Arbitrator, grtTokenAddress),
42-
pauseGuardian: await getPauseGuardian(provider, GraphAccountIndex.PauseGuardian, grtTokenAddress),
43-
subgraphAvailabilityOracle: await getSubgraphAvailabilityOracle(provider, GraphAccountIndex.SubgraphAvailabilityOracle, grtTokenAddress),
44-
gateway: await getGateway(provider, GraphAccountIndex.Gateway, grtTokenAddress),
45-
test: await getTestAccounts(provider, grtTokenAddress),
34+
deployer: await getDeployer(provider, GraphAccountIndex.Deployer),
35+
governor: await getGovernor(provider, GraphAccountIndex.Governor),
36+
arbitrator: await getArbitrator(provider, GraphAccountIndex.Arbitrator),
37+
pauseGuardian: await getPauseGuardian(provider, GraphAccountIndex.PauseGuardian),
38+
subgraphAvailabilityOracle: await getSubgraphAvailabilityOracle(provider, GraphAccountIndex.SubgraphAvailabilityOracle),
39+
gateway: await getGateway(provider, GraphAccountIndex.Gateway),
40+
test: await getTestAccounts(provider),
4641
}
4742
}
4843

49-
export async function getDeployer(provider: HardhatEthersProvider, accountIndex = GraphAccountIndex.Deployer, grtTokenAddress?: string | Addressable) {
50-
return _getAccount(provider, accountIndex, grtTokenAddress)
44+
export async function getDeployer(provider: HardhatEthersProvider, accountIndex = GraphAccountIndex.Deployer) {
45+
return _getAccount(provider, accountIndex)
5146
}
5247

53-
export async function getGovernor(provider: HardhatEthersProvider, accountIndex = GraphAccountIndex.Governor, grtTokenAddress?: string | Addressable) {
54-
return _getAccount(provider, accountIndex, grtTokenAddress)
48+
export async function getGovernor(provider: HardhatEthersProvider, accountIndex = GraphAccountIndex.Governor) {
49+
return _getAccount(provider, accountIndex)
5550
}
5651

57-
export async function getArbitrator(provider: HardhatEthersProvider, accountIndex = GraphAccountIndex.Arbitrator, grtTokenAddress?: string | Addressable) {
58-
return _getAccount(provider, accountIndex, grtTokenAddress)
52+
export async function getArbitrator(provider: HardhatEthersProvider, accountIndex = GraphAccountIndex.Arbitrator) {
53+
return _getAccount(provider, accountIndex)
5954
}
6055

61-
export async function getPauseGuardian(provider: HardhatEthersProvider, accountIndex = GraphAccountIndex.PauseGuardian, grtTokenAddress?: string | Addressable) {
62-
return _getAccount(provider, accountIndex, grtTokenAddress)
56+
export async function getPauseGuardian(provider: HardhatEthersProvider, accountIndex = GraphAccountIndex.PauseGuardian) {
57+
return _getAccount(provider, accountIndex)
6358
}
6459

65-
export async function getSubgraphAvailabilityOracle(provider: HardhatEthersProvider, accountIndex = GraphAccountIndex.SubgraphAvailabilityOracle, grtTokenAddress?: string | Addressable) {
66-
return _getAccount(provider, accountIndex, grtTokenAddress)
60+
export async function getSubgraphAvailabilityOracle(provider: HardhatEthersProvider, accountIndex = GraphAccountIndex.SubgraphAvailabilityOracle) {
61+
return _getAccount(provider, accountIndex)
6762
}
6863

69-
export async function getGateway(provider: HardhatEthersProvider, accountIndex = GraphAccountIndex.Gateway, grtTokenAddress?: string | Addressable) {
70-
return _getAccount(provider, accountIndex, grtTokenAddress)
64+
export async function getGateway(provider: HardhatEthersProvider, accountIndex = GraphAccountIndex.Gateway) {
65+
return _getAccount(provider, accountIndex)
7166
}
7267

73-
export async function getTestAccounts(provider: HardhatEthersProvider, grtTokenAddress?: string | Addressable) {
68+
export async function getTestAccounts(provider: HardhatEthersProvider) {
7469
const accounts = await provider.send('eth_accounts', []) as string[]
7570
const numReservedAccounts = Object.values(GraphAccountIndex).filter(v => typeof v === 'number').length
7671
if (accounts.length < numReservedAccounts) {
@@ -79,21 +74,10 @@ export async function getTestAccounts(provider: HardhatEthersProvider, grtTokenA
7974
return await Promise.all(
8075
accounts
8176
.slice(numReservedAccounts)
82-
.map(async account => await _getAccount(provider, account, grtTokenAddress)),
77+
.map(async account => await _getAccount(provider, account)),
8378
)
8479
}
8580

86-
async function _getAccount(provider: HardhatEthersProvider, accountIndex: number | string, grtTokenAddress?: string | Addressable) {
87-
const account = await provider.getSigner(accountIndex)
88-
89-
// If the chain is local, set balance to 10M GRT
90-
if (grtTokenAddress) {
91-
const chainId = await provider.send('eth_chainId', []) as string
92-
const isLocal = [toBeHex(1337), toBeHex(31337)].includes(toBeHex(BigInt(chainId)))
93-
if (isLocal) {
94-
await setGRTBalance(provider, grtTokenAddress, account.address, TEN_MILLION)
95-
}
96-
}
97-
98-
return account
81+
async function _getAccount(provider: HardhatEthersProvider, accountIndex: number | string) {
82+
return await provider.getSigner(accountIndex)
9983
}

0 commit comments

Comments
 (0)