@defillama/sdk 5.0.242 → 5.0.245

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.
@@ -0,0 +1,485 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ var _a;
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.INDEXER_METHOD = exports.MAX_HOSTS_PER_RUN = exports.DEFAULT_MIN_CALLS = exports.OTHER_CHAIN = exports.ES_HOST_INDEX = exports.ES_INDEX = void 0;
8
+ exports.registerEndpoints = registerEndpoints;
9
+ exports.resolveChain = resolveChain;
10
+ exports.ignoreHost = ignoreHost;
11
+ exports.recordMethod = recordMethod;
12
+ exports.recordLogs = recordLogs;
13
+ exports.install = install;
14
+ exports.getCurrent = getCurrent;
15
+ exports.snapshot = snapshot;
16
+ exports.mergeSnapshots = mergeSnapshots;
17
+ exports.run = run;
18
+ exports.flushActive = flushActive;
19
+ exports.getMinCalls = getMinCalls;
20
+ exports.buildDocs = buildDocs;
21
+ exports.report = report;
22
+ /**
23
+ * Per-run counters for every outbound HTTP request a process makes, attributed to a chain
24
+ * and to the adapter run that made them, and flushed to Elasticsearch when the run ends.
25
+ *
26
+ * What gets written (see `buildDocs`)
27
+ * - `adapter-calls`: one flat doc per (run, chain) carrying the run's meta (application, name, runType...),
28
+ * `chain`, `calls` (rpc http requests), `getLogs` (rpc getLogs attempts), `indexerCalls` (http requests to
29
+ * the llama indexer for that chain), `logs` / `logsRpc` / `logsIndexer` (log rows fetched over the wire),
30
+ * `methods.*`, the run totals (`runCalls`, `runGetLogs`, `runLogs`), `success`, `runtime` and a shared
31
+ * `runId`. Requests matching no registered rpc go to `chain: "_other"`. Nothing is dropped, so a terms
32
+ * aggregation on `chain` or `name` over any time range is exact.
33
+ * - `adapter-call-hosts`: one doc per (run, host) for the 25 busiest hosts of the run, same base fields
34
+ * plus `host` and `rpc` (true when the host is a registered rpc endpoint).
35
+ * Both carry `@timestamp` (ISO) so Kibana picks it up as the time field with no index template.
36
+ *
37
+ * How it works
38
+ * - `install()` wraps `http.request` / `http.get` / `https.request` / `https.get` and subscribes to
39
+ * the `undici:request:create` diagnostics channel (global `fetch`). That catches axios, ethers,
40
+ * @solana/web3.js, graphql-request, raw fetch... without touching any call site.
41
+ * - The SDK registers the RPC urls it resolves for a chain (`registerEndpoints`, called from
42
+ * LlamaProvider and the `chains/*` endpoint resolvers). A request whose url starts with a
43
+ * registered endpoint is counted against that chain, everything else against its host only.
44
+ * - `run(meta, fn)` executes `fn` inside an AsyncLocalStorage context, so concurrent adapter runs
45
+ * in one process (the server's pooled children) each get their own counters.
46
+ *
47
+ * All state lives on `globalThis` under a well-known symbol: when two copies of the SDK are loaded
48
+ * (server's node_modules + the adapters repo's node_modules) they share one hook, one endpoint
49
+ * registry and one context, and nothing is counted twice.
50
+ */
51
+ const async_hooks_1 = require("async_hooks");
52
+ const crypto_1 = __importDefault(require("crypto"));
53
+ const http_1 = __importDefault(require("http"));
54
+ const https_1 = __importDefault(require("https"));
55
+ const diagnostics_channel_1 = __importDefault(require("diagnostics_channel"));
56
+ const elastic_1 = require("./elastic");
57
+ const debugLog_1 = require("./debugLog");
58
+ const env_1 = require("./env");
59
+ /** one doc per (run, chain) */
60
+ exports.ES_INDEX = 'adapter-calls';
61
+ /** one doc per (run, host) */
62
+ exports.ES_HOST_INDEX = 'adapter-call-hosts';
63
+ /** `chain` of the doc counting requests that matched no registered rpc endpoint */
64
+ exports.OTHER_CHAIN = '_other';
65
+ /** runs with fewer http requests in total are not written at all (env CALL_STATS_MIN_CALLS) */
66
+ exports.DEFAULT_MIN_CALLS = 1;
67
+ exports.MAX_HOSTS_PER_RUN = 25;
68
+ exports.INDEXER_METHOD = 'indexer';
69
+ const STATE_KEY = Symbol.for('@defillama/sdk/callStats');
70
+ function newStats(meta) {
71
+ return { meta, startTime: Date.now(), total: 0, byChain: {}, byHost: {}, unattributed: 0, byMethod: {}, logs: { rpc: {}, indexer: {} } };
72
+ }
73
+ const shared = (_a = globalThis[STATE_KEY]) !== null && _a !== void 0 ? _a : (globalThis[STATE_KEY] = {
74
+ als: new async_hooks_1.AsyncLocalStorage(),
75
+ installed: false,
76
+ endpoints: new Map(),
77
+ global: newStats({ application: 'global', name: '-' }),
78
+ ignoredHosts: new Set(),
79
+ registered: new Set(),
80
+ active: new Set(),
81
+ });
82
+ // the state may have been created by an older sdk copy that did not track active runs
83
+ if (!shared.active)
84
+ shared.active = new Set();
85
+ // ---------------------------------------------------------------------------
86
+ // endpoint registry
87
+ // ---------------------------------------------------------------------------
88
+ function parseUrl(url) {
89
+ try {
90
+ const u = new URL(url);
91
+ if (u.protocol !== 'http:' && u.protocol !== 'https:')
92
+ return;
93
+ return { host: u.host.toLowerCase(), path: u.pathname.replace(/\/+$/, '') };
94
+ }
95
+ catch {
96
+ return;
97
+ }
98
+ }
99
+ /**
100
+ * Remember that `endpoints` serve `chain`, so requests to them are counted against that chain.
101
+ * Called by the SDK wherever it resolves rpc urls; adapters can call it for endpoints they manage themselves.
102
+ */
103
+ function registerEndpoints(chain, endpoints) {
104
+ if (!chain || !endpoints)
105
+ return;
106
+ chain = chain.toLowerCase();
107
+ // callers pass the same list on every request: skip the url parsing after the first time
108
+ const key = chain + '|' + (Array.isArray(endpoints) ? endpoints.join(',') : endpoints);
109
+ if (shared.registered.has(key))
110
+ return;
111
+ shared.registered.add(key);
112
+ const list = Array.isArray(endpoints) ? endpoints : endpoints.split(',');
113
+ for (const raw of list) {
114
+ const parsed = parseUrl(String(raw).trim());
115
+ if (!parsed)
116
+ continue;
117
+ let entries = shared.endpoints.get(parsed.host);
118
+ if (!entries) {
119
+ entries = [];
120
+ shared.endpoints.set(parsed.host, entries);
121
+ }
122
+ if (entries.some(e => e.path === parsed.path && e.chain === chain))
123
+ continue;
124
+ entries.push({ path: parsed.path, chain });
125
+ entries.sort((a, b) => b.path.length - a.path.length);
126
+ }
127
+ }
128
+ /** Chain a url is counted against, or undefined when it matches no registered endpoint. */
129
+ function resolveChain(url) {
130
+ const parsed = parseUrl(url);
131
+ if (!parsed)
132
+ return;
133
+ const entries = shared.endpoints.get(parsed.host);
134
+ if (!entries)
135
+ return;
136
+ for (const entry of entries) {
137
+ if (!entry.path || parsed.path === entry.path || parsed.path.startsWith(entry.path + '/'))
138
+ return entry.chain;
139
+ }
140
+ }
141
+ /** Requests to these hosts are not counted (eg. the elasticsearch cluster the stats are written to). */
142
+ function ignoreHost(url) {
143
+ const parsed = parseUrl(url);
144
+ if (parsed)
145
+ shared.ignoredHosts.add(parsed.host);
146
+ }
147
+ // ---------------------------------------------------------------------------
148
+ // recording
149
+ // ---------------------------------------------------------------------------
150
+ function record(url) {
151
+ var _a, _b, _c;
152
+ const parsed = parseUrl(url);
153
+ if (!parsed || shared.ignoredHosts.has(parsed.host))
154
+ return;
155
+ const stats = (_a = shared.als.getStore()) !== null && _a !== void 0 ? _a : shared.global;
156
+ stats.total++;
157
+ stats.byHost[parsed.host] = ((_b = stats.byHost[parsed.host]) !== null && _b !== void 0 ? _b : 0) + 1;
158
+ const chain = resolveChain(url);
159
+ if (chain)
160
+ stats.byChain[chain] = ((_c = stats.byChain[chain]) !== null && _c !== void 0 ? _c : 0) + 1;
161
+ else
162
+ stats.unattributed++;
163
+ }
164
+ /**
165
+ * Count a logical rpc request (one attempt, so retries count) against `method` and `chain` in the current run.
166
+ * The http layer already counts the request itself; this adds the method breakdown (getLogs being the one that matters).
167
+ */
168
+ function recordMethod(method, chain = exports.OTHER_CHAIN) {
169
+ var _a, _b, _c;
170
+ const stats = (_a = shared.als.getStore()) !== null && _a !== void 0 ? _a : shared.global;
171
+ const byChain = (_b = stats.byMethod[method]) !== null && _b !== void 0 ? _b : (stats.byMethod[method] = {});
172
+ chain = chain.toLowerCase();
173
+ byChain[chain] = ((_c = byChain[chain]) !== null && _c !== void 0 ? _c : 0) + 1;
174
+ }
175
+ /** Count `count` log rows fetched from `source` for `chain` in the current run (rows received, cached reads are not fetched). */
176
+ function recordLogs(source, chain = exports.OTHER_CHAIN, count) {
177
+ var _a, _b, _c;
178
+ if (!(count > 0))
179
+ return;
180
+ const stats = (_a = shared.als.getStore()) !== null && _a !== void 0 ? _a : shared.global;
181
+ const byChain = (_b = stats.logs[source]) !== null && _b !== void 0 ? _b : (stats.logs[source] = {});
182
+ chain = chain.toLowerCase();
183
+ byChain[chain] = ((_c = byChain[chain]) !== null && _c !== void 0 ? _c : 0) + count;
184
+ }
185
+ function sumValues(map) {
186
+ return Object.values(map !== null && map !== void 0 ? map : {}).reduce((a, b) => a + b, 0);
187
+ }
188
+ function getLogsCount(stats, chain) {
189
+ var _a, _b, _c;
190
+ const byChain = (_b = (_a = stats.byMethod) === null || _a === void 0 ? void 0 : _a.getLogs) !== null && _b !== void 0 ? _b : {};
191
+ if (chain)
192
+ return (_c = byChain[chain]) !== null && _c !== void 0 ? _c : 0;
193
+ return sumValues(byChain);
194
+ }
195
+ function logsFetched(stats, source, chain) {
196
+ var _a, _b, _c;
197
+ const byChain = (_b = (_a = stats.logs) === null || _a === void 0 ? void 0 : _a[source]) !== null && _b !== void 0 ? _b : {};
198
+ if (chain)
199
+ return (_c = byChain[chain]) !== null && _c !== void 0 ? _c : 0;
200
+ return sumValues(byChain);
201
+ }
202
+ /** method -> requests across chains */
203
+ function methodTotals(stats) {
204
+ var _a;
205
+ const out = {};
206
+ for (const [method, byChain] of Object.entries((_a = stats.byMethod) !== null && _a !== void 0 ? _a : {}))
207
+ out[method] = Object.values(byChain).reduce((a, b) => a + b, 0);
208
+ return out;
209
+ }
210
+ /** method -> requests for one chain (only methods the chain used) */
211
+ function methodsForChain(stats, chain) {
212
+ var _a;
213
+ const out = {};
214
+ for (const [method, byChain] of Object.entries((_a = stats.byMethod) !== null && _a !== void 0 ? _a : {}))
215
+ if (byChain[chain])
216
+ out[method] = byChain[chain];
217
+ return out;
218
+ }
219
+ function urlFromRequestArgs(args, defaultProtocol) {
220
+ let url;
221
+ let options;
222
+ if (typeof args[0] === 'string') {
223
+ url = args[0];
224
+ if (args[1] && typeof args[1] === 'object')
225
+ options = args[1];
226
+ }
227
+ else if (args[0] instanceof URL) {
228
+ url = args[0].href;
229
+ if (args[1] && typeof args[1] === 'object')
230
+ options = args[1];
231
+ }
232
+ else if (args[0] && typeof args[0] === 'object') {
233
+ options = args[0];
234
+ }
235
+ if (url && (!options || (!options.hostname && !options.host && !options.path)))
236
+ return url;
237
+ if (!options)
238
+ return url;
239
+ // options override the url (same precedence as node)
240
+ const base = url ? new URL(url) : undefined;
241
+ const protocol = options.protocol || (base === null || base === void 0 ? void 0 : base.protocol) || defaultProtocol;
242
+ const host = options.hostname || options.host || (base === null || base === void 0 ? void 0 : base.hostname) || 'localhost';
243
+ const port = options.port ? `:${options.port}` : (options.hostname || !options.host) && (base === null || base === void 0 ? void 0 : base.port) ? `:${base.port}` : '';
244
+ const path = options.path || (base ? base.pathname + base.search : '/');
245
+ return `${protocol}//${host}${host.includes(':') ? '' : port}${path}`;
246
+ }
247
+ function wrap(mod, name, defaultProtocol) {
248
+ const original = mod[name];
249
+ if (typeof original !== 'function')
250
+ return;
251
+ const patched = function (...args) {
252
+ try {
253
+ const url = urlFromRequestArgs(args, defaultProtocol);
254
+ if (url)
255
+ record(url);
256
+ }
257
+ catch { /* never break the request */ }
258
+ return original.apply(this, args);
259
+ };
260
+ Object.defineProperty(patched, 'name', { value: original.name });
261
+ mod[name] = patched;
262
+ }
263
+ /** Patch the node http layer. Idempotent, shared across sdk copies. Called by `run`. */
264
+ function install() {
265
+ var _a, _b;
266
+ if (shared.installed)
267
+ return;
268
+ shared.installed = true;
269
+ wrap(http_1.default, 'request', 'http:');
270
+ wrap(http_1.default, 'get', 'http:');
271
+ wrap(https_1.default, 'request', 'https:');
272
+ wrap(https_1.default, 'get', 'https:');
273
+ try {
274
+ // global fetch (undici); node < 18.7 has no subscribe, fetch is then simply not counted
275
+ ;
276
+ (_b = (_a = diagnostics_channel_1.default).subscribe) === null || _b === void 0 ? void 0 : _b.call(_a, 'undici:request:create', (message) => {
277
+ var _a;
278
+ try {
279
+ const request = message === null || message === void 0 ? void 0 : message.request;
280
+ if (request === null || request === void 0 ? void 0 : request.origin)
281
+ record(String(request.origin) + String((_a = request.path) !== null && _a !== void 0 ? _a : ''));
282
+ }
283
+ catch { /* ignore */ }
284
+ });
285
+ }
286
+ catch { /* ignore */ }
287
+ try {
288
+ const esConfig = (0, env_1.getEnvValue)('ELASTICSEARCH_CONFIG');
289
+ if (esConfig)
290
+ ignoreHost(JSON.parse(esConfig.replace(/\\"/g, '"')).host);
291
+ }
292
+ catch { /* ignore */ }
293
+ }
294
+ /** Stats of the current run context, or the process-wide bucket when called outside `run`. */
295
+ function getCurrent() {
296
+ var _a;
297
+ return (_a = shared.als.getStore()) !== null && _a !== void 0 ? _a : shared.global;
298
+ }
299
+ function copyNested(map) {
300
+ const out = {};
301
+ for (const [key, byChain] of Object.entries(map !== null && map !== void 0 ? map : {}))
302
+ out[key] = { ...byChain };
303
+ return out;
304
+ }
305
+ function addNested(target, source) {
306
+ var _a, _b;
307
+ for (const [key, byChain] of Object.entries(source !== null && source !== void 0 ? source : {})) {
308
+ const into = (_a = target[key]) !== null && _a !== void 0 ? _a : (target[key] = {});
309
+ for (const [k, v] of Object.entries(byChain))
310
+ into[k] = ((_b = into[k]) !== null && _b !== void 0 ? _b : 0) + v;
311
+ }
312
+ }
313
+ function snapshot(stats = getCurrent()) {
314
+ return {
315
+ total: stats.total, byChain: { ...stats.byChain }, byHost: { ...stats.byHost }, unattributed: stats.unattributed,
316
+ byMethod: copyNested(stats.byMethod), logs: copyNested(stats.logs),
317
+ };
318
+ }
319
+ function mergeSnapshots(snapshots) {
320
+ var _a, _b, _c, _d, _e, _f;
321
+ const out = { total: 0, byChain: {}, byHost: {}, unattributed: 0, byMethod: {}, logs: { rpc: {}, indexer: {} } };
322
+ for (const s of snapshots) {
323
+ if (!s)
324
+ continue;
325
+ out.total += (_a = s.total) !== null && _a !== void 0 ? _a : 0;
326
+ out.unattributed += (_b = s.unattributed) !== null && _b !== void 0 ? _b : 0;
327
+ for (const [k, v] of Object.entries((_c = s.byChain) !== null && _c !== void 0 ? _c : {}))
328
+ out.byChain[k] = ((_d = out.byChain[k]) !== null && _d !== void 0 ? _d : 0) + v;
329
+ for (const [k, v] of Object.entries((_e = s.byHost) !== null && _e !== void 0 ? _e : {}))
330
+ out.byHost[k] = ((_f = out.byHost[k]) !== null && _f !== void 0 ? _f : 0) + v;
331
+ addNested(out.byMethod, s.byMethod);
332
+ addNested(out.logs, s.logs);
333
+ }
334
+ return out;
335
+ }
336
+ /**
337
+ * Run `fn` with its own counters and report them when it settles (success or failure).
338
+ * Nested calls get their own context; calls made by `fn` through any http client are attributed to it.
339
+ */
340
+ async function run(meta, fn, options = {}) {
341
+ install();
342
+ const stats = newStats(meta);
343
+ shared.active.add(stats);
344
+ return shared.als.run(stats, async () => {
345
+ let success = false;
346
+ try {
347
+ const result = await fn();
348
+ success = true;
349
+ return result;
350
+ }
351
+ finally {
352
+ shared.active.delete(stats);
353
+ // already written by flushActive: the run was given up on (timeout / shutdown), its outcome no longer counts
354
+ if (!stats.reported) {
355
+ stats.reported = true;
356
+ try {
357
+ await report(stats, { success, runtime: (Date.now() - stats.startTime) / 1000, ...options });
358
+ }
359
+ catch (e) {
360
+ (0, debugLog_1.debugLog)('[callStats] failed to report', e === null || e === void 0 ? void 0 : e.message);
361
+ }
362
+ }
363
+ }
364
+ });
365
+ }
366
+ /**
367
+ * Write the docs of the runs still in flight (all of them, or those whose meta passes `filter`) as failed runs
368
+ * with `interrupted: reason`, and mark them so they are not written again when they eventually settle.
369
+ * For a process that is about to be killed, or a job the caller has given up on: without this the heaviest runs,
370
+ * the ones that hit the timeout, would be exactly the ones never recorded. Returns the number of runs written.
371
+ */
372
+ async function flushActive(reason, { filter, ...options } = {}) {
373
+ const runs = [...shared.active].filter(stats => !stats.reported && (!filter || filter(stats.meta)));
374
+ for (const stats of runs)
375
+ stats.reported = true;
376
+ await Promise.all(runs.map(stats => report(stats, { success: false, interrupted: reason, runtime: (Date.now() - stats.startTime) / 1000, ...options })
377
+ .catch(e => (0, debugLog_1.debugLog)('[callStats] failed to flush', e === null || e === void 0 ? void 0 : e.message))));
378
+ return runs.length;
379
+ }
380
+ // ---------------------------------------------------------------------------
381
+ // reporting
382
+ // ---------------------------------------------------------------------------
383
+ function getMinCalls(minCalls) {
384
+ if (minCalls !== undefined)
385
+ return minCalls;
386
+ return +(0, env_1.getEnvValue)('CALL_STATS_MIN_CALLS', String(exports.DEFAULT_MIN_CALLS));
387
+ }
388
+ /**
389
+ * One row per chain that made an http request, had an rpc method recorded or had logs fetched, plus `_other`
390
+ * for requests matching no registered rpc. Most calls first. Nothing is thresholded away: the long tail of
391
+ * small adapters is exactly what a per-chain sum must include.
392
+ */
393
+ function chainRows(stats) {
394
+ var _a, _b;
395
+ const chains = new Set(Object.keys(stats.byChain));
396
+ for (const byChain of Object.values((_a = stats.byMethod) !== null && _a !== void 0 ? _a : {}))
397
+ for (const chain of Object.keys(byChain))
398
+ chains.add(chain);
399
+ for (const byChain of Object.values((_b = stats.logs) !== null && _b !== void 0 ? _b : {}))
400
+ for (const chain of Object.keys(byChain))
401
+ chains.add(chain);
402
+ if (stats.unattributed > 0)
403
+ chains.add(exports.OTHER_CHAIN);
404
+ const rows = [...chains].map(chain => {
405
+ var _a, _b;
406
+ const methods = methodsForChain(stats, chain);
407
+ const logsRpc = logsFetched(stats, 'rpc', chain);
408
+ const logsIndexer = logsFetched(stats, 'indexer', chain);
409
+ return {
410
+ chain,
411
+ calls: chain === exports.OTHER_CHAIN ? stats.unattributed : (_a = stats.byChain[chain]) !== null && _a !== void 0 ? _a : 0,
412
+ getLogs: getLogsCount(stats, chain),
413
+ indexerCalls: (_b = methods[exports.INDEXER_METHOD]) !== null && _b !== void 0 ? _b : 0,
414
+ logs: logsRpc + logsIndexer, logsRpc, logsIndexer,
415
+ methods,
416
+ };
417
+ }).filter(r => r.calls > 0 || r.logs > 0 || Object.keys(r.methods).length > 0);
418
+ rows.sort((a, b) => b.calls - a.calls || b.getLogs - a.getLogs || b.logs - a.logs);
419
+ return rows;
420
+ }
421
+ /** The busiest hosts of the run, rpc endpoints included so provider load is visible too. */
422
+ function hostRows(stats) {
423
+ return Object.entries(stats.byHost)
424
+ .map(([host, calls]) => ({ host, calls, rpc: shared.endpoints.has(host) }))
425
+ .sort((a, b) => b.calls - a.calls)
426
+ .slice(0, exports.MAX_HOSTS_PER_RUN);
427
+ }
428
+ /** Scalar meta fields become top-level doc fields; arrays/objects (eg. the list of chains to run) would only bloat the mapping. */
429
+ function flatMeta(meta) {
430
+ const out = {};
431
+ for (const [key, value] of Object.entries(meta))
432
+ if (value !== undefined && value !== null && typeof value !== 'object')
433
+ out[key] = value;
434
+ return out;
435
+ }
436
+ function buildDocs(stats, meta, { success, runtime, minCalls, interrupted } = {}) {
437
+ var _a;
438
+ const rows = stats.total >= getMinCalls(minCalls) ? chainRows(stats) : [];
439
+ if (!rows.length)
440
+ return { chainDocs: [], hostDocs: [] };
441
+ const base = {
442
+ '@timestamp': new Date().toISOString(),
443
+ ...flatMeta(meta),
444
+ runId: crypto_1.default.randomBytes(8).toString('hex'),
445
+ success, runtime, interrupted,
446
+ runCalls: stats.total,
447
+ runGetLogs: getLogsCount(stats),
448
+ runIndexerCalls: sumValues((_a = stats.byMethod) === null || _a === void 0 ? void 0 : _a[exports.INDEXER_METHOD]),
449
+ runLogs: logsFetched(stats, 'rpc') + logsFetched(stats, 'indexer'),
450
+ runChains: rows.filter(r => r.chain !== exports.OTHER_CHAIN).length,
451
+ };
452
+ return {
453
+ chainDocs: rows.map(r => ({ ...base, ...r })),
454
+ hostDocs: hostRows(stats).map(r => ({ ...base, ...r })),
455
+ };
456
+ }
457
+ /** Write the docs for `stats` to elasticsearch (no-op when ELASTICSEARCH_CONFIG is unset) and print the summary in debug mode. */
458
+ async function report(stats, { success, runtime, minCalls, interrupted, print, skipElastic, meta } = {}) {
459
+ var _a;
460
+ meta = (_a = meta !== null && meta !== void 0 ? meta : stats.meta) !== null && _a !== void 0 ? _a : { application: 'unknown', name: '-' };
461
+ const { chainDocs, hostDocs } = buildDocs(stats, meta, { success, runtime, minCalls, interrupted });
462
+ if (print)
463
+ printStats(stats, meta, console.log, console.table);
464
+ else
465
+ printStats(stats, meta, debugLog_1.debugLog, debugLog_1.debugTable);
466
+ if (skipElastic)
467
+ return;
468
+ await Promise.all([
469
+ ...chainDocs.map(doc => (0, elastic_1.writeLog)(exports.ES_INDEX, doc)),
470
+ ...hostDocs.map(doc => (0, elastic_1.writeLog)(exports.ES_HOST_INDEX, doc)),
471
+ ]);
472
+ }
473
+ function printStats(stats, meta, log, table) {
474
+ var _a;
475
+ if (!stats.total)
476
+ return;
477
+ const logs = logsFetched(stats, 'rpc') + logsFetched(stats, 'indexer');
478
+ log(`[callStats] ${meta.application}/${meta.name}: ${stats.total} http requests (${stats.unattributed} not matching a known rpc, ${getLogsCount(stats)} getLogs, ${sumValues((_a = stats.byMethod) === null || _a === void 0 ? void 0 : _a[exports.INDEXER_METHOD])} indexer requests, ${logs} logs fetched)`);
479
+ const rows = [
480
+ ...chainRows(stats).slice(0, 30).map(r => ({ chain: r.chain, calls: r.calls, getLogs: r.getLogs, indexerCalls: r.indexerCalls, logs: r.logs })),
481
+ ...hostRows(stats).filter(h => !h.rpc).slice(0, 10).map(h => ({ chain: `host: ${h.host}`, calls: h.calls, getLogs: 0, indexerCalls: 0, logs: 0 })),
482
+ ];
483
+ if (rows.length)
484
+ table(rows);
485
+ }
@@ -44,6 +44,7 @@
44
44
  "assetchain": "Asset Chain",
45
45
  "assetmantle": "AssetMantle",
46
46
  "astar": "Astar",
47
+ "aster": "Aster",
47
48
  "astrzk": "Astar zkEVM",
48
49
  "aura": "Aura Network",
49
50
  "aurora": "Aurora",
@@ -90,6 +91,7 @@
90
91
  "btn": "Bitnet",
91
92
  "btnx": "Botanix",
92
93
  "btr": "Bitlayer",
94
+ "bulk": "BULK",
93
95
  "bullet": "Bullet",
94
96
  "bytomsidechain": "Bytomsidechain",
95
97
  "cabal": "Cabal",
@@ -101,6 +103,7 @@
101
103
  "capx": "Capx Chain",
102
104
  "carbon": "Carbon",
103
105
  "cardano": "Cardano",
106
+ "casper": "Casper",
104
107
  "celestia": "Celestia",
105
108
  "celo": "Celo",
106
109
  "chainflip": "Chainflip",
@@ -160,6 +163,7 @@
160
163
  "dsc": "DSC",
161
164
  "duckchain": "DuckChain",
162
165
  "dungeon": "Dungeon",
166
+ "dusk": "Dusk",
163
167
  "dydx": "dYdX",
164
168
  "dymension": "Dymension",
165
169
  "earnm": "Earnm",
@@ -209,6 +213,7 @@
209
213
  "flow": "Flow",
210
214
  "fluence": "Fluence",
211
215
  "fluent": "Fluent",
216
+ "flux": "Flux",
212
217
  "flynet": "Flynet",
213
218
  "fogo": "Fogo",
214
219
  "forma": "Forma",
@@ -230,6 +235,7 @@
230
235
  "gensyn": "Gensyn",
231
236
  "ggchain": "GGCHAIN",
232
237
  "glue": "Glue",
238
+ "gnoland": "Gno.land",
233
239
  "goat": "GOAT",
234
240
  "gochain": "GoChain",
235
241
  "godwoken": "Godwoken",
@@ -362,10 +368,12 @@
362
368
  "moonbeam": "Moonbeam",
363
369
  "moonriver": "Moonriver",
364
370
  "morph": "Morph",
371
+ "morph_tachyon": "Morph Tachyon",
365
372
  "move": "Movement",
366
373
  "mrt": "MyRx",
367
374
  "mtt_network": "MTT Network",
368
375
  "multivac": "MultiVAC",
376
+ "muster": "Muster",
369
377
  "muuchain": "MUUCHAIN",
370
378
  "mvc": "MVC",
371
379
  "mxczkevm": "Moonchain",
@@ -437,6 +445,7 @@
437
445
  "pi": "Pi Network",
438
446
  "planq": "Planq",
439
447
  "plasma": "Plasma",
448
+ "platon": "PlatON",
440
449
  "plume": "Plume",
441
450
  "plume_mainnet": "Plume Mainnet",
442
451
  "pokt": "Pokt",
@@ -505,6 +514,7 @@
505
514
  "shimmer_evm": "ShimmerEVM",
506
515
  "sifchain": "Sifchain",
507
516
  "silicon_zk": "Silicon zkEVM",
517
+ "sis": "Sis",
508
518
  "skale": "SKALE",
509
519
  "skate": "Skate",
510
520
  "smartbch": "smartBCH",
@@ -596,6 +606,7 @@
596
606
  "wemix": "WEMIX3.0",
597
607
  "winr": "WINR Chain",
598
608
  "witnet": "Witnet",
609
+ "world_mobile": "World Mobile",
599
610
  "wormchain": "Wormchain",
600
611
  "xai": "Xai",
601
612
  "xdai": "Gnosis",
@@ -671,6 +682,7 @@
671
682
  "AssetMantle": "assetmantle",
672
683
  "Astar": "astar",
673
684
  "Astar zkEVM": "astrzk",
685
+ "Aster": "aster",
674
686
  "Aura Network": "aura",
675
687
  "Aurora": "aurora",
676
688
  "Avalanche": "avax",
@@ -685,6 +697,7 @@
685
697
  "BSC": "bsc",
686
698
  "BSV Blockchain": "bsv",
687
699
  "BSquared": "bsquared",
700
+ "BULK": "bulk",
688
701
  "Babylon Genesis": "babylon",
689
702
  "Bahamut": "ftn",
690
703
  "BandChain": "band",
@@ -734,6 +747,7 @@
734
747
  "Capx Chain": "capx",
735
748
  "Carbon": "carbon",
736
749
  "Cardano": "cardano",
750
+ "Casper": "casper",
737
751
  "Celestia": "celestia",
738
752
  "Celo": "celo",
739
753
  "Chainflip": "chainflip",
@@ -791,6 +805,7 @@
791
805
  "Doma": "doma",
792
806
  "DuckChain": "duckchain",
793
807
  "Dungeon": "dungeon",
808
+ "Dusk": "dusk",
794
809
  "Dymension": "dymension",
795
810
  "EDU Chain": "occ",
796
811
  "ENI": "eni",
@@ -839,6 +854,7 @@
839
854
  "Flow": "flow",
840
855
  "Fluence": "fluence",
841
856
  "Fluent": "fluent",
857
+ "Flux": "flux",
842
858
  "Flynet": "flynet",
843
859
  "Fogo": "fogo",
844
860
  "Form Network": "formnetwork",
@@ -861,6 +877,7 @@
861
877
  "Genshiro": "genshiro",
862
878
  "Gensyn": "gensyn",
863
879
  "Glue": "glue",
880
+ "Gno.land": "gnoland",
864
881
  "Gnosis": "xdai",
865
882
  "GoChain": "gochain",
866
883
  "Goat": "goat",
@@ -1006,9 +1023,11 @@
1006
1023
  "Moonchain": "mxczkevm",
1007
1024
  "Moonriver": "moonriver",
1008
1025
  "Morph": "morph",
1026
+ "Morph Tachyon": "morph_tachyon",
1009
1027
  "Movement": "move",
1010
1028
  "MultiVAC": "multivac",
1011
1029
  "MultiversX": "elrond",
1030
+ "Muster": "muster",
1012
1031
  "MyRx": "mrt",
1013
1032
  "Mythos": "mythos",
1014
1033
  "N1": "n1",
@@ -1085,6 +1104,7 @@
1085
1104
  "Pi Network": "pi",
1086
1105
  "Planq": "planq",
1087
1106
  "Plasma": "plasma",
1107
+ "PlatON": "platon",
1088
1108
  "Plume": "plume",
1089
1109
  "Plume (Deprecated)": "plume",
1090
1110
  "Plume Mainnet": "plume_mainnet",
@@ -1163,6 +1183,7 @@
1163
1183
  "ShimmerEVM": "shimmer_evm",
1164
1184
  "Sifchain": "sifchain",
1165
1185
  "Silicon zkEVM": "silicon_zk",
1186
+ "Sis": "sis",
1166
1187
  "Skate": "skate",
1167
1188
  "Solana": "solana",
1168
1189
  "Sommelier": "sommelier",
@@ -1254,6 +1275,7 @@
1254
1275
  "Wax": "wax",
1255
1276
  "Witnet": "witnet",
1256
1277
  "World Chain": "wc",
1278
+ "World Mobile": "world_mobile",
1257
1279
  "Wormchain": "wormchain",
1258
1280
  "X Layer": "xlayer",
1259
1281
  "XCHAIN": "idex",
@@ -14,6 +14,7 @@ const general_1 = require("../general");
14
14
  const ethers_1 = require("ethers");
15
15
  const common_1 = require("./common");
16
16
  const debugLog_1 = require("./debugLog");
17
+ const callStats_1 = require("./callStats");
17
18
  const promisePool_1 = __importDefault(require("./promisePool"));
18
19
  var blocks_1 = require("./blocks");
19
20
  Object.defineProperty(exports, "getLatestBlock", { enumerable: true, get: function () { return blocks_1.getLatestBlock; } });
@@ -87,6 +88,7 @@ async function _getLogs(params) {
87
88
  };
88
89
  try {
89
90
  const partLogs = await provider.getLogs(logParams);
91
+ (0, callStats_1.recordLogs)('rpc', params.chain, partLogs.length);
90
92
  logs = logs.concat(partLogs);
91
93
  currentBlock = nextBlock;
92
94
  }