@defillama/sdk 5.0.173 → 5.0.177

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 (53) hide show
  1. package/build/Balances.d.ts +2 -2
  2. package/build/ChainApi.d.ts +26 -14
  3. package/build/ChainApi.js +58 -28
  4. package/build/abi/abi2.js +23 -15
  5. package/build/abi/cachedABIs.d.ts +1 -1
  6. package/build/abi/convertResults.d.ts +4 -1
  7. package/build/abi/convertResults.js +20 -15
  8. package/build/abi/index.js +16 -39
  9. package/build/abi/multicall.js +6 -31
  10. package/build/abi/multicall3.js +36 -37
  11. package/build/abi/rpcCall.js +1 -2
  12. package/build/abi/tron.d.ts +5 -6
  13. package/build/abi/tron.js +79 -198
  14. package/build/api.js +17 -7
  15. package/build/api2.js +17 -7
  16. package/build/computeTVL/humanizeNumber.js +1 -2
  17. package/build/erc20/index.js +5 -6
  18. package/build/eth/index.d.ts +1 -0
  19. package/build/eth/index.js +39 -16
  20. package/build/general.js +2 -2
  21. package/build/generalUtil.d.ts +2 -24
  22. package/build/generalUtil.js +39 -246
  23. package/build/index.js +17 -7
  24. package/build/providers.json +1 -1
  25. package/build/util/LlamaProvider.js +8 -3
  26. package/build/util/blocks.js +17 -20
  27. package/build/util/cache.d.ts +11 -2
  28. package/build/util/cache.js +53 -9
  29. package/build/util/common.d.ts +33 -0
  30. package/build/util/common.js +352 -0
  31. package/build/util/computeTVL.js +6 -11
  32. package/build/util/cosmos.js +6 -9
  33. package/build/util/debugLog.js +3 -3
  34. package/build/util/elastic.d.ts +19 -0
  35. package/build/util/elastic.js +54 -6
  36. package/build/util/env.d.ts +7 -1
  37. package/build/util/env.js +28 -15
  38. package/build/util/graph.js +4 -8
  39. package/build/util/index.d.ts +1 -1
  40. package/build/util/index.js +17 -15
  41. package/build/util/indexer.js +29 -19
  42. package/build/util/internal-cache.js +22 -13
  43. package/build/util/logs.js +7 -7
  44. package/build/util/promisePool.d.ts +4 -1
  45. package/build/util/promisePool.js +22 -7
  46. package/build/util/r2.d.ts +0 -1
  47. package/build/util/r2.js +4 -9
  48. package/build/util/removeRedundantRPCs.js +2 -2
  49. package/build/util/transactions.js +1 -2
  50. package/build/util/updateProviderList.js +6 -6
  51. package/package.json +3 -1
  52. package/build/computeTVL/prices.d.ts +0 -9
  53. package/build/computeTVL/prices.js +0 -73
@@ -15,22 +15,35 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getBalances = exports.getBalance = void 0;
36
+ exports.getBalance = getBalance;
37
+ exports.getBalances = getBalances;
27
38
  const general_1 = require("../general");
28
39
  const Tron = __importStar(require("../abi/tron"));
29
40
  const multicall3_1 = require("../abi/multicall3");
30
41
  const abi2_1 = require("../abi/abi2");
31
42
  const debugLog_1 = require("../util/debugLog");
43
+ const generalUtil_1 = require("../generalUtil");
32
44
  async function getBalance(params) {
33
45
  var _a;
46
+ // this is needed eth.getBalances doesnt include staked trx value
34
47
  if (params.chain === 'tron')
35
48
  return Tron.getBalance(params);
36
49
  const balance = await (0, general_1.getProvider)(params.chain).getBalance(params.target, params.block);
@@ -46,9 +59,9 @@ async function getBalance(params) {
46
59
  output,
47
60
  };
48
61
  }
49
- exports.getBalance = getBalance;
50
62
  async function getBalances(params) {
51
63
  var _a;
64
+ // this is needed eth.getBalances doesnt include staked trx value
52
65
  if (params.chain === 'tron')
53
66
  return Tron.getBalances(params);
54
67
  let output;
@@ -61,10 +74,11 @@ async function getBalances(params) {
61
74
  abi: 'function getEthBalance(address addr) view returns (uint256)',
62
75
  chain: params.chain,
63
76
  block: params.block,
77
+ permitFailure: params.permitFailure,
64
78
  });
