├── packages ├── cli │ ├── tests │ │ ├── cli │ │ │ ├── init │ │ │ │ ├── near │ │ │ │ │ └── .gitkeep │ │ │ │ ├── subgraph │ │ │ │ │ └── .gitkeep │ │ │ │ ├── substreams │ │ │ │ │ └── substreams.spkg │ │ │ │ └── ethereum │ │ │ │ │ └── abis │ │ │ │ │ └── Airdropped.json │ │ │ ├── validation │ │ │ │ ├── abi-not-found │ │ │ │ │ ├── mapping.ts │ │ │ │ │ ├── schema.graphql │ │ │ │ │ ├── Abi.json │ │ │ │ │ └── subgraph.yaml │ │ │ │ ├── indexer-hints │ │ │ │ │ ├── mapping.ts │ │ │ │ │ ├── schema.graphql │ │ │ │ │ ├── Abi.json │ │ │ │ │ └── subgraph.yaml │ │ │ │ ├── invalid-abis │ │ │ │ │ ├── mapping.ts │ │ │ │ │ ├── InvalidAbi.json │ │ │ │ │ ├── schema.graphql │ │ │ │ │ └── subgraph.yaml │ │ │ │ ├── near-is-valid │ │ │ │ │ ├── mapping.ts │ │ │ │ │ ├── schema.graphql │ │ │ │ │ └── subgraph.yaml │ │ │ │ ├── 2d-array-is-valid │ │ │ │ │ ├── mapping.ts │ │ │ │ │ ├── schema.graphql │ │ │ │ │ ├── Abi.json │ │ │ │ │ └── subgraph.yaml │ │ │ │ ├── 3d-array-is-valid │ │ │ │ │ ├── mapping.ts │ │ │ │ │ ├── Abi.json │ │ │ │ │ ├── schema.graphql │ │ │ │ │ └── subgraph.yaml │ │ │ │ ├── entity-field-args │ │ │ │ │ ├── mapping.ts │ │ │ │ │ ├── schema.graphql │ │ │ │ │ ├── Abi.json │ │ │ │ │ └── subgraph.yaml │ │ │ │ ├── event-not-found │ │ │ │ │ ├── mapping.ts │ │ │ │ │ ├── schema.graphql │ │ │ │ │ ├── Abi.json │ │ │ │ │ └── subgraph.yaml │ │ │ │ ├── missing-entity-id │ │ │ │ │ ├── mapping.ts │ │ │ │ │ ├── schema.graphql │ │ │ │ │ ├── Abi.json │ │ │ │ │ ├── types │ │ │ │ │ │ ├── schema.ts │ │ │ │ │ │ └── ExampleSubgraph │ │ │ │ │ │ │ └── ExampleContract.ts │ │ │ │ │ └── subgraph.yaml │ │ │ │ ├── no-network-names │ │ │ │ │ ├── mapping.ts │ │ │ │ │ ├── schema.graphql │ │ │ │ │ ├── Abi.json │ │ │ │ │ └── subgraph.yaml │ │ │ │ ├── topic0-is-valid │ │ │ │ │ ├── mapping.ts │ │ │ │ │ ├── schema.graphql │ │ │ │ │ ├── Abi.json │ │ │ │ │ └── subgraph.yaml │ │ │ │ ├── big-decimal-is-valid │ │ │ │ │ ├── mapping.ts │ │ │ │ │ ├── schema.graphql │ │ │ │ │ ├── Abi.json │ │ │ │ │ └── subgraph.yaml │ │ │ │ ├── block-handler-filters │ │ │ │ │ ├── Abi.json │ │ │ │ │ ├── mapping.ts │ │ │ │ │ ├── schema.graphql │ │ │ │ │ └── subgraph.yaml │ │ │ │ ├── call-function-not-found │ │ │ │ │ ├── mapping.ts │ │ │ │ │ ├── schema.graphql │ │ │ │ │ └── subgraph.yaml │ │ │ │ ├── call-handler-with-tuple │ │ │ │ │ ├── mapping.ts │ │ │ │ │ ├── schema.graphql │ │ │ │ │ ├── Abi.json │ │ │ │ │ └── subgraph.yaml │ │ │ │ ├── duplicate-template-name │ │ │ │ │ ├── mapping.ts │ │ │ │ │ ├── schema.graphql │ │ │ │ │ └── Abi.json │ │ │ │ ├── example-values-found │ │ │ │ │ ├── mapping.ts │ │ │ │ │ ├── schema.graphql │ │ │ │ │ ├── Abi.json │ │ │ │ │ ├── subgraph.yaml │ │ │ │ │ └── generated │ │ │ │ │ │ └── ExampleSubgraph │ │ │ │ │ │ └── ExampleContract.ts │ │ │ │ ├── invalid-graphql-schema │ │ │ │ │ ├── mapping.ts │ │ │ │ │ ├── Abi.json │ │ │ │ │ ├── schema.graphql │ │ │ │ │ └── subgraph.yaml │ │ │ │ ├── conflicting-network-names │ │ │ │ │ ├── mapping.ts │ │ │ │ │ ├── schema.graphql │ │ │ │ │ ├── Abi.json │ │ │ │ │ └── subgraph.yaml │ │ │ │ ├── conflicting-protocol-names │ │ │ │ │ ├── mapping.ts │ │ │ │ │ ├── schema.graphql │ │ │ │ │ ├── Abi.json │ │ │ │ │ └── subgraph.yaml │ │ │ │ ├── duplicate-data-source-name │ │ │ │ │ ├── mapping.ts │ │ │ │ │ ├── schema.graphql │ │ │ │ │ ├── Abi.json │ │ │ │ │ └── subgraph.yaml │ │ │ │ ├── invalid-contract-addresses │ │ │ │ │ ├── mapping.ts │ │ │ │ │ ├── schema.graphql │ │ │ │ │ └── Abi.json │ │ │ │ ├── invalid-data-source-template │ │ │ │ │ ├── mapping.ts │ │ │ │ │ ├── schema.graphql │ │ │ │ │ └── subgraph.yaml │ │ │ │ ├── invalid-entity-field-types │ │ │ │ │ ├── mapping.ts │ │ │ │ │ ├── Abi.json │ │ │ │ │ └── subgraph.yaml │ │ │ │ ├── invalid-fulltext-directive │ │ │ │ │ ├── mapping.ts │ │ │ │ │ ├── Abi.json │ │ │ │ │ └── subgraph.yaml │ │ │ │ ├── nested-template-nice-error │ │ │ │ │ ├── mapping.ts │ │ │ │ │ ├── schema.graphql │ │ │ │ │ ├── Abi.json │ │ │ │ │ └── subgraph.yaml │ │ │ │ ├── require-immutable-argument │ │ │ │ │ ├── mapping.ts │ │ │ │ │ ├── Abi.json │ │ │ │ │ ├── schema.graphql │ │ │ │ │ └── subgraph.yaml │ │ │ │ ├── derived-from-target-type-missing │ │ │ │ │ ├── mapping.ts │ │ │ │ │ ├── Abi.json │ │ │ │ │ ├── schema.graphql │ │ │ │ │ └── subgraph.yaml │ │ │ │ ├── source-without-address-is-valid │ │ │ │ │ ├── mapping.ts │ │ │ │ │ ├── schema.graphql │ │ │ │ │ ├── Abi.json │ │ │ │ │ ├── subgraph.yaml │ │ │ │ │ └── generated │ │ │ │ │ │ └── ExampleSubgraph │ │ │ │ │ │ └── ExampleContract.ts │ │ │ │ ├── ethereum-contract-without-handlers │ │ │ │ │ ├── mapping.ts │ │ │ │ │ ├── schema.graphql │ │ │ │ │ ├── Abi.json │ │ │ │ │ └── subgraph.yaml │ │ │ │ ├── missing-or-invalid-derived-from-fields.stdout │ │ │ │ ├── missing-or-invalid-derived-from-fields │ │ │ │ │ ├── mapping.ts │ │ │ │ │ ├── Abi.json │ │ │ │ │ ├── subgraph.yaml │ │ │ │ │ └── schema.graphql │ │ │ │ ├── missing-entity-id.stderr │ │ │ │ ├── derived-from-target-type-missing.stderr │ │ │ │ ├── entity-field-args.stderr │ │ │ │ ├── invalid-abis.stderr │ │ │ │ ├── duplicate-template-name.stderr │ │ │ │ ├── invalid-manifest-cannot-infer-protocol │ │ │ │ │ └── subgraph.yaml │ │ │ │ ├── duplicate-data-source-name.stderr │ │ │ │ ├── invalid-manifest │ │ │ │ │ └── subgraph.yaml │ │ │ │ ├── require-immutable-argument.stderr │ │ │ │ ├── ethereum-contract-without-handlers.stderr │ │ │ │ ├── invalid-manifest-cannot-infer-protocol.stderr │ │ │ │ ├── nested-template-nice-error.stderr │ │ │ │ ├── call-function-not-found.stderr │ │ │ │ ├── conflicting-network-names.stderr │ │ │ │ ├── conflicting-protocol-names.stderr │ │ │ │ ├── abi-not-found copy.stderr │ │ │ │ ├── event-not-found.stderr │ │ │ │ ├── derived-from-with-interface │ │ │ │ │ ├── schema.graphql │ │ │ │ │ ├── subgraph.yaml │ │ │ │ │ └── mapping.ts │ │ │ │ ├── missing-or-invalid-derived-from-fields.stderr │ │ │ │ ├── invalid-manifest.stderr │ │ │ │ ├── invalid-contract-addresses.stderr │ │ │ │ ├── invalid-data-source-template.stderr │ │ │ │ ├── call-handler-with-tuple.stderr │ │ │ │ ├── source-without-address-is-valid.stderr │ │ │ │ └── invalid-graphql-schema.stderr │ │ │ ├── add │ │ │ │ └── subgraph │ │ │ │ │ ├── networks.json │ │ │ │ │ ├── schema.graphql │ │ │ │ │ ├── src │ │ │ │ │ └── mapping.ts │ │ │ │ │ └── subgraph.yaml │ │ │ ├── globalSetup.ts │ │ │ ├── globalTeardown.ts │ │ │ └── spawn-command.d.ts │ │ └── .latest.json │ ├── bin │ │ ├── run.cmd │ │ └── run.js │ ├── src │ │ ├── index.ts │ │ ├── command-helpers │ │ │ ├── ipfs.ts │ │ │ ├── fs.ts │ │ │ ├── subgraph.ts │ │ │ ├── retry.ts │ │ │ ├── node.ts │ │ │ └── jsonrpc.ts │ │ ├── constants.ts │ │ ├── validation │ │ │ └── index.ts │ │ ├── protocols │ │ │ ├── contract.ts │ │ │ ├── cosmos │ │ │ │ ├── scaffold │ │ │ │ │ └── manifest.ts │ │ │ │ └── subgraph.ts │ │ │ ├── subgraph.ts │ │ │ ├── substreams │ │ │ │ ├── scaffold │ │ │ │ │ └── manifest.ts │ │ │ │ └── subgraph.ts │ │ │ ├── arweave │ │ │ │ ├── scaffold │ │ │ │ │ └── manifest.ts │ │ │ │ └── subgraph.ts │ │ │ ├── near │ │ │ │ ├── scaffold │ │ │ │ │ └── manifest.ts │ │ │ │ └── subgraph.ts │ │ │ ├── subgraph │ │ │ │ ├── scaffold │ │ │ │ │ ├── mapping.ts │ │ │ │ │ └── manifest.ts │ │ │ │ └── subgraph.ts │ │ │ ├── ethereum │ │ │ │ ├── contract.ts │ │ │ │ └── codegen │ │ │ │ │ └── template.ts │ │ │ └── file_template.ts │ │ ├── migrations │ │ │ ├── util │ │ │ │ ├── load-manifest.ts │ │ │ │ └── versions.ts │ │ │ ├── spec_version_0_0_2.ts │ │ │ └── spec_version_0_0_3.ts │ │ ├── fetch.ts │ │ ├── version.ts │ │ ├── debug.ts │ │ ├── scaffold │ │ │ ├── get-git-ignore.ts │ │ │ ├── cosmos.test.ts │ │ │ └── near.test.ts │ │ └── commands │ │ │ └── clean.ts │ ├── tsconfig.build.json │ ├── tsconfig.dev.json │ ├── vitest.config.ts │ └── tsconfig.json └── ts │ ├── .gitignore │ ├── types │ └── tsconfig.base.json │ ├── tsconfig.json │ ├── common │ ├── conversion.ts │ └── json.ts │ ├── test │ ├── entity.ts │ └── bytes.ts │ ├── package.json │ └── chain │ └── starknet.ts ├── website ├── src │ ├── vite-env.d.ts │ ├── lib │ │ ├── constants.ts │ │ ├── graphql.ts │ │ ├── utils.ts │ │ └── ipfs.ts │ ├── routes │ │ ├── __root.tsx │ │ ├── publish.tsx │ │ └── index.lazy.tsx │ ├── components │ │ ├── editor.tsx │ │ ├── ui │ │ │ ├── label.tsx │ │ │ ├── textarea.tsx │ │ │ ├── toaster.tsx │ │ │ └── input.tsx │ │ └── wallet-provider.tsx │ └── main.tsx ├── .env.example ├── postcss.config.js ├── public │ └── the-graph-logomark-light.png ├── tsconfig.node.json ├── .gitignore ├── components.json ├── vite.config.ts ├── .eslintrc.cjs ├── index.html └── tsconfig.json ├── examples ├── near-blocks │ ├── .gitattributes │ ├── tsconfig.json │ ├── schema.graphql │ ├── README.md │ ├── src │ │ └── mapping.ts │ ├── subgraph.yaml │ ├── package.json │ ├── docker-compose.yml │ └── .gitignore ├── ethereum-gravatar │ ├── .gitattributes │ ├── schema.graphql │ ├── README.md │ ├── artifacts │ │ └── contracts │ │ │ ├── Migrations.sol │ │ │ └── Migrations.dbg.json │ │ │ └── Gravity.sol │ │ │ └── GravatarRegistry.dbg.json │ ├── hardhat.config.ts │ ├── migrations │ │ ├── 1_initial_migration.js │ │ ├── 2_deploy_contract.js │ │ └── 3_create_gravatars.js │ ├── contracts │ │ └── Migrations.sol │ ├── src │ │ └── mapping.ts │ ├── subgraph.yaml │ ├── package.json │ └── docker-compose.yml ├── near-receipts │ ├── .gitattributes │ ├── schema.graphql │ ├── README.md │ ├── subgraph.yaml │ ├── package.json │ ├── docker-compose.yml │ └── .gitignore ├── substreams-powered-subgraph │ ├── .gitignore │ ├── rust-toolchain.toml │ ├── schema.graphql │ ├── proto │ │ └── example.proto │ ├── Cargo.toml │ ├── subgraph.yaml │ ├── README.md │ ├── substreams.yaml │ └── package.json ├── cosmos-block-filtering │ ├── config │ │ ├── osmosis.json │ │ └── cosmoshub.json │ ├── schema.graphql │ ├── tsconfig.json │ ├── src │ │ └── mapping.ts │ ├── subgraph.yaml │ ├── subgraph.template.yaml │ ├── docker-compose.yml │ ├── .gitignore │ └── README.md ├── cosmos-validator-delegations │ ├── config │ │ ├── osmosis.json │ │ └── cosmoshub.json │ ├── tsconfig.json │ ├── schema.graphql │ ├── subgraph.yaml │ ├── subgraph.template.yaml │ ├── docker-compose.yml │ ├── .gitignore │ └── src │ │ └── mapping.ts ├── cosmos-validator-rewards │ ├── config │ │ ├── osmosis.json │ │ └── cosmoshub.json │ ├── tsconfig.json │ ├── schema.graphql │ ├── src │ │ └── mapping.ts │ ├── subgraph.yaml │ ├── subgraph.template.yaml │ ├── docker-compose.yml │ └── .gitignore ├── ethereum-basic-event-handlers │ ├── hardhat │ │ ├── hardhat.config.js │ │ ├── package.json │ │ ├── entrypoint.sh │ │ └── Dockerfile │ ├── README.md │ ├── .gitignore │ ├── tsconfig.json │ ├── schema.graphql │ ├── build │ │ ├── schema.graphql │ │ └── subgraph.yaml │ ├── hardhat.config.ts │ ├── scripts │ │ └── deploy.ts │ ├── src │ │ └── mapping.ts │ ├── template-subgraph.yaml │ └── subgraph.yaml ├── cosmos-osmosis-token-swaps │ ├── tsconfig.json │ ├── schema.graphql │ ├── subgraph.yaml │ ├── package.json │ ├── docker-compose.yml │ ├── README.md │ └── .gitignore ├── matic-lens-protocol-posts-subgraph │ ├── tsconfig.json │ ├── networks.json │ ├── schema.graphql │ └── package.json ├── example-subgraph │ ├── dist │ │ ├── ExampleSubgraph │ │ │ └── ExampleSubgraph.wasm │ │ ├── subgraph.yaml │ │ └── schema.graphql │ ├── package.json │ ├── subgraph.yaml │ └── schema.graphql ├── aggregations │ ├── README.md │ ├── package.json │ └── subgraph.yaml └── arweave-blocks-transactions │ ├── README.md │ ├── package.json │ ├── schema.graphql │ └── .gitignore ├── pnpm-workspace.yaml ├── .vscode ├── extensions.json ├── tasks.json ├── settings.json └── launch.json ├── .changeset ├── metal-lights-train.md ├── @graphprotocol_graph-cli-2068-dependencies.md ├── README.md └── config.json ├── .prettierignore ├── .gitmodules ├── .prettierrc.js ├── .github └── ISSUE_TEMPLATE │ └── config.yml ├── resources └── test │ └── docker-compose-standalone-node.yml ├── renovate.json └── LICENSE-MIT /packages/cli/tests/cli/init/near/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/init/subgraph/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/ts/.gitignore: -------------------------------------------------------------------------------- 1 | # build files 2 | *.wasm 3 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/abi-not-found/mapping.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/indexer-hints/mapping.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/invalid-abis/mapping.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/near-is-valid/mapping.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/2d-array-is-valid/mapping.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/3d-array-is-valid/mapping.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/entity-field-args/mapping.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/event-not-found/mapping.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/missing-entity-id/mapping.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/no-network-names/mapping.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/topic0-is-valid/mapping.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/cli/bin/run.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | node "%~dp0\run" %* 4 | -------------------------------------------------------------------------------- /packages/cli/src/index.ts: -------------------------------------------------------------------------------- 1 | export { run } from '@oclif/core'; 2 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/big-decimal-is-valid/mapping.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/block-handler-filters/Abi.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/block-handler-filters/mapping.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/call-function-not-found/mapping.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/call-handler-with-tuple/mapping.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/duplicate-template-name/mapping.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/example-values-found/mapping.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/invalid-graphql-schema/mapping.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /website/src/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /examples/near-blocks/.gitattributes: -------------------------------------------------------------------------------- 1 | *.sol linguist-language=Solidity 2 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/conflicting-network-names/mapping.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/conflicting-protocol-names/mapping.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/duplicate-data-source-name/mapping.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/invalid-contract-addresses/mapping.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/invalid-data-source-template/mapping.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/invalid-entity-field-types/mapping.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/invalid-fulltext-directive/mapping.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/nested-template-nice-error/mapping.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/require-immutable-argument/mapping.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/ethereum-gravatar/.gitattributes: -------------------------------------------------------------------------------- 1 | *.sol linguist-language=Solidity 2 | -------------------------------------------------------------------------------- /examples/near-receipts/.gitattributes: -------------------------------------------------------------------------------- 1 | *.sol linguist-language=Solidity 2 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/derived-from-target-type-missing/mapping.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/invalid-abis/InvalidAbi.json: -------------------------------------------------------------------------------- 1 | "Hello" 2 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/source-without-address-is-valid/mapping.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/ethereum-contract-without-handlers/mapping.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/missing-or-invalid-derived-from-fields.stdout: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/missing-or-invalid-derived-from-fields/mapping.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /website/.env.example: -------------------------------------------------------------------------------- 1 | VITE_WALLETCONNECT_PROJECT_ID= 2 | -------------------------------------------------------------------------------- /pnpm-workspace.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | - packages/* 3 | - examples/* 4 | - website 5 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/init/substreams/substreams.spkg: -------------------------------------------------------------------------------- 1 | test file, nothing to see here 2 | -------------------------------------------------------------------------------- /packages/ts/types/tsconfig.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "assemblyscript/std/assembly" 3 | } 4 | -------------------------------------------------------------------------------- /packages/cli/tests/.latest.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.6.0", 3 | "timestamp": 1732733567707 4 | } 5 | -------------------------------------------------------------------------------- /website/src/lib/constants.ts: -------------------------------------------------------------------------------- 1 | export const CHAINS = ['arbitrum-one', 'arbitrum-sepolia'] as const; 2 | -------------------------------------------------------------------------------- /packages/cli/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "include": ["./src"] 4 | } 5 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": ["esbenp.prettier-vscode", "dbaeumer.vscode-eslint"] 3 | } 4 | -------------------------------------------------------------------------------- /examples/substreams-powered-subgraph/.gitignore: -------------------------------------------------------------------------------- 1 | *.spkg 2 | target/ 3 | .idea 4 | src/pb/ 5 | node_modules/ 6 | -------------------------------------------------------------------------------- /examples/cosmos-block-filtering/config/osmosis.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Osmosis", 3 | "network": "osmosis-1" 4 | } 5 | -------------------------------------------------------------------------------- /website/postcss.config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | plugins: { 3 | '@tailwindcss/postcss': {}, 4 | }, 5 | }; 6 | -------------------------------------------------------------------------------- /examples/cosmos-block-filtering/config/cosmoshub.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CosmosHub", 3 | "network": "cosmoshub-4" 4 | } 5 | -------------------------------------------------------------------------------- /examples/cosmos-validator-delegations/config/osmosis.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Osmosis", 3 | "network": "osmosis-1" 4 | } 5 | -------------------------------------------------------------------------------- /examples/cosmos-validator-rewards/config/osmosis.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Osmosis", 3 | "network": "osmosis-1" 4 | } 5 | -------------------------------------------------------------------------------- /examples/ethereum-basic-event-handlers/hardhat/hardhat.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | solidity: '0.8.9', 3 | }; 4 | -------------------------------------------------------------------------------- /examples/cosmos-validator-rewards/config/cosmoshub.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CosmosHub", 3 | "network": "cosmoshub-4" 4 | } 5 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/abi-not-found/schema.graphql: -------------------------------------------------------------------------------- 1 | type MyEntity @entity(immutable: true) { 2 | id: ID! 3 | } 4 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/block-handler-filters/schema.graphql: -------------------------------------------------------------------------------- 1 | type A @entity(immutable: true) { 2 | id: ID! 3 | } 4 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/invalid-abis/schema.graphql: -------------------------------------------------------------------------------- 1 | type MyEntity @entity(immutable: true) { 2 | id: ID! 3 | } 4 | -------------------------------------------------------------------------------- /examples/cosmos-validator-delegations/config/cosmoshub.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CosmosHub", 3 | "network": "cosmoshub-4" 4 | } 5 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/event-not-found/schema.graphql: -------------------------------------------------------------------------------- 1 | type MyEntity @entity(immutable: true) { 2 | id: ID! 3 | } 4 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/no-network-names/schema.graphql: -------------------------------------------------------------------------------- 1 | type MyEntity @entity(immutable: true) { 2 | id: ID! 3 | } 4 | -------------------------------------------------------------------------------- /.changeset/metal-lights-train.md: -------------------------------------------------------------------------------- 1 | --- 2 | '@graphprotocol/graph-cli': patch 3 | --- 4 | 5 | Fixed entity id format in generated tests 6 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/call-function-not-found/schema.graphql: -------------------------------------------------------------------------------- 1 | type MyEntity @entity(immutable: true) { 2 | id: ID! 3 | } 4 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/call-handler-with-tuple/schema.graphql: -------------------------------------------------------------------------------- 1 | type MyEntity @entity(immutable: true) { 2 | id: ID! 3 | } 4 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/example-values-found/schema.graphql: -------------------------------------------------------------------------------- 1 | type MyEntity @entity(immutable: true) { 2 | id: ID! 3 | } 4 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/missing-entity-id/schema.graphql: -------------------------------------------------------------------------------- 1 | type MyEntity @entity(immutable: true) { 2 | name: String! 3 | } 4 | -------------------------------------------------------------------------------- /examples/near-blocks/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@graphprotocol/graph-ts/types/tsconfig.base.json", 3 | "include": ["src"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/conflicting-network-names/schema.graphql: -------------------------------------------------------------------------------- 1 | type MyEntity @entity(immutable: true) { 2 | id: ID! 3 | } 4 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/conflicting-protocol-names/schema.graphql: -------------------------------------------------------------------------------- 1 | type MyEntity @entity(immutable: true) { 2 | id: ID! 3 | } 4 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/invalid-contract-addresses/schema.graphql: -------------------------------------------------------------------------------- 1 | type MyEntity @entity(immutable: true) { 2 | id: ID! 3 | } 4 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/invalid-data-source-template/schema.graphql: -------------------------------------------------------------------------------- 1 | type MyEntity @entity(immutable: true) { 2 | id: ID! 3 | } 4 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/nested-template-nice-error/schema.graphql: -------------------------------------------------------------------------------- 1 | type MyEntity @entity(immutable: true) { 2 | id: ID! 3 | } 4 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/ethereum-contract-without-handlers/schema.graphql: -------------------------------------------------------------------------------- 1 | type MyEntity @entity(immutable: true) { 2 | id: ID! 3 | } 4 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/indexer-hints/schema.graphql: -------------------------------------------------------------------------------- 1 | type MyEntity @entity(immutable: true) { 2 | id: ID! 3 | x: BigDecimal! 4 | } 5 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/source-without-address-is-valid/schema.graphql: -------------------------------------------------------------------------------- 1 | type MyEntity @entity(immutable: true) { 2 | id: ID! 3 | } 4 | -------------------------------------------------------------------------------- /examples/cosmos-block-filtering/schema.graphql: -------------------------------------------------------------------------------- 1 | type Block @entity(immutable: true) { 2 | id: ID! 3 | number: BigInt 4 | timestamp: BigInt 5 | } 6 | -------------------------------------------------------------------------------- /examples/cosmos-block-filtering/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@graphprotocol/graph-ts/types/tsconfig.base.json", 3 | "include": ["src"] 4 | } 5 | -------------------------------------------------------------------------------- /examples/cosmos-validator-rewards/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@graphprotocol/graph-ts/types/tsconfig.base.json", 3 | "include": ["src"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/topic0-is-valid/schema.graphql: -------------------------------------------------------------------------------- 1 | type MyEntity @entity(immutable: true) { 2 | id: ID! 3 | x: BigDecimal! 4 | } 5 | -------------------------------------------------------------------------------- /website/public/the-graph-logomark-light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/graphprotocol/graph-tooling/HEAD/website/public/the-graph-logomark-light.png -------------------------------------------------------------------------------- /examples/cosmos-osmosis-token-swaps/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@graphprotocol/graph-ts/types/tsconfig.base.json", 3 | "include": ["src"] 4 | } 5 | -------------------------------------------------------------------------------- /examples/cosmos-validator-delegations/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@graphprotocol/graph-ts/types/tsconfig.base.json", 3 | "include": ["src"] 4 | } 5 | -------------------------------------------------------------------------------- /examples/cosmos-validator-rewards/schema.graphql: -------------------------------------------------------------------------------- 1 | type Reward @entity(immutable: true) { 2 | id: ID! 3 | amount: String 4 | validator: String 5 | } 6 | -------------------------------------------------------------------------------- /packages/cli/src/command-helpers/ipfs.ts: -------------------------------------------------------------------------------- 1 | const DEFAULT_IPFS_URL = 'https://api.thegraph.com/ipfs/api/v0' as const; 2 | 3 | export { DEFAULT_IPFS_URL }; 4 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/big-decimal-is-valid/schema.graphql: -------------------------------------------------------------------------------- 1 | type MyEntity @entity(immutable: true) { 2 | id: ID! 3 | x: BigDecimal! 4 | } 5 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/duplicate-template-name/schema.graphql: -------------------------------------------------------------------------------- 1 | type MyEntity @entity(immutable: true) { 2 | id: ID! 3 | x: BigDecimal! 4 | } 5 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/entity-field-args/schema.graphql: -------------------------------------------------------------------------------- 1 | type MyEntity @entity(immutable: true) { 2 | id: ID! 3 | foo(bar: Int!): Int! 4 | } 5 | -------------------------------------------------------------------------------- /examples/substreams-powered-subgraph/rust-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "1.72" 3 | components = ["rustfmt"] 4 | targets = ["wasm32-unknown-unknown"] 5 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/derived-from-target-type-missing/Abi.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "event", 4 | "name": "ExampleEvent" 5 | } 6 | ] 7 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/duplicate-data-source-name/schema.graphql: -------------------------------------------------------------------------------- 1 | type MyEntity @entity(immutable: true) { 2 | id: ID! 3 | x: BigDecimal! 4 | } 5 | -------------------------------------------------------------------------------- /packages/ts/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "assemblyscript/std/assembly", 3 | "include": ["index.ts", "helper-functions.ts", "global/global.ts", "test"] 4 | } 5 | -------------------------------------------------------------------------------- /examples/matic-lens-protocol-posts-subgraph/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@graphprotocol/graph-ts/types/tsconfig.base.json", 3 | "include": ["src", "tests"] 4 | } 5 | -------------------------------------------------------------------------------- /examples/ethereum-gravatar/schema.graphql: -------------------------------------------------------------------------------- 1 | type Gravatar @entity(immutable: false) { 2 | id: ID! 3 | owner: Bytes! 4 | displayName: String! 5 | imageUrl: String! 6 | } 7 | -------------------------------------------------------------------------------- /packages/cli/src/command-helpers/fs.ts: -------------------------------------------------------------------------------- 1 | import path from 'node:path'; 2 | 3 | const displayPath = (p: string) => path.relative(process.cwd(), p); 4 | 5 | export { displayPath }; 6 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/add/subgraph/networks.json: -------------------------------------------------------------------------------- 1 | { 2 | "test": { 3 | "Gravity": { 4 | "address": "0xCfEB869F69431e42cdB54A4F4f105C19C080A601" 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/2d-array-is-valid/schema.graphql: -------------------------------------------------------------------------------- 1 | type MyEntity @entity(immutable: true) { 2 | id: ID! 3 | childTokenURIs: [[String!]!]! # string[][] 4 | } 5 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/abi-not-found/Abi.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "event", 4 | "name": "ExampleEvent", 5 | "inputs": [{ "type": "string" }] 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/indexer-hints/Abi.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "event", 4 | "name": "ExampleEvent", 5 | "inputs": [{ "type": "string" }] 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/2d-array-is-valid/Abi.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "event", 4 | "name": "ExampleEvent", 5 | "inputs": [{ "type": "string" }] 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/3d-array-is-valid/Abi.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "event", 4 | "name": "ExampleEvent", 5 | "inputs": [{ "type": "string" }] 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/3d-array-is-valid/schema.graphql: -------------------------------------------------------------------------------- 1 | type MyEntity @entity(immutable: true) { 2 | id: ID! 3 | childTokenURIs: [[[String!]!]!]! # string[][][] 4 | } 5 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/entity-field-args/Abi.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "event", 4 | "name": "ExampleEvent", 5 | "inputs": [{ "type": "string" }] 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/event-not-found/Abi.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "event", 4 | "name": "ExampleEvent", 5 | "inputs": [{ "type": "string" }] 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/missing-entity-id/Abi.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "event", 4 | "name": "ExampleEvent", 5 | "inputs": [{ "type": "string" }] 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/no-network-names/Abi.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "event", 4 | "name": "ExampleEvent", 5 | "inputs": [{ "type": "string" }] 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/topic0-is-valid/Abi.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "event", 4 | "name": "ExampleEvent", 5 | "inputs": [{ "type": "string" }] 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/big-decimal-is-valid/Abi.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "event", 4 | "name": "ExampleEvent", 5 | "inputs": [{ "type": "string" }] 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/derived-from-target-type-missing/schema.graphql: -------------------------------------------------------------------------------- 1 | type Foo @entity(immutable: true) { 2 | id: ID! 3 | bars: [Bars!]! @derivedFrom(field: "foo") 4 | } 5 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/duplicate-template-name/Abi.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "event", 4 | "name": "ExampleEvent", 5 | "inputs": [{ "type": "string" }] 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/example-values-found/Abi.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "event", 4 | "name": "ExampleEvent", 5 | "inputs": [{ "type": "string" }] 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/invalid-graphql-schema/Abi.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "event", 4 | "name": "ExampleEvent", 5 | "inputs": [{ "type": "string" }] 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /website/src/routes/__root.tsx: -------------------------------------------------------------------------------- 1 | import { createRootRoute, Outlet } from '@tanstack/react-router'; 2 | 3 | export const Route = createRootRoute({ 4 | component: () => , 5 | }); 6 | -------------------------------------------------------------------------------- /examples/ethereum-gravatar/README.md: -------------------------------------------------------------------------------- 1 | # Example Ethereum Subgraph 2 | 3 | An example to help you get started with The Graph. For more information see the docs on 4 | https://thegraph.com/docs/. 5 | -------------------------------------------------------------------------------- /examples/example-subgraph/dist/ExampleSubgraph/ExampleSubgraph.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/graphprotocol/graph-tooling/HEAD/examples/example-subgraph/dist/ExampleSubgraph/ExampleSubgraph.wasm -------------------------------------------------------------------------------- /examples/near-blocks/schema.graphql: -------------------------------------------------------------------------------- 1 | type BlockEvent @entity(immutable: true) { 2 | id: ID! 3 | number: BigInt 4 | hash: Bytes 5 | timestampNanosec: BigInt 6 | gasPrice: BigInt 7 | } 8 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/conflicting-network-names/Abi.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "event", 4 | "name": "ExampleEvent", 5 | "inputs": [{ "type": "string" }] 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/conflicting-protocol-names/Abi.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "event", 4 | "name": "ExampleEvent", 5 | "inputs": [{ "type": "string" }] 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/duplicate-data-source-name/Abi.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "event", 4 | "name": "ExampleEvent", 5 | "inputs": [{ "type": "string" }] 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/invalid-contract-addresses/Abi.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "event", 4 | "name": "ExampleEvent", 5 | "inputs": [{ "type": "string" }] 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/invalid-entity-field-types/Abi.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "event", 4 | "name": "ExampleEvent", 5 | "inputs": [{ "type": "string" }] 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/invalid-fulltext-directive/Abi.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "event", 4 | "name": "ExampleEvent", 5 | "inputs": [{ "type": "string" }] 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/nested-template-nice-error/Abi.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "event", 4 | "name": "ExampleEvent", 5 | "inputs": [{ "type": "string" }] 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/require-immutable-argument/Abi.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "event", 4 | "name": "ExampleEvent", 5 | "inputs": [{ "type": "string" }] 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /packages/cli/tsconfig.dev.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "sourceMap": true, 5 | "inlineSources": true 6 | }, 7 | "include": ["./src"] 8 | } 9 | -------------------------------------------------------------------------------- /examples/ethereum-basic-event-handlers/README.md: -------------------------------------------------------------------------------- 1 | # Example Subgraph 2 | 3 | An example to help you get started with The Graph. For more information see the docs on 4 | https://thegraph.com/docs/. 5 | -------------------------------------------------------------------------------- /examples/ethereum-gravatar/artifacts/contracts/Migrations.sol/Migrations.dbg.json: -------------------------------------------------------------------------------- 1 | { 2 | "_format": "hh-sol-dbg-1", 3 | "buildInfo": "../../build-info/02f396becc82f8cfeb8abea132c96e29.json" 4 | } 5 | -------------------------------------------------------------------------------- /packages/cli/src/constants.ts: -------------------------------------------------------------------------------- 1 | import { version } from './version.js'; 2 | 3 | export const GRAPH_CLI_SHARED_HEADERS = { 4 | 'User-Agent': `@graphprotocol/graph-cli@${version}` as const, 5 | }; 6 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/ethereum-contract-without-handlers/Abi.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "event", 4 | "name": "ExampleEvent", 5 | "inputs": [{ "type": "string" }] 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/source-without-address-is-valid/Abi.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "event", 4 | "name": "ExampleEvent", 5 | "inputs": [{ "type": "string" }] 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /examples/ethereum-gravatar/artifacts/contracts/Gravity.sol/GravatarRegistry.dbg.json: -------------------------------------------------------------------------------- 1 | { 2 | "_format": "hh-sol-dbg-1", 3 | "buildInfo": "../../build-info/02f396becc82f8cfeb8abea132c96e29.json" 4 | } 5 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/missing-or-invalid-derived-from-fields/Abi.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "event", 4 | "name": "ExampleEvent", 5 | "inputs": [{ "type": "string" }] 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /packages/cli/src/validation/index.ts: -------------------------------------------------------------------------------- 1 | export { validateContract, validateContractValues } from './contract.js'; 2 | export { validateManifest } from './manifest.js'; 3 | export { validateSchema } from './schema.js'; 4 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/globalSetup.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | 3 | import { linkCli } from './link'; 4 | 5 | export default async () => { 6 | process.env.GRAPH_CLI_TESTS = '1'; 7 | await linkCli(); 8 | }; 9 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/near-is-valid/schema.graphql: -------------------------------------------------------------------------------- 1 | type MyEntity @entity(immutable: true) { 2 | id: ID! 3 | x: Account! 4 | } 5 | 6 | type Account @entity(immutable: true) { 7 | id: ID! 8 | } 9 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/globalTeardown.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | 3 | import { unlinkCli } from './util'; 4 | 5 | export default async () => { 6 | delete process.env.GRAPH_CLI_TESTS; 7 | await unlinkCli(); 8 | }; 9 | -------------------------------------------------------------------------------- /examples/matic-lens-protocol-posts-subgraph/networks.json: -------------------------------------------------------------------------------- 1 | { 2 | "matic": { 3 | "Contract": { 4 | "address": "0xDb46d1Dc155634FbC732f92E853b10B288AD5a1d", 5 | "startBlock": 28384641 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/missing-entity-id.stderr: -------------------------------------------------------------------------------- 1 | - Load subgraph from subgraph.yaml 2 | ✖ Failed to load subgraph from subgraph.yaml: Error in schema.graphql: 3 | 4 | MyEntity: 5 | - Missing field: id: ID! 6 | -------------------------------------------------------------------------------- /examples/ethereum-basic-event-handlers/.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | coverage 3 | coverage.json 4 | typechain 5 | typechain-types 6 | 7 | # Hardhat files 8 | cache 9 | artifacts/build-info 10 | artifacts/contracts/**/*.dbg.json 11 | -------------------------------------------------------------------------------- /examples/near-blocks/README.md: -------------------------------------------------------------------------------- 1 | # Example NEAR Blocks Subgraph 2 | 3 | An example to help you get started with NEAR indexing with The Graph. For more information see the 4 | docs on https://thegraph.com/docs/supported-networks/near. 5 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/invalid-graphql-schema/schema.graphql: -------------------------------------------------------------------------------- 1 | type Something @entity(immutable: true) { 2 | id: ID! 3 | } 4 | 5 | type MyEntity @entity(immutable: true) { 6 | id: ID! 7 | invalidField: [Something]! 8 | } 9 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/derived-from-target-type-missing.stderr: -------------------------------------------------------------------------------- 1 | - Load subgraph from subgraph.yaml 2 | ✖ Failed to load subgraph from subgraph.yaml: Error in schema.graphql: 3 | 4 | Foo: 5 | - Field 'bars': Unknown type 'Bars'. 6 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/entity-field-args.stderr: -------------------------------------------------------------------------------- 1 | - Load subgraph from subgraph.yaml 2 | ✖ Failed to load subgraph from subgraph.yaml: Error in schema.graphql: 3 | 4 | MyEntity: 5 | - Field 'foo': Field arguments are not supported. 6 | -------------------------------------------------------------------------------- /examples/ethereum-basic-event-handlers/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "commonjs", 5 | "moduleResolution": "node", 6 | "outDir": "dist", 7 | "esModuleInterop": true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/ethereum-gravatar/hardhat.config.ts: -------------------------------------------------------------------------------- 1 | import { HardhatUserConfig } from 'hardhat/config'; 2 | import '@nomicfoundation/hardhat-toolbox'; 3 | 4 | const config: HardhatUserConfig = { 5 | solidity: '0.4.25', 6 | }; 7 | 8 | export default config; 9 | -------------------------------------------------------------------------------- /examples/ethereum-gravatar/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | var Migrations = artifacts.require('./Migrations.sol'); 2 | 3 | module.exports = async function () { 4 | const migrations = await Migrations.new(); 5 | Migrations.setAsDeployed(migrations); 6 | }; 7 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/invalid-abis.stderr: -------------------------------------------------------------------------------- 1 | - Load subgraph from subgraph.yaml 2 | ✖ Failed to load subgraph from subgraph.yaml: Error in subgraph.yaml: 3 | 4 | Path: dataSources > 0 > mapping > abis > 0 > file 5 | No valid ABI in file: InvalidAbi.json 6 | -------------------------------------------------------------------------------- /.changeset/@graphprotocol_graph-cli-2068-dependencies.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@graphprotocol/graph-cli": patch 3 | --- 4 | dependencies updates: 5 | - Updated dependency [`kubo-rpc-client@^6.0.0` ↗︎](https://www.npmjs.com/package/kubo-rpc-client/v/6.0.0) (from `^5.0.2`, in `dependencies`) 6 | -------------------------------------------------------------------------------- /examples/substreams-powered-subgraph/schema.graphql: -------------------------------------------------------------------------------- 1 | type Contract @entity(immutable: true) { 2 | id: ID! 3 | 4 | "The timestamp when the contract was deployed" 5 | timestamp: String! 6 | 7 | "The block number of the contract deployment" 8 | blockNumber: BigInt! 9 | } 10 | -------------------------------------------------------------------------------- /examples/ethereum-gravatar/migrations/2_deploy_contract.js: -------------------------------------------------------------------------------- 1 | const GravatarRegistry = artifacts.require('./GravatarRegistry.sol'); 2 | 3 | module.exports = async function () { 4 | const gravatarRegistry = await GravatarRegistry.new(); 5 | GravatarRegistry.setAsDeployed(gravatarRegistry); 6 | }; 7 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/duplicate-template-name.stderr: -------------------------------------------------------------------------------- 1 | - Load subgraph from subgraph.yaml 2 | ✖ Failed to load subgraph from subgraph.yaml: Error in subgraph.yaml: 3 | 4 | Path: templates > 1 > name 5 | More than one template named 'ExampleSubgraph', template names must be unique. 6 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/invalid-manifest-cannot-infer-protocol/subgraph.yaml: -------------------------------------------------------------------------------- 1 | schema: 2 | file: ./non-existent.grapqhl 3 | dataSources: 4 | - name: 5 5 | abis: 6 | name: Foo 7 | mapping: 8 | - 12 9 | - 13 10 | - 14 11 | templates: 12 | field: foo 13 | -------------------------------------------------------------------------------- /examples/near-receipts/schema.graphql: -------------------------------------------------------------------------------- 1 | type Greeter @entity(immutable: true) { 2 | id: ID! 3 | name: String! 4 | greetings: [Greeting!] @derivedFrom(field: "greeter") 5 | } 6 | 7 | type Greeting @entity(immutable: true) { 8 | id: ID! 9 | greeter: Greeter! 10 | timestamp: BigInt! 11 | } 12 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/duplicate-data-source-name.stderr: -------------------------------------------------------------------------------- 1 | - Load subgraph from subgraph.yaml 2 | ✖ Failed to load subgraph from subgraph.yaml: Error in subgraph.yaml: 3 | 4 | Path: dataSources > 1 > name 5 | More than one data source named 'ExampleSubgraph', data source names must be unique. 6 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/invalid-manifest/subgraph.yaml: -------------------------------------------------------------------------------- 1 | schema: 2 | file: ./non-existent.grapqhl 3 | dataSources: 4 | - kind: ethereum/contract 5 | name: 5 6 | abis: 7 | name: Foo 8 | mapping: 9 | - 12 10 | - 13 11 | - 14 12 | templates: 13 | field: foo 14 | -------------------------------------------------------------------------------- /website/tsconfig.node.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "skipLibCheck": true, 5 | "module": "ESNext", 6 | "moduleResolution": "bundler", 7 | "allowSyntheticDefaultImports": true, 8 | "strict": true 9 | }, 10 | "include": ["vite.config.ts"] 11 | } 12 | -------------------------------------------------------------------------------- /examples/cosmos-osmosis-token-swaps/schema.graphql: -------------------------------------------------------------------------------- 1 | type Token @entity(immutable: true) { 2 | id: ID! 3 | amount: String 4 | denom: String 5 | } 6 | 7 | type TokenSwap @entity(immutable: true) { 8 | id: ID! 9 | sender: String 10 | poolId: String 11 | tokenIn: Token 12 | tokenOut: Token 13 | } 14 | -------------------------------------------------------------------------------- /examples/cosmos-validator-delegations/schema.graphql: -------------------------------------------------------------------------------- 1 | type Delegation @entity(immutable: true) { 2 | id: ID! 3 | delegatorAddress: String 4 | validatorAddress: String 5 | amount: Coin 6 | } 7 | 8 | type Coin @entity(immutable: true) { 9 | id: ID! 10 | denom: String 11 | amount: String 12 | } 13 | -------------------------------------------------------------------------------- /packages/cli/src/protocols/contract.ts: -------------------------------------------------------------------------------- 1 | // TODO: make sure the classes implement this type 2 | export interface ContractCtor { 3 | new (account: string): Contract; 4 | identifierName(): string; 5 | } 6 | 7 | export interface Contract { 8 | validate(): { valid: boolean; error: string | null }; 9 | } 10 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | .changeset 2 | dist 3 | build 4 | generated 5 | packages/cli/tests/cli/init 6 | packages/cli/tests/cli/validation 7 | packages/cli/tests/cli/add 8 | packages/cli/config/TheGraphNetworksRegistry.json 9 | packages/cli/CHANGELOG.md 10 | pnpm-lock.yaml 11 | website/src/graphql-env.d.ts 12 | renovate.json 13 | -------------------------------------------------------------------------------- /examples/matic-lens-protocol-posts-subgraph/schema.graphql: -------------------------------------------------------------------------------- 1 | type PostCreated @entity(immutable: true) { 2 | id: Bytes! 3 | ownerId: BigInt! 4 | contentURI: String! 5 | timestamp: BigInt! 6 | } 7 | 8 | type PostContent @entity(immutable: true) { 9 | id: Bytes! 10 | hash: String! 11 | content: String! 12 | } 13 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/require-immutable-argument.stderr: -------------------------------------------------------------------------------- 1 | - Load subgraph from subgraph.yaml 2 | ✖ Failed to load subgraph from subgraph.yaml: Error in schema.graphql: 3 | 4 | EntityA: 5 | - @entity directive requires `immutable` argument 6 | Hint: Try updating the entity definition with: @entity(immutable: true) 7 | -------------------------------------------------------------------------------- /examples/substreams-powered-subgraph/proto/example.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package example; 4 | 5 | message Contracts { 6 | repeated Contract contracts = 1; 7 | } 8 | 9 | message Contract { 10 | string address = 1; 11 | uint64 blockNumber = 2; 12 | string timestamp = 3; 13 | uint64 ordinal = 4; 14 | } -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/ethereum-contract-without-handlers.stderr: -------------------------------------------------------------------------------- 1 | - Load subgraph from subgraph.yaml 2 | ✖ Failed to load subgraph from subgraph.yaml: Error in subgraph.yaml: 3 | 4 | Path: dataSources > 0 > mapping 5 | Mapping has no blockHandlers, callHandlers or eventHandlers. 6 | At least one such handler must be defined. 7 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/add/subgraph/schema.graphql: -------------------------------------------------------------------------------- 1 | type NewGravatar @entity(immutable: true) { 2 | id: ID! 3 | owner: Bytes! 4 | displayName: String! 5 | imageUrl: String! 6 | } 7 | 8 | type UpdatedGravatar @entity(immutable: true) { 9 | id: ID! 10 | owner: Bytes! 11 | displayName: String! 12 | imageUrl: String! 13 | } 14 | -------------------------------------------------------------------------------- /examples/ethereum-basic-event-handlers/schema.graphql: -------------------------------------------------------------------------------- 1 | type NewGravatar @entity(immutable: false) { 2 | id: ID! 3 | owner: Bytes! 4 | displayName: String! 5 | imageUrl: String! 6 | } 7 | 8 | type UpdatedGravatar @entity(immutable: false) { 9 | id: ID! 10 | owner: Bytes! 11 | displayName: String! 12 | imageUrl: String! 13 | } 14 | -------------------------------------------------------------------------------- /examples/ethereum-basic-event-handlers/build/schema.graphql: -------------------------------------------------------------------------------- 1 | type NewGravatar @entity(immutable: false) { 2 | id: ID! 3 | owner: Bytes! 4 | displayName: String! 5 | imageUrl: String! 6 | } 7 | 8 | type UpdatedGravatar @entity(immutable: false) { 9 | id: ID! 10 | owner: Bytes! 11 | displayName: String! 12 | imageUrl: String! 13 | } 14 | -------------------------------------------------------------------------------- /examples/near-receipts/README.md: -------------------------------------------------------------------------------- 1 | # Example NEAR Receipts Subgraph: Good Morning NEAR 2 | 3 | This subgraph indexes `app.good-morning.near`, which you can interact with at 4 | https://gm-near.surge.sh/ 5 | 6 | An example to help you get started with NEAR indexing with The Graph. For more information see the 7 | docs on https://thegraph.com/docs/supported-networks/near. 8 | -------------------------------------------------------------------------------- /packages/cli/src/protocols/cosmos/scaffold/manifest.ts: -------------------------------------------------------------------------------- 1 | export const source = () => ` 2 | startBlock: 0`; 3 | 4 | export const mapping = () => ` 5 | apiVersion: 0.0.5 6 | language: wasm/assemblyscript 7 | entities: 8 | - ExampleEntity 9 | blockHandlers: 10 | - handler: handleBlock 11 | file: ./src/contract.ts`; 12 | -------------------------------------------------------------------------------- /examples/ethereum-basic-event-handlers/hardhat/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "contracts-docker", 3 | "version": "1.0.0", 4 | "description": "", 5 | "author": "", 6 | "license": "ISC", 7 | "keywords": [], 8 | "scripts": { 9 | "localnode": "hardhat node --hostname 0.0.0.0" 10 | }, 11 | "dependencies": { 12 | "hardhat": "^2.22.1" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/invalid-manifest-cannot-infer-protocol.stderr: -------------------------------------------------------------------------------- 1 | - Load subgraph from subgraph.yaml 2 | ✖ Failed to load subgraph from subgraph.yaml: Error in subgraph.yaml: 3 | 4 | Path: / 5 | Unable to determine for which protocol manifest file is built for. Ensure you have at least one 'dataSources' and/or 'templates' elements defined in your subgraph. 6 | -------------------------------------------------------------------------------- /packages/cli/src/protocols/subgraph.ts: -------------------------------------------------------------------------------- 1 | import immutable from 'immutable'; 2 | 3 | export interface SubgraphOptions { 4 | manifest?: any; 5 | resolveFile: (path: string) => string; 6 | protocol?: any; 7 | } 8 | 9 | export interface Subgraph extends SubgraphOptions { 10 | validateManifest(): immutable.List; 11 | handlerTypes(): immutable.List; 12 | } 13 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/spawn-command.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'spawn-command' { 2 | import { spawn, SpawnOptions, ChildProcessByStdio } from 'node:child_process'; 3 | 4 | type SpawnResult = ChildProcessByStdio; 5 | export { SpawnOptions, SpawnResult }; 6 | export default function spawn(command: string, options: SpawnOptions): SpawnResult; 7 | } 8 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "examples/subgraph-composition-example"] 2 | path = examples/subgraph-composition-example 3 | url = https://github.com/isum/subgraph-composition-example.git 4 | [submodule "examples/subgraph-composition-sample-subgraph"] 5 | path = examples/subgraph-composition-sample-subgraph 6 | url = https://github.com/incrypto32/subgraph-composition-sample-subgraph.git 7 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/nested-template-nice-error.stderr: -------------------------------------------------------------------------------- 1 | - Load subgraph from subgraph.yaml 2 | ✖ Failed to load subgraph from subgraph.yaml: Error in subgraph.yaml: 3 | 4 | Path: dataSources > 0 > mapping 5 | The way to declare data source templates has changed, please move the templates from inside data sources to a `templates:` field at the top level of the manifest. 6 | -------------------------------------------------------------------------------- /packages/cli/src/protocols/substreams/scaffold/manifest.ts: -------------------------------------------------------------------------------- 1 | export const source = ({ spkgPath, spkgModule }: { spkgPath?: string; spkgModule?: string }) => ` 2 | package: 3 | moduleName: ${spkgModule || 'graph_out'} 4 | file: ${spkgPath || 'substreams.spkg'}`; 5 | 6 | export const mapping = () => ` 7 | apiVersion: 0.0.5 8 | kind: substreams/graph-entities`; 9 | -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | import prettierConfig from '@theguild/prettier-config'; 2 | 3 | export default { 4 | ...prettierConfig, 5 | overrides: [ 6 | ...(prettierConfig.overrides || []), 7 | { 8 | files: '*.md{,x}', 9 | options: { 10 | semi: false, 11 | trailingComma: 'none', 12 | proseWrap: 'preserve', 13 | }, 14 | }, 15 | ], 16 | }; 17 | -------------------------------------------------------------------------------- /packages/cli/src/migrations/util/load-manifest.ts: -------------------------------------------------------------------------------- 1 | import path from 'node:path'; 2 | import fs from 'fs-extra'; 3 | import yaml from 'js-yaml'; 4 | 5 | export async function loadManifest(manifestFile: string) { 6 | if (manifestFile.match(/.js$/)) { 7 | return await import(path.resolve(manifestFile)); 8 | } 9 | return yaml.load(await fs.readFile(manifestFile, 'utf-8')); 10 | } 11 | -------------------------------------------------------------------------------- /packages/cli/vitest.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vitest/config'; 2 | 3 | export default defineConfig({ 4 | test: { 5 | env: { 6 | // node v21 has warnings about the deprecation of punycode which can break test snapshots 7 | NODE_NO_WARNINGS: '1', 8 | }, 9 | hookTimeout: 20_000, 10 | globalSetup: './tests/cli/globalSetup.ts', 11 | }, 12 | }); 13 | -------------------------------------------------------------------------------- /examples/ethereum-basic-event-handlers/hardhat.config.ts: -------------------------------------------------------------------------------- 1 | import { HardhatUserConfig } from 'hardhat/config'; 2 | import '@nomicfoundation/hardhat-toolbox'; 3 | 4 | const config: HardhatUserConfig = { 5 | solidity: '0.4.25', 6 | defaultNetwork: 'test', 7 | networks: { 8 | test: { 9 | url: 'http://localhost:8545', 10 | }, 11 | }, 12 | }; 13 | 14 | export default config; 15 | -------------------------------------------------------------------------------- /examples/ethereum-basic-event-handlers/hardhat/entrypoint.sh: -------------------------------------------------------------------------------- 1 | # Adapted from https://github.com/codingwithmanny/hardhat-docker 2 | 3 | #!/bin/sh 4 | 5 | # Change to the correct directory 6 | cd /usr/src/app 7 | 8 | # Run hardhat 9 | pnpm localnode 10 | 11 | # Keep node alive 12 | set -e 13 | if [ "${1#-}" != "${1}" ] || [ -z "$(command -v "${1}")" ]; then 14 | set -- node "$@" 15 | fi 16 | exec "$@" 17 | -------------------------------------------------------------------------------- /website/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | 26 | /src/routeTree.gen.ts 27 | -------------------------------------------------------------------------------- /website/components.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://ui.shadcn.com/schema.json", 3 | "style": "new-york", 4 | "rsc": false, 5 | "tsx": true, 6 | "tailwind": { 7 | "config": "tailwind.config.js", 8 | "css": "src/global.css", 9 | "baseColor": "slate", 10 | "cssVariables": true, 11 | "prefix": "" 12 | }, 13 | "aliases": { 14 | "components": "@/components", 15 | "utils": "@/lib/utils" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /website/src/routes/publish.tsx: -------------------------------------------------------------------------------- 1 | import { z } from 'zod'; 2 | import { createFileRoute } from '@tanstack/react-router'; 3 | 4 | export const Route = createFileRoute('/publish')({ 5 | validateSearch: z.object({ 6 | subgraphId: z.string().optional(), 7 | // Transforming string to enum here doesn't actually work 8 | network: z.string().optional(), 9 | id: z.string().optional(), 10 | apiKey: z.string().optional(), 11 | }), 12 | }); 13 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/call-function-not-found.stderr: -------------------------------------------------------------------------------- 1 | - Load subgraph from subgraph.yaml 2 | ✖ Failed to load subgraph from subgraph.yaml: Error in subgraph.yaml: 3 | 4 | Path: dataSources > 0 > callHandlers > 0 5 | Call function with signature 'doSomething(uint256)' not present in ABI 'ExampleContract'. 6 | Available call functions: 7 | - () 8 | - owner() 9 | - transferOwnership(address) 10 | - upgrade(address,bytes) 11 | -------------------------------------------------------------------------------- /examples/ethereum-basic-event-handlers/hardhat/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:20-alpine 2 | 3 | COPY . /usr/src/app 4 | 5 | WORKDIR /usr/src/app 6 | 7 | RUN apk add git 8 | 9 | RUN apk add --update python3 make g++ && rm -rf /var/cache/apk/* 10 | 11 | RUN corepack enable 12 | 13 | RUN corepack prepare pnpm@9.10.0 --activate 14 | 15 | RUN pnpm install 16 | 17 | COPY $PWD/entrypoint.sh /usr/local/bin 18 | 19 | ENTRYPOINT ["/bin/sh", "/usr/local/bin/entrypoint.sh"] 20 | -------------------------------------------------------------------------------- /examples/substreams-powered-subgraph/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "substreams-ethereum-quickstart" 3 | version = "1.0.0" 4 | edition = "2021" 5 | 6 | [lib] 7 | name = "substreams" 8 | crate-type = ["cdylib"] 9 | 10 | [dependencies] 11 | substreams = "0.5" 12 | substreams-ethereum = "0.9" 13 | substreams-entity-change = "1.3" 14 | prost = "0.11" 15 | prost-types = "0.11" 16 | base64 = "0.13" 17 | 18 | [profile.release] 19 | lto = true 20 | opt-level = 's' 21 | strip = "debuginfo" 22 | -------------------------------------------------------------------------------- /packages/cli/src/protocols/arweave/scaffold/manifest.ts: -------------------------------------------------------------------------------- 1 | export const source = ({ contract }: { contract: string }) => ` 2 | owner: '${contract}'`; 3 | 4 | export const mapping = () => ` 5 | apiVersion: 0.0.5 6 | language: wasm/assemblyscript 7 | entities: 8 | - Block 9 | - Transaction 10 | blockHandlers: 11 | - handler: handleBlock 12 | transactionHandlers: 13 | - handler: handleTx 14 | file: ./src/mapping.ts`; 15 | -------------------------------------------------------------------------------- /packages/cli/bin/run.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | import process from 'node:process'; 3 | import semver from 'semver'; 4 | import { execute } from '@oclif/core'; 5 | import { nodeVersion } from '../dist/version.js'; 6 | 7 | if (!semver.satisfies(process.version, nodeVersion)) { 8 | process.stderr.write( 9 | `Node.js version ${nodeVersion} is required. Current version: ${process.version}\n`, 10 | ); 11 | process.exit(1); 12 | } 13 | 14 | await execute({ dir: import.meta.url }); 15 | -------------------------------------------------------------------------------- /packages/cli/src/fetch.ts: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line no-restricted-imports 2 | import { fetch } from '@whatwg-node/fetch'; 3 | import { GRAPH_CLI_SHARED_HEADERS } from './constants.js'; 4 | 5 | export default function fetchWrapper( 6 | input: Parameters[0], 7 | init?: Parameters[1], 8 | ) { 9 | return fetch(input, { 10 | ...init, 11 | headers: { 12 | ...init?.headers, 13 | ...GRAPH_CLI_SHARED_HEADERS, 14 | }, 15 | }); 16 | } 17 | -------------------------------------------------------------------------------- /website/vite.config.ts: -------------------------------------------------------------------------------- 1 | import path from 'node:path'; 2 | import { defineConfig } from 'vite'; 3 | import { nodePolyfills } from 'vite-plugin-node-polyfills'; 4 | import { TanStackRouterVite } from '@tanstack/router-vite-plugin'; 5 | import react from '@vitejs/plugin-react'; 6 | 7 | export default defineConfig({ 8 | plugins: [react(), nodePolyfills(), TanStackRouterVite()], 9 | resolve: { 10 | alias: { 11 | '@': path.resolve(__dirname, './src'), 12 | }, 13 | }, 14 | }); 15 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build:dev", 6 | "type": "shell", 7 | "command": "pnpm", 8 | "args": ["--filter=@graphprotocol/graph-cli", "build:dev"], 9 | "group": { 10 | "kind": "build", 11 | "isDefault": true 12 | }, 13 | "presentation": { 14 | "reveal": "silent", 15 | "panel": "shared" 16 | }, 17 | "problemMatcher": "$tsc" 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "yaml.schemas": { 3 | "https://json.schemastore.org/github-issue-config.json": ".github/ISSUE_TEMPLATE/config.yml", 4 | "https://json.schemastore.org/github-workflow.json": ".github/workflows/**/*.yml" 5 | }, 6 | "eslint.format.enable": true, 7 | "editor.formatOnSave": true, 8 | "editor.defaultFormatter": "esbenp.prettier-vscode", 9 | "typescript.tsdk": "website/node_modules/typescript/lib", 10 | "typescript.enablePromptUseWorkspaceTsdk": true 11 | } 12 | -------------------------------------------------------------------------------- /examples/aggregations/README.md: -------------------------------------------------------------------------------- 1 | This subgraph demonstrates aggregations by aggregating over some easily predictable values, namely 2 | the block numbers of the underlying chain. It's of little value beyond that. 3 | 4 | The [schema](./schema.graphql), the [subgraph manifest](./subgraph.yaml) and the 5 | [mappings](./src/mappings/blocks.ts) have comments that explain how to write your own aggregations. 6 | 7 | The script `check-data.sh` can be used to check that the aggregations were performed correctly. 8 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Feature Request 4 | url: https://github.com/graphprotocol/graph-tooling/discussions/new?category=ideas 5 | about: Have an idea for a new feature? Please share it with us here. 6 | - name: Have a question? 7 | url: https://discord.gg/vtvv7FP 8 | about: 9 | Not sure about something? need help from the community? have a question to our team? please 10 | ask and answer questions here. 11 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/conflicting-network-names.stderr: -------------------------------------------------------------------------------- 1 | - Load subgraph from subgraph.yaml 2 | ✖ Failed to load subgraph from subgraph.yaml: Error in subgraph.yaml: 3 | 4 | Path: / 5 | Conflicting networks used in data sources and templates: 6 | Data sources and templates using 'mainnet': 7 | - ExampleSubgraph 8 | Data sources and templates having no network set: 9 | - ExampleTemplate 10 | Recommendation: Make all data sources and templates use the same network name. 11 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/conflicting-protocol-names.stderr: -------------------------------------------------------------------------------- 1 | - Load subgraph from subgraph.yaml 2 | ✖ Failed to load subgraph from subgraph.yaml: Error in subgraph.yaml: 3 | 4 | Path: / 5 | Conflicting protocol kinds used in data sources and templates: 6 | Data sources and templates using 'ethereum': 7 | - ExampleSubgraph 8 | Data sources and templates using 'near': 9 | - ExampleTemplate 10 | Recommendation: Make all data sources and templates use the same protocol kind. 11 | -------------------------------------------------------------------------------- /examples/cosmos-block-filtering/src/mapping.ts: -------------------------------------------------------------------------------- 1 | import { BigInt, cosmos } from '@graphprotocol/graph-ts'; 2 | import { Block } from '../generated/schema'; 3 | 4 | export function handleBlock(bl: cosmos.Block): void { 5 | const hash = bl.header.hash.toHexString(); 6 | const height = BigInt.fromString(bl.header.height.toString()); 7 | 8 | const block = new Block(hash); 9 | 10 | block.number = height; 11 | block.timestamp = BigInt.fromString(bl.header.time.seconds.toString()); 12 | 13 | block.save(); 14 | } 15 | -------------------------------------------------------------------------------- /packages/cli/src/protocols/near/scaffold/manifest.ts: -------------------------------------------------------------------------------- 1 | import { strings } from 'gluegun'; 2 | 3 | export const source = ({ contract }: { contract: string }) => ` 4 | account: '${contract}'`; 5 | 6 | export const mapping = ({ contractName }: { contractName: string }) => ` 7 | apiVersion: 0.0.5 8 | language: wasm/assemblyscript 9 | entities: 10 | - ExampleEntity 11 | receiptHandlers: 12 | - handler: handleReceipt 13 | file: ./src/${strings.kebabCase(contractName)}.ts`; 14 | -------------------------------------------------------------------------------- /packages/ts/common/conversion.ts: -------------------------------------------------------------------------------- 1 | import './eager-offset'; 2 | import { Bytes } from './collections'; 3 | 4 | /** Host type conversion interface */ 5 | export declare namespace typeConversion { 6 | function bytesToString(bytes: Uint8Array): string; 7 | function bytesToHex(bytes: Uint8Array): string; 8 | function bigIntToString(bigInt: Uint8Array): string; 9 | function bigIntToHex(bigInt: Uint8Array): string; 10 | function stringToH160(s: string): Bytes; 11 | function bytesToBase58(n: Uint8Array): string; 12 | } 13 | -------------------------------------------------------------------------------- /packages/cli/src/command-helpers/subgraph.ts: -------------------------------------------------------------------------------- 1 | export const getSubgraphBasename = (name: string) => { 2 | const segments = name.split('/', 2); 3 | return segments[segments.length - 1]; 4 | }; 5 | 6 | export const formatSubgraphName = (slug: string) => { 7 | return slug 8 | .toLowerCase() 9 | .replace(/\s+/g, '-') 10 | .replace(/[^a-z0-9_-]/g, ''); 11 | }; 12 | 13 | export const formatContractName = (contractName: string) => { 14 | return contractName.replace(/[\s.]+/g, '_').replace(/[^a-zA-Z0-9_-]/g, ''); 15 | }; 16 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/abi-not-found copy.stderr: -------------------------------------------------------------------------------- 1 | - Load subgraph from subgraph.yaml 2 | ✖ Failed to load subgraph from subgraph.yaml: Error in subgraph.yaml: 3 | 4 | Path: dataSources > 0 > source > abi 5 | ABI name 'NonExistentAbi' not found in mapping > abis. 6 | Available ABIs: 7 | - FirstAbi 8 | - SecondAbi 9 | 10 | Path: templates > 0 > eventHandlers > 0 11 | Event with signature 'ExampleEvent(string,uint256)' not present in ABI 'ExampleContract'. 12 | Available events: 13 | - ExampleEvent(string) 14 | -------------------------------------------------------------------------------- /examples/near-blocks/src/mapping.ts: -------------------------------------------------------------------------------- 1 | import { BigInt, near } from '@graphprotocol/graph-ts'; 2 | import { BlockEvent } from '../generated/schema'; 3 | 4 | export function handleBlock(block: near.Block): void { 5 | const header = block.header; 6 | let event = new BlockEvent(header.hash.toHexString()); 7 | event.number = BigInt.fromI32(header.height as i32); 8 | event.hash = header.hash; 9 | event.timestampNanosec = BigInt.fromU64(header.timestampNanosec); 10 | event.gasPrice = header.gasPrice; 11 | 12 | event.save(); 13 | } 14 | -------------------------------------------------------------------------------- /.changeset/README.md: -------------------------------------------------------------------------------- 1 | # Changesets 2 | 3 | Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works 4 | with multi-package repos, or single-package repos to help you version and publish your code. You can 5 | find the full documentation for it [in our repository](https://github.com/changesets/changesets) 6 | 7 | We have a quick list of common questions to get you started engaging with this project in 8 | [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) 9 | -------------------------------------------------------------------------------- /examples/substreams-powered-subgraph/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.4 2 | description: Ethereum Contract Tracking Subgraph (powered by Substreams) 3 | repository: https://github.com/graphprotocol/graph-tooling 4 | schema: 5 | file: schema.graphql 6 | dataSources: 7 | - kind: substreams 8 | name: substream_test 9 | network: mainnet 10 | source: 11 | package: 12 | moduleName: graph_out 13 | file: substreams-test-v1.0.1.spkg 14 | mapping: 15 | kind: substreams/graph-entities 16 | apiVersion: 0.0.5 17 | -------------------------------------------------------------------------------- /packages/cli/src/protocols/subgraph/scaffold/mapping.ts: -------------------------------------------------------------------------------- 1 | export const generatePlaceholderHandlers = ({ 2 | entities, 3 | contract, 4 | }: { 5 | entities: string[]; 6 | contract: string; 7 | }) => ` 8 | import { ExampleEntity } from '../generated/schema' 9 | import {${entities.join(', ')}} from '../generated/subgraph-${contract}' 10 | 11 | ${entities 12 | .map( 13 | entityName => ` 14 | export function handle${entityName}(entity: ${entityName}): void { 15 | // Empty handler for ${entityName} 16 | }`, 17 | ) 18 | .join('\n')} 19 | `; 20 | -------------------------------------------------------------------------------- /packages/cli/src/version.ts: -------------------------------------------------------------------------------- 1 | import fs from 'node:fs'; 2 | import path from 'node:path'; 3 | import { fileURLToPath } from 'node:url'; 4 | 5 | const packageJson = JSON.parse( 6 | fs 7 | .readFileSync( 8 | // works even when bundled/built because the path to package.json is the same 9 | path.join(fileURLToPath(import.meta.url), '..', '..', 'package.json'), 10 | ) 11 | .toString(), 12 | ); 13 | 14 | export const version = packageJson.version as string; 15 | export const nodeVersion = (packageJson.engines?.node ?? '') as string; 16 | -------------------------------------------------------------------------------- /packages/ts/test/entity.ts: -------------------------------------------------------------------------------- 1 | import { BigDecimal, BigInt, Bytes, Entity } from './temp_lib/index'; 2 | 3 | export function testEntity(): void { 4 | const entity = new Entity(); 5 | 6 | entity.setBytes('x', new Bytes(1)); 7 | assert(entity.getBytes('x') == new Bytes(1)); 8 | 9 | entity.setBoolean('x', true); 10 | assert(entity.getBoolean('x') == true); 11 | 12 | // entity.setBigDecimal('x', new BigDecimal(BigInt.fromI32(2))); 13 | // TS2322: `getBigDecimal` doesn't return a nullable 14 | // assert(entity.getBigDecimal('x') !== null); 15 | } 16 | -------------------------------------------------------------------------------- /examples/cosmos-block-filtering/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.5 2 | description: Block Filtering Example 3 | repository: https://github.com/graphprotocol/graph-toolings 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: cosmos 8 | name: CosmosHub 9 | network: cosmoshub-4 10 | source: 11 | startBlock: 0 12 | mapping: 13 | apiVersion: 0.0.7 14 | language: wasm/assemblyscript 15 | entities: 16 | - Block 17 | blockHandlers: 18 | - handler: handleBlock 19 | file: ./src/mapping.ts 20 | -------------------------------------------------------------------------------- /examples/cosmos-validator-rewards/src/mapping.ts: -------------------------------------------------------------------------------- 1 | import { cosmos } from '@graphprotocol/graph-ts'; 2 | import { Reward } from '../generated/schema'; 3 | 4 | export function handleReward(data: cosmos.EventData): void { 5 | const height = data.block.header.height; 6 | 7 | const amount = data.event.getAttributeValue('amount'); 8 | const validator = data.event.getAttributeValue('validator'); 9 | 10 | let reward = new Reward(`${height}-${validator}`); 11 | 12 | reward.amount = amount; 13 | reward.validator = validator; 14 | 15 | reward.save(); 16 | } 17 | -------------------------------------------------------------------------------- /examples/ethereum-basic-event-handlers/scripts/deploy.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'hardhat'; 2 | 3 | async function main() { 4 | const Gravity = await ethers.getContractFactory('GravatarRegistry'); 5 | const gravity = await Gravity.deploy(); 6 | 7 | await gravity.deployed(); 8 | 9 | console.log(`Gravity.sol deployed to ${gravity.address}`); 10 | } 11 | 12 | // We recommend this pattern to be able to use async/await everywhere 13 | // and properly handle errors. 14 | main().catch(error => { 15 | console.error(error); 16 | process.exitCode = 1; 17 | }); 18 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/event-not-found.stderr: -------------------------------------------------------------------------------- 1 | - Load subgraph from subgraph.yaml 2 | ✖ Failed to load subgraph from subgraph.yaml: Error in subgraph.yaml: 3 | 4 | Path: dataSources > 0 > eventHandlers > 0 5 | Event with signature 'ExampleEvent(string,uint256)' not present in ABI 'ExampleContract'. 6 | Available events: 7 | - ExampleEvent(string) 8 | 9 | Path: templates > 0 > eventHandlers > 0 10 | Event with signature 'ExampleEvent(string,uint256)' not present in ABI 'ExampleContract'. 11 | Available events: 12 | - ExampleEvent(string) 13 | -------------------------------------------------------------------------------- /resources/test/docker-compose-standalone-node.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | ethereum: 4 | image: trufflesuite/ganache-cli:latest 5 | ports: 6 | - '18545:8545' 7 | - '18546:8546' 8 | command: -d -l 100000000000 -g 1 --noVMErrorsOnRPCResponse 9 | ipfs: 10 | image: ipfs/go-ipfs:v0.4.23 11 | ports: 12 | - '15001:5001' 13 | postgres: 14 | image: postgres 15 | ports: 16 | - '15432:5432' 17 | environment: 18 | POSTGRES_USER: graph 19 | POSTGRES_PASSWORD: let-me-in 20 | POSTGRES_DB: graph 21 | -------------------------------------------------------------------------------- /examples/near-blocks/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.4 2 | description: NEAR Blocks 3 | repository: https://github.com/graphprotocol/graph-toolings/tree/main/near/blocks-example 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: near 8 | name: blocks 9 | network: near-mainnet 10 | source: 11 | startBlock: 0 12 | mapping: 13 | apiVersion: 0.0.6 14 | language: wasm/assemblyscript 15 | file: ./src/mapping.ts 16 | entities: 17 | - BlockEvent 18 | blockHandlers: 19 | - handler: handleBlock 20 | -------------------------------------------------------------------------------- /.changeset/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://unpkg.com/@changesets/config@2.2.0/schema.json", 3 | "changelog": [ 4 | "@changesets/changelog-github", 5 | { "repo": "graphprotocol/graph-cli" } 6 | ], 7 | "commit": false, 8 | "fixed": [], 9 | "linked": [], 10 | "access": "public", 11 | "baseBranch": "main", 12 | "updateInternalDependencies": "patch", 13 | "ignore": [ 14 | "example-*", 15 | "website" 16 | ], 17 | "snapshot": { 18 | "useCalculatedVersion": true, 19 | "prereleaseTemplate": "{tag}-{datetime}-{commit}" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /examples/cosmos-block-filtering/subgraph.template.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.5 2 | description: Block Filtering Example 3 | repository: https://github.com/graphprotocol/graph-toolings 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: cosmos 8 | name: { { name } } 9 | network: { { network } } 10 | source: 11 | startBlock: 0 12 | mapping: 13 | apiVersion: 0.0.7 14 | language: wasm/assemblyscript 15 | entities: 16 | - Block 17 | blockHandlers: 18 | - handler: handleBlock 19 | file: ./src/mapping.ts 20 | -------------------------------------------------------------------------------- /examples/cosmos-validator-delegations/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.5 2 | description: Validator Delegations Example 3 | repository: https://github.com/graphprotocol/graph-toolings 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: cosmos 8 | name: CosmosHub 9 | network: cosmoshub-4 10 | source: 11 | startBlock: 0 12 | mapping: 13 | apiVersion: 0.0.7 14 | language: wasm/assemblyscript 15 | entities: 16 | - Delegation 17 | - Coin 18 | transactionHandlers: 19 | - handler: handleTx 20 | file: ./src/mapping.ts 21 | -------------------------------------------------------------------------------- /examples/cosmos-validator-rewards/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.5 2 | description: Validator Rewards Example 3 | repository: https://github.com/graphprotocol/graph-toolings 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: cosmos 8 | name: CosmosHub 9 | network: cosmoshub-4 10 | source: 11 | startBlock: 0 12 | mapping: 13 | apiVersion: 0.0.7 14 | language: wasm/assemblyscript 15 | entities: 16 | - Reward 17 | eventHandlers: 18 | - event: rewards 19 | handler: handleReward 20 | file: ./src/mapping.ts 21 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/call-handler-with-tuple/Abi.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "constant": false, 4 | "inputs": [ 5 | { "name": "", "type": "uint256" }, 6 | { 7 | "type": "tuple", 8 | "components": [ 9 | { "type": "bytes32" }, 10 | { "type": "bytes32" }, 11 | { "type": "uint256" } 12 | ] 13 | }, 14 | { 15 | "type": "bool" 16 | } 17 | ], 18 | "name": "doSomething", 19 | "outputs": [], 20 | "payable": false, 21 | "stateMutability": "nonpayable", 22 | "type": "function" 23 | } 24 | ] 25 | -------------------------------------------------------------------------------- /website/src/routes/index.lazy.tsx: -------------------------------------------------------------------------------- 1 | import { createLazyFileRoute } from '@tanstack/react-router'; 2 | 3 | export const Route = createLazyFileRoute('/')({ 4 | component: Page, 5 | }); 6 | 7 | export function Page() { 8 | return ( 9 | 10 | 11 | 16 | 17 | 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/ethereum-contract-without-handlers/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.1 2 | schema: 3 | file: ./schema.graphql 4 | dataSources: 5 | - kind: ethereum/contract 6 | name: ExampleSubgraph 7 | source: 8 | address: "22843e74c59580b3eaf6c233fa67d8b7c561a835" 9 | abi: ExampleContract 10 | mapping: 11 | kind: ethereum/events 12 | apiVersion: 0.0.5 13 | language: wasm/assemblyscript 14 | file: ./mapping.ts 15 | entities: 16 | - ExampleEntity 17 | abis: 18 | - name: ExampleContract 19 | file: ./Abi.json 20 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/require-immutable-argument/schema.graphql: -------------------------------------------------------------------------------- 1 | # Entity is not valid because it is missing the immutable argument; 2 | type EntityA @entity { 3 | id: ID! 4 | } 5 | 6 | # Entity is valid because it has the immutable argument; 7 | type EntityB @entity(immutable: true) { 8 | id: ID! 9 | } 10 | 11 | # Entity is valid because it has the immutable argument; 12 | type EntityC @entity(immutable: false) { 13 | id: ID! 14 | } 15 | 16 | # Entity is valid because the timeseries argument ensures immutability; 17 | type EntityD @entity(timeseries: true) { 18 | id: ID! 19 | } 20 | -------------------------------------------------------------------------------- /examples/cosmos-validator-rewards/subgraph.template.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.5 2 | description: Validator Rewards Example 3 | repository: https://github.com/graphprotocol/graph-toolings 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: cosmos 8 | name: { { name } } 9 | network: { { network } } 10 | source: 11 | startBlock: 0 12 | mapping: 13 | apiVersion: 0.0.7 14 | language: wasm/assemblyscript 15 | entities: 16 | - Reward 17 | eventHandlers: 18 | - event: rewards 19 | handler: handleReward 20 | file: ./src/mapping.ts 21 | -------------------------------------------------------------------------------- /examples/ethereum-gravatar/migrations/3_create_gravatars.js: -------------------------------------------------------------------------------- 1 | const GravatarRegistry = artifacts.require('./GravatarRegistry.sol'); 2 | 3 | module.exports = async function () { 4 | const registry = await GravatarRegistry.deployed(); 5 | 6 | console.log('Account address:', registry.address); 7 | 8 | let accounts = await web3.eth.getAccounts(); 9 | await registry.createGravatar('Carl', 'https://thegraph.com/img/team/team_04.png', { 10 | from: accounts[0], 11 | }); 12 | await registry.createGravatar('Lucas', 'https://thegraph.com/img/team/bw_Lucas.jpg', { 13 | from: accounts[1], 14 | }); 15 | }; 16 | -------------------------------------------------------------------------------- /examples/cosmos-validator-delegations/subgraph.template.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.5 2 | description: Validator Delegations Example 3 | repository: https://github.com/graphprotocol/graph-toolings 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: cosmos 8 | name: { { name } } 9 | network: { { network } } 10 | source: 11 | startBlock: 0 12 | mapping: 13 | apiVersion: 0.0.7 14 | language: wasm/assemblyscript 15 | entities: 16 | - Delegation 17 | - Coin 18 | transactionHandlers: 19 | - handler: handleTx 20 | file: ./src/mapping.ts 21 | -------------------------------------------------------------------------------- /packages/cli/src/debug.ts: -------------------------------------------------------------------------------- 1 | import debugFactory from 'debug'; 2 | 3 | debugFactory.formatters.L = immutableList => { 4 | return JSON.stringify(immutableList); 5 | }; 6 | 7 | debugFactory.formatters.M = immutableMap => { 8 | if (immutableMap?.toMap != null) { 9 | return JSON.stringify(immutableMap.toMap()); 10 | } 11 | 12 | if (typeof immutableMap?.toJS === 'function') { 13 | return JSON.stringify(immutableMap.toJS()); 14 | } 15 | 16 | if (typeof immutableMap === 'object') { 17 | return JSON.stringify(immutableMap); 18 | } 19 | return immutableMap; 20 | }; 21 | 22 | export default debugFactory; 23 | -------------------------------------------------------------------------------- /website/.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { browser: true, es2020: true }, 4 | extends: [ 5 | 'eslint:recommended', 6 | 'plugin:@typescript-eslint/recommended', 7 | 'plugin:react-hooks/recommended', 8 | ], 9 | ignorePatterns: ['dist', '.eslintrc.cjs', 'tailwind.config.js'], 10 | parser: '@typescript-eslint/parser', 11 | plugins: ['react-refresh'], 12 | rules: { 13 | 'react-refresh/only-export-components': ['warn', { allowConstantExport: true }], 14 | '@typescript-eslint/no-empty-object-type': 'warn', 15 | '@typescript-eslint/no-unused-vars': 'warn', 16 | }, 17 | }; 18 | -------------------------------------------------------------------------------- /examples/cosmos-osmosis-token-swaps/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.5 2 | description: Osmosis Token Swaps Example 3 | repository: https://github.com/graphprotocol/graph-toolings 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: cosmos 8 | name: Osmosis 9 | network: osmosis-1 10 | source: 11 | startBlock: 2522560 12 | mapping: 13 | apiVersion: 0.0.7 14 | language: wasm/assemblyscript 15 | entities: 16 | - TokenSwap 17 | - Token 18 | eventHandlers: 19 | - event: token_swapped 20 | handler: handleSwaps 21 | file: ./src/mapping.ts 22 | -------------------------------------------------------------------------------- /packages/cli/src/scaffold/get-git-ignore.ts: -------------------------------------------------------------------------------- 1 | export const getGitIgnore = () => { 2 | return `# Graph CLI generated artifacts 3 | build/ 4 | generated/ 5 | 6 | # Dependency directories 7 | node_modules/ 8 | jspm_packages/ 9 | 10 | # Logs 11 | logs 12 | *.log 13 | npm-debug.log* 14 | yarn-debug.log* 15 | yarn-error.log* 16 | 17 | # Optional npm cache directory 18 | .npm 19 | 20 | # Optional eslint cache 21 | .eslintcache 22 | 23 | # dotenv environment variables file 24 | .env 25 | 26 | # Testing 27 | coverage 28 | coverage.json 29 | 30 | # Typechain 31 | typechain 32 | typechain-types 33 | 34 | # Hardhat files 35 | cache 36 | `; 37 | }; 38 | -------------------------------------------------------------------------------- /examples/ethereum-gravatar/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract Migrations { 4 | address public owner; 5 | uint public last_completed_migration; 6 | 7 | constructor() public { 8 | owner = msg.sender; 9 | } 10 | 11 | modifier restricted() { 12 | if (msg.sender == owner) _; 13 | } 14 | 15 | function setCompleted(uint completed) public restricted { 16 | last_completed_migration = completed; 17 | } 18 | 19 | function upgrade(address new_address) public restricted { 20 | Migrations upgraded = Migrations(new_address); 21 | upgraded.setCompleted(last_completed_migration); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /packages/cli/src/command-helpers/retry.ts: -------------------------------------------------------------------------------- 1 | import { prompt } from 'gluegun'; 2 | 3 | export async function retryWithPrompt(func: () => Promise): Promise { 4 | for (;;) { 5 | try { 6 | return await func(); 7 | } catch (_) { 8 | try { 9 | const { retry } = await prompt.ask({ 10 | type: 'confirm', 11 | name: 'retry', 12 | message: 'Do you want to retry?', 13 | initial: true, 14 | }); 15 | 16 | if (!retry) { 17 | break; 18 | } 19 | } catch (_) { 20 | break; 21 | } 22 | } 23 | } 24 | return undefined; 25 | } 26 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/missing-entity-id/types/schema.ts: -------------------------------------------------------------------------------- 1 | import { 2 | TypedMap, 3 | Entity, 4 | Value, 5 | Address, 6 | Bytes, 7 | BigInt 8 | } from "@graphprotocol/graph-ts"; 9 | 10 | export class MyEntity extends Entity { 11 | get name(): string { 12 | let value = this.get("name"); 13 | if (value === null) { 14 | return null; 15 | } else { 16 | return value.toString() as string; 17 | } 18 | } 19 | 20 | set name(value: string) { 21 | if (value === null) { 22 | this.unset("name"); 23 | } else { 24 | this.set("name", Value.fromString(value as string)); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /packages/cli/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "./dist", 4 | "moduleResolution": "bundler", 5 | "module": "ESNext", 6 | "target": "ESNext", 7 | "strict": true, 8 | "noUnusedLocals": true, 9 | "noUnusedParameters": true, 10 | "esModuleInterop": true, 11 | "forceConsistentCasingInFileNames": true, 12 | "useUnknownInCatchVariables": false, 13 | "declaration": true, 14 | "skipLibCheck": true, 15 | "allowJs": true 16 | }, 17 | "ts-node": { 18 | "esm": true 19 | }, 20 | "include": ["./src", "./tests"], 21 | "exclude": ["./tests/cli/init", "./tests/cli/validation"] 22 | } 23 | -------------------------------------------------------------------------------- /examples/near-receipts/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.4 2 | description: Good Morning NEAR 3 | repository: https://github.com/graphprotocol/graph-toolings/tree/main/near/receipts-example 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: near 8 | name: receipts 9 | network: near-mainnet 10 | source: 11 | account: 'app.good-morning.near' 12 | startBlock: 50736511 13 | mapping: 14 | apiVersion: 0.0.6 15 | language: wasm/assemblyscript 16 | file: ./src/mapping.ts 17 | entities: 18 | - Greeter 19 | - Greeting 20 | receiptHandlers: 21 | - handler: handleReceipt 22 | -------------------------------------------------------------------------------- /packages/cli/src/protocols/ethereum/contract.ts: -------------------------------------------------------------------------------- 1 | import { Contract } from '../contract.js'; 2 | 3 | export default class EthereumContract implements Contract { 4 | static identifierName() { 5 | return 'address'; 6 | } 7 | 8 | constructor(private address: string) { 9 | this.address = address; 10 | } 11 | 12 | validate() { 13 | const pattern = /^(0x)?[0-9a-fA-F]{40}$/; 14 | 15 | const errorMessage = "Must be 40 hexadecimal characters, with an optional '0x' prefix."; 16 | 17 | const valid = pattern.test(this.address); 18 | 19 | return { 20 | valid, 21 | error: valid ? null : errorMessage, 22 | }; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/derived-from-with-interface/schema.graphql: -------------------------------------------------------------------------------- 1 | type Gravatar @entity(immutable: false) { 2 | id: ID! 3 | # This field points at an interface; we allow that a derived field 4 | # in a type that implements the interface derives from this field 5 | # The test checks that this construct is accepted 6 | owner: Account! 7 | imageUrl: String! 8 | } 9 | 10 | interface Account { 11 | id: ID! 12 | gravatars: [Gravatar!]! @derivedFrom(field: "owner") 13 | } 14 | 15 | type UserAccount implements Account @entity(immutable: true) { 16 | id: ID! 17 | name: String! 18 | gravatars: [Gravatar!]! @derivedFrom(field: "owner") 19 | } 20 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/init/ethereum/abis/Airdropped.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "anonymous": false, 4 | "inputs": [ 5 | { 6 | "indexed": false, 7 | "internalType": "address[]", 8 | "name": "to", 9 | "type": "address[]" 10 | }, 11 | { 12 | "indexed": false, 13 | "internalType": "uint256", 14 | "name": "quantity", 15 | "type": "uint256" 16 | }, 17 | { 18 | "indexed": false, 19 | "internalType": "uint256", 20 | "name": "fromTokenId", 21 | "type": "uint256" 22 | } 23 | ], 24 | "name": "Airdropped", 25 | "type": "event" 26 | } 27 | ] 28 | -------------------------------------------------------------------------------- /website/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 10 | 11 | 12 | Tooling | The Graph 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "type": "node", 6 | "request": "launch", 7 | "name": "Debug graph init", 8 | "skipFiles": ["/**"], 9 | "program": "${workspaceFolder}/packages/cli/bin/run", 10 | "args": ["init", "--skip-git"], 11 | "preLaunchTask": "build:dev", 12 | "outFiles": ["${workspaceFolder}/packages/cli/dist/**/*.js"], 13 | "sourceMaps": true, 14 | "resolveSourceMapLocations": ["${workspaceFolder}/**", "!**/node_modules/**"], 15 | "console": "integratedTerminal", 16 | "internalConsoleOptions": "neverOpen" 17 | } 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/missing-or-invalid-derived-from-fields.stderr: -------------------------------------------------------------------------------- 1 | - Load subgraph from subgraph.yaml 2 | ✖ Failed to load subgraph from subgraph.yaml: Error in schema.graphql: 3 | 4 | A: 5 | - Field 'b': @derivedFrom field 'a' does not exist on type 'B' 6 | - Field 'c': @derivedFrom field 'a' does not exist on type 'C' 7 | - Field 'd': @derivedFrom directive must have a 'field' argument 8 | - Field 'e': @derivedFrom directive must have a 'field' argument 9 | - Field 'f': Value of the @derivedFrom 'field' argument must be a string 10 | - Field 'g': @derivedFrom field 'a' on type 'G' must have the type 'A', 'A!', '[A!]!', or one of the interface types that 'A' implements 11 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/entity-field-args/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.1 2 | schema: 3 | file: ./schema.graphql 4 | dataSources: 5 | - kind: ethereum/contract 6 | name: ExampleSubgraph 7 | source: 8 | address: '22843e74c59580b3eaf6c233fa67d8b7c561a835' 9 | abi: ExampleContract 10 | mapping: 11 | kind: ethereum/events 12 | apiVersion: 0.0.5 13 | language: wasm/assemblyscript 14 | file: ./mapping.ts 15 | entities: 16 | - ExampleEntity 17 | abis: 18 | - name: ExampleContract 19 | file: ./Abi.json 20 | eventHandlers: 21 | - event: ExampleEvent(string) 22 | handler: handleExampleEvent 23 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/invalid-abis/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.1 2 | schema: 3 | file: ./schema.graphql 4 | dataSources: 5 | - kind: ethereum/contract 6 | name: ExampleSubgraph 7 | source: 8 | address: '22843e74c59580b3eaf6c233fa67d8b7c561a835' 9 | abi: ExampleContract 10 | mapping: 11 | kind: ethereum/events 12 | apiVersion: 0.0.5 13 | language: wasm/assemblyscript 14 | file: ./mapping.ts 15 | entities: 16 | - ExampleEntity 17 | abis: 18 | - name: ExampleContract 19 | file: ./InvalidAbi.json 20 | eventHandlers: 21 | - event: ExampleEvent(string) 22 | handler: handleExampleEvent 23 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/missing-entity-id/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.1 2 | schema: 3 | file: ./schema.graphql 4 | dataSources: 5 | - kind: ethereum/contract 6 | name: ExampleSubgraph 7 | source: 8 | address: '22843e74c59580b3eaf6c233fa67d8b7c561a835' 9 | abi: ExampleContract 10 | mapping: 11 | kind: ethereum/events 12 | apiVersion: 0.0.5 13 | language: wasm/assemblyscript 14 | file: ./mapping.ts 15 | entities: 16 | - ExampleEntity 17 | abis: 18 | - name: ExampleContract 19 | file: ./Abi.json 20 | eventHandlers: 21 | - event: ExampleEvent(string) 22 | handler: handleExampleEvent 23 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/call-function-not-found/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.1 2 | schema: 3 | file: ./schema.graphql 4 | dataSources: 5 | - kind: ethereum/contract 6 | name: ExampleSubgraph 7 | source: 8 | address: "22843e74c59580b3eaf6c233fa67d8b7c561a835" 9 | abi: ExampleContract 10 | mapping: 11 | kind: ethereum/events 12 | apiVersion: 0.0.5 13 | language: wasm/assemblyscript 14 | file: ./mapping.ts 15 | entities: 16 | - ExampleEntity 17 | abis: 18 | - name: ExampleContract 19 | file: ./Abi.json 20 | callHandlers: 21 | - function: doSomething(uint256) 22 | handler: handleDoSomething 23 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/invalid-graphql-schema/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.1 2 | schema: 3 | file: ./schema.graphql 4 | dataSources: 5 | - kind: ethereum/contract 6 | name: ExampleSubgraph 7 | source: 8 | address: '22843e74c59580b3eaf6c233fa67d8b7c561a835' 9 | abi: ExampleContract 10 | mapping: 11 | kind: ethereum/events 12 | apiVersion: 0.0.5 13 | language: wasm/assemblyscript 14 | file: ./mapping.ts 15 | entities: 16 | - ExampleEntity 17 | abis: 18 | - name: ExampleContract 19 | file: ./Abi.json 20 | eventHandlers: 21 | - event: ExampleEvent(string) 22 | handler: handleExampleEvent 23 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/invalid-manifest.stderr: -------------------------------------------------------------------------------- 1 | - Load subgraph from subgraph.yaml 2 | ✖ Failed to load subgraph from subgraph.yaml: Error in subgraph.yaml: 3 | 4 | Path: specVersion 5 | No value provided 6 | 7 | Path: schema > file 8 | File does not exist: non-existent.grapqhl 9 | 10 | Path: dataSources > 0 > name 11 | Expected string, found number: 12 | 5 13 | 14 | Path: dataSources > 0 > source 15 | No value provided 16 | 17 | Path: dataSources > 0 > mapping 18 | Expected map, found list: 19 | - 12 20 | - 13 21 | - 14 22 | 23 | Path: dataSources > 0 24 | Unexpected key in map: abis 25 | 26 | Path: templates 27 | Expected list, found map: 28 | field: foo 29 | -------------------------------------------------------------------------------- /packages/cli/src/command-helpers/node.ts: -------------------------------------------------------------------------------- 1 | import { URL } from 'node:url'; 2 | import { print } from 'gluegun'; 3 | 4 | export const SUBGRAPH_STUDIO_URL = 'https://api.studio.thegraph.com/deploy/'; 5 | 6 | export const validateNodeUrl = (node: string) => new URL(node); 7 | 8 | export const normalizeNodeUrl = (node: string) => new URL(node).toString(); 9 | 10 | export function chooseNodeUrl({ node }: { node?: string }) { 11 | if (node) { 12 | try { 13 | validateNodeUrl(node); 14 | return { node }; 15 | } catch (e) { 16 | print.error(`Graph node "${node}" is invalid: ${e.message}`); 17 | process.exit(1); 18 | } 19 | } 20 | 21 | return { node: SUBGRAPH_STUDIO_URL }; 22 | } 23 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/invalid-entity-field-types/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.1 2 | schema: 3 | file: ./schema.graphql 4 | dataSources: 5 | - kind: ethereum/contract 6 | name: ExampleSubgraph 7 | source: 8 | address: '22843e74c59580b3eaf6c233fa67d8b7c561a835' 9 | abi: ExampleContract 10 | mapping: 11 | kind: ethereum/events 12 | apiVersion: 0.0.5 13 | language: wasm/assemblyscript 14 | file: ./mapping.ts 15 | entities: 16 | - ExampleEntity 17 | abis: 18 | - name: ExampleContract 19 | file: ./Abi.json 20 | eventHandlers: 21 | - event: ExampleEvent(string) 22 | handler: handleExampleEvent 23 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/invalid-fulltext-directive/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.1 2 | schema: 3 | file: ./schema.graphql 4 | dataSources: 5 | - kind: ethereum/contract 6 | name: ExampleSubgraph 7 | source: 8 | address: '22843e74c59580b3eaf6c233fa67d8b7c561a835' 9 | abi: ExampleContract 10 | mapping: 11 | kind: ethereum/events 12 | apiVersion: 0.0.5 13 | language: wasm/assemblyscript 14 | file: ./mapping.ts 15 | entities: 16 | - ExampleEntity 17 | abis: 18 | - name: ExampleContract 19 | file: ./Abi.json 20 | eventHandlers: 21 | - event: ExampleEvent(string) 22 | handler: handleExampleEvent 23 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/derived-from-target-type-missing/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.1 2 | schema: 3 | file: ./schema.graphql 4 | dataSources: 5 | - kind: ethereum/contract 6 | name: ExampleSubgraph 7 | source: 8 | address: '22843e74c59580b3eaf6c233fa67d8b7c561a835' 9 | abi: ExampleContract 10 | mapping: 11 | kind: ethereum/events 12 | apiVersion: 0.0.5 13 | language: wasm/assemblyscript 14 | file: ./mapping.ts 15 | entities: 16 | - ExampleEntity 17 | abis: 18 | - name: ExampleContract 19 | file: ./Abi.json 20 | eventHandlers: 21 | - event: ExampleEvent(string) 22 | handler: handleExampleEvent 23 | -------------------------------------------------------------------------------- /packages/cli/src/protocols/subgraph/subgraph.ts: -------------------------------------------------------------------------------- 1 | import immutable from 'immutable'; 2 | import { Subgraph, SubgraphOptions } from '../subgraph'; 3 | 4 | export default class SubgraphDataSource implements Subgraph { 5 | public manifest: SubgraphOptions['manifest']; 6 | public resolveFile: SubgraphOptions['resolveFile']; 7 | public protocol: SubgraphOptions['protocol']; 8 | 9 | constructor(options: SubgraphOptions) { 10 | this.manifest = options.manifest; 11 | this.resolveFile = options.resolveFile; 12 | this.protocol = options.protocol; 13 | } 14 | 15 | validateManifest() { 16 | return immutable.List(); 17 | } 18 | 19 | handlerTypes() { 20 | return immutable.List([]); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/missing-or-invalid-derived-from-fields/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.1 2 | schema: 3 | file: ./schema.graphql 4 | dataSources: 5 | - kind: ethereum/contract 6 | name: DataSource 7 | source: 8 | address: '0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' 9 | abi: ExampleContract 10 | mapping: 11 | kind: ethereum/events 12 | apiVersion: 0.0.5 13 | language: wasm/assemblyscript 14 | file: ./mapping.ts 15 | entities: 16 | - ExampleEntity 17 | abis: 18 | - name: ExampleContract 19 | file: ./Abi.json 20 | eventHandlers: 21 | - event: ExampleEvent(string) 22 | handler: handleExampleEvent 23 | -------------------------------------------------------------------------------- /packages/cli/src/protocols/substreams/subgraph.ts: -------------------------------------------------------------------------------- 1 | import immutable from 'immutable'; 2 | import { Subgraph, SubgraphOptions } from '../subgraph.js'; 3 | 4 | export default class SubstreamsSubgraph implements Subgraph { 5 | public manifest: SubgraphOptions['manifest']; 6 | public resolveFile: SubgraphOptions['resolveFile']; 7 | public protocol: SubgraphOptions['protocol']; 8 | 9 | constructor(options: SubgraphOptions) { 10 | this.manifest = options.manifest; 11 | this.resolveFile = options.resolveFile; 12 | this.protocol = options.protocol; 13 | } 14 | 15 | validateManifest() { 16 | return immutable.List(); 17 | } 18 | 19 | handlerTypes() { 20 | return immutable.List([]); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/example-subgraph/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example-event-handler", 3 | "repository": { 4 | "type": "git", 5 | "url": "https://github.com/graphprotocol/graph-tooling", 6 | "directory": "examples/example-subgraph" 7 | }, 8 | "private": true, 9 | "scripts": { 10 | "build": "../../packages/cli/bin/run.js build subgraph.yaml", 11 | "build-ipfs": "../../packages/cli/bin/run.js build --ipfs /ip4/127.0.0.1/tcp/5001 subgraph.yaml", 12 | "build-wast": "../../packages/cli/bin/run.js build -t wast subgraph.yaml", 13 | "codegen": "../../packages/cli/bin/run.js codegen --output-dir src/types/ subgraph.yaml" 14 | }, 15 | "devDependencies": { 16 | "@graphprotocol/graph-ts": "0.35.1" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/cli/src/protocols/arweave/subgraph.ts: -------------------------------------------------------------------------------- 1 | import immutable from 'immutable'; 2 | import { Subgraph, SubgraphOptions } from '../subgraph.js'; 3 | 4 | export default class ArweaveSubgraph implements Subgraph { 5 | manifest: SubgraphOptions['manifest']; 6 | resolveFile: SubgraphOptions['resolveFile']; 7 | protocol: SubgraphOptions['protocol']; 8 | 9 | constructor(options: SubgraphOptions) { 10 | this.manifest = options.manifest; 11 | this.resolveFile = options.resolveFile; 12 | this.protocol = options.protocol; 13 | } 14 | 15 | validateManifest() { 16 | return immutable.List(); 17 | } 18 | 19 | handlerTypes() { 20 | return immutable.List(['blockHandlers', 'transactionHandlers']); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/2d-array-is-valid/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.1 2 | repository: https://github.com/graphprotocol/test-subgraph 3 | description: Test subgraph 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: ethereum/contract 8 | name: ExampleSubgraph 9 | source: 10 | abi: ExampleContract 11 | mapping: 12 | kind: ethereum/events 13 | apiVersion: 0.0.5 14 | language: wasm/assemblyscript 15 | file: ./mapping.ts 16 | entities: 17 | - ExampleEntity 18 | abis: 19 | - name: ExampleContract 20 | file: ./Abi.json 21 | eventHandlers: 22 | - event: ExampleEvent(string) 23 | handler: handleExampleEvent 24 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/3d-array-is-valid/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.1 2 | repository: https://github.com/graphprotocol/test-subgraph 3 | description: Test subgraph 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: ethereum/contract 8 | name: ExampleSubgraph 9 | source: 10 | abi: ExampleContract 11 | mapping: 12 | kind: ethereum/events 13 | apiVersion: 0.0.5 14 | language: wasm/assemblyscript 15 | file: ./mapping.ts 16 | entities: 17 | - ExampleEntity 18 | abis: 19 | - name: ExampleContract 20 | file: ./Abi.json 21 | eventHandlers: 22 | - event: ExampleEvent(string) 23 | handler: handleExampleEvent 24 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/big-decimal-is-valid/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.1 2 | repository: https://github.com/graphprotocol/test-subgraph 3 | description: Test subgraph 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: ethereum/contract 8 | name: ExampleSubgraph 9 | source: 10 | abi: ExampleContract 11 | mapping: 12 | kind: ethereum/events 13 | apiVersion: 0.0.5 14 | language: wasm/assemblyscript 15 | file: ./mapping.ts 16 | entities: 17 | - ExampleEntity 18 | abis: 19 | - name: ExampleContract 20 | file: ./Abi.json 21 | eventHandlers: 22 | - event: ExampleEvent(string) 23 | handler: handleExampleEvent 24 | -------------------------------------------------------------------------------- /website/src/components/editor.tsx: -------------------------------------------------------------------------------- 1 | import MonacoEditor from '@monaco-editor/react'; 2 | 3 | export function Editor({ value }: { value: string }) { 4 | return ( 5 | { 16 | monaco.editor.defineTheme('graph-cli', { 17 | base: 'hc-black', 18 | inherit: false, 19 | rules: [], 20 | colors: { 21 | 'editor.background': '#FFFFFF', 22 | }, 23 | }); 24 | }} 25 | /> 26 | ); 27 | } 28 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/call-handler-with-tuple/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.2 2 | schema: 3 | file: ./schema.graphql 4 | dataSources: 5 | - kind: ethereum/contract 6 | name: ExampleSubgraph 7 | source: 8 | address: '22843e74c59580b3eaf6c233fa67d8b7c561a835' 9 | abi: ExampleContract 10 | mapping: 11 | kind: ethereum/events 12 | apiVersion: 0.0.5 13 | language: wasm/assemblyscript 14 | file: ./mapping.ts 15 | entities: 16 | - ExampleEntity 17 | abis: 18 | - name: ExampleContract 19 | file: ./Abi.json 20 | callHandlers: 21 | - function: doSomething(uint256,(bytes32,bytes32,uint256),bool) 22 | handler: handleDoSomething 23 | -------------------------------------------------------------------------------- /packages/cli/src/protocols/near/subgraph.ts: -------------------------------------------------------------------------------- 1 | import immutable from 'immutable'; 2 | import { Subgraph, SubgraphOptions } from '../subgraph.js'; 3 | 4 | export default class NearSubgraph implements Subgraph { 5 | public manifest: SubgraphOptions['manifest']; 6 | public resolveFile: SubgraphOptions['resolveFile']; 7 | public protocol: SubgraphOptions['protocol']; 8 | 9 | constructor(options: SubgraphOptions) { 10 | this.manifest = options.manifest; 11 | this.resolveFile = options.resolveFile; 12 | this.protocol = options.protocol; 13 | } 14 | 15 | validateManifest() { 16 | return immutable.List(); 17 | } 18 | 19 | handlerTypes() { 20 | return immutable.List(['blockHandlers', 'receiptHandlers']); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/source-without-address-is-valid/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.1 2 | repository: https://github.com/graphprotocol/test-subgraph 3 | description: Test subgraph 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: ethereum/contract 8 | name: ExampleSubgraph 9 | source: 10 | abi: ExampleContract 11 | mapping: 12 | kind: ethereum/events 13 | apiVersion: 0.0.5 14 | language: wasm/assemblyscript 15 | file: ./mapping.ts 16 | entities: 17 | - ExampleEntity 18 | abis: 19 | - name: ExampleContract 20 | file: ./Abi.json 21 | eventHandlers: 22 | - event: ExampleEvent(string) 23 | handler: handleExampleEvent 24 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/require-immutable-argument/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.1 2 | schema: 3 | file: ./schema.graphql 4 | dataSources: 5 | - kind: ethereum/contract 6 | name: ExampleContract 7 | source: 8 | address: '22843e74c59580b3eaf6c233fa67d8b7c561a835' 9 | abi: ExampleEvent 10 | mapping: 11 | kind: ethereum/events 12 | apiVersion: 0.0.5 13 | language: wasm/assemblyscript 14 | file: ./mapping.ts 15 | entities: 16 | - EntityA 17 | - EntityB 18 | - EntityC 19 | - EntityD 20 | abis: 21 | - name: ExampleEvent 22 | file: ./Abi.json 23 | eventHandlers: 24 | - event: ExampleEvent(string) 25 | handler: handleExampleEvent 26 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/invalid-contract-addresses.stderr: -------------------------------------------------------------------------------- 1 | - Load subgraph from subgraph.yaml 2 | ✖ Failed to load subgraph from subgraph.yaml: Error in subgraph.yaml: 3 | 4 | Path: dataSources > 0 > source > address 5 | Contract address is invalid: 22843e74c59580b3eaf6c233fa67d8b7c561a835a 6 | Must be 40 hexadecimal characters, with an optional '0x' prefix. 7 | 8 | Path: dataSources > 1 > source > address 9 | Contract address is invalid: 22843e74c59580b3eaf6c233fa67d8b7c561axyz 10 | Must be 40 hexadecimal characters, with an optional '0x' prefix. 11 | 12 | Path: dataSources > 2 > source > address 13 | Contract address is invalid: 0x22843e74c59580b3eaf6c233fa67d8b7c561a835a 14 | Must be 40 hexadecimal characters, with an optional '0x' prefix. 15 | -------------------------------------------------------------------------------- /website/src/components/ui/label.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { cva, type VariantProps } from 'class-variance-authority'; 3 | import { cn } from '@/lib/utils'; 4 | import * as LabelPrimitive from '@radix-ui/react-label'; 5 | 6 | const labelVariants = cva( 7 | 'text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70', 8 | ); 9 | 10 | const Label = React.forwardRef< 11 | React.ElementRef, 12 | React.ComponentPropsWithoutRef & VariantProps 13 | >(({ className, ...props }, ref) => ( 14 | 15 | )); 16 | Label.displayName = LabelPrimitive.Root.displayName; 17 | 18 | export { Label }; 19 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/example-values-found/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.1 2 | repository: https://github.com/graphprotocol/graph-tooling 3 | description: Gravatar for Ethereum 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: ethereum/contract 8 | name: ExampleSubgraph 9 | source: 10 | address: '22843e74c59580b3eaf6c233fa67d8b7c561a835' 11 | abi: ExampleContract 12 | mapping: 13 | kind: ethereum/events 14 | apiVersion: 0.0.5 15 | language: wasm/assemblyscript 16 | file: ./mapping.ts 17 | entities: 18 | - ExampleEntity 19 | abis: 20 | - name: ExampleContract 21 | file: ./Abi.json 22 | eventHandlers: 23 | - event: ExampleEvent(string) 24 | handler: handleExampleEvent 25 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/topic0-is-valid/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.1 2 | repository: https://github.com/graphprotocol/test-subgraph 3 | description: Test subgraph 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: ethereum/contract 8 | name: ExampleSubgraph 9 | source: 10 | abi: ExampleContract 11 | mapping: 12 | kind: ethereum/events 13 | apiVersion: 0.0.5 14 | language: wasm/assemblyscript 15 | file: ./mapping.ts 16 | entities: 17 | - ExampleEntity 18 | abis: 19 | - name: ExampleContract 20 | file: ./Abi.json 21 | eventHandlers: 22 | - event: ExampleEvent(string) 23 | topic0: b74a38eb2ebca56512a2bb0283f335555a4a4dac46ab998d65fd76f9027dca70 24 | handler: handleExampleEvent 25 | -------------------------------------------------------------------------------- /packages/cli/src/protocols/cosmos/subgraph.ts: -------------------------------------------------------------------------------- 1 | import immutable from 'immutable'; 2 | import { Subgraph, SubgraphOptions } from '../subgraph.js'; 3 | 4 | export default class CosmosSubgraph implements Subgraph { 5 | manifest: SubgraphOptions['manifest']; 6 | resolveFile: SubgraphOptions['resolveFile']; 7 | protocol: SubgraphOptions['protocol']; 8 | 9 | constructor(options: SubgraphOptions) { 10 | this.manifest = options.manifest; 11 | this.resolveFile = options.resolveFile; 12 | this.protocol = options.protocol; 13 | } 14 | 15 | validateManifest() { 16 | return immutable.List(); 17 | } 18 | 19 | handlerTypes() { 20 | return immutable.List([ 21 | 'blockHandlers', 22 | 'eventHandlers', 23 | 'transactionHandlers', 24 | 'messageHandlers', 25 | ]); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /examples/substreams-powered-subgraph/README.md: -------------------------------------------------------------------------------- 1 | # Substreams-powered subgraph: tracking contract creation 2 | 3 | A basic Substreams-powered subgraph, including the Substreams definition. This example detects new 4 | contract deployments on Ethereum, tracking the creation block and timestamp. There is a 5 | demonstration of the Graph Node integration, using `substreams_entity_change` types and helpers. 6 | 7 | ## Prerequisites 8 | 9 | This 10 | [requires the dependencies necessary for local Substreams development](https://substreams.streamingfast.io/developers-guide/installation-requirements). 11 | 12 | ## Quickstart 13 | 14 | ``` 15 | yarn install # install graph-cli 16 | yarn substreams:prepare # build and package the substreams module 17 | yarn subgraph:build # build the subgraph 18 | yarn deploy # deploy the subgraph 19 | ``` 20 | -------------------------------------------------------------------------------- /website/src/components/ui/textarea.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { cn } from '@/lib/utils'; 3 | 4 | type TextareaProps = React.TextareaHTMLAttributes; 5 | 6 | const Textarea = React.forwardRef( 7 | ({ className, ...props }, ref) => { 8 | return ( 9 | 17 | ); 18 | }, 19 | ); 20 | Textarea.displayName = 'Textarea'; 21 | 22 | export { Textarea }; 23 | -------------------------------------------------------------------------------- /packages/cli/src/scaffold/cosmos.test.ts: -------------------------------------------------------------------------------- 1 | import { describe, expect, test } from 'vitest'; 2 | import Protocol from '../protocols/index.js'; 3 | import Scaffold from './index.js'; 4 | 5 | const protocol = new Protocol('cosmos'); 6 | 7 | const scaffoldOptions = { 8 | protocol, 9 | network: 'cosmoshub-4', 10 | contractName: 'CosmosHub', 11 | }; 12 | 13 | const scaffold = new Scaffold(scaffoldOptions); 14 | 15 | describe('Cosmos subgraph scaffolding', () => { 16 | test('Manifest', async () => { 17 | expect(await scaffold.generateManifest()).toMatchSnapshot(); 18 | }); 19 | 20 | test('Schema (default)', async () => { 21 | expect(await scaffold.generateSchema()).toMatchSnapshot(); 22 | }); 23 | 24 | test('Mapping (default)', async () => { 25 | expect(await scaffold.generateMapping()).toMatchSnapshot(); 26 | }); 27 | }); 28 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/block-handler-filters/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.1 2 | schema: 3 | file: ./schema.graphql 4 | dataSources: 5 | - kind: ethereum/contract 6 | name: DataSource 7 | source: 8 | address: '0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' 9 | abi: ExampleContract 10 | mapping: 11 | kind: ethereum/events 12 | apiVersion: 0.0.5 13 | language: wasm/assemblyscript 14 | file: ./mapping.ts 15 | entities: 16 | - A 17 | abis: 18 | - name: ExampleContract 19 | file: ./Abi.json 20 | blockHandlers: 21 | - handler: handleBlock0 22 | - handler: handleBlock1 23 | filter: 24 | kind: polling 25 | every: 2 26 | - handler: handleBlock2 27 | filter: 28 | kind: once 29 | 30 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/derived-from-with-interface/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.2 2 | schema: 3 | file: ./schema.graphql 4 | dataSources: 5 | - kind: ethereum/contract 6 | name: Gravity 7 | network: mainnet 8 | source: 9 | address: '0x2E645469f354BB4F5c8a05B3b30A929361cf77eC' 10 | abi: Gravity 11 | mapping: 12 | kind: ethereum/events 13 | apiVersion: 0.0.5 14 | language: wasm/assemblyscript 15 | entities: 16 | - Gravatar 17 | abis: 18 | - name: Gravity 19 | file: ./Gravity.json 20 | eventHandlers: 21 | - event: NewGravatar(uint256,address,string,string) 22 | handler: handleNewGravatar 23 | - event: UpdatedGravatar(uint256,address,string,string) 24 | handler: handleUpdatedGravatar 25 | file: ./mapping.ts 26 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/indexer-hints/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.1 2 | repository: https://github.com/graphprotocol/test-subgraph 3 | description: Test subgraph 4 | schema: 5 | file: ./schema.graphql 6 | indexerHints: 7 | prune: 100 8 | dataSources: 9 | - kind: ethereum/contract 10 | name: ExampleSubgraph 11 | source: 12 | abi: ExampleContract 13 | mapping: 14 | kind: ethereum/events 15 | apiVersion: 0.0.5 16 | language: wasm/assemblyscript 17 | file: ./mapping.ts 18 | entities: 19 | - ExampleEntity 20 | abis: 21 | - name: ExampleContract 22 | file: ./Abi.json 23 | eventHandlers: 24 | - event: ExampleEvent(string) 25 | topic0: b74a38eb2ebca56512a2bb0283f335555a4a4dac46ab998d65fd76f9027dca70 26 | handler: handleExampleEvent 27 | -------------------------------------------------------------------------------- /packages/cli/src/command-helpers/jsonrpc.ts: -------------------------------------------------------------------------------- 1 | import { print } from 'gluegun'; 2 | import jayson from 'jayson'; 3 | 4 | export function createJsonRpcClient(url: URL): jayson.Client | null { 5 | const params = { 6 | host: url.hostname, 7 | port: url.port, 8 | path: url.pathname, 9 | // username may be empty 10 | auth: url.password ? `${url.username}:${url.password}` : undefined, 11 | timeout: 120_000, // 120 seconds 12 | }; 13 | 14 | if (url.protocol === 'https:') { 15 | return jayson.Client.https(params); 16 | } 17 | if (url.protocol === 'http:') { 18 | return jayson.Client.http(params); 19 | } 20 | print.error(`Unsupported protocol: ${url.protocol.substring(0, url.protocol.length - 1)}`); 21 | print.error('The Graph Node URL must be of the following format: http(s)://host[:port]/[path]'); 22 | return null; 23 | } 24 | -------------------------------------------------------------------------------- /examples/example-subgraph/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.5 2 | description: 'example of a subgraph' 3 | repository: https://github.com/graphprotocol/graph-tooling.git 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: ethereum/contract 8 | name: ExampleSubgraph 9 | network: mainnet 10 | source: 11 | address: '0x22843e74c59580b3eaf6c233fa67d8b7c561a835' 12 | abi: ExampleContract 13 | mapping: 14 | kind: ethereum/events 15 | apiVersion: 0.0.7 16 | language: wasm/assemblyscript 17 | file: ./src/mapping.ts 18 | entities: 19 | - ExampleEntity 20 | - OtherEntity 21 | abis: 22 | - name: ExampleContract 23 | file: ./abis/ExampleContract.json 24 | eventHandlers: 25 | - event: ExampleEvent(indexed string) 26 | handler: handleExampleEvent 27 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/missing-or-invalid-derived-from-fields/schema.graphql: -------------------------------------------------------------------------------- 1 | type A @entity(immutable: true) { 2 | id: ID! 3 | b: B @derivedFrom(field: "a") 4 | c: [C!]! @derivedFrom(field: "a") 5 | d: D @derivedFrom 6 | e: E @derivedFrom(attr: "a") 7 | f: F @derivedFrom(field: 123) 8 | g: G @derivedFrom(field: "a") 9 | h: H @derivedFrom(field: "a") 10 | } 11 | 12 | type B @entity(immutable: true) { 13 | id: ID! 14 | } 15 | 16 | type C @entity(immutable: true) { 17 | id: ID! 18 | } 19 | 20 | type D @entity(immutable: true) { 21 | id: ID! 22 | } 23 | 24 | type E @entity(immutable: true) { 25 | id: ID! 26 | } 27 | 28 | type F @entity(immutable: true) { 29 | id: ID! 30 | } 31 | 32 | type G @entity(immutable: true) { 33 | id: ID! 34 | a: BigInt 35 | } 36 | 37 | type H @entity(immutable: true) { 38 | id: ID! 39 | a: A! 40 | } 41 | -------------------------------------------------------------------------------- /packages/cli/src/scaffold/near.test.ts: -------------------------------------------------------------------------------- 1 | import { describe, expect, test } from 'vitest'; 2 | import Protocol from '../protocols/index.js'; 3 | import Scaffold from './index.js'; 4 | 5 | const protocol = new Protocol('near'); 6 | 7 | const scaffoldOptions = { 8 | protocol, 9 | contract: 'abc.def.near', 10 | network: 'near-mainnet', 11 | contractName: 'Contract', 12 | }; 13 | 14 | const scaffold = new Scaffold(scaffoldOptions); 15 | 16 | describe('NEAR subgraph scaffolding', () => { 17 | test('Manifest', async () => { 18 | expect(await scaffold.generateManifest()).toMatchSnapshot(); 19 | }); 20 | 21 | test('Schema (default)', async () => { 22 | expect(await scaffold.generateSchema()).toMatchSnapshot(); 23 | }); 24 | 25 | test('Mapping (default)', async () => { 26 | expect(await scaffold.generateMapping()).toMatchSnapshot(); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /examples/ethereum-gravatar/src/mapping.ts: -------------------------------------------------------------------------------- 1 | import { NewGravatar, UpdatedGravatar } from '../generated/Gravity/Gravity'; 2 | import { Gravatar } from '../generated/schema'; 3 | 4 | export function handleNewGravatar(event: NewGravatar): void { 5 | let gravatar = new Gravatar(event.params.id.toHex()); 6 | gravatar.owner = event.params.owner; 7 | gravatar.displayName = event.params.displayName; 8 | gravatar.imageUrl = event.params.imageUrl; 9 | gravatar.save(); 10 | } 11 | 12 | export function handleUpdatedGravatar(event: UpdatedGravatar): void { 13 | let id = event.params.id.toHex(); 14 | let gravatar = Gravatar.load(id); 15 | if (gravatar == null) { 16 | gravatar = new Gravatar(id); 17 | } 18 | gravatar.owner = event.params.owner; 19 | gravatar.displayName = event.params.displayName; 20 | gravatar.imageUrl = event.params.imageUrl; 21 | gravatar.save(); 22 | } 23 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/near-is-valid/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.1 2 | repository: https://github.com/graphprotocol/near-subgraph 3 | description: NEAR subgraph 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: near 8 | name: NearSubgraph 9 | network: near-mainnet 10 | source: 11 | account: wnear.flux-dev 12 | startBlock: 1 13 | accounts: 14 | prefixes: 15 | - some-prefix 16 | - a-prefix.with-dot 17 | suffixes: 18 | - suffix.near 19 | - near 20 | - another-suffix.testnet 21 | mapping: 22 | apiVersion: 0.0.5 23 | language: wasm/assemblyscript 24 | file: ./mapping.ts 25 | entities: 26 | - ExampleEntity 27 | blockHandlers: 28 | - handler: handleNewBlock 29 | receiptHandlers: 30 | - handler: handleReceipt 31 | -------------------------------------------------------------------------------- /examples/example-subgraph/dist/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.5 2 | description: example of a subgraph 3 | repository: 'https://github.com/graphprotocol/graph-cli.git' 4 | schema: 5 | file: schema.graphql 6 | dataSources: 7 | - kind: ethereum/contract 8 | name: ExampleSubgraph 9 | network: mainnet 10 | source: 11 | address: '0x22843e74c59580b3eaf6c233fa67d8b7c561a835' 12 | abi: ExampleContract 13 | mapping: 14 | kind: ethereum/events 15 | apiVersion: 0.0.7 16 | language: wasm/assemblyscript 17 | file: ExampleSubgraph/ExampleSubgraph.wasm 18 | entities: 19 | - ExampleEntity 20 | - OtherEntity 21 | abis: 22 | - name: ExampleContract 23 | file: ExampleSubgraph/abis/ExampleContract.json 24 | eventHandlers: 25 | - event: ExampleEvent(indexed string) 26 | handler: handleExampleEvent 27 | -------------------------------------------------------------------------------- /packages/cli/src/protocols/subgraph/scaffold/manifest.ts: -------------------------------------------------------------------------------- 1 | import { strings } from 'gluegun'; 2 | 3 | export const source = ({ 4 | contract, 5 | startBlock, 6 | }: { 7 | contract: string; 8 | contractName: string; 9 | startBlock: string; 10 | }) => 11 | ` 12 | address: '${contract}' 13 | startBlock: ${startBlock}`; 14 | 15 | export const mapping = ({ 16 | entities, 17 | contractName, 18 | }: { 19 | entities: string[]; 20 | contractName: string; 21 | }) => ` 22 | kind: ethereum/events 23 | apiVersion: 0.0.9 24 | language: wasm/assemblyscript 25 | entities: 26 | - ExampleEntity 27 | handlers: 28 | ${entities 29 | .map( 30 | entity => ` 31 | - handler: handle${entity} 32 | entity: ${entity}`, 33 | ) 34 | .join(' ')} 35 | file: ./src/${strings.kebabCase(contractName)}.ts 36 | `; 37 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/derived-from-with-interface/mapping.ts: -------------------------------------------------------------------------------- 1 | import { NewGravatar, UpdatedGravatar } from '../generated/Gravity/Gravity' 2 | import { Gravatar } from '../generated/schema' 3 | 4 | export function handleNewGravatar(event: NewGravatar): void { 5 | let gravatar = new Gravatar(event.params.id.toHex()) 6 | gravatar.owner = event.params.owner 7 | gravatar.displayName = event.params.displayName 8 | gravatar.imageUrl = event.params.imageUrl 9 | gravatar.save() 10 | } 11 | 12 | export function handleUpdatedGravatar(event: UpdatedGravatar): void { 13 | let id = event.params.id.toHex() 14 | let gravatar = Gravatar.load(id) 15 | if (gravatar == null) { 16 | gravatar = new Gravatar(id) 17 | } 18 | gravatar.owner = event.params.owner 19 | gravatar.displayName = event.params.displayName 20 | gravatar.imageUrl = event.params.imageUrl 21 | gravatar.save() 22 | } 23 | -------------------------------------------------------------------------------- /packages/ts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@graphprotocol/graph-ts", 3 | "version": "0.38.2", 4 | "description": "TypeScript/AssemblyScript library for writing subgraph mappings for The Graph", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/graphprotocol/graph-tooling.git", 8 | "directory": "packages/ts" 9 | }, 10 | "main": "index.ts", 11 | "module": "index.ts", 12 | "types": "index.ts", 13 | "scripts": { 14 | "build": "asc --exportRuntime --runtime stub index.ts helper-functions.ts --lib graph-ts -o index.wasm --disableWarning 235", 15 | "format": "prettier --write -c **/*.{js,mjs,ts}", 16 | "lint": "prettier -c **/*.{js,mjs,ts}", 17 | "test": "node test/test.mjs" 18 | }, 19 | "dependencies": { 20 | "assemblyscript": "0.27.31" 21 | }, 22 | "publishConfig": { 23 | "access": "public", 24 | "provenance": true 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /website/src/components/ui/toaster.tsx: -------------------------------------------------------------------------------- 1 | import { 2 | Toast, 3 | ToastClose, 4 | ToastDescription, 5 | ToastProvider, 6 | ToastTitle, 7 | ToastViewport, 8 | } from '@/components/ui/toast'; 9 | import { useToast } from '@/components/ui/use-toast'; 10 | 11 | export function Toaster() { 12 | const { toasts } = useToast(); 13 | 14 | return ( 15 | 16 | {toasts.map(({ id, title, description, action, ...props }) => { 17 | return ( 18 | 19 | 20 | {title && {title}} 21 | {description && {description}} 22 | 23 | {action} 24 | 25 | 26 | ); 27 | })} 28 | 29 | 30 | ); 31 | } 32 | -------------------------------------------------------------------------------- /website/src/lib/graphql.ts: -------------------------------------------------------------------------------- 1 | import { print } from 'graphql'; 2 | import { TypedDocumentNode } from '@graphql-typed-document-node/core'; 3 | 4 | export const NETWORK_SUBGRAPH_MAINNET = 5 | 'https://gateway.thegraph.com/api/{api-key}/subgraphs/id/DZz4kDTdmzWLWsV373w2bSmoar3umKKH9y82SUKr5qmp'; 6 | export const NETWORK_SUBGRAPH_SEPOLIA = 7 | 'https://gateway.thegraph.com/api/{api-key}/subgraphs/id/3xQHhMudr1oh69ut36G2mbzpYmYxwqCeU6wwqyCDCnqV'; 8 | 9 | export async function networkSubgraphExecute( 10 | query: TypedDocumentNode, 11 | variables: V, 12 | endpoint: string, 13 | apiKey: string, 14 | ) { 15 | const response = await fetch(endpoint.replace('{api-key}', apiKey), { 16 | method: 'POST', 17 | body: JSON.stringify({ 18 | query: print(query), 19 | variables, 20 | }), 21 | }); 22 | const result = await response.json(); 23 | return result.data as T; 24 | } 25 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/invalid-data-source-template.stderr: -------------------------------------------------------------------------------- 1 | - Load subgraph from subgraph.yaml 2 | ✖ Failed to load subgraph from subgraph.yaml: Error in subgraph.yaml: 3 | 4 | Path: dataSources > 0 > mapping > abis > 0 > file 5 | File does not exist: Abi.json 6 | 7 | Path: templates > 0 > kind 8 | No value provided 9 | 10 | Path: templates > 0 > name 11 | Expected string, found number: 12 | 5 13 | 14 | Path: templates > 0 > source 15 | Unexpected key in map: address 16 | 17 | Path: templates > 0 > mapping > entities 18 | No value provided 19 | 20 | Path: templates > 0 > mapping > abis > 0 > file 21 | File does not exist: NonexistentAbi.json 22 | 23 | Path: templates > 0 > mapping > language 24 | No value provided 25 | 26 | Path: templates > 0 > mapping > file 27 | No value provided 28 | 29 | Path: templates > 0 > mapping > apiVersion 30 | No value provided 31 | -------------------------------------------------------------------------------- /website/src/components/ui/input.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { cn } from '@/lib/utils'; 3 | 4 | type InputProps = React.InputHTMLAttributes; 5 | 6 | const Input = React.forwardRef( 7 | ({ className, type, ...props }, ref) => { 8 | return ( 9 | 18 | ); 19 | }, 20 | ); 21 | Input.displayName = 'Input'; 22 | 23 | export { Input }; 24 | -------------------------------------------------------------------------------- /examples/matic-lens-protocol-posts-subgraph/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example-lens-protocol-posts-sg", 3 | "version": "0.0.1", 4 | "license": "UNLICENSED", 5 | "private": true, 6 | "scripts": { 7 | "build": "graph build", 8 | "codegen": "graph codegen", 9 | "create-local": "graph create --node http://localhost:8020/ lens-protocol-posts-sg", 10 | "deploy": "graph deploy --node https://api.studio.thegraph.com/deploy/ lens-protocol-posts-sg", 11 | "deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 lens-protocol-posts-sg", 12 | "remove-local": "graph remove --node http://localhost:8020/ lens-protocol-posts-sg", 13 | "test": "graph test" 14 | }, 15 | "dependencies": { 16 | "@graphprotocol/graph-cli": "0.90.1", 17 | "@graphprotocol/graph-ts": "0.35.1" 18 | }, 19 | "devDependencies": { 20 | "matchstick-as": "0.6.0" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/missing-entity-id/types/ExampleSubgraph/ExampleContract.ts: -------------------------------------------------------------------------------- 1 | import { 2 | EthereumEvent, 3 | SmartContract, 4 | EthereumValue, 5 | JSONValue, 6 | TypedMap, 7 | Entity, 8 | Bytes, 9 | Address, 10 | BigInt 11 | } from "@graphprotocol/graph-ts"; 12 | 13 | export class ExampleEvent extends EthereumEvent { 14 | get params(): ExampleEventParams { 15 | return new ExampleEventParams(this); 16 | } 17 | } 18 | 19 | export class ExampleEventParams { 20 | _event: ExampleEvent; 21 | 22 | constructor(event: ExampleEvent) { 23 | this._event = event; 24 | } 25 | 26 | get param0(): string { 27 | return this._event.parameters[0].value.toString(); 28 | } 29 | } 30 | 31 | export class ExampleContract extends SmartContract { 32 | static bind(address: Address): ExampleContract { 33 | return new ExampleContract("ExampleContract", address); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /examples/near-blocks/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example-near-blocks", 3 | "version": "0.1.0", 4 | "repository": { 5 | "type": "git", 6 | "url": "https://github.com/graphprotocol/graph-tooling", 7 | "directory": "examples/near-blocks" 8 | }, 9 | "license": "MIT", 10 | "private": true, 11 | "scripts": { 12 | "build": "graph build", 13 | "codegen": "graph codegen", 14 | "create": "graph create example --node https://api.studio.thegraph.com/deploy/", 15 | "create-local": "graph create example --node http://127.0.0.1:8020", 16 | "deploy": "graph deploy example --ipfs https://api.thegraph.com/ipfs/ --node https://api.studio.thegraph.com/deploy/", 17 | "deploy-local": "graph deploy example --ipfs http://localhost:5001 --node http://127.0.0.1:8020" 18 | }, 19 | "devDependencies": { 20 | "@graphprotocol/graph-cli": "0.90.1", 21 | "@graphprotocol/graph-ts": "0.35.1" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/near-receipts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example-near-receipts", 3 | "version": "0.1.0", 4 | "repository": { 5 | "type": "git", 6 | "url": "https://github.com/graphprotocol/graph-tooling", 7 | "directory": "examples/near-receipts" 8 | }, 9 | "license": "MIT", 10 | "private": true, 11 | "scripts": { 12 | "build": "graph build", 13 | "codegen": "graph codegen", 14 | "create": "graph create example --node https://api.studio.thegraph.com/deploy/", 15 | "create-local": "graph create example --node http://127.0.0.1:8020", 16 | "deploy": "graph deploy example --ipfs https://api.thegraph.com/ipfs/ --node https://api.studio.thegraph.com/deploy/", 17 | "deploy-local": "graph deploy example --ipfs http://localhost:5001 --node http://127.0.0.1:8020" 18 | }, 19 | "devDependencies": { 20 | "@graphprotocol/graph-cli": "0.90.1", 21 | "@graphprotocol/graph-ts": "0.35.1" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /packages/ts/common/json.ts: -------------------------------------------------------------------------------- 1 | import './eager-offset'; 2 | import { Bytes, Result } from './collections'; 3 | import { BigInt } from './numbers'; 4 | import { JSONValue } from './value'; 5 | 6 | /** Host JSON interface */ 7 | export declare namespace json { 8 | function fromBytes(data: Bytes): JSONValue; 9 | function try_fromBytes(data: Bytes): Result; 10 | function toI64(decimal: string): i64; 11 | function toU64(decimal: string): u64; 12 | function toF64(decimal: string): f64; 13 | function toBigInt(decimal: string): BigInt; 14 | } 15 | 16 | export namespace json { 17 | export function fromString(data: string): JSONValue { 18 | const bytes = Bytes.fromUTF8(data); 19 | 20 | return json.fromBytes(bytes); 21 | } 22 | 23 | export function try_fromString(data: string): Result { 24 | const bytes = Bytes.fromUTF8(data); 25 | 26 | return json.try_fromBytes(bytes); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /examples/ethereum-basic-event-handlers/build/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.5 2 | description: Gravatar for Ethereum 3 | repository: https://github.com/graphprotocol/graph-tooling 4 | schema: 5 | file: schema.graphql 6 | dataSources: 7 | - kind: ethereum/contract 8 | name: Gravity 9 | network: test 10 | source: 11 | address: "0x5FbDB2315678afecb367f032d93F642f64180aa3" 12 | abi: Gravity 13 | mapping: 14 | kind: ethereum/events 15 | apiVersion: 0.0.7 16 | language: wasm/assemblyscript 17 | entities: 18 | - Gravatar 19 | abis: 20 | - name: Gravity 21 | file: Gravity/GravatarRegistry.json 22 | eventHandlers: 23 | - event: NewGravatar(uint256,address,string,string) 24 | handler: handleNewGravatar 25 | - event: UpdatedGravatar(uint256,address,string,string) 26 | handler: handleUpdatedGravatar 27 | file: Gravity/Gravity.wasm 28 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/add/subgraph/src/mapping.ts: -------------------------------------------------------------------------------- 1 | import { 2 | NewGravatar as NewGravatarEvent, 3 | UpdatedGravatar as UpdatedGravatarEvent, 4 | } from '../generated/Gravity/Gravity'; 5 | import { NewGravatar, UpdatedGravatar } from '../generated/schema'; 6 | 7 | export function handleNewGravatar(event: NewGravatarEvent): void { 8 | const newGravatar = new NewGravatar(event.params.id.toHex()); 9 | newGravatar.owner = event.params.owner; 10 | newGravatar.displayName = event.params.displayName; 11 | newGravatar.imageUrl = event.params.imageUrl; 12 | newGravatar.save(); 13 | } 14 | 15 | export function handleUpdatedGravatar(event: UpdatedGravatarEvent): void { 16 | const updatedGravatar = new UpdatedGravatar(event.params.id.toHex()); 17 | updatedGravatar.owner = event.params.owner; 18 | updatedGravatar.displayName = event.params.displayName; 19 | updatedGravatar.imageUrl = event.params.imageUrl; 20 | updatedGravatar.save(); 21 | } 22 | -------------------------------------------------------------------------------- /examples/ethereum-basic-event-handlers/src/mapping.ts: -------------------------------------------------------------------------------- 1 | import { 2 | NewGravatar as NewGravatarEvent, 3 | UpdatedGravatar as UpdatedGravatarEvent, 4 | } from '../generated/Gravity/Gravity'; 5 | import { NewGravatar, UpdatedGravatar } from '../generated/schema'; 6 | 7 | export function handleNewGravatar(event: NewGravatarEvent): void { 8 | const newGravatar = new NewGravatar(event.params.id.toHex()); 9 | newGravatar.owner = event.params.owner; 10 | newGravatar.displayName = event.params.displayName; 11 | newGravatar.imageUrl = event.params.imageUrl; 12 | newGravatar.save(); 13 | } 14 | 15 | export function handleUpdatedGravatar(event: UpdatedGravatarEvent): void { 16 | const updatedGravatar = new UpdatedGravatar(event.params.id.toHex()); 17 | updatedGravatar.owner = event.params.owner; 18 | updatedGravatar.displayName = event.params.displayName; 19 | updatedGravatar.imageUrl = event.params.imageUrl; 20 | updatedGravatar.save(); 21 | } 22 | -------------------------------------------------------------------------------- /examples/ethereum-basic-event-handlers/template-subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.5 2 | description: Gravatar for Ethereum 3 | repository: https://github.com/graphprotocol/graph-tooling 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: ethereum/contract 8 | name: Gravity 9 | network: test 10 | source: 11 | address: 'DEPLOYED_CONTRACT_ADDRESS' 12 | abi: Gravity 13 | mapping: 14 | kind: ethereum/events 15 | apiVersion: 0.0.7 16 | language: wasm/assemblyscript 17 | entities: 18 | - Gravatar 19 | abis: 20 | - name: Gravity 21 | file: ./artifacts/contracts/Gravity.sol/GravatarRegistry.json 22 | eventHandlers: 23 | - event: NewGravatar(uint256,address,string,string) 24 | handler: handleNewGravatar 25 | - event: UpdatedGravatar(uint256,address,string,string) 26 | handler: handleUpdatedGravatar 27 | file: ./src/mapping.ts 28 | -------------------------------------------------------------------------------- /examples/ethereum-gravatar/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.4 2 | description: Gravatar for Ethereum 3 | repository: https://github.com/graphprotocol/graph-toolings 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: ethereum/contract 8 | name: Gravity 9 | network: mainnet 10 | source: 11 | address: '0x2E645469f354BB4F5c8a05B3b30A929361cf77eC' 12 | abi: Gravity 13 | mapping: 14 | kind: ethereum/events 15 | apiVersion: 0.0.6 16 | language: wasm/assemblyscript 17 | entities: 18 | - Gravatar 19 | abis: 20 | - name: Gravity 21 | file: ./artifacts/contracts/Gravity.sol/GravatarRegistry.json 22 | eventHandlers: 23 | - event: NewGravatar(uint256,address,string,string) 24 | handler: handleNewGravatar 25 | - event: UpdatedGravatar(uint256,address,string,string) 26 | handler: handleUpdatedGravatar 27 | file: ./src/mapping.ts 28 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/add/subgraph/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.5 2 | description: Gravatar for Ethereum 3 | repository: https://github.com/graphprotocol/graph-tooling 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: ethereum/contract 8 | name: Gravity 9 | network: test 10 | source: 11 | address: '0xCfEB869F69431e42cdB54A4F4f105C19C080A601' 12 | abi: Gravity 13 | mapping: 14 | kind: ethereum/events 15 | apiVersion: 0.0.7 16 | language: wasm/assemblyscript 17 | entities: 18 | - NewGravatar 19 | - UpdatedGravatar 20 | abis: 21 | - name: Gravity 22 | file: ./abis/Gravity.json 23 | eventHandlers: 24 | - event: NewGravatar(uint256,address,string,string) 25 | handler: handleNewGravatar 26 | - event: UpdatedGravatar(uint256,address,string,string) 27 | handler: handleUpdatedGravatar 28 | file: ./src/mapping.ts 29 | -------------------------------------------------------------------------------- /examples/ethereum-basic-event-handlers/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.5 2 | description: Gravatar for Ethereum 3 | repository: https://github.com/graphprotocol/graph-tooling 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: ethereum/contract 8 | name: Gravity 9 | network: test 10 | source: 11 | address: '0x5FbDB2315678afecb367f032d93F642f64180aa3' 12 | abi: Gravity 13 | mapping: 14 | kind: ethereum/events 15 | apiVersion: 0.0.7 16 | language: wasm/assemblyscript 17 | entities: 18 | - Gravatar 19 | abis: 20 | - name: Gravity 21 | file: ./artifacts/contracts/Gravity.sol/GravatarRegistry.json 22 | eventHandlers: 23 | - event: NewGravatar(uint256,address,string,string) 24 | handler: handleNewGravatar 25 | - event: UpdatedGravatar(uint256,address,string,string) 26 | handler: handleUpdatedGravatar 27 | file: ./src/mapping.ts 28 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/example-values-found/generated/ExampleSubgraph/ExampleContract.ts: -------------------------------------------------------------------------------- 1 | // THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | 3 | import { 4 | ethereum, 5 | JSONValue, 6 | TypedMap, 7 | Entity, 8 | Bytes, 9 | Address, 10 | BigInt, 11 | } from "@graphprotocol/graph-ts"; 12 | 13 | export class ExampleEvent extends ethereum.Event { 14 | get params(): ExampleEvent__Params { 15 | return new ExampleEvent__Params(this); 16 | } 17 | } 18 | 19 | export class ExampleEvent__Params { 20 | _event: ExampleEvent; 21 | 22 | constructor(event: ExampleEvent) { 23 | this._event = event; 24 | } 25 | 26 | get param0(): string { 27 | return this._event.parameters[0].value.toString(); 28 | } 29 | } 30 | 31 | export class ExampleContract extends ethereum.SmartContract { 32 | static bind(address: Address): ExampleContract { 33 | return new ExampleContract("ExampleContract", address); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/source-without-address-is-valid/generated/ExampleSubgraph/ExampleContract.ts: -------------------------------------------------------------------------------- 1 | // THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | 3 | import { 4 | ethereum, 5 | JSONValue, 6 | TypedMap, 7 | Entity, 8 | Bytes, 9 | Address, 10 | BigInt, 11 | } from "@graphprotocol/graph-ts"; 12 | 13 | export class ExampleEvent extends ethereum.Event { 14 | get params(): ExampleEvent__Params { 15 | return new ExampleEvent__Params(this); 16 | } 17 | } 18 | 19 | export class ExampleEvent__Params { 20 | _event: ExampleEvent; 21 | 22 | constructor(event: ExampleEvent) { 23 | this._event = event; 24 | } 25 | 26 | get param0(): string { 27 | return this._event.parameters[0].value.toString(); 28 | } 29 | } 30 | 31 | export class ExampleContract extends ethereum.SmartContract { 32 | static bind(address: Address): ExampleContract { 33 | return new ExampleContract("ExampleContract", address); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /examples/example-subgraph/dist/schema.graphql: -------------------------------------------------------------------------------- 1 | type ExampleEntity @entity { 2 | id: ID! 3 | 4 | optionalBoolean: Boolean 5 | requiredBoolean: Boolean! 6 | optionalBooleanList: [Boolean!] 7 | requiredBooleanList: [Boolean!]! 8 | 9 | optionalString: String 10 | requiredString: String! 11 | optionalStringList: [String!] 12 | requiredStringList: [String!]! 13 | 14 | optionalBytes: Bytes 15 | requiredBytes: Bytes! 16 | optionalBytesList: [Bytes!] 17 | requiredBytesList: [Bytes!]! 18 | 19 | optionalInt: Int 20 | requiredInt: Int! 21 | optionalIntList: [Int!] 22 | requiredIntList: [Int!]! 23 | 24 | optionalBigInt: BigInt 25 | requiredBigInt: BigInt! 26 | optionalBigIntList: [BigInt!] 27 | requiredBigIntList: [BigInt!]! 28 | 29 | optionalReference: OtherEntity 30 | requiredReference: OtherEntity! 31 | optionalReferenceList: [OtherEntity!] 32 | requiredReferenceList: [OtherEntity!]! 33 | } 34 | 35 | type OtherEntity @entity { 36 | id: ID! 37 | } 38 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/invalid-data-source-template/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.1 2 | schema: 3 | file: ./schema.graphql 4 | dataSources: 5 | - kind: ethereum/contract 6 | name: ExampleSubgraph 7 | source: 8 | address: '22843e74c59580b3eaf6c233fa67d8b7c561a835' 9 | abi: ExampleContract 10 | mapping: 11 | kind: ethereum/events 12 | apiVersion: 0.0.5 13 | language: wasm/assemblyscript 14 | file: ./mapping.ts 15 | entities: 16 | - ExampleEntity 17 | abis: 18 | - name: ExampleContract 19 | file: ./Abi.json 20 | eventHandlers: 21 | - event: ExampleEvent(string,uint256) 22 | handler: handleExampleEvent 23 | templates: 24 | - name: 5 25 | source: 26 | abi: SomeAbi 27 | address: '0x22843e74c59580b3eaf6c233fa67d8b7c561a835' 28 | mapping: 29 | kind: ethereum/foo 30 | abis: 31 | - name: SomeAbi 32 | file: ./NonexistentAbi.json 33 | -------------------------------------------------------------------------------- /packages/ts/chain/starknet.ts: -------------------------------------------------------------------------------- 1 | import '../common/eager-offset'; 2 | import { Bytes } from '../common/collections'; 3 | import { BigInt } from '../common/numbers'; 4 | 5 | export namespace starknet { 6 | export class Block { 7 | constructor( 8 | public number: BigInt, 9 | public hash: Bytes, 10 | public prevHash: Bytes, 11 | public timestamp: BigInt, 12 | ) {} 13 | } 14 | 15 | export class Transaction { 16 | constructor( 17 | public type: TransactionType, 18 | public hash: Bytes, 19 | ) {} 20 | } 21 | 22 | export enum TransactionType { 23 | DEPLOY = 0, 24 | INVOKE_FUNCTION = 1, 25 | DECLARE = 2, 26 | L1_HANDLER = 3, 27 | DEPLOY_ACCOUNT = 4, 28 | } 29 | 30 | export class Event { 31 | constructor( 32 | public fromAddr: Bytes, 33 | public keys: Array, 34 | public data: Array, 35 | public block: Block, 36 | public transaction: Transaction, 37 | ) {} 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /examples/aggregations/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example-aggregations", 3 | "repository": { 4 | "type": "git", 5 | "url": "https://github.com/graphprotocol/graph-tooling", 6 | "directory": "examples/aggregations" 7 | }, 8 | "license": "MIT", 9 | "private": true, 10 | "scripts": { 11 | "build": "graph build", 12 | "codegen": "graph codegen", 13 | "create": "graph create example --node https://api.studio.thegraph.com/deploy/", 14 | "create-local": "graph create example --node http://127.0.0.1:8020", 15 | "deploy": "graph deploy example --ipfs https://api.thegraph.com/ipfs/ --node https://api.studio.thegraph.com/deploy/", 16 | "deploy-local": "graph deploy example --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020", 17 | "test": "graph test" 18 | }, 19 | "dependencies": { 20 | "@graphprotocol/graph-cli": "0.90.1", 21 | "@graphprotocol/graph-ts": "^0.35.1" 22 | }, 23 | "devDependencies": { 24 | "matchstick-as": "0.6.0" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /examples/example-subgraph/schema.graphql: -------------------------------------------------------------------------------- 1 | type ExampleEntity @entity(immutable: false) { 2 | id: ID! 3 | 4 | optionalBoolean: Boolean 5 | requiredBoolean: Boolean! 6 | optionalBooleanList: [Boolean!] 7 | requiredBooleanList: [Boolean!]! 8 | 9 | optionalString: String 10 | requiredString: String! 11 | optionalStringList: [String!] 12 | requiredStringList: [String!]! 13 | 14 | optionalBytes: Bytes 15 | requiredBytes: Bytes! 16 | optionalBytesList: [Bytes!] 17 | requiredBytesList: [Bytes!]! 18 | 19 | optionalInt: Int 20 | requiredInt: Int! 21 | optionalIntList: [Int!] 22 | requiredIntList: [Int!]! 23 | 24 | optionalBigInt: BigInt 25 | requiredBigInt: BigInt! 26 | optionalBigIntList: [BigInt!] 27 | requiredBigIntList: [BigInt!]! 28 | 29 | optionalReference: OtherEntity 30 | requiredReference: OtherEntity! 31 | optionalReferenceList: [OtherEntity!] 32 | requiredReferenceList: [OtherEntity!]! 33 | } 34 | 35 | type OtherEntity @entity(immutable: true) { 36 | id: ID! 37 | } 38 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": ["config:recommended"], 4 | "prConcurrentLimit": 25, 5 | "reviewers": ["YaroShkvorets", "0237h"], 6 | "automerge": true, 7 | "major": { 8 | "automerge": false 9 | }, 10 | "lockFileMaintenance": { 11 | "enabled": true, 12 | "automerge": true 13 | }, 14 | "recreateWhen": "never", 15 | "labels": ["dependencies"], 16 | "rebaseWhen": "conflicted", 17 | "packageRules": [ 18 | { 19 | "matchUpdateTypes": ["minor", "patch"], 20 | "groupName": "all non-major dependencies", 21 | "groupSlug": "all-minor-patch" 22 | }, 23 | { 24 | "matchPackageNames": ["oclif", "@theguild/**", "@pinax/**", "typescript"], 25 | "groupName": null 26 | }, 27 | { 28 | "matchPackageNames": ["assemblyscript", "oclif"], 29 | "enabled": false 30 | }, 31 | { 32 | "matchManagers": ["github-actions"], 33 | "groupName": null 34 | } 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/call-handler-with-tuple.stderr: -------------------------------------------------------------------------------- 1 | - Load subgraph from subgraph.yaml 2 | ✔ Load subgraph from subgraph.yaml 3 | - Load contract ABIs 4 | Load contract ABI from Abi.json 5 | - Load contract ABIs 6 | ✔ Load contract ABIs 7 | - Generate types for contract ABIs 8 | Generate types for contract ABI: ExampleContract (Abi.json) 9 | - Generate types for contract ABIs 10 | Write types to generated/ExampleSubgraph/ExampleContract.ts 11 | - Generate types for contract ABIs 12 | ✔ Generate types for contract ABIs 13 | - Generate types for data source templates 14 | ✔ Generate types for data source templates 15 | - Load data source template ABIs 16 | ✔ Load data source template ABIs 17 | - Generate types for data source template ABIs 18 | ✔ Generate types for data source template ABIs 19 | - Load GraphQL schema from schema.graphql 20 | ✔ Load GraphQL schema from schema.graphql 21 | - Generate types for GraphQL schema 22 | Write types to generated/schema.ts 23 | - Generate types for GraphQL schema 24 | ✔ Generate types for GraphQL schema 25 | -------------------------------------------------------------------------------- /examples/arweave-blocks-transactions/README.md: -------------------------------------------------------------------------------- 1 | # Arweave Blocks and Transactions Example 2 | 3 | This subgraph is indexing blocks, transactions, tags, and POAs. Make sure to replace the `owner` 4 | field inside the .yaml file with the owner id. 5 | 6 | > NOTE: The id of an owner is not required, the subgraph can index all blocks and transactions. 7 | 8 | ### Dev Dependencies 9 | 10 | To be able to build an Arweave subgraph, you need a graph-cli version of 0.30.2 or above. Run the 11 | command below to update to the latest version: 12 | 13 | ``` 14 | npm-update -g i @graphprotocol/graph-cli 15 | ``` 16 | 17 | ### Querying the Subgraph 18 | 19 | With the following query, you can retrieve all the appended blocks between two dates: 20 | 21 | ```graphql 22 | query BlocksBetweenDates($timestamp_start: BigInt!, $timestamp_end: BigInt!) { 23 | blocks(where: { timestamp_gt: $timestamp_start, timestamp_lt: $timestamp_end }) { 24 | id 25 | timestamp 26 | height 27 | } 28 | } 29 | ``` 30 | 31 | For more information see the docs on https://thegraph.com/docs/. 32 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/source-without-address-is-valid.stderr: -------------------------------------------------------------------------------- 1 | - Load subgraph from subgraph.yaml 2 | ✔ Load subgraph from subgraph.yaml 3 | - Load contract ABIs 4 | Load contract ABI from Abi.json 5 | - Load contract ABIs 6 | ✔ Load contract ABIs 7 | - Generate types for contract ABIs 8 | Generate types for contract ABI: ExampleContract (Abi.json) 9 | - Generate types for contract ABIs 10 | Write types to generated/ExampleSubgraph/ExampleContract.ts 11 | - Generate types for contract ABIs 12 | ✔ Generate types for contract ABIs 13 | - Generate types for data source templates 14 | ✔ Generate types for data source templates 15 | - Load data source template ABIs 16 | ✔ Load data source template ABIs 17 | - Generate types for data source template ABIs 18 | ✔ Generate types for data source template ABIs 19 | - Load GraphQL schema from schema.graphql 20 | ✔ Load GraphQL schema from schema.graphql 21 | - Generate types for GraphQL schema 22 | Write types to generated/schema.ts 23 | - Generate types for GraphQL schema 24 | ✔ Generate types for GraphQL schema 25 | -------------------------------------------------------------------------------- /examples/ethereum-gravatar/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example-ethereum-gravatar", 3 | "version": "0.1.0", 4 | "repository": { 5 | "type": "git", 6 | "url": "https://github.com/graphprotocol/graph-tooling", 7 | "directory": "examples/ethereum-gravatar" 8 | }, 9 | "license": "MIT", 10 | "private": true, 11 | "scripts": { 12 | "build": "graph build", 13 | "build:contract": "hardhat compile", 14 | "codegen": "graph codegen", 15 | "create": "graph create example --node https://api.studio.thegraph.com/deploy/", 16 | "create-local": "graph create example --node http://127.0.0.1:8020", 17 | "deploy": "graph deploy example --ipfs https://api.thegraph.com/ipfs/ --node https://api.studio.thegraph.com/deploy/", 18 | "deploy-local": "graph deploy example --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020" 19 | }, 20 | "devDependencies": { 21 | "@graphprotocol/graph-cli": "0.90.1", 22 | "@graphprotocol/graph-ts": "0.35.1", 23 | "@nomicfoundation/hardhat-toolbox": "^5.0.0", 24 | "hardhat": "^2.22.17" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/cli/src/migrations/util/versions.ts: -------------------------------------------------------------------------------- 1 | import path from 'node:path'; 2 | import fs from 'fs-extra'; 3 | 4 | export async function getGraphTsVersion(sourceDir: string) { 5 | let graphTsPath!: string; 6 | 7 | for ( 8 | let dir: string | undefined = path.resolve(sourceDir); 9 | // Terminate after the root dir or when we have found node_modules 10 | dir !== undefined; 11 | // Continue with the parent directory, terminate after the root dir 12 | dir = path.dirname(dir) === dir ? undefined : path.dirname(dir) 13 | ) { 14 | const graphTsNodeModulesPath = path.join(dir, 'node_modules', '@graphprotocol', 'graph-ts'); 15 | 16 | if (fs.existsSync(graphTsNodeModulesPath)) { 17 | graphTsPath = graphTsNodeModulesPath; 18 | // Loop until we find the first occurrence of graph-ts in node_modules 19 | break; 20 | } 21 | } 22 | 23 | const pkgJsonFile = path.join(graphTsPath, 'package.json'); 24 | const data = await fs.readFile(pkgJsonFile); 25 | const jsonData = JSON.parse(data.toString()); 26 | return jsonData.version; 27 | } 28 | -------------------------------------------------------------------------------- /website/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2020", 4 | "useDefineForClassFields": true, 5 | "lib": ["ES2020", "DOM", "DOM.Iterable"], 6 | "module": "ESNext", 7 | "skipLibCheck": true, 8 | 9 | /* Bundler mode */ 10 | "moduleResolution": "bundler", 11 | "allowImportingTsExtensions": true, 12 | "resolveJsonModule": true, 13 | "isolatedModules": true, 14 | "noEmit": true, 15 | "jsx": "react-jsx", 16 | 17 | /* Linting */ 18 | "strict": true, 19 | "noUnusedLocals": true, 20 | "noUnusedParameters": true, 21 | "noFallthroughCasesInSwitch": true, 22 | 23 | "baseUrl": ".", 24 | "paths": { 25 | "@/*": ["./src/*"] 26 | }, 27 | "plugins": [ 28 | { 29 | "name": "@0no-co/graphqlsp", 30 | "schema": "https://api.thegraph.com/subgraphs/name/graphprotocol/graph-network-arbitrum", 31 | "tadaOutputLocation": "./src/graphql-env.d.ts" 32 | } 33 | ] 34 | }, 35 | "include": ["src"], 36 | "references": [{ "path": "./tsconfig.node.json" }] 37 | } 38 | -------------------------------------------------------------------------------- /packages/cli/src/migrations/spec_version_0_0_2.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | 3 | import * as toolbox from 'gluegun'; 4 | import { loadManifest } from './util/load-manifest.js'; 5 | 6 | // Spec version to 0.0.2 uses top level templates. graph-cli no longer supports 7 | // 0.0.1 which used nested templates. 8 | export default { 9 | name: 'Bump manifest specVersion from 0.0.1 to 0.0.2', 10 | predicate: async ({ manifestFile }: { manifestFile: string }) => { 11 | const manifest = await loadManifest(manifestFile); 12 | return ( 13 | manifest && 14 | typeof manifest === 'object' && 15 | manifest.specVersion && 16 | manifest.specVersion === '0.0.1' 17 | ); 18 | }, 19 | apply: async ({ manifestFile }: { manifestFile: string }) => { 20 | await toolbox.patching.replace(manifestFile, 'specVersion: 0.0.1', 'specVersion: 0.0.2'); 21 | await toolbox.patching.replace(manifestFile, "specVersion: '0.0.1'", "specVersion: '0.0.2'"); 22 | await toolbox.patching.replace(manifestFile, 'specVersion: "0.0.1"', 'specVersion: "0.0.2"'); 23 | }, 24 | }; 25 | -------------------------------------------------------------------------------- /website/src/main.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom/client'; 3 | import './global.css'; 4 | import { createRouter, RouterProvider } from '@tanstack/react-router'; 5 | import { ThemeProvider } from './components/theme-provider.tsx'; 6 | import { Toaster } from './components/ui/toaster.tsx'; 7 | import { WalletProvider } from './components/wallet-provider.tsx'; 8 | // Import the generated route tree 9 | import { routeTree } from './routeTree.gen'; 10 | 11 | // Create a new router instance 12 | const router = createRouter({ routeTree }); 13 | 14 | // Register the router instance for type safety 15 | declare module '@tanstack/react-router' { 16 | interface Register { 17 | router: typeof router; 18 | } 19 | } 20 | 21 | ReactDOM.createRoot(document.getElementById('root')!).render( 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | , 30 | ); 31 | -------------------------------------------------------------------------------- /examples/aggregations/subgraph.yaml: -------------------------------------------------------------------------------- 1 | # Enable aggregations by using a spec version >= 1.1.0 2 | # 3 | # The graph-node to which this is deployed must have GRAPH_MAX_SPEC_VERSION 4 | # also set to at least 1.1.0 5 | # 6 | specVersion: 1.1.0 7 | description: 'Information about Ethereum Mainnet Blocks (run #3)' 8 | repository: https://github.com/graphprotocol/common-subgraphs/blocks/ethereum 9 | schema: 10 | file: ./schema.graphql 11 | dataSources: 12 | - kind: ethereum/contract 13 | name: Contract 14 | network: mainnet 15 | source: 16 | # We don't realy need a contract, just use Gravatar to have something 17 | # here 18 | address: '0x2E645469f354BB4F5c8a05B3b30A929361cf77eC' 19 | abi: Contract 20 | startBlock: 0 21 | mapping: 22 | kind: ethereum/events 23 | apiVersion: 0.0.7 24 | language: wasm/assemblyscript 25 | entities: 26 | - Block 27 | abis: 28 | - name: Contract 29 | file: ./abis/Contract.json 30 | blockHandlers: 31 | - handler: handleBlock 32 | file: ./src/mappings/blocks.ts 33 | -------------------------------------------------------------------------------- /examples/substreams-powered-subgraph/substreams.yaml: -------------------------------------------------------------------------------- 1 | specVersion: v0.1.0 2 | package: 3 | name: 'substreams_test' # the name to be used in the .spkg 4 | version: v1.0.1 # the version to use when creating the .spkg 5 | 6 | imports: # dependencies 7 | entity: https://github.com/streamingfast/substreams-entity-change/releases/download/v0.2.1/substreams-entity-change-v0.2.1.spkg 8 | 9 | protobuf: # specifies custom types for use by Substreams modules 10 | files: 11 | - example.proto 12 | importPaths: 13 | - ./proto 14 | 15 | binaries: 16 | default: 17 | type: wasm/rust-v1 18 | file: ./target/wasm32-unknown-unknown/release/substreams.wasm 19 | 20 | modules: # specify modules with their inputs and outputs. 21 | - name: map_contract 22 | kind: map 23 | inputs: 24 | - source: sf.ethereum.type.v2.Block 25 | output: 26 | type: proto:test.Contracts 27 | 28 | - name: graph_out 29 | kind: map 30 | inputs: 31 | - map: map_contract 32 | output: 33 | type: proto:substreams.entity.v1.EntityChanges # this type can be consumed by Graph Node 34 | -------------------------------------------------------------------------------- /examples/substreams-powered-subgraph/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example-substreams-powered-subgraph", 3 | "version": "0.1.0", 4 | "repository": { 5 | "type": "git", 6 | "url": "https://github.com/graphprotocol/graph-tooling", 7 | "directory": "examples/substreams-powered-subgraph" 8 | }, 9 | "private": true, 10 | "scripts": { 11 | "codegen": "graph codegen", 12 | "deploy": "graph deploy", 13 | "subgraph:build": "graph build", 14 | "substreams:build": "cargo build --target wasm32-unknown-unknown --release", 15 | "substreams:clean": "rm -rf ./target && rm -rf ./src/pb", 16 | "substreams:package": "substreams pack ./substreams.yaml", 17 | "substreams:prepare": "yarn substreams:protogen && yarn substreams:build && yarn substreams:package", 18 | "substreams:protogen": "substreams protogen ./substreams.yaml --exclude-paths='sf/substreams,google'", 19 | "substreams:stream": "substreams run -e mainnet.eth.streamingfast.io:443 substreams.yaml graph_out -s 12292922 -t +10" 20 | }, 21 | "devDependencies": { 22 | "@graphprotocol/graph-cli": "0.90.1" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /packages/cli/src/migrations/spec_version_0_0_3.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | 3 | import * as toolbox from 'gluegun'; 4 | import { loadManifest } from './util/load-manifest.js'; 5 | 6 | // Spec version 0.0.4 uses feature management, but features are 7 | // detected and validated by the graph-node instance during subgraph 8 | // deployment. 9 | // 10 | // Also, we skip spec version 0.0.3, which is considered invalid and 11 | // non-canonical. 12 | export default { 13 | name: 'Bump manifest specVersion from 0.0.2 to 0.0.4', 14 | predicate: async ({ manifestFile }: { manifestFile: string }) => { 15 | const manifest = await loadManifest(manifestFile); 16 | return ( 17 | manifest && 18 | typeof manifest === 'object' && 19 | manifest.specVersion && 20 | (manifest.specVersion === '0.0.2' || manifest.specVersion === '0.0.3') 21 | ); 22 | }, 23 | apply: async ({ manifestFile }: { manifestFile: string }) => { 24 | await toolbox.patching.patch(manifestFile, { 25 | insert: 'specVersion: 0.0.4', 26 | replace: new RegExp(`specVersion: ['"]?0.0.[23]['"]?`), 27 | }); 28 | }, 29 | }; 30 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/nested-template-nice-error/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.1 2 | repository: https://github.com/graphprotocol/test-subgraph 3 | description: Test subgraph 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: ethereum/contract 8 | name: ExampleSubgraph 9 | source: 10 | abi: ExampleContract 11 | mapping: 12 | kind: ethereum/events 13 | apiVersion: 0.0.5 14 | language: wasm/assemblyscript 15 | file: ./mapping.ts 16 | entities: 17 | - ExampleEntity 18 | abis: 19 | - name: ExampleContract 20 | file: ./Abi.json 21 | templates: 22 | - kind: ethereum/contract 23 | name: ExampleSubgraph 24 | source: 25 | abi: ExampleContract 26 | mapping: 27 | kind: ethereum/events 28 | apiVersion: 0.0.5 29 | language: wasm/assemblyscript 30 | file: ./mapping.ts 31 | entities: 32 | - ExampleEntity 33 | abis: 34 | - name: ExampleContract 35 | file: ./Abi.json 36 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/conflicting-protocol-names/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.1 2 | schema: 3 | file: ./schema.graphql 4 | dataSources: 5 | - kind: ethereum/contract 6 | name: ExampleSubgraph 7 | network: mainnet 8 | source: 9 | address: 22843e74c59580b3eaf6c233fa67d8b7c561a835 10 | abi: ExampleContract 11 | mapping: 12 | kind: ethereum/events 13 | apiVersion: 0.0.5 14 | language: wasm/assemblyscript 15 | file: ./mapping.ts 16 | entities: 17 | - ExampleEntity 18 | abis: 19 | - name: ExampleContract 20 | file: ./Abi.json 21 | eventHandlers: 22 | - event: ExampleEvent(string) 23 | handler: handleExampleEvent 24 | templates: 25 | - kind: near 26 | name: ExampleTemplate 27 | source: 28 | abi: ExampleContract 29 | mapping: 30 | kind: ethereum/events 31 | apiVersion: 0.0.5 32 | language: wasm/assemblyscript 33 | file: ./mapping.ts 34 | entities: 35 | - ExampleEntity 36 | abis: 37 | - name: ExampleContract 38 | file: ./Abi.json 39 | eventHandlers: 40 | - event: ExampleEvent(string) 41 | handler: handleExampleEvent 42 | -------------------------------------------------------------------------------- /examples/arweave-blocks-transactions/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example-arweave-blocks-transactions", 3 | "version": "0.1.0", 4 | "description": "subgraph example for Arweave", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/graphprotocol/graph-tooling", 8 | "directory": "examples/arweave-blocks-transactions" 9 | }, 10 | "license": "MIT", 11 | "private": true, 12 | "scripts": { 13 | "build": "graph build", 14 | "codegen": "graph codegen", 15 | "create": "graph create arweave-example --node https://api.studio.thegraph.com/deploy/", 16 | "create-local": "graph create arweave-example --node http://localhost:8020", 17 | "deploy": "graph deploy arweave-example --ipfs https://api.thegraph.com/ipfs/ --node https://api.studio.thegraph.com/deploy/", 18 | "deploy-local": "graph deploy arweave-example -l v0.1.0 --ipfs http://localhost:5001 --node http://localhost:8020", 19 | "remove-local": "graph remove arweave-example --node http://localhost:8020" 20 | }, 21 | "devDependencies": { 22 | "@graphprotocol/graph-cli": "0.90.1", 23 | "@graphprotocol/graph-ts": "0.35.1" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/conflicting-network-names/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.1 2 | schema: 3 | file: ./schema.graphql 4 | dataSources: 5 | - kind: ethereum/contract 6 | name: ExampleSubgraph 7 | network: mainnet 8 | source: 9 | address: 22843e74c59580b3eaf6c233fa67d8b7c561a835 10 | abi: ExampleContract 11 | mapping: 12 | kind: ethereum/events 13 | apiVersion: 0.0.5 14 | language: wasm/assemblyscript 15 | file: ./mapping.ts 16 | entities: 17 | - ExampleEntity 18 | abis: 19 | - name: ExampleContract 20 | file: ./Abi.json 21 | eventHandlers: 22 | - event: ExampleEvent(string) 23 | handler: handleExampleEvent 24 | templates: 25 | - kind: ethereum/contract 26 | name: ExampleTemplate 27 | source: 28 | abi: ExampleContract 29 | mapping: 30 | kind: ethereum/events 31 | apiVersion: 0.0.5 32 | language: wasm/assemblyscript 33 | file: ./mapping.ts 34 | entities: 35 | - ExampleEntity 36 | abis: 37 | - name: ExampleContract 38 | file: ./Abi.json 39 | eventHandlers: 40 | - event: ExampleEvent(string) 41 | handler: handleExampleEvent 42 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 Graph Protocol, Inc. and contributors. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /examples/arweave-blocks-transactions/schema.graphql: -------------------------------------------------------------------------------- 1 | type Block @entity(immutable: true) { 2 | id: ID! 3 | 4 | timestamp: BigInt! 5 | last_retarget: BigInt! 6 | height: BigInt! 7 | indep_hash: Bytes! 8 | nonce: Bytes! 9 | previous_block: Bytes! 10 | diff: Bytes! 11 | hash: Bytes! 12 | tx_root: Bytes! 13 | txs: [Bytes!]! 14 | wallet_list: Bytes! 15 | reward_addr: Bytes! 16 | tags: [Tag!]! 17 | reward_pool: Bytes! 18 | weave_size: Bytes! 19 | block_size: Bytes! 20 | cumulative_diff: Bytes! 21 | hash_list_merkle: Bytes! 22 | poa: Poa 23 | } 24 | 25 | type Transaction @entity(immutable: true) { 26 | id: ID! 27 | 28 | block: Block! 29 | tx_id: Bytes! 30 | last_tx: Bytes! 31 | owner: Bytes! 32 | tags: [Tag!]! 33 | target: Bytes! 34 | quantity: Bytes! 35 | data: Bytes! 36 | data_size: Bytes! 37 | data_root: Bytes! 38 | signature: Bytes! 39 | reward: Bytes! 40 | } 41 | 42 | type Poa @entity(immutable: true) { 43 | id: ID! 44 | 45 | option: String! 46 | tx_path: Bytes! 47 | data_path: Bytes! 48 | chunk: Bytes! 49 | } 50 | 51 | type Tag @entity(immutable: true) { 52 | id: ID! 53 | 54 | name: Bytes! 55 | value: Bytes! 56 | } 57 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/invalid-graphql-schema.stderr: -------------------------------------------------------------------------------- 1 | - Load subgraph from subgraph.yaml 2 | ✔ Load subgraph from subgraph.yaml 3 | - Load contract ABIs 4 | Load contract ABI from Abi.json 5 | - Load contract ABIs 6 | ✔ Load contract ABIs 7 | - Generate types for contract ABIs 8 | Generate types for contract ABI: ExampleContract (Abi.json) 9 | - Generate types for contract ABIs 10 | Write types to generated/ExampleSubgraph/ExampleContract.ts 11 | - Generate types for contract ABIs 12 | ✔ Generate types for contract ABIs 13 | - Generate types for data source templates 14 | ✔ Generate types for data source templates 15 | - Load data source template ABIs 16 | ✔ Load data source template ABIs 17 | - Generate types for data source template ABIs 18 | ✔ Generate types for data source template ABIs 19 | - Load GraphQL schema from schema.graphql 20 | ✔ Load GraphQL schema from schema.graphql 21 | - Generate types for GraphQL schema 22 | ✖ Failed to generate types for GraphQL schema: 23 | GraphQL schema can't have List's with Nullable members. 24 | Error in 'invalidField' field of type '[Something]'. 25 | Suggestion: add an '!' to the member type of the List, change from '[Something]' to '[Something!]' 26 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/no-network-names/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.1 2 | schema: 3 | file: ./schema.graphql 4 | dataSources: 5 | - kind: ethereum/contract 6 | name: ExampleSubgraph 7 | source: 8 | address: '22843e74c59580b3eaf6c233fa67d8b7c561a835' 9 | abi: ExampleContract 10 | mapping: 11 | kind: ethereum/events 12 | apiVersion: 0.0.5 13 | language: wasm/assemblyscript 14 | file: ./mapping.ts 15 | entities: 16 | - ExampleEntity 17 | abis: 18 | - name: ExampleContract 19 | file: ./Abi.json 20 | eventHandlers: 21 | - event: ExampleEvent(string) 22 | handler: handleExampleEvent 23 | templates: 24 | - kind: ethereum/contract 25 | name: ExampleTemplate 26 | source: 27 | abi: ExampleContract 28 | mapping: 29 | kind: ethereum/events 30 | apiVersion: 0.0.5 31 | language: wasm/assemblyscript 32 | file: ./mapping.ts 33 | entities: 34 | - ExampleEntity 35 | abis: 36 | - name: ExampleContract 37 | file: ./Abi.json 38 | eventHandlers: 39 | - event: ExampleEvent(string) 40 | handler: handleExampleEvent 41 | -------------------------------------------------------------------------------- /examples/cosmos-osmosis-token-swaps/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example-cosmos-osmosis-token-swaps-", 3 | "version": "0.1.0", 4 | "repository": { 5 | "type": "git", 6 | "url": "https://github.com/graphprotocol/graph-tooling", 7 | "directory": "examples/cosmos-osmosis-token-swaps" 8 | }, 9 | "license": "MIT", 10 | "private": true, 11 | "scripts": { 12 | "build": "graph build", 13 | "codegen": "graph codegen", 14 | "create": "graph create osmosis-token-swaps --node https://api.studio.thegraph.com/deploy/", 15 | "create-local": "graph create osmosis-token-swaps --node http://0.0.0.0:8020", 16 | "deploy": "graph deploy osmosis-token-swaps --ipfs https://api.thegraph.com/ipfs/ --node https://api.studio.thegraph.com/deploy/", 17 | "deploy-local": "graph deploy osmosis-token-swaps -l v0.1.0 --ipfs http://0.0.0.0:5001 --node http://0.0.0.0:8020", 18 | "remove-local": "graph remove osmosis-token-swaps --node http://0.0.0.0:8020" 19 | }, 20 | "dependencies": { 21 | "babel-polyfill": "^6.26.0", 22 | "babel-register": "^6.26.0" 23 | }, 24 | "devDependencies": { 25 | "@graphprotocol/graph-cli": "0.90.1", 26 | "@graphprotocol/graph-ts": "0.35.1" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /examples/near-blocks/docker-compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | graph-node: 3 | image: graphprotocol/graph-node:v0.32.0 4 | ports: 5 | - '8000:8000' 6 | - '8001:8001' 7 | - '8020:8020' 8 | - '8030:8030' 9 | - '8040:8040' 10 | depends_on: 11 | - ipfs 12 | - postgres 13 | environment: 14 | postgres_host: postgres 15 | postgres_user: graph-node 16 | postgres_pass: let-me-in 17 | postgres_db: graph-node 18 | ipfs: 'ipfs:5001' 19 | # Change next line if you want to connect to a different JSON-RPC endpoint 20 | ethereum: 'mainnet:http://host.docker.internal:8545' 21 | GRAPH_LOG: info 22 | ipfs: 23 | image: ipfs/go-ipfs:v0.4.23 24 | ports: 25 | - '5001:5001' 26 | volumes: 27 | - ipfs-data:/data/ipfs 28 | postgres: 29 | image: postgres 30 | ports: 31 | - '5432:5432' 32 | command: ['postgres', '-cshared_preload_libraries=pg_stat_statements'] 33 | environment: 34 | POSTGRES_USER: graph-node 35 | POSTGRES_PASSWORD: let-me-in 36 | POSTGRES_DB: graph-node 37 | volumes: 38 | - postgres-data:/var/lib/postgresql/data 39 | 40 | volumes: 41 | ipfs-data: 42 | postgres-data: 43 | -------------------------------------------------------------------------------- /examples/near-receipts/docker-compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | graph-node: 3 | image: graphprotocol/graph-node:v0.32.0 4 | ports: 5 | - '8000:8000' 6 | - '8001:8001' 7 | - '8020:8020' 8 | - '8030:8030' 9 | - '8040:8040' 10 | depends_on: 11 | - ipfs 12 | - postgres 13 | environment: 14 | postgres_host: postgres 15 | postgres_user: graph-node 16 | postgres_pass: let-me-in 17 | postgres_db: graph-node 18 | ipfs: 'ipfs:5001' 19 | # Change next line if you want to connect to a different JSON-RPC endpoint 20 | ethereum: 'mainnet:http://host.docker.internal:8545' 21 | GRAPH_LOG: info 22 | ipfs: 23 | image: ipfs/go-ipfs:v0.4.23 24 | ports: 25 | - '5001:5001' 26 | volumes: 27 | - ipfs-data:/data/ipfs 28 | postgres: 29 | image: postgres 30 | ports: 31 | - '5432:5432' 32 | command: ['postgres', '-cshared_preload_libraries=pg_stat_statements'] 33 | environment: 34 | POSTGRES_USER: graph-node 35 | POSTGRES_PASSWORD: let-me-in 36 | POSTGRES_DB: graph-node 37 | volumes: 38 | - postgres-data:/var/lib/postgresql/data 39 | 40 | volumes: 41 | ipfs-data: 42 | postgres-data: 43 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/event-not-found/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.1 2 | schema: 3 | file: ./schema.graphql 4 | dataSources: 5 | - kind: ethereum/contract 6 | name: ExampleSubgraph 7 | source: 8 | address: '22843e74c59580b3eaf6c233fa67d8b7c561a835' 9 | abi: ExampleContract 10 | mapping: 11 | kind: ethereum/events 12 | apiVersion: 0.0.5 13 | language: wasm/assemblyscript 14 | file: ./mapping.ts 15 | entities: 16 | - ExampleEntity 17 | abis: 18 | - name: ExampleContract 19 | file: ./Abi.json 20 | eventHandlers: 21 | - event: ExampleEvent(string,uint256) 22 | handler: handleExampleEvent 23 | templates: 24 | - kind: ethereum/contract 25 | name: ExampleTemplate 26 | source: 27 | abi: ExampleContract 28 | mapping: 29 | kind: ethereum/events 30 | apiVersion: 0.0.5 31 | language: wasm/assemblyscript 32 | file: ./mapping.ts 33 | entities: 34 | - ExampleEntity 35 | abis: 36 | - name: ExampleContract 37 | file: ./Abi.json 38 | eventHandlers: 39 | - event: ExampleEvent(string,uint256) 40 | handler: handleExampleEvent 41 | -------------------------------------------------------------------------------- /examples/ethereum-gravatar/docker-compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | graph-node: 3 | image: graphprotocol/graph-node:v0.32.0 4 | ports: 5 | - '8000:8000' 6 | - '8001:8001' 7 | - '8020:8020' 8 | - '8030:8030' 9 | - '8040:8040' 10 | depends_on: 11 | - ipfs 12 | - postgres 13 | environment: 14 | postgres_host: postgres 15 | postgres_user: graph-node 16 | postgres_pass: let-me-in 17 | postgres_db: graph-node 18 | ipfs: 'ipfs:5001' 19 | # Change next line if you want to connect to a different JSON-RPC endpoint 20 | ethereum: 'mainnet:http://host.docker.internal:8545' 21 | GRAPH_LOG: info 22 | ipfs: 23 | image: ipfs/go-ipfs:v0.4.23 24 | ports: 25 | - '5001:5001' 26 | volumes: 27 | - ipfs-data:/data/ipfs 28 | postgres: 29 | image: postgres 30 | ports: 31 | - '5432:5432' 32 | command: ['postgres', '-cshared_preload_libraries=pg_stat_statements'] 33 | environment: 34 | POSTGRES_USER: graph-node 35 | POSTGRES_PASSWORD: let-me-in 36 | POSTGRES_DB: graph-node 37 | volumes: 38 | - postgres-data:/var/lib/postgresql/data 39 | 40 | volumes: 41 | ipfs-data: 42 | postgres-data: 43 | -------------------------------------------------------------------------------- /examples/cosmos-block-filtering/docker-compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | graph-node: 3 | image: graphprotocol/graph-node:v0.32.0 4 | ports: 5 | - '8000:8000' 6 | - '8001:8001' 7 | - '8020:8020' 8 | - '8030:8030' 9 | - '8040:8040' 10 | depends_on: 11 | - ipfs 12 | - postgres 13 | environment: 14 | postgres_host: postgres 15 | postgres_user: graph-node 16 | postgres_pass: let-me-in 17 | postgres_db: graph-node 18 | ipfs: 'ipfs:5001' 19 | # Change next line if you want to connect to a different JSON-RPC endpoint 20 | ethereum: 'mainnet:http://host.docker.internal:8545' 21 | GRAPH_LOG: info 22 | ipfs: 23 | image: ipfs/go-ipfs:v0.4.23 24 | ports: 25 | - '5001:5001' 26 | volumes: 27 | - ipfs-data:/data/ipfs 28 | postgres: 29 | image: postgres 30 | ports: 31 | - '5432:5432' 32 | command: ['postgres', '-cshared_preload_libraries=pg_stat_statements'] 33 | environment: 34 | POSTGRES_USER: graph-node 35 | POSTGRES_PASSWORD: let-me-in 36 | POSTGRES_DB: graph-node 37 | volumes: 38 | - postgres-data:/var/lib/postgresql/data 39 | 40 | volumes: 41 | ipfs-data: 42 | postgres-data: 43 | -------------------------------------------------------------------------------- /website/src/lib/utils.ts: -------------------------------------------------------------------------------- 1 | import base from 'base-x'; 2 | import { clsx, type ClassValue } from 'clsx'; 3 | import { twMerge } from 'tailwind-merge'; 4 | import { Address, encodePacked, keccak256, toBytes, toHex } from 'viem'; 5 | 6 | export function cn(...inputs: ClassValue[]) { 7 | return twMerge(clsx(inputs)); 8 | } 9 | 10 | const base58 = base('123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'); 11 | 12 | export const ipfsHexHash = (ipfsHash: string) => { 13 | const hash = base58.decode(ipfsHash).slice(2); 14 | const hex = Buffer.from(hash).toString('hex'); 15 | return `0x${hex}` as const; 16 | }; 17 | 18 | export const convertSubgraphIdtoBase58 = (subgraphId: string) => { 19 | return base58.encode(toBytes(toHex(BigInt(subgraphId)))); 20 | }; 21 | 22 | export const buildSubgraphId = ({ 23 | chainId, 24 | account, 25 | seqId, 26 | }: { 27 | account: Address; 28 | seqId: bigint; 29 | chainId?: number; 30 | }) => { 31 | if (chainId) { 32 | return BigInt( 33 | keccak256(encodePacked(['address', 'uint256', 'uint256'], [account, seqId, BigInt(chainId)])), 34 | ).toString(); 35 | } 36 | 37 | return BigInt(keccak256(encodePacked(['address', 'uint256'], [account, seqId]))).toString(); 38 | }; 39 | -------------------------------------------------------------------------------- /examples/cosmos-osmosis-token-swaps/docker-compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | graph-node: 3 | image: graphprotocol/graph-node:v0.32.0 4 | ports: 5 | - '8000:8000' 6 | - '8001:8001' 7 | - '8020:8020' 8 | - '8030:8030' 9 | - '8040:8040' 10 | depends_on: 11 | - ipfs 12 | - postgres 13 | environment: 14 | postgres_host: postgres 15 | postgres_user: graph-node 16 | postgres_pass: let-me-in 17 | postgres_db: graph-node 18 | ipfs: 'ipfs:5001' 19 | # Change next line if you want to connect to a different JSON-RPC endpoint 20 | ethereum: 'mainnet:http://host.docker.internal:8545' 21 | GRAPH_LOG: info 22 | ipfs: 23 | image: ipfs/go-ipfs:v0.4.23 24 | ports: 25 | - '5001:5001' 26 | volumes: 27 | - ipfs-data:/data/ipfs 28 | postgres: 29 | image: postgres 30 | ports: 31 | - '5432:5432' 32 | command: ['postgres', '-cshared_preload_libraries=pg_stat_statements'] 33 | environment: 34 | POSTGRES_USER: graph-node 35 | POSTGRES_PASSWORD: let-me-in 36 | POSTGRES_DB: graph-node 37 | volumes: 38 | - postgres-data:/var/lib/postgresql/data 39 | 40 | volumes: 41 | ipfs-data: 42 | postgres-data: 43 | -------------------------------------------------------------------------------- /examples/cosmos-validator-delegations/docker-compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | graph-node: 3 | image: graphprotocol/graph-node:v0.32.0 4 | ports: 5 | - '8000:8000' 6 | - '8001:8001' 7 | - '8020:8020' 8 | - '8030:8030' 9 | - '8040:8040' 10 | depends_on: 11 | - ipfs 12 | - postgres 13 | environment: 14 | postgres_host: postgres 15 | postgres_user: graph-node 16 | postgres_pass: let-me-in 17 | postgres_db: graph-node 18 | ipfs: 'ipfs:5001' 19 | # Change next line if you want to connect to a different JSON-RPC endpoint 20 | ethereum: 'mainnet:http://host.docker.internal:8545' 21 | GRAPH_LOG: info 22 | ipfs: 23 | image: ipfs/go-ipfs:v0.4.23 24 | ports: 25 | - '5001:5001' 26 | volumes: 27 | - ipfs-data:/data/ipfs 28 | postgres: 29 | image: postgres 30 | ports: 31 | - '5432:5432' 32 | command: ['postgres', '-cshared_preload_libraries=pg_stat_statements'] 33 | environment: 34 | POSTGRES_USER: graph-node 35 | POSTGRES_PASSWORD: let-me-in 36 | POSTGRES_DB: graph-node 37 | volumes: 38 | - postgres-data:/var/lib/postgresql/data 39 | 40 | volumes: 41 | ipfs-data: 42 | postgres-data: 43 | -------------------------------------------------------------------------------- /examples/cosmos-validator-rewards/docker-compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | graph-node: 3 | image: graphprotocol/graph-node:v0.32.0 4 | ports: 5 | - '8000:8000' 6 | - '8001:8001' 7 | - '8020:8020' 8 | - '8030:8030' 9 | - '8040:8040' 10 | depends_on: 11 | - ipfs 12 | - postgres 13 | environment: 14 | postgres_host: postgres 15 | postgres_user: graph-node 16 | postgres_pass: let-me-in 17 | postgres_db: graph-node 18 | ipfs: 'ipfs:5001' 19 | # Change next line if you want to connect to a different JSON-RPC endpoint 20 | ethereum: 'mainnet:http://host.docker.internal:8545' 21 | GRAPH_LOG: info 22 | ipfs: 23 | image: ipfs/go-ipfs:v0.4.23 24 | ports: 25 | - '5001:5001' 26 | volumes: 27 | - ipfs-data:/data/ipfs 28 | postgres: 29 | image: postgres 30 | ports: 31 | - '5432:5432' 32 | command: ['postgres', '-cshared_preload_libraries=pg_stat_statements'] 33 | environment: 34 | POSTGRES_USER: graph-node 35 | POSTGRES_PASSWORD: let-me-in 36 | POSTGRES_DB: graph-node 37 | volumes: 38 | - postgres-data:/var/lib/postgresql/data 39 | 40 | volumes: 41 | ipfs-data: 42 | postgres-data: 43 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/duplicate-data-source-name/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.1 2 | repository: https://github.com/graphprotocol/test-subgraph 3 | description: Test subgraph 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: ethereum/contract 8 | name: ExampleSubgraph 9 | source: 10 | abi: ExampleContract 11 | mapping: 12 | kind: ethereum/events 13 | apiVersion: 0.0.5 14 | language: wasm/assemblyscript 15 | file: ./mapping.ts 16 | entities: 17 | - ExampleEntity 18 | abis: 19 | - name: ExampleContract 20 | file: ./Abi.json 21 | eventHandlers: 22 | - event: ExampleEvent(string) 23 | handler: handleExampleEvent 24 | - kind: ethereum/contract 25 | name: ExampleSubgraph 26 | source: 27 | abi: ExampleContract 28 | mapping: 29 | kind: ethereum/events 30 | apiVersion: 0.0.5 31 | language: wasm/assemblyscript 32 | file: ./mapping.ts 33 | entities: 34 | - ExampleEntity 35 | abis: 36 | - name: ExampleContract 37 | file: ./Abi.json 38 | eventHandlers: 39 | - event: ExampleEvent(string) 40 | handler: handleExampleEvent 41 | -------------------------------------------------------------------------------- /examples/cosmos-osmosis-token-swaps/README.md: -------------------------------------------------------------------------------- 1 | # Osmosis Token Swaps Example 2 | 3 | This example subgraph stores `TokenSwap` objects that represent token swaps made using the 4 | [GAMM](https://docs.osmosis.zone/developing/osmosis-core/modules/spec-gamm.html) (Generalized 5 | Automated Market Maker) in the Osmosis chain. In order to do that, an event handler is used to 6 | filter 7 | [token_swapped](https://github.com/osmosis-labs/osmosis/blob/c8ac95c6a6ea42e934d49599eafc8609b3c6fe61/x/gamm/types/events.go#L13) 8 | events. The type of event to be filtered is specified in the subgraph manifest file. That way, the 9 | handler will just receive events of that type. 10 | 11 | By running this example subgraph, and with the following query, you can retrieve all the swaps made 12 | by a given address: 13 | 14 | ``` 15 | query SwapsForAccount($senderAddress: String!) { 16 | tokenSwaps(where: {sender: $senderAddress}) { 17 | tokenIn { 18 | amount 19 | denom 20 | }, 21 | tokenOut { 22 | amount 23 | denom 24 | } 25 | } 26 | } 27 | ``` 28 | 29 | ``` 30 | { 31 | "senderAddress": "osmo1wd3j7cvcnr3pfey4fx2mz9xml9euu68z6zg0xp" 32 | } 33 | ``` 34 | 35 | For more information see the docs on https://thegraph.com/docs/. 36 | -------------------------------------------------------------------------------- /examples/near-blocks/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | 63 | build/* 64 | generated/* 65 | -------------------------------------------------------------------------------- /examples/near-receipts/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | 63 | generated/ 64 | build/ 65 | -------------------------------------------------------------------------------- /website/src/lib/ipfs.ts: -------------------------------------------------------------------------------- 1 | import { create } from 'kubo-rpc-client'; 2 | 3 | const ipfsClient = create({ 4 | url: 'https://api.thegraph.com/ipfs/api/v0', 5 | }); 6 | 7 | export async function uploadFileToIpfs(file: { path: string; content: Buffer }) { 8 | try { 9 | const files = ipfsClient.addAll([file]); 10 | 11 | // We get back async iterable 12 | const filesIterator = files[Symbol.asyncIterator](); 13 | // We only care about the first item, since that is the file, rest could be directories 14 | const { value } = await filesIterator.next(); 15 | 16 | // we grab the file and pin it 17 | const uploadedFile = value as Awaited>; 18 | await ipfsClient.pin.add(uploadedFile.cid); 19 | 20 | return uploadedFile.cid.toString(); 21 | } catch (e) { 22 | // @ts-expect-error - we are throwing an error here 23 | throw Error(`Failed to upload file to IPFS: ${e?.message || e}`); 24 | } 25 | } 26 | 27 | export async function readIpfsFile(cid: string) { 28 | const file = ipfsClient.cat(cid); 29 | 30 | const chunks: Uint8Array[] = []; 31 | for await (const chunk of file) { 32 | chunks.push(chunk); 33 | } 34 | 35 | return Buffer.concat(chunks).toString('utf-8'); 36 | } 37 | -------------------------------------------------------------------------------- /examples/cosmos-block-filtering/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /generated/ 3 | 4 | # Logs 5 | logs 6 | *.log 7 | npm-debug.log* 8 | yarn-debug.log* 9 | yarn-error.log* 10 | 11 | # Runtime data 12 | pids 13 | *.pid 14 | *.seed 15 | *.pid.lock 16 | 17 | # Directory for instrumented libs generated by jscoverage/JSCover 18 | lib-cov 19 | 20 | # Coverage directory used by tools like istanbul 21 | coverage 22 | 23 | # nyc test coverage 24 | .nyc_output 25 | 26 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 27 | .grunt 28 | 29 | # Bower dependency directory (https://bower.io/) 30 | bower_components 31 | 32 | # node-waf configuration 33 | .lock-wscript 34 | 35 | # Compiled binary addons (https://nodejs.org/api/addons.html) 36 | build/Release 37 | 38 | # Dependency directories 39 | node_modules/ 40 | jspm_packages/ 41 | 42 | # TypeScript v1 declaration files 43 | typings/ 44 | 45 | # Optional npm cache directory 46 | .npm 47 | 48 | # Optional eslint cache 49 | .eslintcache 50 | 51 | # Optional REPL history 52 | .node_repl_history 53 | 54 | # Output of 'npm pack' 55 | *.tgz 56 | 57 | # Yarn Integrity file 58 | .yarn-integrity 59 | 60 | # dotenv environment variables file 61 | .env 62 | 63 | # next.js build output 64 | .next 65 | -------------------------------------------------------------------------------- /packages/cli/src/protocols/file_template.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | 3 | import immutable from 'immutable'; 4 | import * as tsCodegen from '../codegen/typescript.js'; 5 | 6 | export default class FileTemplateCodeGen { 7 | constructor(private template: immutable.Map) { 8 | this.template = template; 9 | } 10 | 11 | generateModuleImports() { 12 | return []; 13 | } 14 | 15 | generateCreateMethod() { 16 | const name = this.template.get('name'); 17 | 18 | return tsCodegen.staticMethod( 19 | 'create', 20 | [tsCodegen.param('cid', tsCodegen.namedType('string'))], 21 | tsCodegen.namedType('void'), 22 | ` 23 | DataSourceTemplate.create('${name}', [cid]) 24 | `, 25 | ); 26 | } 27 | 28 | generateCreateWithContextMethod() { 29 | const name = this.template.get('name'); 30 | 31 | return tsCodegen.staticMethod( 32 | 'createWithContext', 33 | [ 34 | tsCodegen.param('cid', tsCodegen.namedType('string')), 35 | tsCodegen.param('context', tsCodegen.namedType('DataSourceContext')), 36 | ], 37 | tsCodegen.namedType('void'), 38 | ` 39 | DataSourceTemplate.createWithContext('${name}', [cid], context) 40 | `, 41 | ); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /examples/arweave-blocks-transactions/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | generated/ 3 | 4 | # Logs 5 | logs 6 | *.log 7 | npm-debug.log* 8 | yarn-debug.log* 9 | yarn-error.log* 10 | 11 | # Runtime data 12 | pids 13 | *.pid 14 | *.seed 15 | *.pid.lock 16 | 17 | # Directory for instrumented libs generated by jscoverage/JSCover 18 | lib-cov 19 | 20 | # Coverage directory used by tools like istanbul 21 | coverage 22 | 23 | # nyc test coverage 24 | .nyc_output 25 | 26 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 27 | .grunt 28 | 29 | # Bower dependency directory (https://bower.io/) 30 | bower_components 31 | 32 | # node-waf configuration 33 | .lock-wscript 34 | 35 | # Compiled binary addons (https://nodejs.org/api/addons.html) 36 | build/Release 37 | 38 | # Dependency directories 39 | node_modules/ 40 | jspm_packages/ 41 | 42 | # TypeScript v1 declaration files 43 | typings/ 44 | 45 | # Optional npm cache directory 46 | .npm 47 | 48 | # Optional eslint cache 49 | .eslintcache 50 | 51 | # Optional REPL history 52 | .node_repl_history 53 | 54 | # Output of 'npm pack' 55 | *.tgz 56 | 57 | # Yarn Integrity file 58 | .yarn-integrity 59 | 60 | # dotenv environment variables file 61 | .env 62 | 63 | # next.js build output 64 | .next 65 | -------------------------------------------------------------------------------- /examples/cosmos-osmosis-token-swaps/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | generated/ 3 | 4 | # Logs 5 | logs 6 | *.log 7 | npm-debug.log* 8 | yarn-debug.log* 9 | yarn-error.log* 10 | 11 | # Runtime data 12 | pids 13 | *.pid 14 | *.seed 15 | *.pid.lock 16 | 17 | # Directory for instrumented libs generated by jscoverage/JSCover 18 | lib-cov 19 | 20 | # Coverage directory used by tools like istanbul 21 | coverage 22 | 23 | # nyc test coverage 24 | .nyc_output 25 | 26 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 27 | .grunt 28 | 29 | # Bower dependency directory (https://bower.io/) 30 | bower_components 31 | 32 | # node-waf configuration 33 | .lock-wscript 34 | 35 | # Compiled binary addons (https://nodejs.org/api/addons.html) 36 | build/Release 37 | 38 | # Dependency directories 39 | node_modules/ 40 | jspm_packages/ 41 | 42 | # TypeScript v1 declaration files 43 | typings/ 44 | 45 | # Optional npm cache directory 46 | .npm 47 | 48 | # Optional eslint cache 49 | .eslintcache 50 | 51 | # Optional REPL history 52 | .node_repl_history 53 | 54 | # Output of 'npm pack' 55 | *.tgz 56 | 57 | # Yarn Integrity file 58 | .yarn-integrity 59 | 60 | # dotenv environment variables file 61 | .env 62 | 63 | # next.js build output 64 | .next 65 | -------------------------------------------------------------------------------- /examples/cosmos-validator-rewards/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /generated/ 3 | 4 | # Logs 5 | logs 6 | *.log 7 | npm-debug.log* 8 | yarn-debug.log* 9 | yarn-error.log* 10 | 11 | # Runtime data 12 | pids 13 | *.pid 14 | *.seed 15 | *.pid.lock 16 | 17 | # Directory for instrumented libs generated by jscoverage/JSCover 18 | lib-cov 19 | 20 | # Coverage directory used by tools like istanbul 21 | coverage 22 | 23 | # nyc test coverage 24 | .nyc_output 25 | 26 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 27 | .grunt 28 | 29 | # Bower dependency directory (https://bower.io/) 30 | bower_components 31 | 32 | # node-waf configuration 33 | .lock-wscript 34 | 35 | # Compiled binary addons (https://nodejs.org/api/addons.html) 36 | build/Release 37 | 38 | # Dependency directories 39 | node_modules/ 40 | jspm_packages/ 41 | 42 | # TypeScript v1 declaration files 43 | typings/ 44 | 45 | # Optional npm cache directory 46 | .npm 47 | 48 | # Optional eslint cache 49 | .eslintcache 50 | 51 | # Optional REPL history 52 | .node_repl_history 53 | 54 | # Output of 'npm pack' 55 | *.tgz 56 | 57 | # Yarn Integrity file 58 | .yarn-integrity 59 | 60 | # dotenv environment variables file 61 | .env 62 | 63 | # next.js build output 64 | .next 65 | -------------------------------------------------------------------------------- /examples/cosmos-validator-delegations/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /generated/ 3 | 4 | # Logs 5 | logs 6 | *.log 7 | npm-debug.log* 8 | yarn-debug.log* 9 | yarn-error.log* 10 | 11 | # Runtime data 12 | pids 13 | *.pid 14 | *.seed 15 | *.pid.lock 16 | 17 | # Directory for instrumented libs generated by jscoverage/JSCover 18 | lib-cov 19 | 20 | # Coverage directory used by tools like istanbul 21 | coverage 22 | 23 | # nyc test coverage 24 | .nyc_output 25 | 26 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 27 | .grunt 28 | 29 | # Bower dependency directory (https://bower.io/) 30 | bower_components 31 | 32 | # node-waf configuration 33 | .lock-wscript 34 | 35 | # Compiled binary addons (https://nodejs.org/api/addons.html) 36 | build/Release 37 | 38 | # Dependency directories 39 | node_modules/ 40 | jspm_packages/ 41 | 42 | # TypeScript v1 declaration files 43 | typings/ 44 | 45 | # Optional npm cache directory 46 | .npm 47 | 48 | # Optional eslint cache 49 | .eslintcache 50 | 51 | # Optional REPL history 52 | .node_repl_history 53 | 54 | # Output of 'npm pack' 55 | *.tgz 56 | 57 | # Yarn Integrity file 58 | .yarn-integrity 59 | 60 | # dotenv environment variables file 61 | .env 62 | 63 | # next.js build output 64 | .next 65 | -------------------------------------------------------------------------------- /packages/cli/tests/cli/validation/abi-not-found/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.1 2 | schema: 3 | file: ./schema.graphql 4 | dataSources: 5 | - kind: ethereum/contract 6 | name: DataSource 7 | source: 8 | address: '0x22843e74c59580b3eaf6c233fa67d8b7c561a835' 9 | abi: NonExistentAbi 10 | mapping: 11 | kind: ethereum/events 12 | apiVersion: 0.0.5 13 | language: wasm/assemblyscript 14 | file: ./mapping.ts 15 | entities: 16 | - ExampleEntity 17 | abis: 18 | - name: FirstAbi 19 | file: ./Abi.json 20 | - name: SecondAbi 21 | file: ./Abi.json 22 | eventHandlers: 23 | - event: ExampleEvent(string) 24 | handler: handleExampleEvent 25 | templates: 26 | - kind: ethereum/contract 27 | name: ExampleTemplate 28 | source: 29 | abi: ExampleContract 30 | mapping: 31 | kind: ethereum/events 32 | apiVersion: 0.0.5 33 | language: wasm/assemblyscript 34 | file: ./mapping.ts 35 | entities: 36 | - ExampleEntity 37 | abis: 38 | - name: ExampleContract 39 | file: ./Abi.json 40 | eventHandlers: 41 | - event: ExampleEvent(string,uint256) 42 | handler: handleExampleEvent 43 | -------------------------------------------------------------------------------- /examples/cosmos-block-filtering/README.md: -------------------------------------------------------------------------------- 1 | # Block Filtering Example 2 | 3 | This example subgraph stores `Block` objects that represent blocks appended to a Cosmos chain. It's 4 | a very simple implementation where just the block number and the block timestamp is saved to the 5 | store. 6 | 7 | ## Generating a manifest 8 | 9 | The subgraph is compatible with multiple Cosmos networks so before building the subgraph you need to 10 | generate a manifest file for the network of your choice. In case of the Cosmos Hub network, run the 11 | following command: 12 | 13 | ```shell 14 | $ yarn prepare:cosmoshub 15 | ``` 16 | 17 | For the list of supported networks, see the scripts in the [`package.json`](package.json) file. 18 | 19 | ## Querying the subgraph 20 | 21 | With the following query, you can retrieve all the appended blocks between two dates: 22 | 23 | ``` 24 | query BlocksBetweenDates($timestamp_start: BigInt!, $timestamp_end: BigInt!) { 25 | blocks(where: {timestamp_gt: $timestamp_start, timestamp_lt: $timestamp_end}) { 26 | id, 27 | number, 28 | timestamp 29 | } 30 | } 31 | ``` 32 | 33 | ``` 34 | { 35 | "timestamp_start": 1613653200, 36 | "timestamp_end": 1613656800 37 | } 38 | ``` 39 | 40 | For more information see the docs on https://thegraph.com/docs/. 41 | -------------------------------------------------------------------------------- /packages/cli/src/protocols/ethereum/codegen/template.ts: -------------------------------------------------------------------------------- 1 | import immutable from 'immutable'; 2 | import * as tsCodegen from '../../../codegen/typescript.js'; 3 | 4 | export default class EthereumTemplateCodeGen { 5 | constructor(public template: immutable.Map) { 6 | this.template = template; 7 | } 8 | 9 | generateModuleImports() { 10 | return ['Address']; 11 | } 12 | 13 | generateCreateMethod() { 14 | const name = this.template.get('name'); 15 | 16 | return tsCodegen.staticMethod( 17 | 'create', 18 | [tsCodegen.param('address', tsCodegen.namedType('Address'))], 19 | tsCodegen.namedType('void'), 20 | ` 21 | DataSourceTemplate.create('${name}', [address.toHex()]) 22 | `, 23 | ); 24 | } 25 | 26 | generateCreateWithContextMethod() { 27 | const name = this.template.get('name'); 28 | 29 | return tsCodegen.staticMethod( 30 | 'createWithContext', 31 | [ 32 | tsCodegen.param('address', tsCodegen.namedType('Address')), 33 | tsCodegen.param('context', tsCodegen.namedType('DataSourceContext')), 34 | ], 35 | tsCodegen.namedType('void'), 36 | ` 37 | DataSourceTemplate.createWithContext('${name}', [address.toHex()], context) 38 | `, 39 | ); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /packages/cli/src/commands/clean.ts: -------------------------------------------------------------------------------- 1 | import { filesystem, print } from 'gluegun'; 2 | import { Command, Flags } from '@oclif/core'; 3 | 4 | export default class CleanCommand extends Command { 5 | static description = 'Clean the cache and generated files.'; 6 | 7 | static flags = { 8 | help: Flags.help({ 9 | char: 'h', 10 | }), 11 | 'codegen-dir': Flags.directory({ 12 | summary: 'Directory where the "graph codegen" code is stored.', 13 | default: 'generated/', 14 | }), 15 | 'build-dir': Flags.directory({ 16 | summary: 'Directory where the "graph build" code is stored.', 17 | default: 'build/', 18 | }), 19 | }; 20 | 21 | async run() { 22 | const { 23 | flags: { 'codegen-dir': codegenDir, 'build-dir': buildDir }, 24 | } = await this.parse(CleanCommand); 25 | const spinner = print.spin(`Cleaning cache and generated files`); 26 | 27 | spinner.start(); 28 | try { 29 | await filesystem.removeAsync(codegenDir); 30 | await filesystem.removeAsync(buildDir); 31 | spinner.succeed(); 32 | print.success('Cache and generated files cleaned'); 33 | } catch (e) { 34 | spinner.fail('Failed to clean cache and generated files'); 35 | } finally { 36 | spinner.stop(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /packages/ts/test/bytes.ts: -------------------------------------------------------------------------------- 1 | import { ByteArray, Bytes } from './temp_lib/index'; 2 | 3 | // Test some Bytes methods. 4 | export function testBytesWithByteArray(): void { 5 | const longArray = new ByteArray(5); 6 | longArray[0] = 251; 7 | longArray[1] = 255; 8 | longArray[2] = 251; 9 | longArray[3] = 255; 10 | longArray[4] = 0; 11 | assert(longArray.toU32() == 4_294_705_147); 12 | assert(longArray.toI32() == 4_294_705_147); 13 | 14 | const bytes = Bytes.fromHexString('0x56696b746f726961'); 15 | assert((bytes[0] = 0x56)); 16 | assert((bytes[1] = 0x69)); 17 | assert((bytes[2] = 0x6b)); 18 | assert((bytes[3] = 0x74)); 19 | assert((bytes[4] = 0x6f)); 20 | assert((bytes[5] = 0x72)); 21 | assert((bytes[6] = 0x69)); 22 | assert((bytes[7] = 0x61)); 23 | 24 | // eslint-disable-next-line no-self-compare 25 | assert(ByteArray.fromI32(1) == ByteArray.fromI32(1)); 26 | assert(ByteArray.fromI32(1) != ByteArray.fromI32(2)); 27 | } 28 | 29 | export function testBytesFromUTF8(): void { 30 | // [123, 32, 34, 104, 101, 108, 108, 111, 34, 58, 32, 34, 119, 111, 114, 108, 100, 34, 32, 125] 31 | const str = '{ "hello": "world" }'; 32 | 33 | const bytes = Bytes.fromUTF8(str); 34 | 35 | for (let i = 0; i < bytes.length; i++) { 36 | assert(bytes[i] == str.charCodeAt(i)); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /website/src/components/wallet-provider.tsx: -------------------------------------------------------------------------------- 1 | import { ConnectKitProvider, getDefaultConfig } from 'connectkit'; 2 | import { createConfig, http, WagmiProvider } from 'wagmi'; 3 | import { arbitrum, arbitrumSepolia } from 'wagmi/chains'; 4 | import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; 5 | 6 | const queryClient = new QueryClient(); 7 | 8 | const config = createConfig( 9 | getDefaultConfig({ 10 | // Your dApps chains 11 | chains: [arbitrum, arbitrumSepolia], 12 | transports: { 13 | [arbitrum.id]: http(), 14 | [arbitrumSepolia.id]: http(), 15 | }, 16 | walletConnectProjectId: import.meta.env.VITE_WALLETCONNECT_PROJECT_ID ?? '1', 17 | // Required App Info 18 | appName: 'Graph Tooling', 19 | 20 | // Optional App Info 21 | appDescription: 'Permissionless deploy for subgraphs', 22 | appUrl: 'https://cli.thegraph.com', 23 | appIcon: 'https://storage.googleapis.com/graph-web/favicon.png', 24 | }), 25 | ); 26 | 27 | export function WalletProvider({ children }: { children: React.ReactNode }) { 28 | return ( 29 | 30 | 31 | {children} 32 | 33 | 34 | ); 35 | } 36 | -------------------------------------------------------------------------------- /examples/cosmos-validator-delegations/src/mapping.ts: -------------------------------------------------------------------------------- 1 | import { cosmos } from '@graphprotocol/graph-ts'; 2 | import { Coin, Delegation } from '../generated/schema'; 3 | import { decodeMsgDelegate, MsgCoin, MsgDelegate } from './decoding'; 4 | 5 | export function handleTx(data: cosmos.TransactionData): void { 6 | const id = `${data.block.header.hash.toHexString()}-${data.tx.index}`; 7 | const messages = data.tx.tx.body.messages; 8 | 9 | for (let i = 0; i < messages.length; i++) { 10 | let msgType = messages[i].typeUrl; 11 | let msgValue = messages[i].value as Uint8Array; 12 | 13 | if (msgType == '/cosmos.staking.v1beta1.MsgDelegate') { 14 | saveDelegation(id, decodeMsgDelegate(msgValue)); // The message needs to be decoded to access its attributes. 15 | } 16 | } 17 | } 18 | 19 | function saveDelegation(id: string, message: MsgDelegate): void { 20 | const msg = new Delegation(id); 21 | 22 | msg.delegatorAddress = message.delegator_address; 23 | msg.validatorAddress = message.validator_address; 24 | msg.amount = saveCoin(id, message.amount as MsgCoin); 25 | 26 | msg.save(); 27 | } 28 | 29 | function saveCoin(id: string, c: MsgCoin): string { 30 | const coin = new Coin(id); 31 | 32 | coin.amount = c.amount; 33 | coin.denom = c.denom; 34 | 35 | coin.save(); 36 | 37 | return id; 38 | } 39 | --------------------------------------------------------------------------------