@defillama/sdk 5.0.216 → 5.0.218
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 +9 -1
- package/build/providers.json +1 -1
- package/build/util/cache.js +34 -12
- package/build/util/chainUtils/data.json +21 -1
- package/build/util/coins.js +20 -5
- package/build/util/env.d.ts +1 -0
- package/build/util/env.js +8 -4
- package/build/util/r2.d.ts +3 -1
- package/build/util/r2.js +3 -1
- package/package.json +1 -1
package/build/util/cache.js
CHANGED
|
@@ -64,29 +64,51 @@ async function readCache(file, options = {}) {
|
|
|
64
64
|
return {};
|
|
65
65
|
}
|
|
66
66
|
async function readFile() {
|
|
67
|
-
|
|
67
|
+
var _a;
|
|
68
68
|
try {
|
|
69
|
-
|
|
70
|
-
const stats = await fs.stat(filePath);
|
|
71
|
-
if (Date.now() - stats.mtimeMs > ONE_DAY_IN_MS)
|
|
72
|
-
throw new Error('File too old, read from R2 instead');
|
|
73
|
-
}
|
|
74
|
-
if (options.readFromR2Cache)
|
|
75
|
-
throw new Error('Read from R2 cache');
|
|
76
|
-
const data = await fs.readFile(filePath);
|
|
69
|
+
const data = await readDataFromLocal((_a = options.readFromR2Cache) !== null && _a !== void 0 ? _a : false);
|
|
77
70
|
return data;
|
|
78
71
|
}
|
|
79
72
|
catch (error) {
|
|
80
73
|
// debugLog('Error reading cache:', error)
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
74
|
+
return readDataFromR2();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async function readDataFromLocal(readFromR2Cache) {
|
|
78
|
+
const filePath = getFilePath(file);
|
|
79
|
+
if (options.checkIfRecent) {
|
|
80
|
+
const stats = await fs.stat(filePath);
|
|
81
|
+
if (Date.now() - stats.mtimeMs > ONE_DAY_IN_MS)
|
|
82
|
+
throw new Error('File too old, read from R2 instead');
|
|
83
|
+
}
|
|
84
|
+
if (readFromR2Cache)
|
|
85
|
+
throw new Error('Read from R2 cache');
|
|
86
|
+
const data = await fs.readFile(filePath);
|
|
87
|
+
return data;
|
|
88
|
+
}
|
|
89
|
+
async function readDataFromR2() {
|
|
90
|
+
var _a;
|
|
91
|
+
if (options.skipR2Cache)
|
|
92
|
+
return;
|
|
93
|
+
try {
|
|
94
|
+
const r2Data = await (0, r2_1.getR2JSONString)(exports.currentVersion + '/' + file, { throwErrorOnFail: (_a = options.readFromR2Cache) !== null && _a !== void 0 ? _a : false });
|
|
84
95
|
if (r2Data) {
|
|
85
96
|
// `file` already carries the `-uncompressed` suffix (added above), so omit skipCompression here to avoid writeCache appending it again
|
|
86
97
|
await writeCache(file, r2Data, { alreadyCompressed: true, skipR2CacheWrite: true });
|
|
87
98
|
return r2Data;
|
|
88
99
|
}
|
|
89
100
|
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
if (options.readFromR2Cache) {
|
|
103
|
+
// if we were forced to read from R2 cache, try reading from local cache if R2 fails
|
|
104
|
+
try {
|
|
105
|
+
const data = await readDataFromLocal(false);
|
|
106
|
+
return data;
|
|
107
|
+
}
|
|
108
|
+
catch (_e) { }
|
|
109
|
+
}
|
|
110
|
+
return {};
|
|
111
|
+
}
|
|
90
112
|
}
|
|
91
113
|
}
|
|
92
114
|
async function writeCache(file, data, options = {}) {
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"chainKeyToChainLabelMap": {
|
|
3
3
|
"0g": "0G",
|
|
4
|
+
"Ethereum": "Ethereum",
|
|
4
5
|
"abstract": "Abstract",
|
|
5
6
|
"acala": "Acala",
|
|
6
7
|
"ace": "Endurance",
|
|
8
|
+
"adi": "ADI",
|
|
7
9
|
"adventure_layer": "Adventure Layer",
|
|
8
10
|
"aelf": "aelf",
|
|
9
11
|
"aeternity": "Aeternity",
|
|
12
|
+
"afx": "AFX L1",
|
|
10
13
|
"agoric": "Agoric",
|
|
11
14
|
"ailayer": "AILayer",
|
|
12
15
|
"airdao": "AirDAO",
|
|
@@ -22,6 +25,7 @@
|
|
|
22
25
|
"althea": "Althea",
|
|
23
26
|
"alv": "ALV",
|
|
24
27
|
"ancient8": "Ancient8",
|
|
28
|
+
"anubi": "Anubis",
|
|
25
29
|
"ao": "AO",
|
|
26
30
|
"apechain": "ApeChain",
|
|
27
31
|
"appchain": "Appchain",
|
|
@@ -39,6 +43,7 @@
|
|
|
39
43
|
"aura": "Aura Network",
|
|
40
44
|
"aurora": "Aurora",
|
|
41
45
|
"avax": "Avalanche",
|
|
46
|
+
"b3": "B3",
|
|
42
47
|
"babylon": "Babylon Genesis",
|
|
43
48
|
"band": "BandChain",
|
|
44
49
|
"base": "Base",
|
|
@@ -101,6 +106,7 @@
|
|
|
101
106
|
"concordium": "Concordium",
|
|
102
107
|
"conflux": "Conflux",
|
|
103
108
|
"constellation": "Constellation",
|
|
109
|
+
"cookiechain": "CookieChain",
|
|
104
110
|
"core": "CORE",
|
|
105
111
|
"corn": "Corn",
|
|
106
112
|
"cosmos": "CosmosHub",
|
|
@@ -249,6 +255,7 @@
|
|
|
249
255
|
"joc": "JOC",
|
|
250
256
|
"joltify": "Joltify",
|
|
251
257
|
"juno": "Juno",
|
|
258
|
+
"jupnet": "Jupnet",
|
|
252
259
|
"kadena": "Kadena",
|
|
253
260
|
"kalshi": "Kalshi",
|
|
254
261
|
"karak": "K2",
|
|
@@ -418,12 +425,14 @@
|
|
|
418
425
|
"reya": "ReyaChain",
|
|
419
426
|
"ripple": "XRPL",
|
|
420
427
|
"rise": "RISE",
|
|
428
|
+
"robinhood": "Robinhood Chain",
|
|
421
429
|
"robonomics": "Robonomics",
|
|
422
430
|
"rollux": "Rollux",
|
|
423
431
|
"ronin": "Ronin",
|
|
424
432
|
"rpg": "Rangers",
|
|
425
433
|
"rsk": "Rootstock",
|
|
426
434
|
"rss3_vsl": "RSS3",
|
|
435
|
+
"rubin": "Rubin",
|
|
427
436
|
"rvn": "Ravencoin",
|
|
428
437
|
"saakuru": "Saakuru",
|
|
429
438
|
"saga": "Saga",
|
|
@@ -472,7 +481,7 @@
|
|
|
472
481
|
"stratis": "Stratis",
|
|
473
482
|
"strato": "Strato",
|
|
474
483
|
"stride": "Stride",
|
|
475
|
-
"sty": "
|
|
484
|
+
"sty": "Data Network",
|
|
476
485
|
"sui": "Sui",
|
|
477
486
|
"supra": "Supra",
|
|
478
487
|
"svm": "SatoshiVM",
|
|
@@ -535,6 +544,7 @@
|
|
|
535
544
|
"xdc": "XDC",
|
|
536
545
|
"xion": "XION",
|
|
537
546
|
"xlayer": "X Layer",
|
|
547
|
+
"xo": "XO",
|
|
538
548
|
"xone": "Xone Chain",
|
|
539
549
|
"xp": "Xphere",
|
|
540
550
|
"xpla": "XPLA",
|
|
@@ -560,6 +570,8 @@
|
|
|
560
570
|
"chainLabelsToKeyMap": {
|
|
561
571
|
"0G": "0g",
|
|
562
572
|
"AB": "new",
|
|
573
|
+
"ADI": "adi",
|
|
574
|
+
"AFX L1": "afx",
|
|
563
575
|
"AILayer": "ailayer",
|
|
564
576
|
"ALEO": "aleo",
|
|
565
577
|
"ALV": "alv",
|
|
@@ -580,6 +592,7 @@
|
|
|
580
592
|
"AlphaSec": "alphasec",
|
|
581
593
|
"Althea": "althea",
|
|
582
594
|
"Ancient8": "ancient8",
|
|
595
|
+
"Anubis": "anubi",
|
|
583
596
|
"ApeChain": "apechain",
|
|
584
597
|
"Appchain": "appchain",
|
|
585
598
|
"Aptos": "aptos",
|
|
@@ -597,6 +610,7 @@
|
|
|
597
610
|
"Aura Network": "aura",
|
|
598
611
|
"Aurora": "aurora",
|
|
599
612
|
"Avalanche": "avax",
|
|
613
|
+
"B3": "b3",
|
|
600
614
|
"BCHyper": "bcypher",
|
|
601
615
|
"BESC Hyperchain": "besc",
|
|
602
616
|
"BEVM": "chainx",
|
|
@@ -663,6 +677,7 @@
|
|
|
663
677
|
"Concordium": "concordium",
|
|
664
678
|
"Conflux": "conflux",
|
|
665
679
|
"Constellation": "constellation",
|
|
680
|
+
"CookieChain": "cookiechain",
|
|
666
681
|
"Corn": "corn",
|
|
667
682
|
"Cosmos": "cosmos",
|
|
668
683
|
"CosmosHub": "cosmos",
|
|
@@ -683,6 +698,7 @@
|
|
|
683
698
|
"Dango Mainnet": "dango",
|
|
684
699
|
"Darwinia": "darwinia",
|
|
685
700
|
"Dash": "dash",
|
|
701
|
+
"Data Network": "sty",
|
|
686
702
|
"DeFiChain EVM": "defichain_evm",
|
|
687
703
|
"DeFiVerse": "defiverse",
|
|
688
704
|
"Defi Oracle Meta": "dfio_meta_main",
|
|
@@ -812,6 +828,7 @@
|
|
|
812
828
|
"JOC": "joc",
|
|
813
829
|
"Joltify": "joltify",
|
|
814
830
|
"Juno": "juno",
|
|
831
|
+
"Jupnet": "jupnet",
|
|
815
832
|
"K2": "karak",
|
|
816
833
|
"KCC": "kcc",
|
|
817
834
|
"KUB": "bitkub",
|
|
@@ -1002,10 +1019,12 @@
|
|
|
1002
1019
|
"Reya Network": "reya",
|
|
1003
1020
|
"ReyaChain": "reya",
|
|
1004
1021
|
"Ripple": "ripple",
|
|
1022
|
+
"Robinhood Chain": "robinhood",
|
|
1005
1023
|
"Robonomics": "robonomics",
|
|
1006
1024
|
"Rollux": "rollux",
|
|
1007
1025
|
"Ronin": "ronin",
|
|
1008
1026
|
"Rootstock": "rsk",
|
|
1027
|
+
"Rubin": "rubin",
|
|
1009
1028
|
"SKALE": "skale",
|
|
1010
1029
|
"SKALE Europa": "europa",
|
|
1011
1030
|
"SX Network": "sx",
|
|
@@ -1119,6 +1138,7 @@
|
|
|
1119
1138
|
"XCHAIN": "idex",
|
|
1120
1139
|
"XDC": "xdc",
|
|
1121
1140
|
"XION": "xion",
|
|
1141
|
+
"XO": "xo",
|
|
1122
1142
|
"XPLA": "xpla",
|
|
1123
1143
|
"XPR Network": "proton",
|
|
1124
1144
|
"XRPL": "ripple",
|
package/build/util/coins.js
CHANGED
|
@@ -11,6 +11,7 @@ const promisePool_1 = __importDefault(require("./promisePool"));
|
|
|
11
11
|
const common_1 = require("./common");
|
|
12
12
|
const _1 = require(".");
|
|
13
13
|
const coinsApiKey = (0, env_1.getEnvValue)("COINS_API_KEY");
|
|
14
|
+
const proApiKey = (0, env_1.getEnvValue)("INTERNAL_API_KEY");
|
|
14
15
|
const bodySize = 100;
|
|
15
16
|
function getBodies(readKeys, timestamp) {
|
|
16
17
|
const chunks = (0, _1.sliceIntoChunks)(readKeys, bodySize);
|
|
@@ -31,9 +32,26 @@ async function restCallWrapper(request, retries = 3, name = "-") {
|
|
|
31
32
|
if (retries <= 0)
|
|
32
33
|
throw (0, common_1.formError)(e);
|
|
33
34
|
}
|
|
34
|
-
await (0, common_1.sleepRandom)(
|
|
35
|
+
await (0, common_1.sleepRandom)(2000 + 10000, 2000);
|
|
35
36
|
return restCallWrapper(request, retries, name);
|
|
36
37
|
}
|
|
38
|
+
async function fetchWithProFallback(body, subRoute) {
|
|
39
|
+
// if pro api key is set, try the pro route first and fall back to the normal route on failure
|
|
40
|
+
if (proApiKey) {
|
|
41
|
+
try {
|
|
42
|
+
return await restCallWrapper(() => axios_1.default.post(`https://pro-api.llama.fi/${proApiKey}/coins/${subRoute}`, body, {
|
|
43
|
+
headers: { "Content-Type": "application/json" },
|
|
44
|
+
}), 2);
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
// fall through to the normal route below
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return restCallWrapper(() => axios_1.default.post(`https://coins.llama.fi/${subRoute}`, body, {
|
|
51
|
+
headers: { "Content-Type": "application/json" },
|
|
52
|
+
params: { source: "internal", apikey: coinsApiKey },
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
37
55
|
const priceCacheAll = {
|
|
38
56
|
now: {
|
|
39
57
|
"coingecko:tether": {
|
|
@@ -74,10 +92,7 @@ async function getPricesData(readKeys, timestamp, dataType) {
|
|
|
74
92
|
processor: async (body) => {
|
|
75
93
|
if (!body.coins.length)
|
|
76
94
|
return;
|
|
77
|
-
const res = await
|
|
78
|
-
headers: { "Content-Type": "application/json" },
|
|
79
|
-
params: { source: "internal", apikey: coinsApiKey },
|
|
80
|
-
}));
|
|
95
|
+
const res = await fetchWithProFallback(body, subRoute);
|
|
81
96
|
const data = dataType === "price" ? res.data.coins : res.data;
|
|
82
97
|
Object.entries(data).forEach(([PK, value]) => {
|
|
83
98
|
const pkNormalized = PK.toLowerCase();
|
package/build/util/env.d.ts
CHANGED
package/build/util/env.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.ENV_CONSTANTS = void 0;
|
|
4
|
+
exports.ENV_CONSTANTS = exports.whitelistedEnvConstants = void 0;
|
|
5
5
|
exports.getChainId = getChainId;
|
|
6
6
|
exports.getMaxParallelRequests = getMaxParallelRequests;
|
|
7
7
|
exports.getParallelGetLogsLimit = getParallelGetLogsLimit;
|
|
@@ -17,12 +17,16 @@ exports.getChainRPCs = getChainRPCs;
|
|
|
17
17
|
exports.getWhitelistedRPCs = getWhitelistedRPCs;
|
|
18
18
|
exports.shouldSkipBlockValidation = shouldSkipBlockValidation;
|
|
19
19
|
exports.getBoolEnvValue = getBoolEnvValue;
|
|
20
|
-
|
|
21
|
-
'R2_ENDPOINT', 'R2_ACCESS_KEY_ID', 'R2_SECRET_ACCESS_KEY', 'TRON_PRO_API_KEY', 'COINS_API_KEY',
|
|
20
|
+
exports.whitelistedEnvConstants = [
|
|
21
|
+
'R2_ENDPOINT', 'R2_ACCESS_KEY_ID', 'R2_SECRET_ACCESS_KEY', 'TRON_PRO_API_KEY', 'COINS_API_KEY', 'INTERNAL_API_KEY',
|
|
22
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 = {
|
|
26
|
+
EVMOS_MULTICALL_CHUNK_SIZE: "3", // evmos reduced gas limit, this is a workaround to make multicall work
|
|
27
|
+
CRONOS_MULTICALL_CHUNK_SIZE: "10", // cronos reduced gas limit, this is a workaround to make multicall work
|
|
28
|
+
HEDERA_MULTICALL_CHUNK_SIZE: "50", // cronos reduced gas limit, this is a workaround to make multicall work
|
|
29
|
+
KATANA_MULTICALL_CHUNK_SIZE: "50",
|
|
26
30
|
INTERNAL_SDK_CACHE_FILE: './cache.json',
|
|
27
31
|
TRON_RPC_CONCURRENCY_LIMIT: '5',
|
|
28
32
|
LLAMA_INDEXER_ADDRESS_CHUNK_SIZE: '20',
|
|
@@ -50,7 +54,7 @@ const _ENV_CONSTANTS = {
|
|
|
50
54
|
GET_LOGS_INDEXER: isDebugLevel3 || process.env.LLAMA_SDK_GET_LOGS_INDEXER === 'true',
|
|
51
55
|
DEFAULT_SHORTEN_STRING_LENGTH: (_a = process.env.LLAMA_SDK_DEFAULT_SHORTEN_STRING_LENGTH) !== null && _a !== void 0 ? _a : '120',
|
|
52
56
|
};
|
|
53
|
-
whitelistedEnvConstants.forEach(key => _ENV_CONSTANTS[key] = getEnvValue(key));
|
|
57
|
+
exports.whitelistedEnvConstants.forEach(key => _ENV_CONSTANTS[key] = getEnvValue(key));
|
|
54
58
|
Object.keys(defaultEnvValues).forEach(key => _ENV_CONSTANTS[key] = getEnvValue(key, defaultEnvValues[key]));
|
|
55
59
|
// doing this as I am paranoid that that empty object when first declared might be exported before values are set
|
|
56
60
|
exports.ENV_CONSTANTS = { ..._ENV_CONSTANTS };
|
package/build/util/r2.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export declare function storeR2JSONString(filename: string, body: string | Buffer): Promise<any>;
|
|
2
|
-
export declare function getR2JSONString(filename: string
|
|
2
|
+
export declare function getR2JSONString(filename: string, { throwErrorOnFail }?: {
|
|
3
|
+
throwErrorOnFail?: boolean | undefined;
|
|
4
|
+
}): Promise<any>;
|
package/build/util/r2.js
CHANGED
|
@@ -33,7 +33,7 @@ async function storeR2JSONString(filename, body) {
|
|
|
33
33
|
});
|
|
34
34
|
return R2.send(command);
|
|
35
35
|
}
|
|
36
|
-
async function getR2JSONString(filename) {
|
|
36
|
+
async function getR2JSONString(filename, { throwErrorOnFail = false } = {}) {
|
|
37
37
|
try {
|
|
38
38
|
if (!R2)
|
|
39
39
|
return await _fetchData();
|
|
@@ -42,6 +42,8 @@ async function getR2JSONString(filename) {
|
|
|
42
42
|
return await Body.transformToString();
|
|
43
43
|
}
|
|
44
44
|
catch (e) {
|
|
45
|
+
if (throwErrorOnFail)
|
|
46
|
+
throw e;
|
|
45
47
|
return {};
|
|
46
48
|
}
|
|
47
49
|
async function _fetchData() {
|