@defillama/sdk 5.0.221 → 5.0.223
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/build/Balances.js +3 -3
- package/build/index.d.ts +1 -0
- package/build/index.js +4 -1
- package/build/providers.json +1 -1
- package/build/util/blocks.js +6 -6
- package/build/util/chainUtils/data.json +21 -1
- package/build/util/env.js +2 -1
- package/build/util/indexer.d.ts +2 -0
- package/build/util/indexer.js +92 -35
- package/build/util/indexerSql.d.ts +2 -0
- package/build/util/indexerSql.js +71 -0
- package/build/util/logs.js +23 -6
- package/package.json +2 -1
package/build/util/blocks.js
CHANGED
|
@@ -157,6 +157,10 @@ async function lookupBlock(timestamp, extraParams) {
|
|
|
157
157
|
const limiter = getChainLimiter(chain);
|
|
158
158
|
return limiter(() => _lookupBlock(timestamp, extraParams));
|
|
159
159
|
}
|
|
160
|
+
const earliestAvailableBlockRange = {
|
|
161
|
+
nibiru: 4 * 1e5, // nibiru hold only the last 400k block data
|
|
162
|
+
evmos: 2 * 1e5,
|
|
163
|
+
};
|
|
160
164
|
async function _lookupBlock(timestamp, extraParams) {
|
|
161
165
|
var _a, _b;
|
|
162
166
|
const { allowedTimeRange = 5 * 60, acceptableBlockImprecision = 10 } = extraParams !== null && extraParams !== void 0 ? extraParams : {};
|
|
@@ -188,13 +192,9 @@ async function _lookupBlock(timestamp, extraParams) {
|
|
|
188
192
|
let imprecision;
|
|
189
193
|
try {
|
|
190
194
|
let firstBlock, lastBlock;
|
|
191
|
-
if ([
|
|
195
|
+
if (!!earliestAvailableBlockRange[chain]) {
|
|
192
196
|
lastBlock = await (0, exports.getLatestBlock)(chain);
|
|
193
|
-
let firstBlockNum = lastBlock.number;
|
|
194
|
-
switch (chain) {
|
|
195
|
-
case 'nibiru': firstBlockNum -= 4 * 1e5; // nibiru hold only the last 400k block data
|
|
196
|
-
case 'evmos': firstBlockNum -= 2 * 1e5; // evmos hold only the last 200k block data
|
|
197
|
-
}
|
|
197
|
+
let firstBlockNum = lastBlock.number - earliestAvailableBlockRange[chain];
|
|
198
198
|
firstBlock = await fetchBlockFromProvider(firstBlockNum, chain);
|
|
199
199
|
}
|
|
200
200
|
else {
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"ancient8": "Ancient8",
|
|
28
28
|
"anubi": "Anubis",
|
|
29
29
|
"ao": "AO",
|
|
30
|
+
"ap3x": "Apex Fusion",
|
|
30
31
|
"apechain": "ApeChain",
|
|
31
32
|
"appchain": "Appchain",
|
|
32
33
|
"aptos": "Aptos",
|
|
@@ -75,6 +76,7 @@
|
|
|
75
76
|
"boba_bnb": "Boba_Bnb",
|
|
76
77
|
"bone": "Bone",
|
|
77
78
|
"bostrom": "Bostrom",
|
|
79
|
+
"bot": "BOT Chain",
|
|
78
80
|
"bouncebit": "BounceBit",
|
|
79
81
|
"bsc": "BSC",
|
|
80
82
|
"bsquared": "BSquared",
|
|
@@ -105,6 +107,7 @@
|
|
|
105
107
|
"civitia": "Civitia",
|
|
106
108
|
"clv": "CLV",
|
|
107
109
|
"cmp": "CMP",
|
|
110
|
+
"codex": "Codex",
|
|
108
111
|
"comdex": "Comdex",
|
|
109
112
|
"concordium": "Concordium",
|
|
110
113
|
"conflux": "Conflux",
|
|
@@ -183,6 +186,7 @@
|
|
|
183
186
|
"everscale": "Everscale",
|
|
184
187
|
"evmos": "Evmos",
|
|
185
188
|
"fantom": "Fantom",
|
|
189
|
+
"fetchhub": "Fetch Hub",
|
|
186
190
|
"fhe": "Mind Network",
|
|
187
191
|
"filecoin": "Filecoin",
|
|
188
192
|
"findora": "Findora",
|
|
@@ -256,6 +260,7 @@
|
|
|
256
260
|
"iota": "IOTA",
|
|
257
261
|
"iotaevm": "IOTA EVM",
|
|
258
262
|
"iotex": "IoTeX",
|
|
263
|
+
"irys_mainnet_beta": "Irys",
|
|
259
264
|
"islm": "HAQQ",
|
|
260
265
|
"jbc": "JBC",
|
|
261
266
|
"joc": "JOC",
|
|
@@ -276,9 +281,11 @@
|
|
|
276
281
|
"kekchain": "Kekchain",
|
|
277
282
|
"kinto": "Kinto",
|
|
278
283
|
"kintsugi": "Kintsugi",
|
|
284
|
+
"kiteai": "KiteAI",
|
|
279
285
|
"klaytn": "Kaia",
|
|
280
286
|
"kopi": "Kopi",
|
|
281
287
|
"kroma": "Kroma",
|
|
288
|
+
"krown": "Krown Network",
|
|
282
289
|
"kujira": "Kujira",
|
|
283
290
|
"kusama": "Kusama",
|
|
284
291
|
"lac": "LaChain Network",
|
|
@@ -434,6 +441,7 @@
|
|
|
434
441
|
"reya": "ReyaChain",
|
|
435
442
|
"ripple": "XRPL",
|
|
436
443
|
"rise": "RISE",
|
|
444
|
+
"rls": "Rayls",
|
|
437
445
|
"robinhood": "Robinhood Chain",
|
|
438
446
|
"robonomics": "Robonomics",
|
|
439
447
|
"rollux": "Rollux",
|
|
@@ -487,6 +495,7 @@
|
|
|
487
495
|
"starknet": "Starknet",
|
|
488
496
|
"stellar": "Stellar",
|
|
489
497
|
"step": "Step",
|
|
498
|
+
"strat": "Strat",
|
|
490
499
|
"stratis": "Stratis",
|
|
491
500
|
"strato": "Strato",
|
|
492
501
|
"stride": "Stride",
|
|
@@ -533,6 +542,7 @@
|
|
|
533
542
|
"velas": "Velas",
|
|
534
543
|
"venom": "Venom",
|
|
535
544
|
"verus": "Verus",
|
|
545
|
+
"vfl": "zkVerify",
|
|
536
546
|
"vinu": "VinuChain",
|
|
537
547
|
"virbicoin": "VirBiCoin",
|
|
538
548
|
"vision": "Vision",
|
|
@@ -603,6 +613,7 @@
|
|
|
603
613
|
"Ancient8": "ancient8",
|
|
604
614
|
"Anubis": "anubi",
|
|
605
615
|
"ApeChain": "apechain",
|
|
616
|
+
"Apex Fusion": "ap3x",
|
|
606
617
|
"Appchain": "appchain",
|
|
607
618
|
"Aptos": "aptos",
|
|
608
619
|
"Arbitrum": "arbitrum",
|
|
@@ -625,6 +636,7 @@
|
|
|
625
636
|
"BESC Hyperchain": "besc",
|
|
626
637
|
"BEVM": "chainx",
|
|
627
638
|
"BOB": "bob",
|
|
639
|
+
"BOT Chain": "bot",
|
|
628
640
|
"BSC": "bsc",
|
|
629
641
|
"BSV Blockchain": "bsv",
|
|
630
642
|
"BSquared": "bsquared",
|
|
@@ -685,6 +697,7 @@
|
|
|
685
697
|
"Chromia": "chromia",
|
|
686
698
|
"Citrea": "citrea",
|
|
687
699
|
"Civitia": "civitia",
|
|
700
|
+
"Codex": "codex",
|
|
688
701
|
"Comdex": "comdex",
|
|
689
702
|
"Concordium": "concordium",
|
|
690
703
|
"Conflux": "conflux",
|
|
@@ -764,6 +777,7 @@
|
|
|
764
777
|
"Evmos": "evmos",
|
|
765
778
|
"FSC": "fsc",
|
|
766
779
|
"Fantom": "fantom",
|
|
780
|
+
"Fetch Hub": "fetchhub",
|
|
767
781
|
"Filecoin": "filecoin",
|
|
768
782
|
"Findora": "findora",
|
|
769
783
|
"Firechain": "firechain",
|
|
@@ -839,6 +853,7 @@
|
|
|
839
853
|
"Interlay": "interlay",
|
|
840
854
|
"Intuition": "intuition",
|
|
841
855
|
"IoTeX": "iotex",
|
|
856
|
+
"Irys": "irys_mainnet_beta",
|
|
842
857
|
"JBC": "jbc",
|
|
843
858
|
"JOC": "joc",
|
|
844
859
|
"Joltify": "joltify",
|
|
@@ -860,9 +875,11 @@
|
|
|
860
875
|
"Kekchain": "kekchain",
|
|
861
876
|
"Kinto": "kinto",
|
|
862
877
|
"Kintsugi": "kintsugi",
|
|
878
|
+
"KiteAI": "kiteai",
|
|
863
879
|
"Klaytn": "klaytn",
|
|
864
880
|
"Kopi": "kopi",
|
|
865
881
|
"Kroma": "kroma",
|
|
882
|
+
"Krown Network": "krown",
|
|
866
883
|
"Kucoin": "kcc",
|
|
867
884
|
"Kujira": "kujira",
|
|
868
885
|
"Kusama": "kusama",
|
|
@@ -1031,6 +1048,7 @@
|
|
|
1031
1048
|
"Rangers": "rpg",
|
|
1032
1049
|
"Rari": "rari",
|
|
1033
1050
|
"Ravencoin": "rvn",
|
|
1051
|
+
"Rayls": "rls",
|
|
1034
1052
|
"Redbelly": "rbn",
|
|
1035
1053
|
"Redstone": "redstone",
|
|
1036
1054
|
"Reef": "reef",
|
|
@@ -1089,6 +1107,7 @@
|
|
|
1089
1107
|
"Stellar": "stellar",
|
|
1090
1108
|
"Step": "step",
|
|
1091
1109
|
"Story": "sty",
|
|
1110
|
+
"Strat": "strat",
|
|
1092
1111
|
"Stratis": "stratis",
|
|
1093
1112
|
"Strato": "strato",
|
|
1094
1113
|
"Stride": "stride",
|
|
@@ -1200,7 +1219,8 @@
|
|
|
1200
1219
|
"zkLink": "zklink",
|
|
1201
1220
|
"zkLink Nova": "zklink",
|
|
1202
1221
|
"zkSync": "zksync",
|
|
1203
|
-
"zkSync Era": "era"
|
|
1222
|
+
"zkSync Era": "era",
|
|
1223
|
+
"zkVerify": "vfl"
|
|
1204
1224
|
},
|
|
1205
1225
|
"deadChains": {
|
|
1206
1226
|
"airdao": "2026-01-20",
|
package/build/util/env.js
CHANGED
|
@@ -19,7 +19,8 @@ exports.shouldSkipBlockValidation = shouldSkipBlockValidation;
|
|
|
19
19
|
exports.getBoolEnvValue = getBoolEnvValue;
|
|
20
20
|
exports.whitelistedEnvConstants = [
|
|
21
21
|
'R2_ENDPOINT', 'R2_ACCESS_KEY_ID', 'R2_SECRET_ACCESS_KEY', 'TRON_PRO_API_KEY', 'COINS_API_KEY', 'INTERNAL_API_KEY',
|
|
22
|
-
'ELASTICSEARCH_CONFIG', 'GRAPH_API_KEY', 'LLAMA_INDEXER_V2_ENDPOINT', 'LLAMA_INDEXER_V2_API_KEY', 'LLAMA_INDEXER_TIMEOUT_MS'
|
|
22
|
+
'ELASTICSEARCH_CONFIG', 'GRAPH_API_KEY', 'LLAMA_INDEXER_V2_ENDPOINT', 'LLAMA_INDEXER_V2_API_KEY', 'LLAMA_INDEXER_TIMEOUT_MS',
|
|
23
|
+
'LLAMA_INDEXER_V4_ENDPOINT', 'LLAMA_INDEXER_V4_API_KEY', 'LLAMA_INDEXER_PREFER_V4', 'LLAMA_INDEXER_V4_ONLY_CHAINS',
|
|
23
24
|
];
|
|
24
25
|
const isDebugLevel3 = process.env.LLAMA_SDK_DEBUG_LEVEL_3 === 'true';
|
|
25
26
|
const defaultEnvValues = {
|
package/build/util/indexer.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Address } from "../types";
|
|
2
2
|
import { GetTransactionOptions } from "./transactions";
|
|
3
|
+
export type IndexerVersion = "v2" | "v4";
|
|
4
|
+
export declare function getChainIndexerVersion(chain: string): IndexerVersion;
|
|
3
5
|
export declare const supportedChainSet2: Set<string>;
|
|
4
6
|
export type IndexerGetLogsOptions = {
|
|
5
7
|
target?: Address;
|
package/build/util/indexer.js
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
|
+
var _a, _b;
|
|
5
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
7
|
exports.supportedChainSet2 = void 0;
|
|
8
|
+
exports.getChainIndexerVersion = getChainIndexerVersion;
|
|
7
9
|
exports.getLogs = getLogs;
|
|
8
10
|
exports.getTokenTransfers = getTokenTransfers;
|
|
9
11
|
exports.getTransactions = getTransactions;
|
|
@@ -22,8 +24,12 @@ const debugLog_1 = require("./debugLog");
|
|
|
22
24
|
const env_1 = require("./env");
|
|
23
25
|
const logs_1 = require("./logs");
|
|
24
26
|
const logs_decode_shared_1 = require("./logs.decode.shared");
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
+
const LLAMA_INDEXER_V2_ENDPOINT = (0, env_1.getEnvValue)("LLAMA_INDEXER_V2_ENDPOINT");
|
|
28
|
+
const LLAMA_INDEXER_V2_API_KEY = (0, env_1.getEnvValue)("LLAMA_INDEXER_V2_API_KEY");
|
|
29
|
+
const LLAMA_INDEXER_V4_ENDPOINT = (0, env_1.getEnvValue)("LLAMA_INDEXER_V4_ENDPOINT");
|
|
30
|
+
const LLAMA_INDEXER_V4_API_KEY = (_a = (0, env_1.getEnvValue)("LLAMA_INDEXER_V4_API_KEY")) !== null && _a !== void 0 ? _a : LLAMA_INDEXER_V2_API_KEY;
|
|
31
|
+
// route every supported chain through v4 (v2 stays available as explicit config)
|
|
32
|
+
const LLAMA_INDEXER_PREFER_V4 = (0, env_1.getEnvValue)("LLAMA_INDEXER_PREFER_V4") === "true";
|
|
27
33
|
const addressChunkSize = +(0, env_1.getEnvValue)("LLAMA_INDEXER_ADDRESS_CHUNK_SIZE") || 100;
|
|
28
34
|
const INDEXER_REQUEST_TIMEOUT_MS = +(0, env_1.getEnvValue)("LLAMA_INDEXER_TIMEOUT_MS");
|
|
29
35
|
const indexerChainIdChainMapping = {
|
|
@@ -52,43 +58,88 @@ const indexerChainIdChainMapping = {
|
|
|
52
58
|
4326: "megaeth",
|
|
53
59
|
196: "xlayer"
|
|
54
60
|
};
|
|
61
|
+
const v4OnlyChainIdChainMapping = {
|
|
62
|
+
4663: "robinhood",
|
|
63
|
+
};
|
|
64
|
+
((_b = (0, env_1.getEnvValue)("LLAMA_INDEXER_V4_ONLY_CHAINS")) !== null && _b !== void 0 ? _b : "")
|
|
65
|
+
.split(",")
|
|
66
|
+
.map((entry) => entry.trim())
|
|
67
|
+
.filter(Boolean)
|
|
68
|
+
.forEach((entry) => {
|
|
69
|
+
const [chainId, chainName] = entry.split(":").map((i) => i.trim());
|
|
70
|
+
if (!chainId || !chainName || isNaN(+chainId))
|
|
71
|
+
throw new Error(`Invalid LLAMA_INDEXER_V4_ONLY_CHAINS entry: ${entry}`);
|
|
72
|
+
v4OnlyChainIdChainMapping[+chainId] = chainName;
|
|
73
|
+
});
|
|
74
|
+
const allChainIdChainMapping = { ...indexerChainIdChainMapping, ...v4OnlyChainIdChainMapping };
|
|
75
|
+
const v4OnlyChainSet = new Set(Object.values(v4OnlyChainIdChainMapping));
|
|
76
|
+
const indexerConfigs = {
|
|
77
|
+
v2: { endpoint: LLAMA_INDEXER_V2_ENDPOINT, apiKey: LLAMA_INDEXER_V2_API_KEY },
|
|
78
|
+
v4: { endpoint: LLAMA_INDEXER_V4_ENDPOINT, apiKey: LLAMA_INDEXER_V4_API_KEY },
|
|
79
|
+
};
|
|
55
80
|
// http agents for streaming (keep-alive)
|
|
56
81
|
const httpAgent = new http_1.default.Agent({ keepAlive: true, maxSockets: 256, maxFreeSockets: 64 });
|
|
57
82
|
const httpsAgent = new https_1.default.Agent({ keepAlive: true, maxSockets: 256, maxFreeSockets: 64 });
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
83
|
+
const axiosInstances = {
|
|
84
|
+
v2: axios_1.default.create({
|
|
85
|
+
headers: { "x-api-key": LLAMA_INDEXER_V2_API_KEY },
|
|
86
|
+
baseURL: LLAMA_INDEXER_V2_ENDPOINT,
|
|
87
|
+
httpAgent,
|
|
88
|
+
httpsAgent,
|
|
89
|
+
timeout: INDEXER_REQUEST_TIMEOUT_MS,
|
|
90
|
+
}),
|
|
91
|
+
v4: axios_1.default.create({
|
|
92
|
+
headers: { "x-api-key": LLAMA_INDEXER_V4_API_KEY },
|
|
93
|
+
baseURL: LLAMA_INDEXER_V4_ENDPOINT,
|
|
94
|
+
httpAgent,
|
|
95
|
+
httpsAgent,
|
|
96
|
+
timeout: INDEXER_REQUEST_TIMEOUT_MS,
|
|
97
|
+
}),
|
|
98
|
+
};
|
|
99
|
+
function checkIndexerConfig(version) {
|
|
100
|
+
const { endpoint, apiKey } = indexerConfigs[version];
|
|
101
|
+
if (!endpoint || !apiKey)
|
|
102
|
+
throw new Error(`Llama Indexer (${version}) URL/api key is not set`);
|
|
103
|
+
}
|
|
104
|
+
// pick which indexer serves a given chain:
|
|
105
|
+
// - v4-only chains (not indexed on v2) always go to v4
|
|
106
|
+
// - everything else goes to v2, unless LLAMA_INDEXER_PREFER_V4 is set or v2 is not configured
|
|
107
|
+
function getChainIndexerVersion(chain) {
|
|
108
|
+
if (v4OnlyChainSet.has(chain))
|
|
109
|
+
return "v4";
|
|
110
|
+
if (!LLAMA_INDEXER_V4_ENDPOINT)
|
|
111
|
+
return "v2";
|
|
112
|
+
if (LLAMA_INDEXER_PREFER_V4 || !LLAMA_INDEXER_V2_ENDPOINT)
|
|
113
|
+
return "v4";
|
|
114
|
+
return "v2";
|
|
68
115
|
}
|
|
69
116
|
function getChainId(chain) {
|
|
70
117
|
var _a;
|
|
71
|
-
const chainId = (_a = Object.entries(
|
|
118
|
+
const chainId = (_a = Object.entries(allChainIdChainMapping).find(([, chainName]) => chainName === chain)) === null || _a === void 0 ? void 0 : _a[0];
|
|
72
119
|
if (!chainId)
|
|
73
120
|
throw new Error("Chain not supported");
|
|
74
121
|
return +chainId;
|
|
75
122
|
}
|
|
76
123
|
function getSupportedChains() {
|
|
77
|
-
return new Set(Object.values(
|
|
124
|
+
return new Set(Object.values(allChainIdChainMapping));
|
|
78
125
|
}
|
|
79
126
|
exports.supportedChainSet2 = getSupportedChains();
|
|
80
|
-
const
|
|
127
|
+
const syncStates = {
|
|
128
|
+
v2: { chainIndexStatus: {} },
|
|
129
|
+
v4: { chainIndexStatus: {} },
|
|
130
|
+
};
|
|
81
131
|
const cacheTime = 1 * 60 * 1000; // 1 min
|
|
82
|
-
async function getChainIndexStatus() {
|
|
83
|
-
checkIndexerConfig();
|
|
132
|
+
async function getChainIndexStatus(version) {
|
|
133
|
+
checkIndexerConfig(version);
|
|
134
|
+
const state = syncStates[version];
|
|
84
135
|
if (state.timestamp && Date.now() - state.timestamp < cacheTime)
|
|
85
136
|
return state.chainIndexStatus;
|
|
86
137
|
state.timestamp = Date.now();
|
|
87
138
|
state.chainIndexStatus = (async () => {
|
|
88
|
-
const { data: { syncStatus }, } = await
|
|
139
|
+
const { data: { syncStatus }, } = await axiosInstances[version].get(`/sync`).catch((e) => { throw (0, common_1.formError)(e); });
|
|
89
140
|
const info = {};
|
|
90
141
|
syncStatus.forEach((d) => {
|
|
91
|
-
const chain =
|
|
142
|
+
const chain = allChainIdChainMapping[d.chain];
|
|
92
143
|
if (chain) {
|
|
93
144
|
info[chain] = {
|
|
94
145
|
block: d.lastIndexedBlock,
|
|
@@ -104,11 +155,11 @@ async function getChainIndexStatus() {
|
|
|
104
155
|
// Streaming support (disabled by default, opt-in via clientStreaming: true)
|
|
105
156
|
// ---------------------------------------------------------------------------
|
|
106
157
|
async function streamJsonArrayFromIndexer(opts) {
|
|
107
|
-
const { path, arrayKey = "logs", onItem, onChunkStats, shouldStop } = opts;
|
|
158
|
+
const { path, version, arrayKey = "logs", onItem, onChunkStats, shouldStop } = opts;
|
|
108
159
|
const controller = new AbortController();
|
|
109
160
|
let bytesReceived = 0;
|
|
110
161
|
let itemsProcessed = 0;
|
|
111
|
-
const res = await
|
|
162
|
+
const res = await axiosInstances[version].get(path, {
|
|
112
163
|
responseType: "stream",
|
|
113
164
|
timeout: 0,
|
|
114
165
|
maxContentLength: Infinity,
|
|
@@ -198,9 +249,10 @@ async function getLogs(options) {
|
|
|
198
249
|
throw new Error("When noTarget is true, block range must be less than 500k blocks. Please narrow down your block range.");
|
|
199
250
|
}
|
|
200
251
|
// Ensure the indexer is synced far enough
|
|
201
|
-
|
|
252
|
+
const indexerVersion = getChainIndexerVersion(chain);
|
|
253
|
+
checkIndexerConfig(indexerVersion);
|
|
202
254
|
const chainId = getChainId(chain);
|
|
203
|
-
const chainIndexStatus = await getChainIndexStatus();
|
|
255
|
+
const chainIndexStatus = await getChainIndexStatus(indexerVersion);
|
|
204
256
|
const lastIndexedBlock = (_b = (_a = chainIndexStatus[chain]) === null || _a === void 0 ? void 0 : _a.block) !== null && _b !== void 0 ? _b : 0;
|
|
205
257
|
if (lastIndexedBlock < toBlock) {
|
|
206
258
|
const percentageMissing = ((toBlock - lastIndexedBlock) / (toBlock - fromBlock)) * 100;
|
|
@@ -261,7 +313,7 @@ async function getLogs(options) {
|
|
|
261
313
|
// Streaming (opt-in) — NO server-side parsing; mirror legacy semantics
|
|
262
314
|
// -----------------------------------------------------------------------
|
|
263
315
|
if (clientStreaming) {
|
|
264
|
-
const useAll =
|
|
316
|
+
const useAll = all === true;
|
|
265
317
|
const effectiveLimit = useAll ? Number.POSITIVE_INFINITY : ((_d = options.limit) !== null && _d !== void 0 ? _d : limit);
|
|
266
318
|
const shouldLimit = !useAll && Number.isFinite(effectiveLimit);
|
|
267
319
|
const effectiveOffset = useAll ? 0 : ((_f = (_e = options.offset) !== null && _e !== void 0 ? _e : initialOffset) !== null && _f !== void 0 ? _f : 0);
|
|
@@ -368,6 +420,7 @@ async function getLogs(options) {
|
|
|
368
420
|
};
|
|
369
421
|
await streamJsonArrayFromIndexer({
|
|
370
422
|
path: `/logs?${qs.toString()}`,
|
|
423
|
+
version: indexerVersion,
|
|
371
424
|
arrayKey: "logs",
|
|
372
425
|
onItem: (raw) => {
|
|
373
426
|
var _a, _b, _c;
|
|
@@ -437,7 +490,7 @@ async function getLogs(options) {
|
|
|
437
490
|
offset: chunkOffset,
|
|
438
491
|
noTarget,
|
|
439
492
|
};
|
|
440
|
-
const { data: { logs: _logs, totalCount }, } = await
|
|
493
|
+
const { data: { logs: _logs, totalCount }, } = await axiosInstances[indexerVersion](`/logs`, { params }).catch((e) => { throw (0, common_1.formError)(e); });
|
|
441
494
|
const filtered = _logs.filter((l) => {
|
|
442
495
|
var _a, _b, _c;
|
|
443
496
|
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));
|
|
@@ -505,7 +558,8 @@ async function getTokenTransfers({ chain = "ethereum", fromAddressFilter, fromBl
|
|
|
505
558
|
var _a, _b;
|
|
506
559
|
if (!debugMode)
|
|
507
560
|
debugMode = debugLog_1.DEBUG_LEVEL2 && !!env_1.ENV_CONSTANTS.GET_LOGS_INDEXER;
|
|
508
|
-
|
|
561
|
+
const indexerVersion = getChainIndexerVersion(chain);
|
|
562
|
+
checkIndexerConfig(indexerVersion);
|
|
509
563
|
const chainId = getChainId(chain);
|
|
510
564
|
const fromFilterEnabled = !!(fromAddressFilter === null || fromAddressFilter === void 0 ? void 0 : fromAddressFilter.length);
|
|
511
565
|
if (typeof fromAddressFilter === "string")
|
|
@@ -536,8 +590,8 @@ async function getTokenTransfers({ chain = "ethereum", fromAddressFilter, fromBl
|
|
|
536
590
|
throw new Error("target|targets is required");
|
|
537
591
|
targets = targets.map((t) => t.toLowerCase());
|
|
538
592
|
const addresses = targets.join(",");
|
|
539
|
-
// Ensure
|
|
540
|
-
const chainIndexStatus = await getChainIndexStatus();
|
|
593
|
+
// Ensure the indexer is up-to-date
|
|
594
|
+
const chainIndexStatus = await getChainIndexStatus(indexerVersion);
|
|
541
595
|
const lastIndexedBlock = (_b = (_a = chainIndexStatus[chain]) === null || _a === void 0 ? void 0 : _a.block) !== null && _b !== void 0 ? _b : 0;
|
|
542
596
|
if (lastIndexedBlock < toBlock) {
|
|
543
597
|
throw new Error(`Indexer not up to date for ${chain}. Last indexed block: ${lastIndexedBlock}, requested block: ${toBlock}`);
|
|
@@ -576,7 +630,7 @@ async function getTokenTransfers({ chain = "ethereum", fromAddressFilter, fromBl
|
|
|
576
630
|
default:
|
|
577
631
|
throw new Error("Invalid transferType");
|
|
578
632
|
}
|
|
579
|
-
const { data: { transfers: _logs }, } = await
|
|
633
|
+
const { data: { transfers: _logs }, } = await axiosInstances[indexerVersion](`/token-transfers`, { params }).catch((e) => { throw (0, common_1.formError)(e); });
|
|
580
634
|
rawTransfers.push(..._logs);
|
|
581
635
|
currentOffset += limit;
|
|
582
636
|
hasMore = _logs.length === limit;
|
|
@@ -609,13 +663,14 @@ async function getTransactions({ chain = "ethereum", addresses, transaction_hash
|
|
|
609
663
|
var _a, _b;
|
|
610
664
|
if (!debugMode)
|
|
611
665
|
debugMode = debugLog_1.DEBUG_LEVEL2 && !!env_1.ENV_CONSTANTS.GET_LOGS_INDEXER;
|
|
612
|
-
|
|
666
|
+
const indexerVersion = getChainIndexerVersion(chain);
|
|
667
|
+
checkIndexerConfig(indexerVersion);
|
|
613
668
|
const chainId = getChainId(chain);
|
|
614
669
|
if ((!addresses || addresses.length === 0) && (!transaction_hashes || transaction_hashes.length === 0))
|
|
615
670
|
throw new Error("You must provide at least 'addresses' or 'transaction_hashes'");
|
|
616
671
|
if (!from_block || !to_block)
|
|
617
672
|
throw new Error("'from_block' and 'to_block' are required to search for transactions");
|
|
618
|
-
const chainIndexStatus = await getChainIndexStatus();
|
|
673
|
+
const chainIndexStatus = await getChainIndexStatus(indexerVersion);
|
|
619
674
|
const lastIndexedBlock = (_b = (_a = chainIndexStatus[chain]) === null || _a === void 0 ? void 0 : _a.block) !== null && _b !== void 0 ? _b : 0;
|
|
620
675
|
if (to_block > lastIndexedBlock) {
|
|
621
676
|
throw new Error(`Indexer not up to date for ${chain}. Last indexed block: ${lastIndexedBlock}, requested block: ${to_block}`);
|
|
@@ -646,7 +701,7 @@ async function getTransactions({ chain = "ethereum", addresses, transaction_hash
|
|
|
646
701
|
(0, debugLog_1.debugLog)("[Indexer] Pulling transactions " + debugTimeKey);
|
|
647
702
|
console.time(debugTimeKey);
|
|
648
703
|
}
|
|
649
|
-
const { data: { transactions } } = await
|
|
704
|
+
const { data: { transactions } } = await axiosInstances[indexerVersion](`/transactions`, { params }).catch((e) => { throw (0, common_1.formError)(e); });
|
|
650
705
|
if (debugMode) {
|
|
651
706
|
console.timeEnd(debugTimeKey);
|
|
652
707
|
(0, debugLog_1.debugLog)("Transactions pulled " + chain, addresses || transaction_hashes, (transactions === null || transactions === void 0 ? void 0 : transactions.length) || 0);
|
|
@@ -678,11 +733,13 @@ async function getTransactions({ chain = "ethereum", addresses, transaction_hash
|
|
|
678
733
|
}));
|
|
679
734
|
}
|
|
680
735
|
function isIndexerEnabled(chain) {
|
|
681
|
-
if (!
|
|
736
|
+
if (!LLAMA_INDEXER_V2_ENDPOINT && !LLAMA_INDEXER_V4_ENDPOINT)
|
|
682
737
|
return false;
|
|
683
|
-
if (
|
|
738
|
+
if (!chain)
|
|
739
|
+
return true;
|
|
740
|
+
if (!exports.supportedChainSet2.has(chain))
|
|
684
741
|
return false;
|
|
685
|
-
return
|
|
742
|
+
return !!indexerConfigs[getChainIndexerVersion(chain)].endpoint;
|
|
686
743
|
}
|
|
687
744
|
function isIndexer2Enabled(chain) {
|
|
688
745
|
return isIndexerEnabled(chain);
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isIndexerSqlEnabled = isIndexerSqlEnabled;
|
|
7
|
+
exports.queryClickhouse = queryClickhouse;
|
|
8
|
+
const axios_1 = __importDefault(require("axios"));
|
|
9
|
+
const http_1 = __importDefault(require("http"));
|
|
10
|
+
const https_1 = __importDefault(require("https"));
|
|
11
|
+
const env_1 = require("./env");
|
|
12
|
+
const httpAgent = new http_1.default.Agent({ keepAlive: true, maxSockets: 64, maxFreeSockets: 16 });
|
|
13
|
+
const httpsAgent = new https_1.default.Agent({ keepAlive: true, maxSockets: 64, maxFreeSockets: 16 });
|
|
14
|
+
function sqlConfig() {
|
|
15
|
+
return {
|
|
16
|
+
endpoint: (0, env_1.getEnvValue)("LLAMA_INDEXER_SQL_ENDPOINT"),
|
|
17
|
+
user: (0, env_1.getEnvValue)("LLAMA_INDEXER_SQL_USER"),
|
|
18
|
+
password: (0, env_1.getEnvValue)("LLAMA_INDEXER_SQL_PASSWORD"),
|
|
19
|
+
timeoutMs: +(0, env_1.getEnvValue)("LLAMA_INDEXER_SQL_TIMEOUT_MS") || 180000,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function isIndexerSqlEnabled() {
|
|
23
|
+
const c = sqlConfig();
|
|
24
|
+
return !!(c.endpoint && c.user && c.password);
|
|
25
|
+
}
|
|
26
|
+
async function queryClickhouse(sql, params, settings) {
|
|
27
|
+
var _a, _b;
|
|
28
|
+
const { endpoint, user, password, timeoutMs } = sqlConfig();
|
|
29
|
+
if (!endpoint || !user || !password) {
|
|
30
|
+
throw new Error("Llama indexer SQL gateway not configured (LLAMA_INDEXER_SQL_ENDPOINT/USER/PASSWORD)");
|
|
31
|
+
}
|
|
32
|
+
const search = new URLSearchParams();
|
|
33
|
+
search.set("default_format", "JSONEachRow");
|
|
34
|
+
for (const [k, v] of Object.entries(params !== null && params !== void 0 ? params : {})) {
|
|
35
|
+
search.set(`param_${k}`, typeof v === "object" ? JSON.stringify(v) : String(v));
|
|
36
|
+
}
|
|
37
|
+
for (const [k, v] of Object.entries(settings !== null && settings !== void 0 ? settings : {})) {
|
|
38
|
+
search.set(k, String(v));
|
|
39
|
+
}
|
|
40
|
+
let res;
|
|
41
|
+
try {
|
|
42
|
+
res = await axios_1.default.post(`${endpoint}?${search.toString()}`, sql, {
|
|
43
|
+
auth: { username: user, password },
|
|
44
|
+
headers: { "Content-Type": "text/plain; charset=utf-8" },
|
|
45
|
+
responseType: "text",
|
|
46
|
+
transformResponse: (d) => d,
|
|
47
|
+
timeout: timeoutMs,
|
|
48
|
+
maxBodyLength: Infinity,
|
|
49
|
+
maxContentLength: Infinity,
|
|
50
|
+
httpAgent,
|
|
51
|
+
httpsAgent,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
const status = (_a = e === null || e === void 0 ? void 0 : e.response) === null || _a === void 0 ? void 0 : _a.status;
|
|
56
|
+
const body = typeof ((_b = e === null || e === void 0 ? void 0 : e.response) === null || _b === void 0 ? void 0 : _b.data) === "string" ? e.response.data.slice(0, 500) : "";
|
|
57
|
+
throw new Error(`indexer /sql query failed${status ? ` (HTTP ${status})` : ""}: ${body || (e === null || e === void 0 ? void 0 : e.message) || e}`);
|
|
58
|
+
}
|
|
59
|
+
return parseJsonEachRow(res.data);
|
|
60
|
+
}
|
|
61
|
+
function parseJsonEachRow(text) {
|
|
62
|
+
if (!text)
|
|
63
|
+
return [];
|
|
64
|
+
const out = [];
|
|
65
|
+
for (const line of text.split("\n")) {
|
|
66
|
+
if (!line)
|
|
67
|
+
continue;
|
|
68
|
+
out.push(JSON.parse(line));
|
|
69
|
+
}
|
|
70
|
+
return out;
|
|
71
|
+
}
|
package/build/util/logs.js
CHANGED
|
@@ -32,9 +32,6 @@ async function getLogs(options) {
|
|
|
32
32
|
const response = await (0, indexer_1.getLogs)({
|
|
33
33
|
...options,
|
|
34
34
|
all: true, // internal service – always fetch full set
|
|
35
|
-
parseLog: options.parseLog,
|
|
36
|
-
eventAbi: options.eventAbi,
|
|
37
|
-
onlyArgs: options.onlyArgs,
|
|
38
35
|
});
|
|
39
36
|
return response;
|
|
40
37
|
}
|
|
@@ -258,8 +255,12 @@ function toFilterTopic(topic) {
|
|
|
258
255
|
exports.default = getLogs;
|
|
259
256
|
async function getLogParams(options, isIndexerCall = false) {
|
|
260
257
|
let { target, chain = "ethereum", fromBlock, toBlock, fromTimestamp, toTimestamp, eventAbi, topic, topics, extraTopics, entireLog = false, onlyArgs = false, targets = [], noTarget = false, parseLog = false, allowParseFailure = false, processor, flatten = false, } = options;
|
|
261
|
-
|
|
258
|
+
let parseLogWasImplicit = false;
|
|
259
|
+
let parseFailureWarned = false;
|
|
260
|
+
if (eventAbi && !Object.prototype.hasOwnProperty.call(options, "parseLog")) {
|
|
262
261
|
parseLog = true;
|
|
262
|
+
parseLogWasImplicit = true;
|
|
263
|
+
}
|
|
263
264
|
// keep raw log if entireLog=true
|
|
264
265
|
if (entireLog)
|
|
265
266
|
onlyArgs = false;
|
|
@@ -354,9 +355,25 @@ async function getLogParams(options, isIndexerCall = false) {
|
|
|
354
355
|
log.args = undefined;
|
|
355
356
|
}
|
|
356
357
|
else {
|
|
357
|
-
|
|
358
|
-
|
|
358
|
+
const parseFailureTolerated = allowParseFailure || (entireLog && parseLogWasImplicit);
|
|
359
|
+
try {
|
|
360
|
+
parsed = iface.parseLog(log);
|
|
361
|
+
}
|
|
362
|
+
catch (e) {
|
|
363
|
+
if (!parseFailureTolerated)
|
|
364
|
+
throw e;
|
|
365
|
+
parsed = null;
|
|
366
|
+
}
|
|
367
|
+
if (!parsed && !parseFailureTolerated)
|
|
359
368
|
throw new Error(`Failed to parse log: ${JSON.stringify(log.transactionHash)}`);
|
|
369
|
+
// tolerated failures must stay visible: a targeted call where logs silently fail
|
|
370
|
+
// to decode is usually a bug in the caller eventAbi (warn once per call)
|
|
371
|
+
if (!parsed && !allowParseFailure && !parseFailureWarned) {
|
|
372
|
+
parseFailureWarned = true;
|
|
373
|
+
console.warn(`[sdk.getLogs] some logs did not decode against the provided eventAbi and were returned without .args ` +
|
|
374
|
+
`(chain=${chain}, topic0=${topic}, firstTx=${log.transactionHash}). ` +
|
|
375
|
+
`Pass parseLog: true to make this an error, or allowParseFailure: true to silence this warning.`);
|
|
376
|
+
}
|
|
360
377
|
// Enrich args with named properties to match Viem output structure
|
|
361
378
|
if ((parsed === null || parsed === void 0 ? void 0 : parsed.args) && event && iface) {
|
|
362
379
|
log.args = (0, logs_decode_shared_1.enrichEthersArgsWithNamedProperties)(parsed.args, event, iface);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defillama/sdk",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.223",
|
|
4
4
|
"description": "SDK for calculating TVL",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"test": "npm run load-providers && TEST_MODE=true LLAMA_DEBUG_MODE='' SDK_DEBUG='' LLAMA_DEBUG_LEVEL2='' LLAMA_DEBUG_LEVEL3='' jest",
|
|
13
13
|
"test-only": "echo 'skipped building providers.json' && TEST_MODE=true LLAMA_DEBUG_MODE='' SDK_DEBUG='' LLAMA_DEBUG_LEVEL2='' LLAMA_DEBUG_LEVEL3='' jest",
|
|
14
14
|
"test-debug": "TEST_MODE=true jest",
|
|
15
|
+
"test-indexer": "TEST_MODE=true jest src/util/indexer.routing.test.ts src/util/indexer.test.ts src/util/indexer.robinhood.test.ts src/util/indexer.e2e.test.ts --runInBand",
|
|
15
16
|
"update-providers": "ts-node src/util/updateProviderList.ts",
|
|
16
17
|
"remove-rpcs": "ts-node src/util/removeRedundantRPCs.ts",
|
|
17
18
|
"format": "prettier --write \"src/**/*.ts\"",
|