@defillama/sdk 4.0.74 → 4.0.75

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.
Files changed (62) hide show
  1. package/build/{abi → src/abi}/index.js +1 -0
  2. package/build/{generalUtil.js → src/generalUtil.js} +9 -4
  3. package/build/{util → src/util}/index.js +20 -20
  4. package/build/test.d.ts +1 -0
  5. package/build/test.js +62 -0
  6. package/package.json +1 -1
  7. /package/build/{Balances.d.ts → src/Balances.d.ts} +0 -0
  8. /package/build/{Balances.js → src/Balances.js} +0 -0
  9. /package/build/{ChainApi.d.ts → src/ChainApi.d.ts} +0 -0
  10. /package/build/{ChainApi.js → src/ChainApi.js} +0 -0
  11. /package/build/{abi → src/abi}/abi2.d.ts +0 -0
  12. /package/build/{abi → src/abi}/abi2.js +0 -0
  13. /package/build/{abi → src/abi}/cachedABIs.d.ts +0 -0
  14. /package/build/{abi → src/abi}/cachedABIs.js +0 -0
  15. /package/build/{abi → src/abi}/convertResults.d.ts +0 -0
  16. /package/build/{abi → src/abi}/convertResults.js +0 -0
  17. /package/build/{abi → src/abi}/index.d.ts +0 -0
  18. /package/build/{abi → src/abi}/multicall.d.ts +0 -0
  19. /package/build/{abi → src/abi}/multicall.js +0 -0
  20. /package/build/{abi → src/abi}/multicall3.d.ts +0 -0
  21. /package/build/{abi → src/abi}/multicall3.js +0 -0
  22. /package/build/{abi → src/abi}/rpcCall.d.ts +0 -0
  23. /package/build/{abi → src/abi}/rpcCall.js +0 -0
  24. /package/build/{abi → src/abi}/tron.d.ts +0 -0
  25. /package/build/{abi → src/abi}/tron.js +0 -0
  26. /package/build/{api.d.ts → src/api.d.ts} +0 -0
  27. /package/build/{api.js → src/api.js} +0 -0
  28. /package/build/{api2.d.ts → src/api2.d.ts} +0 -0
  29. /package/build/{api2.js → src/api2.js} +0 -0
  30. /package/build/{computeTVL → src/computeTVL}/blocks.d.ts +0 -0
  31. /package/build/{computeTVL → src/computeTVL}/blocks.js +0 -0
  32. /package/build/{computeTVL → src/computeTVL}/humanizeNumber.d.ts +0 -0
  33. /package/build/{computeTVL → src/computeTVL}/humanizeNumber.js +0 -0
  34. /package/build/{computeTVL → src/computeTVL}/prices.d.ts +0 -0
  35. /package/build/{computeTVL → src/computeTVL}/prices.js +0 -0
  36. /package/build/{erc20 → src/erc20}/index.d.ts +0 -0
  37. /package/build/{erc20 → src/erc20}/index.js +0 -0
  38. /package/build/{eth → src/eth}/index.d.ts +0 -0
  39. /package/build/{eth → src/eth}/index.js +0 -0
  40. /package/build/{general.d.ts → src/general.d.ts} +0 -0
  41. /package/build/{general.js → src/general.js} +0 -0
  42. /package/build/{generalUtil.d.ts → src/generalUtil.d.ts} +0 -0
  43. /package/build/{index.d.ts → src/index.d.ts} +0 -0
  44. /package/build/{index.js → src/index.js} +0 -0
  45. /package/build/{providers.json → src/providers.json} +0 -0
  46. /package/build/{types.d.ts → src/types.d.ts} +0 -0
  47. /package/build/{types.js → src/types.js} +0 -0
  48. /package/build/{util → src/util}/cache.d.ts +0 -0
  49. /package/build/{util → src/util}/cache.js +0 -0
  50. /package/build/{util → src/util}/computeTVL.d.ts +0 -0
  51. /package/build/{util → src/util}/computeTVL.js +0 -0
  52. /package/build/{util → src/util}/debugLog.d.ts +0 -0
  53. /package/build/{util → src/util}/debugLog.js +0 -0
  54. /package/build/{util → src/util}/index.d.ts +0 -0
  55. /package/build/{util → src/util}/internal-cache.d.ts +0 -0
  56. /package/build/{util → src/util}/internal-cache.js +0 -0
  57. /package/build/{util → src/util}/promisePool.d.ts +0 -0
  58. /package/build/{util → src/util}/promisePool.js +0 -0
  59. /package/build/{util → src/util}/r2.d.ts +0 -0
  60. /package/build/{util → src/util}/r2.js +0 -0
  61. /package/build/{util → src/util}/updateProviderList.d.ts +0 -0
  62. /package/build/{util → src/util}/updateProviderList.js +0 -0
@@ -208,6 +208,7 @@ function call(params) {
208
208
  }];
209
209
  case 3:
210
210
  e_1 = _c.sent();
211
+ errorParams.isCallError = true;
211
212
  throw (0, generalUtil_1.formError)(e_1, errorParams);
212
213
  case 4: return [2 /*return*/];
213
214
  }
