@defillama/sdk 5.0.154 → 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.
package/build/util/index.d.ts
CHANGED
|
@@ -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;
|
package/build/util/index.js
CHANGED
|
@@ -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
|
-
|
|
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`;
|
package/build/util/logs.js
CHANGED
|
@@ -109,7 +109,7 @@ async function getLogs(options) {
|
|
|
109
109
|
await addLogsToCache(_from, _to);
|
|
110
110
|
}
|
|
111
111
|
/* ---------------------------- Return result ----------------------------- */
|
|
112
|
-
|
|
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.
|
|
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
|
/* ----------------------------------------------------------------------- */
|