@defillama/sdk 5.0.152 → 5.0.156

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.
@@ -26,6 +26,7 @@ export declare function normalizeBalances(balances: {
26
26
  }): {
27
27
  [address: string]: string;
28
28
  };
29
- export declare function tableToString(data: any, columns?: any, { title }?: {
29
+ export declare function tableToString(data: any, columns?: any, { title, columns: _columns }?: {
30
30
  title?: string;
31
+ columns?: string[];
31
32
  }): string;
@@ -162,14 +162,41 @@ function normalizeBalances(balances) {
162
162
  return balances;
163
163
  }
164
164
  exports.normalizeBalances = normalizeBalances;
165
- function tableToString(data, columns, { title } = {}) {
165
+ function tableToString(data, columns, { title, columns: _columns } = {}) {
166
+ // If only two arguments are passed and the second is not an array, treat it as options
167
+ if (arguments.length === 2 && !Array.isArray(columns) && typeof columns === 'object') {
168
+ ({ title, columns: _columns } = columns !== null && columns !== void 0 ? columns : {});
169
+ columns = undefined;
170
+ }
171
+ if (_columns && Array.isArray(_columns))
172
+ columns = _columns;
166
173
  let tableString = '';
174
+ if (!Array.isArray(data) && typeof data === 'object') {
175
+ data = Object.entries(data).map(([key, value]) => {
176
+ const row = { key };
177
+ if (typeof value === 'object' && !Array.isArray(value)) {
178
+ Object.entries(value).forEach(([subKey, subValue]) => {
179
+ row[subKey] = subValue;
180
+ });
181
+ }
182
+ else {
183
+ row.value = value;
184
+ }
185
+ return row;
186
+ });
187
+ }
167
188
  if (!data || !Array.isArray(data) || data.length === 0) {
168
189
  return '';
169
190
  }
170
191
  data = [...data]; // Ensure we don't modify the original data
171
192
  if (!columns || !Array.isArray(columns) || columns.length === 0) {
172
- columns = Object.keys(data[0] || {});
193
+ const columnsSet = new Set();
194
+ data.forEach((row) => {
195
+ Object.keys(row).forEach((col) => {
196
+ columnsSet.add(col);
197
+ });
198
+ });
199
+ columns = Array.from(columnsSet);
173
200
  }
174
201
  if (title)
175
202
  tableString += `# ${title}\n\n`;
@@ -109,7 +109,7 @@ async function getLogs(options) {
109
109
  await addLogsToCache(_from, _to);
110
110
  }
111
111
  /* ---------------------------- Return result ----------------------------- */
112
- const out = [];
112
+ let out = [];
113
113
  for (const c of caches) {
114
114
  const { fromBlock: cStart, toBlock: cEnd } = c.metadata;
115
115
  if (fromBlock > cEnd || toBlock < cStart)
@@ -120,7 +120,7 @@ async function getLogs(options) {
120
120
  if (processor)
121
121
  await processor(filtered);
122
122
  // Always include filtered logs in the return value, even when a processor is provided
123
- out.push(...filtered);
123
+ out = out.concat(filtered); // use concat instead of ... to avoid running into issues with large arrays (RangeError: Maximum call stack size exceeded)
124
124
  }
125
125
  return out;
126
126
  /* ----------------------------------------------------------------------- */
@@ -97,7 +97,7 @@ function filterRPCs(rpc) {
97
97
  if (i.includes('$'))
98
98
  return false; // remove anything where api key is injected
99
99
  // reject websocket, http, testnet, devnet, and anything with '='
100
- if (/(wss\:|ws\:|http\:|test|devnet|terminet\.io|huobichain\.com|getblock\.io|bitstack\.com|nodereal.io\/v1|pokt\.network|ankr\.com|histori\.xyz|owlracle\.info\=)/.test(i))
100
+ if (/(wss\:|ws\:|http\:|test|devnet|terminet\.io|huobichain\.com|getblock\.io|bitstack\.com|nodereal.io\/v1|pokt\.network|ankr\.com|histori\.xyz|chainstacklabs\.com|owlracle\.info\=)/.test(i))
101
101
  return false; // remove anything with blacklisted words
102
102
  return true;
103
103
  }).map((i) => {
@@ -108,6 +108,7 @@ function filterRPCs(rpc) {
108
108
  }
109
109
  const chainShortNameMapping = {
110
110
  real: 're-al',
111
+ karura: 'karura_evm',
111
112
  taiko: 'tko-mainnet',
112
113
  bsquared: 'b2-mainnet',
113
114
  ox_chain: 'ox-chain',
@@ -118,7 +119,7 @@ const chainShortNameMapping = {
118
119
  hydradx: 'hdx',
119
120
  nibiru: 'cataclysm_1',
120
121
  elsm: 'ely',
121
- tac: 'tacchain_239_1',
122
+ tac: 'tacchain',
122
123
  };
123
124
  async function filterForWorkingRPCs(rpc, chain, chainId) {
124
125
  if (rpc.length < 10)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defillama/sdk",
3
- "version": "5.0.152",
3
+ "version": "5.0.156",
4
4
  "description": "SDK for calculating TVL",
5
5
  "main": "build/index.js",
6
6
  "scripts": {