@defillama/sdk 5.0.227 → 5.0.228
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.
|
@@ -461,6 +461,7 @@
|
|
|
461
461
|
"secret": "Secret",
|
|
462
462
|
"seda": "Seda",
|
|
463
463
|
"sei": "Sei",
|
|
464
|
+
"seleman": "SELEMAN",
|
|
464
465
|
"shape": "Shape",
|
|
465
466
|
"shibarium": "Shibarium",
|
|
466
467
|
"shiden": "Shiden",
|
|
@@ -1064,6 +1065,7 @@
|
|
|
1064
1065
|
"Ronin": "ronin",
|
|
1065
1066
|
"Rootstock": "rsk",
|
|
1066
1067
|
"Rubin": "rubin",
|
|
1068
|
+
"SELEMAN": "seleman",
|
|
1067
1069
|
"SKALE": "skale",
|
|
1068
1070
|
"SKALE Europa": "europa",
|
|
1069
1071
|
"SX Network": "sx",
|
package/build/util/indexer.js
CHANGED
|
@@ -124,6 +124,42 @@ function getSupportedChains() {
|
|
|
124
124
|
return new Set(Object.values(allChainIdChainMapping));
|
|
125
125
|
}
|
|
126
126
|
exports.supportedChainSet2 = getSupportedChains();
|
|
127
|
+
function supportsCursorPagination(version) {
|
|
128
|
+
return version === "v4";
|
|
129
|
+
}
|
|
130
|
+
function getLogCursor(log) {
|
|
131
|
+
var _a, _b, _c;
|
|
132
|
+
if (!log)
|
|
133
|
+
return undefined;
|
|
134
|
+
const afterBlock = (_a = log.block_number) !== null && _a !== void 0 ? _a : log.blockNumber;
|
|
135
|
+
const afterIndex = (_c = (_b = log.log_index) !== null && _b !== void 0 ? _b : log.logIndex) !== null && _c !== void 0 ? _c : log.index;
|
|
136
|
+
if (afterBlock === undefined || afterIndex === undefined)
|
|
137
|
+
return undefined;
|
|
138
|
+
return { after_block: +afterBlock, after_index: +afterIndex };
|
|
139
|
+
}
|
|
140
|
+
function getTransferCursor(transfer) {
|
|
141
|
+
const cursor = getLogCursor(transfer);
|
|
142
|
+
if (!cursor)
|
|
143
|
+
return undefined;
|
|
144
|
+
if (transfer.id !== undefined && transfer.id !== null)
|
|
145
|
+
cursor.after_id = String(transfer.id);
|
|
146
|
+
return cursor;
|
|
147
|
+
}
|
|
148
|
+
function applyCursorParams(params, cursor) {
|
|
149
|
+
if (!cursor)
|
|
150
|
+
return;
|
|
151
|
+
params.after_block = cursor.after_block;
|
|
152
|
+
params.after_index = cursor.after_index;
|
|
153
|
+
if (cursor.after_id !== undefined)
|
|
154
|
+
params.after_id = cursor.after_id;
|
|
155
|
+
}
|
|
156
|
+
function applyLocalOffset(rows, remainingOffset) {
|
|
157
|
+
if (remainingOffset <= 0)
|
|
158
|
+
return { rows, remainingOffset };
|
|
159
|
+
if (remainingOffset >= rows.length)
|
|
160
|
+
return { rows: [], remainingOffset: remainingOffset - rows.length };
|
|
161
|
+
return { rows: rows.slice(remainingOffset), remainingOffset: 0 };
|
|
162
|
+
}
|
|
127
163
|
const syncStates = {
|
|
128
164
|
v2: { chainIndexStatus: {} },
|
|
129
165
|
v4: { chainIndexStatus: {} },
|
|
@@ -470,12 +506,15 @@ async function getLogs(options) {
|
|
|
470
506
|
(0, debugLog_1.debugLog)("[Indexer] Pulling logs " + debugTimeKey);
|
|
471
507
|
console.time(debugTimeKey);
|
|
472
508
|
}
|
|
509
|
+
const useCursorPagination = supportsCursorPagination(indexerVersion) && all;
|
|
473
510
|
for (const chunk of addressChunks) {
|
|
474
511
|
if (Array.isArray(chunk) && chunk.length === 0)
|
|
475
512
|
throw new Error("Address chunk cannot be empty");
|
|
476
|
-
let chunkOffset = initialOffset;
|
|
513
|
+
let chunkOffset = useCursorPagination ? 0 : initialOffset;
|
|
514
|
+
let remainingOffset = useCursorPagination ? initialOffset : 0;
|
|
477
515
|
let logCount = 0;
|
|
478
516
|
let hasMore = true;
|
|
517
|
+
let cursor;
|
|
479
518
|
do {
|
|
480
519
|
const params = {
|
|
481
520
|
addresses: hasAddressFilter ? chunk === null || chunk === void 0 ? void 0 : chunk.join(",") : undefined,
|
|
@@ -490,8 +529,15 @@ async function getLogs(options) {
|
|
|
490
529
|
offset: chunkOffset,
|
|
491
530
|
noTarget,
|
|
492
531
|
};
|
|
532
|
+
if (useCursorPagination) {
|
|
533
|
+
params.includeTotal = false;
|
|
534
|
+
applyCursorParams(params, cursor);
|
|
535
|
+
}
|
|
493
536
|
const { data: { logs: _logs, totalCount }, } = await axiosInstances[indexerVersion](`/logs`, { params }).catch((e) => { throw (0, common_1.formError)(e); });
|
|
494
|
-
const
|
|
537
|
+
const nextCursor = useCursorPagination ? getLogCursor(_logs[_logs.length - 1]) : undefined;
|
|
538
|
+
const offsetResult = useCursorPagination ? applyLocalOffset(_logs, remainingOffset) : { rows: _logs, remainingOffset };
|
|
539
|
+
remainingOffset = offsetResult.remainingOffset;
|
|
540
|
+
const filtered = offsetResult.rows.filter((l) => {
|
|
495
541
|
var _a, _b, _c;
|
|
496
542
|
const isWhitelisted = !addressSet.size || addressSet.has((_c = (_b = ((_a = l.source) !== null && _a !== void 0 ? _a : l.address)) === null || _b === void 0 ? void 0 : _b.toLowerCase) === null || _c === void 0 ? void 0 : _c.call(_b));
|
|
497
543
|
return !!isWhitelisted;
|
|
@@ -517,7 +563,13 @@ async function getLogs(options) {
|
|
|
517
563
|
safePush(allLogsPairs, transformedPair);
|
|
518
564
|
}
|
|
519
565
|
logCount += _logs.length;
|
|
520
|
-
|
|
566
|
+
if (useCursorPagination && nextCursor) {
|
|
567
|
+
cursor = nextCursor;
|
|
568
|
+
chunkOffset = 0;
|
|
569
|
+
}
|
|
570
|
+
else {
|
|
571
|
+
chunkOffset += limit;
|
|
572
|
+
}
|
|
521
573
|
if (_logs.length === 0) {
|
|
522
574
|
hasMore = false;
|
|
523
575
|
}
|
|
@@ -602,8 +654,11 @@ async function getTokenTransfers({ chain = "ethereum", fromAddressFilter, fromBl
|
|
|
602
654
|
(0, debugLog_1.debugLog)("[Indexer] Pulling token transfers " + debugTimeKey);
|
|
603
655
|
console.time(debugTimeKey);
|
|
604
656
|
}
|
|
605
|
-
|
|
657
|
+
const useCursorPagination = supportsCursorPagination(indexerVersion) && all;
|
|
658
|
+
let currentOffset = useCursorPagination ? 0 : offset;
|
|
659
|
+
let remainingOffset = useCursorPagination ? offset : 0;
|
|
606
660
|
let hasMore = true;
|
|
661
|
+
let cursor;
|
|
607
662
|
do {
|
|
608
663
|
const params = {
|
|
609
664
|
addresses,
|
|
@@ -616,6 +671,10 @@ async function getTokenTransfers({ chain = "ethereum", fromAddressFilter, fromBl
|
|
|
616
671
|
from_address: false,
|
|
617
672
|
to_address: false,
|
|
618
673
|
};
|
|
674
|
+
if (useCursorPagination) {
|
|
675
|
+
params.includeTotal = false;
|
|
676
|
+
applyCursorParams(params, cursor);
|
|
677
|
+
}
|
|
619
678
|
switch (transferType) {
|
|
620
679
|
case "in":
|
|
621
680
|
params.to_address = true;
|
|
@@ -631,8 +690,17 @@ async function getTokenTransfers({ chain = "ethereum", fromAddressFilter, fromBl
|
|
|
631
690
|
throw new Error("Invalid transferType");
|
|
632
691
|
}
|
|
633
692
|
const { data: { transfers: _logs }, } = await axiosInstances[indexerVersion](`/token-transfers`, { params }).catch((e) => { throw (0, common_1.formError)(e); });
|
|
634
|
-
|
|
635
|
-
|
|
693
|
+
const nextCursor = useCursorPagination ? getTransferCursor(_logs[_logs.length - 1]) : undefined;
|
|
694
|
+
const offsetResult = useCursorPagination ? applyLocalOffset(_logs, remainingOffset) : { rows: _logs, remainingOffset };
|
|
695
|
+
remainingOffset = offsetResult.remainingOffset;
|
|
696
|
+
rawTransfers.push(...offsetResult.rows);
|
|
697
|
+
if (useCursorPagination && nextCursor) {
|
|
698
|
+
cursor = nextCursor;
|
|
699
|
+
currentOffset = 0;
|
|
700
|
+
}
|
|
701
|
+
else {
|
|
702
|
+
currentOffset += limit;
|
|
703
|
+
}
|
|
636
704
|
hasMore = _logs.length === limit;
|
|
637
705
|
} while (all && hasMore);
|
|
638
706
|
const filteredTransfers = rawTransfers.filter((l) => {
|