@graphprotocol/graph-cli 0.37.3 → 0.37.4-alpha-20230117095424-b5750b1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/bin.js +6 -0
- package/dist/cli.js +26 -0
- package/dist/codegen/schema.js +244 -0
- package/dist/codegen/schema.test.js +455 -0
- package/dist/codegen/template.js +66 -0
- package/dist/codegen/types/conversions.js +335 -0
- package/dist/codegen/types/index.js +71 -0
- package/dist/codegen/types/index.test.js +563 -0
- package/dist/codegen/typescript.js +200 -0
- package/dist/codegen/util.js +40 -0
- package/dist/codegen/util.test.js +93 -0
- package/dist/command-helpers/abi.js +76 -0
- package/dist/command-helpers/auth.js +76 -0
- package/dist/command-helpers/compiler.js +66 -0
- package/dist/command-helpers/data-sources.js +29 -0
- package/dist/command-helpers/fs.js +9 -0
- package/dist/command-helpers/gluegun.js +48 -0
- package/dist/command-helpers/ipfs.js +5 -0
- package/dist/command-helpers/jsonrpc.js +27 -0
- package/dist/command-helpers/network.js +90 -0
- package/dist/command-helpers/network.test.js +86 -0
- package/dist/command-helpers/node.js +40 -0
- package/dist/command-helpers/scaffold.js +110 -0
- package/dist/command-helpers/spinner.js +80 -0
- package/dist/command-helpers/studio.js +14 -0
- package/dist/command-helpers/studio.test.js +41 -0
- package/dist/command-helpers/subgraph.js +22 -0
- package/dist/command-helpers/version.js +66 -0
- package/dist/command-helpers/version.test.js +186 -0
- package/dist/commands/add.js +187 -0
- package/dist/commands/auth.js +122 -0
- package/dist/commands/build.js +136 -0
- package/dist/commands/codegen.js +128 -0
- package/dist/commands/create.js +94 -0
- package/dist/commands/deploy.js +335 -0
- package/dist/commands/init.js +800 -0
- package/dist/commands/local.js +380 -0
- package/dist/commands/remove.js +95 -0
- package/dist/commands/test.js +293 -0
- package/dist/compiler/asc.js +83 -0
- package/dist/compiler/index.js +466 -0
- package/dist/debug.js +16 -0
- package/dist/migrations/mapping_api_version_0_0_1.js +83 -0
- package/dist/migrations/mapping_api_version_0_0_2.js +83 -0
- package/dist/migrations/mapping_api_version_0_0_3.js +83 -0
- package/dist/migrations/mapping_api_version_0_0_4.js +85 -0
- package/dist/migrations/mapping_api_version_0_0_5.js +85 -0
- package/dist/migrations/spec_version_0_0_2.js +45 -0
- package/dist/migrations/spec_version_0_0_3.js +50 -0
- package/dist/migrations/util/load-manifest.js +16 -0
- package/dist/migrations/util/versions.js +28 -0
- package/dist/migrations.js +54 -0
- package/{src → dist}/protocols/arweave/manifest.graphql +0 -0
- package/{src/protocols/arweave/scaffold/manifest.ts → dist/protocols/arweave/scaffold/manifest.js} +7 -3
- package/{src/protocols/arweave/scaffold/mapping.ts → dist/protocols/arweave/scaffold/mapping.js} +5 -2
- package/dist/protocols/arweave/subgraph.js +23 -0
- package/dist/protocols/contract.js +2 -0
- package/{src → dist}/protocols/cosmos/manifest.graphql +0 -0
- package/dist/protocols/cosmos/scaffold/manifest.js +15 -0
- package/{src/protocols/cosmos/scaffold/mapping.ts → dist/protocols/cosmos/scaffold/mapping.js} +5 -2
- package/dist/protocols/cosmos/subgraph.js +28 -0
- package/dist/protocols/ethereum/abi.js +138 -0
- package/dist/protocols/ethereum/codegen/abi.js +474 -0
- package/dist/protocols/ethereum/codegen/abi.test.js +325 -0
- package/dist/protocols/ethereum/codegen/template.js +52 -0
- package/dist/protocols/ethereum/contract.js +22 -0
- package/{src → dist}/protocols/ethereum/manifest.graphql +0 -0
- package/dist/protocols/ethereum/scaffold/manifest.js +32 -0
- package/{src/protocols/ethereum/scaffold/mapping.ts → dist/protocols/ethereum/scaffold/mapping.js} +18 -29
- package/dist/protocols/ethereum/subgraph.js +172 -0
- package/dist/protocols/ethereum/type-generator.js +123 -0
- package/dist/protocols/index.js +266 -0
- package/dist/protocols/ipfs/codegen/file_template.js +53 -0
- package/dist/protocols/near/contract.js +41 -0
- package/{src → dist}/protocols/near/manifest.graphql +0 -0
- package/dist/protocols/near/scaffold/manifest.js +16 -0
- package/{src/protocols/near/scaffold/mapping.ts → dist/protocols/near/scaffold/mapping.js} +5 -2
- package/dist/protocols/near/subgraph.js +23 -0
- package/dist/protocols/subgraph.js +2 -0
- package/{src → dist}/protocols/substreams/manifest.graphql +0 -0
- package/dist/protocols/substreams/scaffold/manifest.js +12 -0
- package/dist/protocols/substreams/subgraph.js +23 -0
- package/{src/scaffold/cosmos.test.ts → dist/scaffold/cosmos.test.js} +21 -22
- package/{src/scaffold/ethereum.test.ts → dist/scaffold/ethereum.test.js} +85 -101
- package/dist/scaffold/index.js +133 -0
- package/dist/scaffold/mapping.js +57 -0
- package/{src/scaffold/near.test.ts → dist/scaffold/near.test.js} +22 -23
- package/dist/scaffold/schema.js +86 -0
- package/dist/scaffold/tests.js +179 -0
- package/dist/schema.js +54 -0
- package/dist/subgraph.js +243 -0
- package/dist/type-generator.js +225 -0
- package/dist/validation/contract.js +44 -0
- package/dist/validation/index.js +10 -0
- package/dist/validation/manifest.js +266 -0
- package/dist/validation/schema.js +768 -0
- package/dist/validation/schema.test.js +35 -0
- package/dist/watcher.js +79 -0
- package/package.json +5 -1
- package/babel.config.js +0 -3
- package/jest.config.js +0 -175
- package/src/bin.ts +0 -6
- package/src/cli.ts +0 -30
- package/src/codegen/schema.test.ts +0 -460
- package/src/codegen/schema.ts +0 -299
- package/src/codegen/template.ts +0 -45
- package/src/codegen/types/conversions.ts +0 -358
- package/src/codegen/types/index.test.ts +0 -715
- package/src/codegen/types/index.ts +0 -111
- package/src/codegen/typescript.ts +0 -224
- package/src/codegen/util.test.ts +0 -112
- package/src/codegen/util.ts +0 -54
- package/src/command-helpers/abi.ts +0 -99
- package/src/command-helpers/auth.ts +0 -46
- package/src/command-helpers/compiler.ts +0 -60
- package/src/command-helpers/data-sources.ts +0 -36
- package/src/command-helpers/fs.ts +0 -5
- package/src/command-helpers/gluegun.ts +0 -52
- package/src/command-helpers/ipfs-http-client.d.ts +0 -1
- package/src/command-helpers/ipfs.ts +0 -3
- package/src/command-helpers/jsonrpc.ts +0 -22
- package/src/command-helpers/network.test.ts +0 -85
- package/src/command-helpers/network.ts +0 -133
- package/src/command-helpers/node.ts +0 -46
- package/src/command-helpers/scaffold.ts +0 -174
- package/src/command-helpers/spinner.ts +0 -60
- package/src/command-helpers/studio.test.ts +0 -84
- package/src/command-helpers/studio.ts +0 -25
- package/src/command-helpers/subgraph.ts +0 -21
- package/src/command-helpers/version.test.ts +0 -241
- package/src/command-helpers/version.ts +0 -53
- package/src/commands/add.ts +0 -220
- package/src/commands/auth.ts +0 -138
- package/src/commands/binary-install-raw.d.ts +0 -1
- package/src/commands/build.ts +0 -147
- package/src/commands/codegen.ts +0 -123
- package/src/commands/create.ts +0 -109
- package/src/commands/deploy.ts +0 -388
- package/src/commands/init.ts +0 -1060
- package/src/commands/local.ts +0 -539
- package/src/commands/remove.ts +0 -110
- package/src/commands/test.ts +0 -369
- package/src/compiler/asc.ts +0 -77
- package/src/compiler/index.ts +0 -677
- package/src/debug.ts +0 -15
- package/src/migrations/mapping_api_version_0_0_1.ts +0 -75
- package/src/migrations/mapping_api_version_0_0_2.ts +0 -75
- package/src/migrations/mapping_api_version_0_0_3.ts +0 -75
- package/src/migrations/mapping_api_version_0_0_4.ts +0 -77
- package/src/migrations/mapping_api_version_0_0_5.ts +0 -77
- package/src/migrations/spec_version_0_0_2.ts +0 -24
- package/src/migrations/spec_version_0_0_3.ts +0 -29
- package/src/migrations/util/load-manifest.ts +0 -10
- package/src/migrations/util/versions.ts +0 -27
- package/src/migrations.ts +0 -33
- package/src/protocols/arweave/subgraph.ts +0 -22
- package/src/protocols/contract.ts +0 -9
- package/src/protocols/cosmos/scaffold/manifest.ts +0 -11
- package/src/protocols/cosmos/subgraph.ts +0 -27
- package/src/protocols/ethereum/abi.ts +0 -153
- package/src/protocols/ethereum/codegen/abi.test.ts +0 -330
- package/src/protocols/ethereum/codegen/abi.ts +0 -719
- package/src/protocols/ethereum/codegen/template.ts +0 -41
- package/src/protocols/ethereum/contract.ts +0 -24
- package/src/protocols/ethereum/scaffold/manifest.ts +0 -28
- package/src/protocols/ethereum/subgraph.ts +0 -189
- package/src/protocols/ethereum/type-generator.ts +0 -191
- package/src/protocols/index.ts +0 -287
- package/src/protocols/ipfs/codegen/file_template.ts +0 -43
- package/src/protocols/near/contract.ts +0 -47
- package/src/protocols/near/scaffold/manifest.ts +0 -13
- package/src/protocols/near/subgraph.ts +0 -22
- package/src/protocols/subgraph.ts +0 -12
- package/src/protocols/substreams/scaffold/manifest.ts +0 -8
- package/src/protocols/substreams/subgraph.ts +0 -22
- package/src/scaffold/index.ts +0 -172
- package/src/scaffold/mapping.ts +0 -44
- package/src/scaffold/schema.ts +0 -89
- package/src/scaffold/tests.ts +0 -217
- package/src/schema.ts +0 -26
- package/src/subgraph.ts +0 -302
- package/src/type-generator.ts +0 -266
- package/src/validation/contract.ts +0 -51
- package/src/validation/index.ts +0 -5
- package/src/validation/manifest.ts +0 -360
- package/src/validation/schema.test.ts +0 -38
- package/src/validation/schema.ts +0 -957
- package/src/watcher.ts +0 -96
- package/tests/cli/globalSetup.ts +0 -8
- package/tests/cli/globalTeardown.ts +0 -8
- package/tests/cli/init/ethereum/abis/Marketplace.json +0 -408
- package/tests/cli/init/ethereum/abis/OverloadedElements.json +0 -91
- package/tests/cli/init/ethereum/abis/SoloMargin.json +0 -2729
- package/tests/cli/init/ethereum/from-contract-with-abi-and-structs.stderr +0 -14
- package/tests/cli/init/ethereum/from-contract-with-abi-and-structs.stdout +0 -12
- package/tests/cli/init/ethereum/from-contract-with-abi.stderr +0 -14
- package/tests/cli/init/ethereum/from-contract-with-abi.stdout +0 -12
- package/tests/cli/init/ethereum/from-contract-with-overloaded-elements.stderr +0 -14
- package/tests/cli/init/ethereum/from-contract-with-overloaded-elements.stdout +0 -12
- package/tests/cli/init/ethereum/from-contract.stderr +0 -16
- package/tests/cli/init/ethereum/from-contract.stdout +0 -12
- package/tests/cli/init/ethereum/from-example.stderr +0 -12
- package/tests/cli/init/ethereum/from-example.stdout +0 -12
- package/tests/cli/init/near/from-contract.stderr +0 -14
- package/tests/cli/init/near/from-contract.stdout +0 -12
- package/tests/cli/init.test.ts +0 -157
- package/tests/cli/spawn-command.d.ts +0 -7
- package/tests/cli/util.ts +0 -132
- package/tests/cli/validation/abi-not-found/Abi.json +0 -7
- package/tests/cli/validation/abi-not-found/mapping.ts +0 -0
- package/tests/cli/validation/abi-not-found/schema.graphql +0 -3
- package/tests/cli/validation/abi-not-found/subgraph.yaml +0 -42
- package/tests/cli/validation/abi-not-found copy.stderr +0 -13
- package/tests/cli/validation/big-decimal-is-valid/Abi.json +0 -7
- package/tests/cli/validation/big-decimal-is-valid/mapping.ts +0 -0
- package/tests/cli/validation/big-decimal-is-valid/schema.graphql +0 -4
- package/tests/cli/validation/big-decimal-is-valid/subgraph.yaml +0 -23
- package/tests/cli/validation/call-function-not-found/Abi.json +0 -57
- package/tests/cli/validation/call-function-not-found/mapping.ts +0 -0
- package/tests/cli/validation/call-function-not-found/schema.graphql +0 -3
- package/tests/cli/validation/call-function-not-found/subgraph.yaml +0 -22
- package/tests/cli/validation/call-function-not-found.stderr +0 -10
- package/tests/cli/validation/call-handler-with-tuple/Abi.json +0 -24
- package/tests/cli/validation/call-handler-with-tuple/generated/schema.ts +0 -44
- package/tests/cli/validation/call-handler-with-tuple/mapping.ts +0 -0
- package/tests/cli/validation/call-handler-with-tuple/schema.graphql +0 -3
- package/tests/cli/validation/call-handler-with-tuple/subgraph.yaml +0 -22
- package/tests/cli/validation/call-handler-with-tuple.stderr +0 -24
- package/tests/cli/validation/conflicting-network-names/Abi.json +0 -7
- package/tests/cli/validation/conflicting-network-names/mapping.ts +0 -0
- package/tests/cli/validation/conflicting-network-names/schema.graphql +0 -3
- package/tests/cli/validation/conflicting-network-names/subgraph.yaml +0 -41
- package/tests/cli/validation/conflicting-network-names.stderr +0 -10
- package/tests/cli/validation/conflicting-protocol-names/Abi.json +0 -7
- package/tests/cli/validation/conflicting-protocol-names/mapping.ts +0 -0
- package/tests/cli/validation/conflicting-protocol-names/schema.graphql +0 -3
- package/tests/cli/validation/conflicting-protocol-names/subgraph.yaml +0 -41
- package/tests/cli/validation/conflicting-protocol-names.stderr +0 -10
- package/tests/cli/validation/derived-from-target-type-missing/Abi.json +0 -6
- package/tests/cli/validation/derived-from-target-type-missing/mapping.ts +0 -0
- package/tests/cli/validation/derived-from-target-type-missing/schema.graphql +0 -4
- package/tests/cli/validation/derived-from-target-type-missing/subgraph.yaml +0 -22
- package/tests/cli/validation/derived-from-target-type-missing.stderr +0 -5
- package/tests/cli/validation/derived-from-with-interface/Gravity.json +0 -1
- package/tests/cli/validation/derived-from-with-interface/mapping.ts +0 -22
- package/tests/cli/validation/derived-from-with-interface/schema.graphql +0 -19
- package/tests/cli/validation/derived-from-with-interface/subgraph.yaml +0 -25
- package/tests/cli/validation/duplicate-data-source-name/Abi.json +0 -7
- package/tests/cli/validation/duplicate-data-source-name/mapping.ts +0 -0
- package/tests/cli/validation/duplicate-data-source-name/schema.graphql +0 -4
- package/tests/cli/validation/duplicate-data-source-name/subgraph.yaml +0 -40
- package/tests/cli/validation/duplicate-data-source-name.stderr +0 -5
- package/tests/cli/validation/duplicate-template-name/Abi.json +0 -7
- package/tests/cli/validation/duplicate-template-name/mapping.ts +0 -0
- package/tests/cli/validation/duplicate-template-name/schema.graphql +0 -4
- package/tests/cli/validation/duplicate-template-name/subgraph.yaml +0 -59
- package/tests/cli/validation/duplicate-template-name.stderr +0 -5
- package/tests/cli/validation/entity-field-args/Abi.json +0 -7
- package/tests/cli/validation/entity-field-args/mapping.ts +0 -0
- package/tests/cli/validation/entity-field-args/schema.graphql +0 -4
- package/tests/cli/validation/entity-field-args/subgraph.yaml +0 -22
- package/tests/cli/validation/entity-field-args.stderr +0 -5
- package/tests/cli/validation/ethereum-contract-without-handlers/Abi.json +0 -7
- package/tests/cli/validation/ethereum-contract-without-handlers/mapping.ts +0 -0
- package/tests/cli/validation/ethereum-contract-without-handlers/schema.graphql +0 -3
- package/tests/cli/validation/ethereum-contract-without-handlers/subgraph.yaml +0 -19
- package/tests/cli/validation/ethereum-contract-without-handlers.stderr +0 -6
- package/tests/cli/validation/event-not-found/Abi.json +0 -7
- package/tests/cli/validation/event-not-found/mapping.ts +0 -0
- package/tests/cli/validation/event-not-found/schema.graphql +0 -3
- package/tests/cli/validation/event-not-found/subgraph.yaml +0 -40
- package/tests/cli/validation/event-not-found.stderr +0 -12
- package/tests/cli/validation/example-values-found/Abi.json +0 -7
- package/tests/cli/validation/example-values-found/generated/ExampleSubgraph/ExampleContract.ts +0 -35
- package/tests/cli/validation/example-values-found/generated/schema.ts +0 -44
- package/tests/cli/validation/example-values-found/mapping.ts +0 -0
- package/tests/cli/validation/example-values-found/schema.graphql +0 -3
- package/tests/cli/validation/example-values-found/subgraph.yaml +0 -24
- package/tests/cli/validation/example-values-found.stderr +0 -34
- package/tests/cli/validation/invalid-abis/InvalidAbi.json +0 -1
- package/tests/cli/validation/invalid-abis/mapping.ts +0 -0
- package/tests/cli/validation/invalid-abis/schema.graphql +0 -3
- package/tests/cli/validation/invalid-abis/subgraph.yaml +0 -22
- package/tests/cli/validation/invalid-abis.stderr +0 -5
- package/tests/cli/validation/invalid-contract-addresses/Abi.json +0 -7
- package/tests/cli/validation/invalid-contract-addresses/mapping.ts +0 -0
- package/tests/cli/validation/invalid-contract-addresses/schema.graphql +0 -3
- package/tests/cli/validation/invalid-contract-addresses/subgraph.yaml +0 -58
- package/tests/cli/validation/invalid-contract-addresses.stderr +0 -14
- package/tests/cli/validation/invalid-data-source-template/mapping.ts +0 -0
- package/tests/cli/validation/invalid-data-source-template/schema.graphql +0 -3
- package/tests/cli/validation/invalid-data-source-template/subgraph.yaml +0 -32
- package/tests/cli/validation/invalid-data-source-template.stderr +0 -30
- package/tests/cli/validation/invalid-entity-field-types/Abi.json +0 -7
- package/tests/cli/validation/invalid-entity-field-types/mapping.ts +0 -0
- package/tests/cli/validation/invalid-entity-field-types/schema.graphql +0 -157
- package/tests/cli/validation/invalid-entity-field-types/subgraph.yaml +0 -22
- package/tests/cli/validation/invalid-entity-field-types.stderr +0 -148
- package/tests/cli/validation/invalid-fulltext-directive/Abi.json +0 -7
- package/tests/cli/validation/invalid-fulltext-directive/mapping.ts +0 -0
- package/tests/cli/validation/invalid-fulltext-directive/schema.graphql +0 -140
- package/tests/cli/validation/invalid-fulltext-directive/subgraph.yaml +0 -22
- package/tests/cli/validation/invalid-fulltext-directive.stderr +0 -32
- package/tests/cli/validation/invalid-graphql-schema/Abi.json +0 -7
- package/tests/cli/validation/invalid-graphql-schema/mapping.ts +0 -0
- package/tests/cli/validation/invalid-graphql-schema/schema.graphql +0 -8
- package/tests/cli/validation/invalid-graphql-schema/subgraph.yaml +0 -22
- package/tests/cli/validation/invalid-graphql-schema.stderr +0 -25
- package/tests/cli/validation/invalid-manifest/subgraph.yaml +0 -13
- package/tests/cli/validation/invalid-manifest-cannot-infer-protocol/subgraph.yaml +0 -12
- package/tests/cli/validation/invalid-manifest-cannot-infer-protocol.stderr +0 -5
- package/tests/cli/validation/invalid-manifest.stderr +0 -28
- package/tests/cli/validation/missing-entity-id/Abi.json +0 -7
- package/tests/cli/validation/missing-entity-id/mapping.ts +0 -0
- package/tests/cli/validation/missing-entity-id/schema.graphql +0 -3
- package/tests/cli/validation/missing-entity-id/subgraph.yaml +0 -22
- package/tests/cli/validation/missing-entity-id/types/ExampleSubgraph/ExampleContract.ts +0 -35
- package/tests/cli/validation/missing-entity-id/types/schema.ts +0 -27
- package/tests/cli/validation/missing-entity-id.stderr +0 -5
- package/tests/cli/validation/missing-or-invalid-derived-from-fields/Abi.json +0 -7
- package/tests/cli/validation/missing-or-invalid-derived-from-fields/mapping.ts +0 -0
- package/tests/cli/validation/missing-or-invalid-derived-from-fields/schema.graphql +0 -40
- package/tests/cli/validation/missing-or-invalid-derived-from-fields/subgraph.yaml +0 -22
- package/tests/cli/validation/missing-or-invalid-derived-from-fields.stderr +0 -10
- package/tests/cli/validation/missing-or-invalid-derived-from-fields.stdout +0 -0
- package/tests/cli/validation/near-is-valid/mapping.ts +0 -0
- package/tests/cli/validation/near-is-valid/schema.graphql +0 -8
- package/tests/cli/validation/near-is-valid/subgraph.yaml +0 -30
- package/tests/cli/validation/nested-template-nice-error/Abi.json +0 -7
- package/tests/cli/validation/nested-template-nice-error/mapping.ts +0 -0
- package/tests/cli/validation/nested-template-nice-error/schema.graphql +0 -3
- package/tests/cli/validation/nested-template-nice-error/subgraph.yaml +0 -35
- package/tests/cli/validation/nested-template-nice-error.stderr +0 -5
- package/tests/cli/validation/no-network-names/Abi.json +0 -7
- package/tests/cli/validation/no-network-names/mapping.ts +0 -0
- package/tests/cli/validation/no-network-names/schema.graphql +0 -3
- package/tests/cli/validation/no-network-names/subgraph.yaml +0 -40
- package/tests/cli/validation/no-network-names.stderr +0 -34
- package/tests/cli/validation/source-without-address-is-valid/Abi.json +0 -7
- package/tests/cli/validation/source-without-address-is-valid/generated/ExampleSubgraph/ExampleContract.ts +0 -35
- package/tests/cli/validation/source-without-address-is-valid/mapping.ts +0 -0
- package/tests/cli/validation/source-without-address-is-valid/schema.graphql +0 -3
- package/tests/cli/validation/source-without-address-is-valid/subgraph.yaml +0 -23
- package/tests/cli/validation/source-without-address-is-valid.stderr +0 -24
- package/tests/cli/validation/topic0-is-valid/Abi.json +0 -7
- package/tests/cli/validation/topic0-is-valid/mapping.ts +0 -0
- package/tests/cli/validation/topic0-is-valid/schema.graphql +0 -4
- package/tests/cli/validation/topic0-is-valid/subgraph.yaml +0 -24
- package/tests/cli/validation.test.ts +0 -226
- package/tsconfig.build.json +0 -4
- package/tsconfig.json +0 -19
package/src/protocols/index.ts
DELETED
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
import immutable from 'immutable';
|
|
2
|
-
import debug from '../debug';
|
|
3
|
-
import Subgraph from '../subgraph';
|
|
4
|
-
import * as ArweaveManifestScaffold from './arweave/scaffold/manifest';
|
|
5
|
-
import * as ArweaveMappingScaffold from './arweave/scaffold/mapping';
|
|
6
|
-
import ArweaveSubgraph from './arweave/subgraph';
|
|
7
|
-
import { ContractCtor } from './contract';
|
|
8
|
-
import * as CosmosManifestScaffold from './cosmos/scaffold/manifest';
|
|
9
|
-
import * as CosmosMappingScaffold from './cosmos/scaffold/mapping';
|
|
10
|
-
import CosmosSubgraph from './cosmos/subgraph';
|
|
11
|
-
import EthereumABI from './ethereum/abi';
|
|
12
|
-
import EthereumTemplateCodeGen from './ethereum/codegen/template';
|
|
13
|
-
import EthereumContract from './ethereum/contract';
|
|
14
|
-
import * as EthereumManifestScaffold from './ethereum/scaffold/manifest';
|
|
15
|
-
import * as EthereumMappingScaffold from './ethereum/scaffold/mapping';
|
|
16
|
-
import EthereumSubgraph from './ethereum/subgraph';
|
|
17
|
-
import EthereumTypeGenerator from './ethereum/type-generator';
|
|
18
|
-
import NearContract from './near/contract';
|
|
19
|
-
import * as NearManifestScaffold from './near/scaffold/manifest';
|
|
20
|
-
import * as NearMappingScaffold from './near/scaffold/mapping';
|
|
21
|
-
import NearSubgraph from './near/subgraph';
|
|
22
|
-
import { SubgraphOptions } from './subgraph';
|
|
23
|
-
import * as SubstreamsManifestScaffold from './substreams/scaffold/manifest';
|
|
24
|
-
import SubstreamsSubgraph from './substreams/subgraph';
|
|
25
|
-
|
|
26
|
-
const protocolDebug = debug('graph-cli:protocol');
|
|
27
|
-
|
|
28
|
-
export default class Protocol {
|
|
29
|
-
static fromDataSources(dataSourcesAndTemplates: any) {
|
|
30
|
-
const firstDataSourceKind = dataSourcesAndTemplates[0].kind;
|
|
31
|
-
return new Protocol(firstDataSourceKind);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
name: ProtocolName;
|
|
35
|
-
|
|
36
|
-
// TODO: should assert non null? see the constructor switch default case comment
|
|
37
|
-
config!: ProtocolConfig;
|
|
38
|
-
|
|
39
|
-
constructor(name: ProtocolName) {
|
|
40
|
-
this.name = Protocol.normalizeName(name)!;
|
|
41
|
-
|
|
42
|
-
switch (this.name) {
|
|
43
|
-
case 'arweave':
|
|
44
|
-
this.config = arweaveProtocol;
|
|
45
|
-
break;
|
|
46
|
-
case 'cosmos':
|
|
47
|
-
this.config = cosmosProtocol;
|
|
48
|
-
break;
|
|
49
|
-
case 'ethereum':
|
|
50
|
-
this.config = ethereumProtocol;
|
|
51
|
-
break;
|
|
52
|
-
case 'near':
|
|
53
|
-
this.config = nearProtocol;
|
|
54
|
-
break;
|
|
55
|
-
case 'substreams':
|
|
56
|
-
this.config = substreamsProtocol;
|
|
57
|
-
break;
|
|
58
|
-
default:
|
|
59
|
-
// Do not throw when undefined, a better error message is printed after the constructor
|
|
60
|
-
// when validating the Subgraph itself
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
static availableProtocols() {
|
|
65
|
-
return immutable.fromJS({
|
|
66
|
-
// `ethereum/contract` is kept for backwards compatibility.
|
|
67
|
-
// New networks (or protocol perhaps) shouldn't have the `/contract` anymore (unless a new case makes use of it).
|
|
68
|
-
arweave: ['arweave'],
|
|
69
|
-
ethereum: ['ethereum', 'ethereum/contract'],
|
|
70
|
-
near: ['near'],
|
|
71
|
-
cosmos: ['cosmos'],
|
|
72
|
-
substreams: ['substreams'],
|
|
73
|
-
}) as immutable.Collection<ProtocolName, string[]>;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
static availableNetworks() {
|
|
77
|
-
let networks = immutable.fromJS({
|
|
78
|
-
arweave: ['arweave-mainnet'],
|
|
79
|
-
ethereum: [
|
|
80
|
-
'mainnet',
|
|
81
|
-
'rinkeby',
|
|
82
|
-
'goerli',
|
|
83
|
-
'poa-core',
|
|
84
|
-
'poa-sokol',
|
|
85
|
-
'gnosis',
|
|
86
|
-
'matic',
|
|
87
|
-
'mumbai',
|
|
88
|
-
'fantom',
|
|
89
|
-
'fantom-testnet',
|
|
90
|
-
'bsc',
|
|
91
|
-
'chapel',
|
|
92
|
-
'clover',
|
|
93
|
-
'avalanche',
|
|
94
|
-
'fuji',
|
|
95
|
-
'celo',
|
|
96
|
-
'celo-alfajores',
|
|
97
|
-
'fuse',
|
|
98
|
-
'moonbeam',
|
|
99
|
-
'moonriver',
|
|
100
|
-
'mbase',
|
|
101
|
-
'arbitrum-one',
|
|
102
|
-
'arbitrum-rinkeby',
|
|
103
|
-
'optimism',
|
|
104
|
-
'optimism-kovan',
|
|
105
|
-
'aurora',
|
|
106
|
-
'aurora-testnet',
|
|
107
|
-
],
|
|
108
|
-
near: ['near-mainnet', 'near-testnet'],
|
|
109
|
-
cosmos: [
|
|
110
|
-
'cosmoshub-4',
|
|
111
|
-
'theta-testnet-001', // CosmosHub testnet
|
|
112
|
-
'osmosis-1',
|
|
113
|
-
'osmo-test-4', // Osmosis testnet
|
|
114
|
-
'juno-1',
|
|
115
|
-
'uni-3', // Juno testnet
|
|
116
|
-
],
|
|
117
|
-
}) as immutable.Map<'arweave' | 'ethereum' | 'near' | 'cosmos' | 'substreams', string[]>;
|
|
118
|
-
|
|
119
|
-
const allNetworks: string[] = [];
|
|
120
|
-
networks.forEach(value => {
|
|
121
|
-
allNetworks.push(...value);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
networks = networks.set('substreams', allNetworks);
|
|
125
|
-
|
|
126
|
-
return networks;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
static normalizeName(name: ProtocolName) {
|
|
130
|
-
return Protocol.availableProtocols().findKey(possibleNames => {
|
|
131
|
-
return possibleNames.includes(name);
|
|
132
|
-
})!;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
displayName() {
|
|
136
|
-
return this.config?.displayName;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Receives a data source kind, and checks if it's valid
|
|
140
|
-
// for the given protocol instance (this).
|
|
141
|
-
isValidKindName(kind: string) {
|
|
142
|
-
return Protocol.availableProtocols().get(this.name, immutable.List()).includes(kind);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
hasABIs() {
|
|
146
|
-
return this.config.abi != null;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
hasContract() {
|
|
150
|
-
return this.config.contract != null;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
hasEvents() {
|
|
154
|
-
// A problem with hasEvents usage in the codebase is that it's almost every where
|
|
155
|
-
// where used, the ABI data is actually use after the conditional, so it seems
|
|
156
|
-
// both concept are related. So internally, we map to this condition.
|
|
157
|
-
return this.hasABIs();
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
hasTemplates() {
|
|
161
|
-
return this.config.getTemplateCodeGen != null;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
hasDataSourceMappingFile() {
|
|
165
|
-
return this.getMappingScaffold() != null;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
getTypeGenerator(options: any) {
|
|
169
|
-
if (this.config == null || this.config.getTypeGenerator == null) {
|
|
170
|
-
return null;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return this.config.getTypeGenerator(options);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
getTemplateCodeGen(template: any) {
|
|
177
|
-
if (!this.hasTemplates()) {
|
|
178
|
-
throw new Error(`Template data sources with kind '${this.name}' are not supported yet`);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
return this.config.getTemplateCodeGen?.(template);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
getABI() {
|
|
185
|
-
return this.config.abi;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
getSubgraph(options: SubgraphOptions) {
|
|
189
|
-
return this.config.getSubgraph({ ...options, protocol: this });
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
getContract() {
|
|
193
|
-
return this.config.contract;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
getManifestScaffold() {
|
|
197
|
-
return this.config.manifestScaffold;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
getMappingScaffold() {
|
|
201
|
-
return this.config.mappingScaffold;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
export type ProtocolName = 'arweave' | 'ethereum' | 'near' | 'cosmos' | 'substreams';
|
|
206
|
-
|
|
207
|
-
export interface ProtocolConfig {
|
|
208
|
-
displayName: string;
|
|
209
|
-
abi?: any;
|
|
210
|
-
contract?: ContractCtor;
|
|
211
|
-
getTemplateCodeGen?: (template: any) => any;
|
|
212
|
-
getTypeGenerator?: (options: any) => any;
|
|
213
|
-
getSubgraph(options: SubgraphOptions): Subgraph;
|
|
214
|
-
manifestScaffold: any;
|
|
215
|
-
mappingScaffold: any;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
const arweaveProtocol: ProtocolConfig = {
|
|
219
|
-
displayName: 'Arweave',
|
|
220
|
-
abi: undefined,
|
|
221
|
-
contract: undefined,
|
|
222
|
-
getTemplateCodeGen: undefined,
|
|
223
|
-
getTypeGenerator: undefined,
|
|
224
|
-
getSubgraph(options) {
|
|
225
|
-
return new ArweaveSubgraph(options);
|
|
226
|
-
},
|
|
227
|
-
manifestScaffold: ArweaveManifestScaffold,
|
|
228
|
-
mappingScaffold: ArweaveMappingScaffold,
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
const cosmosProtocol: ProtocolConfig = {
|
|
232
|
-
displayName: 'Cosmos',
|
|
233
|
-
abi: undefined,
|
|
234
|
-
contract: undefined,
|
|
235
|
-
getTemplateCodeGen: undefined,
|
|
236
|
-
getTypeGenerator: undefined,
|
|
237
|
-
getSubgraph(options) {
|
|
238
|
-
return new CosmosSubgraph(options);
|
|
239
|
-
},
|
|
240
|
-
manifestScaffold: CosmosManifestScaffold,
|
|
241
|
-
mappingScaffold: CosmosMappingScaffold,
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
const ethereumProtocol: ProtocolConfig = {
|
|
245
|
-
displayName: 'Ethereum',
|
|
246
|
-
abi: EthereumABI,
|
|
247
|
-
contract: EthereumContract,
|
|
248
|
-
getTemplateCodeGen(template) {
|
|
249
|
-
return new EthereumTemplateCodeGen(template);
|
|
250
|
-
},
|
|
251
|
-
getTypeGenerator(options) {
|
|
252
|
-
return new EthereumTypeGenerator(options);
|
|
253
|
-
},
|
|
254
|
-
getSubgraph(options) {
|
|
255
|
-
return new EthereumSubgraph(options);
|
|
256
|
-
},
|
|
257
|
-
manifestScaffold: EthereumManifestScaffold,
|
|
258
|
-
mappingScaffold: EthereumMappingScaffold,
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
const nearProtocol: ProtocolConfig = {
|
|
262
|
-
displayName: 'NEAR',
|
|
263
|
-
abi: undefined,
|
|
264
|
-
contract: NearContract,
|
|
265
|
-
getTypeGenerator: undefined,
|
|
266
|
-
getTemplateCodeGen: undefined,
|
|
267
|
-
getSubgraph(options) {
|
|
268
|
-
return new NearSubgraph(options);
|
|
269
|
-
},
|
|
270
|
-
manifestScaffold: NearManifestScaffold,
|
|
271
|
-
mappingScaffold: NearMappingScaffold,
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
const substreamsProtocol: ProtocolConfig = {
|
|
275
|
-
displayName: 'Substreams',
|
|
276
|
-
abi: undefined,
|
|
277
|
-
contract: undefined,
|
|
278
|
-
getTypeGenerator: undefined,
|
|
279
|
-
getTemplateCodeGen: undefined,
|
|
280
|
-
getSubgraph(options) {
|
|
281
|
-
return new SubstreamsSubgraph(options);
|
|
282
|
-
},
|
|
283
|
-
manifestScaffold: SubstreamsManifestScaffold,
|
|
284
|
-
mappingScaffold: undefined,
|
|
285
|
-
};
|
|
286
|
-
|
|
287
|
-
protocolDebug('Available networks %M', Protocol.availableNetworks());
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
|
|
3
|
-
import immutable from 'immutable';
|
|
4
|
-
import * as tsCodegen from '../../../codegen/typescript';
|
|
5
|
-
|
|
6
|
-
export default class IpfsFileTemplateCodeGen {
|
|
7
|
-
constructor(private template: immutable.Map<any, any>) {
|
|
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
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { Contract } from '../contract';
|
|
2
|
-
|
|
3
|
-
const MINIMUM_ACCOUNT_ID_LENGTH = 2 as const;
|
|
4
|
-
const MAXIMUM_ACCOUNT_ID_LENGTH = 64 as const;
|
|
5
|
-
|
|
6
|
-
const RULES_URL = 'https://docs.near.org/docs/concepts/account#account-id-rules' as const;
|
|
7
|
-
|
|
8
|
-
export default class NearContract implements Contract {
|
|
9
|
-
static identifierName() {
|
|
10
|
-
return 'account';
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
constructor(private account: string) {
|
|
14
|
-
this.account = account;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
private validateLength(value: string) {
|
|
18
|
-
return value.length >= MINIMUM_ACCOUNT_ID_LENGTH && value.length <= MAXIMUM_ACCOUNT_ID_LENGTH;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
private validateFormat(value: string) {
|
|
22
|
-
const pattern = /^(([a-z\d]+[-_])*[a-z\d]+\.)*([a-z\d]+[-_])*[a-z\d]+$/;
|
|
23
|
-
|
|
24
|
-
return pattern.test(value);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
validate() {
|
|
28
|
-
if (!this.validateLength(this.account)) {
|
|
29
|
-
return {
|
|
30
|
-
valid: false,
|
|
31
|
-
error: `Account must be between '${MINIMUM_ACCOUNT_ID_LENGTH}' and '${MAXIMUM_ACCOUNT_ID_LENGTH}' characters, see ${RULES_URL}`,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (!this.validateFormat(this.account)) {
|
|
36
|
-
return {
|
|
37
|
-
valid: false,
|
|
38
|
-
error: `Account must conform to the rules on ${RULES_URL}`,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
valid: true,
|
|
44
|
-
error: null,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
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`;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import immutable from 'immutable';
|
|
2
|
-
import { Subgraph, SubgraphOptions } from '../subgraph';
|
|
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
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
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<any>;
|
|
11
|
-
handlerTypes(): immutable.List<any>;
|
|
12
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import immutable from 'immutable';
|
|
2
|
-
import { Subgraph, SubgraphOptions } from '../subgraph';
|
|
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
|
-
}
|
package/src/scaffold/index.ts
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import { strings } from 'gluegun';
|
|
2
|
-
import prettier from 'prettier';
|
|
3
|
-
import { getSubgraphBasename } from '../command-helpers/subgraph';
|
|
4
|
-
import Protocol from '../protocols';
|
|
5
|
-
import ABI from '../protocols/ethereum/abi';
|
|
6
|
-
import { generateEventIndexingHandlers } from './mapping';
|
|
7
|
-
import { abiEvents, generateEventType, generateExampleEntityType } from './schema';
|
|
8
|
-
import { generateTestsFiles } from './tests';
|
|
9
|
-
|
|
10
|
-
const GRAPH_CLI_VERSION = process.env.GRAPH_CLI_TESTS
|
|
11
|
-
? // JSON.stringify should remove this key, we will install the local
|
|
12
|
-
// graph-cli for the tests using `npm link` instead of fetching from npm.
|
|
13
|
-
undefined
|
|
14
|
-
: // For scaffolding real subgraphs
|
|
15
|
-
String(module.exports.version);
|
|
16
|
-
|
|
17
|
-
export interface ScaffoldOptions {
|
|
18
|
-
protocol: Protocol;
|
|
19
|
-
abi?: ABI;
|
|
20
|
-
indexEvents?: boolean;
|
|
21
|
-
contract?: string;
|
|
22
|
-
network: string;
|
|
23
|
-
contractName: string;
|
|
24
|
-
subgraphName?: string;
|
|
25
|
-
node?: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export default class Scaffold {
|
|
29
|
-
protocol: Protocol;
|
|
30
|
-
abi?: ABI;
|
|
31
|
-
indexEvents?: boolean;
|
|
32
|
-
contract?: string;
|
|
33
|
-
network: string;
|
|
34
|
-
contractName: string;
|
|
35
|
-
subgraphName?: string;
|
|
36
|
-
node?: string;
|
|
37
|
-
|
|
38
|
-
constructor(options: ScaffoldOptions) {
|
|
39
|
-
this.protocol = options.protocol;
|
|
40
|
-
this.abi = options.abi;
|
|
41
|
-
this.indexEvents = options.indexEvents;
|
|
42
|
-
this.contract = options.contract;
|
|
43
|
-
this.network = options.network;
|
|
44
|
-
this.contractName = options.contractName;
|
|
45
|
-
this.subgraphName = options.subgraphName;
|
|
46
|
-
this.node = options.node;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
generatePackageJson() {
|
|
50
|
-
return prettier.format(
|
|
51
|
-
JSON.stringify({
|
|
52
|
-
name: getSubgraphBasename(String(this.subgraphName)),
|
|
53
|
-
license: 'UNLICENSED',
|
|
54
|
-
scripts: {
|
|
55
|
-
codegen: 'graph codegen',
|
|
56
|
-
build: 'graph build',
|
|
57
|
-
deploy: `graph deploy ` + `--node ${this.node} ` + this.subgraphName,
|
|
58
|
-
'create-local': `graph create --node http://localhost:8020/ ${this.subgraphName}`,
|
|
59
|
-
'remove-local': `graph remove --node http://localhost:8020/ ${this.subgraphName}`,
|
|
60
|
-
'deploy-local':
|
|
61
|
-
`graph deploy ` +
|
|
62
|
-
`--node http://localhost:8020/ ` +
|
|
63
|
-
`--ipfs http://localhost:5001 ` +
|
|
64
|
-
this.subgraphName,
|
|
65
|
-
test: 'graph test',
|
|
66
|
-
},
|
|
67
|
-
dependencies: {
|
|
68
|
-
'@graphprotocol/graph-cli': GRAPH_CLI_VERSION,
|
|
69
|
-
'@graphprotocol/graph-ts': `0.29.1`,
|
|
70
|
-
},
|
|
71
|
-
devDependencies: this.protocol.hasEvents() ? { 'matchstick-as': `0.5.0` } : undefined,
|
|
72
|
-
}),
|
|
73
|
-
{ parser: 'json' },
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
generateManifest() {
|
|
78
|
-
const protocolManifest = this.protocol.getManifestScaffold();
|
|
79
|
-
|
|
80
|
-
return prettier.format(
|
|
81
|
-
`
|
|
82
|
-
specVersion: 0.0.5
|
|
83
|
-
schema:
|
|
84
|
-
file: ./schema.graphql
|
|
85
|
-
dataSources:
|
|
86
|
-
- kind: ${this.protocol.name}
|
|
87
|
-
name: ${this.contractName}
|
|
88
|
-
network: ${this.network}
|
|
89
|
-
source: ${protocolManifest.source(this)}
|
|
90
|
-
mapping: ${protocolManifest.mapping(this)}
|
|
91
|
-
`,
|
|
92
|
-
{ parser: 'yaml' },
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
generateSchema() {
|
|
97
|
-
const hasEvents = this.protocol.hasEvents();
|
|
98
|
-
const events = hasEvents ? abiEvents(this.abi!).toJS() : [];
|
|
99
|
-
|
|
100
|
-
return prettier.format(
|
|
101
|
-
hasEvents && this.indexEvents
|
|
102
|
-
? events.map((event: any) => generateEventType(event, this.protocol.name)).join('\n\n')
|
|
103
|
-
: generateExampleEntityType(this.protocol, events),
|
|
104
|
-
{
|
|
105
|
-
parser: 'graphql',
|
|
106
|
-
},
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
generateTsConfig() {
|
|
111
|
-
return prettier.format(
|
|
112
|
-
JSON.stringify({
|
|
113
|
-
extends: '@graphprotocol/graph-ts/types/tsconfig.base.json',
|
|
114
|
-
include: ['src'],
|
|
115
|
-
}),
|
|
116
|
-
{ parser: 'json' },
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
generateMappings() {
|
|
121
|
-
return this.protocol.getMappingScaffold()
|
|
122
|
-
? { [`${strings.kebabCase(this.contractName)}.ts`]: this.generateMapping() }
|
|
123
|
-
: undefined;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
generateMapping() {
|
|
127
|
-
const hasEvents = this.protocol.hasEvents();
|
|
128
|
-
const events = hasEvents ? abiEvents(this.abi!).toJS() : [];
|
|
129
|
-
const protocolMapping = this.protocol.getMappingScaffold();
|
|
130
|
-
|
|
131
|
-
return prettier.format(
|
|
132
|
-
hasEvents && this.indexEvents
|
|
133
|
-
? generateEventIndexingHandlers(events, this.contractName)
|
|
134
|
-
: protocolMapping.generatePlaceholderHandlers({
|
|
135
|
-
...this,
|
|
136
|
-
events,
|
|
137
|
-
}),
|
|
138
|
-
{ parser: 'typescript', semi: false },
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
generateABIs() {
|
|
143
|
-
return this.protocol.hasABIs()
|
|
144
|
-
? {
|
|
145
|
-
[`${this.contractName}.json`]: prettier.format(JSON.stringify(this.abi?.data), {
|
|
146
|
-
parser: 'json',
|
|
147
|
-
}),
|
|
148
|
-
}
|
|
149
|
-
: undefined;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
generateTests() {
|
|
153
|
-
const hasEvents = this.protocol.hasEvents();
|
|
154
|
-
const events = hasEvents ? abiEvents(this.abi!).toJS() : [];
|
|
155
|
-
|
|
156
|
-
return events.length > 0
|
|
157
|
-
? generateTestsFiles(this.contractName, events, this.indexEvents)
|
|
158
|
-
: undefined;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
generate() {
|
|
162
|
-
return {
|
|
163
|
-
'package.json': this.generatePackageJson(),
|
|
164
|
-
'subgraph.yaml': this.generateManifest(),
|
|
165
|
-
'schema.graphql': this.generateSchema(),
|
|
166
|
-
'tsconfig.json': this.generateTsConfig(),
|
|
167
|
-
src: this.generateMappings(),
|
|
168
|
-
abis: this.generateABIs(),
|
|
169
|
-
tests: this.generateTests(),
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
}
|
package/src/scaffold/mapping.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import * as util from '../codegen/util';
|
|
2
|
-
|
|
3
|
-
export const generateFieldAssignment = (path: string[]) =>
|
|
4
|
-
`entity.${path.join('_')} = event.params.${path.join('.')}`;
|
|
5
|
-
|
|
6
|
-
export const generateFieldAssignments = ({ index, input }: { index: number; input: any }) =>
|
|
7
|
-
input.type === 'tuple'
|
|
8
|
-
? util
|
|
9
|
-
.unrollTuple({ value: input, index, path: [input.name || `param${index}`] })
|
|
10
|
-
.map(({ path }: any) => generateFieldAssignment(path))
|
|
11
|
-
: generateFieldAssignment([input.name || `param${index}`]);
|
|
12
|
-
|
|
13
|
-
export const generateEventFieldAssignments = (event: any) =>
|
|
14
|
-
event.inputs.reduce(
|
|
15
|
-
(acc: any[], input: any, index: number) =>
|
|
16
|
-
acc.concat(generateFieldAssignments({ input, index })),
|
|
17
|
-
[],
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
export const generateEventIndexingHandlers = (events: any[], contractName: string) =>
|
|
21
|
-
`
|
|
22
|
-
import { ${events.map(
|
|
23
|
-
event => `${event._alias} as ${event._alias}Event`,
|
|
24
|
-
)}} from '../generated/${contractName}/${contractName}'
|
|
25
|
-
import { ${events.map(event => event._alias)} } from '../generated/schema'
|
|
26
|
-
|
|
27
|
-
${events
|
|
28
|
-
.map(
|
|
29
|
-
event =>
|
|
30
|
-
`
|
|
31
|
-
export function handle${event._alias}(event: ${event._alias}Event): void {
|
|
32
|
-
let entity = new ${event._alias}(event.transaction.hash.concatI32(event.logIndex.toI32()))
|
|
33
|
-
${generateEventFieldAssignments(event).join('\n')}
|
|
34
|
-
|
|
35
|
-
entity.blockNumber = event.block.number
|
|
36
|
-
entity.blockTimestamp = event.block.timestamp
|
|
37
|
-
entity.transactionHash = event.transaction.hash
|
|
38
|
-
|
|
39
|
-
entity.save()
|
|
40
|
-
}
|
|
41
|
-
`,
|
|
42
|
-
)
|
|
43
|
-
.join('\n')}
|
|
44
|
-
`;
|