@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.
@@ -21,6 +21,7 @@ const StreamArray_1 = require("stream-json/streamers/StreamArray");
21
21
  const _1 = require(".");
22
22
  const blocks_1 = require("./blocks");
23
23
  const common_1 = require("./common");
24
+ const callStats_1 = require("./callStats");
24
25
  const debugLog_1 = require("./debugLog");
25
26
  const env_1 = require("./env");
26
27
  const logs_1 = require("./logs");
@@ -164,6 +165,11 @@ function assertCursorAdvances(next, previous) {
164
165
  if (!advances)
165
166
  throw new Error("Indexer v4 pagination cursor did not advance");
166
167
  }
168
+ // chain of an indexer query, for call stats: every page request is counted against it
169
+ function chainOfParams(params) {
170
+ var _a;
171
+ return (_a = allChainIdChainMapping[params === null || params === void 0 ? void 0 : params.chainId]) !== null && _a !== void 0 ? _a : callStats_1.OTHER_CHAIN;
172
+ }
167
173
  // Translate the public offset/limit contract into keyset pagination. Even all=false
168
174
  // may need several requests: the v4 server caps offsets, not the public SDK API.
169
175
  async function* getV4Pages(path, key, params, limit, offset, all, getCursor) {
@@ -174,8 +180,10 @@ async function* getV4Pages(path, key, params, limit, offset, all, getCursor) {
174
180
  let cursor;
175
181
  let remainingOffset = offset;
176
182
  let remainingLimit = all ? Infinity : limit;
183
+ const chain = chainOfParams(params);
177
184
  while (remainingLimit > 0) {
178
185
  const pageParams = { ...params, limit, offset: 0, includeTotal: false, ...cursor };
186
+ (0, callStats_1.recordMethod)(callStats_1.INDEXER_METHOD, chain);
179
187
  const response = await axiosInstances.v4(path, {
180
188
  params: pageParams,
181
189
  ...(key === "transfers" ? { responseType: "text", transformResponse: (data) => data } : {}),
@@ -185,6 +193,8 @@ async function* getV4Pages(path, key, params, limit, offset, all, getCursor) {
185
193
  const page = data[key];
186
194
  if (!Array.isArray(page))
187
195
  throw new Error(`Indexer v4 returned an invalid ${key} response`);
196
+ if (key === "logs")
197
+ (0, callStats_1.recordLogs)('indexer', chain, page.length);
188
198
  // Capture the cursor before consumers normalize/mutate the raw rows.
189
199
  const next = getCursor(page[page.length - 1]);
190
200
  const result = applyLocalOffset(page, remainingOffset);
@@ -207,10 +217,14 @@ async function* getIndexerPages(version, path, key, params, limit, offset, all,
207
217
  return;
208
218
  }
209
219
  let count = 0;
220
+ const chain = chainOfParams(params);
210
221
  do {
222
+ (0, callStats_1.recordMethod)(callStats_1.INDEXER_METHOD, chain);
211
223
  const { data } = await axiosInstances.v2(path, { params: { ...params, limit, offset } })
212
224
  .catch((e) => { throw (0, common_1.formError)(e); });
213
225
  const rows = data[key];
226
+ if (key === "logs" && Array.isArray(rows))
227
+ (0, callStats_1.recordLogs)('indexer', chain, rows.length);
214
228
  yield rows;
215
229
  count += rows.length;
216
230
  if (!rows.length || rows.length < limit || (key === "logs" && typeof data.totalCount === "number" && data.totalCount <= count))
@@ -230,6 +244,7 @@ async function getChainIndexStatus(version) {
230
244
  return state.chainIndexStatus;
231
245
  state.timestamp = Date.now();
232
246
  state.chainIndexStatus = (async () => {
247
+ (0, callStats_1.recordMethod)(callStats_1.INDEXER_METHOD); // serves every chain: counted under _other
233
248
  const { data: { syncStatus }, } = await axiosInstances[version].get(`/sync`).catch((e) => { throw (0, common_1.formError)(e); });
234
249
  const info = {};
235
250
  syncStatus.forEach((d) => {
@@ -250,10 +265,11 @@ async function getChainIndexStatus(version) {
250
265
  return state.chainIndexStatus;
251
266
  }
252
267
  async function streamLogs(opts) {
253
- const { path, version, onItem, onChunkStats, shouldStop } = opts;
268
+ const { path, version, chain, onItem, onChunkStats, shouldStop } = opts;
254
269
  const controller = new AbortController();
255
270
  let bytesReceived = 0;
256
271
  let itemsProcessed = 0;
272
+ (0, callStats_1.recordMethod)(callStats_1.INDEXER_METHOD, chain);
257
273
  const res = await axiosInstances[version].get(path, {
258
274
  responseType: "stream",
259
275
  timeout: INDEXER_REQUEST_TIMEOUT_MS,
@@ -295,6 +311,9 @@ async function streamLogs(opts) {
295
311
  if (!stopped)
296
312
  throw processingError !== null && processingError !== void 0 ? processingError : e;
297
313
  }
314
+ finally {
315
+ (0, callStats_1.recordLogs)('indexer', chain, itemsProcessed); // rows received, including those of a stream that then failed
316
+ }
298
317
  onChunkStats === null || onChunkStats === void 0 ? void 0 : onChunkStats({ chunkSize: 0, bytesReceived, itemsProcessed });
299
318
  }
300
319
  async function decodeStreamingLogs(logs, transformLog, batchDecoder, onlyArgs) {
@@ -342,6 +361,9 @@ async function getLogs(options) {
342
361
  }
343
362
  // Ensure the indexer is synced far enough
344
363
  const indexerVersion = getChainIndexerVersion(chain);
364
+ // one logical getLogs query against the indexer (chunks over maxBlockRange recurse here and count separately)
365
+ if (blockRange <= effectiveMaxBlockRange)
366
+ (0, callStats_1.recordMethod)('indexerGetLogs', chain);
345
367
  checkIndexerConfig(indexerVersion);
346
368
  const chainId = getChainId(chain);
347
369
  const chainIndexStatus = await getChainIndexStatus(indexerVersion);
@@ -450,6 +472,7 @@ async function getLogs(options) {
450
472
  await streamLogs({
451
473
  path: `/logs?${qs.toString()}`,
452
474
  version: indexerVersion,
475
+ chain,
453
476
  onItem: async (raw) => {
454
477
  var _a, _b, _c;
455
478
  if (stopNow)
@@ -30,7 +30,7 @@ async function getChainData() {
30
30
  }
31
31
  async function main() {
32
32
  await (0, chainUtils_1.updateChainLabels)();
33
- const oldProviders = await (0, generalUtil_1.fetchJson)(`https://unpkg.com/@defillama/sdk@v5.0.238/build/providers.json`);
33
+ const oldProviders = await (0, generalUtil_1.fetchJson)(`https://unpkg.com/@defillama/sdk@latest/build/providers.json`);
34
34
  const currentChains = await (0, generalUtil_1.fetchJson)(`https://raw.githubusercontent.com/DefiLlama/DefiLlama-Adapters/refs/heads/main/projects/helper/chains.json`);
35
35
  const currentChainsSet = new Set(currentChains);
36
36
  let chainData = await getChainData();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defillama/sdk",
3
- "version": "5.0.242",
3
+ "version": "5.0.245",
4
4
  "description": "SDK for calculating TVL",
5
5
  "main": "build/index.js",
6
6
  "scripts": {