@defillama/sdk 5.0.10 → 5.0.12

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 (40) hide show
  1. package/build/Balances.d.ts +10 -0
  2. package/build/Balances.js +51 -107
  3. package/build/ChainApi.d.ts +1 -0
  4. package/build/ChainApi.js +152 -253
  5. package/build/abi/abi2.js +47 -144
  6. package/build/abi/convertResults.js +9 -29
  7. package/build/abi/index.js +220 -326
  8. package/build/abi/multicall.js +115 -217
  9. package/build/abi/multicall3.js +59 -123
  10. package/build/abi/rpcCall.js +43 -106
  11. package/build/abi/tron.js +153 -283
  12. package/build/api.js +3 -4
  13. package/build/computeTVL/blocks.d.ts +1 -1
  14. package/build/computeTVL/blocks.js +2 -1
  15. package/build/computeTVL/humanizeNumber.js +6 -7
  16. package/build/computeTVL/prices.js +55 -145
  17. package/build/erc20/index.js +34 -122
  18. package/build/eth/index.js +37 -107
  19. package/build/general.js +22 -23
  20. package/build/generalUtil.js +68 -127
  21. package/build/index.js +2 -2
  22. package/build/providers.json +1 -1
  23. package/build/util/blocks.d.ts +5 -2
  24. package/build/util/blocks.js +234 -373
  25. package/build/util/blockscout.js +13 -58
  26. package/build/util/cache.js +112 -274
  27. package/build/util/computeTVL.js +72 -150
  28. package/build/util/cosmos.js +21 -75
  29. package/build/util/debugLog.js +5 -13
  30. package/build/util/env.d.ts +3 -2
  31. package/build/util/env.js +30 -35
  32. package/build/util/index.d.ts +5 -3
  33. package/build/util/index.js +105 -134
  34. package/build/util/internal-cache.js +7 -8
  35. package/build/util/logs.d.ts +1 -2
  36. package/build/util/logs.js +148 -236
  37. package/build/util/promisePool.js +11 -62
  38. package/build/util/r2.js +36 -95
  39. package/build/util/updateProviderList.js +23 -83
  40. package/package.json +2 -3
