@graphprotocol/graph-cli 0.91.1 → 0.92.0-alpha-20241209150634-4f2ab935596be92b5d147871fedff09f4d8766df
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 +8 -0
- package/bin/run.js +4 -0
- package/dist/codegen/schema.d.ts +3 -3
- package/dist/codegen/schema.js +9 -36
- package/dist/codegen/schema.test.js +89 -117
- package/dist/codegen/template.d.ts +2 -2
- package/dist/codegen/template.js +8 -35
- package/dist/codegen/types/conversions.d.ts +1 -1
- package/dist/codegen/types/conversions.js +3 -8
- package/dist/codegen/types/index.js +13 -28
- package/dist/codegen/types/index.test.js +432 -457
- package/dist/codegen/typescript.js +30 -22
- package/dist/codegen/util.d.ts +1 -1
- package/dist/codegen/util.js +7 -16
- package/dist/codegen/util.test.js +12 -14
- package/dist/command-helpers/abi.d.ts +1 -1
- package/dist/command-helpers/abi.js +26 -41
- package/dist/command-helpers/abi.test.js +17 -19
- package/dist/command-helpers/auth.js +13 -44
- package/dist/command-helpers/compiler.d.ts +4 -5
- package/dist/command-helpers/compiler.js +11 -42
- package/dist/command-helpers/compiler.test.js +17 -19
- package/dist/command-helpers/data-sources.d.ts +1 -1
- package/dist/command-helpers/data-sources.js +11 -20
- package/dist/command-helpers/fs.js +3 -9
- package/dist/command-helpers/ipfs.js +1 -4
- package/dist/command-helpers/jsonrpc.js +8 -15
- package/dist/command-helpers/network.js +19 -28
- package/dist/command-helpers/network.test.js +25 -53
- package/dist/command-helpers/node.d.ts +1 -2
- package/dist/command-helpers/node.js +9 -15
- package/dist/command-helpers/scaffold.d.ts +9 -9
- package/dist/command-helpers/scaffold.js +58 -59
- package/dist/command-helpers/sort.js +1 -4
- package/dist/command-helpers/sort.test.js +18 -20
- package/dist/command-helpers/spinner.js +6 -11
- package/dist/command-helpers/subgraph.js +1 -5
- package/dist/command-helpers/version.js +8 -39
- package/dist/command-helpers/version.test.js +46 -71
- package/dist/commands/add.d.ts +8 -8
- package/dist/commands/add.js +74 -104
- package/dist/commands/auth.d.ts +2 -2
- package/dist/commands/auth.js +30 -31
- package/dist/commands/build.d.ts +9 -9
- package/dist/commands/build.js +54 -83
- package/dist/commands/clean.d.ts +3 -3
- package/dist/commands/clean.js +21 -24
- package/dist/commands/codegen.d.ts +8 -8
- package/dist/commands/codegen.js +54 -83
- package/dist/commands/create.d.ts +5 -5
- package/dist/commands/create.js +38 -42
- package/dist/commands/deploy.d.ts +16 -16
- package/dist/commands/deploy.js +117 -138
- package/dist/commands/init.d.ts +17 -17
- package/dist/commands/init.js +212 -248
- package/dist/commands/local.d.ts +13 -13
- package/dist/commands/local.js +102 -110
- package/dist/commands/publish.d.ts +8 -8
- package/dist/commands/publish.js +66 -90
- package/dist/commands/remove.d.ts +5 -5
- package/dist/commands/remove.js +38 -42
- package/dist/commands/test.d.ts +8 -8
- package/dist/commands/test.js +74 -80
- package/dist/compiler/asc.d.ts +0 -1
- package/dist/compiler/asc.js +3 -44
- package/dist/compiler/index.d.ts +3 -4
- package/dist/compiler/index.js +106 -124
- package/dist/constants.js +3 -6
- package/dist/debug.js +4 -9
- package/dist/fetch.js +5 -8
- package/dist/index.js +1 -5
- package/dist/migrations/mapping_api_version_0_0_1.js +8 -36
- package/dist/migrations/mapping_api_version_0_0_2.js +8 -36
- package/dist/migrations/mapping_api_version_0_0_3.js +8 -36
- package/dist/migrations/mapping_api_version_0_0_4.js +8 -36
- package/dist/migrations/mapping_api_version_0_0_5.js +8 -36
- package/dist/migrations/spec_version_0_0_2.js +4 -29
- package/dist/migrations/spec_version_0_0_3.js +4 -29
- package/dist/migrations/util/load-manifest.js +6 -13
- package/dist/migrations/util/versions.js +9 -16
- package/dist/migrations.js +12 -39
- package/dist/protocols/arweave/scaffold/manifest.js +2 -7
- package/dist/protocols/arweave/scaffold/mapping.js +1 -5
- package/dist/protocols/arweave/subgraph.d.ts +1 -1
- package/dist/protocols/arweave/subgraph.js +7 -10
- package/dist/protocols/contract.js +1 -2
- package/dist/protocols/cosmos/scaffold/manifest.js +2 -7
- package/dist/protocols/cosmos/scaffold/mapping.js +1 -5
- package/dist/protocols/cosmos/subgraph.d.ts +1 -1
- package/dist/protocols/cosmos/subgraph.js +7 -10
- package/dist/protocols/ethereum/abi.d.ts +1 -1
- package/dist/protocols/ethereum/abi.js +15 -18
- package/dist/protocols/ethereum/codegen/abi.d.ts +4 -4
- package/dist/protocols/ethereum/codegen/abi.js +28 -59
- package/dist/protocols/ethereum/codegen/abi.test.js +60 -88
- package/dist/protocols/ethereum/codegen/template.d.ts +1 -1
- package/dist/protocols/ethereum/codegen/template.js +3 -28
- package/dist/protocols/ethereum/contract.d.ts +1 -1
- package/dist/protocols/ethereum/contract.js +2 -4
- package/dist/protocols/ethereum/scaffold/manifest.d.ts +2 -2
- package/dist/protocols/ethereum/scaffold/manifest.js +9 -17
- package/dist/protocols/ethereum/scaffold/mapping.d.ts +1 -1
- package/dist/protocols/ethereum/scaffold/mapping.js +3 -7
- package/dist/protocols/ethereum/subgraph.d.ts +2 -2
- package/dist/protocols/ethereum/subgraph.js +24 -50
- package/dist/protocols/ethereum/type-generator.d.ts +3 -3
- package/dist/protocols/ethereum/type-generator.js +42 -46
- package/dist/protocols/file_template.d.ts +1 -1
- package/dist/protocols/file_template.js +3 -28
- package/dist/protocols/index.d.ts +5 -5
- package/dist/protocols/index.js +48 -74
- package/dist/protocols/near/contract.d.ts +1 -1
- package/dist/protocols/near/contract.js +2 -4
- package/dist/protocols/near/scaffold/manifest.js +4 -9
- package/dist/protocols/near/scaffold/mapping.js +1 -5
- package/dist/protocols/near/subgraph.d.ts +1 -1
- package/dist/protocols/near/subgraph.js +7 -10
- package/dist/protocols/subgraph/scaffold/manifest.js +2 -7
- package/dist/protocols/subgraph/scaffold/mapping.js +1 -5
- package/dist/protocols/subgraph/subgraph.js +7 -10
- package/dist/protocols/subgraph.js +1 -2
- package/dist/protocols/substreams/scaffold/manifest.d.ts +1 -1
- package/dist/protocols/substreams/scaffold/manifest.js +2 -7
- package/dist/protocols/substreams/subgraph.d.ts +1 -1
- package/dist/protocols/substreams/subgraph.js +7 -10
- package/dist/scaffold/cosmos.test.js +12 -17
- package/dist/scaffold/ethereum.test.js +26 -31
- package/dist/scaffold/get-docker-file.js +1 -5
- package/dist/scaffold/get-git-ignore.js +1 -5
- package/dist/scaffold/index.d.ts +2 -2
- package/dist/scaffold/index.js +47 -38
- package/dist/scaffold/mapping.js +14 -45
- package/dist/scaffold/near.test.js +12 -17
- package/dist/scaffold/schema.d.ts +1 -1
- package/dist/scaffold/schema.js +17 -49
- package/dist/scaffold/tests.js +15 -22
- package/dist/schema.d.ts +2 -2
- package/dist/schema.js +9 -35
- package/dist/subgraph.d.ts +1 -1
- package/dist/subgraph.js +38 -71
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/type-generator.d.ts +2 -2
- package/dist/type-generator.js +67 -95
- package/dist/utils.d.ts +2 -1
- package/dist/utils.js +6 -11
- package/dist/validation/contract.d.ts +2 -2
- package/dist/validation/contract.js +6 -14
- package/dist/validation/index.d.ts +3 -3
- package/dist/validation/index.js +3 -10
- package/dist/validation/manifest.d.ts +1 -1
- package/dist/validation/manifest.js +31 -38
- package/dist/validation/schema.js +60 -93
- package/dist/validation/schema.test.js +27 -29
- package/dist/version.js +5 -11
- package/dist/watcher.js +12 -13
- package/oclif.manifest.json +563 -404
- package/package.json +39 -41
- package/bin/run +0 -6
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.staticMethod = exports.StaticMethod = exports.param = exports.Param = exports.nullableType = exports.NullableType = exports.namedType = exports.NamedType = exports.moduleImports = exports.ModuleImports = exports.method = exports.Method = exports.klassMember = exports.klass = exports.GENERATED_FILE_NOTE = exports.ClassMember = exports.Class = exports.arrayType = exports.ArrayType = void 0;
|
|
4
1
|
class Param {
|
|
2
|
+
name;
|
|
3
|
+
type;
|
|
5
4
|
constructor(name, type) {
|
|
6
5
|
this.name = name;
|
|
7
6
|
this.type = type;
|
|
@@ -12,8 +11,11 @@ class Param {
|
|
|
12
11
|
return `${this.name}: ${this.type.toString()}`;
|
|
13
12
|
}
|
|
14
13
|
}
|
|
15
|
-
exports.Param = Param;
|
|
16
14
|
class Method {
|
|
15
|
+
name;
|
|
16
|
+
params;
|
|
17
|
+
returnType;
|
|
18
|
+
body;
|
|
17
19
|
constructor(name, params, returnType, body) {
|
|
18
20
|
this.name = name;
|
|
19
21
|
this.params = params;
|
|
@@ -31,8 +33,11 @@ class Method {
|
|
|
31
33
|
`;
|
|
32
34
|
}
|
|
33
35
|
}
|
|
34
|
-
exports.Method = Method;
|
|
35
36
|
class StaticMethod {
|
|
37
|
+
name;
|
|
38
|
+
params;
|
|
39
|
+
returnType;
|
|
40
|
+
body;
|
|
36
41
|
constructor(name, params, returnType, body) {
|
|
37
42
|
this.name = name;
|
|
38
43
|
this.params = params;
|
|
@@ -50,8 +55,12 @@ class StaticMethod {
|
|
|
50
55
|
`;
|
|
51
56
|
}
|
|
52
57
|
}
|
|
53
|
-
exports.StaticMethod = StaticMethod;
|
|
54
58
|
class Class {
|
|
59
|
+
name;
|
|
60
|
+
extends;
|
|
61
|
+
methods;
|
|
62
|
+
members;
|
|
63
|
+
export;
|
|
55
64
|
constructor(name, options) {
|
|
56
65
|
this.name = name;
|
|
57
66
|
this.name = name;
|
|
@@ -75,8 +84,9 @@ ${this.methods.map(method => method.toString()).join('')}
|
|
|
75
84
|
`;
|
|
76
85
|
}
|
|
77
86
|
}
|
|
78
|
-
exports.Class = Class;
|
|
79
87
|
class ClassMember {
|
|
88
|
+
name;
|
|
89
|
+
type;
|
|
80
90
|
constructor(name, type) {
|
|
81
91
|
this.name = name;
|
|
82
92
|
this.type = type;
|
|
@@ -87,8 +97,8 @@ class ClassMember {
|
|
|
87
97
|
return ` ${this.name}: ${this.type.toString()}`;
|
|
88
98
|
}
|
|
89
99
|
}
|
|
90
|
-
exports.ClassMember = ClassMember;
|
|
91
100
|
class NamedType {
|
|
101
|
+
name;
|
|
92
102
|
constructor(name) {
|
|
93
103
|
this.name = name;
|
|
94
104
|
this.name = name;
|
|
@@ -149,8 +159,9 @@ class NamedType {
|
|
|
149
159
|
return primitives.includes(this.name);
|
|
150
160
|
}
|
|
151
161
|
}
|
|
152
|
-
exports.NamedType = NamedType;
|
|
153
162
|
class ArrayType {
|
|
163
|
+
inner;
|
|
164
|
+
name;
|
|
154
165
|
constructor(inner) {
|
|
155
166
|
this.inner = inner;
|
|
156
167
|
this.inner = inner;
|
|
@@ -160,8 +171,8 @@ class ArrayType {
|
|
|
160
171
|
return this.name;
|
|
161
172
|
}
|
|
162
173
|
}
|
|
163
|
-
exports.ArrayType = ArrayType;
|
|
164
174
|
class NullableType {
|
|
175
|
+
inner;
|
|
165
176
|
constructor(inner) {
|
|
166
177
|
this.inner = inner;
|
|
167
178
|
this.inner = inner;
|
|
@@ -170,8 +181,9 @@ class NullableType {
|
|
|
170
181
|
return `${this.inner.toString()} | null`;
|
|
171
182
|
}
|
|
172
183
|
}
|
|
173
|
-
exports.NullableType = NullableType;
|
|
174
184
|
class ModuleImports {
|
|
185
|
+
nameOrNames;
|
|
186
|
+
module;
|
|
175
187
|
constructor(nameOrNames, module) {
|
|
176
188
|
this.nameOrNames = nameOrNames;
|
|
177
189
|
this.module = module;
|
|
@@ -182,26 +194,22 @@ class ModuleImports {
|
|
|
182
194
|
return `import { ${typeof this.nameOrNames === 'string' ? this.nameOrNames : this.nameOrNames.join(',')} } from "${this.module}"`;
|
|
183
195
|
}
|
|
184
196
|
}
|
|
185
|
-
exports.ModuleImports = ModuleImports;
|
|
186
197
|
const namedType = (name) => new NamedType(name);
|
|
187
|
-
exports.namedType = namedType;
|
|
188
198
|
const arrayType = (name) => new ArrayType(name);
|
|
189
|
-
exports.arrayType = arrayType;
|
|
190
199
|
const param = (name, type) => new Param(name, type);
|
|
191
|
-
exports.param = param;
|
|
192
200
|
const method = (name, params, returnType, body) => new Method(name, params, returnType, body);
|
|
193
|
-
exports.method = method;
|
|
194
201
|
const staticMethod = (name, params, returnType, body) => new StaticMethod(name, params, returnType, body);
|
|
195
|
-
exports.staticMethod = staticMethod;
|
|
196
202
|
const klass = (name, options) => new Class(name, options);
|
|
197
|
-
exports.klass = klass;
|
|
198
203
|
const klassMember = (name, type) => new ClassMember(name, type);
|
|
199
|
-
exports.klassMember = klassMember;
|
|
200
204
|
const nullableType = (type) => new NullableType(type);
|
|
201
|
-
exports.nullableType = nullableType;
|
|
202
205
|
const moduleImports = (nameOrNames, module) => new ModuleImports(nameOrNames, module);
|
|
203
|
-
exports.moduleImports = moduleImports;
|
|
204
206
|
const GENERATED_FILE_NOTE = `
|
|
205
207
|
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
|
206
208
|
`;
|
|
207
|
-
|
|
209
|
+
export { ArrayType, arrayType, Class, ClassMember,
|
|
210
|
+
// Utilities
|
|
211
|
+
GENERATED_FILE_NOTE, klass, klassMember, Method, method, ModuleImports, moduleImports, NamedType,
|
|
212
|
+
// Code generators
|
|
213
|
+
namedType, NullableType, nullableType,
|
|
214
|
+
// Types
|
|
215
|
+
Param, param, StaticMethod, staticMethod, };
|
package/dist/codegen/util.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export declare function disambiguateNames<T>({ values, getName, setName, }: {
|
|
|
3
3
|
getName: (value: T, index: number) => string;
|
|
4
4
|
setName: (value: T, name: string) => void;
|
|
5
5
|
}): void[];
|
|
6
|
-
export declare function isTupleType(t: string):
|
|
6
|
+
export declare function isTupleType(t: string): t is "tuple";
|
|
7
7
|
export declare function containsTupleType(t: string): true | RegExpMatchArray | null;
|
|
8
8
|
export declare function isTupleArrayType(t: string): RegExpMatchArray | null;
|
|
9
9
|
export declare function isTupleMatrixType(t: string): RegExpMatchArray | null;
|
package/dist/codegen/util.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.unrollTuple = exports.isTupleMatrixType = exports.isTupleArrayType = exports.containsTupleType = exports.isTupleType = exports.disambiguateNames = void 0;
|
|
4
|
-
function disambiguateNames({ values, getName, setName, }) {
|
|
1
|
+
export function disambiguateNames({ values, getName, setName, }) {
|
|
5
2
|
const collisionCounter = new Map();
|
|
6
3
|
return values.map((value, index) => {
|
|
7
4
|
const name = getName(value, index);
|
|
@@ -14,27 +11,21 @@ function disambiguateNames({ values, getName, setName, }) {
|
|
|
14
11
|
return setName(value, `${name}${counter}`);
|
|
15
12
|
});
|
|
16
13
|
}
|
|
17
|
-
|
|
18
|
-
function isTupleType(t) {
|
|
14
|
+
export function isTupleType(t) {
|
|
19
15
|
return t === 'tuple';
|
|
20
16
|
}
|
|
21
|
-
|
|
22
|
-
function containsTupleType(t) {
|
|
17
|
+
export function containsTupleType(t) {
|
|
23
18
|
return isTupleType(t) || isTupleArrayType(t) || isTupleMatrixType(t);
|
|
24
19
|
}
|
|
25
|
-
|
|
26
|
-
function isTupleArrayType(t) {
|
|
20
|
+
export function isTupleArrayType(t) {
|
|
27
21
|
return t.match(/^tuple\[([0-9]+)?\]$/);
|
|
28
22
|
}
|
|
29
|
-
|
|
30
|
-
function isTupleMatrixType(t) {
|
|
23
|
+
export function isTupleMatrixType(t) {
|
|
31
24
|
return t.match(/^tuple\[([0-9]+)?\]\[([0-9]+)?\]$/);
|
|
32
25
|
}
|
|
33
|
-
|
|
34
|
-
const unrollTuple = ({ path, value, }) => value.components.reduce((acc, component, index) => {
|
|
26
|
+
export const unrollTuple = ({ path, value, }) => value.components.reduce((acc, component, index) => {
|
|
35
27
|
const name = component.name || `value${index}`;
|
|
36
28
|
return acc.concat(component.type === 'tuple'
|
|
37
|
-
?
|
|
29
|
+
? unrollTuple({ path: [...path, name], index, value: component })
|
|
38
30
|
: [{ path: [...path, name], type: component.type }]);
|
|
39
31
|
}, []);
|
|
40
|
-
exports.unrollTuple = unrollTuple;
|
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
(0, vitest_1.test)('Name disambiguation', () => {
|
|
7
|
-
(0, vitest_1.expect)((0, util_1.disambiguateNames)({
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
import { disambiguateNames, unrollTuple } from './util.js';
|
|
3
|
+
describe.concurrent('Codegen utilities', () => {
|
|
4
|
+
test('Name disambiguation', () => {
|
|
5
|
+
expect(disambiguateNames({
|
|
8
6
|
values: ['a', 'b', 'c'],
|
|
9
7
|
getName: x => x,
|
|
10
8
|
setName: (_x, name) => name,
|
|
11
9
|
})).toEqual(['a', 'b', 'c']);
|
|
12
|
-
|
|
10
|
+
expect(disambiguateNames({
|
|
13
11
|
values: ['a', 'a', 'a'],
|
|
14
12
|
getName: x => x,
|
|
15
13
|
setName: (_x, name) => name,
|
|
16
14
|
})).toEqual(['a', 'a1', 'a2']);
|
|
17
|
-
|
|
15
|
+
expect(disambiguateNames({
|
|
18
16
|
values: [
|
|
19
17
|
{ name: 'ExampleEvent', inputs: [] },
|
|
20
18
|
{ name: 'ExampleEvent', inputs: [{ type: 'uint256' }] },
|
|
@@ -31,13 +29,13 @@ vitest_1.describe.concurrent('Codegen utilities', () => {
|
|
|
31
29
|
{ name: 'ExampleEvent2', inputs: [{ type: 'uint96' }] },
|
|
32
30
|
]);
|
|
33
31
|
});
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
test('Tuple unrolling', () => {
|
|
33
|
+
expect(unrollTuple({
|
|
36
34
|
value: { type: 'tuple', name: 'value', components: [] },
|
|
37
35
|
path: ['value'],
|
|
38
36
|
index: 0,
|
|
39
37
|
})).toEqual([]);
|
|
40
|
-
|
|
38
|
+
expect(unrollTuple({
|
|
41
39
|
value: {
|
|
42
40
|
type: 'tuple',
|
|
43
41
|
name: 'value',
|
|
@@ -46,7 +44,7 @@ vitest_1.describe.concurrent('Codegen utilities', () => {
|
|
|
46
44
|
path: ['value'],
|
|
47
45
|
index: 0,
|
|
48
46
|
})).toEqual([{ path: ['value', 'a'], type: 'string' }]);
|
|
49
|
-
|
|
47
|
+
expect(unrollTuple({
|
|
50
48
|
value: {
|
|
51
49
|
type: 'tuple',
|
|
52
50
|
name: 'value',
|
|
@@ -61,7 +59,7 @@ vitest_1.describe.concurrent('Codegen utilities', () => {
|
|
|
61
59
|
{ path: ['value', 'a'], type: 'string' },
|
|
62
60
|
{ path: ['value', 'b'], type: 'uint256' },
|
|
63
61
|
]);
|
|
64
|
-
|
|
62
|
+
expect(unrollTuple({
|
|
65
63
|
value: {
|
|
66
64
|
type: 'tuple',
|
|
67
65
|
name: 'value',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import ABI from '../protocols/ethereum/abi';
|
|
1
|
+
import ABI from '../protocols/ethereum/abi.js';
|
|
2
2
|
export declare const loadAbiFromEtherscan: (ABICtor: typeof ABI, network: string, address: string) => Promise<ABI>;
|
|
3
3
|
export declare const loadStartBlockForContract: (network: string, address: string) => Promise<string>;
|
|
4
4
|
export declare const loadContractNameForAddress: (network: string, address: string) => Promise<string>;
|
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const immutable_1 = __importDefault(require("immutable"));
|
|
8
|
-
const constants_1 = require("../constants");
|
|
9
|
-
const debug_1 = __importDefault(require("../debug"));
|
|
10
|
-
const fetch_1 = __importDefault(require("../fetch"));
|
|
11
|
-
const spinner_1 = require("./spinner");
|
|
12
|
-
const logger = (0, debug_1.default)('graph-cli:abi-helpers');
|
|
1
|
+
import immutable from 'immutable';
|
|
2
|
+
import { GRAPH_CLI_SHARED_HEADERS } from '../constants.js';
|
|
3
|
+
import debugFactory from '../debug.js';
|
|
4
|
+
import fetch from '../fetch.js';
|
|
5
|
+
import { withSpinner } from './spinner.js';
|
|
6
|
+
const logger = debugFactory('graph-cli:abi-helpers');
|
|
13
7
|
const fetchFromEtherscan = async (url) => {
|
|
14
|
-
const result = await (
|
|
8
|
+
const result = await fetch(url);
|
|
15
9
|
let json = {};
|
|
16
10
|
if (result.ok) {
|
|
17
11
|
json = await result.json().catch(error => {
|
|
@@ -26,23 +20,20 @@ const fetchFromEtherscan = async (url) => {
|
|
|
26
20
|
logger('Failed to fetchFromEtherscan: [%s] %s (%s)\n%O', result.status, result.statusText, result.url, json);
|
|
27
21
|
return null;
|
|
28
22
|
};
|
|
29
|
-
const loadAbiFromEtherscan = async (ABICtor, network, address) => await
|
|
23
|
+
export const loadAbiFromEtherscan = async (ABICtor, network, address) => await withSpinner(`Fetching ABI from Etherscan`, `Failed to fetch ABI from Etherscan`, `Warnings while fetching ABI from Etherscan`, async () => {
|
|
30
24
|
const scanApiUrl = getEtherscanLikeAPIUrl(network);
|
|
31
25
|
const json = await fetchFromEtherscan(`${scanApiUrl}?module=contract&action=getabi&address=${address}`);
|
|
32
26
|
if (json)
|
|
33
|
-
return new ABICtor('Contract', undefined,
|
|
27
|
+
return new ABICtor('Contract', undefined, immutable.fromJS(JSON.parse(json.result)));
|
|
34
28
|
throw new Error('Try loading it from a local file');
|
|
35
29
|
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return (0, exports.getStartBlockForContract)(network, address);
|
|
30
|
+
export const loadStartBlockForContract = async (network, address) => await withSpinner(`Fetching Start Block`, `Failed to fetch Start Block`, `Warnings while fetching deploy contract transaction from Etherscan`, async () => {
|
|
31
|
+
return getStartBlockForContract(network, address);
|
|
39
32
|
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return (0, exports.getContractNameForAddress)(network, address);
|
|
33
|
+
export const loadContractNameForAddress = async (network, address) => await withSpinner(`Fetching Contract Name`, `Failed to fetch Contract Name`, `Warnings while fetching contract name from Etherscan`, async () => {
|
|
34
|
+
return getContractNameForAddress(network, address);
|
|
43
35
|
});
|
|
44
|
-
|
|
45
|
-
const fetchDeployContractTransactionFromEtherscan = async (network, address) => {
|
|
36
|
+
export const fetchDeployContractTransactionFromEtherscan = async (network, address) => {
|
|
46
37
|
const scanApiUrl = getEtherscanLikeAPIUrl(network);
|
|
47
38
|
const json = await fetchFromEtherscan(`${scanApiUrl}?module=contract&action=getcontractcreation&contractaddresses=${address}`);
|
|
48
39
|
if (json) {
|
|
@@ -52,18 +43,17 @@ const fetchDeployContractTransactionFromEtherscan = async (network, address) =>
|
|
|
52
43
|
}
|
|
53
44
|
throw new Error(`Failed to fetch deploy contract transaction`);
|
|
54
45
|
};
|
|
55
|
-
|
|
56
|
-
const fetchTransactionByHashFromRPC = async (network, transactionHash) => {
|
|
46
|
+
export const fetchTransactionByHashFromRPC = async (network, transactionHash) => {
|
|
57
47
|
let json;
|
|
58
48
|
const RPCURL = getPublicRPCEndpoint(network);
|
|
59
49
|
try {
|
|
60
50
|
if (!RPCURL)
|
|
61
51
|
throw new Error(`Unable to fetch RPC URL for ${network}`);
|
|
62
|
-
const result = await (
|
|
52
|
+
const result = await fetch(String(RPCURL), {
|
|
63
53
|
method: 'POST',
|
|
64
54
|
headers: {
|
|
65
55
|
'Content-Type': 'application/json',
|
|
66
|
-
...
|
|
56
|
+
...GRAPH_CLI_SHARED_HEADERS,
|
|
67
57
|
},
|
|
68
58
|
body: JSON.stringify({
|
|
69
59
|
jsonrpc: '2.0',
|
|
@@ -80,8 +70,7 @@ const fetchTransactionByHashFromRPC = async (network, transactionHash) => {
|
|
|
80
70
|
throw new Error(`Failed to run \`eth_getTransactionByHash\` on RPC (${RPCURL}) (run with env \`DEBUG=*\` for full error).`);
|
|
81
71
|
}
|
|
82
72
|
};
|
|
83
|
-
|
|
84
|
-
const fetchSourceCodeFromEtherscan = async (network, address) => {
|
|
73
|
+
export const fetchSourceCodeFromEtherscan = async (network, address) => {
|
|
85
74
|
const scanApiUrl = getEtherscanLikeAPIUrl(network);
|
|
86
75
|
const json = await fetchFromEtherscan(`${scanApiUrl}?module=contract&action=getsourcecode&address=${address}`);
|
|
87
76
|
// Have to check that the SourceCode response is not empty due to Etherscan API bug responding with
|
|
@@ -90,10 +79,9 @@ const fetchSourceCodeFromEtherscan = async (network, address) => {
|
|
|
90
79
|
return json;
|
|
91
80
|
throw new Error(`Failed to fetch contract source code: ${json.result[0].ABI}`);
|
|
92
81
|
};
|
|
93
|
-
|
|
94
|
-
const getContractNameForAddress = async (network, address) => {
|
|
82
|
+
export const getContractNameForAddress = async (network, address) => {
|
|
95
83
|
try {
|
|
96
|
-
const contractSourceCode = await
|
|
84
|
+
const contractSourceCode = await fetchSourceCodeFromEtherscan(network, address);
|
|
97
85
|
let contractName = contractSourceCode.result[0].ContractName;
|
|
98
86
|
// Some explorers will return the full path of the contract instead of just the name
|
|
99
87
|
// Example: contracts/SyncSwapRouter.sol:SyncSwapRouter
|
|
@@ -107,11 +95,10 @@ const getContractNameForAddress = async (network, address) => {
|
|
|
107
95
|
throw new Error(error?.message);
|
|
108
96
|
}
|
|
109
97
|
};
|
|
110
|
-
|
|
111
|
-
const getStartBlockForContract = async (network, address) => {
|
|
98
|
+
export const getStartBlockForContract = async (network, address) => {
|
|
112
99
|
try {
|
|
113
|
-
const transactionHash = await
|
|
114
|
-
const txn = await
|
|
100
|
+
const transactionHash = await fetchDeployContractTransactionFromEtherscan(network, address);
|
|
101
|
+
const txn = await fetchTransactionByHashFromRPC(network, transactionHash);
|
|
115
102
|
const blockNumber = parseInt(txn.result.blockNumber, 16);
|
|
116
103
|
logger('Successfully getStartBlockForContract. blockNumber: %s', blockNumber);
|
|
117
104
|
return blockNumber;
|
|
@@ -121,21 +108,19 @@ const getStartBlockForContract = async (network, address) => {
|
|
|
121
108
|
throw new Error(error?.message);
|
|
122
109
|
}
|
|
123
110
|
};
|
|
124
|
-
|
|
125
|
-
const
|
|
126
|
-
const result = await (0, fetch_1.default)(`https://blockscout.com/${network.replace('-', '/')}/api?module=contract&action=getabi&address=${address}`);
|
|
111
|
+
export const loadAbiFromBlockScout = async (ABICtor, network, address) => await withSpinner(`Fetching ABI from BlockScout`, `Failed to fetch ABI from BlockScout`, `Warnings while fetching ABI from BlockScout`, async () => {
|
|
112
|
+
const result = await fetch(`https://blockscout.com/${network.replace('-', '/')}/api?module=contract&action=getabi&address=${address}`);
|
|
127
113
|
const json = await result.json();
|
|
128
114
|
// BlockScout returns a JSON object that has a `status`, a `message` and
|
|
129
115
|
// a `result` field. The `status` is '0' in case of errors and '1' in
|
|
130
116
|
// case of success
|
|
131
117
|
if (json.status === '1') {
|
|
132
118
|
logger('Successfully loadAbiFromBlockScout. address: %s', address);
|
|
133
|
-
return new ABICtor('Contract', undefined,
|
|
119
|
+
return new ABICtor('Contract', undefined, immutable.fromJS(JSON.parse(json.result)));
|
|
134
120
|
}
|
|
135
121
|
logger('Failed to loadAbiFromBlockScout. address: %s', address);
|
|
136
122
|
throw new Error('ABI not found, try loading it from a local file');
|
|
137
123
|
});
|
|
138
|
-
exports.loadAbiFromBlockScout = loadAbiFromBlockScout;
|
|
139
124
|
const getEtherscanLikeAPIUrl = (network) => {
|
|
140
125
|
switch (network) {
|
|
141
126
|
case 'mainnet':
|
|
@@ -1,41 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const vitest_1 = require("vitest");
|
|
4
|
-
const abi_1 = require("./abi");
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
import { getStartBlockForContract } from './abi.js';
|
|
5
3
|
// An object with some test cases for contract deployment block numbers
|
|
6
4
|
const TEST_CONTRACT_START_BLOCKS = {
|
|
7
5
|
'arbitrum-goerli': {
|
|
8
|
-
'0xde438d54c7b75f798985ae38a4d07b5431702077':
|
|
6
|
+
'0xde438d54c7b75f798985ae38a4d07b5431702077': 4_488_583,
|
|
9
7
|
},
|
|
10
8
|
'arbitrum-one': {
|
|
11
|
-
'0xF4d73326C13a4Fc5FD7A064217e12780e9Bd62c3':
|
|
9
|
+
'0xF4d73326C13a4Fc5FD7A064217e12780e9Bd62c3': 226_981,
|
|
12
10
|
},
|
|
13
11
|
avalanche: {
|
|
14
|
-
'0xc35DADB65012eC5796536bD9864eD8773aBc74C4':
|
|
12
|
+
'0xc35DADB65012eC5796536bD9864eD8773aBc74C4': 506_190,
|
|
15
13
|
},
|
|
16
14
|
bsc: {
|
|
17
|
-
'0xc35DADB65012eC5796536bD9864eD8773aBc74C4':
|
|
15
|
+
'0xc35DADB65012eC5796536bD9864eD8773aBc74C4': 5_205_069,
|
|
18
16
|
},
|
|
19
17
|
fantom: {
|
|
20
|
-
'0xf731202A3cf7EfA9368C2d7bD613926f7A144dB5':
|
|
18
|
+
'0xf731202A3cf7EfA9368C2d7bD613926f7A144dB5': 28_771_200,
|
|
21
19
|
},
|
|
22
20
|
goerli: {
|
|
23
|
-
'0xff02b7d59975E76F67B63b20b813a9Ec0f6AbD60':
|
|
21
|
+
'0xff02b7d59975E76F67B63b20b813a9Ec0f6AbD60': 226_385,
|
|
24
22
|
},
|
|
25
23
|
mainnet: {
|
|
26
|
-
'0xc2EdaD668740f1aA35E4D8f227fB8E17dcA888Cd':
|
|
24
|
+
'0xc2EdaD668740f1aA35E4D8f227fB8E17dcA888Cd': 10_736_242,
|
|
27
25
|
},
|
|
28
26
|
matic: {
|
|
29
|
-
'0x0769fd68dFb93167989C6f7254cd0D766Fb2841F':
|
|
27
|
+
'0x0769fd68dFb93167989C6f7254cd0D766Fb2841F': 13_911_377,
|
|
30
28
|
},
|
|
31
29
|
moonbeam: {
|
|
32
|
-
'0x011E52E4E40CF9498c79273329E8827b21E2e581':
|
|
30
|
+
'0x011E52E4E40CF9498c79273329E8827b21E2e581': 505_060,
|
|
33
31
|
},
|
|
34
32
|
moonriver: {
|
|
35
|
-
'0x3dB01570D97631f69bbb0ba39796865456Cf89A5':
|
|
33
|
+
'0x3dB01570D97631f69bbb0ba39796865456Cf89A5': 800_950,
|
|
36
34
|
},
|
|
37
35
|
optimism: {
|
|
38
|
-
'0xc35DADB65012eC5796536bD9864eD8773aBc74C4':
|
|
36
|
+
'0xc35DADB65012eC5796536bD9864eD8773aBc74C4': 7_019_815,
|
|
39
37
|
},
|
|
40
38
|
// Skipping these networks for now because they do not support the latest etherscan contracts API or is blockScout based
|
|
41
39
|
// Chains that doesn't support the latest etherscan contracts API
|
|
@@ -83,13 +81,13 @@ const TEST_CONTRACT_START_BLOCKS = {
|
|
|
83
81
|
// },
|
|
84
82
|
};
|
|
85
83
|
// skip this test since its time consuming
|
|
86
|
-
|
|
84
|
+
describe.skip('getStartBlockForContract', () => {
|
|
87
85
|
for (const [network, contracts] of Object.entries(TEST_CONTRACT_START_BLOCKS)) {
|
|
88
86
|
for (const [contract, startBlockExp] of Object.entries(contracts)) {
|
|
89
|
-
|
|
87
|
+
test(`Returns the start block ${network} ${contract} ${startBlockExp}`, async () => {
|
|
90
88
|
//loop through the TEST_CONTRACT_START_BLOCKS object and test each network
|
|
91
|
-
const startBlock = await
|
|
92
|
-
|
|
89
|
+
const startBlock = await getStartBlockForContract(network, contract);
|
|
90
|
+
expect(startBlock).toBe(startBlockExp);
|
|
93
91
|
});
|
|
94
92
|
}
|
|
95
93
|
}
|
|
@@ -1,50 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.saveDeployKey = exports.identifyDeployKey = void 0;
|
|
30
|
-
const fs_1 = __importDefault(require("fs"));
|
|
31
|
-
const os_1 = __importDefault(require("os"));
|
|
32
|
-
const path_1 = __importDefault(require("path"));
|
|
33
|
-
const toolbox = __importStar(require("gluegun"));
|
|
34
|
-
const node_1 = require("./node");
|
|
35
|
-
const homedir = os_1.default.homedir();
|
|
36
|
-
const CONFIG_PATH = path_1.default.join(homedir, '/.graph-cli.json');
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import * as toolbox from 'gluegun';
|
|
5
|
+
import { normalizeNodeUrl } from './node.js';
|
|
6
|
+
const homedir = os.homedir();
|
|
7
|
+
const CONFIG_PATH = path.join(homedir, '/.graph-cli.json');
|
|
37
8
|
const getConfig = () => {
|
|
38
9
|
let config;
|
|
39
10
|
try {
|
|
40
|
-
config = JSON.parse(
|
|
11
|
+
config = JSON.parse(fs.readFileSync(CONFIG_PATH).toString());
|
|
41
12
|
}
|
|
42
13
|
catch {
|
|
43
14
|
config = {};
|
|
44
15
|
}
|
|
45
16
|
return config;
|
|
46
17
|
};
|
|
47
|
-
const identifyDeployKey = async (node, deployKey) => {
|
|
18
|
+
export const identifyDeployKey = async (node, deployKey) => {
|
|
48
19
|
// Determine the deploy key to use, if any:
|
|
49
20
|
// - First try using --deploy-key, if provided
|
|
50
21
|
// - Then see if we have a deploy key set for the Graph node
|
|
@@ -52,7 +23,7 @@ const identifyDeployKey = async (node, deployKey) => {
|
|
|
52
23
|
return deployKey;
|
|
53
24
|
}
|
|
54
25
|
try {
|
|
55
|
-
node =
|
|
26
|
+
node = normalizeNodeUrl(node);
|
|
56
27
|
const config = getConfig();
|
|
57
28
|
return config[node];
|
|
58
29
|
}
|
|
@@ -61,16 +32,14 @@ const identifyDeployKey = async (node, deployKey) => {
|
|
|
61
32
|
toolbox.print.info(`Continuing without a deploy key\n`);
|
|
62
33
|
}
|
|
63
34
|
};
|
|
64
|
-
|
|
65
|
-
const saveDeployKey = async (node, deployKey) => {
|
|
35
|
+
export const saveDeployKey = async (node, deployKey) => {
|
|
66
36
|
try {
|
|
67
|
-
node =
|
|
37
|
+
node = normalizeNodeUrl(node);
|
|
68
38
|
const config = getConfig();
|
|
69
39
|
config[node] = deployKey;
|
|
70
|
-
|
|
40
|
+
fs.writeFileSync(CONFIG_PATH, JSON.stringify(config));
|
|
71
41
|
}
|
|
72
42
|
catch (e) {
|
|
73
43
|
throw new Error(`Error storing deploy key: ${e.message}`);
|
|
74
44
|
}
|
|
75
45
|
};
|
|
76
|
-
exports.saveDeployKey = saveDeployKey;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import Protocol from '../protocols';
|
|
1
|
+
import { URL } from 'node:url';
|
|
2
|
+
import Compiler from '../compiler/index.js';
|
|
3
|
+
import Protocol from '../protocols/index.js';
|
|
5
4
|
interface CreateCompilerOptions {
|
|
6
5
|
ipfs: string | URL | undefined;
|
|
7
6
|
headers?: Headers | Record<string, string>;
|
|
@@ -15,5 +14,5 @@ interface CreateCompilerOptions {
|
|
|
15
14
|
* Appends /api/v0 to the end of a The Graph IPFS URL
|
|
16
15
|
*/
|
|
17
16
|
export declare function appendApiVersionForGraph(inputString: string): string;
|
|
18
|
-
export declare function createCompiler(manifest: string, { ipfs, headers, outputDir, outputFormat, skipMigrations, blockIpfsMethods, protocol, }: CreateCompilerOptions): Compiler | null
|
|
17
|
+
export declare function createCompiler(manifest: string, { ipfs, headers, outputDir, outputFormat, skipMigrations, blockIpfsMethods, protocol, }: CreateCompilerOptions): Promise<Compiler | null>;
|
|
19
18
|
export {};
|