65
79
  output = multicallResults.map((value, i) => ({
66
80
  target: params.targets[i],
67
- balance: (0, general_1.handleDecimals)(value, params.decimals)
81
+ balance: (0, general_1.handleDecimals)(value !== null && value !== void 0 ? value : '0', params.decimals)
68
82
  }));
69
83
  }
70
84
  }
@@ -72,11 +86,21 @@ async function getBalances(params) {
72
86
  (0, debugLog_1.debugLog)('Multicall failed, falling back to single calls for fetching eth balances', e);
73
87
  }
74
88
  if (!output) {
75
- const balances = params.targets.map(async (target) => ({
76
- target,
77
- balance: (0, general_1.handleDecimals)(await (0, general_1.getProvider)(params.chain).getBalance(target, params.block), params.decimals),
78
- }));
79
- output = await Promise.all(balances);
89
+ output = await (0, generalUtil_1.runInPromisePool)({
90
+ items: params.targets,
91
+ concurrency: 7,
92
+ processor: async (target) => ({
93
+ target,
94
+ balance: (0, general_1.handleDecimals)(await (0, general_1.getProvider)(params.chain).getBalance(target, params.block), params.decimals),
95
+ }),
96
+ permitFailure: params.permitFailure
97
+ });
98
+ // If some calls failed, fill their balance with 0
99
+ if (params.permitFailure)
100
+ output.forEach((o, idx) => {
101
+ if (!(o === null || o === void 0 ? void 0 : o.balance))
102
+ output[idx] = { target: params.targets[idx], balance: '0' };
103
+ });
80
104
  }
81
105
  if (params.logArray)