@@ -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.chain && errorParams.result === '0x') {
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().slice(0, 150); });
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().slice(0, 150);
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;
@@ -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 _d;
207
- return __generator(this, function (_e) {
208
- switch (_e.label) {
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
- _e.label = 1;
212
+ _k.label = 1;
213
213
  case 1:
214
- _e.trys.push([1, 3, , 4]);
214
+ _k.trys.push([1, 3, , 4]);
215
215
  return [4 /*yield*/, getBlockscoutBlock(timestamp, chain)];
216
216
  case 2:
217
- response = _e.sent();
217
+ response = _k.sent();
218
218
  return [2 /*return*/, response];
219
219
  case 3:
220
- e_1 = _e.sent();
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 = _e.sent();
228
+ res = _k.sent();
229
229
  return [4 /*yield*/, res.json()];
230
230
  case 6:
231
- data = _e.sent();
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
- _e.label = 8;
245
+ _k.label = 8;
246
246
  case 8:
247
- _e.trys.push([8, 17, , 18]);
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 = _e.sent();
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 = _e.sent();
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
- _d = _e.sent(), lastBlock = _d[0], firstBlock = _d[1];
268
- _e.label = 13;
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
- _e.label = 14;
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 = _e.sent();
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 = _e.sent();
314
+ e_2 = _k.sent();
315
315
  throw (0, generalUtil_1.formError)(e_2);
316
316
  case 18: return [2 /*return*/];
317
317
  }
@@ -0,0 +1 @@
1
+ export {};
package/build/test.js ADDED
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ // process.env.ETHEREUM_RPC=''
3
+ // process.env.SDK_MULTICALL_CHUNK_SIZE='100'
4
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
5
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
6
+ return new (P || (P = Promise))(function (resolve, reject) {
7
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
8
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
9
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
10
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
11
+ });
12
+ };
13
+ var __generator = (this && this.__generator) || function (thisArg, body) {
14
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
15
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
16
+ function verb(n) { return function (v) { return step([n, v]); }; }
17
+ function step(op) {
18
+ if (f) throw new TypeError("Generator is already executing.");
19
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
20
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
21
+ if (y = 0, t) op = [op[0] & 2, t.value];
22
+ switch (op[0]) {
23
+ case 0: case 1: t = op; break;
24
+ case 4: _.label++; return { value: op[1], done: false };
25
+ case 5: _.label++; y = op[1]; op = [0]; continue;
26
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
27
+ default:
28
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
29
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
30
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
31
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
32
+ if (t[2]) _.ops.pop();
33
+ _.trys.pop(); continue;
34
+ }
35
+ op = body.call(thisArg, _);
36
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
37
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
38
+ }
39
+ };
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ var src_1 = require("./src");
42
+ function run() {
43
+ return __awaiter(this, void 0, void 0, function () {
44
+ var api, calls, target, loanData;
45
+ return __generator(this, function (_a) {
46
+ switch (_a.label) {
47
+ case 0:
48
+ api = new src_1.ChainApi({
49
+ chain: 'ethereum',
50
+ });
51
+ calls = ["76", "91", "92", "93", "94", "100", "101", "124", "125", "126", "137", "142", "147", "150", "173", "179", "183", "195", "198", "203", "238", "245", "258", "281", "283", "286", "294", "296", "302", "303", "324", "338", "342", "344", "351", "352", "353", "365", "386", "428", "436", "437", "438", "439", "440", "442", "444", "445", "451", "453", "454", "461", "462", "465", "468", "481", "482", "483", "491", "495", "496", "497", "498", "499", "505", "506", "523", "525", "527", "528", "529", "531", "541", "596", "599", "605", "610", "611", "612", "613", "614", "615", "616", "617", "618", "619", "620", "622", "623", "655", "663", "664", "665", "666", "680", "709", "771", "772", "776", "777", "778", "779", "780", "783", "785", "802", "806", "816", "819", "824", "852", "853", "888", "896", "906", "907", "921", "927", "928", "929", "930", "931", "932", "933", "934", "935", "939", "942", "943", "950", "956", "957", "958", "961", "972", "978", "980", "987", "997", "998", "1001", "1002", "1003", "1004", "1005", "1010", "1011", "1012", "1013", "1014", "1015", "1016", "1017", "1018", "1019", "1024", "1025", "1029", "1031", "1036", "1037", "1046", "1063", "1064", "1065", "1067", "1068", "1071", "1072", "1073", "1079", "1080", "1089", "1090", "1091", "1092", "1093", "1094", "1096", "1105", "1106", "1107", "1111", "1112", "1114", "1115", "1116", "1117", "1123", "1126", "1127", "1131", "1132", "1134", "1142", "1146", "1147", "1149", "1154", "1155", "1156", "1158", "1159", "1160", "1165", "1166", "1167"];
52
+ target = '0x00182FdB0B880eE24D428e3Cc39383717677C37e';
53
+ return [4 /*yield*/, api.multiCall({ abi: "function bids(uint256) view returns (address borrower, address receiver, address lender, uint256 marketplaceId, bytes32 _metadataURI, tuple(address lendingToken, uint256 principal, tuple(uint256 principal, uint256 interest) totalRepaid, uint32 timestamp, uint32 acceptedTimestamp, uint32 lastRepaidTimestamp, uint32 loanDuration) loanDetails, tuple(uint256 paymentCycleAmount, uint32 paymentCycle, uint16 APR) terms, uint8 state, uint8 paymentType)", calls: calls, target: target, })];
54
+ case 1:
55
+ loanData = _a.sent();
56
+ console.log(loanData.length);
57
+ return [2 /*return*/];
58
+ }
59
+ });
60
+ });
61
+ }
62
+ run().catch(console.error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defillama/sdk",
3
- "version": "4.0.74",
3
+ "version": "4.0.75",
4
4
  "description": "SDK for calculating TVL",
5
5
  "main": "build/index.js",
6
6
  "scripts": {
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes