@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.
Files changed (267) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/package.json +5 -1
  3. package/babel.config.js +0 -3
  4. package/jest.config.js +0 -175
  5. package/src/bin.ts +0 -6
  6. package/src/cli.ts +0 -30
  7. package/src/codegen/schema.test.ts +0 -460
  8. package/src/codegen/schema.ts +0 -299
  9. package/src/codegen/template.ts +0 -45
  10. package/src/codegen/types/conversions.ts +0 -358
  11. package/src/codegen/types/index.test.ts +0 -715
  12. package/src/codegen/types/index.ts +0 -111
  13. package/src/codegen/typescript.ts +0 -224
  14. package/src/codegen/util.test.ts +0 -112
  15. package/src/codegen/util.ts +0 -54
  16. package/src/command-helpers/abi.ts +0 -99
  17. package/src/command-helpers/auth.ts +0 -46
  18. package/src/command-helpers/compiler.ts +0 -60
  19. package/src/command-helpers/data-sources.ts +0 -36
  20. package/src/command-helpers/fs.ts +0 -5
  21. package/src/command-helpers/gluegun.ts +0 -52
  22. package/src/command-helpers/ipfs-http-client.d.ts +0 -1
  23. package/src/command-helpers/ipfs.ts +0 -3
  24. package/src/command-helpers/jsonrpc.ts +0 -22
  25. package/src/command-helpers/network.test.ts +0 -85
  26. package/src/command-helpers/network.ts +0 -133
  27. package/src/command-helpers/node.ts +0 -46
  28. package/src/command-helpers/scaffold.ts +0 -174
  29. package/src/command-helpers/spinner.ts +0 -60
  30. package/src/command-helpers/studio.test.ts +0 -84
  31. package/src/command-helpers/studio.ts +0 -25
  32. package/src/command-helpers/subgraph.ts +0 -21
  33. package/src/command-helpers/version.test.ts +0 -241
  34. package/src/command-helpers/version.ts +0 -53
  35. package/src/commands/add.ts +0 -220
  36. package/src/commands/auth.ts +0 -138
  37. package/src/commands/binary-install-raw.d.ts +0 -1
  38. package/src/commands/build.ts +0 -147
  39. package/src/commands/codegen.ts +0 -123
  40. package/src/commands/create.ts +0 -109
  41. package/src/commands/deploy.ts +0 -388
  42. package/src/commands/init.ts +0 -1060
  43. package/src/commands/local.ts +0 -539
  44. package/src/commands/remove.ts +0 -110
  45. package/src/commands/test.ts +0 -369
  46. package/src/compiler/asc.ts +0 -77
  47. package/src/compiler/index.ts +0 -677
  48. package/src/debug.ts +0 -15
  49. package/src/migrations/mapping_api_version_0_0_1.ts +0 -75
  50. package/src/migrations/mapping_api_version_0_0_2.ts +0 -75
  51. package/src/migrations/mapping_api_version_0_0_3.ts +0 -75
  52. package/src/migrations/mapping_api_version_0_0_4.ts +0 -77
  53. package/src/migrations/mapping_api_version_0_0_5.ts +0 -77
  54. package/src/migrations/spec_version_0_0_2.ts +0 -24
  55. package/src/migrations/spec_version_0_0_3.ts +0 -29
  56. package/src/migrations/util/load-manifest.ts +0 -10
  57. package/src/migrations/util/versions.ts +0 -27
  58. package/src/migrations.ts +0 -33
  59. package/src/protocols/arweave/manifest.graphql +0 -57
  60. package/src/protocols/arweave/scaffold/manifest.ts +0 -14
  61. package/src/protocols/arweave/scaffold/mapping.ts +0 -49
  62. package/src/protocols/arweave/subgraph.ts +0 -22
  63. package/src/protocols/contract.ts +0 -9
  64. package/src/protocols/cosmos/manifest.graphql +0 -76
  65. package/src/protocols/cosmos/scaffold/manifest.ts +0 -11
  66. package/src/protocols/cosmos/scaffold/mapping.ts +0 -35
  67. package/src/protocols/cosmos/subgraph.ts +0 -27
  68. package/src/protocols/ethereum/abi.ts +0 -153
  69. package/src/protocols/ethereum/codegen/abi.test.ts +0 -330
  70. package/src/protocols/ethereum/codegen/abi.ts +0 -719
  71. package/src/protocols/ethereum/codegen/template.ts +0 -41
  72. package/src/protocols/ethereum/contract.ts +0 -24
  73. package/src/protocols/ethereum/manifest.graphql +0 -94
  74. package/src/protocols/ethereum/scaffold/manifest.ts +0 -28
  75. package/src/protocols/ethereum/scaffold/mapping.ts +0 -76
  76. package/src/protocols/ethereum/subgraph.ts +0 -189
  77. package/src/protocols/ethereum/type-generator.ts +0 -191
  78. package/src/protocols/index.ts +0 -287
  79. package/src/protocols/ipfs/codegen/file_template.ts +0 -43
  80. package/src/protocols/near/contract.ts +0 -47
  81. package/src/protocols/near/manifest.graphql +0 -64
  82. package/src/protocols/near/scaffold/manifest.ts +0 -13
  83. package/src/protocols/near/scaffold/mapping.ts +0 -35
  84. package/src/protocols/near/subgraph.ts +0 -22
  85. package/src/protocols/subgraph.ts +0 -12
  86. package/src/protocols/substreams/manifest.graphql +0 -45
  87. package/src/protocols/substreams/scaffold/manifest.ts +0 -8
  88. package/src/protocols/substreams/subgraph.ts +0 -22
  89. package/src/scaffold/cosmos.test.ts +0 -83
  90. package/src/scaffold/ethereum.test.ts +0 -512
  91. package/src/scaffold/index.ts +0 -172
  92. package/src/scaffold/mapping.ts +0 -44
  93. package/src/scaffold/near.test.ts +0 -86
  94. package/src/scaffold/schema.ts +0 -89
  95. package/src/scaffold/tests.ts +0 -217
  96. package/src/schema.ts +0 -26
  97. package/src/subgraph.ts +0 -302
  98. package/src/type-generator.ts +0 -266
  99. package/src/validation/contract.ts +0 -51
  100. package/src/validation/index.ts +0 -5
  101. package/src/validation/manifest.ts +0 -360
  102. package/src/validation/schema.test.ts +0 -38
  103. package/src/validation/schema.ts +0 -957
  104. package/src/watcher.ts +0 -96
  105. package/tests/cli/globalSetup.ts +0 -8
  106. package/tests/cli/globalTeardown.ts +0 -8
  107. package/tests/cli/init/ethereum/abis/Marketplace.json +0 -408
  108. package/tests/cli/init/ethereum/abis/OverloadedElements.json +0 -91
  109. package/tests/cli/init/ethereum/abis/SoloMargin.json +0 -2729
  110. package/tests/cli/init/ethereum/from-contract-with-abi-and-structs.stderr +0 -14
  111. package/tests/cli/init/ethereum/from-contract-with-abi-and-structs.stdout +0 -12
  112. package/tests/cli/init/ethereum/from-contract-with-abi.stderr +0 -14
  113. package/tests/cli/init/ethereum/from-contract-with-abi.stdout +0 -12
  114. package/tests/cli/init/ethereum/from-contract-with-overloaded-elements.stderr +0 -14
  115. package/tests/cli/init/ethereum/from-contract-with-overloaded-elements.stdout +0 -12
  116. package/tests/cli/init/ethereum/from-contract.stderr +0 -16
  117. package/tests/cli/init/ethereum/from-contract.stdout +0 -12
  118. package/tests/cli/init/ethereum/from-example.stderr +0 -12
  119. package/tests/cli/init/ethereum/from-example.stdout +0 -12
  120. package/tests/cli/init/near/from-contract.stderr +0 -14
  121. package/tests/cli/init/near/from-contract.stdout +0 -12
  122. package/tests/cli/init.test.ts +0 -157
  123. package/tests/cli/spawn-command.d.ts +0 -7
  124. package/tests/cli/util.ts +0 -132
  125. package/tests/cli/validation/abi-not-found/Abi.json +0 -7
  126. package/tests/cli/validation/abi-not-found/mapping.ts +0 -0
  127. package/tests/cli/validation/abi-not-found/schema.graphql +0 -3
  128. package/tests/cli/validation/abi-not-found/subgraph.yaml +0 -42
  129. package/tests/cli/validation/abi-not-found copy.stderr +0 -13
  130. package/tests/cli/validation/big-decimal-is-valid/Abi.json +0 -7
  131. package/tests/cli/validation/big-decimal-is-valid/mapping.ts +0 -0
  132. package/tests/cli/validation/big-decimal-is-valid/schema.graphql +0 -4
  133. package/tests/cli/validation/big-decimal-is-valid/subgraph.yaml +0 -23
  134. package/tests/cli/validation/call-function-not-found/Abi.json +0 -57
  135. package/tests/cli/validation/call-function-not-found/mapping.ts +0 -0
  136. package/tests/cli/validation/call-function-not-found/schema.graphql +0 -3
  137. package/tests/cli/validation/call-function-not-found/subgraph.yaml +0 -22
  138. package/tests/cli/validation/call-function-not-found.stderr +0 -10
  139. package/tests/cli/validation/call-handler-with-tuple/Abi.json +0 -24
  140. package/tests/cli/validation/call-handler-with-tuple/generated/schema.ts +0 -44
  141. package/tests/cli/validation/call-handler-with-tuple/mapping.ts +0 -0
  142. package/tests/cli/validation/call-handler-with-tuple/schema.graphql +0 -3
  143. package/tests/cli/validation/call-handler-with-tuple/subgraph.yaml +0 -22
  144. package/tests/cli/validation/call-handler-with-tuple.stderr +0 -24
  145. package/tests/cli/validation/conflicting-network-names/Abi.json +0 -7
  146. package/tests/cli/validation/conflicting-network-names/mapping.ts +0 -0
  147. package/tests/cli/validation/conflicting-network-names/schema.graphql +0 -3
  148. package/tests/cli/validation/conflicting-network-names/subgraph.yaml +0 -41
  149. package/tests/cli/validation/conflicting-network-names.stderr +0 -10
  150. package/tests/cli/validation/conflicting-protocol-names/Abi.json +0 -7
  151. package/tests/cli/validation/conflicting-protocol-names/mapping.ts +0 -0
  152. package/tests/cli/validation/conflicting-protocol-names/schema.graphql +0 -3
  153. package/tests/cli/validation/conflicting-protocol-names/subgraph.yaml +0 -41
  154. package/tests/cli/validation/conflicting-protocol-names.stderr +0 -10
  155. package/tests/cli/validation/derived-from-target-type-missing/Abi.json +0 -6
  156. package/tests/cli/validation/derived-from-target-type-missing/mapping.ts +0 -0
  157. package/tests/cli/validation/derived-from-target-type-missing/schema.graphql +0 -4
  158. package/tests/cli/validation/derived-from-target-type-missing/subgraph.yaml +0 -22
  159. package/tests/cli/validation/derived-from-target-type-missing.stderr +0 -5
  160. package/tests/cli/validation/derived-from-with-interface/Gravity.json +0 -1
  161. package/tests/cli/validation/derived-from-with-interface/mapping.ts +0 -22
  162. package/tests/cli/validation/derived-from-with-interface/schema.graphql +0 -19
  163. package/tests/cli/validation/derived-from-with-interface/subgraph.yaml +0 -25
  164. package/tests/cli/validation/duplicate-data-source-name/Abi.json +0 -7
  165. package/tests/cli/validation/duplicate-data-source-name/mapping.ts +0 -0
  166. package/tests/cli/validation/duplicate-data-source-name/schema.graphql +0 -4
  167. package/tests/cli/validation/duplicate-data-source-name/subgraph.yaml +0 -40
  168. package/tests/cli/validation/duplicate-data-source-name.stderr +0 -5
  169. package/tests/cli/validation/duplicate-template-name/Abi.json +0 -7
  170. package/tests/cli/validation/duplicate-template-name/mapping.ts +0 -0
  171. package/tests/cli/validation/duplicate-template-name/schema.graphql +0 -4
  172. package/tests/cli/validation/duplicate-template-name/subgraph.yaml +0 -59
  173. package/tests/cli/validation/duplicate-template-name.stderr +0 -5
  174. package/tests/cli/validation/entity-field-args/Abi.json +0 -7
  175. package/tests/cli/validation/entity-field-args/mapping.ts +0 -0
  176. package/tests/cli/validation/entity-field-args/schema.graphql +0 -4
  177. package/tests/cli/validation/entity-field-args/subgraph.yaml +0 -22
  178. package/tests/cli/validation/entity-field-args.stderr +0 -5
  179. package/tests/cli/validation/ethereum-contract-without-handlers/Abi.json +0 -7
  180. package/tests/cli/validation/ethereum-contract-without-handlers/mapping.ts +0 -0
  181. package/tests/cli/validation/ethereum-contract-without-handlers/schema.graphql +0 -3
  182. package/tests/cli/validation/ethereum-contract-without-handlers/subgraph.yaml +0 -19
  183. package/tests/cli/validation/ethereum-contract-without-handlers.stderr +0 -6
  184. package/tests/cli/validation/event-not-found/Abi.json +0 -7
  185. package/tests/cli/validation/event-not-found/mapping.ts +0 -0
  186. package/tests/cli/validation/event-not-found/schema.graphql +0 -3
  187. package/tests/cli/validation/event-not-found/subgraph.yaml +0 -40
  188. package/tests/cli/validation/event-not-found.stderr +0 -12
  189. package/tests/cli/validation/example-values-found/Abi.json +0 -7
  190. package/tests/cli/validation/example-values-found/generated/ExampleSubgraph/ExampleContract.ts +0 -35
  191. package/tests/cli/validation/example-values-found/generated/schema.ts +0 -44
  192. package/tests/cli/validation/example-values-found/mapping.ts +0 -0
  193. package/tests/cli/validation/example-values-found/schema.graphql +0 -3
  194. package/tests/cli/validation/example-values-found/subgraph.yaml +0 -24
  195. package/tests/cli/validation/example-values-found.stderr +0 -34
  196. package/tests/cli/validation/invalid-abis/InvalidAbi.json +0 -1
  197. package/tests/cli/validation/invalid-abis/mapping.ts +0 -0
  198. package/tests/cli/validation/invalid-abis/schema.graphql +0 -3
  199. package/tests/cli/validation/invalid-abis/subgraph.yaml +0 -22
  200. package/tests/cli/validation/invalid-abis.stderr +0 -5
  201. package/tests/cli/validation/invalid-contract-addresses/Abi.json +0 -7
  202. package/tests/cli/validation/invalid-contract-addresses/mapping.ts +0 -0
  203. package/tests/cli/validation/invalid-contract-addresses/schema.graphql +0 -3
  204. package/tests/cli/validation/invalid-contract-addresses/subgraph.yaml +0 -58
  205. package/tests/cli/validation/invalid-contract-addresses.stderr +0 -14
  206. package/tests/cli/validation/invalid-data-source-template/mapping.ts +0 -0
  207. package/tests/cli/validation/invalid-data-source-template/schema.graphql +0 -3
  208. package/tests/cli/validation/invalid-data-source-template/subgraph.yaml +0 -32
  209. package/tests/cli/validation/invalid-data-source-template.stderr +0 -30
  210. package/tests/cli/validation/invalid-entity-field-types/Abi.json +0 -7
  211. package/tests/cli/validation/invalid-entity-field-types/mapping.ts +0 -0
  212. package/tests/cli/validation/invalid-entity-field-types/schema.graphql +0 -157
  213. package/tests/cli/validation/invalid-entity-field-types/subgraph.yaml +0 -22
  214. package/tests/cli/validation/invalid-entity-field-types.stderr +0 -148
  215. package/tests/cli/validation/invalid-fulltext-directive/Abi.json +0 -7
  216. package/tests/cli/validation/invalid-fulltext-directive/mapping.ts +0 -0
  217. package/tests/cli/validation/invalid-fulltext-directive/schema.graphql +0 -140
  218. package/tests/cli/validation/invalid-fulltext-directive/subgraph.yaml +0 -22
  219. package/tests/cli/validation/invalid-fulltext-directive.stderr +0 -32
  220. package/tests/cli/validation/invalid-graphql-schema/Abi.json +0 -7
  221. package/tests/cli/validation/invalid-graphql-schema/mapping.ts +0 -0
  222. package/tests/cli/validation/invalid-graphql-schema/schema.graphql +0 -8
  223. package/tests/cli/validation/invalid-graphql-schema/subgraph.yaml +0 -22
  224. package/tests/cli/validation/invalid-graphql-schema.stderr +0 -25
  225. package/tests/cli/validation/invalid-manifest/subgraph.yaml +0 -13
  226. package/tests/cli/validation/invalid-manifest-cannot-infer-protocol/subgraph.yaml +0 -12
  227. package/tests/cli/validation/invalid-manifest-cannot-infer-protocol.stderr +0 -5
  228. package/tests/cli/validation/invalid-manifest.stderr +0 -28
  229. package/tests/cli/validation/missing-entity-id/Abi.json +0 -7
  230. package/tests/cli/validation/missing-entity-id/mapping.ts +0 -0
  231. package/tests/cli/validation/missing-entity-id/schema.graphql +0 -3
  232. package/tests/cli/validation/missing-entity-id/subgraph.yaml +0 -22
  233. package/tests/cli/validation/missing-entity-id/types/ExampleSubgraph/ExampleContract.ts +0 -35
  234. package/tests/cli/validation/missing-entity-id/types/schema.ts +0 -27
  235. package/tests/cli/validation/missing-entity-id.stderr +0 -5
  236. package/tests/cli/validation/missing-or-invalid-derived-from-fields/Abi.json +0 -7
  237. package/tests/cli/validation/missing-or-invalid-derived-from-fields/mapping.ts +0 -0
  238. package/tests/cli/validation/missing-or-invalid-derived-from-fields/schema.graphql +0 -40
  239. package/tests/cli/validation/missing-or-invalid-derived-from-fields/subgraph.yaml +0 -22
  240. package/tests/cli/validation/missing-or-invalid-derived-from-fields.stderr +0 -10
  241. package/tests/cli/validation/missing-or-invalid-derived-from-fields.stdout +0 -0
  242. package/tests/cli/validation/near-is-valid/mapping.ts +0 -0
  243. package/tests/cli/validation/near-is-valid/schema.graphql +0 -8
  244. package/tests/cli/validation/near-is-valid/subgraph.yaml +0 -30
  245. package/tests/cli/validation/nested-template-nice-error/Abi.json +0 -7
  246. package/tests/cli/validation/nested-template-nice-error/mapping.ts +0 -0
  247. package/tests/cli/validation/nested-template-nice-error/schema.graphql +0 -3
  248. package/tests/cli/validation/nested-template-nice-error/subgraph.yaml +0 -35
  249. package/tests/cli/validation/nested-template-nice-error.stderr +0 -5
  250. package/tests/cli/validation/no-network-names/Abi.json +0 -7
  251. package/tests/cli/validation/no-network-names/mapping.ts +0 -0
  252. package/tests/cli/validation/no-network-names/schema.graphql +0 -3
  253. package/tests/cli/validation/no-network-names/subgraph.yaml +0 -40
  254. package/tests/cli/validation/no-network-names.stderr +0 -34
  255. package/tests/cli/validation/source-without-address-is-valid/Abi.json +0 -7
  256. package/tests/cli/validation/source-without-address-is-valid/generated/ExampleSubgraph/ExampleContract.ts +0 -35
  257. package/tests/cli/validation/source-without-address-is-valid/mapping.ts +0 -0
  258. package/tests/cli/validation/source-without-address-is-valid/schema.graphql +0 -3
  259. package/tests/cli/validation/source-without-address-is-valid/subgraph.yaml +0 -23
  260. package/tests/cli/validation/source-without-address-is-valid.stderr +0 -24
  261. package/tests/cli/validation/topic0-is-valid/Abi.json +0 -7
  262. package/tests/cli/validation/topic0-is-valid/mapping.ts +0 -0
  263. package/tests/cli/validation/topic0-is-valid/schema.graphql +0 -4
  264. package/tests/cli/validation/topic0-is-valid/subgraph.yaml +0 -24
  265. package/tests/cli/validation.test.ts +0 -226
  266. package/tsconfig.build.json +0 -4
  267. 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
- });
@@ -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
- }