Skip to content

Commit 0f7080d

Browse files
committed
feat: create address book if doesnt exist when running deploy task
Signed-off-by: Tomás Migone <[email protected]>
1 parent 71b90c4 commit 0f7080d

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ export function getAddressBookPath(
3131
logDebug(`Address book path: ${normalizedAddressBookPath}`)
3232

3333
if (!fs.existsSync(normalizedAddressBookPath)) {
34-
throw new GraphPluginError(`Address book not found: ${normalizedAddressBookPath}`)
34+
if (opts.createAddressBook) {
35+
logDebug(`Creating address book: ${normalizedAddressBookPath}`)
36+
fs.writeFileSync(normalizedAddressBookPath, '{}')
37+
} else {
38+
throw new GraphPluginError(`Address book not found: ${normalizedAddressBookPath}`)
39+
}
3540
}
3641

3742
return normalizedAddressBookPath

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,17 @@ export const greExtendConfig = (config: HardhatConfig, userConfig: Readonly<Hard
3030
}
3131

3232
export const greExtendEnvironment = (hre: HardhatRuntimeEnvironment) => {
33-
hre.graph = lazyFunction(() => (opts: GraphRuntimeEnvironmentOptions = { deployments: {} }) => {
33+
hre.graph = lazyFunction(() => (opts?: GraphRuntimeEnvironmentOptions) => {
3434
logDebug('*** Initializing Graph Runtime Environment (GRE) ***')
3535
logDebug(`Main network: ${hre.network.name}`)
36+
37+
if (opts === undefined) {
38+
opts = {
39+
deployments: {},
40+
createAddressBook: false,
41+
}
42+
}
43+
3644
const chainId = hre.network.config.chainId
3745
if (chainId === undefined) {
3846
throw new GraphPluginError('Please define chainId in your Hardhat network configuration')

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export type GraphDeploymentOptions = {
99

1010
export type GraphRuntimeEnvironmentOptions = {
1111
deployments?: GraphDeploymentOptions
12+
createAddressBook?: boolean
1213
}
1314

1415
export type GraphRuntimeEnvironment = GraphDeployments & {

packages/horizon/tasks/deploy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ task('deploy:protocol', 'Deploy a new version of the Graph Protocol Horizon cont
1717
)
1818
.addOptionalParam('accountIndex', 'Derivation path index for the account to use', 0, types.int)
1919
.setAction(async (args, hre: HardhatRuntimeEnvironment) => {
20-
const graph = hre.graph()
20+
const graph = hre.graph({ createAddressBook: true })
2121

2222
// Load configuration for the deployment
2323
console.log('\n========== ⚙️ Deployment configuration ==========')

packages/subgraph-service/tasks/deploy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ task('deploy:protocol', 'Deploy a new version of the Graph Protocol Horizon cont
3030
types.string,
3131
)
3232
.setAction(async (args, hre: HardhatRuntimeEnvironment) => {
33-
const graph = hre.graph()
33+
const graph = hre.graph({ createAddressBook: true })
3434

3535
// Load configuration files for the deployment
3636
console.log('\n========== ⚙️ Deployment configuration ==========')

0 commit comments

Comments
 (0)