-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Tomás Migone <[email protected]>
- Loading branch information
Showing
13 changed files
with
137 additions
and
101 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
11 changes: 1 addition & 10 deletions
11
...hardhat-graph-protocol/src/deployments.ts → ...hat-graph-protocol/src/deployment-list.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,22 +1,13 @@ | ||
import type { GraphHorizonAddressBook, GraphHorizonContracts } from './sdk/deployments/horizon' | ||
|
||
// List of supported Graph deployments | ||
const GraphDeploymentsList = [ | ||
export 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
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,102 +1,44 @@ | ||
// To extend one of Hardhat's types, you need to import the module where it has been defined, and redeclare it. | ||
import 'hardhat/types/config' | ||
import 'hardhat/types/runtime' | ||
|
||
import type { GraphDeployment, GraphDeploymentRuntimeEnvironmentMap } from './deployments' | ||
import type { HardhatEthersProvider } from '@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider' | ||
|
||
export type GraphRuntimeEnvironmentOptions = { | ||
deployments?: { | ||
[deployment in GraphDeployment]?: string | { | ||
addressBook: string | ||
} | ||
} | ||
} | ||
|
||
export type GraphRuntimeEnvironment = { | ||
[deployment in keyof GraphDeploymentRuntimeEnvironmentMap]?: GraphDeploymentRuntimeEnvironmentMap[deployment] | ||
} & { | ||
provider: HardhatEthersProvider | ||
chainId: number | ||
} | ||
|
||
export function assertGraphRuntimeEnvironment( | ||
obj: unknown, | ||
): obj is GraphRuntimeEnvironment { | ||
if (typeof obj !== 'object' || obj === null) return false | ||
|
||
const deployments = obj as Partial<GraphDeploymentRuntimeEnvironmentMap> | ||
|
||
for (const deployment in deployments) { | ||
const environment = deployments[deployment as keyof GraphDeploymentRuntimeEnvironmentMap] | ||
if (!environment || typeof environment !== 'object') { | ||
return false | ||
} | ||
} | ||
|
||
if (typeof (obj as GraphRuntimeEnvironment).provider !== 'object') { | ||
return false | ||
} | ||
|
||
if (typeof (obj as GraphRuntimeEnvironment).chainId !== 'function') { | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
import type { GraphDeployments, GraphRuntimeEnvironment, GraphRuntimeEnvironmentOptions } from './types' | ||
|
||
declare module 'hardhat/types/runtime' { | ||
export interface HardhatRuntimeEnvironment { | ||
interface HardhatRuntimeEnvironment { | ||
graph: (opts?: GraphRuntimeEnvironmentOptions) => GraphRuntimeEnvironment | ||
} | ||
} | ||
|
||
declare module 'hardhat/types/config' { | ||
export interface HardhatConfig { | ||
interface HardhatConfig { | ||
graph: GraphRuntimeEnvironmentOptions | ||
} | ||
|
||
export interface HardhatUserConfig { | ||
interface HardhatUserConfig { | ||
graph: GraphRuntimeEnvironmentOptions | ||
} | ||
|
||
export interface HardhatNetworkConfig { | ||
deployments?: { | ||
[deployment in GraphDeployment]?: string | { | ||
addressBook: string | ||
} | ||
} | ||
interface HardhatNetworkConfig { | ||
deployments?: GraphDeployments | ||
} | ||
|
||
export interface HardhatNetworkUserConfig { | ||
deployments?: { | ||
[deployment in GraphDeployment]?: string | { | ||
addressBook: string | ||
} | ||
} | ||
interface HardhatNetworkUserConfig { | ||
deployments?: GraphDeployments | ||
} | ||
|
||
export interface HttpNetworkConfig { | ||
deployments?: { | ||
[deployment in GraphDeployment]?: string | { | ||
addressBook: string | ||
} | ||
} | ||
interface HttpNetworkConfig { | ||
deployments?: GraphDeployments | ||
} | ||
|
||
export interface HttpNetworkUserConfig { | ||
deployments?: { | ||
[deployment in GraphDeployment]?: string | { | ||
addressBook: string | ||
} | ||
} | ||
interface HttpNetworkUserConfig { | ||
deployments?: GraphDeployments | ||
} | ||
|
||
export interface ProjectPathsConfig { | ||
interface ProjectPathsConfig { | ||
graph?: string | ||
} | ||
|
||
export interface ProjectPathsUserConfig { | ||
interface ProjectPathsUserConfig { | ||
graph?: string | ||
} | ||
} |
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,57 @@ | ||
import { type GraphDeploymentRuntimeEnvironmentMap, GraphDeploymentsList } from './deployment-list' | ||
import type { HardhatEthersProvider } from '@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider' | ||
|
||
export type GraphDeployment = (typeof GraphDeploymentsList)[number] | ||
|
||
export type GraphDeployments = { | ||
[deployment in GraphDeployment]?: string | { | ||
addressBook: string | ||
} | ||
} | ||
|
||
export type GraphRuntimeEnvironmentOptions = { | ||
deployments?: { | ||
[deployment in GraphDeployment]?: string | { | ||
addressBook: string | ||
} | ||
} | ||
} | ||
|
||
export type GraphRuntimeEnvironment = { | ||
[deployment in keyof GraphDeploymentRuntimeEnvironmentMap]?: GraphDeploymentRuntimeEnvironmentMap[deployment] | ||
} & { | ||
provider: HardhatEthersProvider | ||
chainId: number | ||
} | ||
|
||
export function isGraphDeployment(deployment: unknown): deployment is GraphDeployment { | ||
return ( | ||
typeof deployment === 'string' | ||
&& GraphDeploymentsList.includes(deployment as GraphDeployment) | ||
) | ||
} | ||
|
||
export function assertGraphRuntimeEnvironment( | ||
obj: unknown, | ||
): obj is GraphRuntimeEnvironment { | ||
if (typeof obj !== 'object' || obj === null) return false | ||
|
||
const deployments = obj as Partial<GraphDeploymentRuntimeEnvironmentMap> | ||
|
||
for (const deployment in deployments) { | ||
const environment = deployments[deployment as keyof GraphDeploymentRuntimeEnvironmentMap] | ||
if (!environment || typeof environment !== 'object') { | ||
return false | ||
} | ||
} | ||
|
||
if (typeof (obj as GraphRuntimeEnvironment).provider !== 'object') { | ||
return false | ||
} | ||
|
||
if (typeof (obj as GraphRuntimeEnvironment).chainId !== 'function') { | ||
return false | ||
} | ||
|
||
return true | ||
} |
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
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
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,45 @@ | ||
// TypeScript does not resolve correctly the type extensions when they are symlinked from the same monorepo. | ||
// So we need to re-type it... this file should be a copy of hardhat-graph-protocol/src/type-extensions.ts | ||
import 'hardhat/types/config' | ||
import 'hardhat/types/runtime' | ||
import type { GraphDeployments, GraphRuntimeEnvironment, GraphRuntimeEnvironmentOptions } from 'hardhat-graph-protocol/src/types' | ||
|
||
declare module 'hardhat/types/runtime' { | ||
interface HardhatRuntimeEnvironment { | ||
graph: (opts?: GraphRuntimeEnvironmentOptions) => GraphRuntimeEnvironment | ||
} | ||
} | ||
|
||
declare module 'hardhat/types/config' { | ||
interface HardhatConfig { | ||
graph: GraphRuntimeEnvironmentOptions | ||
} | ||
|
||
interface HardhatUserConfig { | ||
graph: GraphRuntimeEnvironmentOptions | ||
} | ||
|
||
interface HardhatNetworkConfig { | ||
deployments?: GraphDeployments | ||
} | ||
|
||
interface HardhatNetworkUserConfig { | ||
deployments?: GraphDeployments | ||
} | ||
|
||
interface HttpNetworkConfig { | ||
deployments?: GraphDeployments | ||
} | ||
|
||
interface HttpNetworkUserConfig { | ||
deployments?: GraphDeployments | ||
} | ||
|
||
interface ProjectPathsConfig { | ||
graph?: string | ||
} | ||
|
||
interface ProjectPathsUserConfig { | ||
graph?: string | ||
} | ||
} |
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