-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add more improvements to ignition deployment system
Signed-off-by: Tomás Migone <[email protected]>
- Loading branch information
Showing
112 changed files
with
247 additions
and
36,663 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
|
@@ -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", | ||
|
71 changes: 71 additions & 0 deletions
71
packages/hardhat-graph-protocol/src/sdk/ignition/ignition.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.