@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
@@ -1 +1 @@
1
- export { getChainBlocks, getBlocks, getBlock, getCurrentBlocks, chainsForBlocks, } from "../util/blocks";
1
+ export { getChainBlocks, getBlocks, getBlock, getCurrentBlocks, chainsForBlocks, getBlockNumber, } from "../util/blocks";
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.chainsForBlocks = exports.getCurrentBlocks = exports.getBlock = exports.getBlocks = exports.getChainBlocks = void 0;
3
+ exports.getBlockNumber = exports.chainsForBlocks = exports.getCurrentBlocks = exports.getBlock = exports.getBlocks = exports.getChainBlocks = void 0;
4
4
  var blocks_1 = require("../util/blocks");
5
5
  Object.defineProperty(exports, "getChainBlocks", { enumerable: true, get: function () { return blocks_1.getChainBlocks; } });
6
6
  Object.defineProperty(exports, "getBlocks", { enumerable: true, get: function () { return blocks_1.getBlocks; } });
7
7
  Object.defineProperty(exports, "getBlock", { enumerable: true, get: function () { return blocks_1.getBlock; } });
8
8
  Object.defineProperty(exports, "getCurrentBlocks", { enumerable: true, get: function () { return blocks_1.getCurrentBlocks; } });
9
9
  Object.defineProperty(exports, "chainsForBlocks", { enumerable: true, get: function () { return blocks_1.chainsForBlocks; } });
