@defillama/sdk 5.0.204 → 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.
@@ -0,0 +1,6 @@
1
+ import { chainKeyToChainLabelMap, chainLabelsToKeyMap } from './data.json';
2
+ export { chainKeyToChainLabelMap, chainLabelsToKeyMap, };
3
+ export declare function updateData(): Promise<void>;
4
+ export declare const sluggifyString: (name: string) => string;
5
+ export declare function getChainKeyFromLabel(label: string): string;
6
+ export declare function getChainLabelFromKey(id: string): string;
@@ -0,0 +1,74 @@
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.sluggifyString = exports.chainLabelsToKeyMap = exports.chainKeyToChainLabelMap = void 0;
7
+ exports.updateData = updateData;
8
+ exports.getChainKeyFromLabel = getChainKeyFromLabel;
9
+ exports.getChainLabelFromKey = getChainLabelFromKey;
10
+ const data_json_1 = require("./data.json");
11
+ Object.defineProperty(exports, "chainKeyToChainLabelMap", { enumerable: true, get: function () { return data_json_1.chainKeyToChainLabelMap; } });
12
+ Object.defineProperty(exports, "chainLabelsToKeyMap", { enumerable: true, get: function () { return data_json_1.chainLabelsToKeyMap; } });
13
+ const fs_1 = __importDefault(require("fs"));
14
+ const path_1 = __importDefault(require("path"));
15
+ async function updateData() {
16
+ try {
17
+ // mapping pulled from https://github.com/DefiLlama/defillama-server/blob/master/defi/src/utils/normalizeChain.ts
18
+ const response = await fetch('https://api.llama.fi/overview/_internal/chain-name-id-map-v2');
19
+ const remoteData = await response.json();
20
+ for (const [key, value] of Object.entries(remoteData.chainKeyToChainLabelMap)) {
21
+ data_json_1.chainKeyToChainLabelMap[key] = value;
22
+ }
23
+ for (const [key, value] of Object.entries(remoteData.chainLabelsToKeyMap)) {
24
+ data_json_1.chainLabelsToKeyMap[key] = value;
25
+ }
26
+ // Save to data.json file
27
+ const dataFilePath = path_1.default.join(__dirname, 'data.json');
28
+ fs_1.default.writeFileSync(dataFilePath, JSON.stringify({
29
+ chainKeyToChainLabelMap: sortJSONData(data_json_1.chainKeyToChainLabelMap),
30
+ chainLabelsToKeyMap: sortJSONData(data_json_1.chainLabelsToKeyMap),
31
+ }, null, 2));
32
+ }
33
+ catch (error) {
34
+ console.error('Error updating chain data:', error);
35
+ }
36
+ }
37
+ const sluggifyString = (name) => name.toLowerCase().split(" ").join("-").split("'").join("");
38
+ exports.sluggifyString = sluggifyString;
39
+ function sortJSONData(jsonData) {
40
+ const sortedKeys = Object.keys(jsonData).sort();
41
+ const sortedData = {};
42
+ for (const key of sortedKeys) {
43
+ sortedData[key] = jsonData[key];
44
+ }
45
+ return sortedData;
46
+ }
47
+ const _chainLabelToChainIdCache = {};
48
+ Object.entries(data_json_1.chainLabelsToKeyMap).forEach(([label, id]) => {
49
+ _chainLabelToChainIdCache[label] = id;
50
+ _chainLabelToChainIdCache[(0, exports.sluggifyString)(label)] = id;
51
+ });
52
+ // to be used if we are unsure if a label exists in our system, if it is known, use chainLabelsToKeyMap instead
53
+ function getChainKeyFromLabel(label) {
54
+ let value = _chainLabelToChainIdCache[label];
55
+ if (!value) {
56
+ let sluggifiedLabel = (0, exports.sluggifyString)(label);
57
+ value = _chainLabelToChainIdCache[sluggifiedLabel];
58
+ if (!value) {
59
+ value = sluggifiedLabel.replace(/\-/g, '_'); // try replacing - with _
60
+ _chainLabelToChainIdCache[sluggifiedLabel] = value;
61
+ }
62
+ _chainLabelToChainIdCache[label] = value;
63
+ }
64
+ return value;
65
+ }
66
+ // to be used if we are unsure if a label exists in our system, if it is known, use chainKeyToChainLabelMap instead
67
+ function getChainLabelFromKey(id) {
68
+ let value = data_json_1.chainKeyToChainLabelMap[id];
69
+ if (value)
70
+ return value;
71
+ value = id.slice(0, 1).toUpperCase() + id.slice(1); // Capitalize first letter
72
+ data_json_1.chainKeyToChainLabelMap[id] = value;
73
+ return value;
74
+ }
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', 'LLAMA_INDEXER_ENDPOINT', 'LLAMA_INDEXER_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
23
  ];
