-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gre): working version for horizon with legacy contracts
Signed-off-by: Tomás Migone <[email protected]>
- Loading branch information
Showing
20 changed files
with
258 additions
and
209 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,49 @@ | ||
import fs from 'fs' | ||
|
||
import { GraphPluginError } from './sdk/utils/error' | ||
import { logDebug } from './logger' | ||
import { normalizePath } from './sdk/utils/path' | ||
|
||
import type { GraphDeployment, GraphRuntimeEnvironmentOptions } from './types' | ||
import type { GraphDeployment } from './deployments' | ||
import type { GraphRuntimeEnvironmentOptions } from './type-extensions' | ||
import type { HardhatRuntimeEnvironment } from 'hardhat/types' | ||
import { normalizePath } from './sdk/utils/path' | ||
|
||
export function getAddressBookPath( | ||
deployment: GraphDeployment, | ||
hre: HardhatRuntimeEnvironment, | ||
opts: GraphRuntimeEnvironmentOptions, | ||
): string { | ||
const optsPath = getPath(opts.deployments?.[deployment]) | ||
const networkPath = getPath(hre.network.config.deployments?.[deployment]) | ||
const globalPath = getPath(hre.config.graph?.deployments?.[deployment]) | ||
|
||
logDebug(`== ${deployment} - Getting address book path`) | ||
logDebug(`Graph base dir: ${hre.config.paths.graph}`) | ||
logDebug(`1) opts.addressBooks.[deployment]: ${opts.addressBooks?.[deployment]}`) | ||
logDebug(`2) hre.network.config.addressBooks.[deployment]: ${hre.network.config?.addressBooks?.[deployment]}`) | ||
logDebug(`3) hre.config.graph.addressBooks.[deployment]: ${hre.config.graph?.addressBooks?.[deployment]}`) | ||
|
||
let addressBookPath | ||
= opts.addressBooks?.[deployment] ?? hre.network.config?.addressBooks?.[deployment] ?? hre.config.graph?.addressBooks?.[deployment] | ||
logDebug(`1) opts: ${optsPath}`) | ||
logDebug(`2) network: ${networkPath}`) | ||
logDebug(`3) global: ${globalPath}`) | ||
|
||
const addressBookPath = optsPath ?? networkPath ?? globalPath | ||
if (addressBookPath === undefined) { | ||
throw new GraphPluginError('Must set a an addressBook path!') | ||
} | ||
|
||
addressBookPath = normalizePath(addressBookPath, hre.config.paths.graph) | ||
|
||
if (!fs.existsSync(addressBookPath)) { | ||
throw new GraphPluginError(`Address book not found: ${addressBookPath}`) | ||
const normalizedAddressBookPath = normalizePath(addressBookPath, hre.config.paths.graph) | ||
if (!fs.existsSync(normalizedAddressBookPath)) { | ||
throw new GraphPluginError(`Address book not found: ${normalizedAddressBookPath}`) | ||
} | ||
|
||
logDebug(`Address book path found: ${addressBookPath}`) | ||
return addressBookPath | ||
logDebug(`Address book path found: ${normalizedAddressBookPath}`) | ||
return normalizedAddressBookPath | ||
} | ||
|
||
function getPath(value: string | { | ||
addressBook: string | ||
} | undefined): string | undefined { | ||
if (typeof value === 'string') { | ||
return value | ||
} else if (value && typeof value == 'object') { | ||
return value.addressBook | ||
} | ||
return | ||
} |
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,22 @@ | ||
import type { GraphHorizonAddressBook, GraphHorizonContracts } from './sdk/deployments/horizon' | ||
|
||
// List of supported Graph deployments | ||
const GraphDeploymentsList = [ | ||
'horizon', | ||
] as const | ||
|
||
export type GraphDeployment = (typeof GraphDeploymentsList)[number] | ||
|
||
export type GraphDeploymentRuntimeEnvironmentMap = { | ||
horizon: { | ||
contracts: GraphHorizonContracts | ||
addressBook: GraphHorizonAddressBook | ||
} | ||
} | ||
|
||
export function isGraphDeployment(deployment: unknown): deployment is GraphDeployment { | ||
return ( | ||
typeof deployment === 'string' | ||
&& GraphDeploymentsList.includes(deployment as GraphDeployment) | ||
) | ||
} |
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
4 changes: 2 additions & 2 deletions
4
packages/hardhat-graph-protocol/src/sdk/deployments/horizon/index.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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { GraphHorizonAddressBook } from './address-book' | ||
|
||
import type { GraphHorizonContractName, GraphHorizonContracts, GraphHorizonRuntimeEnvironment } from './types' | ||
import type { GraphHorizonContractName, GraphHorizonContracts } from './types' | ||
|
||
export { | ||
GraphHorizonAddressBook, | ||
} | ||
|
||
export type { GraphHorizonContractName, GraphHorizonContracts, GraphHorizonRuntimeEnvironment } | ||
export type { GraphHorizonContractName, GraphHorizonContracts } |
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
Oops, something went wrong.