10
+ Object.defineProperty(exports, "getBlockNumber", { enumerable: true, get: function () { return blocks_1.getBlockNumber; } });
@@ -2,15 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.humanizeNumber = void 0;
4
4
  function humanizeNumber(amount) {
5
- var quantifiers = [
6
- [Math.pow(10, 9), "B"],
7
- [Math.pow(10, 6), "M"],
8
- [Math.pow(10, 3), "k"],
5
+ const quantifiers = [
6
+ [10 ** 9, "B"],
7
+ [10 ** 6, "M"],
8
+ [10 ** 3, "k"],
9
9
  ];
10
- for (var _i = 0, quantifiers_1 = quantifiers; _i < quantifiers_1.length; _i++) {
11
- var _a = quantifiers_1[_i], denominator = _a[0], letter = _a[1];
10
+ for (const [denominator, letter] of quantifiers) {
12
11
  if (amount > denominator) {
13
- return "".concat((amount / denominator).toFixed(2), " ").concat(letter);
12
+ return `${(amount / denominator).toFixed(2)} ${letter}`;
14
13
  }
15
14
  }
16
15
  return amount.toString();
@@ -1,163 +1,73 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- 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;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
39
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
4
  };
41
5
  Object.defineProperty(exports, "__esModule", { value: true });
42
6
  exports.getHistoricalTokenPrices = exports.getTokenPrices = exports.makeCoingeckoCall = void 0;
43
- var node_fetch_1 = __importDefault(require("node-fetch"));
7
+ const axios_1 = __importDefault(require("axios"));
44
8
  function fetchJson(url) {
45
- return (0, node_fetch_1.default)(url).then(function (res) { return res.json(); });
9
+ return (0, axios_1.default)(url).then((res) => res.data);
46
10
  }
47
- function makeCoingeckoCall(url, coingeckoMaxRetries, getCoingeckoLock) {
48
- return __awaiter(this, void 0, void 0, function () {
49
- var j, values, e_1;
50
- return __generator(this, function (_a) {
51
- switch (_a.label) {
52
- case 0:
53
- j = 0;
54
- _a.label = 1;
55
- case 1:
56
- if (!(j < coingeckoMaxRetries)) return [3 /*break*/, 7];
57
- _a.label = 2;
58
- case 2:
59
- _a.trys.push([2, 5, , 6]);
60
- return [4 /*yield*/, getCoingeckoLock()];
61
- case 3:
62
- _a.sent();
63
- return [4 /*yield*/, fetchJson(url)];
64
- case 4:
65
- values = _a.sent();
66
- return [2 /*return*/, values];
67
- case 5:
68
- e_1 = _a.sent();
69
- if (j >= coingeckoMaxRetries - 1) {
70
- throw e_1;
71
- }
72
- return [3 /*break*/, 6];
73
- case 6:
74
- j++;
75
- return [3 /*break*/, 1];
76
- case 7: return [2 /*return*/];
11
+ async function makeCoingeckoCall(url, coingeckoMaxRetries, getCoingeckoLock) {
12
+ for (let j = 0; j < coingeckoMaxRetries; j++) {
13
+ try {
14
+ await getCoingeckoLock();
15
+ const values = await fetchJson(url);
16
+ return values;
17
+ }
18
+ catch (e) {
19
+ if (j >= coingeckoMaxRetries - 1) {
20
+ throw e;
77
21
  }
78
- });
79
- });
22
+ }
23
+ }
80
24
  }
81
25
  exports.makeCoingeckoCall = makeCoingeckoCall;
82
- function getTokenPrices(originalIds, url, knownTokenPrices, getCoingeckoLock, coingeckoMaxRetries, prefix) {
83
- if (prefix === void 0) { prefix = ""; }
84
- return __awaiter(this, void 0, void 0, function () {
85
- var tokenPrices, newIds, i, knownPrice, i, tempTokenPrices;
86
- return __generator(this, function (_a) {
87
- switch (_a.label) {
88
- case 0:
89
- tokenPrices = {};
90
- newIds = originalIds.slice();
91
- for (i = 0; i < newIds.length; i++) {
92
- knownPrice = knownTokenPrices[prefix + newIds[i]];
93
- if (knownPrice !== undefined) {
94
- tokenPrices[newIds[i]] = knownPrice;
95
- newIds.splice(i, 1);
96
- i--;
97
- }
98
- }
99
- i = 0;
100
- _a.label = 1;
101
- case 1:
102
- if (!(i < newIds.length)) return [3 /*break*/, 4];
103
- return [4 /*yield*/, makeCoingeckoCall("https://api.coingecko.com/api/".concat(url, "=").concat(newIds
104
- .slice(i, i + 100)
105
- .join(","), "&vs_currencies=usd"), coingeckoMaxRetries, getCoingeckoLock)];
106
- case 2:
107
- tempTokenPrices = _a.sent();
108
- Object.assign(tokenPrices, tempTokenPrices);
109
- Object.entries(tempTokenPrices).forEach(function (tokenPrice) {
110
- knownTokenPrices[prefix + tokenPrice[0]] = tokenPrice[1];
111
- });
112
- _a.label = 3;
113
- case 3:
114
- i += 100;
115
- return [3 /*break*/, 1];
116
- case 4: return [2 /*return*/, tokenPrices];
117
- }
26
+ async function getTokenPrices(originalIds, url, knownTokenPrices, getCoingeckoLock, coingeckoMaxRetries, prefix = "") {
27
+ const tokenPrices = {};
28
+ const newIds = originalIds.slice(); // Copy
29
+ for (let i = 0; i < newIds.length; i++) {
30
+ const knownPrice = knownTokenPrices[prefix + newIds[i]];
31
+ if (knownPrice !== undefined) {
32
+ tokenPrices[newIds[i]] = knownPrice;
33
+ newIds.splice(i, 1);
34
+ i--;
35
+ }
36
+ }
37
+ // The url can only contain up to 100 addresses (otherwise we'll get 'URI too large' errors)
38
+ for (let i = 0; i < newIds.length; i += 100) {
39
+ const tempTokenPrices = await makeCoingeckoCall(`https://api.coingecko.com/api/${url}=${newIds
40
+ .slice(i, i + 100)
41
+ .join(",")}&vs_currencies=usd`, coingeckoMaxRetries, getCoingeckoLock);
42
+ Object.assign(tokenPrices, tempTokenPrices);
43
+ Object.entries(tempTokenPrices).forEach((tokenPrice) => {
44
+ knownTokenPrices[prefix + tokenPrice[0]] = tokenPrice[1];
118
45
  });
119
- });
46
+ }
47
+ return tokenPrices;
120
48
  }
121
49
  exports.getTokenPrices = getTokenPrices;
122
- var secondsPerHalfDay = Math.round((24 * 3600) / 2);
123
- function getHistoricalTokenPrices(ids, url, timestamp, getCoingeckoLock, coingeckoMaxRetries) {
50
+ const secondsPerHalfDay = Math.round((24 * 3600) / 2);
51
+ async function getHistoricalTokenPrices(ids, url, timestamp, getCoingeckoLock, coingeckoMaxRetries) {
124
52
  var _a;
125
- return __awaiter(this, void 0, void 0, function () {
126
- var tokenPrices, _i, ids_1, id, range, closest, _b, _c, price;
127
- return __generator(this, function (_d) {
128
- switch (_d.label) {
129
- case 0:
130
- tokenPrices = {};
131
- _i = 0, ids_1 = ids;
132
- _d.label = 1;
133
- case 1:
134
- if (!(_i < ids_1.length)) return [3 /*break*/, 4];
135
- id = ids_1[_i];
136
- return [4 /*yield*/, makeCoingeckoCall("".concat(url, "/").concat(id.toLowerCase(), "/market_chart/range?vs_currency=usd&from=").concat(timestamp - secondsPerHalfDay, "&to=").concat(timestamp + secondsPerHalfDay), coingeckoMaxRetries, getCoingeckoLock)];
137
- case 2:
138
- range = _d.sent();
139
- if (range.error === undefined && ((_a = range.prices) === null || _a === void 0 ? void 0 : _a.length) > 0) {
140
- closest = range.prices[0];
141
- for (_b = 0, _c = range.prices; _b < _c.length; _b++) {
142
- price = _c[_b];
143
- if (Math.abs(price[0] - timestamp) < Math.abs(closest[0] - timestamp)) {
144
- closest = price;
145
- }
146
- }
147
- tokenPrices[id.toLowerCase()] = {
148
- usd: closest[1],
149
- };
150
- }
151
- else {
152
- tokenPrices[id.toLowerCase()] = undefined;
153
- }
154
- _d.label = 3;
155
- case 3:
156
- _i++;
157
- return [3 /*break*/, 1];
158
- case 4: return [2 /*return*/, tokenPrices];
53
+ const tokenPrices = {};
54
+ for (const id of ids) {
55
+ const range = await makeCoingeckoCall(`${url}/${id.toLowerCase()}/market_chart/range?vs_currency=usd&from=${timestamp - secondsPerHalfDay}&to=${timestamp + secondsPerHalfDay}`, coingeckoMaxRetries, getCoingeckoLock);
56
+ if (range.error === undefined && ((_a = range.prices) === null || _a === void 0 ? void 0 : _a.length) > 0) {
57
+ let closest = range.prices[0];
58
+ for (const price of range.prices) {
59
+ if (Math.abs(price[0] - timestamp) < Math.abs(closest[0] - timestamp)) {
60
+ closest = price;
61
+ }
159
62
  }
160
- });
161
- });
63
+ tokenPrices[id.toLowerCase()] = {
64
+ usd: closest[1],
65
+ };
66
+ }
67
+ else {
68
+ tokenPrices[id.toLowerCase()] = undefined;
69
+ }
70
+ }
71
+ return tokenPrices;
162
72
  }
163
73
  exports.getHistoricalTokenPrices = getHistoricalTokenPrices;
@@ -1,45 +1,9 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- 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;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
2
  Object.defineProperty(exports, "__esModule", { value: true });
39
3
  exports.balanceOf = exports.totalSupply = exports.decimals = exports.symbol = exports.info = void 0;
40
- var ethers_1 = require("ethers");
41
- var general_1 = require("../general");
42
- var abi = [
4
+ const ethers_1 = require("ethers");
5
+ const general_1 = require("../general");
6
+ const abi = [
43
7
  "function balanceOf(address owner) view returns (uint256)",
44
8
  "function totalSupply() view returns (uint256)",
45
9
  "function decimals() view returns (uint8)",
@@ -48,98 +12,46 @@ var abi = [
48
12
  function getContract(address, chain) {
49
13
  return new ethers_1.ethers.Contract(address, abi, (0, general_1.getProvider)(chain));
50
14
  }
51
- function info(tokenAddress, chain) {
52
- return __awaiter(this, void 0, void 0, function () {
53
- var contract, tokenSymbol, tokenDecimals, _a;
54
- var _b, _c;
55
- return __generator(this, function (_d) {
56
- switch (_d.label) {
57
- case 0:
58
- contract = getContract(tokenAddress, chain);
59
- tokenSymbol = contract.symbol();
60
- tokenDecimals = contract.decimals();
61
- _b = {};
62
- _c = {};
63
- return [4 /*yield*/, tokenSymbol];
64
- case 1:
65
- _c.symbol = _d.sent();
66
- _a = Number;
67
- return [4 /*yield*/, tokenDecimals];
68
- case 2: return [2 /*return*/, (_b.output = (_c.decimals = _a.apply(void 0, [_d.sent()]),
69
- _c),
70
- _b)];
71
- }
72
- });
73
- });
15
+ async function info(tokenAddress, chain) {
16
+ const contract = getContract(tokenAddress, chain);
17
+ const tokenSymbol = contract.symbol();
18
+ const tokenDecimals = contract.decimals();
19
+ return {
20
+ output: {
21
+ symbol: await tokenSymbol,
22
+ decimals: Number(await tokenDecimals),
23
+ },
24
+ };
74
25
  }
75
26
  exports.info = info;
76
- function symbol(tokenAddress, chain) {
77
- return __awaiter(this, void 0, void 0, function () {
78
- var _a;
79
- return __generator(this, function (_b) {
80
- switch (_b.label) {
81
- case 0:
82
- _a = {};
83
- return [4 /*yield*/, getContract(tokenAddress, chain).symbol()];
84
- case 1: return [2 /*return*/, (_a.output = _b.sent(),
85
- _a)];
86
- }
87
- });
88
- });
27
+ async function symbol(tokenAddress, chain) {
28
+ return {
29
+ output: await getContract(tokenAddress, chain).symbol(),
30
+ };
89
31
  }
90
32
  exports.symbol = symbol;
91
- function decimals(tokenAddress, chain) {
92
- return __awaiter(this, void 0, void 0, function () {
93
- var _a;
94
- var _b;
95
- return __generator(this, function (_c) {
96
- switch (_c.label) {
97
- case 0:
98
- _b = {};
99
- _a = Number;
100
- return [4 /*yield*/, getContract(tokenAddress, chain).decimals()];
101
- case 1: return [2 /*return*/, (_b.output = _a.apply(void 0, [_c.sent()]),
102
- _b)];
103
- }
104
- });
105
- });
33
+ async function decimals(tokenAddress, chain) {
34
+ return {
35
+ output: Number(await getContract(tokenAddress, chain).decimals()),
36
+ };
106
37
  }
107
38
  exports.decimals = decimals;
108
- function totalSupply(params) {
109
- return __awaiter(this, void 0, void 0, function () {
110
- var contract, supply;
111
- return __generator(this, function (_a) {
112
- switch (_a.label) {
113
- case 0:
114
- contract = getContract(params.target, params.chain);
115
- return [4 /*yield*/, contract.totalSupply({
116
- blockTag: params.block,
117
- })];
118
- case 1:
119
- supply = _a.sent();
120
- return [2 /*return*/, {
121
- output: (0, general_1.handleDecimals)(supply, params.decimals),
122
- }];
123
- }
124
- });
39
+ async function totalSupply(params) {
40
+ const contract = getContract(params.target, params.chain);
41
+ const supply = await contract.totalSupply({
42
+ blockTag: params.block,
125
43
  });
44
+ return {
45
+ output: (0, general_1.handleDecimals)(supply, params.decimals),
46
+ };
126
47
  }
127
48
  exports.totalSupply = totalSupply;
128
- function balanceOf(params) {
129
- return __awaiter(this, void 0, void 0, function () {
130
- var balance;
131
- return __generator(this, function (_a) {
132
- switch (_a.label) {
133
- case 0: return [4 /*yield*/, getContract(params.target, params.chain).balanceOf(params.owner, {
134
- blockTag: params.block,
135
- })];
136
- case 1:
137
- balance = _a.sent();
138
- return [2 /*return*/, {
139
- output: (0, general_1.handleDecimals)(balance, params.decimals),
140
- }];
141
- }
142
- });
49
+ async function balanceOf(params) {
50
+ const balance = await getContract(params.target, params.chain).balanceOf(params.owner, {
51
+ blockTag: params.block,
143
52
  });
53
+ return {
54
+ output: (0, general_1.handleDecimals)(balance, params.decimals),
55
+ };
144
56
  }
145
57
  exports.balanceOf = balanceOf;
@@ -22,118 +22,48 @@ 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.getBalances = exports.getBalance = void 0;
63
- var general_1 = require("../general");
64
- var Tron = __importStar(require("../abi/tron"));
65
- function getBalance(params) {
27
+ const general_1 = require("../general");
28
+ const Tron = __importStar(require("../abi/tron"));
29
+ async function getBalance(params) {
66
30
  var _a;
67
- return __awaiter(this, void 0, void 0, function () {
68
- var balance, output;
69
- return __generator(this, function (_b) {
70
- switch (_b.label) {
71
- case 0:
72
- if (params.chain === 'tron')
73
- return [2 /*return*/, Tron.getBalance(params)];
74
- return [4 /*yield*/, (0, general_1.getProvider)(params.chain).getBalance(params.target, params.block)];
75
- case 1:
76
- balance = _b.sent();
77
- output = (0, general_1.handleDecimals)(balance, params.decimals);
78
- if (params.logArray)
79
- params.logArray.push({
80
- chain: (_a = params.chain) !== null && _a !== void 0 ? _a : "ethereum",
81
- holder: params.target,
82
- token: general_1.ETHER_ADDRESS,
83
- amount: output
84
- });
85
- return [2 /*return*/, {
86
- output: output,
87
- }];
88
- }
31
+ if (params.chain === 'tron')
32
+ return Tron.getBalance(params);
33
+ const balance = await (0, general_1.getProvider)(params.chain).getBalance(params.target, params.block);
34
+ const output = (0, general_1.handleDecimals)(balance, params.decimals);
35
+ if (params.logArray)
36
+ params.logArray.push({
37
+ chain: (_a = params.chain) !== null && _a !== void 0 ? _a : "ethereum",
38
+ holder: params.target,
39
+ token: general_1.ETHER_ADDRESS,
40
+ amount: output
89
41
  });
90
- });
42
+ return {
43
+ output,
44
+ };
91
45
  }
92
46
  exports.getBalance = getBalance;
93
- function getBalances(params) {
94
- return __awaiter(this, void 0, void 0, function () {
95
- var balances, output;
96
- var _a;
97
- var _this = this;
98
- return __generator(this, function (_b) {
99
- switch (_b.label) {
100
- case 0:
101
- if (params.chain === 'tron')
102
- return [2 /*return*/, Tron.getBalances(params)];
103
- balances = params.targets.map(function (target) { return __awaiter(_this, void 0, void 0, function () {
104
- var _a;
105
- var _b;
106
- return __generator(this, function (_c) {
107
- switch (_c.label) {
108
- case 0:
109
- _b = {
110
- target: target
111
- };
112
- _a = general_1.handleDecimals;
113
- return [4 /*yield*/, (0, general_1.getProvider)(params.chain).getBalance(target, params.block)];
114
- case 1: return [2 /*return*/, (_b.balance = _a.apply(void 0, [_c.sent(), params.decimals]),
115
- _b)];
116
- }
117
- });
118
- }); });
119
- return [4 /*yield*/, Promise.all(balances)];
120
- case 1:
121
- output = _b.sent();
122
- if (params.logArray)
123
- (_a = params.logArray).push.apply(_a, params.targets.map(function (holder, i) {
124
- var _a;
125
- return ({
126
- chain: (_a = params.chain) !== null && _a !== void 0 ? _a : "ethereum",
127
- holder: holder,
128
- token: general_1.ETHER_ADDRESS,
129
- amount: output[i].balance
130
- });
131
- }));
132
- return [2 /*return*/, {
133
- output: output,
134
- }];
135
- }
136
- });
137
- });
47
+ async function getBalances(params) {
48
+ if (params.chain === 'tron')
49
+ return Tron.getBalances(params);
50
+ const balances = params.targets.map(async (target) => ({
51
+ target,
52
+ balance: (0, general_1.handleDecimals)(await (0, general_1.getProvider)(params.chain).getBalance(target, params.block), params.decimals),
53
+ }));
54
+ const output = await Promise.all(balances);
55
+ if (params.logArray)
56
+ params.logArray.push(...params.targets.map((holder, i) => {
57
+ var _a;
58
+ return ({
59
+ chain: (_a = params.chain) !== null && _a !== void 0 ? _a : "ethereum",
60
+ holder,
61
+ token: general_1.ETHER_ADDRESS,
62
+ amount: output[i].balance
63
+ });
64
+ }));
65
+ return {
66
+ output,
67
+ };
138
68
  }
139
69
  exports.getBalances = getBalances;