@defillama/sdk 5.0.206 → 5.0.207
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/abi/multicall3.js +4 -0
- package/build/providers.json +1 -1
- package/build/util/cache.d.ts +3 -2
- package/build/util/cache.js +18 -3
- package/build/util/chainUtils/data.json +18 -0
- package/build/util/env.js +1 -1
- package/build/util/indexer.d.ts +0 -15
- package/build/util/indexer.js +37 -130
- package/package.json +1 -1
package/build/util/cache.d.ts
CHANGED
|
@@ -27,17 +27,18 @@ export declare function getTempLocalCache({ file, defaultData, clearAfter, retur
|
|
|
27
27
|
export declare function deleteCache(file: string): Promise<void>;
|
|
28
28
|
export declare function readExpiringJsonCache(file: string): Promise<any>;
|
|
29
29
|
export declare function writeExpiringJsonCache(file: string, data: any, { expireAfter, // cache for 1 day by default
|
|
30
|
-
expiryTimestamp, }
|
|
30
|
+
expiryTimestamp, }?: {
|
|
31
31
|
expireAfter?: number;
|
|
32
32
|
expiryTimestamp?: number;
|
|
33
33
|
}): Promise<void>;
|
|
34
|
-
export declare function cachedFetch({ key, endpoint, postData, fetcher, fetchOptions, errorOnNoCache, writeCacheOptions, readCacheOptions, }: {
|
|
34
|
+
export declare function cachedFetch({ key, endpoint, postData, fetcher, fetchOptions, errorOnNoCache, cacheMaxAge, writeCacheOptions, readCacheOptions, }: {
|
|
35
35
|
key: string;
|
|
36
36
|
endpoint?: string;
|
|
37
37
|
postData?: any;
|
|
38
38
|
fetcher?: () => Promise<any>;
|
|
39
39
|
fetchOptions?: any;
|
|
40
40
|
errorOnNoCache?: boolean;
|
|
41
|
+
cacheMaxAge?: number;
|
|
41
42
|
writeCacheOptions?: WriteCacheOptions;
|
|
42
43
|
readCacheOptions?: ReadCacheOptions;
|
|
43
44
|
}): Promise<any>;
|
package/build/util/cache.js
CHANGED
|
@@ -222,14 +222,14 @@ async function readExpiringJsonCache(file) {
|
|
|
222
222
|
return data.data;
|
|
223
223
|
}
|
|
224
224
|
async function writeExpiringJsonCache(file, data, { expireAfter = 60 * 60 * 24, // cache for 1 day by default
|
|
225
|
-
expiryTimestamp, }) {
|
|
225
|
+
expiryTimestamp, } = {}) {
|
|
226
226
|
file = 'expiring/' + file;
|
|
227
227
|
if (!expiryTimestamp)
|
|
228
228
|
expiryTimestamp = Math.floor(Date.now() / 1e3) + expireAfter;
|
|
229
229
|
const options = { skipR2CacheWrite: true, skipCompression: true };
|
|
230
230
|
await writeCache(file, { data, expiryTimestamp }, options);
|
|
231
231
|
}
|
|
232
|
-
async function cachedFetch({ key, endpoint, postData, fetcher, fetchOptions, errorOnNoCache = true, writeCacheOptions = {
|
|
232
|
+
async function cachedFetch({ key, endpoint, postData, fetcher, fetchOptions, errorOnNoCache = true, cacheMaxAge = 0, writeCacheOptions = {
|
|
233
233
|
skipCompression: true,
|
|
234
234
|
skipR2CacheWrite: true,
|
|
235
235
|
}, readCacheOptions = {
|
|
@@ -242,6 +242,21 @@ async function cachedFetch({ key, endpoint, postData, fetcher, fetchOptions, err
|
|
|
242
242
|
key = (0, common_1.getHash)(endpoint);
|
|
243
243
|
}
|
|
244
244
|
const fileKey = 'cached-fetch/' + key;
|
|
245
|
+
// check local cache first
|
|
246
|
+
if (cacheMaxAge > 0) {
|
|
247
|
+
try {
|
|
248
|
+
const filePath = getFilePath(readCacheOptions.skipCompression ? `${fileKey}-uncompressed` : fileKey);
|
|
249
|
+
const stats = await fs.stat(filePath);
|
|
250
|
+
if (Date.now() - stats.mtimeMs < cacheMaxAge) {
|
|
251
|
+
const cachedData = await readCache(fileKey, readCacheOptions);
|
|
252
|
+
if (cachedData && Object.keys(cachedData).length > 0)
|
|
253
|
+
return cachedData;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
// cache miss or stat error, proceed to fetch
|
|
258
|
+
}
|
|
259
|
+
}
|
|
245
260
|
try {
|
|
246
261
|
let data;
|
|
247
262
|
if (fetcher)
|
|
@@ -260,7 +275,7 @@ async function cachedFetch({ key, endpoint, postData, fetcher, fetchOptions, err
|
|
|
260
275
|
catch (error) {
|
|
261
276
|
const errorMessage = (0, common_1.formError)(error).message;
|
|
262
277
|
(0, debugLog_1.debugLog)('Error in cachedFetch:', errorMessage);
|
|
263
|
-
// if fetch fails, read from cache
|
|
278
|
+
// if fetch fails, read from cache (regardless of age)
|
|
264
279
|
const cachedData = await readCache(fileKey, readCacheOptions);
|
|
265
280
|
if (!cachedData && errorOnNoCache)
|
|
266
281
|
throw new Error('Fetch failed and no cache available');
|
|
@@ -84,6 +84,7 @@
|
|
|
84
84
|
"chihuahua": "Chihuahua",
|
|
85
85
|
"chromia": "Chromia",
|
|
86
86
|
"chz": "Chiliz",
|
|
87
|
+
"citrea": "Citrea",
|
|
87
88
|
"civitia": "Civitia",
|
|
88
89
|
"clv": "CLV",
|
|
89
90
|
"cmp": "CMP",
|
|
@@ -238,6 +239,7 @@
|
|
|
238
239
|
"katana": "Katana",
|
|
239
240
|
"kava": "Kava",
|
|
240
241
|
"kcc": "KCC",
|
|
242
|
+
"keeta": "Keeta",
|
|
241
243
|
"kekchain": "Kekchain",
|
|
242
244
|
"kinto": "Kinto",
|
|
243
245
|
"kintsugi": "Kintsugi",
|
|
@@ -297,6 +299,7 @@
|
|
|
297
299
|
"muuchain": "MUUCHAIN",
|
|
298
300
|
"mvc": "MVC",
|
|
299
301
|
"mxczkevm": "Moonchain",
|
|
302
|
+
"n1": "N1",
|
|
300
303
|
"nahmii": "Nahmii",
|
|
301
304
|
"naka": "Naka",
|
|
302
305
|
"namada": "Namada",
|
|
@@ -327,6 +330,7 @@
|
|
|
327
330
|
"ontology_evm": "OntologyEVM",
|
|
328
331
|
"onus": "Onus",
|
|
329
332
|
"op_bnb": "opBNB",
|
|
333
|
+
"open": "Open",
|
|
330
334
|
"optimism": "OP Mainnet",
|
|
331
335
|
"orai": "Oraichain",
|
|
332
336
|
"orderly": "Orderly Network",
|
|
@@ -341,6 +345,7 @@
|
|
|
341
345
|
"parex": "Parex",
|
|
342
346
|
"peaq": "Peaq",
|
|
343
347
|
"penumbra": "Penumbra",
|
|
348
|
+
"pepu": "Pepu",
|
|
344
349
|
"perennial": "Perennial",
|
|
345
350
|
"persistence": "Persistence One",
|
|
346
351
|
"pg": "Pego",
|
|
@@ -419,6 +424,7 @@
|
|
|
419
424
|
"soon_bsc": "svmBNB",
|
|
420
425
|
"sophon": "Sophon",
|
|
421
426
|
"sora": "Sora",
|
|
427
|
+
"spark": "Spark",
|
|
422
428
|
"spn": "Superposition",
|
|
423
429
|
"sseed": "Superseed",
|
|
424
430
|
"stable": "Stable",
|
|
@@ -464,7 +470,9 @@
|
|
|
464
470
|
"ultron": "Ultron",
|
|
465
471
|
"umee": "UX",
|
|
466
472
|
"unichain": "Unichain",
|
|
473
|
+
"union": "Union",
|
|
467
474
|
"unit0": "Unit Zero",
|
|
475
|
+
"valuechain": "ValueChain",
|
|
468
476
|
"vana": "Vana",
|
|
469
477
|
"vechain": "VeChain",
|
|
470
478
|
"velas": "Velas",
|
|
@@ -494,6 +502,7 @@
|
|
|
494
502
|
"xrplevm": "XRPL EVM",
|
|
495
503
|
"xsat": "exSat",
|
|
496
504
|
"yomi": "Yominet",
|
|
505
|
+
"zcash": "Zcash",
|
|
497
506
|
"zeniq": "Zeniq",
|
|
498
507
|
"zenrock": "Zenrock",
|
|
499
508
|
"zero_network": "Zero Network",
|
|
@@ -598,6 +607,7 @@
|
|
|
598
607
|
"Chihuahua": "chihuahua",
|
|
599
608
|
"Chiliz": "chz",
|
|
600
609
|
"Chromia": "chromia",
|
|
610
|
+
"Citrea": "citrea",
|
|
601
611
|
"Civitia": "civitia",
|
|
602
612
|
"Comdex": "comdex",
|
|
603
613
|
"Concordium": "concordium",
|
|
@@ -752,6 +762,7 @@
|
|
|
752
762
|
"Kasplex": "kasplex",
|
|
753
763
|
"Katana": "katana",
|
|
754
764
|
"Kava": "kava",
|
|
765
|
+
"Keeta": "keeta",
|
|
755
766
|
"Kekchain": "kekchain",
|
|
756
767
|
"Kinto": "kinto",
|
|
757
768
|
"Kintsugi": "kintsugi",
|
|
@@ -818,6 +829,7 @@
|
|
|
818
829
|
"Movement": "move",
|
|
819
830
|
"MultiVAC": "multivac",
|
|
820
831
|
"MultiversX": "elrond",
|
|
832
|
+
"N1": "n1",
|
|
821
833
|
"NEO": "neo",
|
|
822
834
|
"NOS": "nos",
|
|
823
835
|
"Nahmii": "nahmii",
|
|
@@ -853,6 +865,7 @@
|
|
|
853
865
|
"OntologyEVM": "ontology_evm",
|
|
854
866
|
"Onus": "onus",
|
|
855
867
|
"Op_Bnb": "op_bnb",
|
|
868
|
+
"Open": "open",
|
|
856
869
|
"OpenGPU": "ogpu",
|
|
857
870
|
"Optimism": "optimism",
|
|
858
871
|
"Orai": "orai",
|
|
@@ -870,6 +883,7 @@
|
|
|
870
883
|
"Peaq": "peaq",
|
|
871
884
|
"Pego": "pg",
|
|
872
885
|
"Penumbra": "penumbra",
|
|
886
|
+
"Pepu": "pepu",
|
|
873
887
|
"Perennial": "perennial",
|
|
874
888
|
"Persistence": "persistence",
|
|
875
889
|
"Persistence One": "persistence",
|
|
@@ -951,6 +965,7 @@
|
|
|
951
965
|
"Soon Network": "soon",
|
|
952
966
|
"Sophon": "sophon",
|
|
953
967
|
"Sora": "sora",
|
|
968
|
+
"Spark": "spark",
|
|
954
969
|
"Stable": "stable",
|
|
955
970
|
"Stacks": "stacks",
|
|
956
971
|
"Stafi": "stafi",
|
|
@@ -996,7 +1011,9 @@
|
|
|
996
1011
|
"Ultron": "ultron",
|
|
997
1012
|
"Umee": "umee",
|
|
998
1013
|
"Unichain": "unichain",
|
|
1014
|
+
"Union": "union",
|
|
999
1015
|
"Unit Zero": "unit0",
|
|
1016
|
+
"ValueChain": "valuechain",
|
|
1000
1017
|
"Vana": "vana",
|
|
1001
1018
|
"Vaulta": "eos",
|
|
1002
1019
|
"VeChain": "vechain",
|
|
@@ -1034,6 +1051,7 @@
|
|
|
1034
1051
|
"ZKsync Era": "era",
|
|
1035
1052
|
"ZKsync Lite": "zksync",
|
|
1036
1053
|
"ZYX": "zyx",
|
|
1054
|
+
"Zcash": "zcash",
|
|
1037
1055
|
"Zeniq": "zeniq",
|
|
1038
1056
|
"Zenrock": "zenrock",
|
|
1039
1057
|
"Zero Network": "zero_network",
|
package/build/util/env.js
CHANGED
|
@@ -19,7 +19,7 @@ exports.shouldSkipBlockValidation = shouldSkipBlockValidation;
|
|
|
19
19
|
exports.getBoolEnvValue = getBoolEnvValue;
|
|
20
20
|
const whitelistedEnvConstants = [
|
|
21
21
|
'R2_ENDPOINT', 'R2_ACCESS_KEY_ID', 'R2_SECRET_ACCESS_KEY', 'TRON_PRO_API_KEY', 'COINS_API_KEY',
|
|
22
|
-
'ELASTICSEARCH_CONFIG', 'GRAPH_API_KEY', '
|
|
22
|
+
'ELASTICSEARCH_CONFIG', 'GRAPH_API_KEY', 'LLAMA_INDEXER_V2_ENDPOINT', 'LLAMA_INDEXER_V2_API_KEY', 'LLAMA_INDEXER_TIMEOUT_MS'
|
|
23
23
|
];
|
|
24
24
|
const isDebugLevel3 = process.env.LLAMA_SDK_DEBUG_LEVEL_3 === 'true';
|
|
25
25
|
const defaultEnvValues = {
|
package/build/util/indexer.d.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { Address } from "../types";
|
|
2
2
|
import { GetTransactionOptions } from "./transactions";
|
|
3
|
-
export declare const supportedChainSet: Set<string>;
|
|
4
3
|
export declare const supportedChainSet2: Set<string>;
|
|
5
|
-
declare enum TokenTypes {
|
|
6
|
-
ERC20 = "erc20",
|
|
7
|
-
ERC721 = "erc721"
|
|
8
|
-
}
|
|
9
4
|
export type IndexerGetLogsOptions = {
|
|
10
5
|
target?: Address;
|
|
11
6
|
topic?: string;
|
|
@@ -66,18 +61,8 @@ export type IndexerGetTokenTransfersOptions = {
|
|
|
66
61
|
tokens?: string | string[];
|
|
67
62
|
token?: string;
|
|
68
63
|
};
|
|
69
|
-
export declare function getTokens(address: string | string[], { onlyWhitelisted, skipCacheRead, skipCache, chain, tokenType, }?: {
|
|
70
|
-
onlyWhitelisted?: boolean;
|
|
71
|
-
skipCacheRead?: boolean;
|
|
72
|
-
skipCache?: boolean;
|
|
73
|
-
chain?: string;
|
|
74
|
-
tokenType?: TokenTypes;
|
|
75
|
-
}): Promise<{
|
|
76
|
-
[chain: string]: string[];
|
|
77
|
-
}>;
|
|
78
64
|
export declare function getLogs(options: IndexerGetLogsOptions): Promise<any[]>;
|
|
79
65
|
export declare function getTokenTransfers({ chain, fromAddressFilter, fromBlock, toBlock, all, limit, offset, target, targets, flatten, fromTimestamp, toTimestamp, debugMode, transferType, token, tokens, }: IndexerGetTokenTransfersOptions): Promise<any[]>;
|
|
80
66
|
export declare function getTransactions({ chain, addresses, transaction_hashes, from_block, to_block, all, limit, offset, debugMode, transactionType, }: GetTransactionOptions): Promise<any>;
|
|
81
67
|
export declare function isIndexerEnabled(chain?: string): boolean;
|
|
82
68
|
export declare function isIndexer2Enabled(chain?: string): boolean;
|
|
83
|
-
export {};
|
package/build/util/indexer.js
CHANGED
|
@@ -3,8 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.supportedChainSet2 =
|
|
7
|
-
exports.getTokens = getTokens;
|
|
6
|
+
exports.supportedChainSet2 = void 0;
|
|
8
7
|
exports.getLogs = getLogs;
|
|
9
8
|
exports.getTokenTransfers = getTokenTransfers;
|
|
10
9
|
exports.getTransactions = getTransactions;
|
|
@@ -17,21 +16,16 @@ const stream_json_1 = require("stream-json");
|
|
|
17
16
|
const Pick_1 = require("stream-json/filters/Pick");
|
|
18
17
|
const StreamArray_1 = require("stream-json/streamers/StreamArray");
|
|
19
18
|
const _1 = require(".");
|
|
20
|
-
const general_1 = require("../general");
|
|
21
19
|
const blocks_1 = require("./blocks");
|
|
22
|
-
const cache_1 = require("./cache");
|
|
23
20
|
const common_1 = require("./common");
|
|
24
21
|
const debugLog_1 = require("./debugLog");
|
|
25
22
|
const env_1 = require("./env");
|
|
26
23
|
const logs_1 = require("./logs");
|
|
27
24
|
const logs_decode_shared_1 = require("./logs.decode.shared");
|
|
28
|
-
const
|
|
29
|
-
const LLAMA_INDEXER_API_KEY = (0, env_1.getEnvValue)("
|
|
30
|
-
const LLAMA_INDEXER_V2_ENDPOINT = (0, env_1.getEnvValue)("LLAMA_INDEXER_V2_ENDPOINT");
|
|
31
|
-
const LLAMA_INDEXER_V2_API_KEY = (0, env_1.getEnvValue)("LLAMA_INDEXER_V2_API_KEY");
|
|
25
|
+
const LLAMA_INDEXER_ENDPOINT = (0, env_1.getEnvValue)("LLAMA_INDEXER_V2_ENDPOINT");
|
|
26
|
+
const LLAMA_INDEXER_API_KEY = (0, env_1.getEnvValue)("LLAMA_INDEXER_V2_API_KEY");
|
|
32
27
|
const addressChunkSize = +(0, env_1.getEnvValue)("LLAMA_INDEXER_ADDRESS_CHUNK_SIZE") || 100;
|
|
33
28
|
const INDEXER_REQUEST_TIMEOUT_MS = +(0, env_1.getEnvValue)("LLAMA_INDEXER_TIMEOUT_MS");
|
|
34
|
-
// v1 chains (still used for balances endpoint)
|
|
35
29
|
const indexerChainIdChainMapping = {
|
|
36
30
|
1: "ethereum",
|
|
37
31
|
10: "optimism",
|
|
@@ -39,7 +33,6 @@ const indexerChainIdChainMapping = {
|
|
|
39
33
|
100: "xdai",
|
|
40
34
|
137: "polygon",
|
|
41
35
|
204: "op_bnb",
|
|
42
|
-
250: "fantom",
|
|
43
36
|
324: "era",
|
|
44
37
|
1101: "polygon_zkevm",
|
|
45
38
|
8453: "base",
|
|
@@ -51,79 +44,51 @@ const indexerChainIdChainMapping = {
|
|
|
51
44
|
81457: "blast",
|
|
52
45
|
534352: "scroll",
|
|
53
46
|
146: "sonic",
|
|
54
|
-
};
|
|
55
|
-
// v2 chains (superset of v1)
|
|
56
|
-
const indexer2ChainIdChainMapping = {
|
|
57
|
-
...indexerChainIdChainMapping,
|
|
58
47
|
130: "unichain",
|
|
59
48
|
1868: "soneium",
|
|
60
49
|
80094: "berachain",
|
|
61
50
|
999: "hyperliquid",
|
|
62
51
|
143: "monad",
|
|
63
52
|
4326: "megaeth",
|
|
64
|
-
|
|
65
|
-
const indexerConfigs = {
|
|
66
|
-
v1: {
|
|
67
|
-
endpoint: indexerURL,
|
|
68
|
-
apiKey: LLAMA_INDEXER_API_KEY,
|
|
69
|
-
chainMapping: indexerChainIdChainMapping,
|
|
70
|
-
},
|
|
71
|
-
v2: {
|
|
72
|
-
endpoint: LLAMA_INDEXER_V2_ENDPOINT,
|
|
73
|
-
apiKey: LLAMA_INDEXER_V2_API_KEY,
|
|
74
|
-
chainMapping: indexer2ChainIdChainMapping,
|
|
75
|
-
},
|
|
53
|
+
196: "xlayer"
|
|
76
54
|
};
|
|
77
55
|
// http agents for streaming (keep-alive)
|
|
78
56
|
const httpAgent = new http_1.default.Agent({ keepAlive: true, maxSockets: 256, maxFreeSockets: 64 });
|
|
79
57
|
const httpsAgent = new https_1.default.Agent({ keepAlive: true, maxSockets: 256, maxFreeSockets: 64 });
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
httpsAgent,
|
|
91
|
-
timeout: INDEXER_REQUEST_TIMEOUT_MS,
|
|
92
|
-
}),
|
|
93
|
-
};
|
|
94
|
-
function checkIndexerConfig(version) {
|
|
95
|
-
const config = indexerConfigs[version];
|
|
96
|
-
if (!config.endpoint || !config.apiKey)
|
|
97
|
-
throw new Error(`Llama Indexer ${version} URL/api key is not set`);
|
|
58
|
+
const axiosInstance = axios_1.default.create({
|
|
59
|
+
headers: { "x-api-key": LLAMA_INDEXER_API_KEY },
|
|
60
|
+
baseURL: LLAMA_INDEXER_ENDPOINT,
|
|
61
|
+
httpAgent,
|
|
62
|
+
httpsAgent,
|
|
63
|
+
timeout: INDEXER_REQUEST_TIMEOUT_MS,
|
|
64
|
+
});
|
|
65
|
+
function checkIndexerConfig() {
|
|
66
|
+
if (!LLAMA_INDEXER_ENDPOINT || !LLAMA_INDEXER_API_KEY)
|
|
67
|
+
throw new Error(`Llama Indexer URL/api key is not set`);
|
|
98
68
|
}
|
|
99
|
-
function getChainId(chain
|
|
69
|
+
function getChainId(chain) {
|
|
100
70
|
var _a;
|
|
101
|
-
const chainId = (_a = Object.entries(
|
|
71
|
+
const chainId = (_a = Object.entries(indexerChainIdChainMapping).find(([, chainName]) => chainName === chain)) === null || _a === void 0 ? void 0 : _a[0];
|
|
102
72
|
if (!chainId)
|
|
103
73
|
throw new Error("Chain not supported");
|
|
104
74
|
return +chainId;
|
|
105
75
|
}
|
|
106
|
-
function getSupportedChains(
|
|
107
|
-
return new Set(Object.values(
|
|
76
|
+
function getSupportedChains() {
|
|
77
|
+
return new Set(Object.values(indexerChainIdChainMapping));
|
|
108
78
|
}
|
|
109
|
-
exports.
|
|
110
|
-
exports.supportedChainSet2 = getSupportedChains("v2");
|
|
111
|
-
const chainToIDMapping = {};
|
|
112
|
-
Object.entries(indexerConfigs.v1.chainMapping).forEach(([id, chain]) => {
|
|
113
|
-
chainToIDMapping[chain] = +id;
|
|
114
|
-
});
|
|
79
|
+
exports.supportedChainSet2 = getSupportedChains();
|
|
115
80
|
const state = { chainIndexStatus: {} };
|
|
116
81
|
const cacheTime = 1 * 60 * 1000; // 1 min
|
|
117
|
-
async function getChainIndexStatus(
|
|
118
|
-
checkIndexerConfig(
|
|
82
|
+
async function getChainIndexStatus() {
|
|
83
|
+
checkIndexerConfig();
|
|
119
84
|
if (state.timestamp && Date.now() - state.timestamp < cacheTime)
|
|
120
85
|
return state.chainIndexStatus;
|
|
121
86
|
state.timestamp = Date.now();
|
|
122
87
|
state.chainIndexStatus = (async () => {
|
|
123
|
-
const { data: { syncStatus }, } = await
|
|
88
|
+
const { data: { syncStatus }, } = await axiosInstance.get(`/sync`).catch((e) => { throw (0, common_1.formError)(e); });
|
|
124
89
|
const info = {};
|
|
125
90
|
syncStatus.forEach((d) => {
|
|
126
|
-
const chain =
|
|
91
|
+
const chain = indexerChainIdChainMapping[d.chain];
|
|
127
92
|
if (chain) {
|
|
128
93
|
info[chain] = {
|
|
129
94
|
block: d.lastIndexedBlock,
|
|
@@ -135,64 +100,6 @@ async function getChainIndexStatus(version = "v2") {
|
|
|
135
100
|
})();
|
|
136
101
|
return state.chainIndexStatus;
|
|
137
102
|
}
|
|
138
|
-
var TokenTypes;
|
|
139
|
-
(function (TokenTypes) {
|
|
140
|
-
TokenTypes["ERC20"] = "erc20";
|
|
141
|
-
TokenTypes["ERC721"] = "erc721";
|
|
142
|
-
})(TokenTypes || (TokenTypes = {}));
|
|
143
|
-
async function getTokens(address, { onlyWhitelisted = true, skipCacheRead = false, skipCache = false, chain, tokenType, } = {}) {
|
|
144
|
-
var _a, _b;
|
|
145
|
-
checkIndexerConfig("v1");
|
|
146
|
-
if (!address)
|
|
147
|
-
throw new Error("Address is required either as a string or an array of strings");
|
|
148
|
-
if (Array.isArray(address) && !address.length)
|
|
149
|
-
throw new Error("Address array cannot be empty");
|
|
150
|
-
if (Array.isArray(address))
|
|
151
|
-
address = address.join(",");
|
|
152
|
-
address = address.toLowerCase();
|
|
153
|
-
let chainId;
|
|
154
|
-
if (chain)
|
|
155
|
-
chainId = chainToIDMapping[chain];
|
|
156
|
-
const project = "llama-indexer-cache";
|
|
157
|
-
const key = onlyWhitelisted ? address : `${address}/all`;
|
|
158
|
-
const file = `${project}/${key}`;
|
|
159
|
-
const timeNow = Math.floor(Date.now() / 1e3);
|
|
160
|
-
const THREE_DAYS = 3 * 24 * 3600;
|
|
161
|
-
let cache = {};
|
|
162
|
-
if (!skipCacheRead && !skipCache) {
|
|
163
|
-
cache = (_a = (await (0, cache_1.readCache)(file))) !== null && _a !== void 0 ? _a : {};
|
|
164
|
-
if (cache.timestamp && timeNow - cache.timestamp < THREE_DAYS)
|
|
165
|
-
return cache.tokens;
|
|
166
|
-
}
|
|
167
|
-
if (env_1.ENV_CONSTANTS.GET_LOGS_INDEXER)
|
|
168
|
-
(0, debugLog_1.debugLog)("[Indexer] Pulling tokens for " + address);
|
|
169
|
-
const tokens = (_b = cache.tokens) !== null && _b !== void 0 ? _b : {};
|
|
170
|
-
const { data: { balances }, } = await axiosInstances.v1(`/balances`, {
|
|
171
|
-
params: {
|
|
172
|
-
addresses: address,
|
|
173
|
-
chainId,
|
|
174
|
-
type: tokenType,
|
|
175
|
-
},
|
|
176
|
-
}).catch(e => { throw (0, common_1.formError)(e); });
|
|
177
|
-
balances
|
|
178
|
-
.filter((b) => +b.total_amount > 0)
|
|
179
|
-
.forEach((b) => {
|
|
180
|
-
const chain = indexerConfigs.v1.chainMapping[b.chain];
|
|
181
|
-
if (!chain)
|
|
182
|
-
return;
|
|
183
|
-
if (!tokens[chain])
|
|
184
|
-
tokens[chain] = [];
|
|
185
|
-
tokens[chain].push(b.address);
|
|
186
|
-
});
|
|
187
|
-
const tokenCache = { timestamp: timeNow, tokens };
|
|
188
|
-
Object.entries(tokens).forEach(([chain, values]) => {
|
|
189
|
-
values.push(general_1.ETHER_ADDRESS);
|
|
190
|
-
tokens[chain] = (0, common_1.getUniqueAddresses)(values);
|
|
191
|
-
});
|
|
192
|
-
if (!skipCache)
|
|
193
|
-
await (0, cache_1.writeCache)(file, tokenCache);
|
|
194
|
-
return tokens;
|
|
195
|
-
}
|
|
196
103
|
// ---------------------------------------------------------------------------
|
|
197
104
|
// Streaming support (disabled by default, opt-in via clientStreaming: true)
|
|
198
105
|
// ---------------------------------------------------------------------------
|
|
@@ -201,7 +108,7 @@ async function streamJsonArrayFromIndexer(opts) {
|
|
|
201
108
|
const controller = new AbortController();
|
|
202
109
|
let bytesReceived = 0;
|
|
203
110
|
let itemsProcessed = 0;
|
|
204
|
-
const res = await
|
|
111
|
+
const res = await axiosInstance.get(path, {
|
|
205
112
|
responseType: "stream",
|
|
206
113
|
timeout: 0,
|
|
207
114
|
maxContentLength: Infinity,
|
|
@@ -291,9 +198,9 @@ async function getLogs(options) {
|
|
|
291
198
|
throw new Error("When noTarget is true, block range must be less than 500k blocks. Please narrow down your block range.");
|
|
292
199
|
}
|
|
293
200
|
// Ensure the indexer is synced far enough
|
|
294
|
-
checkIndexerConfig(
|
|
295
|
-
const chainId = getChainId(chain
|
|
296
|
-
const chainIndexStatus = await getChainIndexStatus(
|
|
201
|
+
checkIndexerConfig();
|
|
202
|
+
const chainId = getChainId(chain);
|
|
203
|
+
const chainIndexStatus = await getChainIndexStatus();
|
|
297
204
|
const lastIndexedBlock = (_b = (_a = chainIndexStatus[chain]) === null || _a === void 0 ? void 0 : _a.block) !== null && _b !== void 0 ? _b : 0;
|
|
298
205
|
if (lastIndexedBlock < toBlock) {
|
|
299
206
|
const percentageMissing = ((toBlock - lastIndexedBlock) / (toBlock - fromBlock)) * 100;
|
|
@@ -526,7 +433,7 @@ async function getLogs(options) {
|
|
|
526
433
|
offset: chunkOffset,
|
|
527
434
|
noTarget,
|
|
528
435
|
};
|
|
529
|
-
const { data: { logs: _logs, totalCount }, } = await
|
|
436
|
+
const { data: { logs: _logs, totalCount }, } = await axiosInstance(`/logs`, { params }).catch(e => { throw (0, common_1.formError)(e); });
|
|
530
437
|
const filtered = _logs.filter((l) => {
|
|
531
438
|
var _a, _b, _c;
|
|
532
439
|
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));
|
|
@@ -594,8 +501,8 @@ async function getTokenTransfers({ chain = "ethereum", fromAddressFilter, fromBl
|
|
|
594
501
|
var _a, _b;
|
|
595
502
|
if (!debugMode)
|
|
596
503
|
debugMode = debugLog_1.DEBUG_LEVEL2 && !!env_1.ENV_CONSTANTS.GET_LOGS_INDEXER;
|
|
597
|
-
checkIndexerConfig(
|
|
598
|
-
const chainId = getChainId(chain
|
|
504
|
+
checkIndexerConfig();
|
|
505
|
+
const chainId = getChainId(chain);
|
|
599
506
|
const fromFilterEnabled = !!(fromAddressFilter === null || fromAddressFilter === void 0 ? void 0 : fromAddressFilter.length);
|
|
600
507
|
if (typeof fromAddressFilter === "string")
|
|
601
508
|
fromAddressFilter = [fromAddressFilter];
|
|
@@ -626,7 +533,7 @@ async function getTokenTransfers({ chain = "ethereum", fromAddressFilter, fromBl
|
|
|
626
533
|
targets = targets.map((t) => t.toLowerCase());
|
|
627
534
|
const addresses = targets.join(",");
|
|
628
535
|
// Ensure v2 indexer is up-to-date
|
|
629
|
-
const chainIndexStatus = await getChainIndexStatus(
|
|
536
|
+
const chainIndexStatus = await getChainIndexStatus();
|
|
630
537
|
const lastIndexedBlock = (_b = (_a = chainIndexStatus[chain]) === null || _a === void 0 ? void 0 : _a.block) !== null && _b !== void 0 ? _b : 0;
|
|
631
538
|
if (lastIndexedBlock < toBlock) {
|
|
632
539
|
throw new Error(`Indexer not up to date for ${chain}. Last indexed block: ${lastIndexedBlock}, requested block: ${toBlock}`);
|
|
@@ -665,7 +572,7 @@ async function getTokenTransfers({ chain = "ethereum", fromAddressFilter, fromBl
|
|
|
665
572
|
default:
|
|
666
573
|
throw new Error("Invalid transferType");
|
|
667
574
|
}
|
|
668
|
-
const { data: { transfers: _logs }, } = await
|
|
575
|
+
const { data: { transfers: _logs }, } = await axiosInstance(`/token-transfers`, { params }).catch(e => { throw (0, common_1.formError)(e); });
|
|
669
576
|
rawTransfers.push(..._logs);
|
|
670
577
|
currentOffset += limit;
|
|
671
578
|
hasMore = _logs.length === limit;
|
|
@@ -698,13 +605,13 @@ async function getTransactions({ chain = "ethereum", addresses, transaction_hash
|
|
|
698
605
|
var _a, _b;
|
|
699
606
|
if (!debugMode)
|
|
700
607
|
debugMode = debugLog_1.DEBUG_LEVEL2 && !!env_1.ENV_CONSTANTS.GET_LOGS_INDEXER;
|
|
701
|
-
checkIndexerConfig(
|
|
702
|
-
const chainId = getChainId(chain
|
|
608
|
+
checkIndexerConfig();
|
|
609
|
+
const chainId = getChainId(chain);
|
|
703
610
|
if ((!addresses || addresses.length === 0) && (!transaction_hashes || transaction_hashes.length === 0))
|
|
704
611
|
throw new Error("You must provide at least 'addresses' or 'transaction_hashes'");
|
|
705
612
|
if (!from_block || !to_block)
|
|
706
613
|
throw new Error("'from_block' and 'to_block' are required to search for transactions");
|
|
707
|
-
const chainIndexStatus = await getChainIndexStatus(
|
|
614
|
+
const chainIndexStatus = await getChainIndexStatus();
|
|
708
615
|
const lastIndexedBlock = (_b = (_a = chainIndexStatus[chain]) === null || _a === void 0 ? void 0 : _a.block) !== null && _b !== void 0 ? _b : 0;
|
|
709
616
|
if (to_block > lastIndexedBlock) {
|
|
710
617
|
throw new Error(`Indexer not up to date for ${chain}. Last indexed block: ${lastIndexedBlock}, requested block: ${to_block}`);
|
|
@@ -735,7 +642,7 @@ async function getTransactions({ chain = "ethereum", addresses, transaction_hash
|
|
|
735
642
|
(0, debugLog_1.debugLog)("[Indexer] Pulling transactions " + debugTimeKey);
|
|
736
643
|
console.time(debugTimeKey);
|
|
737
644
|
}
|
|
738
|
-
const { data: { transactions } } = await
|
|
645
|
+
const { data: { transactions } } = await axiosInstance(`/transactions`, { params }).catch(e => { throw (0, common_1.formError)(e); });
|
|
739
646
|
if (debugMode) {
|
|
740
647
|
console.timeEnd(debugTimeKey);
|
|
741
648
|
(0, debugLog_1.debugLog)("Transactions pulled " + chain, addresses || transaction_hashes, (transactions === null || transactions === void 0 ? void 0 : transactions.length) || 0);
|
|
@@ -767,7 +674,7 @@ async function getTransactions({ chain = "ethereum", addresses, transaction_hash
|
|
|
767
674
|
}));
|
|
768
675
|
}
|
|
769
676
|
function isIndexerEnabled(chain) {
|
|
770
|
-
if (!
|
|
677
|
+
if (!LLAMA_INDEXER_ENDPOINT)
|
|
771
678
|
return false;
|
|
772
679
|
if (chain && !exports.supportedChainSet2.has(chain))
|
|
773
680
|
return false;
|