@graphprotocol/graph-cli 0.37.2 → 0.37.3-alpha-20230110163550-d64bef6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/babel.config.js +3 -0
- package/dist/bin.js +6 -0
- package/dist/cli.js +32 -0
- package/dist/codegen/schema.js +250 -0
- package/dist/codegen/schema.test.js +458 -0
- package/dist/codegen/template.js +65 -0
- package/dist/codegen/types/conversions.js +359 -0
- package/dist/codegen/types/index.js +71 -0
- package/dist/codegen/types/index.test.js +563 -0
- package/dist/codegen/typescript.js +200 -0
- package/dist/codegen/util.js +46 -0
- package/dist/codegen/util.test.js +93 -0
- package/dist/command-helpers/abi.js +78 -0
- package/dist/command-helpers/auth.js +77 -0
- package/dist/command-helpers/compiler.js +66 -0
- package/dist/command-helpers/data-sources.js +29 -0
- package/dist/command-helpers/fs.js +9 -0
- package/dist/command-helpers/gluegun.js +49 -0
- package/dist/command-helpers/ipfs.js +5 -0
- package/dist/command-helpers/jsonrpc.js +29 -0
- package/dist/command-helpers/network.js +93 -0
- package/dist/command-helpers/network.test.js +86 -0
- package/dist/command-helpers/node.js +40 -0
- package/dist/command-helpers/scaffold.js +112 -0
- package/dist/command-helpers/spinner.js +84 -0
- package/dist/command-helpers/studio.js +13 -0
- package/dist/command-helpers/studio.test.js +41 -0
- package/dist/command-helpers/subgraph.js +24 -0
- package/dist/command-helpers/version.js +74 -0
- package/dist/command-helpers/version.test.js +179 -0
- package/dist/commands/add.js +190 -0
- package/dist/commands/auth.js +127 -0
- package/dist/commands/build.js +140 -0
- package/dist/commands/codegen.js +135 -0
- package/dist/commands/create.js +86 -0
- package/dist/commands/deploy.js +334 -0
- package/dist/commands/init.js +788 -0
- package/dist/commands/local.js +387 -0
- package/dist/commands/remove.js +86 -0
- package/dist/commands/test.js +295 -0
- package/dist/compiler/asc.js +83 -0
- package/dist/compiler/index.js +474 -0
- package/dist/debug.js +16 -0
- package/dist/migrations/mapping_api_version_0_0_1.js +78 -0
- package/dist/migrations/mapping_api_version_0_0_2.js +76 -0
- package/dist/migrations/mapping_api_version_0_0_3.js +78 -0
- package/dist/migrations/mapping_api_version_0_0_4.js +80 -0
- package/dist/migrations/mapping_api_version_0_0_5.js +80 -0
- package/dist/migrations/spec_version_0_0_2.js +49 -0
- package/dist/migrations/spec_version_0_0_3.js +54 -0
- package/dist/migrations/util/load-manifest.js +18 -0
- package/dist/migrations/util/versions.js +29 -0
- package/dist/migrations.js +56 -0
- package/dist/protocols/arweave/manifest.graphql +57 -0
- package/dist/protocols/arweave/scaffold/manifest.js +18 -0
- package/dist/protocols/arweave/scaffold/mapping.js +52 -0
- package/dist/protocols/arweave/subgraph.js +23 -0
- package/dist/protocols/cosmos/manifest.graphql +76 -0
- package/dist/protocols/cosmos/scaffold/manifest.js +15 -0
- package/dist/protocols/cosmos/scaffold/mapping.js +38 -0
- package/dist/protocols/cosmos/subgraph.js +25 -0
- package/dist/protocols/ethereum/abi.js +140 -0
- package/dist/protocols/ethereum/codegen/abi.js +451 -0
- package/dist/protocols/ethereum/codegen/abi.test.js +328 -0
- package/dist/protocols/ethereum/codegen/template.js +50 -0
- package/dist/protocols/ethereum/contract.js +20 -0
- package/dist/protocols/ethereum/manifest.graphql +94 -0
- package/dist/protocols/ethereum/scaffold/manifest.js +32 -0
- package/dist/protocols/ethereum/scaffold/mapping.js +65 -0
- package/dist/protocols/ethereum/subgraph.js +171 -0
- package/dist/protocols/ethereum/type-generator.js +125 -0
- package/dist/protocols/index.js +268 -0
- package/dist/protocols/ipfs/codegen/file_template.js +50 -0
- package/dist/protocols/near/contract.js +41 -0
- package/dist/protocols/near/manifest.graphql +64 -0
- package/dist/protocols/near/scaffold/manifest.js +16 -0
- package/dist/protocols/near/scaffold/mapping.js +38 -0
- package/dist/protocols/near/subgraph.js +20 -0
- package/dist/protocols/subgraph.js +2 -0
- package/dist/protocols/substreams/manifest.graphql +45 -0
- package/dist/protocols/substreams/scaffold/manifest.js +12 -0
- package/dist/protocols/substreams/subgraph.js +23 -0
- package/dist/scaffold/cosmos.test.js +83 -0
- package/dist/scaffold/ethereum.test.js +505 -0
- package/dist/scaffold/index.js +128 -0
- package/dist/scaffold/mapping.js +61 -0
- package/dist/scaffold/near.test.js +86 -0
- package/dist/scaffold/schema.js +83 -0
- package/dist/scaffold/tests.js +175 -0
- package/dist/schema.js +54 -0
- package/dist/subgraph.js +249 -0
- package/dist/type-generator.js +224 -0
- package/dist/validation/contract.js +46 -0
- package/dist/validation/index.js +8 -0
- package/dist/validation/manifest.js +271 -0
- package/dist/validation/schema.js +796 -0
- package/dist/validation/schema.test.js +35 -0
- package/dist/watcher.js +79 -0
- package/jest.config.js +1 -1
- package/package.json +16 -9
- package/{bin/graph → src/bin.ts} +2 -1
- package/src/cli.ts +36 -0
- package/src/codegen/schema.js +23 -22
- package/src/codegen/schema.test.js +33 -27
- package/src/codegen/{template.js → template.ts} +8 -6
- package/src/codegen/types/conversions.ts +382 -0
- package/src/codegen/types/index.js +4 -7
- package/src/codegen/types/index.test.js +10 -4
- package/src/codegen/{typescript.js → typescript.ts} +44 -26
- package/src/codegen/util.js +1 -1
- package/src/codegen/util.test.js +5 -2
- package/src/command-helpers/abi.js +46 -30
- package/src/command-helpers/auth.js +6 -9
- package/src/command-helpers/compiler.js +4 -6
- package/src/command-helpers/data-sources.js +8 -11
- package/src/command-helpers/fs.ts +5 -0
- package/src/command-helpers/gluegun.js +2 -4
- package/src/command-helpers/ipfs.ts +3 -0
- package/src/command-helpers/{jsonrpc.js → jsonrpc.ts} +11 -16
- package/src/command-helpers/network.js +58 -44
- package/src/command-helpers/network.test.js +23 -19
- package/src/command-helpers/node.js +3 -7
- package/src/command-helpers/scaffold.js +34 -25
- package/src/command-helpers/{spinner.js → spinner.ts} +10 -10
- package/src/command-helpers/studio.test.js +61 -30
- package/src/command-helpers/studio.ts +20 -0
- package/src/command-helpers/{subgraph.js → subgraph.ts} +6 -6
- package/src/command-helpers/version.js +11 -16
- package/src/command-helpers/version.test.js +111 -82
- package/src/commands/add.js +49 -35
- package/src/commands/auth.js +13 -25
- package/src/commands/build.js +9 -9
- package/src/commands/codegen.js +12 -12
- package/src/commands/create.js +22 -22
- package/src/commands/deploy.js +39 -34
- package/src/commands/init.js +21 -24
- package/src/commands/local.js +15 -14
- package/src/commands/remove.js +22 -22
- package/src/commands/test.js +86 -70
- package/src/compiler/{asc.js → asc.ts} +29 -16
- package/src/compiler/index.js +18 -18
- package/src/{debug.js → debug.ts} +2 -2
- package/src/migrations/mapping_api_version_0_0_1.js +7 -7
- package/src/migrations/mapping_api_version_0_0_2.js +5 -5
- package/src/migrations/mapping_api_version_0_0_3.js +7 -7
- package/src/migrations/mapping_api_version_0_0_4.js +7 -7
- package/src/migrations/mapping_api_version_0_0_5.js +7 -7
- package/src/migrations/spec_version_0_0_2.js +5 -5
- package/src/migrations/spec_version_0_0_3.js +5 -5
- package/src/migrations/util/load-manifest.js +6 -9
- package/src/migrations/util/versions.js +5 -10
- package/src/{migrations.js → migrations.ts} +14 -15
- package/src/protocols/arweave/scaffold/manifest.js +1 -4
- package/src/protocols/arweave/scaffold/mapping.js +1 -3
- package/src/protocols/arweave/subgraph.ts +22 -0
- package/src/protocols/cosmos/scaffold/manifest.js +1 -4
- package/src/protocols/cosmos/scaffold/mapping.js +1 -3
- package/src/protocols/cosmos/subgraph.js +2 -2
- package/src/protocols/ethereum/abi.js +7 -13
- package/src/protocols/ethereum/codegen/abi.js +219 -222
- package/src/protocols/ethereum/codegen/abi.test.js +6 -6
- package/src/protocols/ethereum/codegen/template.js +3 -5
- package/src/protocols/ethereum/contract.js +3 -2
- package/src/protocols/ethereum/scaffold/manifest.js +4 -7
- package/src/protocols/ethereum/scaffold/mapping.js +4 -11
- package/src/protocols/ethereum/subgraph.js +21 -20
- package/src/protocols/ethereum/type-generator.js +24 -30
- package/src/protocols/{index.js → index.ts} +65 -46
- package/src/protocols/ipfs/codegen/file_template.js +2 -2
- package/src/protocols/near/{contract.js → contract.ts} +16 -12
- package/src/protocols/near/scaffold/manifest.js +2 -5
- package/src/protocols/near/scaffold/mapping.js +1 -3
- package/src/protocols/near/subgraph.js +3 -6
- package/src/protocols/subgraph.ts +12 -0
- package/src/protocols/substreams/scaffold/{manifest.js → manifest.ts} +2 -7
- package/src/protocols/substreams/subgraph.ts +22 -0
- package/src/scaffold/cosmos.test.js +3 -3
- package/src/scaffold/ethereum.test.js +4 -4
- package/src/scaffold/index.js +7 -7
- package/src/scaffold/mapping.js +3 -3
- package/src/scaffold/near.test.js +3 -3
- package/src/scaffold/schema.js +4 -4
- package/src/scaffold/tests.js +72 -58
- package/src/schema.ts +26 -0
- package/src/{subgraph.js → subgraph.ts} +80 -60
- package/src/type-generator.js +20 -20
- package/src/validation/contract.js +2 -6
- package/src/validation/index.js +1 -1
- package/src/validation/manifest.js +24 -22
- package/src/validation/schema.test.js +1 -1
- package/src/validation/{schema.js → schema.ts} +268 -221
- package/src/{watcher.js → watcher.ts} +23 -12
- package/tests/cli/globalSetup.js +2 -2
- package/tests/cli/globalTeardown.js +2 -2
- package/tests/cli/init.test.js +2 -2
- package/tests/cli/util.js +7 -13
- package/tsconfig.json +18 -0
- package/src/cli.js +0 -38
- package/src/codegen/types/conversions.js +0 -329
- package/src/command-helpers/fs.js +0 -8
- package/src/command-helpers/ipfs.js +0 -6
- package/src/command-helpers/studio.js +0 -15
- package/src/protocols/arweave/subgraph.js +0 -20
- package/src/protocols/substreams/subgraph.js +0 -17
- package/src/schema.js +0 -23
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { withSpinner } from './spinner'
|
|
2
|
+
import fetch from 'node-fetch'
|
|
3
|
+
import immutable from 'immutable'
|
|
4
4
|
|
|
5
5
|
const loadAbiFromEtherscan = async (ABI, network, address) =>
|
|
6
6
|
await withSpinner(
|
|
@@ -8,7 +8,7 @@ const loadAbiFromEtherscan = async (ABI, network, address) =>
|
|
|
8
8
|
`Failed to fetch ABI from Etherscan`,
|
|
9
9
|
`Warnings while fetching ABI from Etherscan`,
|
|
10
10
|
async spinner => {
|
|
11
|
-
const scanApiUrl = getEtherscanLikeAPIUrl(network)
|
|
11
|
+
const scanApiUrl = getEtherscanLikeAPIUrl(network)
|
|
12
12
|
let result = await fetch(
|
|
13
13
|
`${scanApiUrl}?module=contract&action=getabi&address=${address}`,
|
|
14
14
|
)
|
|
@@ -32,9 +32,10 @@ const loadAbiFromBlockScout = async (ABI, network, address) =>
|
|
|
32
32
|
`Warnings while fetching ABI from BlockScout`,
|
|
33
33
|
async spinner => {
|
|
34
34
|
let result = await fetch(
|
|
35
|
-
`https://blockscout.com/${
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
`https://blockscout.com/${network.replace(
|
|
36
|
+
'-',
|
|
37
|
+
'/',
|
|
38
|
+
)}/api?module=contract&action=getabi&address=${address}`,
|
|
38
39
|
)
|
|
39
40
|
let json = await result.json()
|
|
40
41
|
|
|
@@ -49,30 +50,45 @@ const loadAbiFromBlockScout = async (ABI, network, address) =>
|
|
|
49
50
|
},
|
|
50
51
|
)
|
|
51
52
|
|
|
52
|
-
const getEtherscanLikeAPIUrl =
|
|
53
|
+
const getEtherscanLikeAPIUrl = network => {
|
|
53
54
|
switch (network) {
|
|
54
|
-
case
|
|
55
|
-
|
|
56
|
-
case
|
|
57
|
-
|
|
58
|
-
case
|
|
59
|
-
|
|
60
|
-
case
|
|
61
|
-
|
|
62
|
-
case
|
|
63
|
-
|
|
64
|
-
case
|
|
65
|
-
|
|
66
|
-
case
|
|
67
|
-
|
|
68
|
-
case
|
|
69
|
-
|
|
70
|
-
case
|
|
71
|
-
|
|
55
|
+
case 'mainnet':
|
|
56
|
+
return `https://api.etherscan.io/api`
|
|
57
|
+
case 'arbitrum-one':
|
|
58
|
+
return `https://api.arbiscan.io/api`
|
|
59
|
+
case 'bsc':
|
|
60
|
+
return `https://api.bscscan.com/api`
|
|
61
|
+
case 'matic':
|
|
62
|
+
return `https://api.polygonscan.com/api`
|
|
63
|
+
case 'mumbai':
|
|
64
|
+
return `https://api-testnet.polygonscan.com/api`
|
|
65
|
+
case 'aurora':
|
|
66
|
+
return `https://api.aurorascan.dev/api`
|
|
67
|
+
case 'aurora-testnet':
|
|
68
|
+
return `https://api-testnet.aurorascan.dev/api`
|
|
69
|
+
case 'optimism-kovan':
|
|
70
|
+
return `https://api-kovan-optimistic.etherscan.io/api`
|
|
71
|
+
case 'optimism':
|
|
72
|
+
return `https://api-optimistic.etherscan.io/api`
|
|
73
|
+
case 'moonbeam':
|
|
74
|
+
return `https://api-moonbeam.moonscan.io/api`
|
|
75
|
+
case 'moonriver':
|
|
76
|
+
return `https://api-moonriver.moonscan.io/api`
|
|
77
|
+
case 'mbase':
|
|
78
|
+
return `https://api-moonbase.moonscan.io/api`
|
|
79
|
+
case 'avalanche':
|
|
80
|
+
return `https://api.snowtrace.io/api`
|
|
81
|
+
case 'fuji':
|
|
82
|
+
return `https://api-testnet.snowtrace.io/api`
|
|
83
|
+
case 'gnosis':
|
|
84
|
+
return `https://api.gnosisscan.io/api`
|
|
85
|
+
case 'fantom':
|
|
86
|
+
return `https://api.ftmscan.com/api`
|
|
87
|
+
case 'fantom-testnet':
|
|
88
|
+
return `https://api-testnet.ftmscan.com/api`
|
|
89
|
+
default:
|
|
90
|
+
return `https://api-${network}.etherscan.io/api`
|
|
72
91
|
}
|
|
73
92
|
}
|
|
74
93
|
|
|
75
|
-
|
|
76
|
-
loadAbiFromEtherscan,
|
|
77
|
-
loadAbiFromBlockScout,
|
|
78
|
-
}
|
|
94
|
+
export { loadAbiFromEtherscan, loadAbiFromBlockScout }
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import * as toolbox from 'gluegun/toolbox'
|
|
2
|
+
import { normalizeNodeUrl } from './node'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import fs from 'fs'
|
|
5
|
+
import path from 'path'
|
|
6
6
|
const homedir = require('os').homedir()
|
|
7
7
|
|
|
8
8
|
const CONFIG_PATH = path.join(homedir, '/.graph-cli.json')
|
|
@@ -14,7 +14,7 @@ const getConfig = () => {
|
|
|
14
14
|
config = {}
|
|
15
15
|
}
|
|
16
16
|
return config
|
|
17
|
-
|
|
17
|
+
}
|
|
18
18
|
|
|
19
19
|
const identifyDeployKey = async (node, deployKey) => {
|
|
20
20
|
// Determine the deploy key to use, if any:
|
|
@@ -45,7 +45,4 @@ const saveDeployKey = async (node, deployKey) => {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
identifyDeployKey,
|
|
50
|
-
saveDeployKey,
|
|
51
|
-
}
|
|
48
|
+
export { identifyDeployKey, saveDeployKey }
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const URL = require('url').URL
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import ipfsHttpClient from 'ipfs-http-client'
|
|
3
|
+
import * as toolbox from 'gluegun/toolbox'
|
|
4
|
+
import Compiler from '../compiler'
|
|
5
5
|
|
|
6
6
|
// Helper function to construct a subgraph compiler
|
|
7
7
|
const createCompiler = (
|
|
@@ -40,6 +40,4 @@ The IPFS URL must be of the following format: http(s)://host[:port]/[path]`)
|
|
|
40
40
|
})
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
createCompiler,
|
|
45
|
-
}
|
|
43
|
+
export { createCompiler }
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import immutable from 'immutable'
|
|
2
|
+
import { loadManifest } from '../migrations/util/load-manifest'
|
|
3
3
|
|
|
4
4
|
// Loads manifest from file path and returns all:
|
|
5
5
|
// - data sources
|
|
@@ -16,11 +16,11 @@ const extractDataSourceByType = (manifest, dataSourceType, protocol) =>
|
|
|
16
16
|
.get(dataSourceType, immutable.List())
|
|
17
17
|
.reduce(
|
|
18
18
|
(dataSources, dataSource, dataSourceIndex) =>
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
protocol.isValidKindName(dataSource.get('kind'))
|
|
20
|
+
? dataSources.push(
|
|
21
|
+
immutable.Map({ path: [dataSourceType, dataSourceIndex], dataSource }),
|
|
22
|
+
)
|
|
23
|
+
: dataSources,
|
|
24
24
|
immutable.List(),
|
|
25
25
|
)
|
|
26
26
|
|
|
@@ -32,7 +32,4 @@ const fromManifest = (manifest, protocol) => {
|
|
|
32
32
|
return dataSources.concat(templates)
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
fromFilePath,
|
|
37
|
-
fromManifest,
|
|
38
|
-
}
|
|
35
|
+
export { fromFilePath, fromManifest }
|
|
@@ -35,7 +35,7 @@ const fixParameters = (parameters, booleanOptions) => {
|
|
|
35
35
|
|
|
36
36
|
if (unexpectedStringOptions.length > 1) {
|
|
37
37
|
throw new Error(
|
|
38
|
-
`Unexpected value provided for one or more of ${optionNames}. See --help for more information
|
|
38
|
+
`Unexpected value provided for one or more of ${optionNames}. See --help for more information.`,
|
|
39
39
|
)
|
|
40
40
|
} else if (unexpectedStringOptions.length == 1) {
|
|
41
41
|
let params = parameters.array
|
|
@@ -46,6 +46,4 @@ const fixParameters = (parameters, booleanOptions) => {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
fixParameters,
|
|
51
|
-
}
|
|
49
|
+
export { fixParameters }
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import jayson from 'jayson'
|
|
2
|
+
import { print } from 'gluegun'
|
|
3
3
|
|
|
4
|
-
const createJsonRpcClient = url => {
|
|
5
|
-
|
|
4
|
+
const createJsonRpcClient = (url: URL) => {
|
|
5
|
+
const params = {
|
|
6
6
|
host: url.hostname,
|
|
7
7
|
port: url.port,
|
|
8
8
|
path: url.pathname,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
// username may be empty
|
|
12
|
-
if (url.password) {
|
|
13
|
-
params.auth = `${url.username}:${url.password}`
|
|
9
|
+
// username may be empty
|
|
10
|
+
auth: url.password ? `${url.username}:${url.password}` : undefined,
|
|
14
11
|
}
|
|
15
12
|
|
|
16
13
|
if (url.protocol === 'https:') {
|
|
@@ -18,16 +15,14 @@ const createJsonRpcClient = url => {
|
|
|
18
15
|
} else if (url.protocol === 'http:') {
|
|
19
16
|
return jayson.Client.http(params)
|
|
20
17
|
} else {
|
|
21
|
-
|
|
22
|
-
`Unsupported protocol: ${url.protocol.substring(0, url.protocol.length - 1)}
|
|
18
|
+
print.error(
|
|
19
|
+
`Unsupported protocol: ${url.protocol.substring(0, url.protocol.length - 1)}`,
|
|
23
20
|
)
|
|
24
|
-
|
|
25
|
-
'The Graph Node URL must be of the following format: http(s)://host[:port]/[path]'
|
|
21
|
+
print.error(
|
|
22
|
+
'The Graph Node URL must be of the following format: http(s)://host[:port]/[path]',
|
|
26
23
|
)
|
|
27
24
|
return null
|
|
28
25
|
}
|
|
29
26
|
}
|
|
30
27
|
|
|
31
|
-
|
|
32
|
-
createJsonRpcClient,
|
|
33
|
-
}
|
|
28
|
+
export { createJsonRpcClient }
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const updateSubgraphNetwork = async (
|
|
1
|
+
import path from 'path'
|
|
2
|
+
import yaml from 'yaml'
|
|
3
|
+
import { step, withSpinner } from '../command-helpers/spinner'
|
|
4
|
+
|
|
5
|
+
const updateSubgraphNetwork = async (
|
|
6
|
+
toolbox,
|
|
7
|
+
manifest,
|
|
8
|
+
network,
|
|
9
|
+
networksFile,
|
|
10
|
+
identifierName,
|
|
11
|
+
) =>
|
|
6
12
|
await withSpinner(
|
|
7
13
|
`Update sources network`,
|
|
8
14
|
`Failed to update sources network`,
|
|
@@ -11,41 +17,42 @@ const updateSubgraphNetwork = async (toolbox, manifest, network, networksFile, i
|
|
|
11
17
|
let allNetworks
|
|
12
18
|
|
|
13
19
|
step(spinner, `Reading networks config`)
|
|
14
|
-
allNetworks = await toolbox.filesystem.read(networksFile,
|
|
20
|
+
allNetworks = await toolbox.filesystem.read(networksFile, 'json')
|
|
15
21
|
let networkConfig = allNetworks[network]
|
|
16
22
|
|
|
17
23
|
// Exit if the network passed with --network does not exits in networks.json
|
|
18
|
-
if(!networkConfig) {
|
|
24
|
+
if (!networkConfig) {
|
|
19
25
|
throw new Error(`Network '${network}' was not found in '${networksFile}'`)
|
|
20
26
|
}
|
|
21
27
|
|
|
22
28
|
await toolbox.patching.update(manifest, content => {
|
|
23
29
|
let subgraph = yaml.parse(content)
|
|
24
30
|
let networkSources = Object.keys(networkConfig)
|
|
25
|
-
let subgraphSources = subgraph.dataSources.map(value => value.name)
|
|
31
|
+
let subgraphSources = subgraph.dataSources.map(value => value.name)
|
|
26
32
|
|
|
27
33
|
// Update the dataSources network config
|
|
28
34
|
subgraph.dataSources = subgraph.dataSources.map(source => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return source
|
|
35
|
+
if (!networkSources.includes(source.name)) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
`'${source.name}' was not found in the '${network}' configuration, please update!`,
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (hasChanges(identifierName, network, networkConfig[source.name], source)) {
|
|
42
|
+
step(spinner, `Update '${source.name}' network configuration`)
|
|
43
|
+
source.network = network
|
|
44
|
+
source.source = source.source.abi ? { abi: source.source.abi } : {}
|
|
45
|
+
Object.assign(source.source, networkConfig[source.name])
|
|
46
|
+
} else {
|
|
47
|
+
step(spinner, `Skip '${source.name}': No changes to network configuration`)
|
|
43
48
|
}
|
|
44
|
-
|
|
49
|
+
|
|
50
|
+
return source
|
|
51
|
+
})
|
|
45
52
|
|
|
46
53
|
// All data sources shoud be on the same network,
|
|
47
54
|
// so we have to update the network of all templates too.
|
|
48
|
-
if(subgraph.templates) {
|
|
55
|
+
if (subgraph.templates) {
|
|
49
56
|
subgraph.templates = subgraph.templates.map(template => ({
|
|
50
57
|
...template,
|
|
51
58
|
network,
|
|
@@ -55,37 +62,42 @@ const updateSubgraphNetwork = async (toolbox, manifest, network, networksFile, i
|
|
|
55
62
|
let unsusedSources = networkSources.filter(x => !subgraphSources.includes(x))
|
|
56
63
|
|
|
57
64
|
unsusedSources.forEach(source => {
|
|
58
|
-
step(
|
|
65
|
+
step(
|
|
66
|
+
spinner,
|
|
67
|
+
`dataSource '${source}' from '${networksFile}' not found in ${manifest}`,
|
|
68
|
+
)
|
|
59
69
|
})
|
|
60
70
|
|
|
61
71
|
let yaml_doc = new yaml.Document()
|
|
62
72
|
yaml_doc.contents = subgraph
|
|
63
73
|
return yaml_doc.toString()
|
|
64
74
|
})
|
|
65
|
-
|
|
75
|
+
},
|
|
76
|
+
)
|
|
66
77
|
|
|
67
|
-
const initNetworksConfig = async(toolbox, directory, identifierName) =>
|
|
78
|
+
const initNetworksConfig = async (toolbox, directory, identifierName) =>
|
|
68
79
|
await withSpinner(
|
|
69
80
|
`Initialize networks config`,
|
|
70
81
|
`Failed to initialize networks config`,
|
|
71
82
|
`Warnings while initializing networks config`,
|
|
72
83
|
async spinner => {
|
|
73
|
-
let subgraphStr = await toolbox.filesystem.read(
|
|
84
|
+
let subgraphStr = await toolbox.filesystem.read(
|
|
85
|
+
path.join(directory, 'subgraph.yaml'),
|
|
86
|
+
)
|
|
74
87
|
let subgraph = yaml.parse(subgraphStr)
|
|
75
88
|
|
|
76
|
-
const networks = subgraph.dataSources.reduce(
|
|
77
|
-
|
|
78
|
-
acc,
|
|
79
|
-
{
|
|
89
|
+
const networks = subgraph.dataSources.reduce(
|
|
90
|
+
(acc, source) =>
|
|
91
|
+
Object.assign(acc, {
|
|
80
92
|
[source.network]: {
|
|
81
93
|
[source.name]: {
|
|
82
94
|
[identifierName]: source.source.address,
|
|
83
95
|
startBlock: source.source.startBlock,
|
|
84
96
|
},
|
|
85
97
|
},
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
98
|
+
}),
|
|
99
|
+
{},
|
|
100
|
+
)
|
|
89
101
|
|
|
90
102
|
await toolbox.filesystem.write(`${directory}/networks.json`, networks)
|
|
91
103
|
|
|
@@ -107,19 +119,21 @@ function hasChanges(identifierName, network, networkConfig, dataSource) {
|
|
|
107
119
|
return networkChanged || addressChanged || startBlockChanged
|
|
108
120
|
}
|
|
109
121
|
|
|
110
|
-
const updateNetworksFile = async (
|
|
111
|
-
|
|
112
|
-
|
|
122
|
+
const updateNetworksFile = async (
|
|
123
|
+
toolbox,
|
|
124
|
+
network,
|
|
125
|
+
dataSource,
|
|
126
|
+
address,
|
|
127
|
+
networksFile,
|
|
128
|
+
) => {
|
|
129
|
+
await toolbox.patching.update(networksFile, config => {
|
|
130
|
+
if (Object.keys(config).includes(network)) {
|
|
113
131
|
Object.assign(config[network], { [dataSource]: { address } })
|
|
114
132
|
} else {
|
|
115
|
-
Object.assign(config, { [network]: { [dataSource]: { address } }})
|
|
133
|
+
Object.assign(config, { [network]: { [dataSource]: { address } } })
|
|
116
134
|
}
|
|
117
135
|
return config
|
|
118
136
|
})
|
|
119
137
|
}
|
|
120
138
|
|
|
121
|
-
|
|
122
|
-
updateSubgraphNetwork,
|
|
123
|
-
initNetworksConfig,
|
|
124
|
-
updateNetworksFile
|
|
125
|
-
}
|
|
139
|
+
export { updateSubgraphNetwork, initNetworksConfig, updateNetworksFile }
|
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const SUBGRAPH_PATH_BASE = path.join(
|
|
1
|
+
import { initNetworksConfig, updateSubgraphNetwork } from '../command-helpers/network'
|
|
2
|
+
import * as toolbox from 'gluegun/toolbox'
|
|
3
|
+
import yaml from 'yaml'
|
|
4
|
+
import path from 'path'
|
|
5
|
+
|
|
6
|
+
const SUBGRAPH_PATH_BASE = path.join(
|
|
7
|
+
__dirname,
|
|
8
|
+
'..',
|
|
9
|
+
'..',
|
|
10
|
+
'..',
|
|
11
|
+
'..',
|
|
12
|
+
'examples',
|
|
13
|
+
'example-subgraph',
|
|
14
|
+
)
|
|
7
15
|
|
|
8
16
|
describe('initNetworksConfig', () => {
|
|
9
17
|
beforeAll(async () => {
|
|
@@ -23,8 +31,8 @@ describe('initNetworksConfig', () => {
|
|
|
23
31
|
|
|
24
32
|
let expected = {
|
|
25
33
|
mainnet: {
|
|
26
|
-
ExampleSubgraph: { address: '0x22843e74c59580b3eaf6c233fa67d8b7c561a835' }
|
|
27
|
-
}
|
|
34
|
+
ExampleSubgraph: { address: '0x22843e74c59580b3eaf6c233fa67d8b7c561a835' },
|
|
35
|
+
},
|
|
28
36
|
}
|
|
29
37
|
|
|
30
38
|
expect(networks).toStrictEqual(expected)
|
|
@@ -35,12 +43,15 @@ describe('updateSubgraphNetwork', () => {
|
|
|
35
43
|
beforeAll(async () => {
|
|
36
44
|
let content = {
|
|
37
45
|
optimism: {
|
|
38
|
-
ExampleSubgraph: { address: '0x12345...' }
|
|
39
|
-
}
|
|
46
|
+
ExampleSubgraph: { address: '0x12345...' },
|
|
47
|
+
},
|
|
40
48
|
}
|
|
41
49
|
|
|
42
50
|
await toolbox.filesystem.write(`${SUBGRAPH_PATH_BASE}/networks.json`, content)
|
|
43
|
-
await toolbox.filesystem.copy(
|
|
51
|
+
await toolbox.filesystem.copy(
|
|
52
|
+
`${SUBGRAPH_PATH_BASE}/subgraph.yaml`,
|
|
53
|
+
`${SUBGRAPH_PATH_BASE}/subgraph_copy.yaml`,
|
|
54
|
+
)
|
|
44
55
|
})
|
|
45
56
|
|
|
46
57
|
afterAll(async () => {
|
|
@@ -60,13 +71,7 @@ describe('updateSubgraphNetwork', () => {
|
|
|
60
71
|
expect(network).toBe('mainnet')
|
|
61
72
|
expect(address).toBe('0x22843e74c59580b3eaf6c233fa67d8b7c561a835')
|
|
62
73
|
|
|
63
|
-
await updateSubgraphNetwork(
|
|
64
|
-
toolbox,
|
|
65
|
-
manifest,
|
|
66
|
-
'optimism',
|
|
67
|
-
networksFie,
|
|
68
|
-
'address'
|
|
69
|
-
)
|
|
74
|
+
await updateSubgraphNetwork(toolbox, manifest, 'optimism', networksFie, 'address')
|
|
70
75
|
|
|
71
76
|
subgraph = await toolbox.filesystem.read(manifest)
|
|
72
77
|
subgraphObj = yaml.parse(subgraph)
|
|
@@ -77,5 +82,4 @@ describe('updateSubgraphNetwork', () => {
|
|
|
77
82
|
expect(network).toBe('optimism')
|
|
78
83
|
expect(address).toBe('0x12345...')
|
|
79
84
|
})
|
|
80
|
-
|
|
81
85
|
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const URL = require('url').URL
|
|
2
|
-
|
|
2
|
+
import { print } from 'gluegun/toolbox'
|
|
3
3
|
|
|
4
4
|
const SUBGRAPH_STUDIO_URL = 'https://api.studio.thegraph.com/deploy/'
|
|
5
5
|
const HOSTED_SERVICE_URL = 'https://api.thegraph.com/deploy/'
|
|
@@ -8,7 +8,7 @@ const validateNodeUrl = node => new URL(node)
|
|
|
8
8
|
|
|
9
9
|
const normalizeNodeUrl = node => new URL(node).toString()
|
|
10
10
|
|
|
11
|
-
function chooseNodeUrl
|
|
11
|
+
function chooseNodeUrl({ product, studio, node, allowSimpleName }) {
|
|
12
12
|
if (node) {
|
|
13
13
|
try {
|
|
14
14
|
validateNodeUrl(node)
|
|
@@ -35,8 +35,4 @@ function chooseNodeUrl ({ product, studio, node, allowSimpleName }) {
|
|
|
35
35
|
return { node, allowSimpleName }
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
validateNodeUrl,
|
|
40
|
-
normalizeNodeUrl,
|
|
41
|
-
chooseNodeUrl
|
|
42
|
-
}
|
|
38
|
+
export { validateNodeUrl, normalizeNodeUrl, chooseNodeUrl }
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import fs from 'fs-extra'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import prettier from 'prettier'
|
|
4
|
+
import yaml from 'yaml'
|
|
5
|
+
|
|
6
|
+
import { step } from './spinner'
|
|
7
|
+
import Scaffold from '../scaffold'
|
|
8
|
+
import { generateEventIndexingHandlers } from '../scaffold/mapping'
|
|
9
|
+
import { generateEventType, abiEvents } from '../scaffold/schema'
|
|
10
|
+
import { generateTestsFiles } from '../scaffold/tests'
|
|
11
|
+
import { strings } from 'gluegun'
|
|
12
|
+
import { Map } from 'immutable'
|
|
13
13
|
|
|
14
14
|
const generateDataSource = async (
|
|
15
15
|
protocol,
|
|
@@ -21,13 +21,25 @@ const generateDataSource = async (
|
|
|
21
21
|
const protocolManifest = protocol.getManifestScaffold()
|
|
22
22
|
|
|
23
23
|
return Map.of(
|
|
24
|
-
'kind',
|
|
25
|
-
|
|
26
|
-
'
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
'kind',
|
|
25
|
+
protocol.name,
|
|
26
|
+
'name',
|
|
27
|
+
contractName,
|
|
28
|
+
'network',
|
|
29
|
+
network,
|
|
30
|
+
'source',
|
|
31
|
+
yaml.parse(
|
|
32
|
+
prettier.format(
|
|
33
|
+
protocolManifest.source({ contract: contractAddress, contractName }),
|
|
34
|
+
{ parser: 'yaml' },
|
|
35
|
+
),
|
|
36
|
+
),
|
|
37
|
+
'mapping',
|
|
38
|
+
yaml.parse(
|
|
39
|
+
prettier.format(protocolManifest.mapping({ abi, contractName }), {
|
|
40
|
+
parser: 'yaml',
|
|
41
|
+
}),
|
|
42
|
+
),
|
|
31
43
|
).asMutable()
|
|
32
44
|
}
|
|
33
45
|
|
|
@@ -130,11 +142,9 @@ const writeMapping = async (abi, protocol, contractName, entities) => {
|
|
|
130
142
|
|
|
131
143
|
const writeTestsFiles = async (abi, protocol, contractName) => {
|
|
132
144
|
const hasEvents = protocol.hasEvents()
|
|
133
|
-
const events = hasEvents
|
|
134
|
-
? abiEvents(abi).toJS()
|
|
135
|
-
: []
|
|
145
|
+
const events = hasEvents ? abiEvents(abi).toJS() : []
|
|
136
146
|
|
|
137
|
-
if(events.length > 0) {
|
|
147
|
+
if (events.length > 0) {
|
|
138
148
|
// If a contract is added to a subgraph that has no tests folder
|
|
139
149
|
await fs.ensureDir('./tests/')
|
|
140
150
|
|
|
@@ -148,8 +158,7 @@ const writeTestsFiles = async (abi, protocol, contractName) => {
|
|
|
148
158
|
}
|
|
149
159
|
}
|
|
150
160
|
|
|
151
|
-
|
|
152
|
-
...module.exports,
|
|
161
|
+
export {
|
|
153
162
|
generateScaffold,
|
|
154
163
|
writeScaffold,
|
|
155
164
|
generateDataSource,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
const immutable = require('immutable')
|
|
3
|
-
const toolbox = require('gluegun/toolbox')
|
|
1
|
+
import * as toolbox from 'gluegun'
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
export type Spinner = ReturnType<toolbox.GluegunPrint['spin']>
|
|
4
|
+
|
|
5
|
+
export const step = (spinner: Spinner, subject: string, text: string) => {
|
|
6
6
|
if (text) {
|
|
7
7
|
spinner.stopAndPersist({
|
|
8
8
|
text: toolbox.print.colors.muted(`${subject} ${text}`),
|
|
@@ -23,7 +23,12 @@ const step = (spinner, subject, text) => {
|
|
|
23
23
|
// spinner stops with the warning message and returns the `result` value.
|
|
24
24
|
// Otherwise the spinner prints the in-progress message with a check mark
|
|
25
25
|
// and simply returns the value returned by `f`.
|
|
26
|
-
const withSpinner = async (
|
|
26
|
+
export const withSpinner = async (
|
|
27
|
+
text: string,
|
|
28
|
+
errorText: string,
|
|
29
|
+
warningText: string,
|
|
30
|
+
f: (spinner: Spinner) => Promise<any> | any, // TODO: type result
|
|
31
|
+
) => {
|
|
27
32
|
let spinner = toolbox.print.spin(text)
|
|
28
33
|
try {
|
|
29
34
|
let result = await f(spinner)
|
|
@@ -55,8 +60,3 @@ const withSpinner = async (text, errorText, warningText, f) => {
|
|
|
55
60
|
throw e
|
|
56
61
|
}
|
|
57
62
|
}
|
|
58
|
-
|
|
59
|
-
module.exports = {
|
|
60
|
-
step,
|
|
61
|
-
withSpinner,
|
|
62
|
-
}
|