@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
@@ -1,36 +1,14 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
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
- };
25
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
4
  };
28
5
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.getMulticallAddress = exports.isMulticallV3Supported = void 0;
6
+ exports.default = makeMultiCall;
7
+ exports.isMulticallV3Supported = isMulticallV3Supported;
8
+ exports.getMulticallAddress = getMulticallAddress;
30
9
  const ethers_1 = require("ethers");
31
10
  const convertResults_1 = __importDefault(require("./convertResults"));
32
11
  const multicall_1 = __importDefault(require("./multicall"));
33
- const Tron = __importStar(require("./tron"));
34
12
  const index_1 = require("./index");
35
13
  // https://github.com/mds1/multicall
36
14
  // https://www.multicall3.com/deployments
@@ -221,8 +199,6 @@ const DEPLOYMENT_BLOCK = {
221
199
  '0g': 6546802,
222
200
  };
223
201
  async function makeMultiCall(functionABI, calls, chain, block) {
224
- if (chain === 'tron')
225
- return Tron.multiCall(functionABI, calls);
226
202
  if (!functionABI)
227
203
  throw new Error('Missing ABI parameter');
228
204
  if (calls.some(i => !i.contract))
@@ -231,13 +207,39 @@ async function makeMultiCall(functionABI, calls, chain, block) {
231
207
  return (0, multicall_1.default)(functionABI, calls, chain, block);
232
208
  const contractInterface = new ethers_1.ethers.Interface([functionABI]);
233
209
  let fd = contractInterface.fragments[0];
234
- const contractCalls = calls.map((call) => {
235
- const data = contractInterface.encodeFunctionData(fd, call.params);
236
- return {
237
- to: call.contract,
238
- data,
239
- };
210
+ const failedEncodingIndexes = [];
211
+ const goodEncodingIndexes = [];
212
+ const goodCalls = [];
213
+ const contractCalls = calls.map((call, idx) => {
214
+ var _a;
215
+ try {
216
+ const data = contractInterface.encodeFunctionData(fd, call.params);
217
+ if ((_a = call.contract) === null || _a === void 0 ? void 0 : _a.startsWith('0x')) {
218
+ const _isValidAddress = ethers_1.ethers.getAddress(call.contract); // Validates and checksums the address
219
+ }
220
+ goodCalls.push(call);
221
+ goodEncodingIndexes.push(idx);
222
+ return {
223
+ to: call.contract,
224
+ data,
225
+ };
226
+ }
227
+ catch (e) {
228
+ failedEncodingIndexes.push(idx);
229
+ }
240
230
  });
231
+ // if some calls failed to encode, we fetch the good ones and fill the rest with null
232
+ if (failedEncodingIndexes.length) {
233
+ const goodCallResponses = await makeMultiCall(functionABI, goodCalls, chain, block);
234
+ const responses = [];
235
+ failedEncodingIndexes.forEach(idx => {
236
+ responses[idx] = { input: { params: calls[idx].params, target: calls[idx].contract }, success: false, output: null, error: new Error('Bad encoding') };
237
+ });
238
+ goodEncodingIndexes.forEach((goodIdx, i) => {
239
+ responses[goodIdx] = goodCallResponses[i];
240
+ });
241
+ return responses;
242
+ }
241
243
  let returnValues;
242
244
  try {
243
245
  await _call();
@@ -250,7 +252,7 @@ async function makeMultiCall(functionABI, calls, chain, block) {
250
252
  let output = null;
251
253
  let error = null;
252
254
  try {
253
- output = (0, convertResults_1.default)(contractInterface.decodeFunctionResult(fd, values), fd);
255
+ output = (0, convertResults_1.default)(contractInterface.decodeFunctionResult(fd, values), { functionABI: fd, chain });
254
256
  }
255
257
  catch (e) {
256
258
  error = e;
@@ -273,7 +275,6 @@ async function makeMultiCall(functionABI, calls, chain, block) {
273
275
  returnValues = returnData;
274
276
  }
275
277
  }
276
- exports.default = makeMultiCall;
277
278
  function isMulticallV3Supported(chain, block) {
278
279
  const startBlock = DEPLOYMENT_BLOCK[chain];
279
280
  if (!startBlock)
@@ -284,14 +285,12 @@ function isMulticallV3Supported(chain, block) {
284
285
  return block === 'latest';
285
286
  return block > startBlock;
286
287
  }
287
- exports.isMulticallV3Supported = isMulticallV3Supported;
288
288
  function getMulticallAddress(chain, block) {
289
289
  var _a;
290
290
  if (!isMulticallV3Supported(chain, block))
291
291
  return null;
292
292
  return (_a = CUSTOM_MULTICALL_ADDRESSES[chain]) !== null && _a !== void 0 ? _a : MULTICALL_V3_ADDRESS;
293
293
  }
294
- exports.getMulticallAddress = getMulticallAddress;
295
294
  const CUSTOM_MULTICALL_ADDRESSES = {
296
295
  'onus': '0x748c384f759cc596f0d9fa96dcabe8a11e443b30',
297
296
  'era': '0xF9cda624FBC7e059355ce98a31693d299FACd963',
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.call = void 0;
3
+ exports.call = call;
4
4
  const events_1 = require("events");
5
5
  const debugLog_1 = require("../util/debugLog");
6
6
  const env_1 = require("../util/env");
@@ -50,7 +50,6 @@ async function call(provider, data, block, chain, options = { retry: true }) {
50
50
  }
51
51
  }
52
52
  }
53
- exports.call = call;
54
53
  function getChainCounter(chain) {
55
54
  if (!COUNTERS[chain])
56
55
  COUNTERS[chain] = {
@@ -1,4 +1,5 @@
1
1
  import { Address } from "../types";
2
+ import { evmToTronAddress, tronToEvmAddress } from "../util/common";
2
3
  type CallParams = any;
3
4
  type CallOptions = {
4
5
  target: Address;
@@ -6,10 +7,8 @@ type CallOptions = {
6
7
  params?: CallParams;
7
8
  isMulticall?: boolean;
8
9
  };
9
- export declare function call(options: CallOptions): Promise<{
10
- output: any;
11
- }>;
12
- export declare function multiCall(functionABI: any, calls: {
10
+ export declare function call(options: CallOptions): Promise<any>;
11
+ export declare function multiCall(_functionABI: any, _calls: {
13
12
  contract: string;
14
13
  params: any[];
15
14
  }[]): Promise<any>;
@@ -29,6 +28,6 @@ export declare function getBalances(params: {
29
28
  balance: any;
30
29
  }[];
31
30
  }>;
32
- export declare function unhexifyTarget(address: string): string;
33
- export declare function hexifyTarget(address: string): string;
31
+ export declare const unhexifyTarget: typeof evmToTronAddress;
32
+ export declare const hexifyTarget: typeof tronToEvmAddress;
34
33
  export {};
package/build/abi/tron.js CHANGED
@@ -1,105 +1,83 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
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
+ })();
2
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
37
  };
5
38
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.hexifyTarget = exports.unhexifyTarget = exports.getBalances = exports.getBalance = exports.multiCall = exports.call = void 0;
7
- const axios_1 = __importDefault(require("axios"));
8
- const ethers_1 = require("ethers");
9
- const tron_format_address_1 = require("tron-format-address");
10
- const convertResults_1 = __importDefault(require("./convertResults"));
11
- const debugLog_1 = require("../util/debugLog");
12
- const util_1 = require("../util");
39
+ exports.hexifyTarget = exports.unhexifyTarget = void 0;
40
+ exports.call = call;
41
+ exports.multiCall = multiCall;
42
+ exports.getBalance = getBalance;
43
+ exports.getBalances = getBalances;
13
44
  const general_1 = require("../general");
14
45
  const p_limit_1 = __importDefault(require("p-limit"));
15
46
  const env_1 = require("../util/env");
47
+ const common_1 = require("../util/common");
48
+ const evmAbi = __importStar(require("./index"));
16
49
  const limitRPCCalls = (0, p_limit_1.default)(+(0, env_1.getEnvValue)('TRON_RPC_CONCURRENCY_LIMIT', '5'));
17
- const ownerAddress = 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t';
18
- const MULTICALL_ADDRESS = 'TGXuuKAb4bnrn137u39EKbYzKNXvdCes98';
19
- const getEndpoint = () => (0, env_1.getEnvRPC)('tron');
50
+ const getEndpoint = () => (0, env_1.getEnvValue)('TRON_WALLET_RPC');
51
+ const balanceCache = {};
20
52
  async function call(options) {
21
- var _a, _b;
22
- let { target, abi, params, isMulticall, } = options;
23
- target = unhexifyTarget(target);
24
- const contractInterface = new ethers_1.ethers.Interface([abi]);
25
- const functionABI = ethers_1.ethers.FunctionFragment.from(abi);
26
- let inputTypes = ((_a = abi.inputs) !== null && _a !== void 0 ? _a : []).map((i) => i.type);
27
- if (isMulticall)
28
- inputTypes = [ethers_1.ethers.ParamType.from({
29
- components: [
30
- { name: "target", type: "address" },
31
- { name: "callData", type: "bytes" },
32
- ],
33
- name: "data",
34
- type: "tuple[]",
35
- })];
36
- const outputTypes = ((_b = abi.outputs) !== null && _b !== void 0 ? _b : []).map((i) => i.type);
37
- params.forEach((v, i) => {
38
- if (inputTypes[i] === 'address' && !v.startsWith('0x'))
39
- params[i] = (0, tron_format_address_1.toHex)(v);
40
- });
41
- const callData = contractInterface._encodeParams(inputTypes, params);
42
- const body = {
43
- owner_address: ownerAddress,
44
- contract_address: target,
45
- function_selector: contractInterface.fragments[0].format(),
46
- parameter: callData.slice(2),
47
- visible: true,
48
- };
49
- const { constant_result: [data] } = await limitRPCCalls(() => post(body));
50
- let decodedResult = contractInterface.decodeFunctionResult(functionABI, '0x' + data);
51
- decodedResult = [...decodedResult];
52
- decodedResult.forEach((v, i) => {
53
- if (outputTypes[i] === 'address' && v.startsWith('0x')) {
54
- v = (0, tron_format_address_1.fromHex)(v);
55
- decodedResult[i] = v;
56
- }
57
- let outputName = abi.outputs[i].name;
58
- if (outputName && outputName.length)
59
- decodedResult[outputName] = v;
60
- });
61
- return {
62
- output: (0, convertResults_1.default)(decodedResult, functionABI),
63
- };
53
+ return evmAbi.call({ ...options, chain: 'tron', });
64
54
  }
65
- exports.call = call;
66
- async function multiCall(functionABI, calls) {
67
- var _a;
68
- if ((_a = functionABI.inputs) === null || _a === void 0 ? void 0 : _a.length) {
69
- const inputs = functionABI.inputs;
70
- calls.forEach((call) => {
71
- var _a;
72
- (_a = call.params) === null || _a === void 0 ? void 0 : _a.forEach((v, i) => {
73
- if (inputs[i].type === 'address')
74
- call.params[i] = hexifyTarget(v);
75
- });
76
- });
77
- }
78
- const returnValues = await executeCalls(functionABI, calls);
79
- return returnValues.map((output, index) => {
80
- return {
81
- input: {
82
- params: calls[index].params,
83
- target: calls[index].contract,
84
- },
85
- success: output !== null,
86
- output,
87
- };
55
+ async function multiCall(_functionABI, _calls) {
56
+ return evmAbi.multiCall({
57
+ abi: _functionABI,
58
+ calls: _calls.map(c => ({ target: c.contract, params: c.params })),
59
+ chain: 'tron',
88
60
  });
89
61
  }
90
- exports.multiCall = multiCall;
91
62
  async function getBalance(params) {
92
- var _a, _b, _c, _d, _e;
93
- const data = await limitRPCCalls(() => post({ address: params.target, visible: true, }, '/wallet/getaccount'));
63
+ var _a, _b, _c, _d, _e, _f, _g, _h;
64
+ if (!params.target)
65
+ throw new Error('getBalance: target is required');
66
+ const data = await limitRPCCalls(() => {
67
+ if (!balanceCache[params.target])
68
+ balanceCache[params.target] = post({ address: params.target, visible: true, }, '/wallet/getaccount');
69
+ return balanceCache[params.target];
70
+ });
94
71
  const frozenBalance = (_b = (_a = data.frozen) === null || _a === void 0 ? void 0 : _a.reduce((t, { frozen_balance }) => t + frozen_balance, 0)) !== null && _b !== void 0 ? _b : 0;
95
72
  const frozenBalanceV2 = (_d = (_c = data.frozenV2) === null || _c === void 0 ? void 0 : _c.reduce((t, { amount = 0 }) => t + amount, 0)) !== null && _d !== void 0 ? _d : 0;
96
73
  const freeBalance = (_e = data.balance) !== null && _e !== void 0 ? _e : 0;
97
- const balance = (freeBalance + frozenBalance + frozenBalanceV2).toString();
74
+ const delegatedBandwidthBalance = (_f = data.delegated_frozenV2_balance_for_bandwidth) !== null && _f !== void 0 ? _f : 0;
75
+ const delegatedEnergyBalance = (_h = (_g = data.account_resource) === null || _g === void 0 ? void 0 : _g.delegated_frozenV2_balance_for_energy) !== null && _h !== void 0 ? _h : 0;
76
+ let balance = (freeBalance + frozenBalance + frozenBalanceV2 + delegatedBandwidthBalance + delegatedEnergyBalance).toString();
98
77
  return {
99
78
  output: (0, general_1.handleDecimals)(balance, params.decimals),
100
79
  };
101
80
  }
102
- exports.getBalance = getBalance;
103
81
  async function getBalances(params) {
104
82
  const { targets, decimals } = params;
105
83
  const res = await Promise.all(targets.map(i => getBalance({ target: i, decimals })));
@@ -107,123 +85,26 @@ async function getBalances(params) {
107
85
  output: res.map((v, i) => ({ target: targets[i], balance: v.output })),
108
86
  };
109
87
  }
110
- exports.getBalances = getBalances;
111
- async function executeCalls(functionABI, calls) {
112
- const contractInterface = new ethers_1.ethers.Interface([functionABI]);
113
- let fd = contractInterface.fragments[0];
114
- const contractCalls = calls.map((call) => {
115
- const data = contractInterface.encodeFunctionData(fd, call.params);
116
- return {
117
- to: call.contract,
118
- data: data,
119
- };
120
- });
121
- try {
122
- const { output: [_, returnData] } = await call({ target: MULTICALL_ADDRESS, params: [contractCalls.map((call) => ({ target: hexifyTarget(call.to), callData: call.data, isMulticall: true }))], abi: MULTICALL_ABI, isMulticall: true });
123
- return returnData.map((v) => {
124
- var _a;
125
- let decodedResult = contractInterface.decodeFunctionResult(functionABI, v);
126
- const outputTypes = ((_a = functionABI.outputs) !== null && _a !== void 0 ? _a : []).map((i) => i.type);
127
- let output = [...decodedResult];
128
- output.forEach((v, i) => {
129
- if (outputTypes[i] === 'address' && v.startsWith('0x')) {
130
- v = (0, tron_format_address_1.fromHex)(v);
131
- output[i] = v;
132
- }
133
- let outputName = functionABI.outputs[i].name;
134
- if (outputName && outputName.length)
135
- output[outputName] = v;
136
- });
137
- return (0, convertResults_1.default)(output, fd);
138
- });
139
- }
140
- catch (e) {
141
- console.error(e);
142
- if (calls.length > 10) {
143
- const chunkSize = Math.ceil(calls.length / 5);
144
- const chunks = (0, util_1.sliceIntoChunks)(calls, chunkSize);
145
- (0, debugLog_1.debugLog)(`Multicall failed, call size: ${contractCalls.length}, splitting into smaller chunks and trying again, new call size: ${chunks[0].length}`);
146
- const response = await (0, util_1.runInPromisePool)({
147
- items: chunks,
148
- concurrency: 2,
149
- processor: (calls) => executeCalls(functionABI, calls)
150
- });
151
- return response.flat();
152
- }
153
- (0, debugLog_1.debugLog)("Multicall failed, defaulting to single transactions...");
154
- }
155
- return (0, util_1.runInPromisePool)({
156
- items: calls,
157
- concurrency: 3,
158
- processor: async ({ contract, params }) => {
159
- let result = null;
160
- try {
161
- result = (await call({ target: contract, params, abi: functionABI })).output;
162
- }
163
- catch (e) {
164
- (0, debugLog_1.debugLog)(e);
165
- }
166
- return result;
167
- }
168
- });
169
- }
170
- function unhexifyTarget(address) {
171
- if (address.startsWith('0x'))
172
- return (0, tron_format_address_1.fromHex)(address);
173
- return address;
174
- }
175
- exports.unhexifyTarget = unhexifyTarget;
176
- function hexifyTarget(address) {
177
- if (!address.startsWith('0x'))
178
- return (0, tron_format_address_1.toHex)(address);
179
- return address;
180
- }
181
- exports.hexifyTarget = hexifyTarget;
88
+ exports.unhexifyTarget = common_1.evmToTronAddress;
89
+ exports.hexifyTarget = common_1.tronToEvmAddress;
182
90
  async function post(body = {}, endpoint = '/wallet/triggerconstantcontract') {
183
- const host = getEndpoint();
184
- const headers = { 'Content-Type': 'application/json' };
185
- const apiKey = (0, env_1.getEnvValue)('TRON_PRO_API_KEY');
186
- if (apiKey)
187
- headers['TRON-PRO-API-KEY'] = apiKey;
188
- const { data } = await axios_1.default.post(host + endpoint, body, {
189
- headers,
190
- });
191
- return data;
192
- }
193
- // this is needed else correct function identifier wont be picked up while calling
194
- const MULTICALL_ABI = {
195
- "inputs": [
196
- {
197
- "components": [
198
- {
199
- "internalType": "address",
200
- "name": "target",
201
- "type": "address"
202
- },
203
- {
204
- "internalType": "bytes",
205
- "name": "callData",
206
- "type": "bytes"
207
- }
208
- ],
209
- "internalType": "struct TronMulticall.Call[]",
210
- "name": "calls",
211
- "type": "tuple[]"
91
+ await (0, common_1.sleepRandom)(3000); // sleep random time to avoid rate limit
92
+ const hosts = (getEndpoint()).split(',');
93
+ hosts.sort(() => Math.random() - 0.5); // shuffle hosts
94
+ const errors = [];
95
+ for (const host of hosts) {
96
+ try {
97
+ const headers = { 'Content-Type': 'application/json' };
98
+ const apiKey = (0, env_1.getEnvValue)('TRON_PRO_API_KEY');
99
+ if (apiKey)
100
+ headers['TRON-PRO-API-KEY'] = apiKey;
101
+ const res = await (0, common_1.postJson)(host + endpoint, body, { headers, });
102
+ return res;
212
103
  }
213
- ],
214
- "name": "aggregate",
215
- "outputs": [
216
- {
217
- "internalType": "uint256",
218
- "name": "blockNumber",
219
- "type": "uint256"
220
- },
221
- {
222
- "internalType": "bytes[]",
223
- "name": "returnData",
224
- "type": "bytes[]"
104
+ catch (e) {
105
+ // debugLog('Tron RPC error', e.message)
106
+ errors.push(e);
225
107
  }
226
- ],
227
- "stateMutability": "view",
228
- "type": "function"
229
- };
108
+ }
109
+ throw new Error((0, common_1.shortenString)(`All TRON RPCs are not working. Errors: ${errors.map((i) => i.message).join('; ')}`, 1500));
110
+ }
package/build/api.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.config = exports.abi = exports.erc20 = exports.eth = exports.util = void 0;
27
37
  exports.util = __importStar(require("./util"));
package/build/api2.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.config = exports.abi = exports.erc20 = exports.eth = exports.util = void 0;
27
37
  exports.util = __importStar(require("./util"));
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.humanizeNumber = void 0;
3
+ exports.humanizeNumber = humanizeNumber;
4
4
  function humanizeNumber(amount) {
5
5
  const quantifiers = [
6
6
  [10 ** 9, "B"],
@@ -14,4 +14,3 @@ function humanizeNumber(amount) {
14
14
  }
15
15
  return amount.toString();
16
16
  }
17
- exports.humanizeNumber = humanizeNumber;
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.balanceOf = exports.totalSupply = exports.decimals = exports.symbol = exports.info = void 0;
3
+ exports.info = info;
4
+ exports.symbol = symbol;
5
+ exports.decimals = decimals;
6
+ exports.totalSupply = totalSupply;
7
+ exports.balanceOf = balanceOf;
4
8
  const ethers_1 = require("ethers");
5
9
  const general_1 = require("../general");
6
10
  const abi = [
@@ -23,19 +27,16 @@ async function info(tokenAddress, chain) {
23
27
  },
24
28
  };
25
29
  }
26
- exports.info = info;
27
30
  async function symbol(tokenAddress, chain) {
28
31
  return {
29
32
  output: await getContract(tokenAddress, chain).symbol(),
30
33
  };
31
34
  }
32
- exports.symbol = symbol;
33
35
  async function decimals(tokenAddress, chain) {
34
36
  return {
35
37
  output: Number(await getContract(tokenAddress, chain).decimals()),
36
38
  };
37
39
  }
38
- exports.decimals = decimals;
39
40
  async function totalSupply(params) {
40
41
  const contract = getContract(params.target, params.chain);
41
42
  const supply = await contract.totalSupply({
@@ -45,7 +46,6 @@ async function totalSupply(params) {
45
46
  output: (0, general_1.handleDecimals)(supply, params.decimals),
46
47
  };
47
48
  }
48
- exports.totalSupply = totalSupply;
49
49
  async function balanceOf(params) {
50
50
  const balance = await getContract(params.target, params.chain).balanceOf(params.owner, {
51
51
  blockTag: params.block,
@@ -54,4 +54,3 @@ async function balanceOf(params) {
54
54
  output: (0, general_1.handleDecimals)(balance, params.decimals),
55
55
  };
56
56
  }
57
- exports.balanceOf = balanceOf;
@@ -16,6 +16,7 @@ export declare function getBalances(params: {
16
16
  chain?: Chain;
17
17
  logArray?: LogArray;
18
18
  skipMultiCall?: boolean;
19
+ permitFailure?: boolean;
19
20
  }): Promise<{
20
21
  output: any;
21
22
  }>;