@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,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,64 +0,0 @@
1
- # Each referenced type's in any of the types below must be listed
2
- # here either as `scalar` or `type` for the validation code to work
3
- # properly.
4
- #
5
- # That's why `String` is listed as a scalar even though it's built-in
6
- # GraphQL basic types.
7
- scalar String
8
- scalar File
9
- scalar BigInt
10
-
11
- type SubgraphManifest {
12
- specVersion: String!
13
- features: [String!]
14
- schema: Schema!
15
- description: String
16
- repository: String
17
- graft: Graft
18
- dataSources: [DataSource!]!
19
- }
20
-
21
- type Schema {
22
- file: File!
23
- }
24
-
25
- type DataSource {
26
- kind: String!
27
- name: String!
28
- network: String
29
- source: ContractSource!
30
- mapping: ContractMapping!
31
- }
32
-
33
- type ContractSource {
34
- account: String
35
- startBlock: BigInt
36
- accounts: PartialAccount
37
- }
38
-
39
- type PartialAccount {
40
- prefixes: [String!]
41
- suffixes: [String!]
42
- }
43
-
44
- type ContractMapping {
45
- apiVersion: String!
46
- language: String!
47
- file: File!
48
- entities: [String!]!
49
- blockHandlers: [BlockHandler!]
50
- receiptHandlers: [ReceiptHandler!]
51
- }
52
-
53
- type BlockHandler {
54
- handler: String!
55
- }
56
-
57
- type ReceiptHandler {
58
- handler: String!
59
- }
60
-
61
- type Graft {
62
- base: String!
63
- block: BigInt!
64
- }
@@ -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,35 +0,0 @@
1
- export const generatePlaceholderHandlers = () =>
2
- `
3
- import { near, BigInt } from '@graphprotocol/graph-ts'
4
- import { ExampleEntity } from '../generated/schema'
5
-
6
- export function handleReceipt(receiptWithOutcome: near.ReceiptWithOutcome): void {
7
- // Entities can be loaded from the store using a string ID; this ID
8
- // needs to be unique across all entities of the same type
9
- let entity = ExampleEntity.load(receiptWithOutcome.receipt.id.toHex())
10
-
11
- // Entities only exist after they have been saved to the store;
12
- // \`null\` checks allow to create entities on demand
13
- if (!entity) {
14
- entity = new ExampleEntity(receiptWithOutcome.receipt.id.toHex())
15
-
16
- // Entity fields can be set using simple assignments
17
- entity.count = BigInt.fromI32(0)
18
- }
19
-
20
- // BigInt and BigDecimal math are supported
21
- entity.count = entity.count + BigInt.fromI32(1)
22
-
23
- // Entity fields can be set based on receipt information
24
- entity.block = receiptWithOutcome.block.header.hash
25
-
26
- // Entities can be written to the store with \`.save()\`
27
- entity.save()
28
-
29
- // Note: If a handler doesn't require existing field values, it is faster
30
- // _not_ to load the entity from the store. Instead, create it fresh with
31
- // \`new Entity(...)\`, set the fields that should be updated and save the
32
- // entity back to the store. Fields that were not set or unset remain
33
- // unchanged, allowing for partial updates to be applied.
34
- }
35
- `;
@@ -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,45 +0,0 @@
1
- # Each referenced type's in any of the types below must be listed
2
- # here either as `scalar` or `type` for the validation code to work
3
- # properly.
4
- #
5
- # That's why `String` is listed as a scalar even though it's built-in
6
- # GraphQL basic types.
7
- scalar String
8
- scalar File
9
- scalar BigInt
10
-
11
- type SubgraphManifest {
12
- specVersion: String!
13
- features: [String!]
14
- schema: Schema!
15
- description: String
16
- repository: String
17
- graft: Graft
18
- dataSources: [DataSource!]!
19
- }
20
-
21
- type Schema {
22
- file: File!
23
- }
24
-
25
- type DataSource {
26
- kind: String!
27
- name: String!
28
- network: String
29
- source: SubstreamsSource!
30
- mapping: SubstreamMapping!
31
- }
32
-
33
- type SubstreamsSource {
34
- package: SubstreamsPackage!
35
- }
36
-
37
- type SubstreamsPackage {
38
- moduleName: String!
39
- file: String!
40
- }
41
-
42
- type SubstreamMapping {
43
- apiVersion: String!
44
- kind: String!
45
- }
@@ -1,8 +0,0 @@
1
- export const source = () => `
2
- package:
3
- moduleName: graph_out
4
- file: substreams-eth-block-meta-v0.1.0.spkg`;
5
-
6
- export const mapping = () => `
7
- apiVersion: 0.0.5
8
- kind: substreams/graph-entities`;
@@ -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
- }
@@ -1,83 +0,0 @@
1
- import Protocol from '../protocols';
2
- import Scaffold from './index';
3
-
4
- const protocol = new Protocol('cosmos');
5
-
6
- const scaffoldOptions = {
7
- protocol,
8
- network: 'cosmoshub-4',
9
- contractName: 'CosmosHub',
10
- };
11
-
12
- const scaffold = new Scaffold(scaffoldOptions);
13
-
14
- describe('Cosmos subgraph scaffolding', () => {
15
- test('Manifest', () => {
16
- expect(scaffold.generateManifest()).toEqual(`\
17
- specVersion: 0.0.5
18
- schema:
19
- file: ./schema.graphql
20
- dataSources:
21
- - kind: cosmos
22
- name: CosmosHub
23
- network: cosmoshub-4
24
- source:
25
- startBlock: 0
26
- mapping:
27
- apiVersion: 0.0.5
28
- language: wasm/assemblyscript
29
- entities:
30
- - ExampleEntity
31
- blockHandlers:
32
- - handler: handleBlock
33
- file: ./src/contract.ts
34
- `);
35
- });
36
-
37
- test('Schema (default)', () => {
38
- expect(scaffold.generateSchema()).toEqual(`\
39
- type ExampleEntity @entity {
40
- id: ID!
41
- block: Bytes!
42
- count: BigInt!
43
- }
44
- `);
45
- });
46
-
47
- test('Mapping (default)', () => {
48
- expect(scaffold.generateMapping()).toEqual(`\
49
- import { cosmos, BigInt } from "@graphprotocol/graph-ts"
50
- import { ExampleEntity } from "../generated/schema"
51
-
52
- export function handleBlock(block: cosmos.Block): void {
53
- // Entities can be loaded from the store using a string ID; this ID
54
- // needs to be unique across all entities of the same type
55
- let entity = ExampleEntity.load(block.header.hash.toHex())
56
-
57
- // Entities only exist after they have been saved to the store;
58
- // \`null\` checks allow to create entities on demand
59
- if (!entity) {
60
- entity = new ExampleEntity(block.header.hash.toHex())
61
-
62
- // Entity fields can be set using simple assignments
63
- entity.count = BigInt.fromI32(0)
64
- }
65
-
66
- // BigInt and BigDecimal math are supported
67
- entity.count = entity.count + BigInt.fromI32(1)
68
-
69
- // Entity fields can be set based on receipt information
70
- entity.height = block.header.height
71
-
72
- // Entities can be written to the store with \`.save()\`
73
- entity.save()
74
-
75
- // Note: If a handler doesn't require existing field values, it is faster
76
- // _not_ to load the entity from the store. Instead, create it fresh with
77
- // \`new Entity(...)\`, set the fields that should be updated and save the
78
- // entity back to the store. Fields that were not set or unset remain
79
- // unchanged, allowing for partial updates to be applied.
80
- }
81
- `);
82
- });
83
- });