@graphprotocol/graph-cli 0.37.3 → 0.37.4
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/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/manifest.graphql +0 -57
- package/src/protocols/arweave/scaffold/manifest.ts +0 -14
- package/src/protocols/arweave/scaffold/mapping.ts +0 -49
- package/src/protocols/arweave/subgraph.ts +0 -22
- package/src/protocols/contract.ts +0 -9
- package/src/protocols/cosmos/manifest.graphql +0 -76
- package/src/protocols/cosmos/scaffold/manifest.ts +0 -11
- package/src/protocols/cosmos/scaffold/mapping.ts +0 -35
- 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/manifest.graphql +0 -94
- package/src/protocols/ethereum/scaffold/manifest.ts +0 -28
- package/src/protocols/ethereum/scaffold/mapping.ts +0 -76
- 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/manifest.graphql +0 -64
- package/src/protocols/near/scaffold/manifest.ts +0 -13
- package/src/protocols/near/scaffold/mapping.ts +0 -35
- package/src/protocols/near/subgraph.ts +0 -22
- package/src/protocols/subgraph.ts +0 -12
- package/src/protocols/substreams/manifest.graphql +0 -45
- package/src/protocols/substreams/scaffold/manifest.ts +0 -8
- package/src/protocols/substreams/subgraph.ts +0 -22
- package/src/scaffold/cosmos.test.ts +0 -83
- package/src/scaffold/ethereum.test.ts +0 -512
- package/src/scaffold/index.ts +0 -172
- package/src/scaffold/mapping.ts +0 -44
- package/src/scaffold/near.test.ts +0 -86
- 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
|
@@ -1,512 +0,0 @@
|
|
|
1
|
-
import immutable from 'immutable';
|
|
2
|
-
import Protocol from '../protocols';
|
|
3
|
-
import ABI from '../protocols/ethereum/abi';
|
|
4
|
-
import Scaffold from './index';
|
|
5
|
-
|
|
6
|
-
const TEST_EVENT = {
|
|
7
|
-
name: 'ExampleEvent',
|
|
8
|
-
type: 'event',
|
|
9
|
-
inputs: [
|
|
10
|
-
{ name: 'a', type: 'uint256', indexed: true },
|
|
11
|
-
{ name: 'b', type: 'bytes[4]' },
|
|
12
|
-
{ type: 'string' },
|
|
13
|
-
{
|
|
14
|
-
name: 'c',
|
|
15
|
-
type: 'tuple',
|
|
16
|
-
components: [
|
|
17
|
-
{ name: 'c1', type: 'uint256' },
|
|
18
|
-
{ type: 'bytes32' },
|
|
19
|
-
{ type: 'string' },
|
|
20
|
-
{
|
|
21
|
-
name: 'c3',
|
|
22
|
-
type: 'tuple',
|
|
23
|
-
components: [{ name: 'c31', type: 'uint96' }, { type: 'string' }, { type: 'bytes32' }],
|
|
24
|
-
},
|
|
25
|
-
],
|
|
26
|
-
},
|
|
27
|
-
{ name: 'd', type: 'string', indexed: true },
|
|
28
|
-
],
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const OVERLOADED_EVENT = {
|
|
32
|
-
name: 'ExampleEvent',
|
|
33
|
-
type: 'event',
|
|
34
|
-
inputs: [{ name: 'a', type: 'bytes32' }],
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const TEST_CONTRACT = {
|
|
38
|
-
name: 'ExampleContract',
|
|
39
|
-
type: 'contract',
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const TEST_CALLABLE_FUNCTIONS = [
|
|
43
|
-
{
|
|
44
|
-
name: 'someVariable',
|
|
45
|
-
type: 'function',
|
|
46
|
-
stateMutability: 'view',
|
|
47
|
-
outputs: [{ type: 'uint256' }],
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
name: 'getSomeValue',
|
|
51
|
-
type: 'function',
|
|
52
|
-
stateMutability: 'pure',
|
|
53
|
-
outputs: [{ type: 'tuple', components: [{ type: 'uint256' }] }],
|
|
54
|
-
},
|
|
55
|
-
];
|
|
56
|
-
|
|
57
|
-
const TEST_ABI = new ABI(
|
|
58
|
-
'Contract',
|
|
59
|
-
undefined,
|
|
60
|
-
immutable.fromJS([TEST_EVENT, OVERLOADED_EVENT, TEST_CONTRACT, ...TEST_CALLABLE_FUNCTIONS]),
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
const protocol = new Protocol('ethereum');
|
|
64
|
-
|
|
65
|
-
const scaffoldOptions = {
|
|
66
|
-
protocol,
|
|
67
|
-
abi: TEST_ABI,
|
|
68
|
-
contract: '0xf87e31492faf9a91b02ee0deaad50d51d56d5d4d',
|
|
69
|
-
network: 'kovan',
|
|
70
|
-
contractName: 'Contract',
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
const scaffold = new Scaffold(scaffoldOptions);
|
|
74
|
-
|
|
75
|
-
const scaffoldWithIndexEvents = new Scaffold({
|
|
76
|
-
...scaffoldOptions,
|
|
77
|
-
indexEvents: true,
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
describe('Ethereum subgraph scaffolding', () => {
|
|
81
|
-
test('Manifest', () => {
|
|
82
|
-
expect(scaffold.generateManifest()).toEqual(`\
|
|
83
|
-
specVersion: 0.0.5
|
|
84
|
-
schema:
|
|
85
|
-
file: ./schema.graphql
|
|
86
|
-
dataSources:
|
|
87
|
-
- kind: ethereum
|
|
88
|
-
name: Contract
|
|
89
|
-
network: kovan
|
|
90
|
-
source:
|
|
91
|
-
address: "0xf87e31492faf9a91b02ee0deaad50d51d56d5d4d"
|
|
92
|
-
abi: Contract
|
|
93
|
-
mapping:
|
|
94
|
-
kind: ethereum/events
|
|
95
|
-
apiVersion: 0.0.7
|
|
96
|
-
language: wasm/assemblyscript
|
|
97
|
-
entities:
|
|
98
|
-
- ExampleEvent
|
|
99
|
-
- ExampleEvent1
|
|
100
|
-
abis:
|
|
101
|
-
- name: Contract
|
|
102
|
-
file: ./abis/Contract.json
|
|
103
|
-
eventHandlers:
|
|
104
|
-
- event: ExampleEvent(indexed uint256,bytes[4],string,(uint256,bytes32,string,(uint96,string,bytes32)),indexed string)
|
|
105
|
-
handler: handleExampleEvent
|
|
106
|
-
- event: ExampleEvent(bytes32)
|
|
107
|
-
handler: handleExampleEvent1
|
|
108
|
-
file: ./src/contract.ts
|
|
109
|
-
`);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
test('Schema (default)', () => {
|
|
113
|
-
expect(scaffold.generateSchema()).toEqual(`\
|
|
114
|
-
type ExampleEntity @entity {
|
|
115
|
-
id: Bytes!
|
|
116
|
-
count: BigInt!
|
|
117
|
-
a: BigInt! # uint256
|
|
118
|
-
b: [Bytes]! # bytes[4]
|
|
119
|
-
}
|
|
120
|
-
`);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
test('Schema (for indexing events)', () => {
|
|
124
|
-
expect(scaffoldWithIndexEvents.generateSchema()).toEqual(`\
|
|
125
|
-
type ExampleEvent @entity(immutable: true) {
|
|
126
|
-
id: Bytes!
|
|
127
|
-
a: BigInt! # uint256
|
|
128
|
-
b: [Bytes]! # bytes[4]
|
|
129
|
-
param2: String! # string
|
|
130
|
-
c_c1: BigInt! # uint256
|
|
131
|
-
c_value1: Bytes! # bytes32
|
|
132
|
-
c_value2: String! # string
|
|
133
|
-
c_c3_c31: BigInt! # uint96
|
|
134
|
-
c_c3_value1: String! # string
|
|
135
|
-
c_c3_value2: Bytes! # bytes32
|
|
136
|
-
d: String! # string
|
|
137
|
-
blockNumber: BigInt!
|
|
138
|
-
blockTimestamp: BigInt!
|
|
139
|
-
transactionHash: Bytes!
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
type ExampleEvent1 @entity(immutable: true) {
|
|
143
|
-
id: Bytes!
|
|
144
|
-
a: Bytes! # bytes32
|
|
145
|
-
blockNumber: BigInt!
|
|
146
|
-
blockTimestamp: BigInt!
|
|
147
|
-
transactionHash: Bytes!
|
|
148
|
-
}
|
|
149
|
-
`);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
test('Mapping (default)', () => {
|
|
153
|
-
expect(scaffold.generateMapping()).toEqual(`\
|
|
154
|
-
import { BigInt } from "@graphprotocol/graph-ts"
|
|
155
|
-
import {
|
|
156
|
-
Contract,
|
|
157
|
-
ExampleEvent,
|
|
158
|
-
ExampleEvent1
|
|
159
|
-
} from "../generated/Contract/Contract"
|
|
160
|
-
import { ExampleEntity } from "../generated/schema"
|
|
161
|
-
|
|
162
|
-
export function handleExampleEvent(event: ExampleEvent): void {
|
|
163
|
-
// Entities can be loaded from the store using a string ID; this ID
|
|
164
|
-
// needs to be unique across all entities of the same type
|
|
165
|
-
let entity = ExampleEntity.load(event.transaction.from)
|
|
166
|
-
|
|
167
|
-
// Entities only exist after they have been saved to the store;
|
|
168
|
-
// \`null\` checks allow to create entities on demand
|
|
169
|
-
if (!entity) {
|
|
170
|
-
entity = new ExampleEntity(event.transaction.from)
|
|
171
|
-
|
|
172
|
-
// Entity fields can be set using simple assignments
|
|
173
|
-
entity.count = BigInt.fromI32(0)
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// BigInt and BigDecimal math are supported
|
|
177
|
-
entity.count = entity.count + BigInt.fromI32(1)
|
|
178
|
-
|
|
179
|
-
// Entity fields can be set based on event parameters
|
|
180
|
-
entity.a = event.params.a
|
|
181
|
-
entity.b = event.params.b
|
|
182
|
-
|
|
183
|
-
// Entities can be written to the store with \`.save()\`
|
|
184
|
-
entity.save()
|
|
185
|
-
|
|
186
|
-
// Note: If a handler doesn't require existing field values, it is faster
|
|
187
|
-
// _not_ to load the entity from the store. Instead, create it fresh with
|
|
188
|
-
// \`new Entity(...)\`, set the fields that should be updated and save the
|
|
189
|
-
// entity back to the store. Fields that were not set or unset remain
|
|
190
|
-
// unchanged, allowing for partial updates to be applied.
|
|
191
|
-
|
|
192
|
-
// It is also possible to access smart contracts from mappings. For
|
|
193
|
-
// example, the contract that has emitted the event can be connected to
|
|
194
|
-
// with:
|
|
195
|
-
//
|
|
196
|
-
// let contract = Contract.bind(event.address)
|
|
197
|
-
//
|
|
198
|
-
// The following functions can then be called on this contract to access
|
|
199
|
-
// state variables and other data:
|
|
200
|
-
//
|
|
201
|
-
// - contract.someVariable(...)
|
|
202
|
-
// - contract.getSomeValue(...)
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
export function handleExampleEvent1(event: ExampleEvent1): void {}
|
|
206
|
-
`);
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
test('Mapping (for indexing events)', () => {
|
|
210
|
-
expect(scaffoldWithIndexEvents.generateMapping()).toEqual(`\
|
|
211
|
-
import {
|
|
212
|
-
ExampleEvent as ExampleEventEvent,
|
|
213
|
-
ExampleEvent1 as ExampleEvent1Event
|
|
214
|
-
} from "../generated/Contract/Contract"
|
|
215
|
-
import { ExampleEvent, ExampleEvent1 } from "../generated/schema"
|
|
216
|
-
|
|
217
|
-
export function handleExampleEvent(event: ExampleEventEvent): void {
|
|
218
|
-
let entity = new ExampleEvent(
|
|
219
|
-
event.transaction.hash.concatI32(event.logIndex.toI32())
|
|
220
|
-
)
|
|
221
|
-
entity.a = event.params.a
|
|
222
|
-
entity.b = event.params.b
|
|
223
|
-
entity.param2 = event.params.param2
|
|
224
|
-
entity.c_c1 = event.params.c.c1
|
|
225
|
-
entity.c_value1 = event.params.c.value1
|
|
226
|
-
entity.c_value2 = event.params.c.value2
|
|
227
|
-
entity.c_c3_c31 = event.params.c.c3.c31
|
|
228
|
-
entity.c_c3_value1 = event.params.c.c3.value1
|
|
229
|
-
entity.c_c3_value2 = event.params.c.c3.value2
|
|
230
|
-
entity.d = event.params.d
|
|
231
|
-
|
|
232
|
-
entity.blockNumber = event.block.number
|
|
233
|
-
entity.blockTimestamp = event.block.timestamp
|
|
234
|
-
entity.transactionHash = event.transaction.hash
|
|
235
|
-
|
|
236
|
-
entity.save()
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
export function handleExampleEvent1(event: ExampleEvent1Event): void {
|
|
240
|
-
let entity = new ExampleEvent1(
|
|
241
|
-
event.transaction.hash.concatI32(event.logIndex.toI32())
|
|
242
|
-
)
|
|
243
|
-
entity.a = event.params.a
|
|
244
|
-
|
|
245
|
-
entity.blockNumber = event.block.number
|
|
246
|
-
entity.blockTimestamp = event.block.timestamp
|
|
247
|
-
entity.transactionHash = event.transaction.hash
|
|
248
|
-
|
|
249
|
-
entity.save()
|
|
250
|
-
}
|
|
251
|
-
`);
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
test('Test Files (default)', () => {
|
|
255
|
-
const files = scaffoldWithIndexEvents.generateTests();
|
|
256
|
-
const testFile = files?.['contract.test.ts'];
|
|
257
|
-
const utilsFile = files?.['contract-utils.ts'];
|
|
258
|
-
expect(testFile).toEqual(`\
|
|
259
|
-
import {
|
|
260
|
-
assert,
|
|
261
|
-
describe,
|
|
262
|
-
test,
|
|
263
|
-
clearStore,
|
|
264
|
-
beforeAll,
|
|
265
|
-
afterAll
|
|
266
|
-
} from "matchstick-as/assembly/index"
|
|
267
|
-
import { BigInt, Bytes } from "@graphprotocol/graph-ts"
|
|
268
|
-
import { ExampleEvent } from "../generated/schema"
|
|
269
|
-
import { ExampleEvent as ExampleEventEvent } from "../generated/Contract/Contract"
|
|
270
|
-
import { handleExampleEvent } from "../src/contract"
|
|
271
|
-
import { createExampleEventEvent } from "./contract-utils"
|
|
272
|
-
|
|
273
|
-
// Tests structure (matchstick-as >=0.5.0)
|
|
274
|
-
// https://thegraph.com/docs/en/developer/matchstick/#tests-structure-0-5-0
|
|
275
|
-
|
|
276
|
-
describe("Describe entity assertions", () => {
|
|
277
|
-
beforeAll(() => {
|
|
278
|
-
let a = BigInt.fromI32(234)
|
|
279
|
-
let b = [Bytes.fromI32(1234567890)]
|
|
280
|
-
let param2 = "Example string value"
|
|
281
|
-
let c = "ethereum.Tuple Not implemented"
|
|
282
|
-
let d = "Example string value"
|
|
283
|
-
let newExampleEventEvent = createExampleEventEvent(a, b, param2, c, d)
|
|
284
|
-
handleExampleEvent(newExampleEventEvent)
|
|
285
|
-
})
|
|
286
|
-
|
|
287
|
-
afterAll(() => {
|
|
288
|
-
clearStore()
|
|
289
|
-
})
|
|
290
|
-
|
|
291
|
-
// For more test scenarios, see:
|
|
292
|
-
// https://thegraph.com/docs/en/developer/matchstick/#write-a-unit-test
|
|
293
|
-
|
|
294
|
-
test("ExampleEvent created and stored", () => {
|
|
295
|
-
assert.entityCount("ExampleEvent", 1)
|
|
296
|
-
|
|
297
|
-
// 0xa16081f360e3847006db660bae1c6d1b2e17ec2a is the default address used in newMockEvent() function
|
|
298
|
-
assert.fieldEquals(
|
|
299
|
-
"ExampleEvent",
|
|
300
|
-
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1",
|
|
301
|
-
"a",
|
|
302
|
-
"234"
|
|
303
|
-
)
|
|
304
|
-
assert.fieldEquals(
|
|
305
|
-
"ExampleEvent",
|
|
306
|
-
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1",
|
|
307
|
-
"b",
|
|
308
|
-
"[1234567890]"
|
|
309
|
-
)
|
|
310
|
-
assert.fieldEquals(
|
|
311
|
-
"ExampleEvent",
|
|
312
|
-
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1",
|
|
313
|
-
"param2",
|
|
314
|
-
"Example string value"
|
|
315
|
-
)
|
|
316
|
-
assert.fieldEquals(
|
|
317
|
-
"ExampleEvent",
|
|
318
|
-
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1",
|
|
319
|
-
"c",
|
|
320
|
-
"ethereum.Tuple Not implemented"
|
|
321
|
-
)
|
|
322
|
-
assert.fieldEquals(
|
|
323
|
-
"ExampleEvent",
|
|
324
|
-
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1",
|
|
325
|
-
"d",
|
|
326
|
-
"Example string value"
|
|
327
|
-
)
|
|
328
|
-
|
|
329
|
-
// More assert options:
|
|
330
|
-
// https://thegraph.com/docs/en/developer/matchstick/#asserts
|
|
331
|
-
})
|
|
332
|
-
})
|
|
333
|
-
`);
|
|
334
|
-
expect(utilsFile).toEqual(`\
|
|
335
|
-
import { newMockEvent } from "matchstick-as"
|
|
336
|
-
import { ethereum, BigInt, Bytes } from "@graphprotocol/graph-ts"
|
|
337
|
-
import { ExampleEvent, ExampleEvent1 } from "../generated/Contract/Contract"
|
|
338
|
-
|
|
339
|
-
export function createExampleEventEvent(
|
|
340
|
-
a: BigInt,
|
|
341
|
-
b: Array<Bytes>,
|
|
342
|
-
param2: string,
|
|
343
|
-
c: ethereum.Tuple,
|
|
344
|
-
d: string
|
|
345
|
-
): ExampleEvent {
|
|
346
|
-
let exampleEventEvent = changetype<ExampleEvent>(newMockEvent())
|
|
347
|
-
|
|
348
|
-
exampleEventEvent.parameters = new Array()
|
|
349
|
-
|
|
350
|
-
exampleEventEvent.parameters.push(
|
|
351
|
-
new ethereum.EventParam("a", ethereum.Value.fromUnsignedBigInt(a))
|
|
352
|
-
)
|
|
353
|
-
exampleEventEvent.parameters.push(
|
|
354
|
-
new ethereum.EventParam("b", ethereum.Value.fromBytesArray(b))
|
|
355
|
-
)
|
|
356
|
-
exampleEventEvent.parameters.push(
|
|
357
|
-
new ethereum.EventParam("param2", ethereum.Value.fromString(param2))
|
|
358
|
-
)
|
|
359
|
-
exampleEventEvent.parameters.push(
|
|
360
|
-
new ethereum.EventParam("c", ethereum.Value.fromTuple(c))
|
|
361
|
-
)
|
|
362
|
-
exampleEventEvent.parameters.push(
|
|
363
|
-
new ethereum.EventParam("d", ethereum.Value.fromString(d))
|
|
364
|
-
)
|
|
365
|
-
|
|
366
|
-
return exampleEventEvent
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
export function createExampleEvent1Event(a: Bytes): ExampleEvent1 {
|
|
370
|
-
let exampleEvent1Event = changetype<ExampleEvent1>(newMockEvent())
|
|
371
|
-
|
|
372
|
-
exampleEvent1Event.parameters = new Array()
|
|
373
|
-
|
|
374
|
-
exampleEvent1Event.parameters.push(
|
|
375
|
-
new ethereum.EventParam("a", ethereum.Value.fromFixedBytes(a))
|
|
376
|
-
)
|
|
377
|
-
|
|
378
|
-
return exampleEvent1Event
|
|
379
|
-
}
|
|
380
|
-
`);
|
|
381
|
-
});
|
|
382
|
-
|
|
383
|
-
test('Test Files (for indexing events)', () => {
|
|
384
|
-
const files = scaffoldWithIndexEvents.generateTests();
|
|
385
|
-
const testFile = files?.['contract.test.ts'];
|
|
386
|
-
const utilsFile = files?.['contract-utils.ts'];
|
|
387
|
-
|
|
388
|
-
expect(testFile).toEqual(`\
|
|
389
|
-
import {
|
|
390
|
-
assert,
|
|
391
|
-
describe,
|
|
392
|
-
test,
|
|
393
|
-
clearStore,
|
|
394
|
-
beforeAll,
|
|
395
|
-
afterAll
|
|
396
|
-
} from "matchstick-as/assembly/index"
|
|
397
|
-
import { BigInt, Bytes } from "@graphprotocol/graph-ts"
|
|
398
|
-
import { ExampleEvent } from "../generated/schema"
|
|
399
|
-
import { ExampleEvent as ExampleEventEvent } from "../generated/Contract/Contract"
|
|
400
|
-
import { handleExampleEvent } from "../src/contract"
|
|
401
|
-
import { createExampleEventEvent } from "./contract-utils"
|
|
402
|
-
|
|
403
|
-
// Tests structure (matchstick-as >=0.5.0)
|
|
404
|
-
// https://thegraph.com/docs/en/developer/matchstick/#tests-structure-0-5-0
|
|
405
|
-
|
|
406
|
-
describe("Describe entity assertions", () => {
|
|
407
|
-
beforeAll(() => {
|
|
408
|
-
let a = BigInt.fromI32(234)
|
|
409
|
-
let b = [Bytes.fromI32(1234567890)]
|
|
410
|
-
let param2 = "Example string value"
|
|
411
|
-
let c = "ethereum.Tuple Not implemented"
|
|
412
|
-
let d = "Example string value"
|
|
413
|
-
let newExampleEventEvent = createExampleEventEvent(a, b, param2, c, d)
|
|
414
|
-
handleExampleEvent(newExampleEventEvent)
|
|
415
|
-
})
|
|
416
|
-
|
|
417
|
-
afterAll(() => {
|
|
418
|
-
clearStore()
|
|
419
|
-
})
|
|
420
|
-
|
|
421
|
-
// For more test scenarios, see:
|
|
422
|
-
// https://thegraph.com/docs/en/developer/matchstick/#write-a-unit-test
|
|
423
|
-
|
|
424
|
-
test("ExampleEvent created and stored", () => {
|
|
425
|
-
assert.entityCount("ExampleEvent", 1)
|
|
426
|
-
|
|
427
|
-
// 0xa16081f360e3847006db660bae1c6d1b2e17ec2a is the default address used in newMockEvent() function
|
|
428
|
-
assert.fieldEquals(
|
|
429
|
-
"ExampleEvent",
|
|
430
|
-
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1",
|
|
431
|
-
"a",
|
|
432
|
-
"234"
|
|
433
|
-
)
|
|
434
|
-
assert.fieldEquals(
|
|
435
|
-
"ExampleEvent",
|
|
436
|
-
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1",
|
|
437
|
-
"b",
|
|
438
|
-
"[1234567890]"
|
|
439
|
-
)
|
|
440
|
-
assert.fieldEquals(
|
|
441
|
-
"ExampleEvent",
|
|
442
|
-
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1",
|
|
443
|
-
"param2",
|
|
444
|
-
"Example string value"
|
|
445
|
-
)
|
|
446
|
-
assert.fieldEquals(
|
|
447
|
-
"ExampleEvent",
|
|
448
|
-
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1",
|
|
449
|
-
"c",
|
|
450
|
-
"ethereum.Tuple Not implemented"
|
|
451
|
-
)
|
|
452
|
-
assert.fieldEquals(
|
|
453
|
-
"ExampleEvent",
|
|
454
|
-
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1",
|
|
455
|
-
"d",
|
|
456
|
-
"Example string value"
|
|
457
|
-
)
|
|
458
|
-
|
|
459
|
-
// More assert options:
|
|
460
|
-
// https://thegraph.com/docs/en/developer/matchstick/#asserts
|
|
461
|
-
})
|
|
462
|
-
})
|
|
463
|
-
`);
|
|
464
|
-
expect(utilsFile).toEqual(`\
|
|
465
|
-
import { newMockEvent } from "matchstick-as"
|
|
466
|
-
import { ethereum, BigInt, Bytes } from "@graphprotocol/graph-ts"
|
|
467
|
-
import { ExampleEvent, ExampleEvent1 } from "../generated/Contract/Contract"
|
|
468
|
-
|
|
469
|
-
export function createExampleEventEvent(
|
|
470
|
-
a: BigInt,
|
|
471
|
-
b: Array<Bytes>,
|
|
472
|
-
param2: string,
|
|
473
|
-
c: ethereum.Tuple,
|
|
474
|
-
d: string
|
|
475
|
-
): ExampleEvent {
|
|
476
|
-
let exampleEventEvent = changetype<ExampleEvent>(newMockEvent())
|
|
477
|
-
|
|
478
|
-
exampleEventEvent.parameters = new Array()
|
|
479
|
-
|
|
480
|
-
exampleEventEvent.parameters.push(
|
|
481
|
-
new ethereum.EventParam("a", ethereum.Value.fromUnsignedBigInt(a))
|
|
482
|
-
)
|
|
483
|
-
exampleEventEvent.parameters.push(
|
|
484
|
-
new ethereum.EventParam("b", ethereum.Value.fromBytesArray(b))
|
|
485
|
-
)
|
|
486
|
-
exampleEventEvent.parameters.push(
|
|
487
|
-
new ethereum.EventParam("param2", ethereum.Value.fromString(param2))
|
|
488
|
-
)
|
|
489
|
-
exampleEventEvent.parameters.push(
|
|
490
|
-
new ethereum.EventParam("c", ethereum.Value.fromTuple(c))
|
|
491
|
-
)
|
|
492
|
-
exampleEventEvent.parameters.push(
|
|
493
|
-
new ethereum.EventParam("d", ethereum.Value.fromString(d))
|
|
494
|
-
)
|
|
495
|
-
|
|
496
|
-
return exampleEventEvent
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
export function createExampleEvent1Event(a: Bytes): ExampleEvent1 {
|
|
500
|
-
let exampleEvent1Event = changetype<ExampleEvent1>(newMockEvent())
|
|
501
|
-
|
|
502
|
-
exampleEvent1Event.parameters = new Array()
|
|
503
|
-
|
|
504
|
-
exampleEvent1Event.parameters.push(
|
|
505
|
-
new ethereum.EventParam("a", ethereum.Value.fromFixedBytes(a))
|
|
506
|
-
)
|
|
507
|
-
|
|
508
|
-
return exampleEvent1Event
|
|
509
|
-
}
|
|
510
|
-
`);
|
|
511
|
-
});
|
|
512
|
-
});
|
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
|
-
}
|