@graphprotocol/graph-cli 0.34.0-alpha.0 → 0.35.0-alpha.0

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.
@@ -22,7 +22,6 @@ export namespace ethereum {
22
22
  FIXED_ARRAY = 7,
23
23
  ARRAY = 8,
24
24
  TUPLE = 9,
25
- MATRIX = 10,
26
25
  }
27
26
 
28
27
  /**
@@ -104,8 +103,12 @@ export namespace ethereum {
104
103
  }
105
104
 
106
105
  toMatrix(): Array<Array<Value>> {
107
- assert(this.kind == ValueKind.MATRIX, 'Ethereum value is not a matrix.')
108
- return changetype<Array<Array<Value>>>(this.data as u32)
106
+ let valueArray = this.toArray()
107
+ let out = new Array<Array<Value>>(valueArray.length)
108
+ for (let i: i32 = 0; i < valueArray.length; i++) {
109
+ out[i] = valueArray[i].toArray()
110
+ }
111
+ return out
109
112
  }
110
113
 
111
114
  toTupleArray<T extends Tuple>(): Array<T> {
@@ -122,7 +125,6 @@ export namespace ethereum {
122
125
  }
123
126
 
124
127
  toTupleMatrix<T extends Tuple>(): Array<Array<T>> {
125
- assert(this.kind == ValueKind.MATRIX, 'Ethereum value is not a matrix.')
126
128
  let valueMatrix = this.toMatrix()
127
129
  let out = new Array<Array<T>>(valueMatrix.length)
128
130
  for (let i: i32 = 0; i < valueMatrix.length; i++) {
@@ -213,7 +215,6 @@ export namespace ethereum {
213
215
  }
214
216
 
215
217
  toBooleanMatrix(): Array<Array<boolean>> {
216
- assert(this.kind == ValueKind.MATRIX, 'Ethereum value is not a matrix.')
217
218
  let valueMatrix = this.toMatrix()
218
219
  let out = new Array<Array<boolean>>(valueMatrix.length)
219
220
  for (let i: i32 = 0; i < valueMatrix.length; i++) {
@@ -226,7 +227,6 @@ export namespace ethereum {
226
227
  }
227
228
 
228
229
  toBytesMatrix(): Array<Array<Bytes>> {
229
- assert(this.kind == ValueKind.MATRIX, 'Ethereum value is not a matrix.')
230
230
  let valueMatrix = this.toMatrix()
231
231
  let out = new Array<Array<Bytes>>(valueMatrix.length)
232
232
  for (let i: i32 = 0; i < valueMatrix.length; i++) {
@@ -239,7 +239,6 @@ export namespace ethereum {
239
239
  }
240
240
 
241
241
  toAddressMatrix(): Array<Array<Address>> {
242
- assert(this.kind == ValueKind.MATRIX, 'Ethereum value is not a matrix.')
243
242
  let valueMatrix = this.toMatrix()
244
243
  let out = new Array<Array<Address>>(valueMatrix.length)
245
244
  for (let i: i32 = 0; i < valueMatrix.length; i++) {
@@ -252,7 +251,6 @@ export namespace ethereum {
252
251
  }
253
252
 
254
253
  toStringMatrix(): Array<Array<string>> {
255
- assert(this.kind == ValueKind.MATRIX, 'Ethereum value is not a matrix.')
256
254
  let valueMatrix = this.toMatrix()
257
255
  let out = new Array<Array<string>>(valueMatrix.length)
258
256
  for (let i: i32 = 0; i < valueMatrix.length; i++) {
@@ -265,7 +263,6 @@ export namespace ethereum {
265
263
  }
266
264
 
267
265
  toI32Matrix(): Array<Array<i32>> {
268
- assert(this.kind == ValueKind.MATRIX, 'Ethereum value is not a matrix.')
269
266
  let valueMatrix = this.toMatrix()
270
267
  let out = new Array<Array<i32>>(valueMatrix.length)
271
268
  for (let i: i32 = 0; i < valueMatrix.length; i++) {
@@ -278,7 +275,6 @@ export namespace ethereum {
278
275
  }
279
276
 
280
277
  toBigIntMatrix(): Array<Array<BigInt>> {
281
- assert(this.kind == ValueKind.MATRIX, 'Ethereum value is not a matrix.')
282
278
  let valueMatrix = this.toMatrix()
283
279
  let out = new Array<Array<BigInt>>(valueMatrix.length)
284
280
  for (let i: i32 = 0; i < valueMatrix.length; i++) {
@@ -336,7 +332,11 @@ export namespace ethereum {
336
332
  }
337
333
 
338
334
  static fromMatrix(values: Array<Array<Value>>): Value {
339
- return new Value(ValueKind.MATRIX, changetype<u32>(values))
335
+ let innerOut = new Array<Value>(values.length)
336
+ for (let i: i32 = 0; i < innerOut.length; i++) {
337
+ innerOut[i] = Value.fromArray(values[i])
338
+ }
339
+ return Value.fromArray(innerOut)
340
340
  }
341
341
 
342
342
  static fromTupleArray(values: Array<Tuple>): Value {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@graphprotocol/graph-ts",
3
3
  "description": "TypeScript/AssemblyScript library for writing subgraph mappings for The Graph",
4
- "version": "0.28.0-alpha.0",
4
+ "version": "0.28.0",
5
5
  "module": "index.ts",
6
6
  "types": "index.ts",
7
7
  "main": "index.ts",
@@ -9,7 +9,7 @@
9
9
  "deploy-test": "../../bin/graph deploy test/basic-event-handlers --version-label v0.0.1 --ipfs http://localhost:15001 --node http://127.0.0.1:18020"
10
10
  },
11
11
  "devDependencies": {
12
- "@graphprotocol/graph-ts": "0.28.0-alpha.0",
12
+ "@graphprotocol/graph-ts": "0.28.0",
13
13
  "apollo-fetch": "^0.7.0"
14
14
  },
15
15
  "dependencies": {
@@ -2,10 +2,10 @@
2
2
  # yarn lockfile v1
3
3
 
4
4
 
5
- "@graphprotocol/graph-ts@0.28.0-alpha.0":
6
- version "0.28.0-alpha.0"
7
- resolved "https://registry.yarnpkg.com/@graphprotocol/graph-ts/-/graph-ts-0.28.0-alpha.0.tgz#2d687842c42a25b306e49591cecc413af5ded91f"
8
- integrity sha512-3ZaYh8Xs9cMGcfW8ft+HR0rpT1/SM3wRnUsyPHjPpdVaOykjRTz5noRKYkYFw8r6tdlC+xIWc34/Qp6RaT9SBg==
5
+ "@graphprotocol/graph-ts@0.28.0":
6
+ version "0.28.0"
7
+ resolved "https://registry.yarnpkg.com/@graphprotocol/graph-ts/-/graph-ts-0.28.0.tgz#4229ad10b9a956c76f126bb08a856c556eedef22"
8
+ integrity sha512-Qug3KpmqZ/KOg3FFBOtD74GAK/9AkR7lTxoEYMdx3jZ/+fi9oOSDod2vEkLOjUxsE7yZOseNqiXOxeU0XGqJWw==
9
9
  dependencies:
10
10
  assemblyscript "0.19.10"
11
11
 
@@ -7,7 +7,7 @@
7
7
  "build-wast": "../../bin/graph build -t wast subgraph.yaml"
8
8
  },
9
9
  "devDependencies": {
10
- "@graphprotocol/graph-ts": "0.28.0-alpha.0"
10
+ "@graphprotocol/graph-ts": "0.28.0"
11
11
  },
12
12
  "resolutions": {
13
13
  "assemblyscript": "0.19.10"
@@ -2,10 +2,10 @@
2
2
  # yarn lockfile v1
3
3
 
4
4
 
5
- "@graphprotocol/graph-ts@0.28.0-alpha.0":
6
- version "0.28.0-alpha.0"
7
- resolved "https://registry.yarnpkg.com/@graphprotocol/graph-ts/-/graph-ts-0.28.0-alpha.0.tgz#2d687842c42a25b306e49591cecc413af5ded91f"
8
- integrity sha512-3ZaYh8Xs9cMGcfW8ft+HR0rpT1/SM3wRnUsyPHjPpdVaOykjRTz5noRKYkYFw8r6tdlC+xIWc34/Qp6RaT9SBg==
5
+ "@graphprotocol/graph-ts@0.28.0":
6
+ version "0.28.0"
7
+ resolved "https://registry.yarnpkg.com/@graphprotocol/graph-ts/-/graph-ts-0.28.0.tgz#4229ad10b9a956c76f126bb08a856c556eedef22"
8
+ integrity sha512-Qug3KpmqZ/KOg3FFBOtD74GAK/9AkR7lTxoEYMdx3jZ/+fi9oOSDod2vEkLOjUxsE7yZOseNqiXOxeU0XGqJWw==
9
9
  dependencies:
10
10
  assemblyscript "0.19.10"
11
11
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphprotocol/graph-cli",
3
- "version": "0.34.0-alpha.0",
3
+ "version": "0.35.0-alpha.0",
4
4
  "license": "(Apache-2.0 OR MIT)",
5
5
  "description": "CLI for building for and deploying to The Graph",
6
6
  "dependencies": {
@@ -179,7 +179,6 @@ const ASSEMBLYSCRIPT_TO_ETHEREUM_VALUE = [
179
179
  code => `ethereum.Value.fromTupleArray(${code})`,
180
180
  ],
181
181
 
182
- // ethereumToAsc
183
182
  // Multi dimentional arrays
184
183
 
185
184
  [
@@ -18,13 +18,17 @@ const isTupleType = t => {
18
18
  }
19
19
 
20
20
  const containsTupleType = t => {
21
- return isTupleType(t) || isTupleArrayType(t)
21
+ return isTupleType(t) || isTupleArrayType(t) || isTupleMatrixType(t)
22
22
  }
23
23
 
24
24
  const isTupleArrayType = t => {
25
25
  return t.match(/^tuple\[([0-9]+)?\]$/)
26
26
  }
27
27
 
28
+ const isTupleMatrixType = t => {
29
+ return t.match(/^tuple\[([0-9]+)?\]\[([0-9]+)?\]$/)
30
+ }
31
+
28
32
  const unrollTuple = ({ path, index, value }) =>
29
33
  value.components.reduce((acc, component, index) => {
30
34
  let name = component.name || `value${index}`
@@ -44,5 +48,6 @@ module.exports = {
44
48
  disambiguateNames,
45
49
  isTupleType,
46
50
  isTupleArrayType,
51
+ isTupleMatrixType,
47
52
  unrollTuple,
48
53
  }
@@ -65,6 +65,7 @@ const getEtherscanLikeAPIUrl = (network) => {
65
65
  case "mbase": return `https://api-moonbase.moonscan.io/api`
66
66
  case "avalanche": return `https://api.snowtrace.io/api`;
67
67
  case "fuji": return `https://api-testnet.snowtrace.io/api`;
68
+ case "gnosis": return `https://api.gnosisscan.io/api`;
68
69
  default: return `https://api-${network}.etherscan.io/api`
69
70
  }
70
71
  }
@@ -28,8 +28,14 @@ const withSpinner = async (text, errorText, warningText, f) => {
28
28
  try {
29
29
  let result = await f(spinner)
30
30
  if (typeof result === 'object') {
31
+ let hasError = Object.keys(result).indexOf('error') >= 0
31
32
  let hasWarning = Object.keys(result).indexOf('warning') >= 0
32
33
  let hasResult = Object.keys(result).indexOf('result') >= 0
34
+
35
+ if (hasError) {
36
+ spinner.fail(`${errorText}: ${result.error}`)
37
+ return hasResult ? result.result : result
38
+ }
33
39
  if (hasWarning && hasResult) {
34
40
  if (result.warning !== null) {
35
41
  spinner.warn(`${warningText}: ${result.warning}`)
@@ -1,4 +1,4 @@
1
- const allowedStudioNetworks = ['mainnet', 'rinkeby', 'goerli']
1
+ const allowedStudioNetworks = ['mainnet', 'rinkeby', 'goerli', 'gnosis']
2
2
 
3
3
  const validateStudioNetwork = ({ studio, product, network }) => {
4
4
  let isStudio = studio || product === 'subgraph-studio'
@@ -12,10 +12,19 @@ describe('Version Command Helpers', () => {
12
12
  .toThrow(new Error(`The Subgraph Studio only allows subgraphs for these networks: ${allowedStudioNetworks.join(', ')}`))
13
13
  })
14
14
 
15
- test("And it's NOT Ethereum mainnet", () => {
15
+ test("And it's Gnosis chain", () => {
16
+ expect(() => validateStudioNetwork({
17
+ studio: true,
18
+ network: 'gnosis',
19
+ }))
20
+ .not
21
+ .toThrow(new Error(`The Subgraph Studio only allows subgraphs for these networks: ${allowedStudioNetworks.join(', ')}`))
22
+ })
23
+
24
+ test("And it's NOT an allowed network", () => {
16
25
  expect(() => validateStudioNetwork({
17
26
  product: 'subgraph-studio',
18
- network: 'xdai',
27
+ network: 'celo',
19
28
  }))
20
29
  .toThrow(new Error(`The Subgraph Studio only allows subgraphs for these networks: ${allowedStudioNetworks.join(', ')}`))
21
30
  })
@@ -31,10 +40,10 @@ describe('Version Command Helpers', () => {
31
40
  .toThrow(new Error(`The Subgraph Studio only allows subgraphs for these networks: ${allowedStudioNetworks.join(', ')}`))
32
41
  })
33
42
 
34
- test("And it's NOT Ethereum mainnet", () => {
43
+ test("And it's NOT an allowed network", () => {
35
44
  expect(() => validateStudioNetwork({
36
45
  product: 'hosted-service',
37
- network: 'xdai',
46
+ network: 'celo',
38
47
  }))
39
48
  .not
40
49
  .toThrow(new Error(`The Subgraph Studio only allows subgraphs for these networks: ${allowedStudioNetworks.join(', ')}`))
@@ -24,6 +24,8 @@ const Protocol = require('../protocols')
24
24
  const protocolChoices = Array.from(Protocol.availableProtocols().keys())
25
25
  const availableNetworks = Protocol.availableNetworks()
26
26
 
27
+ const DEFAULT_EXAMPLE_SUBGRAPH = 'ethereum/gravatar'
28
+
27
29
  const HELP = `
28
30
  ${chalk.bold('graph init')} [options] [subgraph-name] [directory]
29
31
 
@@ -40,7 +42,7 @@ ${chalk.dim('Options:')}
40
42
  ${chalk.dim('Choose mode with one of:')}
41
43
 
42
44
  --from-contract <contract> Creates a scaffold based on an existing contract
43
- --from-example Creates a scaffold based on an example subgraph
45
+ --from-example [example] Creates a scaffold based on an example subgraph
44
46
 
45
47
  ${chalk.dim('Options for --from-contract:')}
46
48
 
@@ -106,7 +108,7 @@ const processInitForm = async (
106
108
  message: 'Product for which to initialize',
107
109
  choices: ['subgraph-studio', 'hosted-service'],
108
110
  skip: () =>
109
- protocol === 'near' ||
111
+ protocol === 'arweave' || protocol === 'cosmos' || protocol === 'near' ||
110
112
  product === 'subgraph-studio' ||
111
113
  product === 'hosted-service' ||
112
114
  studio !== undefined || node !== undefined,
@@ -280,9 +282,6 @@ const loadAbiFromFile = async (ABI, filename) => {
280
282
 
281
283
  module.exports = {
282
284
  description: 'Creates a new subgraph with basic scaffolding',
283
- options: {
284
- boolean: ['from-example'],
285
- },
286
285
  run: async toolbox => {
287
286
  // Obtain tools
288
287
  let { print, system } = toolbox
@@ -317,7 +316,6 @@ module.exports = {
317
316
  let subgraphName, directory
318
317
  try {
319
318
  ;[subgraphName, directory] = fixParameters(toolbox.parameters, {
320
- fromExample,
321
319
  allowSimpleName,
322
320
  help,
323
321
  h,
@@ -368,7 +366,7 @@ module.exports = {
368
366
  if (fromExample && subgraphName && directory) {
369
367
  return await initSubgraphFromExample(
370
368
  toolbox,
371
- { allowSimpleName, directory, subgraphName, studio, product },
369
+ { fromExample, allowSimpleName, directory, subgraphName, studio, product },
372
370
  { commands },
373
371
  )
374
372
  }
@@ -455,6 +453,7 @@ module.exports = {
455
453
  await initSubgraphFromExample(
456
454
  toolbox,
457
455
  {
456
+ fromExample: fromExample,
458
457
  subgraphName: inputs.subgraphName,
459
458
  directory: inputs.directory,
460
459
  studio: inputs.studio,
@@ -588,7 +587,7 @@ Make sure to visit the documentation on https://thegraph.com/docs/ for further i
588
587
 
589
588
  const initSubgraphFromExample = async (
590
589
  toolbox,
591
- { allowSimpleName, subgraphName, directory, studio, product },
590
+ { fromExample, allowSimpleName, subgraphName, directory, studio, product },
592
591
  { commands },
593
592
  ) => {
594
593
  let { filesystem, print, system } = toolbox
@@ -612,10 +611,32 @@ const initSubgraphFromExample = async (
612
611
  `Failed to clone example subgraph`,
613
612
  `Warnings while cloning example subgraph`,
614
613
  async spinner => {
615
- await system.run(
616
- `git clone http://github.com/graphprotocol/example-subgraph ${directory}`,
617
- )
618
- return true
614
+ // Create a temporary directory
615
+ const prefix = path.join(os.tmpdir(), 'example-subgraph-')
616
+ const tmpDir = fs.mkdtempSync(prefix)
617
+
618
+ try {
619
+ await system.run(
620
+ `git clone http://github.com/graphprotocol/example-subgraphs ${tmpDir}`
621
+ )
622
+
623
+ // If an example is not specified, use the default one
624
+ if (fromExample === undefined || fromExample === true) {
625
+ fromExample = DEFAULT_EXAMPLE_SUBGRAPH
626
+ }
627
+
628
+ const exampleSubgraphPath = path.join(tmpDir, fromExample);
629
+
630
+ if (!filesystem.exists(exampleSubgraphPath)) {
631
+ return { result: false, error: `Example not found: ${fromExample}` }
632
+ }
633
+
634
+ filesystem.copy(exampleSubgraphPath, directory)
635
+ return true
636
+ }
637
+ finally {
638
+ filesystem.remove(tmpDir)
639
+ }
619
640
  },
620
641
  )
621
642
  if (!cloned) {
@@ -5,6 +5,7 @@ const path = require('path')
5
5
  const AbiCodeGenerator = require('./codegen/abi')
6
6
 
7
7
  const TUPLE_ARRAY_PATTERN = /^tuple\[([0-9]*)\]$/
8
+ const TUPLE_MATRIX_PATTERN = /^tuple\[([0-9]*)\]\[([0-9]*)\]$/
8
9
 
9
10
  const buildOldSignatureParameter = input => {
10
11
  return input.get('type') === 'tuple'
@@ -27,6 +28,13 @@ const buildSignatureParameter = input => {
27
28
  .get('components')
28
29
  .map(component => buildSignatureParameter(component))
29
30
  .join(',')})[${length ? length : ''}]`
31
+ } else if (input.get('type').match(TUPLE_MATRIX_PATTERN)) {
32
+ const length1 = input.get('type').match(TUPLE_MATRIX_PATTERN)[1]
33
+ const length2 = input.get('type').match(TUPLE_MATRIX_PATTERN)[2]
34
+ return `(${input.get('indexed') ? 'indexed ' : ''}${input
35
+ .get('components')
36
+ .map(component => buildSignatureParameter(component))
37
+ .join(',')})[${length1 ? length1 : ''}][${length2 ? length2 : ''}]`
30
38
  } else {
31
39
  return `${input.get('indexed') ? 'indexed ' : ''}${input.get('type')}`
32
40
  }
@@ -362,7 +362,11 @@ module.exports = class AbiCodeGenerator {
362
362
  let tupleGetter = tsCodegen.method(
363
363
  `get ${name}`,
364
364
  [],
365
- util.isTupleArrayType(type) ? `Array<${tupleClassName}>` : tupleClassName,
365
+ util.isTupleMatrixType(type)
366
+ ? `Array<Array<${tupleClassName}>>`
367
+ : util.isTupleArrayType(type)
368
+ ? `Array<${tupleClassName}>`
369
+ : tupleClassName,
366
370
  `
367
371
  return ${
368
372
  isTupleType ? `changetype<${tupleClassName}>(${returnValue})` : `${returnValue}`
@@ -686,6 +690,13 @@ module.exports = class AbiCodeGenerator {
686
690
  const type = inputOrOutput.get('type')
687
691
  return util.isTupleType(type)
688
692
  ? this._tupleTypeName(inputOrOutput, index, tupleParentType, this.abi.name)
693
+ : util.isTupleMatrixType(type)
694
+ ? `Array<Array<${this._tupleTypeName(
695
+ inputOrOutput,
696
+ index,
697
+ tupleParentType,
698
+ this.abi.name,
699
+ )}>>`
689
700
  : util.isTupleArrayType(type)
690
701
  ? `Array<${this._tupleTypeName(
691
702
  inputOrOutput,
@@ -46,7 +46,7 @@ module.exports = class Protocol {
46
46
  'goerli',
47
47
  'poa-core',
48
48
  'poa-sokol',
49
- 'xdai',
49
+ 'gnosis',
50
50
  'matic',
51
51
  'mumbai',
52
52
  'fantom',
@@ -53,7 +53,7 @@ module.exports = class Scaffold {
53
53
  },
54
54
  dependencies: {
55
55
  '@graphprotocol/graph-cli': GRAPH_CLI_VERSION,
56
- '@graphprotocol/graph-ts': `0.28.0-alpha.0`,
56
+ '@graphprotocol/graph-ts': `0.28.0`,
57
57
  },
58
58
  devDependencies: this.protocol.hasEvents() ? { 'matchstick-as': `0.5.0`} : undefined,
59
59
  }),
package/src/subgraph.js CHANGED
@@ -100,17 +100,18 @@ module.exports = class Subgraph {
100
100
  }
101
101
 
102
102
  static validateRepository(manifest, { resolveFile }) {
103
- return manifest.get('repository') !==
104
- 'https://github.com/graphprotocol/example-subgraph'
105
- ? immutable.List()
106
- : immutable.List().push(
103
+ const repository = manifest.get('repository')
104
+
105
+ return /^https:\/\/github\.com\/graphprotocol\/example-subgraphs?$/.test(repository)
106
+ ? immutable.List().push(
107
107
  immutable.fromJS({
108
108
  path: ['repository'],
109
109
  message: `\
110
- The repository is still set to https://github.com/graphprotocol/example-subgraph.
110
+ The repository is still set to ${repository}.
111
111
  Please replace it with a link to your subgraph source code.`,
112
112
  }),
113
113
  )
114
+ : immutable.List()
114
115
  }
115
116
 
116
117
  static validateDescription(manifest, { resolveFile }) {
@@ -247,7 +247,7 @@ const validateValue = (value, ctx) => {
247
247
  // [
248
248
  // { name: 'contract0', kind: 'ethereum/contract', network: 'mainnet' },
249
249
  // { name: 'contract1', kind: 'ethereum', network: 'mainnet' },
250
- // { name: 'contract2', kind: 'ethereum/contract', network: 'xdai' },
250
+ // { name: 'contract2', kind: 'ethereum/contract', network: 'gnosis' },
251
251
  // { name: 'contract3', kind: 'near', network: 'near-mainnet' },
252
252
  // ]
253
253
  //
@@ -255,7 +255,7 @@ const validateValue = (value, ctx) => {
255
255
  // {
256
256
  // ethereum: {
257
257
  // mainnet: ['contract0', 'contract1'],
258
- // xdai: ['contract2'],
258
+ // gnosis: ['contract2'],
259
259
  // },
260
260
  // near: {
261
261
  // 'near-mainnet': ['contract3'],
@@ -15,6 +15,7 @@ describe('Init', () => {
15
15
  'ethereum',
16
16
  '--studio',
17
17
  '--from-example',
18
+ 'ethereum/gravatar',
18
19
  'user/example-subgraph',
19
20
  path.join(ethereumBaseDir, 'from-example'),
20
21
  ],