Skip to content

Commit e8e2e9f

Browse files
committed
feat: create a base hardhat config
Signed-off-by: Tomás Migone <[email protected]>
1 parent c3c94ca commit e8e2e9f

File tree

10 files changed

+129
-96
lines changed

10 files changed

+129
-96
lines changed

packages/hardhat-graph-protocol/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"json5": "^2.2.3"
4848
},
4949
"devDependencies": {
50+
"@nomicfoundation/hardhat-verify": "^2.0.12",
5051
"@types/chai": "^4.0.0",
5152
"@types/debug": "^4.1.12",
5253
"@types/mocha": "^10.0.9",
@@ -55,6 +56,7 @@
5556
"eslint-graph-config": "workspace:^0.0.1",
5657
"ethers": "^6.13.4",
5758
"hardhat": "^2.22.16",
59+
"hardhat-secure-accounts": "^1.0.4",
5860
"mocha": "^10.8.2",
5961
"ts-node": "^8.0.0",
6062
"typescript": "^5.6.3"
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import { vars } from 'hardhat/config'
2+
3+
import type { HardhatUserConfig, NetworksUserConfig, ProjectPathsUserConfig, SolidityUserConfig } from 'hardhat/types'
4+
import type { EtherscanConfig } from '@nomicfoundation/hardhat-verify/types'
5+
6+
// This next import ensures secure accounts config is correctly typed
7+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
8+
import type { SecureAccountsOptions } from 'hardhat-secure-accounts/src/type-extensions'
9+
10+
// Environment variables
11+
const ARBISCAN_API_KEY = vars.get('ARBISCAN_API_KEY', undefined)
12+
13+
// RPCs
14+
const VIRTUAL_ARBITRUM_SEPOLIA_RPC = vars.has('VIRTUAL_ARBITRUM_SEPOLIA_RPC') ? vars.get('VIRTUAL_ARBITRUM_SEPOLIA_RPC') : undefined
15+
const ARBITRUM_SEPOLIA_RPC = vars.get('ARBITRUM_SEPOLIA_RPC', 'https://sepolia-rollup.arbitrum.io/rpc')
16+
17+
// Accounts
18+
const DEPLOYER_PRIVATE_KEY = vars.get('DEPLOYER_PRIVATE_KEY', undefined)
19+
const GOVERNOR_PRIVATE_KEY = vars.get('GOVERNOR_PRIVATE_KEY', undefined)
20+
const getTestnetAccounts = () => {
21+
const accounts: string[] = []
22+
if (DEPLOYER_PRIVATE_KEY) accounts.push(DEPLOYER_PRIVATE_KEY)
23+
if (GOVERNOR_PRIVATE_KEY) accounts.push(GOVERNOR_PRIVATE_KEY)
24+
return accounts.length > 0 ? accounts : undefined
25+
}
26+
const getHardhatAccounts = () => {
27+
return {
28+
mnemonic: 'myth like bonus scare over problem client lizard pioneer submit female collect',
29+
}
30+
}
31+
32+
export const solidityUserConfig: SolidityUserConfig = {
33+
version: '0.8.27',
34+
settings: {
35+
optimizer: {
36+
enabled: true,
37+
runs: 1,
38+
},
39+
},
40+
}
41+
42+
export const projectPathsUserConfig: ProjectPathsUserConfig = {
43+
artifacts: './build/contracts',
44+
sources: './contracts',
45+
}
46+
47+
export const etherscanUserConfig: Partial<EtherscanConfig> = {
48+
apiKey: {
49+
arbitrumSepolia: ARBISCAN_API_KEY,
50+
},
51+
customChains: [
52+
{
53+
network: 'arbitrumSepolia',
54+
chainId: 421614,
55+
urls: { apiURL: 'https://api-sepolia.arbiscan.io/api', browserURL: 'https://sepolia.arbiscan.io/' },
56+
},
57+
],
58+
}
59+
60+
// In general:
61+
// - hardhat is used for unit tests
62+
// - localhost is used for local development on a hardhat network or fork
63+
// - virtualArbitrumSepolia is for Tenderly Virtual Testnet
64+
export const networksUserConfig: NetworksUserConfig = {
65+
hardhat: {
66+
chainId: 31337,
67+
accounts: getHardhatAccounts(),
68+
},
69+
localhost: {
70+
chainId: 31337,
71+
url: 'http://localhost:8545',
72+
accounts: getTestnetAccounts(),
73+
},
74+
arbitrumSepolia: {
75+
chainId: 421614,
76+
url: ARBITRUM_SEPOLIA_RPC,
77+
secureAccounts: {
78+
enabled: true,
79+
},
80+
},
81+
...(VIRTUAL_ARBITRUM_SEPOLIA_RPC && {
82+
virtualArbitrumSepolia: {
83+
chainId: 421615,
84+
url: VIRTUAL_ARBITRUM_SEPOLIA_RPC,
85+
accounts: getTestnetAccounts(),
86+
},
87+
}),
88+
}
89+
90+
export const hardhatBaseConfig: HardhatUserConfig & { etherscan: Partial<EtherscanConfig> } = {
91+
solidity: solidityUserConfig,
92+
paths: projectPathsUserConfig,
93+
secureAccounts: {
94+
enabled: false,
95+
},
96+
networks: networksUserConfig,
97+
graph: {
98+
deployments: {
99+
horizon: {
100+
addressBook: 'addresses.json',
101+
},
102+
},
103+
},
104+
etherscan: etherscanUserConfig,
105+
}
106+
107+
export default hardhatBaseConfig

packages/hardhat-graph-protocol/src/sdk/ignition/ignition.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import path from 'path'
66

77
export function loadConfig(configPath: string, prefix: string, networkName: string): any {
88
const configFileCandidates = [
9-
path.join(require.main?.path ?? '', configPath, `${prefix}.${networkName}.json5`),
10-
path.join(require.main?.path ?? '', configPath, `${prefix}.default.json5`),
9+
path.resolve(process.cwd(), configPath, `${prefix}.${networkName}.json5`),
10+
path.resolve(process.cwd(), configPath, `${prefix}.default.json5`),
1111
]
1212

1313
const configFile = configFileCandidates.find(file => fs.existsSync(file))
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
import { loadConfig, saveAddressBook } from './ignition/ignition'
2+
import { hardhatBaseConfig } from './hardhat.base.config'
23

3-
export const IgnitionHelper = { saveAddressBook, loadConfig }
4+
const IgnitionHelper = { saveAddressBook, loadConfig }
5+
export { hardhatBaseConfig, IgnitionHelper }

packages/horizon/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@ Graph Horizon is the next evolution of the Graph Protocol.
66

77
The following environment variables might be required:
88

9-
- `ETHERSCAN_API_KEY`: Etherscan API key
9+
| Variable | Description |
10+
|----------|-------------|
11+
| `ARBISCAN_API_KEY` | Arbiscan API key |
12+
| `DEPLOYER_PRIVATE_KEY` | Deployer private key - for testnet deployments |
13+
| `GOVERNOR_PRIVATE_KEY` | Governor private key - for testnet deployments |
14+
| `ARBITRUM_SEPOLIA_RPC` | Arbitrum Sepolia RPC URL |
15+
| `VIRTUAL_ARBITRUM_SEPOLIA_RPC` | Virtual Arbitrum Sepolia RPC URL |
1016

1117
You can set them using Hardhat:
1218

1319
```bash
14-
npx hardhat vars set ETHERSCAN_API_KEY
20+
npx hardhat vars set <variable>
1521
```
1622

1723
## Build

packages/horizon/hardhat.config.ts

Lines changed: 2 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,15 @@
1-
import { vars } from 'hardhat/config'
2-
3-
import type { HardhatUserConfig } from 'hardhat/config'
1+
import { hardhatBaseConfig } from 'hardhat-graph-protocol/sdk'
42

53
// Hardhat plugins
64
import '@nomicfoundation/hardhat-foundry'
75
import '@nomicfoundation/hardhat-toolbox'
86
import '@nomicfoundation/hardhat-ignition-ethers'
9-
import '@tenderly/hardhat-tenderly'
107
import 'hardhat-storage-layout'
118
import 'hardhat-contract-sizer'
129
import 'hardhat-secure-accounts'
1310

14-
// Environment variables
15-
const ETHERSCAN_API_KEY = vars.get('ETHERSCAN_API_KEY', '')
16-
const ARBITRUM_VIRTUAL_TESTNET_URL = vars.get('ARBITRUM_VIRTUAL_TESTNET_URL', '')
17-
const DEPLOYER_PRIVATE_KEY = vars.get('DEPLOYER_PRIVATE_KEY')
18-
const GOVERNOR_PRIVATE_KEY = vars.get('GOVERNOR_PRIVATE_KEY')
19-
20-
const getNetworkAccounts = () => {
21-
const accounts: string[] = []
22-
if (vars.has('DEPLOYER_PRIVATE_KEY')) accounts.push(DEPLOYER_PRIVATE_KEY)
23-
if (vars.has('GOVERNOR_PRIVATE_KEY')) accounts.push(GOVERNOR_PRIVATE_KEY)
24-
return accounts.length > 0 ? accounts : undefined
25-
}
26-
2711
if (process.env.BUILD_RUN !== 'true') {
2812
require('hardhat-graph-protocol')
2913
}
3014

31-
const config: HardhatUserConfig = {
32-
solidity: {
33-
version: '0.8.27',
34-
settings: {
35-
optimizer: {
36-
enabled: true,
37-
runs: 1,
38-
},
39-
},
40-
},
41-
paths: {
42-
artifacts: './build/contracts',
43-
sources: './contracts',
44-
},
45-
secureAccounts: {
46-
enabled: false,
47-
},
48-
networks: {
49-
hardhat: {
50-
chainId: 31337,
51-
accounts: {
52-
mnemonic: 'myth like bonus scare over problem client lizard pioneer submit female collect',
53-
},
54-
},
55-
localhost: {
56-
chainId: 31337,
57-
url: 'http://localhost:8545',
58-
accounts: getNetworkAccounts(),
59-
},
60-
arbitrumSepolia: {
61-
chainId: 421614,
62-
secureAccounts: {
63-
enabled: true,
64-
},
65-
url: 'https://sepolia-rollup.arbitrum.io/rpc',
66-
},
67-
arbitrumVirtualTestnet: {
68-
chainId: 421615,
69-
url: ARBITRUM_VIRTUAL_TESTNET_URL,
70-
accounts: getNetworkAccounts(),
71-
},
72-
},
73-
tenderly: {
74-
project: 'graph-network',
75-
username: 'graphprotocol',
76-
},
77-
graph: {
78-
deployments: {
79-
horizon: {
80-
addressBook: 'addresses.json',
81-
},
82-
},
83-
},
84-
etherscan: {
85-
apiKey: {
86-
arbitrumSepolia: ETHERSCAN_API_KEY,
87-
},
88-
customChains: [
89-
{
90-
network: 'arbitrumSepolia',
91-
chainId: 421614,
92-
urls: {
93-
apiURL: 'https://api-sepolia.arbiscan.io/api',
94-
browserURL: 'https://sepolia.arbiscan.io/',
95-
},
96-
},
97-
],
98-
},
99-
}
100-
101-
export default config
15+
export default hardhatBaseConfig

packages/horizon/scripts/deploy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { IgnitionHelper } from 'hardhat-graph-protocol/sdk'
44
import DeployModule from '../ignition/modules/deploy'
55

66
async function main() {
7-
const HorizonConfig = IgnitionHelper.loadConfig('../ignition/configs/', 'horizon', hre.network.name)
7+
const HorizonConfig = IgnitionHelper.loadConfig('./ignition/configs/', 'horizon', hre.network.name)
88

99
// Deploy Horizon
1010
const deployment = await ignition.deploy(DeployModule, {

packages/horizon/scripts/migrate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import MigrateModule from '../ignition/modules/migrate'
55

66
async function main() {
77
console.log(getHorizonBanner())
8-
const HorizonMigrateConfig = IgnitionHelper.loadConfig('../ignition/configs/', 'horizon-migrate', hre.network.name)
8+
const HorizonMigrateConfig = IgnitionHelper.loadConfig('./ignition/configs/', 'horizon-migrate', hre.network.name)
99

1010
const signers = await hre.ethers.getSigners()
1111
const deployer = signers[0]

yarn.lock

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5380,7 +5380,7 @@ __metadata:
53805380
languageName: node
53815381
linkType: hard
53825382

5383-
"@nomicfoundation/hardhat-verify@npm:^2.0.8":
5383+
"@nomicfoundation/hardhat-verify@npm:^2.0.12, @nomicfoundation/hardhat-verify@npm:^2.0.8":
53845384
version: 2.0.12
53855385
resolution: "@nomicfoundation/hardhat-verify@npm:2.0.12"
53865386
dependencies:
@@ -15716,6 +15716,7 @@ __metadata:
1571615716
"@graphprotocol/horizon": "workspace:^0.0.1"
1571715717
"@graphprotocol/subgraph-service": "workspace:^0.0.1"
1571815718
"@nomicfoundation/hardhat-ethers": "npm:^3.0.8"
15719+
"@nomicfoundation/hardhat-verify": "npm:^2.0.12"
1571915720
"@types/chai": "npm:^4.0.0"
1572015721
"@types/debug": "npm:^4.1.12"
1572115722
"@types/mocha": "npm:^10.0.9"
@@ -15725,6 +15726,7 @@ __metadata:
1572515726
eslint-graph-config: "workspace:^0.0.1"
1572615727
ethers: "npm:^6.13.4"
1572715728
hardhat: "npm:^2.22.16"
15729+
hardhat-secure-accounts: "npm:^1.0.4"
1572815730
json5: "npm:^2.2.3"
1572915731
mocha: "npm:^10.8.2"
1573015732
ts-node: "npm:^8.0.0"

0 commit comments

Comments
 (0)