@graphprotocol/graph-cli 0.22.3 → 0.23.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +83 -0
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/.travis.yml +4 -0
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/chain/ethereum.ts +9 -15
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/chain/near.ts +402 -0
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/collections.ts +125 -4
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/eager_offset.ts +2 -1
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/json.ts +14 -0
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/numbers.ts +58 -16
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/value.ts +2 -5
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/global/global.ts +108 -0
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/helper-functions.ts +5 -5
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/index.ts +6 -15
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/package.json +5 -2
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/test/bigInt.ts +138 -108
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/test/bytes.ts +31 -20
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/test/test.js +120 -88
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/tsconfig.json +2 -2
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/types/tsconfig.base.json +3 -0
- package/examples/basic-event-handlers/node_modules/websocket/build/Makefile +2 -2
- package/examples/basic-event-handlers/package.json +1 -1
- package/examples/basic-event-handlers/yarn.lock +4 -4
- package/examples/example-subgraph/package.json +1 -1
- package/examples/example-subgraph/yarn.lock +4 -4
- package/examples/near/.gitkeep +0 -0
- package/jest.config.js +2 -2
- package/manifest-schema.graphql +35 -2
- package/package.json +2 -6
- package/src/codegen/schema.js +1 -2
- package/src/codegen/template.js +9 -51
- package/src/codegen/typescript.js +7 -0
- package/src/command-helpers/compiler.js +6 -2
- package/src/command-helpers/data-sources.js +38 -0
- package/src/command-helpers/fs.js +8 -0
- package/src/commands/build.js +14 -0
- package/src/commands/codegen.js +8 -0
- package/src/commands/deploy.js +11 -8
- package/src/commands/init.js +35 -11
- package/src/commands/test.js +9 -4
- package/src/compiler/index.js +93 -76
- package/src/{abi.js → protocols/ethereum/abi.js} +0 -0
- package/src/{codegen → protocols/ethereum/codegen}/abi.js +9 -6
- package/src/{codegen → protocols/ethereum/codegen}/abi.test.js +1 -1
- package/src/protocols/ethereum/codegen/template.js +42 -0
- package/src/protocols/ethereum/subgraph.js +205 -0
- package/src/protocols/ethereum/type-generator.js +203 -0
- package/src/protocols/index.js +97 -0
- package/src/protocols/near/subgraph.js +42 -0
- package/src/scaffold.js +21 -4
- package/src/scaffold.test.js +1 -1
- package/src/subgraph.js +30 -252
- package/src/type-generator.js +31 -211
- package/src/validation/index.js +1 -0
- package/src/validation/manifest.js +73 -23
- package/src/validation/schema.js +6 -0
- package/subgraph-ethereum.yaml +134 -0
- package/subgraph-near.yaml +134 -0
- package/tests/cli/globalSetup.js +6 -0
- package/tests/cli/globalTeardown.js +6 -0
- package/tests/cli/init.test.js +1 -1
- package/tests/cli/util.js +17 -8
- package/tests/cli/validation/near-is-valid/mapping.ts +0 -0
- package/tests/cli/validation/near-is-valid/schema.graphql +8 -0
- package/tests/cli/validation/near-is-valid/subgraph.yaml +21 -0
- package/tests/cli/validation.test.js +8 -0
package/manifest-schema.graphql
CHANGED
|
@@ -6,7 +6,10 @@ type Schema {
|
|
|
6
6
|
file: File!
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
union DataSource =
|
|
9
|
+
union DataSource =
|
|
10
|
+
EthereumContractDataSource |
|
|
11
|
+
NearContractDataSource
|
|
12
|
+
|
|
10
13
|
union DataSourceTemplate = EthereumContractDataSourceTemplate
|
|
11
14
|
|
|
12
15
|
type EthereumContractDataSource {
|
|
@@ -17,14 +20,27 @@ type EthereumContractDataSource {
|
|
|
17
20
|
mapping: EthereumContractMapping!
|
|
18
21
|
}
|
|
19
22
|
|
|
23
|
+
type NearContractDataSource {
|
|
24
|
+
kind: String!
|
|
25
|
+
name: String!
|
|
26
|
+
network: String
|
|
27
|
+
source: NearContractSource!
|
|
28
|
+
mapping: NearContractMapping!
|
|
29
|
+
}
|
|
30
|
+
|
|
20
31
|
type EthereumContractSource {
|
|
21
32
|
address: String
|
|
22
33
|
abi: String!
|
|
23
34
|
startBlock: BigInt
|
|
24
35
|
}
|
|
25
36
|
|
|
37
|
+
type NearContractSource {
|
|
38
|
+
account: String
|
|
39
|
+
startBlock: BigInt
|
|
40
|
+
}
|
|
41
|
+
|
|
26
42
|
type EthereumContractMapping {
|
|
27
|
-
kind: String
|
|
43
|
+
kind: String
|
|
28
44
|
apiVersion: String!
|
|
29
45
|
language: String!
|
|
30
46
|
file: File!
|
|
@@ -35,6 +51,15 @@ type EthereumContractMapping {
|
|
|
35
51
|
eventHandlers: [EthereumContractEventHandler!]
|
|
36
52
|
}
|
|
37
53
|
|
|
54
|
+
type NearContractMapping {
|
|
55
|
+
apiVersion: String!
|
|
56
|
+
language: String!
|
|
57
|
+
file: File!
|
|
58
|
+
entities: [String!]!
|
|
59
|
+
blockHandlers: [NearBlockHandler!]
|
|
60
|
+
receiptHandlers: [NearReceiptHandler!]
|
|
61
|
+
}
|
|
62
|
+
|
|
38
63
|
type EthereumContractAbi {
|
|
39
64
|
name: String!
|
|
40
65
|
file: File!
|
|
@@ -49,11 +74,19 @@ type EthereumBlockFilter {
|
|
|
49
74
|
kind: String!
|
|
50
75
|
}
|
|
51
76
|
|
|
77
|
+
type NearBlockHandler {
|
|
78
|
+
handler: String!
|
|
79
|
+
}
|
|
80
|
+
|
|
52
81
|
type EthereumCallHandler {
|
|
53
82
|
function: String!
|
|
54
83
|
handler: String!
|
|
55
84
|
}
|
|
56
85
|
|
|
86
|
+
type NearReceiptHandler {
|
|
87
|
+
handler: String!
|
|
88
|
+
}
|
|
89
|
+
|
|
57
90
|
type EthereumContractEventHandler {
|
|
58
91
|
event: String!
|
|
59
92
|
topic0: String
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphprotocol/graph-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.1",
|
|
4
4
|
"description": "CLI for building for and deploying to The Graph",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"assemblyscript": "0.19.10",
|
|
@@ -40,10 +40,6 @@
|
|
|
40
40
|
"scripts": {
|
|
41
41
|
"test": "jest --verbose",
|
|
42
42
|
"test:init": "jest tests/cli/init.test.js --verbose",
|
|
43
|
-
"test:validation": "jest tests/cli/validation.test.js --verbose"
|
|
44
|
-
"release:patch": "npm version patch && npm publish && git push origin master && git push --tags",
|
|
45
|
-
"release:minor": "npm version minor && npm publish && git push origin master && git push --tags",
|
|
46
|
-
"release:alpha:minor": "npm version preminor --preid alpha && npm publish --tag alpha && git push origin master && git push --tags",
|
|
47
|
-
"release:alpha:prerelease": "npm version prerelease --preid alpha && npm publish --tag alpha && git push origin master && git push --tags"
|
|
43
|
+
"test:validation": "jest tests/cli/validation.test.js --verbose"
|
|
48
44
|
}
|
|
49
45
|
}
|
package/src/codegen/schema.js
CHANGED
package/src/codegen/template.js
CHANGED
|
@@ -3,14 +3,19 @@ const immutable = require('immutable')
|
|
|
3
3
|
const tsCodegen = require('./typescript')
|
|
4
4
|
|
|
5
5
|
module.exports = class DataSourceTemplateCodeGenerator {
|
|
6
|
-
constructor(template) {
|
|
6
|
+
constructor(template, protocol) {
|
|
7
7
|
this.template = template
|
|
8
|
+
this.protocolTemplateCodeGen = protocol.getTemplateCodeGen(template)
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
generateModuleImports() {
|
|
11
12
|
return [
|
|
12
13
|
tsCodegen.moduleImports(
|
|
13
|
-
[
|
|
14
|
+
[
|
|
15
|
+
...this.protocolTemplateCodeGen.generateModuleImports(),
|
|
16
|
+
'DataSourceTemplate',
|
|
17
|
+
'DataSourceContext',
|
|
18
|
+
],
|
|
14
19
|
'@graphprotocol/graph-ts',
|
|
15
20
|
),
|
|
16
21
|
]
|
|
@@ -24,55 +29,8 @@ module.exports = class DataSourceTemplateCodeGenerator {
|
|
|
24
29
|
let name = this.template.get('name')
|
|
25
30
|
|
|
26
31
|
let klass = tsCodegen.klass(name, { export: true, extends: 'DataSourceTemplate' })
|
|
27
|
-
klass.addMethod(this.
|
|
28
|
-
klass.addMethod(this.
|
|
32
|
+
klass.addMethod(this.protocolTemplateCodeGen.generateCreateMethod())
|
|
33
|
+
klass.addMethod(this.protocolTemplateCodeGen.generateCreateWithContextMethod())
|
|
29
34
|
return klass
|
|
30
35
|
}
|
|
31
|
-
|
|
32
|
-
_generateCreateMethod() {
|
|
33
|
-
let name = this.template.get('name')
|
|
34
|
-
let kind = this.template.get('kind')
|
|
35
|
-
|
|
36
|
-
switch (kind) {
|
|
37
|
-
case 'ethereum/contract':
|
|
38
|
-
return tsCodegen.staticMethod(
|
|
39
|
-
'create',
|
|
40
|
-
[tsCodegen.param('address', tsCodegen.namedType('Address'))],
|
|
41
|
-
tsCodegen.namedType('void'),
|
|
42
|
-
`
|
|
43
|
-
DataSourceTemplate.create('${name}', [address.toHex()])
|
|
44
|
-
`,
|
|
45
|
-
)
|
|
46
|
-
|
|
47
|
-
default:
|
|
48
|
-
throw new Error(
|
|
49
|
-
`Data sources with kind != 'ethereum/contract' are not supported yet`,
|
|
50
|
-
)
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
_generateCreateWithContextMethod() {
|
|
55
|
-
let name = this.template.get('name')
|
|
56
|
-
let kind = this.template.get('kind')
|
|
57
|
-
|
|
58
|
-
switch (kind) {
|
|
59
|
-
case 'ethereum/contract':
|
|
60
|
-
return tsCodegen.staticMethod(
|
|
61
|
-
'createWithContext',
|
|
62
|
-
[
|
|
63
|
-
tsCodegen.param('address', tsCodegen.namedType('Address')),
|
|
64
|
-
tsCodegen.param('context', tsCodegen.namedType('DataSourceContext')),
|
|
65
|
-
],
|
|
66
|
-
tsCodegen.namedType('void'),
|
|
67
|
-
`
|
|
68
|
-
DataSourceTemplate.createWithContext('${name}', [address.toHex()], context)
|
|
69
|
-
`,
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
default:
|
|
73
|
-
throw new Error(
|
|
74
|
-
`Data sources with kind != 'ethereum/contract' are not supported yet`,
|
|
75
|
-
)
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
36
|
}
|
|
@@ -179,6 +179,10 @@ const klassMember = (name, type) => new ClassMember(name, type)
|
|
|
179
179
|
const nullableType = type => new NullableType(type)
|
|
180
180
|
const moduleImports = (nameOrNames, module) => new ModuleImports(nameOrNames, module)
|
|
181
181
|
|
|
182
|
+
const GENERATED_FILE_NOTE = `
|
|
183
|
+
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
|
184
|
+
`
|
|
185
|
+
|
|
182
186
|
module.exports = {
|
|
183
187
|
// Types
|
|
184
188
|
NullableType,
|
|
@@ -194,4 +198,7 @@ module.exports = {
|
|
|
194
198
|
param,
|
|
195
199
|
nullableType,
|
|
196
200
|
moduleImports,
|
|
201
|
+
|
|
202
|
+
// Utilities
|
|
203
|
+
GENERATED_FILE_NOTE,
|
|
197
204
|
}
|
|
@@ -4,7 +4,10 @@ const toolbox = require('gluegun/toolbox')
|
|
|
4
4
|
const Compiler = require('../compiler')
|
|
5
5
|
|
|
6
6
|
// Helper function to construct a subgraph compiler
|
|
7
|
-
const createCompiler = (
|
|
7
|
+
const createCompiler = (
|
|
8
|
+
manifest,
|
|
9
|
+
{ ipfs, outputDir, outputFormat, skipMigrations, blockIpfsMethods, protocol }
|
|
10
|
+
) => {
|
|
8
11
|
// Parse the IPFS URL
|
|
9
12
|
let url
|
|
10
13
|
try {
|
|
@@ -31,7 +34,8 @@ The IPFS URL must be of the following format: http(s)://host[:port]/[path]`)
|
|
|
31
34
|
outputDir: outputDir,
|
|
32
35
|
outputFormat: outputFormat,
|
|
33
36
|
skipMigrations,
|
|
34
|
-
blockIpfsMethods
|
|
37
|
+
blockIpfsMethods,
|
|
38
|
+
protocol,
|
|
35
39
|
})
|
|
36
40
|
}
|
|
37
41
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const immutable = require('immutable')
|
|
2
|
+
const { loadManifest } = require('../migrations/util/load-manifest')
|
|
3
|
+
|
|
4
|
+
// Loads manifest from file path and returns all:
|
|
5
|
+
// - data sources
|
|
6
|
+
// - templates
|
|
7
|
+
// In a single list.
|
|
8
|
+
const fromFilePath = async manifestPath => {
|
|
9
|
+
const { dataSources = [], templates = [] } = await loadManifest(manifestPath)
|
|
10
|
+
|
|
11
|
+
return dataSources.concat(templates)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const extractDataSourceByType = (manifest, dataSourceType, protocol) =>
|
|
15
|
+
manifest
|
|
16
|
+
.get(dataSourceType, immutable.List())
|
|
17
|
+
.reduce(
|
|
18
|
+
(dataSources, dataSource, dataSourceIndex) =>
|
|
19
|
+
protocol.isValidKindName(dataSource.get('kind'))
|
|
20
|
+
? dataSources.push(
|
|
21
|
+
immutable.Map({ path: [dataSourceType, dataSourceIndex], dataSource }),
|
|
22
|
+
)
|
|
23
|
+
: dataSources,
|
|
24
|
+
immutable.List(),
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
// Extracts data sources and templates from a immutable manifest data structure
|
|
28
|
+
const fromManifest = (manifest, protocol) => {
|
|
29
|
+
const dataSources = extractDataSourceByType(manifest, 'dataSources', protocol)
|
|
30
|
+
const templates = extractDataSourceByType(manifest, 'templates', protocol)
|
|
31
|
+
|
|
32
|
+
return dataSources.concat(templates)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = {
|
|
36
|
+
fromFilePath,
|
|
37
|
+
fromManifest,
|
|
38
|
+
}
|
package/src/commands/build.js
CHANGED
|
@@ -2,6 +2,8 @@ const chalk = require('chalk')
|
|
|
2
2
|
|
|
3
3
|
const { createCompiler } = require('../command-helpers/compiler')
|
|
4
4
|
const { fixParameters } = require('../command-helpers/gluegun')
|
|
5
|
+
const DataSourcesExtractor = require('../command-helpers/data-sources')
|
|
6
|
+
const Protocol = require('../protocols')
|
|
5
7
|
|
|
6
8
|
const HELP = `
|
|
7
9
|
${chalk.bold('graph build')} [options] ${chalk.bold('[<subgraph-manifest>]')}
|
|
@@ -73,11 +75,23 @@ module.exports = {
|
|
|
73
75
|
return
|
|
74
76
|
}
|
|
75
77
|
|
|
78
|
+
let protocol
|
|
79
|
+
try {
|
|
80
|
+
const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(manifest)
|
|
81
|
+
|
|
82
|
+
protocol = Protocol.fromDataSources(dataSourcesAndTemplates)
|
|
83
|
+
} catch (e) {
|
|
84
|
+
print.error(e.message)
|
|
85
|
+
process.exitCode = 1
|
|
86
|
+
return
|
|
87
|
+
}
|
|
88
|
+
|
|
76
89
|
let compiler = createCompiler(manifest, {
|
|
77
90
|
ipfs,
|
|
78
91
|
outputDir,
|
|
79
92
|
outputFormat,
|
|
80
93
|
skipMigrations,
|
|
94
|
+
protocol,
|
|
81
95
|
})
|
|
82
96
|
|
|
83
97
|
// Exit with an error code if the compiler couldn't be created
|
package/src/commands/codegen.js
CHANGED
|
@@ -2,7 +2,9 @@ const chalk = require('chalk')
|
|
|
2
2
|
const path = require('path')
|
|
3
3
|
|
|
4
4
|
const TypeGenerator = require('../type-generator')
|
|
5
|
+
const Protocol = require('../protocols')
|
|
5
6
|
const { fixParameters } = require('../command-helpers/gluegun')
|
|
7
|
+
const DataSourcesExtractor = require('../command-helpers/data-sources')
|
|
6
8
|
const { assertManifestApiVersion, assertGraphTsVersion } = require('../command-helpers/version')
|
|
7
9
|
|
|
8
10
|
const HELP = `
|
|
@@ -60,6 +62,7 @@ module.exports = {
|
|
|
60
62
|
return
|
|
61
63
|
}
|
|
62
64
|
|
|
65
|
+
let protocol
|
|
63
66
|
try {
|
|
64
67
|
// Checks to make sure codegen doesn't run against
|
|
65
68
|
// older subgraphs (both apiVersion and graph-ts version).
|
|
@@ -69,6 +72,10 @@ module.exports = {
|
|
|
69
72
|
// the wrong AssemblyScript version.
|
|
70
73
|
await assertManifestApiVersion(manifest, '0.0.5')
|
|
71
74
|
await assertGraphTsVersion(path.dirname(manifest), '0.22.0')
|
|
75
|
+
|
|
76
|
+
const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(manifest)
|
|
77
|
+
|
|
78
|
+
protocol = Protocol.fromDataSources(dataSourcesAndTemplates)
|
|
72
79
|
} catch (e) {
|
|
73
80
|
print.error(e.message)
|
|
74
81
|
process.exitCode = 1
|
|
@@ -79,6 +86,7 @@ module.exports = {
|
|
|
79
86
|
subgraphManifest: manifest,
|
|
80
87
|
outputDir: outputDir,
|
|
81
88
|
skipMigrations,
|
|
89
|
+
protocol,
|
|
82
90
|
})
|
|
83
91
|
|
|
84
92
|
// Watch working directory for file updates or additions, trigger
|
package/src/commands/deploy.js
CHANGED
|
@@ -11,8 +11,9 @@ const { withSpinner } = require('../command-helpers/spinner')
|
|
|
11
11
|
const { validateSubgraphName } = require('../command-helpers/subgraph')
|
|
12
12
|
const { DEFAULT_IPFS_URL } = require('../command-helpers/ipfs')
|
|
13
13
|
const { assertManifestApiVersion, assertGraphTsVersion } = require('../command-helpers/version')
|
|
14
|
+
const DataSourcesExtractor = require('../command-helpers/data-sources')
|
|
14
15
|
const { validateStudioNetwork } = require('../command-helpers/studio')
|
|
15
|
-
const
|
|
16
|
+
const Protocol = require('../protocols')
|
|
16
17
|
|
|
17
18
|
const HELP = `
|
|
18
19
|
${chalk.bold('graph deploy')} [options] ${chalk.bold('<subgraph-name>')} ${chalk.bold(
|
|
@@ -128,13 +129,9 @@ module.exports = {
|
|
|
128
129
|
: filesystem.resolve('subgraph.yaml')
|
|
129
130
|
|
|
130
131
|
try {
|
|
131
|
-
|
|
132
|
+
const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(manifest)
|
|
132
133
|
|
|
133
|
-
for (const { network } of
|
|
134
|
-
validateStudioNetwork({ studio, product, network })
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
for (const { network } of manifestFile.templates || []) {
|
|
134
|
+
for (const { network } of dataSourcesAndTemplates) {
|
|
138
135
|
validateStudioNetwork({ studio, product, network })
|
|
139
136
|
}
|
|
140
137
|
} catch (e) {
|
|
@@ -192,6 +189,7 @@ module.exports = {
|
|
|
192
189
|
return
|
|
193
190
|
}
|
|
194
191
|
|
|
192
|
+
let protocol
|
|
195
193
|
try {
|
|
196
194
|
// Checks to make sure deploy doesn't run against
|
|
197
195
|
// older subgraphs (both apiVersion and graph-ts version).
|
|
@@ -201,6 +199,10 @@ module.exports = {
|
|
|
201
199
|
// using the wrong AssemblyScript compiler.
|
|
202
200
|
await assertManifestApiVersion(manifest, '0.0.5')
|
|
203
201
|
await assertGraphTsVersion(path.dirname(manifest), '0.22.0')
|
|
202
|
+
|
|
203
|
+
const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(manifest)
|
|
204
|
+
|
|
205
|
+
protocol = Protocol.fromDataSources(dataSourcesAndTemplates)
|
|
204
206
|
} catch (e) {
|
|
205
207
|
print.error(e.message)
|
|
206
208
|
process.exitCode = 1
|
|
@@ -215,7 +217,8 @@ module.exports = {
|
|
|
215
217
|
outputDir,
|
|
216
218
|
outputFormat: 'wasm',
|
|
217
219
|
skipMigrations,
|
|
218
|
-
blockIpfsMethods: isStudio // Network does not support publishing subgraphs with IPFS methods
|
|
220
|
+
blockIpfsMethods: isStudio, // Network does not support publishing subgraphs with IPFS methods
|
|
221
|
+
protocol,
|
|
219
222
|
})
|
|
220
223
|
|
|
221
224
|
// Exit with an error code if the compiler couldn't be created
|
package/src/commands/init.js
CHANGED
|
@@ -9,13 +9,14 @@ const {
|
|
|
9
9
|
getSubgraphBasename,
|
|
10
10
|
validateSubgraphName,
|
|
11
11
|
} = require('../command-helpers/subgraph')
|
|
12
|
+
const DataSourcesExtractor = require('../command-helpers/data-sources')
|
|
12
13
|
const { validateStudioNetwork } = require('../command-helpers/studio')
|
|
13
14
|
const { withSpinner, step } = require('../command-helpers/spinner')
|
|
14
15
|
const { fixParameters } = require('../command-helpers/gluegun')
|
|
15
16
|
const { chooseNodeUrl } = require('../command-helpers/node')
|
|
16
|
-
const { loadManifest } = require('../migrations/util/load-manifest')
|
|
17
17
|
const { abiEvents, generateScaffold, writeScaffold } = require('../scaffold')
|
|
18
|
-
|
|
18
|
+
// TODO: Use Protocol class to getABI
|
|
19
|
+
const ABI = require('../protocols/ethereum/abi')
|
|
19
20
|
|
|
20
21
|
const networkChoices = [
|
|
21
22
|
'mainnet',
|
|
@@ -256,16 +257,24 @@ const loadAbiFromBlockScout = async (network, address) =>
|
|
|
256
257
|
},
|
|
257
258
|
)
|
|
258
259
|
|
|
260
|
+
const getEtherscanLikeAPIUrl = (network) => {
|
|
261
|
+
switch(network){
|
|
262
|
+
case "mainnet": return `https://api.etherscan.io/api`;
|
|
263
|
+
case "bsc": return `https://api.bscscan.com/api`;
|
|
264
|
+
case "matic": return `https://api.polygonscan.com/api`;
|
|
265
|
+
default: return `https://api-${network}.etherscan.io/api`;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
259
269
|
const loadAbiFromEtherscan = async (network, address) =>
|
|
260
270
|
await withSpinner(
|
|
261
271
|
`Fetching ABI from Etherscan`,
|
|
262
272
|
`Failed to fetch ABI from Etherscan`,
|
|
263
273
|
`Warnings while fetching ABI from Etherscan`,
|
|
264
274
|
async spinner => {
|
|
275
|
+
const scanApiUrl = getEtherscanLikeAPIUrl(network);
|
|
265
276
|
let result = await fetch(
|
|
266
|
-
|
|
267
|
-
network === 'mainnet' ? 'api' : `api-${network}`
|
|
268
|
-
}.etherscan.io/api?module=contract&action=getabi&address=${address}`,
|
|
277
|
+
`${scanApiUrl}?module=contract&action=getabi&address=${address}`,
|
|
269
278
|
)
|
|
270
279
|
let json = await result.json()
|
|
271
280
|
|
|
@@ -529,12 +538,26 @@ const initRepository = async (toolbox, directory) =>
|
|
|
529
538
|
},
|
|
530
539
|
)
|
|
531
540
|
|
|
541
|
+
// Only used for local testing / continuous integration.
|
|
542
|
+
//
|
|
543
|
+
// This requires that the command `npm link` is called
|
|
544
|
+
// on the root directory of this repository, as described here:
|
|
545
|
+
// https://docs.npmjs.com/cli/v7/commands/npm-link.
|
|
546
|
+
const npmLinkToLocalCli = async (toolbox, directory) => {
|
|
547
|
+
if (process.env.GRAPH_CLI_TESTS) {
|
|
548
|
+
await toolbox.system.run('npm link @graphprotocol/graph-cli', { cwd: directory })
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
|
|
532
552
|
const installDependencies = async (toolbox, directory, installCommand) =>
|
|
533
553
|
await withSpinner(
|
|
534
554
|
`Install dependencies with ${toolbox.print.colors.muted(installCommand)}`,
|
|
535
555
|
`Failed to install dependencies`,
|
|
536
556
|
`Warnings while installing dependencies`,
|
|
537
557
|
async spinner => {
|
|
558
|
+
// Links to local graph-cli if we're running the automated tests
|
|
559
|
+
await npmLinkToLocalCli(toolbox, directory)
|
|
560
|
+
|
|
538
561
|
await toolbox.system.run(installCommand, { cwd: directory })
|
|
539
562
|
return true
|
|
540
563
|
},
|
|
@@ -613,13 +636,9 @@ const initSubgraphFromExample = async (
|
|
|
613
636
|
try {
|
|
614
637
|
// It doesn't matter if we changed the URL we clone the YAML,
|
|
615
638
|
// we'll check it's network anyway. If it's a studio subgraph we're dealing with.
|
|
616
|
-
|
|
639
|
+
const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(path.join(directory, 'subgraph.yaml'))
|
|
617
640
|
|
|
618
|
-
for (const { network } of
|
|
619
|
-
validateStudioNetwork({ studio, product, network })
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
for (const { network } of manifestFile.templates || []) {
|
|
641
|
+
for (const { network } of dataSourcesAndTemplates) {
|
|
623
642
|
validateStudioNetwork({ studio, product, network })
|
|
624
643
|
}
|
|
625
644
|
} catch (e) {
|
|
@@ -646,6 +665,11 @@ const initSubgraphFromExample = async (
|
|
|
646
665
|
delete pkgJson['license']
|
|
647
666
|
delete pkgJson['repository']
|
|
648
667
|
|
|
668
|
+
// Remove example's cli in favor of the local one (added via `npm link`)
|
|
669
|
+
if (process.env.GRAPH_CLI_TESTS) {
|
|
670
|
+
delete pkgJson['devDependencies']['@graphprotocol/graph-cli']
|
|
671
|
+
}
|
|
672
|
+
|
|
649
673
|
// Write package.json
|
|
650
674
|
await filesystem.write(pkgJsonFilename, pkgJson, { jsonIndent: 2 })
|
|
651
675
|
return true
|
package/src/commands/test.js
CHANGED
|
@@ -2,6 +2,7 @@ const { Binary } = require('binary-install-raw')
|
|
|
2
2
|
const os = require('os')
|
|
3
3
|
const chalk = require('chalk')
|
|
4
4
|
const fetch = require('node-fetch')
|
|
5
|
+
const semver = require('semver')
|
|
5
6
|
|
|
6
7
|
const HELP = `
|
|
7
8
|
${chalk.bold('graph test')} ${chalk.dim('[options]')} ${chalk.bold('<datasource>')}
|
|
@@ -45,7 +46,7 @@ module.exports = {
|
|
|
45
46
|
|
|
46
47
|
let binary = new Binary(platform, url, version);
|
|
47
48
|
await binary.install(force);
|
|
48
|
-
binary.run(datasource);
|
|
49
|
+
datasource ? binary.run(datasource) : binary.run();
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
52
|
|
|
@@ -53,16 +54,20 @@ function getPlatform() {
|
|
|
53
54
|
const type = os.type();
|
|
54
55
|
const arch = os.arch();
|
|
55
56
|
const release = os.release();
|
|
56
|
-
const
|
|
57
|
+
const cpuCore = os.cpus()[0];
|
|
58
|
+
const majorVersion = semver.major(release);
|
|
59
|
+
const isM1 = cpuCore.model.includes("Apple M1");
|
|
57
60
|
|
|
58
|
-
if (arch === 'x64') {
|
|
61
|
+
if (arch === 'x64' || (arch === 'arm64' && isM1)) {
|
|
59
62
|
if (type === 'Darwin') {
|
|
60
63
|
if (majorVersion === '19') {
|
|
61
64
|
return 'binary-macos-10.15';
|
|
62
65
|
} else if (majorVersion === '18') {
|
|
63
66
|
return 'binary-macos-10.14';
|
|
67
|
+
} else if (isM1) {
|
|
68
|
+
return 'binary-macos-11-m1';
|
|
64
69
|
}
|
|
65
|
-
return 'binary-macos-11'
|
|
70
|
+
return 'binary-macos-11';
|
|
66
71
|
} else if (type === 'Linux') {
|
|
67
72
|
if (majorVersion === '18') {
|
|
68
73
|
return 'binary-linux-18';
|