@defillama/sdk 5.0.185 → 5.0.188
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/Balances.d.ts +1 -0
- package/build/Balances.js +2 -1
- package/build/ChainApi.d.ts +1 -0
- package/build/ChainApi.js +19 -5
- package/build/abi/multicall3.js +1 -0
- package/build/generalUtil.d.ts +1 -0
- package/build/generalUtil.js +5 -1
- package/build/index.d.ts +1 -1
- package/build/index.js +1 -1
- package/build/providers.json +1 -1
- package/build/util/LlamaProvider.d.ts +10 -0
- package/build/util/LlamaProvider.js +23 -1
- package/build/util/coins.d.ts +1 -0
- package/build/util/common.js +2 -2
- package/build/util/env.js +2 -1
- package/build/util/indexer.d.ts +16 -0
- package/build/util/indexer.js +323 -78
- package/build/util/logs.decode.shared.d.ts +8 -0
- package/build/util/logs.decode.shared.js +288 -0
- package/build/util/logs.js +31 -19
- package/build/util/updateProviderList.js +61 -16
- package/package.json +5 -2
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.padTopic32 = padTopic32;
|
|
4
|
+
exports.normalizeLog = normalizeLog;
|
|
5
|
+
exports.normalizeValueByType = normalizeValueByType;
|
|
6
|
+
exports.convertTopicsToViemFormat = convertTopicsToViemFormat;
|
|
7
|
+
exports.enrichEthersArgsWithNamedProperties = enrichEthersArgsWithNamedProperties;
|
|
8
|
+
exports.buildEthersCompatibleArgs = buildEthersCompatibleArgs;
|
|
9
|
+
exports.createViemFastPathBatchDecoder = createViemFastPathBatchDecoder;
|
|
10
|
+
const ethers_1 = require("ethers");
|
|
11
|
+
const viem_1 = require("viem");
|
|
12
|
+
function padTopic32(t) {
|
|
13
|
+
if (!t)
|
|
14
|
+
return '0x';
|
|
15
|
+
// Early return if already 32 bytes (0x + 64 hex chars)
|
|
16
|
+
if (t.startsWith('0x') && t.length === 66)
|
|
17
|
+
return t;
|
|
18
|
+
const hex = t.startsWith('0x') ? t.slice(2) : t;
|
|
19
|
+
return ('0x' + hex.padStart(64, '0'));
|
|
20
|
+
}
|
|
21
|
+
function normalizeLog(log, isIndexerCall = false) {
|
|
22
|
+
if (isIndexerCall || log.source) {
|
|
23
|
+
log.address = log.source;
|
|
24
|
+
log.logIndex = log.log_index;
|
|
25
|
+
log.index = log.log_index;
|
|
26
|
+
log.transactionHash = log.transaction_hash;
|
|
27
|
+
log.blockNumber = parseInt(log.block_number || log.blockNumber || 0);
|
|
28
|
+
const topics = [log.topic0, log.topic1, log.topic2, log.topic3]
|
|
29
|
+
.filter(Boolean)
|
|
30
|
+
.map(padTopic32);
|
|
31
|
+
if (!topics[0])
|
|
32
|
+
return false;
|
|
33
|
+
log.topics = topics;
|
|
34
|
+
log._originalTopics = {
|
|
35
|
+
topic0: log.topic0,
|
|
36
|
+
topic1: log.topic1,
|
|
37
|
+
topic2: log.topic2,
|
|
38
|
+
topic3: log.topic3
|
|
39
|
+
};
|
|
40
|
+
log._originalTransactionHash = log.transaction_hash;
|
|
41
|
+
// Only delete fields that are not needed for parsing
|
|
42
|
+
[
|
|
43
|
+
"chain",
|
|
44
|
+
"log_index",
|
|
45
|
+
].forEach((k) => delete log[k]);
|
|
46
|
+
}
|
|
47
|
+
if (log.blockNumber === undefined && log.block_number !== undefined)
|
|
48
|
+
log.blockNumber = parseInt(log.block_number);
|
|
49
|
+
// Restore topics if they were lost
|
|
50
|
+
if (!log.topics && log._originalTopics) {
|
|
51
|
+
log.topics = [log._originalTopics.topic0, log._originalTopics.topic1, log._originalTopics.topic2, log._originalTopics.topic3]
|
|
52
|
+
.filter(Boolean)
|
|
53
|
+
.map(padTopic32);
|
|
54
|
+
}
|
|
55
|
+
// Restore transaction hash if it was lost
|
|
56
|
+
if (!log.transactionHash && log._originalTransactionHash) {
|
|
57
|
+
log.transactionHash = log._originalTransactionHash;
|
|
58
|
+
}
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Normalize value type according to Solidity type to match Ethers format
|
|
63
|
+
* Ethers returns small int types (int24, uint24, uint16, etc.) as strings to avoid JS precision issues
|
|
64
|
+
*/
|
|
65
|
+
const smallIntPattern = /^u?int(8|16|24)$/;
|
|
66
|
+
function normalizeValueByType(value, type) {
|
|
67
|
+
if (value === null || value === undefined)
|
|
68
|
+
return value;
|
|
69
|
+
// Ethers formats small integer types as strings
|
|
70
|
+
if (smallIntPattern.test(type)) {
|
|
71
|
+
if (typeof value === 'number') {
|
|
72
|
+
return value.toString();
|
|
73
|
+
}
|
|
74
|
+
else if (typeof value === 'bigint') {
|
|
75
|
+
return value.toString();
|
|
76
|
+
}
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
return value;
|
|
80
|
+
}
|
|
81
|
+
function convertTopicsToViemFormat(topics) {
|
|
82
|
+
if (!topics || topics.length === 0 || topics[0] === null) {
|
|
83
|
+
return [];
|
|
84
|
+
}
|
|
85
|
+
const filteredTopics = [];
|
|
86
|
+
for (let t = 0; t < topics.length; t++) {
|
|
87
|
+
if (topics[t] !== null) {
|
|
88
|
+
filteredTopics.push(topics[t]);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// Create tuple type for Viem (required format)
|
|
92
|
+
return filteredTopics.length > 0
|
|
93
|
+
? [filteredTopics[0], ...filteredTopics.slice(1)]
|
|
94
|
+
: [];
|
|
95
|
+
}
|
|
96
|
+
// Enrich Ethers args with named properties to match Viem output structure
|
|
97
|
+
function enrichEthersArgsWithNamedProperties(ethersArgs, event, iface) {
|
|
98
|
+
if (!ethersArgs || !event || !event.inputs) {
|
|
99
|
+
return ethersArgs;
|
|
100
|
+
}
|
|
101
|
+
// Create a new args object with named properties
|
|
102
|
+
const enrichedArgs = Object.create(null);
|
|
103
|
+
// Copy all existing properties (numeric and named if present)
|
|
104
|
+
for (const key in ethersArgs) {
|
|
105
|
+
if (ethersArgs.hasOwnProperty && !ethersArgs.hasOwnProperty(key))
|
|
106
|
+
continue;
|
|
107
|
+
enrichedArgs[key] = ethersArgs[key];
|
|
108
|
+
}
|
|
109
|
+
// Ensure named properties are present
|
|
110
|
+
const inputs = event.inputs;
|
|
111
|
+
for (let i = 0; i < inputs.length; i++) {
|
|
112
|
+
const input = inputs[i];
|
|
113
|
+
const value = ethersArgs[i];
|
|
114
|
+
if (value !== undefined && value !== null) {
|
|
115
|
+
if (input.name && !(input.name in enrichedArgs)) {
|
|
116
|
+
enrichedArgs[input.name] = value;
|
|
117
|
+
}
|
|
118
|
+
enrichedArgs[i] = value;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (typeof ethersArgs.length === 'number') {
|
|
122
|
+
enrichedArgs.length = ethersArgs.length;
|
|
123
|
+
}
|
|
124
|
+
return enrichedArgs;
|
|
125
|
+
}
|
|
126
|
+
function buildEthersCompatibleArgs(decodedArgs, eventInputs, normalizeFn = normalizeValueByType) {
|
|
127
|
+
var _a, _b;
|
|
128
|
+
if (!decodedArgs) {
|
|
129
|
+
const args = Object.create(null);
|
|
130
|
+
args.length = eventInputs.length;
|
|
131
|
+
return args;
|
|
132
|
+
}
|
|
133
|
+
const args = Object.create(null);
|
|
134
|
+
args.length = eventInputs.length;
|
|
135
|
+
try {
|
|
136
|
+
if (Array.isArray(decodedArgs)) {
|
|
137
|
+
const len = Math.min(decodedArgs.length, eventInputs.length);
|
|
138
|
+
for (let i = 0; i < len; i++) {
|
|
139
|
+
const input = eventInputs[i];
|
|
140
|
+
const value = decodedArgs[i];
|
|
141
|
+
if (value !== undefined && value !== null) {
|
|
142
|
+
const normalizedValue = normalizeFn(value, input.type);
|
|
143
|
+
if (input.name)
|
|
144
|
+
args[input.name] = normalizedValue;
|
|
145
|
+
args[i] = normalizedValue;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return args;
|
|
149
|
+
}
|
|
150
|
+
if (typeof decodedArgs === 'object') {
|
|
151
|
+
const inputCount = eventInputs.length;
|
|
152
|
+
for (let i = 0; i < inputCount; i++) {
|
|
153
|
+
const input = eventInputs[i];
|
|
154
|
+
const value = (_b = (_a = decodedArgs[input.name]) !== null && _a !== void 0 ? _a : decodedArgs[i]) !== null && _b !== void 0 ? _b : null;
|
|
155
|
+
if (value !== undefined && value !== null) {
|
|
156
|
+
const normalizedValue = normalizeFn(value, input.type);
|
|
157
|
+
if (input.name)
|
|
158
|
+
args[input.name] = normalizedValue;
|
|
159
|
+
args[i] = normalizedValue;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return args;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
catch (e) {
|
|
166
|
+
// Fallback: minimal object creation
|
|
167
|
+
if (Array.isArray(decodedArgs)) {
|
|
168
|
+
const len = decodedArgs.length;
|
|
169
|
+
for (let i = 0; i < len; i++) {
|
|
170
|
+
args[i] = decodedArgs[i];
|
|
171
|
+
}
|
|
172
|
+
args.length = len;
|
|
173
|
+
}
|
|
174
|
+
else if (typeof decodedArgs === 'object') {
|
|
175
|
+
Object.assign(args, decodedArgs);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return args;
|
|
179
|
+
}
|
|
180
|
+
function createViemFastPathBatchDecoder(eventAbi) {
|
|
181
|
+
try {
|
|
182
|
+
// Parse ABI once
|
|
183
|
+
const ev = (0, viem_1.parseAbiItem)(eventAbi);
|
|
184
|
+
if (!ev || ev.type !== 'event')
|
|
185
|
+
return null;
|
|
186
|
+
const inputs = ev.inputs || [];
|
|
187
|
+
const indexed = [];
|
|
188
|
+
const nonIndexed = [];
|
|
189
|
+
for (const inp of inputs) {
|
|
190
|
+
if (inp.indexed) {
|
|
191
|
+
indexed.push(inp);
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
nonIndexed.push(inp);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const nonIndexedTypes = nonIndexed.map(i => ({ type: i.type }));
|
|
198
|
+
return async function decodeBatchViemFast(logs) {
|
|
199
|
+
var _a, _b;
|
|
200
|
+
const out = new Array(logs.length);
|
|
201
|
+
for (let i = 0; i < logs.length; i++) {
|
|
202
|
+
const l = logs[i];
|
|
203
|
+
try {
|
|
204
|
+
const logData = l.data || l.data_field || '0x';
|
|
205
|
+
const decodedNon = nonIndexed.length && logData && logData !== '0x'
|
|
206
|
+
? (0, viem_1.decodeAbiParameters)(nonIndexedTypes, logData)
|
|
207
|
+
: [];
|
|
208
|
+
const args = Object.create(null);
|
|
209
|
+
args.length = inputs.length;
|
|
210
|
+
let topicIdx = 1; // topics[0] = event signature
|
|
211
|
+
let nonIndexedIdx = 0;
|
|
212
|
+
for (let j = 0; j < inputs.length; j++) {
|
|
213
|
+
const inp = inputs[j];
|
|
214
|
+
let value;
|
|
215
|
+
if (inp.indexed) {
|
|
216
|
+
if (topicIdx < (((_a = l.topics) === null || _a === void 0 ? void 0 : _a.length) || 0)) {
|
|
217
|
+
value = l.topics[topicIdx];
|
|
218
|
+
topicIdx++;
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
value = null;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
value = (_b = decodedNon[nonIndexedIdx]) !== null && _b !== void 0 ? _b : null;
|
|
226
|
+
nonIndexedIdx++;
|
|
227
|
+
}
|
|
228
|
+
let normalizedValue = null;
|
|
229
|
+
if (value !== null && value !== undefined) {
|
|
230
|
+
// For indexed addresses, Ethers extracts the address from the padded topic
|
|
231
|
+
// Topics are 32 bytes padded, but Ethers returns addresses as normal 20-byte addresses
|
|
232
|
+
// Ethers uses getAddress() which converts to checksum format
|
|
233
|
+
if (inp.type === 'address' && inp.indexed && typeof value === 'string') {
|
|
234
|
+
let addressStr;
|
|
235
|
+
if (value.startsWith('0x') && value.length === 66) {
|
|
236
|
+
// Topic is 32 bytes padded, extract the address (last 20 bytes = 40 hex chars)
|
|
237
|
+
addressStr = '0x' + value.slice(-40);
|
|
238
|
+
}
|
|
239
|
+
else if (value.startsWith('0x') && value.length === 42) {
|
|
240
|
+
addressStr = value;
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
// Fallback: try to extract address from topic
|
|
244
|
+
const hex = value.startsWith('0x') ? value.slice(2) : value;
|
|
245
|
+
if (hex.length >= 40) {
|
|
246
|
+
addressStr = '0x' + hex.slice(-40);
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
addressStr = value;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
// Use ethers.getAddress to convert to checksum format (like Ethers does)
|
|
253
|
+
try {
|
|
254
|
+
normalizedValue = ethers_1.ethers.getAddress(addressStr);
|
|
255
|
+
}
|
|
256
|
+
catch {
|
|
257
|
+
// Fallback if getAddress fails
|
|
258
|
+
normalizedValue = addressStr.toLowerCase();
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
// For other types, use normal normalization
|
|
263
|
+
normalizedValue = normalizeValueByType(value, inp.type);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
// Always assign both numeric index and named property (even if value is null/undefined)
|
|
267
|
+
// This matches Ethers behavior where all args are present in the args object
|
|
268
|
+
args[j] = normalizedValue;
|
|
269
|
+
if (inp.name) {
|
|
270
|
+
args[inp.name] = normalizedValue;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
out[i] = args;
|
|
274
|
+
}
|
|
275
|
+
catch (e) {
|
|
276
|
+
// Fallback: return empty args on decode error
|
|
277
|
+
const args = Object.create(null);
|
|
278
|
+
args.length = inputs.length;
|
|
279
|
+
out[i] = args;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return out;
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
catch (e) {
|
|
286
|
+
return null;
|
|
287
|
+
}
|
|
288
|
+
}
|
package/build/util/logs.js
CHANGED
|
@@ -15,6 +15,7 @@ const indexer_1 = require("./indexer");
|
|
|
15
15
|
const promisePool_1 = __importDefault(require("./promisePool"));
|
|
16
16
|
const env_1 = require("./env");
|
|
17
17
|
const common_1 = require("./common");
|
|
18
|
+
const logs_decode_shared_1 = require("./logs.decode.shared");
|
|
18
19
|
const currentVersion = "v3";
|
|
19
20
|
/* -------------------------------------------------------------------------- */
|
|
20
21
|
/* getLogs */
|
|
@@ -277,8 +278,14 @@ async function getLogParams(options, isIndexerCall = false) {
|
|
|
277
278
|
if (!noTarget && !target && !targets.length)
|
|
278
279
|
throw new Error('target|targets is required or set the flag "noTarget" to true');
|
|
279
280
|
let iface;
|
|
280
|
-
|
|
281
|
+
let event = null;
|
|
282
|
+
if (eventAbi) {
|
|
281
283
|
iface = new ethers_1.Interface([eventAbi]);
|
|
284
|
+
const fragments = iface.fragments.filter(f => f.type === 'event');
|
|
285
|
+
if (fragments.length > 0) {
|
|
286
|
+
event = fragments[0];
|
|
287
|
+
}
|
|
288
|
+
}
|
|
282
289
|
if (!(topics === null || topics === void 0 ? void 0 : topics.length)) {
|
|
283
290
|
if (topic)
|
|
284
291
|
topic = toFilterTopic(topic);
|
|
@@ -296,19 +303,17 @@ async function getLogParams(options, isIndexerCall = false) {
|
|
|
296
303
|
// normalize indexer payload
|
|
297
304
|
if (isIndexerCall) {
|
|
298
305
|
log.address = log.source;
|
|
299
|
-
|
|
300
|
-
log.
|
|
306
|
+
// Preserve logIndex/index if already set by normalizeLog, otherwise set from log_index
|
|
307
|
+
if (log.logIndex === undefined && log.index === undefined) {
|
|
308
|
+
log.logIndex = log.log_index;
|
|
309
|
+
log.index = log.log_index;
|
|
310
|
+
}
|
|
301
311
|
log.transactionHash = log.transaction_hash;
|
|
302
312
|
log.blockNumber = parseInt(log.block_number);
|
|
303
313
|
// Ensure topics are properly formatted
|
|
304
314
|
const topics = [log.topic0, log.topic1, log.topic2, log.topic3]
|
|
305
315
|
.filter(Boolean)
|
|
306
|
-
.map(
|
|
307
|
-
if (!t)
|
|
308
|
-
return null;
|
|
309
|
-
const topic = t.startsWith("0x") ? t : `0x${t}`;
|
|
310
|
-
return ethers_1.ethers.zeroPadValue(topic, 32);
|
|
311
|
-
});
|
|
316
|
+
.map(logs_decode_shared_1.padTopic32);
|
|
312
317
|
// Ensure first topic (event signature) is present
|
|
313
318
|
if (!topics[0]) {
|
|
314
319
|
return log;
|
|
@@ -338,21 +343,28 @@ async function getLogParams(options, isIndexerCall = false) {
|
|
|
338
343
|
if (!log.topics && log._originalTopics) {
|
|
339
344
|
log.topics = [log._originalTopics.topic0, log._originalTopics.topic1, log._originalTopics.topic2, log._originalTopics.topic3]
|
|
340
345
|
.filter(Boolean)
|
|
341
|
-
.map(
|
|
342
|
-
if (!t)
|
|
343
|
-
return null;
|
|
344
|
-
const topic = t.startsWith("0x") ? t : `0x${t}`;
|
|
345
|
-
return ethers_1.ethers.zeroPadValue(topic, 32);
|
|
346
|
-
});
|
|
346
|
+
.map(logs_decode_shared_1.padTopic32);
|
|
347
347
|
}
|
|
348
348
|
// Restore transaction hash if it was lost
|
|
349
349
|
if (!log.transactionHash && log._originalTransactionHash) {
|
|
350
350
|
log.transactionHash = log._originalTransactionHash;
|
|
351
351
|
}
|
|
352
|
-
|
|
353
|
-
if (!
|
|
354
|
-
|
|
355
|
-
|
|
352
|
+
let parsed = null;
|
|
353
|
+
if (!iface) {
|
|
354
|
+
log.args = undefined;
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
parsed = iface.parseLog(log);
|
|
358
|
+
if (!parsed && !allowParseFailure)
|
|
359
|
+
throw new Error(`Failed to parse log: ${JSON.stringify(log.transactionHash)}`);
|
|
360
|
+
// Enrich args with named properties to match Viem output structure
|
|
361
|
+
if ((parsed === null || parsed === void 0 ? void 0 : parsed.args) && event && iface) {
|
|
362
|
+
log.args = (0, logs_decode_shared_1.enrichEthersArgsWithNamedProperties)(parsed.args, event, iface);
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
log.args = parsed === null || parsed === void 0 ? void 0 : parsed.args;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
356
368
|
if (entireLog)
|
|
357
369
|
log.parsedLog = parsed;
|
|
358
370
|
return onlyArgs ? log.args : log;
|
|
@@ -8,6 +8,8 @@ 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 concurrentCheckChains = +(process.env.SDK_BUILD_CONCURRENT_CHAINS || 7);
|
|
12
|
+
const chainRemovalThreshold = +(process.env.SDK_BUILD_CHAIN_REMOVAL_THRESHOLD || 20);
|
|
11
13
|
const providerList = providers_json_1.default;
|
|
12
14
|
async function getChainData() {
|
|
13
15
|
try {
|
|
@@ -26,17 +28,52 @@ async function getChainData() {
|
|
|
26
28
|
}
|
|
27
29
|
async function main() {
|
|
28
30
|
const oldProviders = await (0, generalUtil_1.fetchJson)(`https://unpkg.com/@defillama/sdk@latest/build/providers.json`);
|
|
31
|
+
const currentChains = await (0, generalUtil_1.fetchJson)(`https://raw.githubusercontent.com/DefiLlama/DefiLlama-Adapters/refs/heads/main/projects/helper/chains.json`);
|
|
32
|
+
const currentChainsSet = new Set(currentChains);
|
|
29
33
|
let chainData = await getChainData();
|
|
30
34
|
const providerIDMap = {};
|
|
31
35
|
Object.values(providerList).forEach((i) => providerIDMap[i.chainId] = i.rpc);
|
|
32
36
|
chainData = chainData
|
|
33
37
|
.filter((i) => i.rpc.length)
|
|
34
38
|
// .filter((i: any) => !i.status || (i.status === 'active' || i.status === 'incubating'))
|
|
35
|
-
.filter((i) => i.shortName)
|
|
39
|
+
.filter((i) => i.shortName)
|
|
40
|
+
.filter((i) => {
|
|
41
|
+
if (currentChainsSet.has(i.shortName))
|
|
42
|
+
return true;
|
|
43
|
+
const bannedKeys = ['sepolia', 'test', 'goerli', 'devnet', 'holesky',];
|
|
44
|
+
const bannedRPCKeys = ['sepolia', 'goerli', 'devnet', 'holesky'];
|
|
45
|
+
const isTestnetKey = bannedKeys.some((j) => i.shortName.includes(j));
|
|
46
|
+
const hasTestnetRPC = i.rpc.some((rpc) => bannedRPCKeys.some((k) => rpc === null || rpc === void 0 ? void 0 : rpc.url.includes(k)));
|
|
47
|
+
if (isTestnetKey || hasTestnetRPC)
|
|
48
|
+
console.log(`Excluding testnet chain ${i.name} (${i.shortName})`);
|
|
49
|
+
return !isTestnetKey && !hasTestnetRPC;
|
|
50
|
+
});
|
|
51
|
+
// trim/remove mainnet|-mainnet|_mainnet from short names, preliminary rpc filtering
|
|
52
|
+
const rpcFilterRegex = /(wss\:|ws\:|terminet\.io|huobichain\.com|getblock\.io|bitstack\.com|nodereal.io\/v1|pokt\.network|histori\.xyz|chainstacklabs\.com|owlracle\.info|blastapi\.io)/;
|
|
53
|
+
chainData.forEach((i) => {
|
|
54
|
+
if (currentChainsSet.has(i.shortName)) {
|
|
55
|
+
// keep the short name as is
|
|
56
|
+
}
|
|
57
|
+
if (i.shortName.endsWith('-mainnet'))
|
|
58
|
+
i.shortName = i.shortName.slice(0, -8);
|
|
59
|
+
else if (i.shortName.endsWith('_mainnet'))
|
|
60
|
+
i.shortName = i.shortName.slice(0, -8);
|
|
61
|
+
else if (i.shortName.endsWith('mainnet'))
|
|
62
|
+
i.shortName = i.shortName.slice(0, -7);
|
|
63
|
+
i.rpc = i.rpc.filter((j) => {
|
|
64
|
+
if (!j.url)
|
|
65
|
+
return false;
|
|
66
|
+
if (rpcFilterRegex.test(j.url)) {
|
|
67
|
+
console.log(`Removing blacklisted rpc ${j.url} from ${i.name}`);
|
|
68
|
+
return false; // remove anything with blacklisted words
|
|
69
|
+
}
|
|
70
|
+
return true;
|
|
71
|
+
});
|
|
72
|
+
});
|
|
36
73
|
// shuffle the array
|
|
37
74
|
chainData.sort(() => Math.random() - 0.5);
|
|
38
75
|
await promise_pool_1.default
|
|
39
|
-
.withConcurrency(
|
|
76
|
+
.withConcurrency(concurrentCheckChains)
|
|
40
77
|
.for(chainData)
|
|
41
78
|
.process(async (i) => {
|
|
42
79
|
var _a, _b;
|
|
@@ -63,16 +100,12 @@ async function main() {
|
|
|
63
100
|
}
|
|
64
101
|
});
|
|
65
102
|
Object.entries(providerList).forEach(([key, i]) => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
103
|
+
i.rpc.forEach((j) => {
|
|
104
|
+
if (filterRPCs([j]).length === 0) {
|
|
105
|
+
(0, debugLog_1.debugLog)(`Removing rpc ${j} from ${key}`);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
70
108
|
i.rpc = Array.from(new Set(filterRPCs(i.rpc)));
|
|
71
|
-
if (key.endsWith('-mainnet') || key.endsWith('_mainnet')) {
|
|
72
|
-
const shortName = key.slice(0, -8);
|
|
73
|
-
if (!providerList[shortName])
|
|
74
|
-
providerList[shortName] = i;
|
|
75
|
-
}
|
|
76
109
|
});
|
|
77
110
|
Object.keys(providerList).forEach((i) => {
|
|
78
111
|
if (!providerList[i].rpc.length)
|
|
@@ -84,25 +117,34 @@ async function main() {
|
|
|
84
117
|
providerList[key] = providerList[shorName];
|
|
85
118
|
}
|
|
86
119
|
const droppedChains = Object.keys(oldProviders).filter(oldChain => providerList[oldChain] === undefined);
|
|
87
|
-
if (droppedChains.length >
|
|
88
|
-
throw new Error(`Following chains used to be included but is not anymore, can the devs fix please?\n${droppedChains.join('
|
|
120
|
+
if (droppedChains.length > chainRemovalThreshold) {
|
|
121
|
+
throw new Error(`Following chains used to be included but is not anymore, can the devs fix please?\n${droppedChains.join(', ')}`);
|
|
89
122
|
}
|
|
90
123
|
delete providerList.bitcoin; // what were they smoking?
|
|
124
|
+
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);
|
|
125
|
+
console.log('Final provider list:');
|
|
126
|
+
console.log('Chain count:', Object.keys(providerList).length);
|
|
127
|
+
console.log('Dropped chain count:', droppedChains.length);
|
|
128
|
+
console.log('RPC count:', rpcCount);
|
|
129
|
+
console.log('Dropped chains:', droppedChains.join(', '));
|
|
91
130
|
fs_1.default.writeFileSync(__dirname + '/../providers.json', JSON.stringify(providerList));
|
|
92
131
|
}
|
|
93
132
|
const blacklist = [
|
|
94
133
|
'https://eth.api.onfinality.io/public'
|
|
95
134
|
];
|
|
135
|
+
// this is stricter filtering used only when chain has more than 10 rpcs
|
|
96
136
|
function filterRPCs(rpc) {
|
|
97
137
|
return rpc.filter((i) => {
|
|
98
138
|
if (blacklist.includes(i))
|
|
99
139
|
return false; // remove rpcs returning bad block heights etc
|
|
100
140
|
if (i.endsWith('/demo'))
|
|
101
141
|
return false; // remove demo rpc
|
|
142
|
+
if (!i.startsWith('http'))
|
|
143
|
+
return false; // remove demo rpc
|
|
102
144
|
if (i.includes('$'))
|
|
103
145
|
return false; // remove anything where api key is injected
|
|
104
146
|
// reject websocket, http, testnet, devnet, and anything with '='
|
|
105
|
-
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
|
|
147
|
+
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|blastapi\.io|\=)/.test(i))
|
|
106
148
|
return false; // remove anything with blacklisted words
|
|
107
149
|
return true;
|
|
108
150
|
}).map((i) => {
|
|
@@ -127,6 +169,8 @@ const chainShortNameMapping = {
|
|
|
127
169
|
elsm: 'ely',
|
|
128
170
|
tac: 'tacchain',
|
|
129
171
|
xone: 'xoc',
|
|
172
|
+
hydragon: 'hydra',
|
|
173
|
+
camp: 'campmainnet',
|
|
130
174
|
};
|
|
131
175
|
async function filterForWorkingRPCs(rpc, chain, chainId) {
|
|
132
176
|
if (rpc.length < 10)
|
|
@@ -143,11 +187,12 @@ async function filterForWorkingRPCs(rpc, chain, chainId) {
|
|
|
143
187
|
timeout: 30000
|
|
144
188
|
});
|
|
145
189
|
if (data.result)
|
|
146
|
-
return
|
|
190
|
+
return true;
|
|
147
191
|
}
|
|
148
192
|
catch (e) {
|
|
149
|
-
console.log(chain, e === null || e === void 0 ? void 0 : e.message);
|
|
193
|
+
console.log('ignoring bad rpc', chain, e === null || e === void 0 ? void 0 : e.message);
|
|
150
194
|
}
|
|
195
|
+
return false;
|
|
151
196
|
}));
|
|
152
197
|
return rpc.filter((_i, index) => promises[index]);
|
|
153
198
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defillama/sdk",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.188",
|
|
4
4
|
"description": "SDK for calculating TVL",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -34,10 +34,13 @@
|
|
|
34
34
|
"axios": "^1.6.5",
|
|
35
35
|
"ethers": "^6.0.0",
|
|
36
36
|
"p-limit": "^3.0.0",
|
|
37
|
-
"
|
|
37
|
+
"stream-json": "^1.9.1",
|
|
38
|
+
"tron-format-address": "^0.1.11",
|
|
39
|
+
"viem": "^2.38.6"
|
|
38
40
|
},
|
|
39
41
|
"devDependencies": {
|
|
40
42
|
"@types/jest": "^29.2.3",
|
|
43
|
+
"@types/stream-json": "^1.7.8",
|
|
41
44
|
"jest": "^29.3.1",
|
|
42
45
|
"ts-jest": "^29.1.1",
|
|
43
46
|
"ts-node": "^10.9.1",
|