@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/ChainApi.js CHANGED
@@ -1,69 +1,22 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
- 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;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
50
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
51
4
  };
52
5
  Object.defineProperty(exports, "__esModule", { value: true });
53
6
  exports.ChainApi = void 0;
54
- var Balances_1 = __importDefault(require("./Balances"));
55
- var general_1 = require("./general");
56
- var abi2_1 = require("./abi/abi2");
57
- var blocks_1 = require("./computeTVL/blocks");
58
- var providers_json_1 = __importDefault(require("./providers.json"));
59
- var debugLog_1 = require("./util/debugLog");
60
- var generalUtil_1 = require("./generalUtil");
61
- var multicall3_1 = require("./abi/multicall3");
62
- var eth_1 = require("./eth");
63
- var logs_1 = __importDefault(require("./util/logs"));
64
- var nullAddress = '0x0000000000000000000000000000000000000000';
65
- var ChainApi = /** @class */ (function () {
66
- function ChainApi(params) {
7
+ const Balances_1 = __importDefault(require("./Balances"));
8
+ const general_1 = require("./general");
9
+ const abi2_1 = require("./abi/abi2");
10
+ const blocks_1 = require("./computeTVL/blocks");
11
+ const providers_json_1 = __importDefault(require("./providers.json"));
12
+ const debugLog_1 = require("./util/debugLog");
13
+ const generalUtil_1 = require("./generalUtil");
14
+ const multicall3_1 = require("./abi/multicall3");
15
+ const eth_1 = require("./eth");
16
+ const logs_1 = __importDefault(require("./util/logs"));
17
+ const nullAddress = '0x0000000000000000000000000000000000000000';
18
+ class ChainApi {
19
+ constructor(params) {
67
20
  var _a, _b;
68
21
  this.block = params.block;
69
22
  this.chain = (_a = params.chain) !== null && _a !== void 0 ? _a : 'ethereum';
@@ -73,211 +26,157 @@ var ChainApi = /** @class */ (function () {
73
26
  // @ts-ignore
74
27
  this.chainId = (_b = providers_json_1.default[this.chain]) === null || _b === void 0 ? void 0 : _b.chainId;
75
28
  }
76
- ChainApi.prototype.call = function (params) {
77
- return (0, abi2_1.call)(__assign(__assign({}, params), { block: this.block, chain: this.chain }));
78
- };
79
- ChainApi.prototype.batchCall = function (params) {
80
- var _this = this;
81
- return Promise.all(params.map(function (i) { return _this.call(i); }));
82
- };
83
- ChainApi.prototype.multiCall = function (params) {
84
- return (0, abi2_1.multiCall)(__assign(__assign({}, params), { block: this.block, chain: this.chain }));
85
- };
86
- ChainApi.prototype.fetchList = function (params) {
87
- return (0, abi2_1.fetchList)(__assign(__assign({}, params), { block: this.block, chain: this.chain }));
88
- };
89
- ChainApi.prototype.bytecodeCall = function (params) {
90
- return (0, abi2_1.bytecodeCall)(__assign(__assign({}, params), { block: this.block, chain: this.chain }));
91
- };
92
- ChainApi.prototype.getBlock = function () {
93
- return __awaiter(this, void 0, void 0, function () {
94
- var _a;
95
- return __generator(this, function (_b) {
96
- switch (_b.label) {
97
- case 0:
98
- if (!!this.block) return [3 /*break*/, 2];
99
- _a = this;
100
- return [4 /*yield*/, (0, blocks_1.getBlock)(this.chain, this.timestamp)];
101
- case 1:
102
- _a.block = (_b.sent()).block;
103
- _b.label = 2;
104
- case 2: return [2 /*return*/, this.block];
105
- }
106
- });
29
+ call(params) {
30
+ return (0, abi2_1.call)({
31
+ ...params,
32
+ block: this.block,
33
+ chain: this.chain,
107
34
  });
108
- };
109
- ChainApi.prototype.log = function () {
110
- var args = [];
111
- for (var _i = 0; _i < arguments.length; _i++) {
112
- args[_i] = arguments[_i];
113
- }
114
- debugLog_1.debugLog.apply(void 0, args);
115
- };
116
- ChainApi.prototype.logTable = function () {
117
- var args = [];
118
- for (var _i = 0; _i < arguments.length; _i++) {
119
- args[_i] = arguments[_i];
120
- }
121
- debugLog_1.debugTable.apply(void 0, args);
122
- };
123
- ChainApi.prototype.add = function (token, balance, _a) {
124
- var _b = _a === void 0 ? {} : _a, _c = _b.skipChain, skipChain = _c === void 0 ? false : _c;
125
- this._balances.add(token, balance, { skipChain: skipChain });
126
- };
127
- ChainApi.prototype.addToken = function (token, balance, _a) {
128
- var _b = _a === void 0 ? {} : _a, _c = _b.skipChain, skipChain = _c === void 0 ? false : _c;
129
- this.add(token, balance, { skipChain: skipChain });
130
- };
131
- ChainApi.prototype.addGasToken = function (balance) {
35
+ }
36
+ batchCall(params) {
37
+ return Promise.all(params.map(i => this.call(i)));
38
+ }
39
+ multiCall(params) {
40
+ return (0, abi2_1.multiCall)({
41
+ ...params,
42
+ block: this.block,
43
+ chain: this.chain,
44
+ });
45
+ }
46
+ fetchList(params) {
47
+ return (0, abi2_1.fetchList)({
48
+ ...params,
49
+ block: this.block,
50
+ chain: this.chain,
51
+ });
52
+ }
53
+ bytecodeCall(params) {
54
+ return (0, abi2_1.bytecodeCall)({
55
+ ...params,
56
+ block: this.block,
57
+ chain: this.chain,
58
+ });
59
+ }
60
+ async getBlock() {
61
+ if (!this.block)
62
+ this.block = await (0, blocks_1.getBlockNumber)(this.chain, this.timestamp);
63
+ return this.block;
64
+ }
65
+ log(...args) {
66
+ (0, debugLog_1.debugLog)(...args);
67
+ }
68
+ logTable(...args) {
69
+ (0, debugLog_1.debugTable)(...args);
70
+ }
71
+ add(token, balance, { skipChain = false } = {}) {
72
+ this._balances.add(token, balance, { skipChain });
73
+ }
74
+ addToken(token, balance, { skipChain = false } = {}) {
75
+ this.add(token, balance, { skipChain });
76
+ }
77
+ addGasToken(balance) {
132
78
  this.add(nullAddress, balance);
133
- };
134
- ChainApi.prototype.addTokens = function (tokens, balances, _a) {
135
- var _b = _a === void 0 ? {} : _a, _c = _b.skipChain, skipChain = _c === void 0 ? false : _c;
136
- this.add(tokens, balances, { skipChain: skipChain });
137
- };
138
- ChainApi.prototype.addBalances = function (balances) {
79
+ }
80
+ addTokens(tokens, balances, { skipChain = false } = {}) {
81
+ this.add(tokens, balances, { skipChain });
82
+ }
83
+ addBalances(balances) {
139
84
  this._balances.addBalances(balances);
140
- };
141
- ChainApi.prototype.getBalances = function () {
85
+ }
86
+ getBalances() {
142
87
  return this._balances.getBalances();
143
- };
144
- ChainApi.prototype.getChainId = function () {
88
+ }
89
+ getChainId() {
145
90
  return this.chainId;
146
- };
147
- ChainApi.prototype.removeTokenBalance = function (token) {
91
+ }
92
+ removeTokenBalance(token) {
148
93
  this._balances.removeTokenBalance(token);
149
- };
150
- ChainApi.prototype.deleteToken = function (token) {
94
+ }
95
+ deleteToken(token) {
151
96
  this._balances.removeTokenBalance(token);
152
- };
153
- ChainApi.prototype.deleteTokens = function (tokens) {
154
- var _this = this;
155
- tokens.forEach(function (i) { return _this.deleteToken(i); });
156
- };
157
- ChainApi.prototype.erc4626Sum = function (_a) {
158
- var calls = _a.calls, _b = _a.tokenAbi, tokenAbi = _b === void 0 ? 'address:token' : _b, _c = _a.balanceAbi, balanceAbi = _c === void 0 ? 'uint256:balance' : _c, balanceCalls = _a.balanceCalls, _d = _a.permitFailure, permitFailure = _d === void 0 ? false : _d, _e = _a.isOG4626, isOG4626 = _e === void 0 ? false : _e;
159
- return __awaiter(this, void 0, void 0, function () {
160
- var tokens, balances;
161
- var _this = this;
162
- return __generator(this, function (_f) {
163
- switch (_f.label) {
164
- case 0:
165
- if (isOG4626) {
166
- tokenAbi = 'asset';
167
- balanceAbi = 'totalAssets';
168
- }
169
- if (typeof tokenAbi === 'string' && (!tokenAbi.includes(':') && !tokenAbi.includes('(')))
170
- tokenAbi = "address:".concat(tokenAbi);
171
- if (typeof balanceAbi === 'string' && (!balanceAbi.includes(':') && !balanceAbi.includes('(')))
172
- balanceAbi = "uint256:".concat(balanceAbi);
173
- return [4 /*yield*/, this.multiCall({ calls: calls, abi: tokenAbi, permitFailure: permitFailure })];
174
- case 1:
175
- tokens = _f.sent();
176
- return [4 /*yield*/, this.multiCall({ calls: calls !== null && calls !== void 0 ? calls : balanceCalls, abi: balanceAbi, permitFailure: permitFailure })];
177
- case 2:
178
- balances = _f.sent();
179
- if (!permitFailure)
180
- this.addTokens(tokens, balances);
181
- else
182
- tokens.forEach(function (i, j) {
183
- if (i && balances[j])
184
- _this.addToken(i, balances[j]);
185
- });
186
- return [2 /*return*/, this.getBalances()];
187
- }
188
- });
189
- });
190
- };
191
- ChainApi.prototype.sumTokens = function (_a) {
192
- var _b = _a.tokens, tokens = _b === void 0 ? [] : _b, _c = _a.owners, owners = _c === void 0 ? [] : _c, owner = _a.owner, _d = _a.tokensAndOwners, tokensAndOwners = _d === void 0 ? [] : _d, _e = _a.tokensAndOwners2, tokensAndOwners2 = _e === void 0 ? [] : _e, _f = _a.blacklistedTokens, blacklistedTokens = _f === void 0 ? [] : _f, _g = _a.blacklistedOwners, blacklistedOwners = _g === void 0 ? [] : _g, _h = _a.ownerTokens, ownerTokens = _h === void 0 ? [] : _h;
193
- return __awaiter(this, void 0, void 0, function () {
194
- var _loop_1, _i, ownerTokens_1, _j, tokens_1, owner_1, ethBalOwners, bals, ethBals, multicallAddress, res;
195
- var _this = this;
196
- return __generator(this, function (_k) {
197
- switch (_k.label) {
198
- case 0:
199
- if (tokensAndOwners2.length)
200
- tokensAndOwners.push.apply(tokensAndOwners, tokensAndOwners2[0].map(function (i, j) { return [i, tokensAndOwners2[1][j]]; }));
201
- if (tokens.length) {
202
- if (owner)
203
- owners.push(owner);
204
- tokensAndOwners.push.apply(tokensAndOwners, tokens.map(function (i) { return owners.map(function (j) { return [i, j]; }); }).flat());
205
- }
206
- _loop_1 = function (tokens_1, owner_1) {
207
- tokens_1.forEach(function (i) { return tokensAndOwners.push([i, owner_1]); });
208
- };
209
- for (_i = 0, ownerTokens_1 = ownerTokens; _i < ownerTokens_1.length; _i++) {
210
- _j = ownerTokens_1[_i], tokens_1 = _j[0], owner_1 = _j[1];
211
- _loop_1(tokens_1, owner_1);
212
- }
213
- tokensAndOwners = getUniqueTokensAndOwners(tokensAndOwners, this.chain);
214
- blacklistedOwners = (0, generalUtil_1.getUniqueAddresses)(blacklistedOwners);
215
- blacklistedTokens = (0, generalUtil_1.getUniqueAddresses)(blacklistedTokens);
216
- tokensAndOwners = tokensAndOwners.filter(function (i) { return !blacklistedTokens.includes(i[0]) && !blacklistedOwners.includes(i[1]); });
217
- ethBalOwners = tokensAndOwners.filter(function (i) { return i[0] === nullAddress; }).map(function (i) { return i[1]; });
218
- tokensAndOwners = tokensAndOwners.filter(function (i) { return i[0] !== nullAddress; });
219
- return [4 /*yield*/, this.multiCall({
220
- calls: tokensAndOwners.map(function (i) { return ({ target: i[0], params: [i[1]] }); }),
221
- abi: 'erc20:balanceOf',
222
- })];
223
- case 1:
224
- bals = _k.sent();
225
- this.addTokens(tokensAndOwners.map(function (i) { return i[0]; }), bals);
226
- if (!ethBalOwners.length) return [3 /*break*/, 6];
227
- ethBals = [];
228
- multicallAddress = (0, multicall3_1.getMulticallAddress)(this.chain, this.block);
229
- if (!multicallAddress) return [3 /*break*/, 3];
230
- return [4 /*yield*/, this.multiCall({
231
- calls: ethBalOwners,
232
- target: multicallAddress,
233
- abi: 'function getEthBalance(address) view returns (uint256)',
234
- })];
235
- case 2:
236
- ethBals = _k.sent();
237
- return [3 /*break*/, 5];
238
- case 3: return [4 /*yield*/, (0, eth_1.getBalances)({ chain: this.chain, targets: ethBalOwners, block: this.block })];
239
- case 4:
240
- res = _k.sent();
241
- ethBals = res.output.map(function (i) { return i.balance; });
242
- _k.label = 5;
243
- case 5:
244
- ethBals.map(function (i) { return _this.addToken(nullAddress, i); });
245
- _k.label = 6;
246
- case 6: return [2 /*return*/, this.getBalances()];
247
- }
248
- });
249
- });
250
- };
251
- ChainApi.prototype.getUSDValue = function () {
252
- return __awaiter(this, void 0, void 0, function () {
253
- return __generator(this, function (_a) {
254
- return [2 /*return*/, this._balances.getUSDValue()];
255
- });
256
- });
257
- };
258
- ChainApi.prototype.getUSDJSONs = function () {
259
- return __awaiter(this, void 0, void 0, function () {
260
- return __generator(this, function (_a) {
261
- return [2 /*return*/, this._balances.getUSDJSONs()];
262
- });
263
- });
264
- };
265
- ChainApi.prototype.getLogs = function (params) {
266
- return __awaiter(this, void 0, void 0, function () {
267
- return __generator(this, function (_a) {
268
- params.chain = this.chain;
269
- return [2 /*return*/, (0, logs_1.default)(params)];
97
+ }
98
+ deleteTokens(tokens) {
99
+ tokens.forEach(i => this.deleteToken(i));
100
+ }
101
+ async erc4626Sum({ calls, tokenAbi = 'address:token', balanceAbi = 'uint256:balance', balanceCalls, permitFailure = false, isOG4626 = false }) {
102
+ if (isOG4626) {
103
+ tokenAbi = 'asset';
104
+ balanceAbi = 'totalAssets';
105
+ }
106
+ if (typeof tokenAbi === 'string' && (!tokenAbi.includes(':') && !tokenAbi.includes('(')))
107
+ tokenAbi = `address:${tokenAbi}`;
108
+ if (typeof balanceAbi === 'string' && (!balanceAbi.includes(':') && !balanceAbi.includes('(')))
109
+ balanceAbi = `uint256:${balanceAbi}`;
110
+ const tokens = await this.multiCall({ calls, abi: tokenAbi, permitFailure });
111
+ const balances = await this.multiCall({ calls: calls !== null && calls !== void 0 ? calls : balanceCalls, abi: balanceAbi, permitFailure });
112
+ if (!permitFailure)
113
+ this.addTokens(tokens, balances);
114
+ else
115
+ tokens.forEach((i, j) => {
116
+ if (i && balances[j])
117
+ this.addToken(i, balances[j]);
270
118
  });
119
+ return this.getBalances();
120
+ }
121
+ async sumTokens({ tokens = [], owners = [], owner, tokensAndOwners = [], tokensAndOwners2 = [], blacklistedTokens = [], blacklistedOwners = [], ownerTokens = [], }) {
122
+ if (tokensAndOwners2.length)
123
+ tokensAndOwners.push(...tokensAndOwners2[0].map((i, j) => [i, tokensAndOwners2[1][j]]));
124
+ if (tokens.length) {
125
+ if (owner)
126
+ owners.push(owner);
127
+ tokensAndOwners.push(...tokens.map(i => owners.map(j => [i, j])).flat());
128
+ }
129
+ for (const [tokens, owner] of ownerTokens)
130
+ tokens.forEach((i) => tokensAndOwners.push([i, owner]));
131
+ tokensAndOwners = getUniqueTokensAndOwners(tokensAndOwners, this.chain);
132
+ blacklistedOwners = (0, generalUtil_1.getUniqueAddresses)(blacklistedOwners);
133
+ blacklistedTokens = (0, generalUtil_1.getUniqueAddresses)(blacklistedTokens);
134
+ tokensAndOwners = tokensAndOwners.filter(i => !blacklistedTokens.includes(i[0]) && !blacklistedOwners.includes(i[1]));
135
+ const ethBalOwners = tokensAndOwners.filter(i => i[0] === nullAddress).map(i => i[1]);
136
+ tokensAndOwners = tokensAndOwners.filter(i => i[0] !== nullAddress);
137
+ const bals = await this.multiCall({
138
+ calls: tokensAndOwners.map(i => ({ target: i[0], params: [i[1]] })),
139
+ abi: 'erc20:balanceOf',
271
140
  });
272
- };
273
- return ChainApi;
274
- }());
141
+ this.addTokens(tokensAndOwners.map(i => i[0]), bals);
142
+ if (ethBalOwners.length) {
143
+ let ethBals = [];
144
+ const multicallAddress = (0, multicall3_1.getMulticallAddress)(this.chain, this.block);
145
+ if (multicallAddress) {
146
+ ethBals = await this.multiCall({
147
+ calls: ethBalOwners,
148
+ target: multicallAddress,
149
+ abi: 'function getEthBalance(address) view returns (uint256)',
150
+ });
151
+ }
152
+ else {
153
+ const res = await (0, eth_1.getBalances)({ chain: this.chain, targets: ethBalOwners, block: this.block });
154
+ ethBals = res.output.map((i) => i.balance);
155
+ }
156
+ ethBals.map(i => this.addToken(nullAddress, i));
157
+ }
158
+ return this.getBalances();
159
+ }
160
+ async getUSDValue() {
161
+ return this._balances.getUSDValue();
162
+ }
163
+ async getUSDJSONs() {
164
+ return this._balances.getUSDJSONs();
165
+ }
166
+ async getLogs(params) {
167
+ params.chain = this.chain;
168
+ return (0, logs_1.default)(params);
169
+ }
170
+ getBalancesV2() {
171
+ return this._balances;
172
+ }
173
+ }
275
174
  exports.ChainApi = ChainApi;
276
175
  exports.default = ChainApi;
277
176
  function getUniqueTokensAndOwners(toa, chain) {
278
177
  if (!toa.length)
279
178
  return [];
280
- var mergedToa = toa.map(function (i) { return i.join('~'); });
281
- var uniqueMerged = (0, generalUtil_1.getUniqueAddresses)(mergedToa, chain);
282
- return uniqueMerged.map(function (i) { return i.split('~'); });
179
+ const mergedToa = toa.map(i => i.join('~'));
180
+ const uniqueMerged = (0, generalUtil_1.getUniqueAddresses)(mergedToa, chain);
181
+ return uniqueMerged.map(i => i.split('~'));
283
182
  }
package/build/abi/abi2.js CHANGED
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
3
  if (k2 === undefined) k2 = k;
15
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -33,147 +22,61 @@ var __importStar = (this && this.__importStar) || function (mod) {
33
22
  __setModuleDefault(result, mod);
34
23
  return result;
35
24
  };
36
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
37
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
38
- return new (P || (P = Promise))(function (resolve, reject) {
39
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
40
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
41
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
42
- step((generator = generator.apply(thisArg, _arguments || [])).next());
43
- });
44
- };
45
- var __generator = (this && this.__generator) || function (thisArg, body) {
46
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
47
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
48
- function verb(n) { return function (v) { return step([n, v]); }; }
49
- function step(op) {
50
- if (f) throw new TypeError("Generator is already executing.");
51
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
52
- 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;
53
- if (y = 0, t) op = [op[0] & 2, t.value];
54
- switch (op[0]) {
55
- case 0: case 1: t = op; break;
56
- case 4: _.label++; return { value: op[1], done: false };
57
- case 5: _.label++; y = op[1]; op = [0]; continue;
58
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
59
- default:
60
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
61
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
62
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
63
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
64
- if (t[2]) _.ops.pop();
65
- _.trys.pop(); continue;
66
- }
67
- op = body.call(thisArg, _);
68
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
69
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
70
- }
71
- };
72
- var __rest = (this && this.__rest) || function (s, e) {
73
- var t = {};
74
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
75
- t[p] = s[p];
76
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
77
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
78
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
79
- t[p[i]] = s[p[i]];
80
- }
81
- return t;
82
- };
83
25
  Object.defineProperty(exports, "__esModule", { value: true });
84
26
  exports.bytecodeCall = exports.fetchList = exports.multiCall = exports.call = void 0;
85
- var abi1 = __importStar(require("./index"));
86
- var debugLog_1 = require("../util/debugLog");
87
- function call(params) {
88
- return __awaiter(this, void 0, void 0, function () {
89
- var response;
90
- return __generator(this, function (_a) {
91
- switch (_a.label) {
92
- case 0: return [4 /*yield*/, abi1.call(params)];
93
- case 1:
94
- response = _a.sent();
95
- if (params.withMetadata)
96
- return [2 /*return*/, response];
97
- return [2 /*return*/, response.output];
98
- }
99
- });
100
- });
27
+ const abi1 = __importStar(require("./index"));
28
+ const debugLog_1 = require("../util/debugLog");
29
+ async function call(params) {
30
+ const response = await abi1.call(params);
31
+ if (params.withMetadata)
32
+ return response;
33
+ return response.output;
101
34
  }
102
35
  exports.call = call;
103
- function multiCall(params) {
104
- return __awaiter(this, void 0, void 0, function () {
105
- var output;
106
- return __generator(this, function (_a) {
107
- switch (_a.label) {
108
- case 0:
109
- params.calls = params.calls.map(function (i) {
110
- if (typeof i === 'object')
111
- return i;
112
- if (typeof i === 'string') {
113
- if (params.target)
114
- return { params: i };
115
- return { target: i };
116
- }
117
- return { params: i };
118
- });
119
- return [4 /*yield*/, abi1.multiCall(params)];
120
- case 1:
121
- output = (_a.sent()).output;
122
- if (params.withMetadata)
123
- return [2 /*return*/, output];
124
- return [2 /*return*/, output.map(function (i) { return i.output; })];
125
- }
126
- });
36
+ async function multiCall(params) {
37
+ params.calls = params.calls.map(i => {
38
+ if (typeof i === 'object')
39
+ return i;
40
+ if (typeof i === 'string') {
41
+ if (params.target)
42
+ return { params: i };
43
+ return { target: i };
44
+ }
45
+ return { params: i };
127
46
  });
47
+ const { output } = await abi1.multiCall(params);
48
+ if (params.withMetadata)
49
+ return output;
50
+ return output.map((i) => i.output);
128
51
  }
129
52
  exports.multiCall = multiCall;
130
- function fetchList(params) {
131
- return __awaiter(this, void 0, void 0, function () {
132
- var _a, startFrom, lengthAbi, itemAbi, withMetadata, _b, startFromOne, itemCount, commonParams, itemLength, calls, i;
133
- return __generator(this, function (_c) {
134
- switch (_c.label) {
135
- case 0:
136
- _a = params.startFrom, startFrom = _a === void 0 ? 0 : _a, lengthAbi = params.lengthAbi, itemAbi = params.itemAbi, withMetadata = params.withMetadata, _b = params.startFromOne, startFromOne = _b === void 0 ? false : _b, itemCount = params.itemCount, commonParams = __rest(params, ["startFrom", "lengthAbi", "itemAbi", "withMetadata", "startFromOne", "itemCount"]);
137
- if (typeof lengthAbi === 'string' && (!lengthAbi.includes(':') && !lengthAbi.includes('(')))
138
- lengthAbi = "uint256:".concat(lengthAbi);
139
- if (typeof itemAbi === 'string' && (!itemAbi.includes(':') && !itemAbi.includes('(')))
140
- itemAbi = "function ".concat(itemAbi, "(uint256) view returns (address)");
141
- if (!itemCount) return [3 /*break*/, 1];
142
- itemLength = itemCount;
143
- return [3 /*break*/, 3];
144
- case 1: return [4 /*yield*/, call(__assign(__assign({}, commonParams), { abi: lengthAbi }))];
145
- case 2:
146
- itemLength = _c.sent();
147
- _c.label = 3;
148
- case 3:
149
- (0, debugLog_1.debugLog)('length: ', itemLength);
150
- if (startFromOne) {
151
- itemLength++;
152
- if (startFrom === 0)
153
- startFrom = 1;
154
- }
155
- calls = [];
156
- for (i = startFrom; i < itemLength; i++)
157
- calls.push(i);
158
- return [2 /*return*/, multiCall(__assign(__assign({}, commonParams), { abi: itemAbi, calls: calls, withMetadata: withMetadata }))];
159
- }
160
- });
161
- });
53
+ async function fetchList(params) {
54
+ let { startFrom = 0, lengthAbi, itemAbi, withMetadata, startFromOne = false, itemCount, ...commonParams } = params;
55
+ if (typeof lengthAbi === 'string' && (!lengthAbi.includes(':') && !lengthAbi.includes('(')))
56
+ lengthAbi = `uint256:${lengthAbi}`;
57
+ if (typeof itemAbi === 'string' && (!itemAbi.includes(':') && !itemAbi.includes('(')))
58
+ itemAbi = `function ${itemAbi}(uint256) view returns (address)`;
59
+ let itemLength;
60
+ if (itemCount)
61
+ itemLength = itemCount;
62
+ else
63
+ itemLength = await call({ ...commonParams, abi: lengthAbi, });
64
+ (0, debugLog_1.debugLog)('length: ', itemLength);
65
+ if (startFromOne) {
66
+ itemLength++;
67
+ if (startFrom === 0)
68
+ startFrom = 1;
69
+ }
70
+ const calls = [];
71
+ for (let i = startFrom; i < itemLength; i++)
72
+ calls.push(i);
73
+ return multiCall({ ...commonParams, abi: itemAbi, calls, withMetadata });
162
74
  }
163
75
  exports.fetchList = fetchList;
164
- function bytecodeCall(params) {
165
- return __awaiter(this, void 0, void 0, function () {
166
- var response;
167
- return __generator(this, function (_a) {
168
- switch (_a.label) {
169
- case 0: return [4 /*yield*/, abi1.bytecodeCall(params)];
170
- case 1:
171
- response = _a.sent();
172
- if (params.withMetadata)
173
- return [2 /*return*/, response];
174
- return [2 /*return*/, response.output];
175
- }
176
- });
177
- });
76
+ async function bytecodeCall(params) {
77
+ const response = await abi1.bytecodeCall(params);
78
+ if (params.withMetadata)
79
+ return response;
80
+ return response.output;
178
81
  }
179
82
  exports.bytecodeCall = bytecodeCall;