Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,7 @@ tx-builder-*.json

# Hardhat Ignition
**/chain-31337/
**/chain-1377/
**/horizon-localhost/
**/horizon-hardhat/
!**/ignition/**/artifacts/
2 changes: 1 addition & 1 deletion packages/eslint-graph-config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default [
'@typescript-eslint/no-inferrable-types': 'warn',
'@typescript-eslint/no-empty-function': 'warn',
'no-only-tests/no-only-tests': 'error',
'no-secrets/no-secrets': ['error', { tolerance: 4.1 }],
'no-secrets/no-secrets': ['error', { tolerance: 5.1 }],
'sort-imports': [
'warn', {
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
Expand Down
17 changes: 14 additions & 3 deletions packages/hardhat-graph-protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,18 @@
],
"author": "Tomás Migone <[email protected]>",
"license": "MIT",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"main": "./dist/src/index.js",
"exports": {
".": {
"types": "./dist/src/index.d.ts",
"default": "./dist/src/index.js"
},
"./sdk": {
"types": "./src/sdk/index.ts",
"default": "./src/sdk/index.ts"
}
},
"types": "./dist/src/index.d.ts",
"scripts": {
"build": "tsc",
"clean": "rm -rf dist",
Expand All @@ -33,7 +43,8 @@
"@graphprotocol/horizon": "workspace:^0.0.1",
"@graphprotocol/subgraph-service": "workspace:^0.0.1",
"@nomicfoundation/hardhat-ethers": "^3.0.8",
"debug": "^4.3.7"
"debug": "^4.3.7",
"json5": "^2.2.3"
},
"devDependencies": {
"@types/chai": "^4.0.0",
Expand Down
71 changes: 71 additions & 0 deletions packages/hardhat-graph-protocol/src/sdk/ignition/ignition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
require('json5/lib/register')

import fs from 'fs'
import path from 'path'

export function loadConfig(configPath: string, prefix: string, networkName: string): any {
const configFileCandidates = [
path.join(require.main?.path ?? '', configPath, `${prefix}.${networkName}.json5`),
path.join(require.main?.path ?? '', configPath, `${prefix}.default.json5`),
]

const configFile = configFileCandidates.find(file => fs.existsSync(file))
if (!configFile) {
throw new Error(
`Config file not found. Tried:\n${configFileCandidates.map(f => `- ${f}`).join('\n')}`,
)
}

return removeNFromBigInts(require(configFile))
}

export function saveAddressBook(
contracts: any,
chainId: number | undefined,
addressBook = 'addresses.json',
): Record<string, Record<string, string>> {
if (!chainId) {
throw new Error('Chain ID is required')
}

// Use different address book for local networks - this one can be gitignored
if ([1377, 31337].includes(chainId)) {
addressBook = 'addresses-local.json'
}

const output = fs.existsSync(addressBook)
? JSON.parse(fs.readFileSync(addressBook, 'utf8'))
: {}

output[chainId] = output[chainId] || {}

// Extract contract names and addresses
Object.entries(contracts).forEach(([contractName, contract]: [string, any]) => {
output[chainId][contractName] = contract.target
})

// Write to output file
const outputDir = path.dirname(addressBook)
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true })
}

fs.writeFileSync(addressBook, JSON.stringify(output, null, 2))

return output as Record<string, Record<string, string>>
}

// Ignition requires "n" suffix for bigints, but not here
function removeNFromBigInts(obj: any): any {
if (typeof obj === 'string') {
return obj.replace(/(\d+)n/g, '$1')
} else if (Array.isArray(obj)) {
return obj.map(removeNFromBigInts)
} else if (typeof obj === 'object' && obj !== null) {
for (const key in obj) {
obj[key] = removeNFromBigInts(obj[key])
}
}
return obj
}
3 changes: 3 additions & 0 deletions packages/hardhat-graph-protocol/src/sdk/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { loadConfig, saveAddressBook } from './ignition/ignition'

export const IgnitionHelper = { saveAddressBook, loadConfig }
25 changes: 18 additions & 7 deletions packages/horizon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,29 @@ You can set them using Hardhat:
npx hardhat vars set ETHERSCAN_API_KEY
```

## Deployment

We use Hardhat Ignition to deploy the contracts. To build and deploy Graph Horizon run the following commands:
## Build

```bash
yarn install
yarn build
npx hardhat ignition deploy ./ignition/modules/horizon.ts \
--parameters ./ignition/configs/horizon.hardhat.json5 \
--network hardhat
```

You can use any network defined in `hardhat.config.ts` by replacing `hardhat` with the network name.
## Deploy

### New deployment
To deploy Graph Horizon from scratch run the following command:

```bash
npx hardhat run scripts/deploy.ts --network hardhat
```

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.

### Upgrade deployment
To upgrade an existing deployment of the original Graph Protocol to Graph Horizon, run the following command:

```bash
npx hardhat run scripts/migrate.ts --network hardhat
```

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.
226 changes: 0 additions & 226 deletions packages/horizon/addresses.json

This file was deleted.

Loading
Loading