@defillama/sdk 5.0.134 → 5.0.137

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.
@@ -110,6 +110,12 @@ class LlamaProvider extends ethers_1.FallbackProvider {
110
110
  runners.splice(1, 0, primaryRunner);
111
111
  }
112
112
  runners = runners.slice(0, attempts);
113
+ // print stats every 5 minutes
114
+ let currentTimeMS = Date.now();
115
+ if (currentTimeMS - lastPrintTimeMS > 1000 * 60 * 5) {
116
+ lastPrintTimeMS = currentTimeMS;
117
+ printRPCCallStats();
118
+ }
113
119
  // if (this.chainName === 'rsk' && method === 'getLogs') {
114
120
  // const hostString = getEnvValue('RSK_ARCHIVAL_RPC')
115
121
  // if (!hostString)
@@ -309,9 +315,11 @@ function getMedianBlockValue(blocks) {
309
315
  const mid = Math.floor(blocks.length / 3);
310
316
  return blocks.length % 2 !== 0 ? blocks[mid] : (blocks[mid - 1] + blocks[mid]) / 2;
311
317
  }
312
- process.on('exit', () => {
318
+ let lastPrintTimeMS = Date.now();
319
+ function printRPCCallStats() {
313
320
  if (Object.keys(rpcRequestCounter).length > 7) {
314
321
  (0, debugLog_1.debugLog)('RPC request count per chain');
315
- console.table(rpcRequestCounter);
322
+ (0, debugLog_1.debugTable)(rpcRequestCounter);
316
323
  }
317
- });
324
+ }
325
+ process.on('exit', printRPCCallStats);
package/build/util/env.js CHANGED
@@ -12,6 +12,7 @@ const whitelistedEnvConstants = [
12
12
  const defaultEnvValues = {
13
13
  INTERNAL_SDK_CACHE_FILE: './cache.json',
14
14
  TRON_RPC_CONCURRENCY_LIMIT: '5',
15
+ LLAMA_INDEXER_ADDRESS_CHUNK_SIZE: '20',
15
16
  TRON_RPC: 'https://api.trongrid.io',
16
17
  TRON_EVM_RPC: 'https://rpc.ankr.com/tron_jsonrpc',
17
18
  NAKA_RPC: 'https://node.nakachain.xyz',
@@ -16,6 +16,7 @@ const logs_1 = require("./logs");
16
16
  const _1 = require(".");
17
17
  const indexerURL = (0, env_1.getEnvValue)('LLAMA_INDEXER_ENDPOINT');
18
18
  const LLAMA_INDEXER_API_KEY = (0, env_1.getEnvValue)('LLAMA_INDEXER_API_KEY');
19
+ const addressChunkSize = +(0, env_1.getEnvValue)('LLAMA_INDEXER_ADDRESS_CHUNK_SIZE');
19
20
  const axiosIndexer = axios_1.default.create({
20
21
  headers: {
21
22
  "x-api-key": LLAMA_INDEXER_API_KEY,
@@ -186,12 +187,12 @@ async function getLogs({ chain = 'ethereum', topic, topics, fromBlock, toBlock,
186
187
  console.time(debugTimeKey);
187
188
  }
188
189
  const addressSet = new Set(address === null || address === void 0 ? void 0 : address.split(','));
189
- const addressChunks = (0, _1.sliceIntoChunks)((_c = address === null || address === void 0 ? void 0 : address.split(',')) !== null && _c !== void 0 ? _c : [], 10);
190
+ const addressChunks = (0, _1.sliceIntoChunks)((_c = address === null || address === void 0 ? void 0 : address.split(',')) !== null && _c !== void 0 ? _c : [], addressChunkSize);
190
191
  // to ensure that we have at least one chunk to process if no target is provided
191
192
  if (noTarget && addressChunks.length === 0)
192
193
  addressChunks.push(undefined);
193
194
  for (const chunk of addressChunks) {
194
- let _logAgg = [];
195
+ let logCount = 0;
195
196
  do {
196
197
  const params = {
197
198
  addresses: hasAddressFilter ? chunk.join(',') : undefined,
@@ -203,17 +204,20 @@ async function getLogs({ chain = 'ethereum', topic, topics, fromBlock, toBlock,
203
204
  offset,
204
205
  };
205
206
  const { data: { logs: _logs, totalCount } } = await axiosIndexer(`/logs`, { params, });
206
- _logAgg.push(..._logs.filter((l) => {
207
- if (!addressSet.size)
208
- return true;
209
- return addressSet.has(l === null || l === void 0 ? void 0 : l.source.toLowerCase());
210
- }));
207
+ // getLogs uses 'address' field to return log source, so we add the field here to make it compatible
208
+ _logs.forEach((l) => {
209
+ l.address = l.source;
210
+ const iswhitelisted = !addressSet.size || addressSet.has(l.source.toLowerCase());
211
+ if (iswhitelisted) {
212
+ logs.push(l);
213
+ }
214
+ });
215
+ logCount += _logs.length;
211
216
  offset += limit;
212
217
  // If we have all the logs, or we have reached the limit, or there are no logs, we stop
213
- if (_logs.length < limit || totalCount <= _logAgg.length || _logs.length === 0)
218
+ if (_logs.length < limit || totalCount <= logCount || _logs.length === 0)
214
219
  hasMore = false;
215
220
  } while (all && hasMore);
216
- logs.push(..._logAgg);
217
221
  }
218
222
  if (debugMode) {
219
223
  console.timeEnd(debugTimeKey);
@@ -235,7 +239,7 @@ async function getLogs({ chain = 'ethereum', topic, topics, fromBlock, toBlock,
235
239
  log.transactionHash = log.transaction_hash;
236
240
  log.blockNumber = log.block_number;
237
241
  log.topics = [log.topic0, log.topic1, log.topic2, log.topic3,].filter(t => t !== '').map(i => ethers_1.ethers.zeroPadValue(i, 32));
238
- const deleteKeys = ['chain', 'address', 'block_number', 'log_index', 'topic0', 'topic1', 'topic2', 'topic3', 'decodedArgs', 'transaction_hash',];
242
+ const deleteKeys = ['chain', 'block_number', 'log_index', 'topic0', 'topic1', 'topic2', 'topic3', 'decodedArgs', 'transaction_hash',];
239
243
  deleteKeys.forEach(k => delete log[k]);
240
244
  const parsedLog = iface === null || iface === void 0 ? void 0 : iface.parseLog({ data: log.data, topics: log.topics, });
241
245
  log.args = parsedLog === null || parsedLog === void 0 ? void 0 : parsedLog.args;
@@ -79,9 +79,6 @@ async function main() {
79
79
  continue;
80
80
  providerList[key] = providerList[shorName];
81
81
  }
82
- if (providerList.hyperliquid) {
83
- providerList.hyperliquid.rpc.push('https://hyperliquid.cloud.blockscout.com/api/eth-rpc');
84
- }
85
82
  const droppedChains = Object.keys(oldProviders).filter(oldChain => providerList[oldChain] === undefined);
86
83
  if (droppedChains.length > 20) {
87
84
  throw new Error(`Following chains used to be included but is not anymore, can the devs fix please?\n${droppedChains.join('\n')}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defillama/sdk",
3
- "version": "5.0.134",
3
+ "version": "5.0.137",
4
4
  "description": "SDK for calculating TVL",
5
5
  "main": "build/index.js",
6
6
  "scripts": {