24
24
  const isDebugLevel3 = process.env.LLAMA_SDK_DEBUG_LEVEL_3 === 'true';
25
25
  const defaultEnvValues = {
@@ -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 {};
@@ -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 = exports.supportedChainSet = void 0;
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 indexerURL = (0, env_1.getEnvValue)("LLAMA_INDEXER_ENDPOINT");
29
- const LLAMA_INDEXER_API_KEY = (0, env_1.getEnvValue)("LLAMA_INDEXER_API_KEY");
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 axiosInstances = {
81
- v1: axios_1.default.create({
82
- headers: { "x-api-key": indexerConfigs.v1.apiKey },
83
- baseURL: indexerConfigs.v1.endpoint,
84
- timeout: INDEXER_REQUEST_TIMEOUT_MS,
85
- }),
86
- v2: axios_1.default.create({
87
- headers: { "x-api-key": indexerConfigs.v2.apiKey },
88
- baseURL: indexerConfigs.v2.endpoint,
89
- httpAgent,
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, version = "v2") {
69
+ function getChainId(chain) {
100
70
  var _a;
101
- const chainId = (_a = Object.entries(indexerConfigs[version].chainMapping).find(([, chainName]) => chainName === chain)) === null || _a === void 0 ? void 0 : _a[0];
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(version = "v2") {
107
- return new Set(Object.values(indexerConfigs[version].chainMapping));
76
+ function getSupportedChains() {
77
+ return new Set(Object.values(indexerChainIdChainMapping));
108
78
  }
109
- exports.supportedChainSet = getSupportedChains("v1"); // legacy
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(version = "v2") {
118
- checkIndexerConfig(version);
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 axiosInstances[version].get(`/sync`).catch(e => { throw (0, common_1.formError)(e); });
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 = indexerConfigs[version].chainMapping[d.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 axiosInstances.v2.get(path, {
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("v2");
295
- const chainId = getChainId(chain, "v2");
296
- const chainIndexStatus = await getChainIndexStatus("v2");
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 axiosInstances.v2(`/logs`, { params }).catch(e => { throw (0, common_1.formError)(e); });
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("v2");
598
- const chainId = getChainId(chain, "v2");
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("v2");
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 axiosInstances.v2(`/token-transfers`, { params }).catch(e => { throw (0, common_1.formError)(e); });
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("v2");
702
- const chainId = getChainId(chain, "v2");
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("v2");
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 axiosInstances.v2(`/transactions`, { params }).catch(e => { throw (0, common_1.formError)(e); });
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 (!indexerConfigs.v2.endpoint)
677
+ if (!LLAMA_INDEXER_ENDPOINT)
771
678
  return false;
772
679
  if (chain && !exports.supportedChainSet2.has(chain))
773
680
  return false;
@@ -8,6 +8,7 @@ const fs_1 = __importDefault(require("fs"));
8
8
  const debugLog_1 = require("./debugLog");
9
9
  const promise_pool_1 = __importDefault(require("@supercharge/promise-pool"));
10
10
  const generalUtil_1 = require("../generalUtil");
11
+ const chainUtils_1 = require("../util/chainUtils");
11
12
  const concurrentCheckChains = +(process.env.SDK_BUILD_CONCURRENT_CHAINS || 7);
12
13
  const chainRemovalThreshold = +(process.env.SDK_BUILD_CHAIN_REMOVAL_THRESHOLD || 20);
13
14
  const droppedTestnetChainsSet = new Set([]);
@@ -28,6 +29,21 @@ async function getChainData() {
28
29
  }
29
30
  }
30
31
  async function main() {
32
+ const chainKeyLabelMapCountBefore = Object.keys(chainUtils_1.chainKeyToChainLabelMap).length;
33
+ const chainLabelsKeyMapCountBefore = Object.keys(chainUtils_1.chainLabelsToKeyMap).length;
34
+ await (0, chainUtils_1.updateData)();
35
+ const chainKeyLabelMapCountAfter = Object.keys(chainUtils_1.chainKeyToChainLabelMap).length;
36
+ const chainLabelsKeyMapCountAfter = Object.keys(chainUtils_1.chainLabelsToKeyMap).length;
37
+ if (chainKeyLabelMapCountAfter > chainKeyLabelMapCountBefore) {
38
+ console.log(`Updated chainKeyToChainLabelMap: ${chainKeyLabelMapCountBefore} -> ${chainKeyLabelMapCountAfter}`);
39
+ }
40
+ if (chainLabelsKeyMapCountAfter > chainLabelsKeyMapCountBefore) {
41
+ console.log(`Updated chainLabelsToKeyMap: ${chainLabelsKeyMapCountBefore} -> ${chainLabelsKeyMapCountAfter}`);
42
+ }
43
+ if (chainKeyLabelMapCountAfter < chainKeyLabelMapCountBefore)
44
+ throw new Error('chainKeyToChainLabelMap count decreased, please investigate');
45
+ if (chainLabelsKeyMapCountAfter < chainLabelsKeyMapCountBefore)
46
+ throw new Error('chainLabelsToKeyMap count decreased, please investigate');
31
47
  const oldProviders = await (0, generalUtil_1.fetchJson)(`https://unpkg.com/@defillama/sdk@latest/build/providers.json`);
32
48
  const currentChains = await (0, generalUtil_1.fetchJson)(`https://raw.githubusercontent.com/DefiLlama/DefiLlama-Adapters/refs/heads/main/projects/helper/chains.json`);
33
49
  const currentChainsSet = new Set(currentChains);
@@ -121,6 +137,15 @@ async function main() {
121
137
  continue;
122
138
  providerList[key] = providerList[shorName];
123
139
  }
140
+ // add from the old providers any missing rpcs that is in the tvl chain list
141
+ Object.entries(oldProviders).forEach(([key, i]) => {
142
+ if (!currentChainsSet.has(key))
143
+ return;
144
+ if (providerList[key])
145
+ return;
146
+ console.log(`Adding missing chain ${key} from old providers`);
147
+ providerList[key] = i;
148
+ });
124
149
  const droppedChains = Object.keys(oldProviders).filter(oldChain => providerList[oldChain] === undefined);
125
150
  const filteredDroppedChains = droppedChains.filter(i => !droppedTestnetChainsSet.has(i) && !i.includes('test'));
126
151
  console.log('Dropped chains before testnet filtering:', droppedChains.length);
@@ -131,12 +156,15 @@ async function main() {
131
156
  delete providerList.bitcoin; // what were they smoking?
132
157
  const rpcCount = Object.values(providerList).reduce((acc, i) => { var _a; return acc + ((_a = i === null || i === void 0 ? void 0 : i.rpc.length) !== null && _a !== void 0 ? _a : 0); }, 0);
133
158
  const rpcCountOld = Object.values(oldProviders).reduce((acc, i) => { var _a; return acc + ((_a = i === null || i === void 0 ? void 0 : i.rpc.length) !== null && _a !== void 0 ? _a : 0); }, 0);
159
+ const newlyAddedChains = Object.keys(providerList).filter(chain => oldProviders[chain] === undefined);
134
160
  console.log('Final provider list:');
135
161
  console.log('Chain count:', Object.keys(providerList).length);
162
+ console.log('Newly added chains count:', newlyAddedChains.length);
136
163
  console.log('Dropped chain count:', filteredDroppedChains.length);
137
164
  console.log('RPC count:', rpcCount);
138
165
  console.log('RPC count current:', rpcCountOld);
139
166
  console.log('Dropped chains:', filteredDroppedChains.join(', '));
167
+ console.log('Newly added chains:', newlyAddedChains.join(', '));
140
168
  fs_1.default.writeFileSync(__dirname + '/../providers.json', JSON.stringify(providerList));
141
169
  }
142
170
  const blacklist = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defillama/sdk",
3
- "version": "5.0.204",
3
+ "version": "5.0.207",
4
4
  "description": "SDK for calculating TVL",
5
5
  "main": "build/index.js",
6
6
  "scripts": {