-
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.
Signed-off-by: Tomás Migone <[email protected]>
- Loading branch information
Showing
15 changed files
with
266 additions
and
1,243 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# hardhat-graph-protocol | ||
|
||
|
||
## Usage | ||
|
||
Install with yarn | ||
|
||
```bash | ||
yarn add --dev hardhat-graph-protocol | ||
|
||
# From the monorepo | ||
yarn add --dev hardhat-graph-protocol@workspace:^x.y.z | ||
``` | ||
|
||
And add it to your `hardhat.config.ts`: | ||
|
||
```ts | ||
import "hardhat-graph-protocol"; | ||
|
||
export default { | ||
... | ||
graph: { | ||
deployments: { | ||
horizon: require.resolve('@graphprotocol/horizon/addresses.json'), | ||
subgraphService: require.resolve('@graphprotocol/subgraph-service/addresses.json'), | ||
} | ||
}, | ||
... | ||
}; | ||
``` | ||
|
||
_Note_: When using the plugin from within this monorepo TypeScript fails to properly apply the type extension typings. This is a known issue and can be worked around by adding a `types/hardhat-graph-protocol.d.ts` file with the same content as the `type-extensions.ts` file in this repository. |
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,13 +1,19 @@ | ||
import type { GraphHorizonAddressBook, GraphHorizonContracts } from './sdk/deployments/horizon' | ||
import type { SubgraphServiceAddressBook, SubgraphServiceContracts } from './sdk/deployments/subgraph-service' | ||
|
||
// List of supported Graph deployments | ||
export const GraphDeploymentsList = [ | ||
'horizon', | ||
'subgraphService', | ||
] as const | ||
|
||
export type GraphDeploymentRuntimeEnvironmentMap = { | ||
horizon: { | ||
contracts: GraphHorizonContracts | ||
addressBook: GraphHorizonAddressBook | ||
} | ||
subgraphService: { | ||
contracts: SubgraphServiceContracts | ||
addressBook: SubgraphServiceAddressBook | ||
} | ||
} |
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
48 changes: 48 additions & 0 deletions
48
packages/hardhat-graph-protocol/src/sdk/deployments/subgraph-service/address-book.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,48 @@ | ||
import { logDebug, logError } from '../../../logger' | ||
import { Provider, Signer } from 'ethers' | ||
import { SubgraphServiceArtifactsMap, SubgraphServiceContractNameList } from './contracts' | ||
import { AddressBook } from '../../address-book' | ||
import { assertObject } from '../../utils/assertion' | ||
|
||
import type { SubgraphServiceContractName, SubgraphServiceContracts } from './contracts' | ||
|
||
export class SubgraphServiceAddressBook extends AddressBook<number, SubgraphServiceContractName> { | ||
isContractName(name: unknown): name is SubgraphServiceContractName { | ||
return ( | ||
typeof name === 'string' | ||
&& SubgraphServiceContractNameList.includes(name as SubgraphServiceContractName) | ||
) | ||
} | ||
|
||
loadContracts( | ||
signerOrProvider?: Signer | Provider, | ||
): SubgraphServiceContracts { | ||
logDebug('Loading Subgraph Service contracts...') | ||
|
||
const contracts = this._loadContracts( | ||
SubgraphServiceArtifactsMap, | ||
signerOrProvider, | ||
) | ||
this._assertSubgraphServiceContracts(contracts) | ||
|
||
// Aliases | ||
contracts.Curation = contracts.L2Curation | ||
contracts.GNS = contracts.L2GNS | ||
|
||
return contracts | ||
} | ||
|
||
_assertSubgraphServiceContracts( | ||
contracts: unknown, | ||
): asserts contracts is SubgraphServiceContracts { | ||
assertObject(contracts) | ||
|
||
// Assert that all SubgraphServiceContracts were loaded | ||
for (const contractName of SubgraphServiceContractNameList) { | ||
if (!contracts[contractName]) { | ||
const errMessage = `Missing SubgraphService contract: ${contractName}` | ||
logError(errMessage) | ||
} | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
packages/hardhat-graph-protocol/src/sdk/deployments/subgraph-service/contracts.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,60 @@ | ||
import path from 'path' | ||
|
||
import type { | ||
L2Curation, | ||
L2GNS, | ||
ServiceRegistry, | ||
SubgraphNFT, | ||
} from '@graphprotocol/contracts' | ||
|
||
import type { | ||
DisputeManager, | ||
SubgraphService, | ||
} from '@graphprotocol/subgraph-service' | ||
import type { ContractList } from '../../lib/contract' | ||
|
||
export const SubgraphServiceContractNameList = [ | ||
// @graphprotocol/contracts | ||
'L2Curation', | ||
'L2GNS', | ||
'SubgraphNFT', | ||
'ServiceRegistry', | ||
|
||
// @graphprotocol/subgraph-service | ||
'SubgraphService', | ||
'DisputeManager', | ||
] as const | ||
|
||
const root = path.resolve(__dirname, '../../../../..') // hardhat-graph-protocol root | ||
export const CONTRACTS_ARTIFACTS_PATH = path.resolve(root, 'node_modules', '@graphprotocol/contracts/build/contracts') | ||
export const SUBGRAPH_SERVICE_ARTIFACTS_PATH = path.resolve(root, 'node_modules', '@graphprotocol/subgraph-service/build/contracts') | ||
|
||
export const SubgraphServiceArtifactsMap = { | ||
// @graphprotocol/contracts | ||
L2Curation: CONTRACTS_ARTIFACTS_PATH, | ||
L2GNS: CONTRACTS_ARTIFACTS_PATH, | ||
SubgraphNFT: CONTRACTS_ARTIFACTS_PATH, | ||
ServiceRegistry: CONTRACTS_ARTIFACTS_PATH, | ||
|
||
// @graphprotocol/subgraph-service | ||
SubgraphService: SUBGRAPH_SERVICE_ARTIFACTS_PATH, | ||
DisputeManager: SUBGRAPH_SERVICE_ARTIFACTS_PATH, | ||
} as const | ||
|
||
export interface SubgraphServiceContracts extends ContractList<SubgraphServiceContractName> { | ||
// @graphprotocol/contracts | ||
L2Curation: L2Curation | ||
L2GNS: L2GNS | ||
SubgraphNFT: SubgraphNFT | ||
ServiceRegistry: ServiceRegistry | ||
|
||
// @graphprotocol/subgraph-service | ||
SubgraphService: SubgraphService | ||
DisputeManager: DisputeManager | ||
|
||
// Aliases | ||
Curation: L2Curation | ||
GNS: L2GNS | ||
} | ||
|
||
export type SubgraphServiceContractName = (typeof SubgraphServiceContractNameList)[number] |
6 changes: 6 additions & 0 deletions
6
packages/hardhat-graph-protocol/src/sdk/deployments/subgraph-service/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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { SubgraphServiceAddressBook } from './address-book' | ||
|
||
import type { SubgraphServiceContractName, SubgraphServiceContracts } from './contracts' | ||
|
||
export { SubgraphServiceAddressBook } | ||
export type { SubgraphServiceContractName, SubgraphServiceContracts } |
Oops, something went wrong.