@defillama/sdk 5.0.250 → 5.0.252
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/abi/index.js +37 -2
- package/build/abi/tron.js +2 -2
- package/build/providers.json +1 -1
- package/build/util/chainUtils/data.json +12 -5
- package/build/util/env.js +1 -1
- package/build/util/indexer.d.ts +1 -0
- package/build/util/logs.js +24 -11
- package/package.json +2 -1
package/build/abi/index.js
CHANGED
|
@@ -196,11 +196,19 @@ async function multiCall(params) {
|
|
|
196
196
|
return cachedMultiCall(params);
|
|
197
197
|
const abi = resolveABI(params.abi);
|
|
198
198
|
const chunkedCalls = (0, util_1.sliceIntoChunks)(contractCalls, chunkSize);
|
|
199
|
+
// Tron only: its JSON-RPC rejects a whole multicall batch when the calls in it
|
|
200
|
+
// add up past the node's CPU limit ("CPU timeout for ... operation executing").
|
|
201
|
+
// That is an RPC error, not a failing contract, so it must not become null
|
|
202
|
+
// results under permitFailure: the batch is split and retried, and an RPC
|
|
203
|
+
// error that survives down to a single call throws.
|
|
204
|
+
const isTron = chain === 'tron';
|
|
199
205
|
const results = await (0, util_1.runInPromisePool)({
|
|
200
206
|
items: chunkedCalls,
|
|
201
207
|
concurrency: 10,
|
|
202
|
-
processor: (calls) =>
|
|
203
|
-
|
|
208
|
+
processor: (calls) => isTron
|
|
209
|
+
? makeTronMultiCall(abi, calls, params.block, !!params.permitFailure)
|
|
210
|
+
: (0, multicall3_1.default)(abi, calls, chain, params.block),
|
|
211
|
+
permitFailure: isTron ? false : params.permitFailure,
|
|
204
212
|
});
|
|
205
213
|
// When an entire chunk's processor call throws (e.g. a chunk-level RPC
|
|
206
214
|
// failure, as opposed to an individual call within it), runInPromisePool
|
|
@@ -243,6 +251,33 @@ async function multiCall(params) {
|
|
|
243
251
|
output: flatResults, // flatten array
|
|
244
252
|
};
|
|
245
253
|
}
|
|
254
|
+
// Tron multicall batch. Calls with an unusable target are failed up front under
|
|
255
|
+
// permitFailure (they are a caller problem and never reach the RPC). If the RPC
|
|
256
|
+
// cannot execute the batch, it is halved and retried - halves run one after the
|
|
257
|
+
// other, so a dead RPC fails after ~log2(n) attempts - and the error is rethrown
|
|
258
|
+
// once a single call still cannot be executed.
|
|
259
|
+
async function makeTronMultiCall(abi, calls, block, permitFailure) {
|
|
260
|
+
if (permitFailure && calls.some((call) => !isValidTarget(call.contract, 'tron'))) {
|
|
261
|
+
const validCalls = calls.filter((call) => isValidTarget(call.contract, 'tron'));
|
|
262
|
+
const validResults = validCalls.length ? await makeTronMultiCall(abi, validCalls, block, false) : [];
|
|
263
|
+
let validIndex = 0;
|
|
264
|
+
return calls.map((call) => isValidTarget(call.contract, 'tron')
|
|
265
|
+
? validResults[validIndex++]
|
|
266
|
+
: { input: { params: call.params, target: call.contract }, success: false, output: null });
|
|
267
|
+
}
|
|
268
|
+
try {
|
|
269
|
+
return await (0, multicall3_1.default)(abi, calls, 'tron', block);
|
|
270
|
+
}
|
|
271
|
+
catch (e) {
|
|
272
|
+
if (calls.length <= 1)
|
|
273
|
+
throw e;
|
|
274
|
+
const mid = Math.ceil(calls.length / 2);
|
|
275
|
+
(0, debugLog_1.debugLog)(`[chain: tron] multicall batch of ${calls.length} failed, retrying as two batches of ${mid}`);
|
|
276
|
+
const firstHalf = await makeTronMultiCall(abi, calls.slice(0, mid), block, false);
|
|
277
|
+
const secondHalf = await makeTronMultiCall(abi, calls.slice(mid), block, false);
|
|
278
|
+
return [...firstHalf, ...secondHalf];
|
|
279
|
+
}
|
|
280
|
+
}
|
|
246
281
|
async function cachedCall(params) {
|
|
247
282
|
params.skipCache = true;
|
|
248
283
|
if (!isCachableAbi(params.abi))
|
package/build/abi/tron.js
CHANGED
|
@@ -47,7 +47,7 @@ const env_1 = require("../util/env");
|
|
|
47
47
|
const common_1 = require("../util/common");
|
|
48
48
|
const evmAbi = __importStar(require("./index"));
|
|
49
49
|
const callStats_1 = require("../util/callStats");
|
|
50
|
-
const limitRPCCalls = (0, p_limit_1.default)(+(0, env_1.getEnvValue)('TRON_RPC_CONCURRENCY_LIMIT'
|
|
50
|
+
const limitRPCCalls = (0, p_limit_1.default)(+(0, env_1.getEnvValue)('TRON_RPC_CONCURRENCY_LIMIT'));
|
|
51
51
|
const getEndpoint = () => (0, env_1.getEnvValue)('TRON_WALLET_RPC');
|
|
52
52
|
const balanceCache = {};
|
|
53
53
|
async function call(options) {
|
|
@@ -95,7 +95,7 @@ async function getBalances(params) {
|
|
|
95
95
|
exports.unhexifyTarget = common_1.evmToTronAddress;
|
|
96
96
|
exports.hexifyTarget = common_1.tronToEvmAddress;
|
|
97
97
|
async function post(body = {}, endpoint = '/wallet/triggerconstantcontract') {
|
|
98
|
-
await
|
|
98
|
+
// await sleepRandom(3000) // sleep random time to avoid rate limit
|
|
99
99
|
const hosts = (getEndpoint()).split(',');
|
|
100
100
|
(0, callStats_1.registerEndpoints)('tron', hosts);
|
|
101
101
|
hosts.sort(() => Math.random() - 0.5); // shuffle hosts
|