Skip to content

Commit c7c8891

Browse files
committed
chore: update hardhat-graph-protocol to latest linting config
Signed-off-by: Tomás Migone <[email protected]>
1 parent 2eb49a0 commit c7c8891

File tree

19 files changed

+105
-116
lines changed

19 files changed

+105
-116
lines changed

packages/hardhat-graph-protocol/README.md

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@ pnpm add --dev hardhat-graph-protocol
2121
Add the plugin to your `hardhat.config.ts`:
2222

2323
```ts
24-
import "hardhat-graph-protocol";
24+
import 'hardhat-graph-protocol'
2525
```
2626

2727
### Using @graphprotocol/toolshed
28+
2829
To use the plugin you'll need to configure the target networks. We recommend using our base hardhat configuration which can be imported from `@graphprotocol/toolshed`:
2930

3031
```ts
3132
import { hardhatBaseConfig, networksUserConfig } from '@graphprotocol/toolshed/hardhat'
32-
import "hardhat-graph-protocol";
33+
import 'hardhat-graph-protocol'
3334

3435
const config: HardhatUserConfig = {
3536
...networksUserConfig,
@@ -40,12 +41,14 @@ export default config // or just "export default hardhatBaseConfig"
4041
```
4142

4243
### Manual configuration
44+
4345
To manually configure target networks:
4446

