@sentio/sdk 1.27.10 → 1.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/aptos/api.d.ts +2 -0
- package/lib/aptos/api.js +14 -0
- package/lib/aptos/api.js.map +1 -0
- package/lib/aptos/aptos-processor.d.ts +5 -4
- package/lib/aptos/aptos-processor.js +8 -9
- package/lib/aptos/aptos-processor.js.map +1 -1
- package/lib/aptos/context.d.ts +3 -2
- package/lib/aptos/context.js +3 -3
- package/lib/aptos/context.js.map +1 -1
- package/lib/aptos/index.d.ts +3 -2
- package/lib/aptos/index.js +18 -3
- package/lib/aptos/index.js.map +1 -1
- package/lib/aptos/models.d.ts +23 -0
- package/lib/aptos/models.js +3 -0
- package/lib/aptos/models.js.map +1 -0
- package/lib/aptos/type-registry.d.ts +21 -0
- package/lib/aptos/type-registry.js +156 -0
- package/lib/aptos/type-registry.js.map +1 -0
- package/lib/aptos/types.d.ts +1 -33
- package/lib/aptos/types.js +49 -142
- package/lib/aptos/types.js.map +1 -1
- package/lib/aptos/types.test.js.map +1 -1
- package/lib/aptos/utils.d.ts +0 -2
- package/lib/aptos/utils.js +1 -8
- package/lib/aptos/utils.js.map +1 -1
- package/lib/aptos-codegen/codegen.js +2 -1
- package/lib/aptos-codegen/codegen.js.map +1 -1
- package/lib/aptos-codegen/typegen.d.ts +0 -1
- package/lib/aptos-codegen/typegen.js +3 -61
- package/lib/aptos-codegen/typegen.js.map +1 -1
- package/lib/cli/upload.js +2 -1
- package/lib/cli/upload.js.map +1 -1
- package/lib/core/base-context.d.ts +12 -0
- package/lib/core/base-context.js +25 -0
- package/lib/core/base-context.js.map +1 -0
- package/lib/core/base-processor.d.ts +1 -2
- package/lib/core/base-processor.js.map +1 -1
- package/lib/core/context.d.ts +2 -11
- package/lib/core/context.js +5 -24
- package/lib/core/context.js.map +1 -1
- package/lib/core/event-tracker.d.ts +1 -1
- package/lib/core/event-tracker.js +2 -2
- package/lib/core/event-tracker.js.map +1 -1
- package/lib/core/exporter.d.ts +1 -1
- package/lib/core/exporter.js.map +1 -1
- package/lib/core/generic-processor.test.js.map +1 -1
- package/lib/core/logger.d.ts +1 -1
- package/lib/core/logger.js.map +1 -1
- package/lib/core/meter.d.ts +1 -1
- package/lib/core/meter.js.map +1 -1
- package/lib/endpoints.d.ts +6 -0
- package/lib/endpoints.js +11 -0
- package/lib/endpoints.js.map +1 -0
- package/lib/gen/google/protobuf/timestamp.d.ts +18 -0
- package/lib/gen/google/protobuf/timestamp.js +75 -0
- package/lib/gen/google/protobuf/timestamp.js.map +1 -0
- package/lib/gen/service/price/protos/price.d.ts +85 -0
- package/lib/gen/service/price/protos/price.js +281 -0
- package/lib/gen/service/price/protos/price.js.map +1 -0
- package/lib/processor-runner.js +6 -0
- package/lib/processor-runner.js.map +1 -1
- package/lib/processor-state.d.ts +2 -6
- package/lib/processor-state.js +0 -2
- package/lib/processor-state.js.map +1 -1
- package/lib/provider.js +5 -5
- package/lib/provider.js.map +1 -1
- package/lib/testing/test-processor-server.d.ts +4 -1
- package/lib/testing/test-processor-server.js +15 -7
- package/lib/testing/test-processor-server.js.map +1 -1
- package/lib/utils/conversion.d.ts +2 -1
- package/lib/utils/conversion.js +3 -3
- package/lib/utils/conversion.js.map +1 -1
- package/lib/utils/dex-price.test.js.map +1 -1
- package/lib/utils/erc20.test.js.map +1 -1
- package/lib/utils/price.d.ts +10 -0
- package/lib/utils/price.js +59 -0
- package/lib/utils/price.js.map +1 -0
- package/lib/utils/token.d.ts +1 -1
- package/lib/utils/token.js +2 -2
- package/lib/utils/token.js.map +1 -1
- package/package.json +5 -2
- package/src/aptos/api.ts +11 -0
- package/src/aptos/aptos-processor.ts +7 -10
- package/src/aptos/context.ts +3 -3
- package/src/aptos/index.ts +3 -2
- package/src/aptos/models.ts +34 -0
- package/src/aptos/type-registry.ts +187 -0
- package/src/aptos/types.ts +53 -199
- package/src/aptos/utils.ts +0 -9
- package/src/aptos-codegen/codegen.ts +2 -1
- package/src/aptos-codegen/typegen.ts +1 -67
- package/src/cli/upload.ts +2 -1
- package/src/core/base-context.ts +28 -0
- package/src/core/base-processor.ts +1 -2
- package/src/core/context.ts +2 -26
- package/src/core/event-tracker.ts +2 -2
- package/src/core/exporter.ts +1 -1
- package/src/core/logger.ts +1 -1
- package/src/core/meter.ts +1 -1
- package/src/endpoints.ts +9 -0
- package/src/gen/google/protobuf/timestamp.ts +105 -0
- package/src/gen/service/price/protos/price.ts +394 -0
- package/src/processor-runner.ts +6 -0
- package/src/processor-state.ts +2 -7
- package/src/provider.ts +5 -5
- package/src/testing/test-processor-server.ts +10 -6
- package/src/utils/conversion.ts +2 -1
- package/src/utils/price.ts +58 -0
- package/src/utils/token.ts +1 -1
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
import { CallContext, CallOptions } from "nice-grpc-common";
|
|
3
|
+
import { Timestamp } from "../../../google/protobuf/timestamp";
|
|
4
|
+
import Long from "long";
|
|
5
|
+
import _m0 from "protobufjs/minimal";
|
|
6
|
+
|
|
7
|
+
export interface CoinID {
|
|
8
|
+
symbol: string | undefined;
|
|
9
|
+
address: CoinID_AddressIdentifier | undefined;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface CoinID_AddressIdentifier {
|
|
13
|
+
address: string;
|
|
14
|
+
chain: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface GetPriceRequest {
|
|
18
|
+
timestamp: Date | undefined;
|
|
19
|
+
coinId: CoinID | undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface GetPriceResponse {
|
|
23
|
+
price: number;
|
|
24
|
+
timestamp: Date | undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function createBaseCoinID(): CoinID {
|
|
28
|
+
return { symbol: undefined, address: undefined };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const CoinID = {
|
|
32
|
+
encode(
|
|
33
|
+
message: CoinID,
|
|
34
|
+
writer: _m0.Writer = _m0.Writer.create()
|
|
35
|
+
): _m0.Writer {
|
|
36
|
+
if (message.symbol !== undefined) {
|
|
37
|
+
writer.uint32(18).string(message.symbol);
|
|
38
|
+
}
|
|
39
|
+
if (message.address !== undefined) {
|
|
40
|
+
CoinID_AddressIdentifier.encode(
|
|
41
|
+
message.address,
|
|
42
|
+
writer.uint32(26).fork()
|
|
43
|
+
).ldelim();
|
|
44
|
+
}
|
|
45
|
+
return writer;
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): CoinID {
|
|
49
|
+
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
|
|
50
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
51
|
+
const message = createBaseCoinID();
|
|
52
|
+
while (reader.pos < end) {
|
|
53
|
+
const tag = reader.uint32();
|
|
54
|
+
switch (tag >>> 3) {
|
|
55
|
+
case 2:
|
|
56
|
+
message.symbol = reader.string();
|
|
57
|
+
break;
|
|
58
|
+
case 3:
|
|
59
|
+
message.address = CoinID_AddressIdentifier.decode(
|
|
60
|
+
reader,
|
|
61
|
+
reader.uint32()
|
|
62
|
+
);
|
|
63
|
+
break;
|
|
64
|
+
default:
|
|
65
|
+
reader.skipType(tag & 7);
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return message;
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
fromJSON(object: any): CoinID {
|
|
73
|
+
return {
|
|
74
|
+
symbol: isSet(object.symbol) ? String(object.symbol) : undefined,
|
|
75
|
+
address: isSet(object.address)
|
|
76
|
+
? CoinID_AddressIdentifier.fromJSON(object.address)
|
|
77
|
+
: undefined,
|
|
78
|
+
};
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
toJSON(message: CoinID): unknown {
|
|
82
|
+
const obj: any = {};
|
|
83
|
+
message.symbol !== undefined && (obj.symbol = message.symbol);
|
|
84
|
+
message.address !== undefined &&
|
|
85
|
+
(obj.address = message.address
|
|
86
|
+
? CoinID_AddressIdentifier.toJSON(message.address)
|
|
87
|
+
: undefined);
|
|
88
|
+
return obj;
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
fromPartial(object: DeepPartial<CoinID>): CoinID {
|
|
92
|
+
const message = createBaseCoinID();
|
|
93
|
+
message.symbol = object.symbol ?? undefined;
|
|
94
|
+
message.address =
|
|
95
|
+
object.address !== undefined && object.address !== null
|
|
96
|
+
? CoinID_AddressIdentifier.fromPartial(object.address)
|
|
97
|
+
: undefined;
|
|
98
|
+
return message;
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
function createBaseCoinID_AddressIdentifier(): CoinID_AddressIdentifier {
|
|
103
|
+
return { address: "", chain: "" };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export const CoinID_AddressIdentifier = {
|
|
107
|
+
encode(
|
|
108
|
+
message: CoinID_AddressIdentifier,
|
|
109
|
+
writer: _m0.Writer = _m0.Writer.create()
|
|
110
|
+
): _m0.Writer {
|
|
111
|
+
if (message.address !== "") {
|
|
112
|
+
writer.uint32(10).string(message.address);
|
|
113
|
+
}
|
|
114
|
+
if (message.chain !== "") {
|
|
115
|
+
writer.uint32(18).string(message.chain);
|
|
116
|
+
}
|
|
117
|
+
return writer;
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
decode(
|
|
121
|
+
input: _m0.Reader | Uint8Array,
|
|
122
|
+
length?: number
|
|
123
|
+
): CoinID_AddressIdentifier {
|
|
124
|
+
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
|
|
125
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
126
|
+
const message = createBaseCoinID_AddressIdentifier();
|
|
127
|
+
while (reader.pos < end) {
|
|
128
|
+
const tag = reader.uint32();
|
|
129
|
+
switch (tag >>> 3) {
|
|
130
|
+
case 1:
|
|
131
|
+
message.address = reader.string();
|
|
132
|
+
break;
|
|
133
|
+
case 2:
|
|
134
|
+
message.chain = reader.string();
|
|
135
|
+
break;
|
|
136
|
+
default:
|
|
137
|
+
reader.skipType(tag & 7);
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return message;
|
|
142
|
+
},
|
|
143
|
+
|
|
144
|
+
fromJSON(object: any): CoinID_AddressIdentifier {
|
|
145
|
+
return {
|
|
146
|
+
address: isSet(object.address) ? String(object.address) : "",
|
|
147
|
+
chain: isSet(object.chain) ? String(object.chain) : "",
|
|
148
|
+
};
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
toJSON(message: CoinID_AddressIdentifier): unknown {
|
|
152
|
+
const obj: any = {};
|
|
153
|
+
message.address !== undefined && (obj.address = message.address);
|
|
154
|
+
message.chain !== undefined && (obj.chain = message.chain);
|
|
155
|
+
return obj;
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
fromPartial(
|
|
159
|
+
object: DeepPartial<CoinID_AddressIdentifier>
|
|
160
|
+
): CoinID_AddressIdentifier {
|
|
161
|
+
const message = createBaseCoinID_AddressIdentifier();
|
|
162
|
+
message.address = object.address ?? "";
|
|
163
|
+
message.chain = object.chain ?? "";
|
|
164
|
+
return message;
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
function createBaseGetPriceRequest(): GetPriceRequest {
|
|
169
|
+
return { timestamp: undefined, coinId: undefined };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export const GetPriceRequest = {
|
|
173
|
+
encode(
|
|
174
|
+
message: GetPriceRequest,
|
|
175
|
+
writer: _m0.Writer = _m0.Writer.create()
|
|
176
|
+
): _m0.Writer {
|
|
177
|
+
if (message.timestamp !== undefined) {
|
|
178
|
+
Timestamp.encode(
|
|
179
|
+
toTimestamp(message.timestamp),
|
|
180
|
+
writer.uint32(10).fork()
|
|
181
|
+
).ldelim();
|
|
182
|
+
}
|
|
183
|
+
if (message.coinId !== undefined) {
|
|
184
|
+
CoinID.encode(message.coinId, writer.uint32(18).fork()).ldelim();
|
|
185
|
+
}
|
|
186
|
+
return writer;
|
|
187
|
+
},
|
|
188
|
+
|
|
189
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): GetPriceRequest {
|
|
190
|
+
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
|
|
191
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
192
|
+
const message = createBaseGetPriceRequest();
|
|
193
|
+
while (reader.pos < end) {
|
|
194
|
+
const tag = reader.uint32();
|
|
195
|
+
switch (tag >>> 3) {
|
|
196
|
+
case 1:
|
|
197
|
+
message.timestamp = fromTimestamp(
|
|
198
|
+
Timestamp.decode(reader, reader.uint32())
|
|
199
|
+
);
|
|
200
|
+
break;
|
|
201
|
+
case 2:
|
|
202
|
+
message.coinId = CoinID.decode(reader, reader.uint32());
|
|
203
|
+
break;
|
|
204
|
+
default:
|
|
205
|
+
reader.skipType(tag & 7);
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return message;
|
|
210
|
+
},
|
|
211
|
+
|
|
212
|
+
fromJSON(object: any): GetPriceRequest {
|
|
213
|
+
return {
|
|
214
|
+
timestamp: isSet(object.timestamp)
|
|
215
|
+
? fromJsonTimestamp(object.timestamp)
|
|
216
|
+
: undefined,
|
|
217
|
+
coinId: isSet(object.coinId) ? CoinID.fromJSON(object.coinId) : undefined,
|
|
218
|
+
};
|
|
219
|
+
},
|
|
220
|
+
|
|
221
|
+
toJSON(message: GetPriceRequest): unknown {
|
|
222
|
+
const obj: any = {};
|
|
223
|
+
message.timestamp !== undefined &&
|
|
224
|
+
(obj.timestamp = message.timestamp.toISOString());
|
|
225
|
+
message.coinId !== undefined &&
|
|
226
|
+
(obj.coinId = message.coinId ? CoinID.toJSON(message.coinId) : undefined);
|
|
227
|
+
return obj;
|
|
228
|
+
},
|
|
229
|
+
|
|
230
|
+
fromPartial(object: DeepPartial<GetPriceRequest>): GetPriceRequest {
|
|
231
|
+
const message = createBaseGetPriceRequest();
|
|
232
|
+
message.timestamp = object.timestamp ?? undefined;
|
|
233
|
+
message.coinId =
|
|
234
|
+
object.coinId !== undefined && object.coinId !== null
|
|
235
|
+
? CoinID.fromPartial(object.coinId)
|
|
236
|
+
: undefined;
|
|
237
|
+
return message;
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
function createBaseGetPriceResponse(): GetPriceResponse {
|
|
242
|
+
return { price: 0, timestamp: undefined };
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export const GetPriceResponse = {
|
|
246
|
+
encode(
|
|
247
|
+
message: GetPriceResponse,
|
|
248
|
+
writer: _m0.Writer = _m0.Writer.create()
|
|
249
|
+
): _m0.Writer {
|
|
250
|
+
if (message.price !== 0) {
|
|
251
|
+
writer.uint32(9).double(message.price);
|
|
252
|
+
}
|
|
253
|
+
if (message.timestamp !== undefined) {
|
|
254
|
+
Timestamp.encode(
|
|
255
|
+
toTimestamp(message.timestamp),
|
|
256
|
+
writer.uint32(18).fork()
|
|
257
|
+
).ldelim();
|
|
258
|
+
}
|
|
259
|
+
return writer;
|
|
260
|
+
},
|
|
261
|
+
|
|
262
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): GetPriceResponse {
|
|
263
|
+
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
|
|
264
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
265
|
+
const message = createBaseGetPriceResponse();
|
|
266
|
+
while (reader.pos < end) {
|
|
267
|
+
const tag = reader.uint32();
|
|
268
|
+
switch (tag >>> 3) {
|
|
269
|
+
case 1:
|
|
270
|
+
message.price = reader.double();
|
|
271
|
+
break;
|
|
272
|
+
case 2:
|
|
273
|
+
message.timestamp = fromTimestamp(
|
|
274
|
+
Timestamp.decode(reader, reader.uint32())
|
|
275
|
+
);
|
|
276
|
+
break;
|
|
277
|
+
default:
|
|
278
|
+
reader.skipType(tag & 7);
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return message;
|
|
283
|
+
},
|
|
284
|
+
|
|
285
|
+
fromJSON(object: any): GetPriceResponse {
|
|
286
|
+
return {
|
|
287
|
+
price: isSet(object.price) ? Number(object.price) : 0,
|
|
288
|
+
timestamp: isSet(object.timestamp)
|
|
289
|
+
? fromJsonTimestamp(object.timestamp)
|
|
290
|
+
: undefined,
|
|
291
|
+
};
|
|
292
|
+
},
|
|
293
|
+
|
|
294
|
+
toJSON(message: GetPriceResponse): unknown {
|
|
295
|
+
const obj: any = {};
|
|
296
|
+
message.price !== undefined && (obj.price = message.price);
|
|
297
|
+
message.timestamp !== undefined &&
|
|
298
|
+
(obj.timestamp = message.timestamp.toISOString());
|
|
299
|
+
return obj;
|
|
300
|
+
},
|
|
301
|
+
|
|
302
|
+
fromPartial(object: DeepPartial<GetPriceResponse>): GetPriceResponse {
|
|
303
|
+
const message = createBaseGetPriceResponse();
|
|
304
|
+
message.price = object.price ?? 0;
|
|
305
|
+
message.timestamp = object.timestamp ?? undefined;
|
|
306
|
+
return message;
|
|
307
|
+
},
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
export type PriceServiceDefinition = typeof PriceServiceDefinition;
|
|
311
|
+
export const PriceServiceDefinition = {
|
|
312
|
+
name: "PriceService",
|
|
313
|
+
fullName: "price_service.PriceService",
|
|
314
|
+
methods: {
|
|
315
|
+
getPrice: {
|
|
316
|
+
name: "GetPrice",
|
|
317
|
+
requestType: GetPriceRequest,
|
|
318
|
+
requestStream: false,
|
|
319
|
+
responseType: GetPriceResponse,
|
|
320
|
+
responseStream: false,
|
|
321
|
+
options: {},
|
|
322
|
+
},
|
|
323
|
+
},
|
|
324
|
+
} as const;
|
|
325
|
+
|
|
326
|
+
export interface PriceServiceServiceImplementation<CallContextExt = {}> {
|
|
327
|
+
getPrice(
|
|
328
|
+
request: GetPriceRequest,
|
|
329
|
+
context: CallContext & CallContextExt
|
|
330
|
+
): Promise<DeepPartial<GetPriceResponse>>;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export interface PriceServiceClient<CallOptionsExt = {}> {
|
|
334
|
+
getPrice(
|
|
335
|
+
request: DeepPartial<GetPriceRequest>,
|
|
336
|
+
options?: CallOptions & CallOptionsExt
|
|
337
|
+
): Promise<GetPriceResponse>;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
type Builtin =
|
|
341
|
+
| Date
|
|
342
|
+
| Function
|
|
343
|
+
| Uint8Array
|
|
344
|
+
| string
|
|
345
|
+
| number
|
|
346
|
+
| boolean
|
|
347
|
+
| undefined;
|
|
348
|
+
|
|
349
|
+
type DeepPartial<T> = T extends Builtin
|
|
350
|
+
? T
|
|
351
|
+
: T extends Long
|
|
352
|
+
? string | number | Long
|
|
353
|
+
: T extends Array<infer U>
|
|
354
|
+
? Array<DeepPartial<U>>
|
|
355
|
+
: T extends ReadonlyArray<infer U>
|
|
356
|
+
? ReadonlyArray<DeepPartial<U>>
|
|
357
|
+
: T extends {}
|
|
358
|
+
? { [K in keyof T]?: DeepPartial<T[K]> }
|
|
359
|
+
: Partial<T>;
|
|
360
|
+
|
|
361
|
+
function toTimestamp(date: Date): Timestamp {
|
|
362
|
+
const seconds = numberToLong(date.getTime() / 1_000);
|
|
363
|
+
const nanos = (date.getTime() % 1_000) * 1_000_000;
|
|
364
|
+
return { seconds, nanos };
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function fromTimestamp(t: Timestamp): Date {
|
|
368
|
+
let millis = t.seconds.toNumber() * 1_000;
|
|
369
|
+
millis += t.nanos / 1_000_000;
|
|
370
|
+
return new Date(millis);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
function fromJsonTimestamp(o: any): Date {
|
|
374
|
+
if (o instanceof Date) {
|
|
375
|
+
return o;
|
|
376
|
+
} else if (typeof o === "string") {
|
|
377
|
+
return new Date(o);
|
|
378
|
+
} else {
|
|
379
|
+
return fromTimestamp(Timestamp.fromJSON(o));
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function numberToLong(number: number) {
|
|
384
|
+
return Long.fromNumber(number);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if (_m0.util.Long !== Long) {
|
|
388
|
+
_m0.util.Long = Long as any;
|
|
389
|
+
_m0.configure();
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function isSet(value: any): boolean {
|
|
393
|
+
return value !== null && value !== undefined;
|
|
394
|
+
}
|
package/src/processor-runner.ts
CHANGED
|
@@ -11,8 +11,10 @@ import fs from 'fs-extra'
|
|
|
11
11
|
import { ProcessorState } from './processor-state'
|
|
12
12
|
import { load } from './loader'
|
|
13
13
|
import { CompressionAlgorithms } from '@grpc/grpc-js/build/src/compression-algorithms'
|
|
14
|
+
import { Endpoints } from './endpoints'
|
|
14
15
|
|
|
15
16
|
global.PROCESSOR_STATE = new ProcessorState()
|
|
17
|
+
global.ENDPOINTS = new Endpoints()
|
|
16
18
|
|
|
17
19
|
const optionDefinitions = [
|
|
18
20
|
{ name: 'target', type: String, defaultOption: true },
|
|
@@ -25,6 +27,8 @@ const optionDefinitions = [
|
|
|
25
27
|
type: String,
|
|
26
28
|
defaultValue: 'chains-config.json',
|
|
27
29
|
},
|
|
30
|
+
{ name: 'chainquery-server', type: String, defaultValue: '' },
|
|
31
|
+
{ name: 'pricefeed-server', type: String, defaultValue: '' },
|
|
28
32
|
]
|
|
29
33
|
|
|
30
34
|
const options = commandLineArgs(optionDefinitions, { partial: true })
|
|
@@ -35,6 +39,8 @@ const fullPath = path.resolve(options['chains-config'])
|
|
|
35
39
|
const chainsConfig = fs.readJsonSync(fullPath)
|
|
36
40
|
|
|
37
41
|
setProvider(chainsConfig, options.concurrency, options['use-chainserver'])
|
|
42
|
+
globalThis.ENDPOINTS.chainQueryAPI = options['chainquery-server']
|
|
43
|
+
globalThis.ENDPOINTS.priceFeedAPI = options['pricefeed-server']
|
|
38
44
|
|
|
39
45
|
console.log('Start Server', options)
|
|
40
46
|
|
package/src/processor-state.ts
CHANGED
|
@@ -5,17 +5,14 @@ import {
|
|
|
5
5
|
BaseProcessorTemplate,
|
|
6
6
|
SolanaBaseProcessor,
|
|
7
7
|
SuiBaseProcessor,
|
|
8
|
+
EventTracker,
|
|
8
9
|
} from './core'
|
|
9
10
|
|
|
10
|
-
import { AptosBaseProcessor } from './aptos'
|
|
11
|
-
|
|
12
11
|
import { BaseContract } from 'ethers'
|
|
13
12
|
import { TemplateInstance } from './gen'
|
|
14
|
-
import { Provider } from '@ethersproject/providers'
|
|
15
|
-
import { EventTracker } from './core'
|
|
16
13
|
import { Metric } from './core/meter'
|
|
17
|
-
import { AptosAccountProcessor } from './aptos/aptos-processor'
|
|
18
14
|
import { Exporter } from './core/exporter'
|
|
15
|
+
import { AptosBaseProcessor, AptosAccountProcessor } from './aptos/aptos-processor'
|
|
19
16
|
|
|
20
17
|
export class ProcessorState {
|
|
21
18
|
// from abiName_address_chainId => contract wrapper
|
|
@@ -24,8 +21,6 @@ export class ProcessorState {
|
|
|
24
21
|
processors: BaseProcessor<BaseContract, BoundContractView<BaseContract, any>>[] = []
|
|
25
22
|
// from abiName_options to contracts
|
|
26
23
|
processorMap = new Map<string, BaseProcessor<any, any>>()
|
|
27
|
-
// evm providers
|
|
28
|
-
providers = new Map<number, Provider>()
|
|
29
24
|
// evm processor templates
|
|
30
25
|
templates: BaseProcessorTemplate<BaseContract, BoundContractView<BaseContract, any>>[] = []
|
|
31
26
|
// evm processor template instances spec
|
package/src/provider.ts
CHANGED
|
@@ -12,23 +12,23 @@ export function getProvider(networkish?: Networkish): Provider {
|
|
|
12
12
|
}
|
|
13
13
|
const network = getNetwork(networkish)
|
|
14
14
|
|
|
15
|
-
if (!global.
|
|
15
|
+
if (!global.ENDPOINTS.providers) {
|
|
16
16
|
throw Error('Provider not set')
|
|
17
17
|
}
|
|
18
|
-
const value = global.
|
|
18
|
+
const value = global.ENDPOINTS.providers.get(network.chainId)
|
|
19
19
|
if (value === undefined) {
|
|
20
20
|
throw Error(
|
|
21
21
|
'Provider not found for chain ' +
|
|
22
22
|
network.chainId +
|
|
23
23
|
', configured chains: ' +
|
|
24
|
-
[...global.
|
|
24
|
+
[...global.ENDPOINTS.providers.keys()].join(' ')
|
|
25
25
|
)
|
|
26
26
|
}
|
|
27
27
|
return value
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export function setProvider(config: Record<string, ChainConfig>, concurrency = 4, useChainServer = false) {
|
|
31
|
-
|
|
31
|
+
globalThis.ENDPOINTS.providers = new Map<number, Provider>()
|
|
32
32
|
|
|
33
33
|
for (const chainIdStr in config) {
|
|
34
34
|
if (isNaN(Number.parseInt(chainIdStr))) {
|
|
@@ -56,7 +56,7 @@ export function setProvider(config: Record<string, ChainConfig>, concurrency = 4
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
const provider = new QueuedStaticJsonRpcProvider(rpcAddress, chainId, concurrency)
|
|
59
|
-
global.
|
|
59
|
+
global.ENDPOINTS.providers.set(chainId, provider)
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
|
|
@@ -9,14 +9,10 @@ import {
|
|
|
9
9
|
ProcessConfigRequest,
|
|
10
10
|
ProcessConfigResponse,
|
|
11
11
|
ProcessInstructionsRequest,
|
|
12
|
-
ProcessorServiceImpl,
|
|
13
12
|
ProcessorServiceImplementation,
|
|
14
|
-
ProcessorState,
|
|
15
13
|
ProcessTransactionsRequest,
|
|
16
|
-
setProvider,
|
|
17
14
|
StartRequest,
|
|
18
|
-
|
|
19
|
-
} from '@sentio/sdk'
|
|
15
|
+
} from '../gen'
|
|
20
16
|
import { CallContext } from 'nice-grpc-common'
|
|
21
17
|
import { Empty } from '../gen/google/protobuf/empty'
|
|
22
18
|
import { ChainConfig } from '../chain-config'
|
|
@@ -24,11 +20,19 @@ import { CHAIN_MAP } from '../utils/chain'
|
|
|
24
20
|
import { Block, Log } from '@ethersproject/abstract-provider'
|
|
25
21
|
import Long from 'long'
|
|
26
22
|
import { getNetwork, Networkish } from '@ethersproject/providers'
|
|
23
|
+
import { Endpoints } from '../endpoints'
|
|
24
|
+
import { ProcessorState } from '../processor-state'
|
|
25
|
+
import { ProcessorServiceImpl } from '../service'
|
|
26
|
+
import { Trace } from '../core/trace'
|
|
27
|
+
import { setProvider } from '../provider'
|
|
27
28
|
|
|
28
29
|
export const TEST_CONTEXT: CallContext = <CallContext>{}
|
|
29
30
|
|
|
30
|
-
function cleanTest() {
|
|
31
|
+
export function cleanTest() {
|
|
31
32
|
global.PROCESSOR_STATE = new ProcessorState()
|
|
33
|
+
if (!global.ENDPOINTS) {
|
|
34
|
+
global.ENDPOINTS = new Endpoints()
|
|
35
|
+
}
|
|
32
36
|
}
|
|
33
37
|
|
|
34
38
|
export class TestProcessorServer implements ProcessorServiceImplementation {
|
package/src/utils/conversion.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BigNumber } from 'ethers'
|
|
2
|
-
import { BigDecimal
|
|
2
|
+
import { BigDecimal } from '../core/big-decimal'
|
|
3
3
|
import { Numberish } from '../core'
|
|
4
|
+
import { MetricValue } from '../gen'
|
|
4
5
|
|
|
5
6
|
export function toBigDecimal(n: BigNumber | bigint) {
|
|
6
7
|
return new BigDecimal(n.toString())
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { PriceServiceClient, PriceServiceDefinition } from '../gen/service/price/protos/price'
|
|
2
|
+
import { createChannel, createClient } from 'nice-grpc'
|
|
3
|
+
|
|
4
|
+
export function getPriceClient(address?: string): PriceServiceClient {
|
|
5
|
+
if (!address) {
|
|
6
|
+
address = global.ENDPOINTS.priceFeedAPI
|
|
7
|
+
}
|
|
8
|
+
const channel = createChannel(address)
|
|
9
|
+
|
|
10
|
+
return createClient(PriceServiceDefinition, channel)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const priceMap = new Map<string, number>()
|
|
14
|
+
let priceClient: PriceServiceClient
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* @param chainId chain id refers to CHAIN_MAP
|
|
19
|
+
* @param coinType
|
|
20
|
+
* @param date
|
|
21
|
+
*/
|
|
22
|
+
export async function getPriceByType(chainId: string, coinType: string, date: Date): Promise<number> {
|
|
23
|
+
if (!priceClient) {
|
|
24
|
+
priceClient = getPriceClient()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const dateStr = [date.getUTCDate(), date.getUTCMonth() + 1, date.getUTCFullYear()].join('-')
|
|
28
|
+
const key = `${coinType}-${dateStr}`
|
|
29
|
+
const price = priceMap.get(key)
|
|
30
|
+
if (price) {
|
|
31
|
+
return price
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/*eslint no-constant-condition: ["error", { "checkLoops": false }]*/
|
|
35
|
+
while (true) {
|
|
36
|
+
try {
|
|
37
|
+
const response = await priceClient.getPrice({
|
|
38
|
+
timestamp: date,
|
|
39
|
+
coinId: {
|
|
40
|
+
address: {
|
|
41
|
+
chain: chainId,
|
|
42
|
+
address: coinType,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
})
|
|
46
|
+
const price = response.price
|
|
47
|
+
priceMap.set(key, price)
|
|
48
|
+
return price
|
|
49
|
+
} catch (e) {
|
|
50
|
+
console.log('error getting price', e, dateStr, coinType)
|
|
51
|
+
await delay(1000)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function delay(ms: number) {
|
|
57
|
+
return new Promise((resolve) => setTimeout(resolve, ms))
|
|
58
|
+
}
|
package/src/utils/token.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { BigNumber } from '@ethersproject/bignumber'
|
|
|
3
3
|
import { transformEtherError } from '../error'
|
|
4
4
|
import { getERC20Contract } from '../builtin/erc20'
|
|
5
5
|
import { getERC20BytesContract } from '../builtin/internal/erc20bytes_processor'
|
|
6
|
-
import { BigDecimal } from '
|
|
6
|
+
import { BigDecimal } from '../core/big-decimal'
|
|
7
7
|
import { toBigDecimal } from './conversion'
|
|
8
8
|
import { utils } from 'ethers'
|
|
9
9
|
|