82
106
  params.logArray.push(...params.targets.map((holder, i) => {
@@ -92,4 +116,3 @@ async function getBalances(params) {
92
116
  output,
93
117
  };
94
118
  }
95
- exports.getBalances = getBalances;
package/build/general.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ETHER_ADDRESS = exports.handleDecimals = exports.TEN = exports.getProvider = exports.setProvider = exports.providers = void 0;
3
+ exports.ETHER_ADDRESS = exports.TEN = exports.getProvider = exports.setProvider = exports.providers = void 0;
4
+ exports.handleDecimals = handleDecimals;
4
5
  var LlamaProvider_1 = require("./util/LlamaProvider");
5
6
  Object.defineProperty(exports, "providers", { enumerable: true, get: function () { return LlamaProvider_1.providers; } });
6
7
  Object.defineProperty(exports, "setProvider", { enumerable: true, get: function () { return LlamaProvider_1.setProvider; } });
@@ -16,5 +17,4 @@ function handleDecimals(num, decimals) {
16
17
  return Number(num / (10 ** decimals)).toString();
17
18
  }
18
19
  }
19
- exports.handleDecimals = handleDecimals;
20
20
  exports.ETHER_ADDRESS = "0x0000000000000000000000000000000000000000";
@@ -1,28 +1,6 @@
1
1
  import * as blocks from "./computeTVL/blocks";
2
2
  import * as humanizeNumber from "./computeTVL/humanizeNumber";
3
- import type { Balances, StringNumber, Address } from "./types";
4
3
  export { sliceIntoChunks, normalizeAddress, getTimestamp, tableToString, } from "./util";
5
- export declare function convertToBigInt(value: any): bigint;
6
- export declare function sumMultiBalanceOf(balances: Balances, results: {
7
- ethCallCount?: number;
8
- output: {
9
- output: StringNumber;
10
- success: boolean;
11
- input: {
12
- target: Address;
13
- params: string[];
14
- };
15
- }[];
16
- }, allCallsMustBeSuccessful?: boolean, transformAddress?: (addr: string) => string): void;
17
- export declare function sumSingleBalance(balances: Balances, token: string, balance: string | number | BigInt, chain?: string): void;
18
- export declare function mergeBalances(balances: Balances, balancesToMerge: Balances): void;
19
- export declare function removeTokenBalance(balances: Balances, token: string, isCaseSensitive?: boolean): Balances;
20
- type ChainBlocks = {
21
- [chain: string]: number;
22
- };
23
- export declare function sumChainTvls(chainTvls: Array<(timestamp: number, ethBlock: number, chainBlocks: ChainBlocks, params: any) => Promise<Balances>>): (timestamp: number, ethBlock: number, chainBlocks: ChainBlocks, params: any) => Promise<any>;
4
+ export { runInPromisePool } from "./util/promisePool";
5
+ export { sumMultiBalanceOf, sumSingleBalance, mergeBalances, removeTokenBalance, sumChainTvls, getUniqueAddresses, convertToBigInt, getProviderUrl, formError, formErrorString, shortenString, fetchJson, postJson, tronToEvmAddress, evmToTronAddress, sleep, sleepRandom, } from './util/common';
24
6
  export { blocks, humanizeNumber, };
25
- export declare function getUniqueAddresses(addresses: string[], chain?: string): string[];
26
- export declare function getProviderUrl(provider: any): any;
27
- export declare function formErrorString(e: any, errorParams?: any): any;
28
- export declare function formError(e: any, errorParams?: any): Error;
@@ -15,259 +15,52 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
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 = exports.tableToString = exports.getTimestamp = exports.normalizeAddress = exports.sliceIntoChunks = void 0;
36
+ exports.humanizeNumber = exports.blocks = exports.sleepRandom = exports.sleep = exports.evmToTronAddress = exports.tronToEvmAddress = exports.postJson = exports.fetchJson = exports.shortenString = exports.formErrorString = exports.formError = exports.getProviderUrl = exports.convertToBigInt = exports.getUniqueAddresses = exports.sumChainTvls = exports.removeTokenBalance = exports.mergeBalances = exports.sumSingleBalance = exports.sumMultiBalanceOf = exports.runInPromisePool = exports.tableToString = exports.getTimestamp = exports.normalizeAddress = exports.sliceIntoChunks = void 0;
27
37
  const blocks = __importStar(require("./computeTVL/blocks"));
28
38
  exports.blocks = blocks;
29
39
  const humanizeNumber = __importStar(require("./computeTVL/humanizeNumber"));
30
40
  exports.humanizeNumber = humanizeNumber;
31
- const ethers = __importStar(require("ethers"));
32
41
  var util_1 = require("./util");
33
42
  Object.defineProperty(exports, "sliceIntoChunks", { enumerable: true, get: function () { return util_1.sliceIntoChunks; } });
34
43
  Object.defineProperty(exports, "normalizeAddress", { enumerable: true, get: function () { return util_1.normalizeAddress; } });
35
44
  Object.defineProperty(exports, "getTimestamp", { enumerable: true, get: function () { return util_1.getTimestamp; } });
36
45
  Object.defineProperty(exports, "tableToString", { enumerable: true, get: function () { return util_1.tableToString; } });
37
- // We ignore `sum` as it's never used (only in some SDK wrapper code)
38
- function convertToBigInt(value) {
39
- const balance = value;
40
- if (!value)
41
- return BigInt(0);
42
- if (typeof value === 'bigint')
43
- return value;
44
- if (typeof value === 'number')
45
- value = value.toString();
46
- if (typeof value === 'string') {
47
- if (!value.startsWith('0x') && value.includes('e')) { // Convert scientific notation to standard notation
48
- let [base, e] = value.split('e');
49
- const [lead, decimal] = base.split('.');
50
- let final;
51
- let exponent = +e;
52
- if (exponent >= 0) {
53
- final = lead + (decimal || '') + '0'.repeat(exponent - (decimal || '').length);
54
- }
55
- else {
56
- // NOTE: unforutenately BigInt doesn't support negative exponents, so this ends up being 0
57
- exponent = exponent * -1;
58
- final = BigInt(lead) / BigInt('1' + Array(exponent).fill(0).join(''));
59
- }
60
- return BigInt(final);
61
- }
62
- return BigInt(value);
63
- }
64
- if (typeof value === 'string')
65
- return BigInt(value);
66
- throw new Error(`Invalid balance: ${balance}`);
67
- }
68
- exports.convertToBigInt = convertToBigInt;
69
- function sumMultiBalanceOf(balances, results, allCallsMustBeSuccessful = true, transformAddress = (addr) => addr) {
70
- results.output.map((result) => {
71
- var _a;
72
- if (result.success) {
73
- const address = transformAddress(result.input.target);
74
- const balance = result.output;
75
- if (BigInt(balance) <= 0) {
76
- return;
77
- }
78
- balances[address] = (BigInt((_a = balances[address]) !== null && _a !== void 0 ? _a : 0) + BigInt(balance)).toString();
79
- }
80
- else if (allCallsMustBeSuccessful) {
81
- console.error(result);
82
- throw new Error(`balanceOf multicall failed`);
83
- }
84
- });
85
- }
86
- exports.sumMultiBalanceOf = sumMultiBalanceOf;
87
- function sumSingleBalance(balances, token, balance, chain) {
88
- if (typeof balance === 'bigint')
89
- balance = balance.toString();
90
- isValidNumber(balance);
91
- if (+balance === 0)
92
- return;
93
- if (chain)
94
- token = `${chain}:${token}`;
95
- if (typeof balance === 'object') {
96
- if (typeof balance.toString === 'function')
97
- balance = balance.toString();
98
- else
99
- throw new Error('Invalid balance value:' + balance);
100
- }
101
- if (typeof balance === 'number' || (balances[token] && typeof balances[token] === 'number')) {
102
- const prevBalance = +(balances.hasOwnProperty(token) ? balances[token] : 0);
103
- if (typeof prevBalance !== 'number' || isNaN(prevBalance))
104
- throw new Error(`Trying to merge token balance and coingecko amount for ${token} current balance: ${balance} previous balance: ${balances[token]}`);
105
- const value = prevBalance + +balance;
106
- isValidNumber(value);
107
- balances[token] = value;
108
- }
109
- else {
110
- const prevBalance = convertToBigInt(balances[token]);
111
- const value = (prevBalance + convertToBigInt(balance));
112
- isValidNumber(Number(value));
113
- balances[token] = Number(value).toString();
114
- }
115
- function isValidNumber(value) {
116
- if (typeof value === 'bigint')
117
- return;
118
- if ([null, undefined].includes(value) || isNaN(+value))
119
- throw new Error(`Invalid balance: ${balance}`);
120
- }
121
- }
122
- exports.sumSingleBalance = sumSingleBalance;
123
- function mergeBalances(balances, balancesToMerge) {
124
- if (balances === balancesToMerge)
125
- return;
126
- Object.entries(balancesToMerge).forEach((balance) => {
127
- sumSingleBalance(balances, balance[0], balance[1]);
128
- });
129
- }
130
- exports.mergeBalances = mergeBalances;
131
- function removeTokenBalance(balances, token, isCaseSensitive = false) {
132
- const re = new RegExp(token, isCaseSensitive ? undefined : 'i');
133
- Object.keys(balances).forEach(key => {
134
- if (re.test(key))
135
- delete balances[key];
136
- });
137
- return balances;
138
- }
139
- exports.removeTokenBalance = removeTokenBalance;
140
- function sumChainTvls(chainTvls) {
141
- return async (timestamp, ethBlock, chainBlocks, params) => {
142
- const api = params.api;
143
- await Promise.all(chainTvls.map(async (chainTvl) => {
144
- const chainBalances = await chainTvl(timestamp, ethBlock, chainBlocks, params);
145
- api.addBalances(chainBalances);
146
- }));
147
- return api.getBalances();
148
- };
149
- }
150
- exports.sumChainTvls = sumChainTvls;
151
- function getUniqueAddresses(addresses, chain) {
152
- if (!addresses.length)
153
- return [];
154
- const isTronAddress = chain === 'tron' && addresses[0].startsWith('T');
155
- const toLowerCase = !isTronAddress;
156
- const set = {};
157
- addresses.forEach(i => set[toLowerCase ? i.toLowerCase() : i] = true);
158
- return Object.keys(set);
159
- }
160
- exports.getUniqueAddresses = getUniqueAddresses;
161
- function getProviderUrl(provider) {
162
- if (provider === null || provider === void 0 ? void 0 : provider.isCustomLlamaProvider)
163
- return provider.rpcs.map((i) => i.url).join(', ');
164
- if (provider instanceof ethers.FallbackProvider)
165
- provider = provider.providerConfigs[0].provider;
166
- if (provider instanceof ethers.JsonRpcProvider)
167
- return provider._getConnection().url;
168
- return '';
169
- }
170
- exports.getProviderUrl = getProviderUrl;
171
- function formErrorString(e, errorParams = {}) {
172
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
173
- if (!e) {
174
- if (errorParams.promisePoolErrors) {
175
- const errors = errorParams.promisePoolErrors.map((i) => formErrorString(i));
176
- return `Promise pool failed! \n ${errors.join('\n')}`;
177
- }
178
- if (errorParams.isMultiCallError) {
179
- const targetStr = errorParams.target ? `[target: ${errorParams.target}]` : '';
180
- 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} `;
181
- (_c = errorParams.failedQueries) === null || _c === void 0 ? void 0 : _c.forEach((i) => {
182
- i = i.input;
183
- let target = !targetStr ? ` target: ${i.target}` : '';
184
- let params = i.params && i.params.length ? `params: ${i.params.length === 1 ? i.params[0] : i.params.join(', ')}]` : '';
185
- errorString += `\n ${target} ${params}`;
186
- });
187
- // truncate error string to 310 chars
188
- return errorString.length > 310 ? errorString.slice(0, 310).concat('...') : errorString;
189
- }
190
- return '';
191
- }
192
- if (e.llamaRPCError) {
193
- const errorString = `Llama RPC error! method: ${e.method} `;
194
- const errors = e.errors.map((i) => { var _a; return `- host: ${i === null || i === void 0 ? void 0 : i.host} error: ${(_a = i === null || i === void 0 ? void 0 : i.error) === null || _a === void 0 ? void 0 : _a.message}`; });
195
- return errorString + '\n' + errors.join('\n');
196
- }
197
- let errorString = e.toString();
198
- if (typeof e !== 'object')
199
- return errorString;
200
- if (((e.reason || e.method || e.shortMessage) && e.code) || errorParams.result === '0x') { // ethers.js error
201
- 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 : '';
202
- 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;
203
- if (e.body) {
204
- try {
205
- e.body = JSON.parse(e.body);
206
- }
207
- catch (e) { }
208
- if ((_r = (_q = e.body) === null || _q === void 0 ? void 0 : _q.error) === null || _r === void 0 ? void 0 : _r.message)
209
- return e.body.error.message;
210
- }
211
- if (!method && e.requestBody) {
212
- try {
213
- e.requestBody = JSON.parse(e.requestBody);
214
- }
215
- catch (e) { }
216
- method = (_s = e.requestBody) === null || _s === void 0 ? void 0 : _s.method;
217
- }
218
- else if (!e.provider && errorParams.provider)
219
- e.provider = errorParams.provider;
220
- let providerUrl = getProviderUrl((_t = e.provider) !== null && _t !== void 0 ? _t : errorParams.provider);
221
- if (e.serverError)
222
- return `host: ${providerUrl} ${e.serverError.toString()}`;
223
- if (e.results) {
224
- let errors = e.results.filter((i) => i.error).map((i) => i.error);
225
- if (errors.length) {
226
- const eStrings = errors.map((i) => formError(i));
227
- return `Failed to call method: ${method} provider: ${providerUrl}
228
- ${eStrings.join('\n')}`;
229
- }
230
- }
231
- else if (e.code === 'CALL_EXCEPTION' || errorParams.isCallError) {
232
- let extraInfo = 'target: ' + errorParams.target;
233
- if (errorParams.params && Array.isArray(errorParams.params) && errorParams.params.length)
234
- extraInfo += shortenString(' params: ' + errorParams.params.join(', '));
235
- return `Failed to call: ${method} ${extraInfo} on chain: [${errorParams.chain}] rpc: ${providerUrl} call reverted, reason: ${errorMessage} ${(_u = e.errorArgs) !== null && _u !== void 0 ? _u : ''}`;
236
- }
237
- else if (e.code === 'BAD_DATA') {
238
- if (!method)
239
- 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;
240
- let extraInfo = 'target: ' + errorParams.target;
241
- return `Failed method: ${method} ${shortenString(extraInfo)} on chain: [${errorParams.chain}] rpc: ${providerUrl} reason: ${errorMessage} ${(_x = e.errorArgs) !== null && _x !== void 0 ? _x : ''}`;
242
- }
243
- if (method === 'eth_blockNumber')
244
- return `host: ${providerUrl} reason: ${e.reason} code: ${e.code}`;
245
- if (method === 'getBlockNumber')
246
- return `Failed to call ${method} ${providerUrl} reason: ${e.reason} code: ${e.code}`;
247
- return `Failed to call ${method} on ${providerUrl} reason: ${e.reason} code: ${e.code}`;
248
- }
249
- return errorString;
250
- }
251
- exports.formErrorString = formErrorString;
252
- function shortenString(str, length = 150) {
253
- return str.length > length ? str.slice(0, length).concat('...') : str;
254
- }
255
- function formError(e, errorParams = {}) {
256
- var _a;
257
- const errorParamsSet = Object.keys(errorParams).length;
258
- if ((e === null || e === void 0 ? void 0 : e._isCustomError) || (!errorParamsSet && typeof e === 'object' && !Object.keys(e).length))
259
- return e; // already formatted or vannila error
260
- const error = new Error(formErrorString(e, errorParams));
261
- try {
262
- if (errorParams.isMultiCallError)
263
- 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()));
264
- else
265
- error._underlyingError = shortenString(e.toString());
266
- }
267
- catch (e) { }
268
- error._isCustomError = true;
269
- error.message = shortenString(error.message, 2999);
270
- error.stack = '';
271
- return error;
272
- }
273
- exports.formError = formError;
46
+ var promisePool_1 = require("./util/promisePool");
47
+ Object.defineProperty(exports, "runInPromisePool", { enumerable: true, get: function () { return promisePool_1.runInPromisePool; } });
48
+ // most of the code has been moved to util/common.ts to avoid circular dependencies
49
+ var common_1 = require("./util/common");
50
+ Object.defineProperty(exports, "sumMultiBalanceOf", { enumerable: true, get: function () { return common_1.sumMultiBalanceOf; } });
51
+ Object.defineProperty(exports, "sumSingleBalance", { enumerable: true, get: function () { return common_1.sumSingleBalance; } });
52
+ Object.defineProperty(exports, "mergeBalances", { enumerable: true, get: function () { return common_1.mergeBalances; } });
53
+ Object.defineProperty(exports, "removeTokenBalance", { enumerable: true, get: function () { return common_1.removeTokenBalance; } });
54
+ Object.defineProperty(exports, "sumChainTvls", { enumerable: true, get: function () { return common_1.sumChainTvls; } });
55
+ Object.defineProperty(exports, "getUniqueAddresses", { enumerable: true, get: function () { return common_1.getUniqueAddresses; } });
56
+ Object.defineProperty(exports, "convertToBigInt", { enumerable: true, get: function () { return common_1.convertToBigInt; } });
57
+ Object.defineProperty(exports, "getProviderUrl", { enumerable: true, get: function () { return common_1.getProviderUrl; } });
58
+ Object.defineProperty(exports, "formError", { enumerable: true, get: function () { return common_1.formError; } });
59
+ Object.defineProperty(exports, "formErrorString", { enumerable: true, get: function () { return common_1.formErrorString; } });
60
+ Object.defineProperty(exports, "shortenString", { enumerable: true, get: function () { return common_1.shortenString; } });
61
+ Object.defineProperty(exports, "fetchJson", { enumerable: true, get: function () { return common_1.fetchJson; } });
62
+ Object.defineProperty(exports, "postJson", { enumerable: true, get: function () { return common_1.postJson; } });
63
+ Object.defineProperty(exports, "tronToEvmAddress", { enumerable: true, get: function () { return common_1.tronToEvmAddress; } });
64
+ Object.defineProperty(exports, "evmToTronAddress", { enumerable: true, get: function () { return common_1.evmToTronAddress; } });
65
+ Object.defineProperty(exports, "sleep", { enumerable: true, get: function () { return common_1.sleep; } });
66
+ Object.defineProperty(exports, "sleepRandom", { enumerable: true, get: function () { return common_1.sleepRandom; } });
package/build/index.js CHANGED
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  exports.humanizeNumber = exports.logTable = exports.log = exports.erc20 = exports.tron = exports.types = exports.indexer = exports.graph = exports.blocks = exports.api2 = exports.elastic = exports.api = exports.sdkCache = exports.getEventLogs = exports.cache = exports.util = exports.setProvider = exports.getProvider = exports.Balances = exports.ChainApi = void 0;
27
37
  const debugLog_1 = require("./util/debugLog");