4547
**Hardhat: Network config**
48+
4649
```ts
4750
networks: {
48-
arbitrumOne: {
51+
arbitrumOne: {
4952
chainId: 42161,
5053
url: `https://arbitrum-one.infura.io/v3/123456`
5154
deployments: {
@@ -55,6 +58,7 @@ To manually configure target networks:
5558
},
5659
}
5760
```
61+
5862
**Hardhat: Graph config**
5963

6064
Additionally, the plugin adds a new config field to hardhat's config file: `graph`. This can be used used to define defaults for all networks:
@@ -86,10 +90,10 @@ The interface for the graph object can be found [here](src/types.ts), it's expan
8690
```ts
8791
export type GraphRuntimeEnvironment = {
8892
[deploymentName]: {
89-
contracts: DeploymentContractsType,
90-
addressBook: DeploymentAddressBookType,
93+
contracts: DeploymentContractsType
94+
addressBook: DeploymentAddressBookType
9195
actions: DeplyomentActionsType
92-
},
96+
}
9397
provider: HardhatEthersProvider
9498
chainId: number
9599
accounts: {
@@ -110,26 +114,31 @@ export type GraphRuntimeEnvironment = {
110114
The plugin provides one object for each configured deployment, this object allows easily interacting with the associated deployment with a few additional features. The current deployments that are supported: `horizon` and `subgraphService`.
111115
112116
Each deployment will be of the form:
117+
113118
```ts
114119
[deploymentName]: {
115120
contracts: DeploymentContractsType,
116121
addressBook: DeploymentAddressBookType,
117122
actions: DeplyomentActionsType
118123
},
119124
```
125+
120126
Where:
127+
121128
- `contracts`: an object with all the contracts available in the deployment, already instanced, fully typed and ready to go.
122129
- `addressBook`: an object allowing read and write access to the deployment's address book.
123130
- `actions`: (optional) an object with helper functions to perform common actions in the associated deployment.
124131
125132
**Transaction logging**
126133
127134
Any transactions made using the `contracts` object will be automatically logged both to the console and to a file:
135+
128136
- `file`, in the project's root directory: `tx-YYYY-MM-DD.log`
129137
- `console`, not shown by default. Run with `DEBUG=toolshed:tx` to enable them.
130138
131139
Note that this does not apply to getter functions (`view` or `pure`) as those are not state modifying calls.
132140
An example log output:
141+
133142
```
134143
[2025-04-10T20:32:37.182Z] > Sending transaction: HorizonStaking.addToProvision
135144
[2025-04-10T20:32:37.182Z] = Sender: 0xACa94ef8bD5ffEE41947b4585a84BdA5a3d3DA6E
@@ -145,7 +154,7 @@ An example log output:
145154
[2025-04-10T20:32:40.946Z] ✔ Transaction succeeded!
146155
```
147156
148-
__Note__ Transaction logging requires using js Proxy which strips down some type definitions from contract methods. This means that when transaction logging is enabled `contract.functionName.estimateGas` for example will not be available.
157+
**Note** Transaction logging requires using js Proxy which strips down some type definitions from contract methods. This means that when transaction logging is enabled `contract.functionName.estimateGas` for example will not be available.
149158
150159
**Transaction auto-awaiting**
151160
@@ -162,6 +171,7 @@ await tx.wait(10)
162171
```
163172

164173
**Examples**
174+
165175
```js
166176
const graph = hre.graph()
167177
const { GraphPayments, HorizonStaking, GraphToken } = graph.horizon.contracts
@@ -179,7 +189,7 @@ await HorizonStaking.connect(signer).provision(signer.address, dataService.addre
179189
// Do the same but using actions - in this case the `provision` helper also approves and stakes
180190
await provision(signer, [signer.address, dataService.address, 100_000_000, 10_000, 42_690])
181191

182-
// Read the address book
192+
// Read the address book
183193
const entry = graph.horizon.addressBook.getEntry('HorizonStaking')
184194
console.log(entry.address) // HorizonStaking proxy address
185195
console.log(entry.implementation) // HorizonStaking implementation address
@@ -188,6 +198,7 @@ console.log(entry.implementation) // HorizonStaking implementation address
188198
### Accounts
189199

190200
The plugin provides helper functions to derive signers from the configured accounts in hardhat config:
201+
191202
```ts
192203
hardhat: {
193204
chainId: 31337,
@@ -198,16 +209,16 @@ The plugin provides helper functions to derive signers from the configured accou
198209
},
199210
```
200211

201-
| Function | Description | Default account derivation index |
202-
|----------|-------------|-------------|
203-
| `getAccounts()` | Returns all the accounts listed below | - |
204-
| `getDeployer()` | Returns the deployer signer | 0 |
205-
| `getGovernor()` | Returns the governor signer | 1 |
206-
| `getArbitrator()` | Returns the arbitrator signer | 2 |
207-
| `getPauseGuardian()` | Returns the pause guardian signer | 3 |
208-
| `getSubgraphAvailabilityOracle()` | Returns a service provider signer | 4 |
209-
| `getGateway()` | Returns the gateway signer | 5 |
210-
| `getTestAccounts()` | Returns the test signers | 6-20 |
212+
| Function | Description | Default account derivation index |
213+
| --------------------------------- | ------------------------------------- | -------------------------------- |
214+
| `getAccounts()` | Returns all the accounts listed below | - |
215+
| `getDeployer()` | Returns the deployer signer | 0 |
216+
| `getGovernor()` | Returns the governor signer | 1 |
217+
| `getArbitrator()` | Returns the arbitrator signer | 2 |
218+
| `getPauseGuardian()` | Returns the pause guardian signer | 3 |
219+
| `getSubgraphAvailabilityOracle()` | Returns a service provider signer | 4 |
220+
| `getGateway()` | Returns the gateway signer | 5 |
221+
| `getTestAccounts()` | Returns the test signers | 6-20 |
211222

212223
Note that these are just helper functions to enforce a convention on which index to use for each account. These might not match what is configured in the target protocol deployment.
213224

packages/hardhat-graph-protocol/eslint.config.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

packages/hardhat-graph-protocol/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"scripts": {
2828
"build": "tsc",
2929
"clean": "rm -rf dist",
30-
"lint": "eslint '**/*.{js,ts}' --fix",
30+
"lint": "eslint --fix --cache '**/*.{js,ts,cjs,mjs,jsx,tsx}'; prettier -w --cache --log-level warn '**/*.{js,ts,cjs,mjs,jsx,tsx}'",
3131
"test": "mocha --exit --recursive 'test/**/*.test.ts'",
3232
"prepublishOnly": "npm run build"
3333
},

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ import {
22
getAccounts as getAccountsToolshed,
33
getArbitrator,
44
getDeployer,
5-
getGateway, getGovernor, getPauseGuardian, getSubgraphAvailabilityOracle, getTestAccounts,
5+
getGateway,
6+
getGovernor,
7+
getPauseGuardian,
8+
getSubgraphAvailabilityOracle,
9+
getTestAccounts,
610
TEN_MILLION,
711
} from '@graphprotocol/toolshed'
812
import { setGRTBalance } from '@graphprotocol/toolshed/hardhat'
9-
10-
import type { Addressable } from 'ethers'
1113
import type { HardhatEthersProvider } from '@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider'
1214
import type { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers'
15+
import type { Addressable } from 'ethers'
1316

1417
type Accounts = {
1518
getAccounts: () => ReturnType<typeof getAccountsToolshed>
@@ -22,7 +25,11 @@ type Accounts = {
2225
getTestAccounts: () => ReturnType<typeof getTestAccounts>
2326
}
2427

25-
export function getAccounts(provider: HardhatEthersProvider, chainId: number, grtTokenAddress: string | Addressable | undefined): Accounts {
28+
export function getAccounts(
29+
provider: HardhatEthersProvider,
30+
chainId: number,
31+
grtTokenAddress: string | Addressable | undefined,
32+
): Accounts {
2633
return {
2734
getAccounts: async () => {
2835
const accounts = await getAccountsToolshed(provider)
@@ -77,7 +84,12 @@ export function getAccounts(provider: HardhatEthersProvider, chainId: number, gr
7784
}
7885
}
7986

80-
async function setBalanceIfLocal(provider: HardhatEthersProvider, chainId: number, grtTokenAddress: string | Addressable | undefined, account: HardhatEthersSigner) {
87+
async function setBalanceIfLocal(
88+
provider: HardhatEthersProvider,
89+
chainId: number,
90+
grtTokenAddress: string | Addressable | undefined,
91+
account: HardhatEthersSigner,
92+
) {
8193
if (grtTokenAddress && [1337, 31337].includes(chainId)) {
8294
await setGRTBalance(provider, grtTokenAddress, account.address, TEN_MILLION)
8395
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { HardhatPluginError } from 'hardhat/plugins'
2+
23
import { logError } from './logger'
34

45
export class GraphPluginError extends HardhatPluginError {

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

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
/* eslint-disable no-case-declarations */
1+
import type { GraphDeployments } from '@graphprotocol/toolshed/deployments'
2+
import { loadGraphHorizon, loadSubgraphService } from '@graphprotocol/toolshed/deployments'
3+
import { HardhatEthersProvider } from '@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider'
4+
import { lazyFunction } from 'hardhat/plugins'
5+
import type { HardhatConfig, HardhatRuntimeEnvironment, HardhatUserConfig } from 'hardhat/types'
26
import path from 'path'
37

4-
import { loadGraphHorizon, loadSubgraphService } from '@graphprotocol/toolshed/deployments'
5-
import { logDebug, logError } from './logger'
68
import { getAccounts } from './accounts'
79
import { getAddressBookPath } from './config'
810
import { GraphPluginError } from './error'
9-
import { HardhatEthersProvider } from '@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider'
10-
import { isGraphDeployment } from './types'
11-
import { lazyFunction } from 'hardhat/plugins'
12-
13-
import type { HardhatConfig, HardhatRuntimeEnvironment, HardhatUserConfig } from 'hardhat/types'
14-
import type { GraphDeployments } from '@graphprotocol/toolshed/deployments'
11+
import { logDebug, logError } from './logger'
1512
import type { GraphRuntimeEnvironmentOptions } from './types'
13+
import { isGraphDeployment } from './types'
1614

1715
export const greExtendConfig = (config: HardhatConfig, userConfig: Readonly<HardhatUserConfig>) => {
1816
const userPath = userConfig.paths?.graph
@@ -41,11 +39,15 @@ export const greExtendEnvironment = (hre: HardhatRuntimeEnvironment) => {
4139
}
4240
logDebug(`Chain Id: ${chainId}`)
4341

44-
const deployments = [...new Set([
45-
...Object.keys(opts.deployments ?? {}),
46-
...Object.keys(hre.network.config.deployments ?? {}),
47-
...Object.keys(hre.config.graph?.deployments ?? {}),
48-
].filter(v => isGraphDeployment(v)))]
42+
const deployments = [
43+
...new Set(
44+
[
45+
...Object.keys(opts.deployments ?? {}),
46+
...Object.keys(hre.network.config.deployments ?? {}),
47+
...Object.keys(hre.config.graph?.deployments ?? {}),
48+
].filter((v) => isGraphDeployment(v)),
49+
),
50+
]
4951
logDebug(`Detected deployments: ${deployments.join(', ')}`)
5052

5153
// Build the Graph Runtime Environment (GRE) for each deployment
@@ -70,7 +72,6 @@ export const greExtendEnvironment = (hre: HardhatRuntimeEnvironment) => {
7072
greDeployments.subgraphService = loadSubgraphService(addressBookPath, chainId, provider)
7173
break
7274
default:
73-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
7475
logError(`Skipping deployment ${deployment} - Reason: unknown deployment`)
7576
break
7677
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { extendConfig, extendEnvironment } from 'hardhat/config'
2-
import { greExtendConfig, greExtendEnvironment } from './gre'
3-
41
// This import is needed to let the TypeScript compiler know that it should include your type
52
// extensions in your npm package's types file.
63
import './type-extensions'
74

5+
import { extendConfig, extendEnvironment } from 'hardhat/config'
6+
7+
import { greExtendConfig, greExtendEnvironment } from './gre'
8+
89
// ** Graph Runtime Environment (GRE) extensions for the HRE **
910
extendConfig(greExtendConfig)
1011
extendEnvironment(greExtendEnvironment)

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { GraphDeploymentsList } from '@graphprotocol/toolshed/deployments'
2-
3-
import type { GraphDeploymentName, GraphDeployments } from '@graphprotocol/toolshed/deployments'
41
import type { GraphAccounts } from '@graphprotocol/toolshed'
2+
import type { GraphDeploymentName, GraphDeployments } from '@graphprotocol/toolshed/deployments'
3+
import { GraphDeploymentsList } from '@graphprotocol/toolshed/deployments'
54
import type { HardhatEthersProvider } from '@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider'
65
import type { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers'
76
export type GraphDeploymentOptions = {

packages/hardhat-graph-protocol/test/config.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { expect } from 'chai'
12
import path from 'path'
23

3-
import { expect } from 'chai'
44
import { getAddressBookPath } from '../src/config'
55
import { loadHardhatContext } from './helpers'
66

@@ -12,7 +12,7 @@ describe('GRE init functions', function () {
1212
expect(() => getAddressBookPath('horizon', this.hre, {})).to.throw('Must set a an addressBook path!')
1313
})
1414

15-
it('should throw if address book doesn\'t exist', function () {
15+
it("should throw if address book doesn't exist", function () {
1616
this.hre = loadHardhatContext('invalid-address-book', 'mainnet')
1717
expect(() => getAddressBookPath('horizon', this.hre, {})).to.throw(/Address book not found: /)
1818
})

packages/hardhat-graph-protocol/test/fixtures/files/addresses-arbsep.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,7 @@
106106
},
107107
"L2GNS": {
108108
"address": "0x3133948342F35b8699d8F94aeE064AbB76eDe965",
109-
"initArgs": [
110-
"0x9DB3ee191681f092607035d9BDA6e59FbEaCa695",
111-
"0xF21Df5BbA7EB9b54D8F60C560aFb9bA63e6aED1A"
112-
],
109+
"initArgs": ["0x9DB3ee191681f092607035d9BDA6e59FbEaCa695", "0xF21Df5BbA7EB9b54D8F60C560aFb9bA63e6aED1A"],
113110
"creationCodeHash": "0xcdd28bb3db05f1267ca0f5ea29536c61841be5937ce711b813924f8ff38918cc",
114111
"runtimeCodeHash": "0x4ca8c37c807bdfda1d6dcf441324b7ea14c6ddec5db37c20c2bf05aeae49bc0d",
115112
"txHash": "0x137140783a99a3e9a60048d607124626ca87e2b972e8cc05efb41ac87c3cbcc4",

0 commit comments

Comments
 (0)