@defillama/sdk 4.0.74 → 4.0.76
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 +1 -0
- package/build/generalUtil.js +9 -4
- package/build/util/index.js +20 -20
- package/package.json +1 -1
package/build/abi/index.js
CHANGED
package/build/generalUtil.js
CHANGED
|
@@ -225,10 +225,10 @@ function formErrorString(e, errorParams) {
|
|
|
225
225
|
return "Failed to call ".concat(method, " errors:\n ").concat(eStrings.join('\n'));
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
|
-
else if (e.code === 'CALL_EXCEPTION' && errorParams.
|
|
228
|
+
else if (e.code === 'CALL_EXCEPTION' && errorParams.isCallError) {
|
|
229
229
|
var extraInfo = 'target: ' + errorParams.target;
|
|
230
230
|
if (errorParams.params && errorParams.params.length)
|
|
231
|
-
extraInfo += ' params: ' + errorParams.params.join(', ');
|
|
231
|
+
extraInfo += shortenString(' params: ' + errorParams.params.join(', '));
|
|
232
232
|
return "Failed to call ".concat(method, " ").concat(extraInfo, " on chain: [").concat(errorParams.chain, "] rpc: ").concat(providerUrl, " call reverted ").concat((_o = e.errorName) !== null && _o !== void 0 ? _o : '', " ").concat((_p = e.errorArgs) !== null && _p !== void 0 ? _p : '');
|
|
233
233
|
}
|
|
234
234
|
if (method === 'eth_blockNumber')
|
|
@@ -240,18 +240,23 @@ function formErrorString(e, errorParams) {
|
|
|
240
240
|
return errorString;
|
|
241
241
|
}
|
|
242
242
|
exports.formErrorString = formErrorString;
|
|
243
|
+
function shortenString(str, length) {
|
|
244
|
+
if (length === void 0) { length = 150; }
|
|
245
|
+
return str.length > length ? str.slice(0, length).concat('...') : str;
|
|
246
|
+
}
|
|
243
247
|
function formError(e, errorParams) {
|
|
244
248
|
var _a;
|
|
245
249
|
if (errorParams === void 0) { errorParams = {}; }
|
|
246
250
|
var error = new Error(formErrorString(e, errorParams));
|
|
247
251
|
try {
|
|
248
252
|
if (errorParams.isMultiCallError)
|
|
249
|
-
error._underlyingErrors = (_a = errorParams === null || errorParams === void 0 ? void 0 : errorParams.failedQueries) === null || _a === void 0 ? void 0 : _a.map(function (i) { return i.error.toString()
|
|
253
|
+
error._underlyingErrors = (_a = errorParams === null || errorParams === void 0 ? void 0 : errorParams.failedQueries) === null || _a === void 0 ? void 0 : _a.map(function (i) { return shortenString(i.error.toString()); });
|
|
250
254
|
else
|
|
251
|
-
error._underlyingError = e.toString()
|
|
255
|
+
error._underlyingError = shortenString(e.toString());
|
|
252
256
|
}
|
|
253
257
|
catch (e) { }
|
|
254
258
|
error._isCustomError = true;
|
|
259
|
+
error.stack = '';
|
|
255
260
|
return error;
|
|
256
261
|
}
|
|
257
262
|
exports.formError = formError;
|
package/build/util/index.js
CHANGED
|
@@ -167,7 +167,7 @@ function getBlockscoutBlock(timestamp, chain) {
|
|
|
167
167
|
}
|
|
168
168
|
var blockTimeCache = {};
|
|
169
169
|
function lookupBlock(timestamp, extraParams) {
|
|
170
|
-
var _a, _b, _c;
|
|
170
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
171
171
|
if (extraParams === void 0) { extraParams = {}; }
|
|
172
172
|
return __awaiter(this, void 0, void 0, function () {
|
|
173
173
|
function updateBlock(blocks) {
|
|
@@ -203,21 +203,21 @@ function lookupBlock(timestamp, extraParams) {
|
|
|
203
203
|
.sort(function (a, b) { return a.timestamp - b.timestamp; })[0];
|
|
204
204
|
}
|
|
205
205
|
var chain, response, e_1, api, res, data, low, lowBlock, highBlock, block, i, time, allowedTimeRange, acceptableBlockImprecision, blockImprecision, imprecision, firstBlock, lastBlock, provider, firstBlockNum, blockDiff, timeDiff, avgBlockTime, closeBlock, midBlock, blocks, e_2;
|
|
206
|
-
var
|
|
207
|
-
return __generator(this, function (
|
|
208
|
-
switch (
|
|
206
|
+
var _j;
|
|
207
|
+
return __generator(this, function (_k) {
|
|
208
|
+
switch (_k.label) {
|
|
209
209
|
case 0:
|
|
210
210
|
chain = (_a = extraParams === null || extraParams === void 0 ? void 0 : extraParams.chain) !== null && _a !== void 0 ? _a : "ethereum";
|
|
211
211
|
if (!blockscoutEndpoints[chain]) return [3 /*break*/, 4];
|
|
212
|
-
|
|
212
|
+
_k.label = 1;
|
|
213
213
|
case 1:
|
|
214
|
-
|
|
214
|
+
_k.trys.push([1, 3, , 4]);
|
|
215
215
|
return [4 /*yield*/, getBlockscoutBlock(timestamp, chain)];
|
|
216
216
|
case 2:
|
|
217
|
-
response =
|
|
217
|
+
response = _k.sent();
|
|
218
218
|
return [2 /*return*/, response];
|
|
219
219
|
case 3:
|
|
220
|
-
e_1 =
|
|
220
|
+
e_1 = _k.sent();
|
|
221
221
|
(0, debugLog_1.debugLog)('error fetching block from blockscout', e_1);
|
|
222
222
|
return [3 /*break*/, 4];
|
|
223
223
|
case 4:
|
|
@@ -225,10 +225,10 @@ function lookupBlock(timestamp, extraParams) {
|
|
|
225
225
|
api = "https://nodes.wavesnodes.com/blocks/heightByTimestamp/".concat(timestamp);
|
|
226
226
|
return [4 /*yield*/, (0, node_fetch_1.default)(api)];
|
|
227
227
|
case 5:
|
|
228
|
-
res =
|
|
228
|
+
res = _k.sent();
|
|
229
229
|
return [4 /*yield*/, res.json()];
|
|
230
230
|
case 6:
|
|
231
|
-
data =
|
|
231
|
+
data = _k.sent();
|
|
232
232
|
return [2 /*return*/, {
|
|
233
233
|
timestamp: timestamp,
|
|
234
234
|
block: +data.height
|
|
@@ -242,36 +242,36 @@ function lookupBlock(timestamp, extraParams) {
|
|
|
242
242
|
allowedTimeRange = 15 * 60 // how much imprecision is allowed (15 minutes now)
|
|
243
243
|
;
|
|
244
244
|
acceptableBlockImprecision = chain === 'ethereum' ? 20 : 200;
|
|
245
|
-
|
|
245
|
+
_k.label = 8;
|
|
246
246
|
case 8:
|
|
247
|
-
|
|
247
|
+
_k.trys.push([8, 17, , 18]);
|
|
248
248
|
firstBlock = void 0, lastBlock = void 0;
|
|
249
249
|
provider = getExtraProvider(chain);
|
|
250
250
|
if (!['evmos'].includes(chain)) return [3 /*break*/, 11];
|
|
251
251
|
return [4 /*yield*/, getBlock(provider, "latest", chain)];
|
|
252
252
|
case 9:
|
|
253
|
-
lastBlock =
|
|
253
|
+
lastBlock = _k.sent();
|
|
254
254
|
firstBlockNum = lastBlock.number;
|
|
255
255
|
switch (chain) {
|
|
256
256
|
default: firstBlockNum -= 2 * 1e5; // evmos hold only the last 200k block data
|
|
257
257
|
}
|
|
258
258
|
return [4 /*yield*/, getBlock(provider, firstBlockNum, chain)];
|
|
259
259
|
case 10:
|
|
260
|
-
firstBlock =
|
|
260
|
+
firstBlock = _k.sent();
|
|
261
261
|
return [3 /*break*/, 13];
|
|
262
262
|
case 11: return [4 /*yield*/, Promise.all([
|
|
263
263
|
getBlock(provider, "latest", chain),
|
|
264
264
|
lowBlock ? lowBlock : getBlock(provider, low, chain),
|
|
265
265
|
])];
|
|
266
266
|
case 12:
|
|
267
|
-
|
|
268
|
-
|
|
267
|
+
_j = _k.sent(), lastBlock = _j[0], firstBlock = _j[1];
|
|
268
|
+
_k.label = 13;
|
|
269
269
|
case 13:
|
|
270
270
|
lowBlock = firstBlock;
|
|
271
271
|
if (!highBlock)
|
|
272
272
|
highBlock = lastBlock;
|
|
273
273
|
if (lastBlock.timestamp - timestamp < -30 * 60) {
|
|
274
|
-
throw new Error("Last block of chain \"".concat(chain, "\" is further than 30 minutes into the past. Provider is \"").concat((_c = provider === null || provider === void 0 ? void 0 : provider.connection) === null || _c === void 0 ? void 0 : _c.url, "\""));
|
|
274
|
+
throw new Error("Last block of chain \"".concat(chain, "\" is further than 30 minutes into the past. Provider is \"").concat((_d = (_c = provider === null || provider === void 0 ? void 0 : provider.connection) === null || _c === void 0 ? void 0 : _c.url) !== null && _d !== void 0 ? _d : (_h = (_g = (_f = ((_e = provider === null || provider === void 0 ? void 0 : provider.providerConfigs) !== null && _e !== void 0 ? _e : [])[0]) === null || _f === void 0 ? void 0 : _f.provider) === null || _g === void 0 ? void 0 : _g.connection) === null || _h === void 0 ? void 0 : _h.url, "\""));
|
|
275
275
|
}
|
|
276
276
|
if (Math.abs(highBlock.timestamp - timestamp) < 60 * 30) {
|
|
277
277
|
// Short-circuit in case we are trying to get the current block
|
|
@@ -281,7 +281,7 @@ function lookupBlock(timestamp, extraParams) {
|
|
|
281
281
|
}];
|
|
282
282
|
}
|
|
283
283
|
updateBlock();
|
|
284
|
-
|
|
284
|
+
_k.label = 14;
|
|
285
285
|
case 14:
|
|
286
286
|
if (!(imprecision > allowedTimeRange && blockImprecision > acceptableBlockImprecision)) return [3 /*break*/, 16];
|
|
287
287
|
++i;
|
|
@@ -297,7 +297,7 @@ function lookupBlock(timestamp, extraParams) {
|
|
|
297
297
|
getBlock(provider, midBlock, chain),
|
|
298
298
|
])];
|
|
299
299
|
case 15:
|
|
300
|
-
blocks =
|
|
300
|
+
blocks = _k.sent();
|
|
301
301
|
updateBlock(blocks);
|
|
302
302
|
return [3 /*break*/, 14];
|
|
303
303
|
case 16:
|
|
@@ -311,7 +311,7 @@ function lookupBlock(timestamp, extraParams) {
|
|
|
311
311
|
timestamp: block.timestamp
|
|
312
312
|
}];
|
|
313
313
|
case 17:
|
|
314
|
-
e_2 =
|
|
314
|
+
e_2 = _k.sent();
|
|
315
315
|
throw (0, generalUtil_1.formError)(e_2);
|
|
316
316
|
case 18: return [2 /*return*/];
|
|
317
317
|
}
|