@defillama/sdk 5.0.217 → 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 +5 -0
- package/build/providers.json +1 -1
- package/build/util/cache.js +34 -12
- package/build/util/chainUtils/data.json +8 -0
- package/build/util/coins.js +20 -5
- package/build/util/env.d.ts +1 -0
- package/build/util/env.js +4 -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 = {}) {
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"althea": "Althea",
|
|
26
26
|
"alv": "ALV",
|
|
27
27
|
"ancient8": "Ancient8",
|
|
28
|
+
"anubi": "Anubis",
|
|
28
29
|
"ao": "AO",
|
|
29
30
|
"apechain": "ApeChain",
|
|
30
31
|
"appchain": "Appchain",
|
|
@@ -254,6 +255,7 @@
|
|
|
254
255
|
"joc": "JOC",
|
|
255
256
|
"joltify": "Joltify",
|
|
256
257
|
"juno": "Juno",
|
|
258
|
+
"jupnet": "Jupnet",
|
|
257
259
|
"kadena": "Kadena",
|
|
258
260
|
"kalshi": "Kalshi",
|
|
259
261
|
"karak": "K2",
|
|
@@ -423,12 +425,14 @@
|
|
|
423
425
|
"reya": "ReyaChain",
|
|
424
426
|
"ripple": "XRPL",
|
|
425
427
|
"rise": "RISE",
|
|
428
|
+
"robinhood": "Robinhood Chain",
|
|
426
429
|
"robonomics": "Robonomics",
|
|
427
430
|
"rollux": "Rollux",
|
|
428
431
|
"ronin": "Ronin",
|
|
429
432
|
"rpg": "Rangers",
|
|
430
433
|
"rsk": "Rootstock",
|
|
431
434
|
"rss3_vsl": "RSS3",
|
|
435
|
+
"rubin": "Rubin",
|
|
432
436
|
"rvn": "Ravencoin",
|
|
433
437
|
"saakuru": "Saakuru",
|
|
434
438
|
"saga": "Saga",
|
|
@@ -588,6 +592,7 @@
|
|
|
588
592
|
"AlphaSec": "alphasec",
|
|
589
593
|
"Althea": "althea",
|
|
590
594
|
"Ancient8": "ancient8",
|
|
595
|
+
"Anubis": "anubi",
|
|
591
596
|
"ApeChain": "apechain",
|
|
592
597
|
"Appchain": "appchain",
|
|
593
598
|
"Aptos": "aptos",
|
|
@@ -823,6 +828,7 @@
|
|
|
823
828
|
"JOC": "joc",
|
|
824
829
|
"Joltify": "joltify",
|
|
825
830
|
"Juno": "juno",
|
|
831
|
+
"Jupnet": "jupnet",
|
|
826
832
|
"K2": "karak",
|
|
827
833
|
"KCC": "kcc",
|
|
828
834
|
"KUB": "bitkub",
|
|
@@ -1013,10 +1019,12 @@
|
|
|
1013
1019
|
"Reya Network": "reya",
|
|
1014
1020
|
"ReyaChain": "reya",
|
|
1015
1021
|
"Ripple": "ripple",
|
|
1022
|
+
"Robinhood Chain": "robinhood",
|
|
1016
1023
|
"Robonomics": "robonomics",
|
|
1017
1024
|
"Rollux": "rollux",
|
|
1018
1025
|
"Ronin": "ronin",
|
|
1019
1026
|
"Rootstock": "rsk",
|
|
1027
|
+
"Rubin": "rubin",
|
|
1020
1028
|
"SKALE": "skale",
|
|
1021
1029
|
"SKALE Europa": "europa",
|
|
1022
1030
|
"SX Network": "sx",
|
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,8 +17,8 @@ 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';
|
|
@@ -54,7 +54,7 @@ const _ENV_CONSTANTS = {
|
|
|
54
54
|
GET_LOGS_INDEXER: isDebugLevel3 || process.env.LLAMA_SDK_GET_LOGS_INDEXER === 'true',
|
|
55
55
|
DEFAULT_SHORTEN_STRING_LENGTH: (_a = process.env.LLAMA_SDK_DEFAULT_SHORTEN_STRING_LENGTH) !== null && _a !== void 0 ? _a : '120',
|
|
56
56
|
};
|
|
57
|
-
whitelistedEnvConstants.forEach(key => _ENV_CONSTANTS[key] = getEnvValue(key));
|
|
57
|
+
exports.whitelistedEnvConstants.forEach(key => _ENV_CONSTANTS[key] = getEnvValue(key));
|
|
58
58
|
Object.keys(defaultEnvValues).forEach(key => _ENV_CONSTANTS[key] = getEnvValue(key, defaultEnvValues[key]));
|
|
59
59
|
// doing this as I am paranoid that that empty object when first declared might be exported before values are set
|
|
60
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() {
|