package/build/general.js CHANGED
@@ -4,14 +4,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.setProvider = exports.ETHER_ADDRESS = exports.handleDecimals = exports.TEN = exports.getProvider = exports.providers = void 0;
7
- var debugLog_1 = require("./util/debugLog");
8
- var ethers_1 = require("ethers");
9
- var providers_json_1 = __importDefault(require("./providers.json"));
10
- var env_1 = require("./util/env");
11
- function createProvider(name, rpcString, chainId) {
7
+ const debugLog_1 = require("./util/debugLog");
8
+ const ethers_1 = require("ethers");
9
+ const providers_json_1 = __importDefault(require("./providers.json"));
10
+ const env_1 = require("./util/env");
11
+ function createProvider(name, rpcString, chainId = 400069) {
12
12
  chainId = (0, env_1.getChainId)(name, chainId);
13
- var networkish = { name: name, chainId: chainId };
14
- var rpcList = rpcString.split(',');
13
+ const networkish = { name, chainId };
14
+ const rpcList = rpcString.split(',');
15
15
  if ((0, env_1.getEnvValue)('HISTORICAL')) {
16
16
  if (chainId === 1) {
17
17
  (0, debugLog_1.debugLog)("RPC providers set to historical, only the first RPC provider will be used");
@@ -20,7 +20,8 @@ function createProvider(name, rpcString, chainId) {
20
20
  }
21
21
  else {
22
22
  try {
23
- return new ethers_1.ethers.FallbackProvider(rpcList.map(function (url, i) { return ({ provider: getProviderObject(url, name), priority: i, chainId: chainId, }); }), networkish, { cacheTimeout: 5 * 1000, quorum: 1, eventQuorum: 1, });
23
+ const providerList = rpcList.map((url, i) => ({ provider: getProviderObject(url, name), chainId, }));
24
+ return new ethers_1.ethers.FallbackProvider(providerList, networkish, { cacheTimeout: 5 * 1000, quorum: 1, eventQuorum: 1, });
24
25
  }
25
26
  catch (e) {
26
27
  // debugLog(`Error creating provider for ${name} with RPCs: ${rpcList.join(', ')}`)
@@ -70,8 +71,8 @@ function createProvider(name, rpcString, chainId) {
70
71
  */
71
72
  // const batchMaxSize = 10 * (1024 * 1024) // 10Mb
72
73
  // some rpcs throw error if batchMaxCount is set higher than 100
73
- var batchMaxCount = (0, env_1.getBatchMaxCount)(chain);
74
- var jsonRpcApiProviderOptions = { staticNetwork: true, batchStallTime: 42, batchMaxCount: batchMaxCount, cacheTimeout: 5 * 1000 };
74
+ const batchMaxCount = (0, env_1.getBatchMaxCount)(chain);
75
+ const jsonRpcApiProviderOptions = { staticNetwork: true, batchStallTime: 42, batchMaxCount, };
75
76
  if (url.startsWith('wss://')) {
76
77
  delete jsonRpcApiProviderOptions.batchMaxCount;
77
78
  return new ethers_1.ethers.WebSocketProvider(url, networkish, jsonRpcApiProviderOptions);
@@ -80,28 +81,26 @@ function createProvider(name, rpcString, chainId) {
80
81
  }
81
82
  }
82
83
  exports.providers = {};
83
- var archivalProviders = {};
84
- function getProvider(chain, getArchivalNode) {
84
+ const archivalProviders = {};
85
+ function getProvider(chain = "ethereum", getArchivalNode = false) {
85
86
  var _a, _b, _c;
86
- if (chain === void 0) { chain = "ethereum"; }
87
- if (getArchivalNode === void 0) { getArchivalNode = false; }
88
87
  if (getArchivalNode) {
89
88
  if (archivalProviders[chain])
90
89
  return archivalProviders[chain]._provider;
91
- var rpcList_1 = (0, env_1.getArchivalRPCs)(chain);
92
- if (rpcList_1.length) {
90
+ let rpcList = (0, env_1.getArchivalRPCs)(chain);
91
+ if (rpcList.length) {
93
92
  // shuffle rpcList
94
- rpcList_1 = rpcList_1.sort(function () { return Math.random() - 0.5; });
95
- var provider = createProvider(chain, rpcList_1.join(','), (_a = providers_json_1.default[chain]) === null || _a === void 0 ? void 0 : _a.chainId);
96
- if (rpcList_1.length === 1)
97
- archivalProviders[chain] = { rpcList: rpcList_1[0], _provider: provider };
93
+ rpcList = rpcList.sort(() => Math.random() - 0.5);
94
+ const provider = createProvider(chain, rpcList.join(','), (_a = providers_json_1.default[chain]) === null || _a === void 0 ? void 0 : _a.chainId);
95
+ if (rpcList.length === 1)
96
+ archivalProviders[chain] = { rpcList: rpcList[0], _provider: provider };
98
97
  return provider;
99
98
  }
100
99
  }
101
100
  if (exports.providers[chain] && !getArchivalNode)
102
101
  return exports.providers[chain]._provider;
103
102
  // use RPC from env variable if set else use RPC from providers.json
104
- var rpcList = (0, env_1.getChainRPCs)(chain, (_b = providers_json_1.default[chain]) === null || _b === void 0 ? void 0 : _b.rpc);
103
+ let rpcList = (0, env_1.getChainRPCs)(chain, (_b = providers_json_1.default[chain]) === null || _b === void 0 ? void 0 : _b.rpc);
105
104
  if (!rpcList) {
106
105
  // in case provider was set using `setProvider` function
107
106
  if (exports.providers[chain])
@@ -111,7 +110,7 @@ function getProvider(chain, getArchivalNode) {
111
110
  }
112
111
  if (!exports.providers[chain] || exports.providers[chain].rpcList !== rpcList) {
113
112
  exports.providers[chain] = {
114
- rpcList: rpcList,
113
+ rpcList,
115
114
  _provider: createProvider(chain, rpcList, (_c = providers_json_1.default[chain]) === null || _c === void 0 ? void 0 : _c.chainId)
116
115
  };
117
116
  }
@@ -126,7 +125,7 @@ function handleDecimals(num, decimals) {
126
125
  return num.toString();
127
126
  }
128
127
  else {
129
- return Number(num / (Math.pow(10, decimals))).toString();
128
+ return Number(num / (10 ** decimals)).toString();
130
129
  }
131
130
  }
132
131
  exports.handleDecimals = handleDecimals;
@@ -22,52 +22,16 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __generator = (this && this.__generator) || function (thisArg, body) {
35
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
- function verb(n) { return function (v) { return step([n, v]); }; }
38
- function step(op) {
39
- if (f) throw new TypeError("Generator is already executing.");
40
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
41
- 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;
42
- if (y = 0, t) op = [op[0] & 2, t.value];
43
- switch (op[0]) {
44
- case 0: case 1: t = op; break;
45
- case 4: _.label++; return { value: op[1], done: false };
46
- case 5: _.label++; y = op[1]; op = [0]; continue;
47
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
- default:
49
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
- if (t[2]) _.ops.pop();
54
- _.trys.pop(); continue;
55
- }
56
- op = body.call(thisArg, _);
57
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
- }
60
- };
61
25
  Object.defineProperty(exports, "__esModule", { value: true });
62
26
  exports.formError = exports.formErrorString = exports.getProviderUrl = exports.getUniqueAddresses = exports.humanizeNumber = exports.blocks = exports.sumChainTvls = exports.removeTokenBalance = exports.mergeBalances = exports.sumSingleBalance = exports.sumMultiBalanceOf = exports.convertToBigInt = void 0;
63
- var blocks = __importStar(require("./computeTVL/blocks"));
27
+ const blocks = __importStar(require("./computeTVL/blocks"));
64
28
  exports.blocks = blocks;
65
- var humanizeNumber = __importStar(require("./computeTVL/humanizeNumber"));
29
+ const humanizeNumber = __importStar(require("./computeTVL/humanizeNumber"));
66
30
  exports.humanizeNumber = humanizeNumber;
67
- var ethers = __importStar(require("ethers"));
31
+ const ethers = __importStar(require("ethers"));
68
32
  // We ignore `sum` as it's never used (only in some SDK wrapper code)
69
33
  function convertToBigInt(value) {
70
- var balance = value;
34
+ const balance = value;
71
35
  if (!value)
72
36
  return BigInt(0);
73
37
  if (typeof value === 'bigint')
@@ -76,10 +40,10 @@ function convertToBigInt(value) {
76
40
  value = value.toString();
77
41
  if (typeof value === 'string') {
78
42
  if (!value.startsWith('0x') && value.includes('e')) { // Convert scientific notation to standard notation
79
- var _a = value.split('e'), base = _a[0], e = _a[1];
80
- var _b = base.split('.'), lead = _b[0], decimal = _b[1];
81
- var final = void 0;
82
- var exponent = +e;
43
+ let [base, e] = value.split('e');
44
+ const [lead, decimal] = base.split('.');
45
+ let final;
46
+ let exponent = +e;
83
47
  if (exponent >= 0) {
84
48
  final = lead + (decimal || '') + '0'.repeat(exponent - (decimal || '').length);
85
49
  }
@@ -94,17 +58,15 @@ function convertToBigInt(value) {
94
58
  }
95
59
  if (typeof value === 'string')
96
60
  return BigInt(value);
97
- throw new Error("Invalid balance: ".concat(balance));
61
+ throw new Error(`Invalid balance: ${balance}`);
98
62
  }
99
63
  exports.convertToBigInt = convertToBigInt;
100
- function sumMultiBalanceOf(balances, results, allCallsMustBeSuccessful, transformAddress) {
101
- if (allCallsMustBeSuccessful === void 0) { allCallsMustBeSuccessful = true; }
102
- if (transformAddress === void 0) { transformAddress = function (addr) { return addr; }; }
103
- results.output.map(function (result) {
64
+ function sumMultiBalanceOf(balances, results, allCallsMustBeSuccessful = true, transformAddress = (addr) => addr) {
65
+ results.output.map((result) => {
104
66
  var _a;
105
67
  if (result.success) {
106
- var address = transformAddress(result.input.target);
107
- var balance = result.output;
68
+ const address = transformAddress(result.input.target);
69
+ const balance = result.output;
108
70
  if (BigInt(balance) <= 0) {
109
71
  return;
110
72
  }
@@ -112,7 +74,7 @@ function sumMultiBalanceOf(balances, results, allCallsMustBeSuccessful, transfor
112
74
  }
113
75
  else if (allCallsMustBeSuccessful) {
114
76
  console.error(result);
115
- throw new Error("balanceOf multicall failed");
77
+ throw new Error(`balanceOf multicall failed`);
116
78
  }
117
79
  });
118
80
  }
@@ -124,7 +86,7 @@ function sumSingleBalance(balances, token, balance, chain) {
124
86
  if (+balance === 0)
125
87
  return;
126
88
  if (chain)
127
- token = "".concat(chain, ":").concat(token);
89
+ token = `${chain}:${token}`;
128
90
  if (typeof balance === 'object') {
129
91
  if (typeof balance.toString === 'function')
130
92
  balance = balance.toString();
@@ -132,16 +94,16 @@ function sumSingleBalance(balances, token, balance, chain) {
132
94
  throw new Error('Invalid balance value:' + balance);
133
95
  }
134
96
  if (typeof balance === 'number' || (balances[token] && typeof balances[token] === 'number')) {
135
- var prevBalance = +(balances.hasOwnProperty(token) ? balances[token] : 0);
97
+ const prevBalance = +(balances.hasOwnProperty(token) ? balances[token] : 0);
136
98
  if (typeof prevBalance !== 'number' || isNaN(prevBalance))
137
- throw new Error("Trying to merge token balance and coingecko amount for ".concat(token, " current balance: ").concat(balance, " previous balance: ").concat(balances[token]));
138
- var value = prevBalance + +balance;
99
+ throw new Error(`Trying to merge token balance and coingecko amount for ${token} current balance: ${balance} previous balance: ${balances[token]}`);
100
+ const value = prevBalance + +balance;
139
101
  isValidNumber(value);
140
102
  balances[token] = value;
141
103
  }
142
104
  else {
143
- var prevBalance = convertToBigInt(balances[token]);
144
- var value = (prevBalance + convertToBigInt(balance));
105
+ const prevBalance = convertToBigInt(balances[token]);
106
+ const value = (prevBalance + convertToBigInt(balance));
145
107
  isValidNumber(Number(value));
146
108
  balances[token] = Number(value).toString();
147
109
  }
@@ -149,22 +111,21 @@ function sumSingleBalance(balances, token, balance, chain) {
149
111
  if (typeof value === 'bigint')
150
112
  return;
151
113
  if ([null, undefined].includes(value) || isNaN(+value))
152
- throw new Error("Invalid balance: ".concat(balance));
114
+ throw new Error(`Invalid balance: ${balance}`);
153
115
  }
154
116
  }
155
117
  exports.sumSingleBalance = sumSingleBalance;
156
118
  function mergeBalances(balances, balancesToMerge) {
157
119
  if (balances === balancesToMerge)
158
120
  return;
159
- Object.entries(balancesToMerge).forEach(function (balance) {
121
+ Object.entries(balancesToMerge).forEach((balance) => {
160
122
  sumSingleBalance(balances, balance[0], balance[1]);
161
123
  });
162
124
  }
163
125
  exports.mergeBalances = mergeBalances;
164
- function removeTokenBalance(balances, token, isCaseSensitive) {
165
- if (isCaseSensitive === void 0) { isCaseSensitive = false; }
166
- var re = new RegExp(token, isCaseSensitive ? undefined : 'i');
167
- Object.keys(balances).forEach(function (key) {
126
+ function removeTokenBalance(balances, token, isCaseSensitive = false) {
127
+ const re = new RegExp(token, isCaseSensitive ? undefined : 'i');
128
+ Object.keys(balances).forEach(key => {
168
129
  if (re.test(key))
169
130
  delete balances[key];
170
131
  });
@@ -172,41 +133,23 @@ function removeTokenBalance(balances, token, isCaseSensitive) {
172
133
  }
173
134
  exports.removeTokenBalance = removeTokenBalance;
174
135
  function sumChainTvls(chainTvls) {
175
- var _this = this;
176
- return function (timestamp, ethBlock, chainBlocks, params) { return __awaiter(_this, void 0, void 0, function () {
177
- var api;
178
- var _this = this;
179
- return __generator(this, function (_a) {
180
- switch (_a.label) {
181
- case 0:
182
- api = params.api;
183
- return [4 /*yield*/, Promise.all(chainTvls.map(function (chainTvl) { return __awaiter(_this, void 0, void 0, function () {
184
- var chainBalances;
185
- return __generator(this, function (_a) {
186
- switch (_a.label) {
187
- case 0: return [4 /*yield*/, chainTvl(timestamp, ethBlock, chainBlocks, params)];
188
- case 1:
189
- chainBalances = _a.sent();
190
- api.addBalances(chainBalances);
191
- return [2 /*return*/];
192
- }
193
- });
194
- }); }))];
195
- case 1:
196
- _a.sent();
197
- return [2 /*return*/, api.getBalances()];
198
- }
199
- });
200
- }); };
136
+ return async (timestamp, ethBlock, chainBlocks, params) => {
137
+ const api = params.api;
138
+ await Promise.all(chainTvls.map(async (chainTvl) => {
139
+ const chainBalances = await chainTvl(timestamp, ethBlock, chainBlocks, params);
140
+ api.addBalances(chainBalances);
141
+ }));
142
+ return api.getBalances();
143
+ };
201
144
  }
202
145
  exports.sumChainTvls = sumChainTvls;
203
146
  function getUniqueAddresses(addresses, chain) {
204
147
  if (!addresses.length)
205
148
  return [];
206
- var isTronAddress = chain === 'tron' && addresses[0].startsWith('T');
207
- var toLowerCase = !isTronAddress;
208
- var set = {};
209
- addresses.forEach(function (i) { return set[toLowerCase ? i.toLowerCase() : i] = true; });
149
+ const isTronAddress = chain === 'tron' && addresses[0].startsWith('T');
150
+ const toLowerCase = !isTronAddress;
151
+ const set = {};
152
+ addresses.forEach(i => set[toLowerCase ? i.toLowerCase() : i] = true);
210
153
  return Object.keys(set);
211
154
  }
212
155
  exports.getUniqueAddresses = getUniqueAddresses;
@@ -218,34 +161,33 @@ function getProviderUrl(provider) {
218
161
  return '';
219
162
  }
220
163
  exports.getProviderUrl = getProviderUrl;
221
- function formErrorString(e, errorParams) {
164
+ function formErrorString(e, errorParams = {}) {
222
165
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
223
- if (errorParams === void 0) { errorParams = {}; }
224
166
  if (!e) {
225
167
  if (errorParams.promisePoolErrors) {
226
- var errors = errorParams.promisePoolErrors.map(function (i) { return formErrorString(i); });
227
- return "Promise pool failed! \n ".concat(errors.join('\n'));
168
+ const errors = errorParams.promisePoolErrors.map((i) => formErrorString(i));
169
+ return `Promise pool failed! \n ${errors.join('\n')}`;
228
170
  }
229
171
  if (errorParams.isMultiCallError) {
230
- var targetStr_1 = errorParams.target ? "[target: ".concat(errorParams.target, "]") : '';
231
- var errorString_1 = "Multicall failed! \n [chain: ".concat((_a = errorParams.chain) !== null && _a !== void 0 ? _a : "ethereum", "] [fail count: ").concat((_b = errorParams.failedQueries) === null || _b === void 0 ? void 0 : _b.length, "] [abi: ").concat(errorParams.abi, "] ").concat(targetStr_1, " ");
232
- (_c = errorParams.failedQueries) === null || _c === void 0 ? void 0 : _c.forEach(function (i) {
172
+ const targetStr = errorParams.target ? `[target: ${errorParams.target}]` : '';
173
+ let errorString = `Multicall failed! \n [chain: ${(_a = errorParams.chain) !== null && _a !== void 0 ? _a : "ethereum"}] [fail count: ${(_b = errorParams.failedQueries) === null || _b === void 0 ? void 0 : _b.length}] [abi: ${errorParams.abi}] ${targetStr} `;
174
+ (_c = errorParams.failedQueries) === null || _c === void 0 ? void 0 : _c.forEach((i) => {
233
175
  i = i.input;
234
- var target = !targetStr_1 ? " target: ".concat(i.target) : '';
235
- var params = i.params && i.params.length ? "params: ".concat(i.params.length === 1 ? i.params[0] : i.params.join(', '), "]") : '';
236
- errorString_1 += "\n ".concat(target, " ").concat(params);
176
+ let target = !targetStr ? ` target: ${i.target}` : '';
177
+ let params = i.params && i.params.length ? `params: ${i.params.length === 1 ? i.params[0] : i.params.join(', ')}]` : '';
178
+ errorString += `\n ${target} ${params}`;
237
179
  });
238
180
  // truncate error string to 310 chars
239
- return errorString_1.length > 310 ? errorString_1.slice(0, 310).concat('...') : errorString_1;
181
+ return errorString.length > 310 ? errorString.slice(0, 310).concat('...') : errorString;
240
182
  }
241
183
  return '';
242
184
  }
243
- var errorString = e.toString();
185
+ let errorString = e.toString();
244
186
  if (typeof e !== 'object')
245
187
  return errorString;
246
188
  if (((e.reason || e.method || e.shortMessage) && e.code) || errorParams.result === '0x') { // ethers.js error
247
- var errorMessage = (_k = (_j = (_h = (_g = (_f = (_e = (_d = e.info) === null || _d === void 0 ? void 0 : _d.error) === null || _e === void 0 ? void 0 : _e.message) !== null && _f !== void 0 ? _f : e.message) !== null && _g !== void 0 ? _g : e.shortMessage) !== null && _h !== void 0 ? _h : e.errorName) !== null && _j !== void 0 ? _j : e.reason) !== null && _k !== void 0 ? _k : '';
248
- var method = (_p = (_l = e.method) !== null && _l !== void 0 ? _l : (_o = (_m = e.info) === null || _m === void 0 ? void 0 : _m.request) === null || _o === void 0 ? void 0 : _o.method) !== null && _p !== void 0 ? _p : errorParams.abi;
189
+ const errorMessage = (_k = (_j = (_h = (_g = (_f = (_e = (_d = e.info) === null || _d === void 0 ? void 0 : _d.error) === null || _e === void 0 ? void 0 : _e.message) !== null && _f !== void 0 ? _f : e.message) !== null && _g !== void 0 ? _g : e.shortMessage) !== null && _h !== void 0 ? _h : e.errorName) !== null && _j !== void 0 ? _j : e.reason) !== null && _k !== void 0 ? _k : '';
190
+ let method = (_p = (_l = e.method) !== null && _l !== void 0 ? _l : (_o = (_m = e.info) === null || _m === void 0 ? void 0 : _m.request) === null || _o === void 0 ? void 0 : _o.method) !== null && _p !== void 0 ? _p : errorParams.abi;
249
191
  if (e.body) {
250
192
  try {
251
193
  e.body = JSON.parse(e.body);
@@ -263,51 +205,50 @@ function formErrorString(e, errorParams) {
263
205
  }
264
206
  else if (!e.provider && errorParams.provider)
265
207
  e.provider = errorParams.provider;
266
- var providerUrl = getProviderUrl((_t = e.provider) !== null && _t !== void 0 ? _t : errorParams.provider);
208
+ let providerUrl = getProviderUrl((_t = e.provider) !== null && _t !== void 0 ? _t : errorParams.provider);
267
209
  if (e.serverError)
268
- return "host: ".concat(providerUrl, " ").concat(e.serverError.toString());
210
+ return `host: ${providerUrl} ${e.serverError.toString()}`;
269
211
  if (e.results) {
270
- var errors = e.results.filter(function (i) { return i.error; }).map(function (i) { return i.error; });
212
+ let errors = e.results.filter((i) => i.error).map((i) => i.error);
271
213
  if (errors.length) {
272
- var eStrings = errors.map(function (i) { return formError(i); });
273
- return "Failed to call method: ".concat(method, " provider: ").concat(providerUrl, "\n ").concat(eStrings.join('\n'));
214
+ const eStrings = errors.map((i) => formError(i));
215
+ return `Failed to call method: ${method} provider: ${providerUrl}
216
+ ${eStrings.join('\n')}`;
274
217
  }
275
218
  }
276
219
  else if (e.code === 'CALL_EXCEPTION' || errorParams.isCallError) {
277
- var extraInfo = 'target: ' + errorParams.target;
220
+ let extraInfo = 'target: ' + errorParams.target;
278
221
  if (errorParams.params && Array.isArray(errorParams.params) && errorParams.params.length)
279
222
  extraInfo += shortenString(' params: ' + errorParams.params.join(', '));
280
- return "Failed to call: ".concat(method, " ").concat(extraInfo, " on chain: [").concat(errorParams.chain, "] rpc: ").concat(providerUrl, " call reverted, reason: ").concat(errorMessage, " ").concat((_u = e.errorArgs) !== null && _u !== void 0 ? _u : '');
223
+ return `Failed to call: ${method} ${extraInfo} on chain: [${errorParams.chain}] rpc: ${providerUrl} call reverted, reason: ${errorMessage} ${(_u = e.errorArgs) !== null && _u !== void 0 ? _u : ''}`;
281
224
  }
282
225
  else if (e.code === 'BAD_DATA') {
283
226
  if (!method)
284
227
  method = (_w = (_v = e === null || e === void 0 ? void 0 : e.info) === null || _v === void 0 ? void 0 : _v.payload) === null || _w === void 0 ? void 0 : _w.method;
285
- var extraInfo = 'target: ' + errorParams.target;
286
- return "Failed method: ".concat(method, " ").concat(shortenString(extraInfo), " on chain: [").concat(errorParams.chain, "] rpc: ").concat(providerUrl, " reason: ").concat(errorMessage, " ").concat((_x = e.errorArgs) !== null && _x !== void 0 ? _x : '');
228
+ let extraInfo = 'target: ' + errorParams.target;
229
+ return `Failed method: ${method} ${shortenString(extraInfo)} on chain: [${errorParams.chain}] rpc: ${providerUrl} reason: ${errorMessage} ${(_x = e.errorArgs) !== null && _x !== void 0 ? _x : ''}`;
287
230
  }
288
231
  if (method === 'eth_blockNumber')
289
- return "host: ".concat(providerUrl, " reason: ").concat(e.reason, " code: ").concat(e.code);
232
+ return `host: ${providerUrl} reason: ${e.reason} code: ${e.code}`;
290
233
  if (method === 'getBlockNumber')
291
- return "Failed to call ".concat(method, " ").concat(providerUrl, " reason: ").concat(e.reason, " code: ").concat(e.code);
292
- return "Failed to call ".concat(method, " on ").concat(providerUrl, " reason: ").concat(e.reason, " code: ").concat(e.code);
234
+ return `Failed to call ${method} ${providerUrl} reason: ${e.reason} code: ${e.code}`;
235
+ return `Failed to call ${method} on ${providerUrl} reason: ${e.reason} code: ${e.code}`;
293
236
  }
294
237
  return errorString;
295
238
  }
296
239
  exports.formErrorString = formErrorString;
297
- function shortenString(str, length) {
298
- if (length === void 0) { length = 150; }
240
+ function shortenString(str, length = 150) {
299
241
  return str.length > length ? str.slice(0, length).concat('...') : str;
300
242
  }
301
- function formError(e, errorParams) {
243
+ function formError(e, errorParams = {}) {
302
244
  var _a;
303
- if (errorParams === void 0) { errorParams = {}; }
304
- var errorParamsSet = Object.keys(errorParams).length;
245
+ const errorParamsSet = Object.keys(errorParams).length;
305
246
  if ((e === null || e === void 0 ? void 0 : e._isCustomError) || (!errorParamsSet && typeof e === 'object' && !Object.keys(e).length))
306
247
  return e; // already formatted or vannila error
307
- var error = new Error(formErrorString(e, errorParams));
248
+ const error = new Error(formErrorString(e, errorParams));
308
249
  try {
309
250
  if (errorParams.isMultiCallError)
310
- 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()); });
251
+ error._underlyingErrors = (_a = errorParams === null || errorParams === void 0 ? void 0 : errorParams.failedQueries) === null || _a === void 0 ? void 0 : _a.map((i) => shortenString(i.error.toString()));
311
252
  else
312
253
  error._underlyingError = shortenString(e.toString());
313
254
  }
package/build/index.js CHANGED
@@ -24,7 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.humanizeNumber = exports.logTable = exports.log = exports.blocks = exports.api2 = exports.api = exports.sdkCache = exports.getEventLogs = exports.cache = exports.util = exports.setProvider = exports.getProvider = exports.Balances = exports.ChainApi = void 0;
27
- var debugLog_1 = require("./util/debugLog");
27
+ const debugLog_1 = require("./util/debugLog");
28
28
  var ChainApi_1 = require("./ChainApi");
29
29
  Object.defineProperty(exports, "ChainApi", { enumerable: true, get: function () { return ChainApi_1.ChainApi; } });
30
30
  var Balances_1 = require("./Balances");
@@ -40,7 +40,7 @@ exports.sdkCache = __importStar(require("./util/internal-cache"));
40
40
  exports.api = __importStar(require("./api"));
41
41
  exports.api2 = __importStar(require("./api2"));
42
42
  exports.blocks = __importStar(require("./computeTVL/blocks"));
43
- var humanN = __importStar(require("./computeTVL/humanizeNumber"));
43
+ const humanN = __importStar(require("./computeTVL/humanizeNumber"));
44
44
  exports.log = debugLog_1.debugLog;
45
45
  exports.logTable = debugLog_1.debugTable;
46
46
  exports.humanizeNumber = humanN.humanizeNumber;