@defillama/sdk 5.0.217 → 5.0.219

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.
@@ -64,29 +64,51 @@ async function readCache(file, options = {}) {
64
64
  return {};
65
65
  }
66
66
  async function readFile() {
67
- const filePath = getFilePath(file);
67
+ var _a;
68
68
  try {
69
- if (options.checkIfRecent) {
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
- if (options.skipR2Cache)
82
- return;
83
- const r2Data = await (0, r2_1.getR2JSONString)(exports.currentVersion + '/' + file);
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",
@@ -305,7 +307,7 @@
305
307
  "metis": "Metis",
306
308
  "mezo": "Mezo",
307
309
  "migaloo": "Migaloo",
308
- "milkomeda": "Milkomeda C1 (Deprecated)",
310
+ "milkomeda": "Milkomeda C1",
309
311
  "milkomeda_a1": "Milkomeda A1",
310
312
  "milkyway": "Milkyway",
311
313
  "milkyway_rollup": "MilkyWay Rollup",
@@ -386,7 +388,7 @@
386
388
  "pharos": "Pharos",
387
389
  "planq": "Planq",
388
390
  "plasma": "Plasma",
389
- "plume": "Plume (Deprecated)",
391
+ "plume": "Plume",
390
392
  "plume_mainnet": "Plume Mainnet",
391
393
  "pokt": "Pokt",
392
394
  "polis": "Polis",
@@ -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",
@@ -971,6 +977,7 @@
971
977
  "Pharos": "pharos",
972
978
  "Planq": "planq",
973
979
  "Plasma": "plasma",
980
+ "Plume": "plume",
974
981
  "Plume (Deprecated)": "plume",
975
982
  "Plume Mainnet": "plume_mainnet",
976
983
  "Pokt": "pokt",
@@ -1013,10 +1020,12 @@
1013
1020
  "Reya Network": "reya",
1014
1021
  "ReyaChain": "reya",
1015
1022
  "Ripple": "ripple",
1023
+ "Robinhood Chain": "robinhood",
1016
1024
  "Robonomics": "robonomics",
1017
1025
  "Rollux": "rollux",
1018
1026
  "Ronin": "ronin",
1019
1027
  "Rootstock": "rsk",
1028
+ "Rubin": "rubin",
1020
1029
  "SKALE": "skale",
1021
1030
  "SKALE Europa": "europa",
1022
1031
  "SX Network": "sx",
@@ -1172,5 +1181,67 @@
1172
1181
  "zkLink Nova": "zklink",
1173
1182
  "zkSync": "zksync",
1174
1183
  "zkSync Era": "era"
1184
+ },
1185
+ "deadChains": {
1186
+ "airdao": "2026-01-20",
1187
+ "artela": "2026-06-05",
1188
+ "astrzk": "2026-02-12",
1189
+ "bitrock": "2026-02-12",
1190
+ "boba_bnb": "2026-01-20",
1191
+ "btnx": "2026-07-09",
1192
+ "chainx": "2026-01-20",
1193
+ "corn": "2026-06-30",
1194
+ "crab": "2026-01-01",
1195
+ "cube": "2026-06-24",
1196
+ "curio": "2026-06-24",
1197
+ "dchainmainnet": "2026-06-24",
1198
+ "dfs": "2026-06-24",
1199
+ "enuls": "2026-03-25",
1200
+ "eon": "2026-02-12",
1201
+ "eos_evm": "2026-02-12",
1202
+ "eventum": "2026-07-01",
1203
+ "evmos": "2026-05-18",
1204
+ "fhe": "2026-06-01",
1205
+ "fluence": "2026-04-08",
1206
+ "functionx": "2026-06-24",
1207
+ "genesys": "2026-03-01",
1208
+ "godwoken": "2026-01-06",
1209
+ "godwoken_v1": "2026-01-06",
1210
+ "grove": "2025-07-28",
1211
+ "ham": "2026-06-05",
1212
+ "heco": "2026-02-12",
1213
+ "inevm": "2026-04-08",
1214
+ "kadena": "2026-02-12",
1215
+ "kardia": "2026-01-20",
1216
+ "kinto": "2026-03-06",
1217
+ "kroma": "2026-01-20",
1218
+ "migaloo": "2026-02-12",
1219
+ "milkomeda": "2026-02-12",
1220
+ "milkomeda_a1": "2026-02-12",
1221
+ "milkyway": "2026-01-20",
1222
+ "milkyway_rollup": "2026-01-20",
1223
+ "mint": "2026-04-17",
1224
+ "nos": "2026-06-24",
1225
+ "nuls": "2026-03-25",
1226
+ "onus": "2026-06-05",
1227
+ "planq": "2026-06-05",
1228
+ "plume": "2026-02-12",
1229
+ "polygon_zkevm": "2026-07-01",
1230
+ "pryzm": "2026-02-09",
1231
+ "qom": "2026-01-20",
1232
+ "real": "2026-02-12",
1233
+ "redstone": "2026-05-18",
1234
+ "rpg": "2026-02-12",
1235
+ "saga": "2026-02-16",
1236
+ "soon_base": "2026-05-25",
1237
+ "stargaze": "2026-06-01",
1238
+ "swellchain": "2026-06-23",
1239
+ "sx": "2026-04-23",
1240
+ "tara": "2026-03-09",
1241
+ "tenet": "2026-04-22",
1242
+ "titan": "2026-05-05",
1243
+ "vision": "2026-02-20",
1244
+ "winr": "2026-05-01",
1245
+ "zksync": "2026-05-15"
1175
1246
  }
1176
1247
  }
@@ -4,3 +4,6 @@ export declare function updateData(): Promise<void>;
4
4
  export declare const sluggifyString: (name: string) => string;
5
5
  export declare function getChainKeyFromLabel(label: string): string;
6
6
  export declare function getChainLabelFromKey(id: string): string;
7
+ export declare function getDeadChains(): string[];
8
+ export declare function getDeadChainsSet(): Set<string>;
9
+ export declare function isDeadChain(chainKeyOrLabel: string): boolean;
@@ -7,12 +7,18 @@ exports.sluggifyString = exports.chainLabelsToKeyMap = exports.chainKeyToChainLa
7
7
  exports.updateData = updateData;
8
8
  exports.getChainKeyFromLabel = getChainKeyFromLabel;
9
9
  exports.getChainLabelFromKey = getChainLabelFromKey;
10
+ exports.getDeadChains = getDeadChains;
11
+ exports.getDeadChainsSet = getDeadChainsSet;
12
+ exports.isDeadChain = isDeadChain;
10
13
  const data_json_1 = require("./data.json");
11
14
  Object.defineProperty(exports, "chainKeyToChainLabelMap", { enumerable: true, get: function () { return data_json_1.chainKeyToChainLabelMap; } });
12
15
  Object.defineProperty(exports, "chainLabelsToKeyMap", { enumerable: true, get: function () { return data_json_1.chainLabelsToKeyMap; } });
13
16
  const fs_1 = __importDefault(require("fs"));
14
17
  const path_1 = __importDefault(require("path"));
18
+ const deadChainsArray = Object.keys(data_json_1.deadChains);
19
+ const deadChainsSet = new Set(deadChainsArray);
15
20
  async function updateData() {
21
+ var _a;
16
22
  try {
17
23
  // mapping pulled from https://github.com/DefiLlama/defillama-server/blob/master/defi/src/utils/normalizeChain.ts
18
24
  const response = await fetch('https://api.llama.fi/overview/_internal/chain-name-id-map-v2');
@@ -23,11 +29,22 @@ async function updateData() {
23
29
  for (const [key, value] of Object.entries(remoteData.chainLabelsToKeyMap)) {
24
30
  data_json_1.chainLabelsToKeyMap[key] = value;
25
31
  }
32
+ // dead chains are pulled from the `deadFrom` field on chainCoingeckoIds entries in https://api.llama.fi/config
33
+ const configResponse = await fetch('https://api.llama.fi/config');
34
+ const config = await configResponse.json();
35
+ for (const [label, value] of Object.entries((_a = config.chainCoingeckoIds) !== null && _a !== void 0 ? _a : {})) {
36
+ const deadFrom = value === null || value === void 0 ? void 0 : value.deadFrom;
37
+ if (!deadFrom)
38
+ continue;
39
+ const key = getChainKeyFromLabel(label);
40
+ data_json_1.deadChains[key] = deadFrom;
41
+ }
26
42
  // Save to data.json file
27
43
  const dataFilePath = path_1.default.join(__dirname, 'data.json');
28
44
  fs_1.default.writeFileSync(dataFilePath, JSON.stringify({
29
45
  chainKeyToChainLabelMap: sortJSONData(data_json_1.chainKeyToChainLabelMap),
30
46
  chainLabelsToKeyMap: sortJSONData(data_json_1.chainLabelsToKeyMap),
47
+ deadChains: sortJSONData(data_json_1.deadChains),
31
48
  }, null, 2));
32
49
  }
33
50
  catch (error) {
@@ -72,3 +89,17 @@ function getChainLabelFromKey(id) {
72
89
  data_json_1.chainKeyToChainLabelMap[id] = value;
73
90
  return value;
74
91
  }
92
+ // returns the map of dead chains keyed by chain key, with the date (YYYY-MM-DD) the chain was marked dead as the value
93
+ function getDeadChains() {
94
+ return deadChainsArray;
95
+ }
96
+ // returns a Set of dead chain keys (cached)
97
+ function getDeadChainsSet() {
98
+ return deadChainsSet;
99
+ }
100
+ // returns true if the given chain (by key or label) is dead
101
+ function isDeadChain(chainKeyOrLabel) {
102
+ if (deadChainsSet.has(chainKeyOrLabel))
103
+ return true;
104
+ return deadChainsSet.has(getChainKeyFromLabel(chainKeyOrLabel));
105
+ }
@@ -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)(5000 + 10000, 5000);
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 restCallWrapper(() => axios_1.default.post(`https://coins.llama.fi/${subRoute}`, body, {
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();
@@ -1,3 +1,4 @@
1
+ export declare const whitelistedEnvConstants: string[];
1
2
  export declare const ENV_CONSTANTS: {
2
3
  [key: string]: string | boolean | undefined;
3
4
  };
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
- const whitelistedEnvConstants = [
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 };
@@ -1,2 +1,4 @@
1
1
  export declare function storeR2JSONString(filename: string, body: string | Buffer): Promise<any>;
2
- export declare function getR2JSONString(filename: string): Promise<any>;
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() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defillama/sdk",
3
- "version": "5.0.217",
3
+ "version": "5.0.219",
4
4
  "description": "SDK for calculating TVL",
5
5
  "main": "build/index.js",
6
6
  "scripts": {