Skip to content

Commit c3c94ca

Browse files
authored
Merge pull request #1093 from graphprotocol/tmigone/ignition-refactor
2 parents 519c5d8 + 835519f commit c3c94ca

File tree

121 files changed

+827
-37156
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+827
-37156
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,7 @@ tx-builder-*.json
5757

5858
# Hardhat Ignition
5959
**/chain-31337/
60+
**/chain-1377/
61+
**/horizon-localhost/
62+
**/horizon-hardhat/
6063
!**/ignition/**/artifacts/

packages/eslint-graph-config/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default [
3636
'@typescript-eslint/no-inferrable-types': 'warn',
3737
'@typescript-eslint/no-empty-function': 'warn',
3838
'no-only-tests/no-only-tests': 'error',
39-
'no-secrets/no-secrets': ['error', { tolerance: 4.1 }],
39+
'no-secrets/no-secrets': ['error', { tolerance: 5.1 }],
4040
'sort-imports': [
4141
'warn', {
4242
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],

packages/hardhat-graph-protocol/package.json

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,18 @@
1313
],
1414
"author": "Tomás Migone <[email protected]>",
1515
"license": "MIT",
16-
"main": "dist/src/index.js",
17-
"types": "dist/src/index.d.ts",
16+
"main": "./dist/src/index.js",
17+
"exports": {
18+
".": {
19+
"types": "./dist/src/index.d.ts",
20+
"default": "./dist/src/index.js"
21+
},
22+
"./sdk": {
23+
"types": "./src/sdk/index.ts",
24+
"default": "./src/sdk/index.ts"
25+
}
26+
},
27+
"types": "./dist/src/index.d.ts",
1828
"scripts": {
1929
"build": "tsc",
2030
"clean": "rm -rf dist",
@@ -33,7 +43,8 @@
3343
"@graphprotocol/horizon": "workspace:^0.0.1",
3444
"@graphprotocol/subgraph-service": "workspace:^0.0.1",
3545
"@nomicfoundation/hardhat-ethers": "^3.0.8",
36-
"debug": "^4.3.7"
46+
"debug": "^4.3.7",
47+
"json5": "^2.2.3"
3748
},
3849
"devDependencies": {
3950
"@types/chai": "^4.0.0",
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
require('json5/lib/register')
3+
4+
import fs from 'fs'
5+
import path from 'path'
6+
7+
export function loadConfig(configPath: string, prefix: string, networkName: string): any {
8+
const configFileCandidates = [
9+
path.join(require.main?.path ?? '', configPath, `${prefix}.${networkName}.json5`),
10+
path.join(require.main?.path ?? '', configPath, `${prefix}.default.json5`),
11+
]
12+
13+
const configFile = configFileCandidates.find(file => fs.existsSync(file))
14+
if (!configFile) {
15+
throw new Error(
16+
`Config file not found. Tried:\n${configFileCandidates.map(f => `- ${f}`).join('\n')}`,
17+
)
18+
}
19+
20+
return removeNFromBigInts(require(configFile))
21+
}
22+
23+
export function saveAddressBook(
24+
contracts: any,
25+
chainId: number | undefined,
26+
addressBook = 'addresses.json',
27+
): Record<string, Record<string, string>> {
28+
if (!chainId) {
29+
throw new Error('Chain ID is required')
30+
}
31+
32+
// Use different address book for local networks - this one can be gitignored
33+
if ([1377, 31337].includes(chainId)) {
34+
addressBook = 'addresses-local.json'
35+
}
36+
37+
const output = fs.existsSync(addressBook)
38+
? JSON.parse(fs.readFileSync(addressBook, 'utf8'))
39+
: {}
40+
41+
output[chainId] = output[chainId] || {}
42+
43+
// Extract contract names and addresses
44+
Object.entries(contracts).forEach(([contractName, contract]: [string, any]) => {
45+
output[chainId][contractName] = contract.target
46+
})
47+
48+
// Write to output file
49+
const outputDir = path.dirname(addressBook)
50+
if (!fs.existsSync(outputDir)) {
51+
fs.mkdirSync(outputDir, { recursive: true })
52+
}
53+
54+
fs.writeFileSync(addressBook, JSON.stringify(output, null, 2))
55+
56+
return output as Record<string, Record<string, string>>
57+
}
58+
59+
// Ignition requires "n" suffix for bigints, but not here
60+
function removeNFromBigInts(obj: any): any {
61+
if (typeof obj === 'string') {
62+
return obj.replace(/(\d+)n/g, '$1')
63+
} else if (Array.isArray(obj)) {
64+
return obj.map(removeNFromBigInts)
65+
} else if (typeof obj === 'object' && obj !== null) {
66+
for (const key in obj) {
67+
obj[key] = removeNFromBigInts(obj[key])
68+
}
69+
}
70+
return obj
71+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { loadConfig, saveAddressBook } from './ignition/ignition'
2+
3+
export const IgnitionHelper = { saveAddressBook, loadConfig }

packages/horizon/README.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,29 @@ You can set them using Hardhat:
1414
npx hardhat vars set ETHERSCAN_API_KEY
1515
```
1616

17-
## Deployment
18-
19-
We use Hardhat Ignition to deploy the contracts. To build and deploy Graph Horizon run the following commands:
17+
## Build
2018

2119
```bash
2220
yarn install
2321
yarn build
24-
npx hardhat ignition deploy ./ignition/modules/horizon.ts \
25-
--parameters ./ignition/configs/horizon.hardhat.json5 \
26-
--network hardhat
2722
```
2823

29-
You can use any network defined in `hardhat.config.ts` by replacing `hardhat` with the network name.
24+
## Deploy
25+
26+
### New deployment
27+
To deploy Graph Horizon from scratch run the following command:
28+
29+
```bash
30+
npx hardhat run scripts/deploy.ts --network hardhat
31+
```
3032

3133
Note that this will deploy a standalone version of Graph Horizon contracts, meaning the Subgraph Service or any other data service will not be deployed. If you want to deploy the Subgraph Service please refer to the [Subgraph Service README](../subgraph-service/README.md) for deploy instructions.
34+
35+
### Upgrade deployment
36+
To upgrade an existing deployment of the original Graph Protocol to Graph Horizon, run the following command:
37+
38+
```bash
39+
npx hardhat run scripts/migrate.ts --network hardhat
40+
```
41+
42+
Note that this will deploy a standalone version of Graph Horizon contracts, meaning the Subgraph Service or any other data service will not be deployed. If you want to deploy the Subgraph Service please refer to the [Subgraph Service README](../subgraph-service/README.md) for deploy instructions.

packages/horizon/addresses.json

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

0 commit comments

Comments
 (0)