@graphprotocol/graph-cli 0.42.0-alpha-20230223150823-e2de1b8 → 0.42.0-alpha-20230223150916-0a8496d

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 CHANGED
@@ -1,19 +1,26 @@
1
1
  # @graphprotocol/graph-cli
2
2
 
3
- ## 0.42.0-alpha-20230223150823-e2de1b8
3
+ ## 0.42.0-alpha-20230223150916-0a8496d
4
4
 
5
5
  ### Minor Changes
6
6
 
7
+ - [#1068](https://github.com/graphprotocol/graph-tooling/pull/1068)
8
+ [`8c7e4e0`](https://github.com/graphprotocol/graph-tooling/commit/8c7e4e0b33033b83cf97eb2466d9cd77437e2dd0)
9
+ Thanks [@incrypto32](https://github.com/incrypto32)! - Add startblock auto fetch for `add` command
10
+
7
11
  - [#1079](https://github.com/graphprotocol/graph-tooling/pull/1079)
8
12
  [`570eb22`](https://github.com/graphprotocol/graph-tooling/commit/570eb225fad705998cca3998879a6a1140a73143)
9
13
  Thanks [@incrypto32](https://github.com/incrypto32)! - Remove optimism-kovan, Add optimism-goerli
10
14
 
11
- - [#1126](https://github.com/graphprotocol/graph-tooling/pull/1126)
12
- [`3b1f32f`](https://github.com/graphprotocol/graph-tooling/commit/3b1f32ff8915286135fdb8927db006568414a664)
13
- Thanks [@azf20](https://github.com/azf20)! - Add `mainnet` as network for substreams
14
-
15
15
  ### Patch Changes
16
16
 
17
+ - [#1068](https://github.com/graphprotocol/graph-tooling/pull/1068)
18
+ [`dd9f83c`](https://github.com/graphprotocol/graph-tooling/commit/dd9f83cf50d2f207fa19b4035bddcdbd21770f26)
19
+ Thanks [@incrypto32](https://github.com/incrypto32)! - dependencies updates:
20
+
21
+ - Added dependency [`@oclif/core@2.0.7` ↗︎](https://www.npmjs.com/package/@oclif/core/v/2.0.7) (to
22
+ `dependencies`)
23
+
17
24
  - [#1127](https://github.com/graphprotocol/graph-tooling/pull/1127)
18
25
  [`b8d2297`](https://github.com/graphprotocol/graph-tooling/commit/b8d2297bea994b852d5a61b557e4eccda283ec75)
19
26
  Thanks [@saihaj](https://github.com/saihaj)! - Prioirtize node flag. If provided we do not need to
@@ -15,9 +15,9 @@ const mapping_1 = require("../scaffold/mapping");
15
15
  const schema_1 = require("../scaffold/schema");
16
16
  const tests_1 = require("../scaffold/tests");
17
17
  const spinner_1 = require("./spinner");
18
- const generateDataSource = async (protocol, contractName, network, contractAddress, abi) => {
18
+ const generateDataSource = async (protocol, contractName, network, contractAddress, abi, startBlock) => {
19
19
  const protocolManifest = protocol.getManifestScaffold();
20
- return immutable_1.Map.of('kind', protocol.name, 'name', contractName, 'network', network, 'source', yaml_1.default.parse(prettier_1.default.format(protocolManifest.source({ contract: contractAddress, contractName }), {
20
+ return immutable_1.Map.of('kind', protocol.name, 'name', contractName, 'network', network, 'source', yaml_1.default.parse(prettier_1.default.format(protocolManifest.source({ contract: contractAddress, contractName, startBlock }), {
21
21
  parser: 'yaml',
22
22
  })), 'mapping', yaml_1.default.parse(prettier_1.default.format(protocolManifest.mapping({ abi, contractName }), {
23
23
  parser: 'yaml',
@@ -40,12 +40,13 @@ const abi_2 = __importDefault(require("../protocols/ethereum/abi"));
40
40
  const subgraph_1 = __importDefault(require("../subgraph"));
41
41
  class AddCommand extends core_1.Command {
42
42
  async run() {
43
- const { args: { address, 'subgraph-manifest': manifestPath }, flags: { abi, 'contract-name': contractName, 'merge-entities': mergeEntities, 'network-file': networksFile, }, } = await this.parse(AddCommand);
43
+ const { args: { address, 'subgraph-manifest': manifestPath }, flags: { abi, 'contract-name': contractName, 'merge-entities': mergeEntities, 'network-file': networksFile, 'start-block': startBlockFlag, }, } = await this.parse(AddCommand);
44
44
  const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(manifestPath);
45
45
  const protocol = protocols_1.default.fromDataSources(dataSourcesAndTemplates);
46
46
  const manifest = await subgraph_1.default.load(manifestPath, { protocol });
47
47
  const network = manifest.result.getIn(['dataSources', 0, 'network']);
48
48
  const result = manifest.result.asMutable();
49
+ let startBlock = startBlockFlag;
49
50
  const entities = getEntities(manifest);
50
51
  const contractNames = getContractNames(manifest);
51
52
  if (contractNames.includes(contractName)) {
@@ -61,6 +62,13 @@ class AddCommand extends core_1.Command {
61
62
  else {
62
63
  ethabi = await (0, abi_1.loadAbiFromEtherscan)(abi_2.default, network, address);
63
64
  }
65
+ try {
66
+ startBlock || (startBlock = Number(await (0, abi_1.loadStartBlockForContract)(network, address)).toString());
67
+ }
68
+ catch (error) {
69
+ // If we can't get the start block, we'll just leave it out of the manifest
70
+ // TODO: Ask the user for the start block
71
+ }
64
72
  const { collisionEntities, onlyCollisions, abiData } = updateEventNamesOnCollision(ethabi, entities, contractName, mergeEntities);
65
73
  ethabi.data = abiData;
66
74
  await (0, scaffold_1.writeABI)(ethabi, contractName);
@@ -68,7 +76,7 @@ class AddCommand extends core_1.Command {
68
76
  await (0, scaffold_1.writeMapping)(ethabi, protocol, contractName, collisionEntities);
69
77
  await (0, scaffold_1.writeTestsFiles)(ethabi, protocol, contractName);
70
78
  const dataSources = result.get('dataSources');
71
- const dataSource = await (0, scaffold_1.generateDataSource)(protocol, contractName, network, address, ethabi);
79
+ const dataSource = await (0, scaffold_1.generateDataSource)(protocol, contractName, network, address, ethabi, startBlock);
72
80
  // Handle the collisions edge case by copying another data source yaml data
73
81
  if (mergeEntities && onlyCollisions) {
74
82
  const firstDataSource = dataSources.get(0);
@@ -113,6 +121,10 @@ AddCommand.flags = {
113
121
  summary: 'Path to the contract ABI.',
114
122
  default: '*Download from Etherscan*',
115
123
  }),
124
+ 'start-block': core_1.Flags.string({
125
+ summary: 'The block number to start indexing events from.',
126
+ default: '*Zero*',
127
+ }),
116
128
  'contract-name': core_1.Flags.string({
117
129
  summary: 'Name of the contract.',
118
130
  default: 'Contract',
@@ -129,7 +129,6 @@ class Protocol {
129
129
  'juno-1',
130
130
  'uni-3', // Juno testnet
131
131
  ],
132
- substreams: ['mainnet'],
133
132
  });
134
133
  const allNetworks = [];
135
134
  networks.forEach(value => {
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.42.0-alpha-20230223150823-e2de1b8",
2
+ "version": "0.42.0-alpha-20230223150916-0a8496d",
3
3
  "commands": {
4
4
  "add": {
5
5
  "id": "add",
@@ -24,6 +24,13 @@
24
24
  "multiple": false,
25
25
  "default": "*Download from Etherscan*"
26
26
  },
27
+ "start-block": {
28
+ "name": "start-block",
29
+ "type": "option",
30
+ "summary": "The block number to start indexing events from.",
31
+ "multiple": false,
32
+ "default": "*Zero*"
33
+ },
27
34
  "contract-name": {
28
35
  "name": "contract-name",
29
36
  "type": "option",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphprotocol/graph-cli",
3
- "version": "0.42.0-alpha-20230223150823-e2de1b8",
3
+ "version": "0.42.0-alpha-20230223150916-0a8496d",
4
4
  "description": "CLI for building for and deploying to The Graph",
5
5
  "license": "(Apache-2.0 OR MIT)",
6
6
  "engines": {