@defillama/sdk 5.0.238 → 5.0.240

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 (131) hide show
  1. package/package.json +1 -1
  2. package/build/Balances.d.ts +0 -139
  3. package/build/Balances.js +0 -363
  4. package/build/ChainApi.d.ts +0 -142
  5. package/build/ChainApi.js +0 -310
  6. package/build/abi/abi2.d.ts +0 -5
  7. package/build/abi/abi2.js +0 -215
  8. package/build/abi/cachedABIs.d.ts +0 -4
  9. package/build/abi/cachedABIs.js +0 -8
  10. package/build/abi/convertResults.d.ts +0 -5
  11. package/build/abi/convertResults.js +0 -60
  12. package/build/abi/index.d.ts +0 -31
  13. package/build/abi/index.js +0 -327
  14. package/build/abi/multicall.d.ts +0 -23
  15. package/build/abi/multicall.js +0 -382
  16. package/build/abi/multicall3.d.ts +0 -7
  17. package/build/abi/multicall3.js +0 -397
  18. package/build/abi/rpcCall.d.ts +0 -4
  19. package/build/abi/rpcCall.js +0 -62
  20. package/build/abi/tron.d.ts +0 -33
  21. package/build/abi/tron.js +0 -116
  22. package/build/api.d.ts +0 -10
  23. package/build/api.js +0 -45
  24. package/build/api2.d.ts +0 -5
  25. package/build/api2.js +0 -41
  26. package/build/chains/algorand.d.ts +0 -277
  27. package/build/chains/algorand.js +0 -618
  28. package/build/chains/aptos.d.ts +0 -230
  29. package/build/chains/aptos.js +0 -612
  30. package/build/chains/cardano.d.ts +0 -242
  31. package/build/chains/cardano.js +0 -407
  32. package/build/chains/cosmos.d.ts +0 -252
  33. package/build/chains/cosmos.js +0 -618
  34. package/build/chains/icp.d.ts +0 -235
  35. package/build/chains/icp.js +0 -1040
  36. package/build/chains/index.d.ts +0 -23
  37. package/build/chains/index.js +0 -59
  38. package/build/chains/near.d.ts +0 -192
  39. package/build/chains/near.js +0 -446
  40. package/build/chains/rpc.d.ts +0 -125
  41. package/build/chains/rpc.js +0 -326
  42. package/build/chains/starknet.d.ts +0 -205
  43. package/build/chains/starknet.js +0 -884
  44. package/build/chains/stellar.d.ts +0 -410
  45. package/build/chains/stellar.js +0 -1082
  46. package/build/chains/substrate.d.ts +0 -333
  47. package/build/chains/substrate.js +0 -1042
  48. package/build/chains/sui.d.ts +0 -365
  49. package/build/chains/sui.js +0 -1135
  50. package/build/chains/svm.d.ts +0 -340
  51. package/build/chains/svm.js +0 -760
  52. package/build/chains/tezos.d.ts +0 -225
  53. package/build/chains/tezos.js +0 -412
  54. package/build/chains/ton.d.ts +0 -353
  55. package/build/chains/ton.js +0 -788
  56. package/build/chains/tron.d.ts +0 -45
  57. package/build/chains/tron.js +0 -110
  58. package/build/chains/utxo.d.ts +0 -202
  59. package/build/chains/utxo.js +0 -592
  60. package/build/chains/xrpl.d.ts +0 -179
  61. package/build/chains/xrpl.js +0 -467
  62. package/build/computeTVL/blocks.d.ts +0 -1
  63. package/build/computeTVL/blocks.js +0 -12
  64. package/build/computeTVL/humanizeNumber.d.ts +0 -1
  65. package/build/computeTVL/humanizeNumber.js +0 -19
  66. package/build/erc20/index.d.ts +0 -31
  67. package/build/erc20/index.js +0 -56
  68. package/build/eth/index.d.ts +0 -22
  69. package/build/eth/index.js +0 -118
  70. package/build/general.d.ts +0 -5
  71. package/build/general.js +0 -20
  72. package/build/generalUtil.d.ts +0 -8
  73. package/build/generalUtil.js +0 -73
  74. package/build/index.d.ts +0 -32
  75. package/build/index.js +0 -74
  76. package/build/providers.json +0 -1
  77. package/build/types.d.ts +0 -76
  78. package/build/types.js +0 -2
  79. package/build/util/LlamaProvider.d.ts +0 -46
  80. package/build/util/LlamaProvider.js +0 -367
  81. package/build/util/blocks.d.ts +0 -36
  82. package/build/util/blocks.js +0 -500
  83. package/build/util/cache.d.ts +0 -45
  84. package/build/util/cache.js +0 -309
  85. package/build/util/chainUtils/data.json +0 -1425
  86. package/build/util/chainUtils/index.d.ts +0 -11
  87. package/build/util/chainUtils/index.js +0 -136
  88. package/build/util/coins.d.ts +0 -19
  89. package/build/util/coins.js +0 -124
  90. package/build/util/common.d.ts +0 -34
  91. package/build/util/common.js +0 -376
  92. package/build/util/computeTVL.d.ts +0 -19
  93. package/build/util/computeTVL.js +0 -102
  94. package/build/util/cosmos.d.ts +0 -1
  95. package/build/util/cosmos.js +0 -8
  96. package/build/util/debugLog.d.ts +0 -4
  97. package/build/util/debugLog.js +0 -18
  98. package/build/util/discord.d.ts +0 -1
  99. package/build/util/discord.js +0 -33
  100. package/build/util/elastic.d.ts +0 -43
  101. package/build/util/elastic.js +0 -113
  102. package/build/util/env.d.ts +0 -20
  103. package/build/util/env.js +0 -175
  104. package/build/util/graph.d.ts +0 -8
  105. package/build/util/graph.js +0 -50
  106. package/build/util/index.d.ts +0 -32
  107. package/build/util/index.js +0 -227
  108. package/build/util/indexer.compatibility.d.ts +0 -6
  109. package/build/util/indexer.compatibility.js +0 -64
  110. package/build/util/indexer.d.ts +0 -92
  111. package/build/util/indexer.js +0 -850
  112. package/build/util/indexerSql.d.ts +0 -9
  113. package/build/util/indexerSql.js +0 -102
  114. package/build/util/internal-cache.d.ts +0 -11
  115. package/build/util/internal-cache.js +0 -77
  116. package/build/util/logs.d.ts +0 -58
  117. package/build/util/logs.decode.shared.d.ts +0 -8
  118. package/build/util/logs.decode.shared.js +0 -289
  119. package/build/util/logs.js +0 -432
  120. package/build/util/promisePool.d.ts +0 -8
  121. package/build/util/promisePool.js +0 -31
  122. package/build/util/r2.d.ts +0 -4
  123. package/build/util/r2.js +0 -52
  124. package/build/util/removeRedundantRPCs.d.ts +0 -1
  125. package/build/util/removeRedundantRPCs.js +0 -49
  126. package/build/util/transactions.d.ts +0 -35
  127. package/build/util/transactions.js +0 -22
  128. package/build/util/updateChainLabels.d.ts +0 -1
  129. package/build/util/updateChainLabels.js +0 -5
  130. package/build/util/updateProviderList.d.ts +0 -1
  131. package/build/util/updateProviderList.js +0 -275
package/build/ChainApi.js DELETED
@@ -1,310 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ChainApi = void 0;
7
- exports.getDebugStats = getDebugStats;
8
- const abi2_1 = require("./abi/abi2");
9
- const Balances_1 = __importDefault(require("./Balances"));
10
- const blocks_1 = require("./computeTVL/blocks");
11
- const general_1 = require("./general");
12
- const providers_json_1 = __importDefault(require("./providers.json"));
13
- const eth_1 = require("./eth");
14
- const common_1 = require("./util/common");
15
- const debugLog_1 = require("./util/debugLog");
16
- const logs_1 = __importDefault(require("./util/logs"));
17
- const transactions_1 = require("./util/transactions");
18
- const callStatsByProject = {};
19
- const nullAddress = '0x0000000000000000000000000000000000000000';
20
- // ERC-20 views of the native coin: balanceOf returns the same balance as eth_getBalance, so when summing
21
- // they are read as the native coin and deduped per owner, otherwise listing both counts the coin twice
22
- const nativeTokenAliases = {
23
- polygon: '0x0000000000000000000000000000000000001010', // POL (MRC20)
24
- celo: '0x471ece3750da237f93b8e339c536989b8978a438', // CELO (GoldToken)
25
- metis: '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000', // METIS
26
- arc: '0x3600000000000000000000000000000000000000', // USDC (6 decimals, native is 18)
27
- stable: '0x779ded0c9e1022225f8e0630b35a9b54be713736', // USDT0 (6 decimals, native is 18)
28
- };
29
- class ChainApi {
30
- constructor(params) {
31
- var _a, _b;
32
- this.block = params.block;
33
- this.chain = (_a = params.chain) !== null && _a !== void 0 ? _a : 'ethereum';
34
- this.timestamp = params.timestamp;
35
- this.provider = (0, general_1.getProvider)(this.chain);
36
- this._balances = new Balances_1.default({ chain: this.chain, timestamp: this.timestamp });
37
- // @ts-ignore
38
- this.chainId = (_b = providers_json_1.default[this.chain]) === null || _b === void 0 ? void 0 : _b.chainId;
39
- this.storedKey = params.storedKey;
40
- this.api = this;
41
- const uKey = this.storedKey ? `${params.protocol}:${this.storedKey}` : (params.protocol ? `${params.protocol}` : `chain-${this.chain}`);
42
- const stats = {
43
- meta: {
44
- chain: this.chain,
45
- storedKey: this.storedKey,
46
- protocol: params.protocol,
47
- },
48
- label: uKey,
49
- total: 0,
50
- };
51
- callStatsByProject[uKey] = stats;
52
- this.stats = stats;
53
- }
54
- addStat(method, value = 1, skipTotal = false) {
55
- if (!skipTotal)
56
- this.stats.total += value;
57
- if (!this.stats[method])
58
- this.stats[method] = 0;
59
- this.stats[method] += value;
60
- }
61
- // autoset block if timestamp is older than 2 hours
62
- async _setBlockFromTimestamp() {
63
- if (this.timestamp && !this.block) {
64
- const twoHoursAgo = Date.now() / 1000 - 2 * 60 * 60;
65
- if (this.timestamp > twoHoursAgo)
66
- return;
67
- await this.getBlock();
68
- }
69
- }
70
- async call(params) {
71
- await this._setBlockFromTimestamp();
72
- this.addStat('call');
73
- return (0, abi2_1.call)({
74
- ...params,
75
- block: this.block,
76
- chain: this.chain,
77
- });
78
- }
79
- async batchCall(params) {
80
- return Promise.all(params.map(i => this.call(i)));
81
- }
82
- async multiCall(params) {
83
- this.addStat('multiCall', params.calls.length, true);
84
- this.addStat('call');
85
- await this._setBlockFromTimestamp();
86
- return (0, abi2_1.multiCall)({
87
- ...params,
88
- block: this.block,
89
- chain: this.chain,
90
- });
91
- }
92
- async fetchList(params) {
93
- this.addStat('fetchList');
94
- await this._setBlockFromTimestamp();
95
- return (0, abi2_1.fetchList)({
96
- ...params,
97
- block: this.block,
98
- chain: this.chain,
99
- });
100
- }
101
- async bytecodeCall(params) {
102
- await this._setBlockFromTimestamp();
103
- return (0, abi2_1.bytecodeCall)({
104
- ...params,
105
- block: this.block,
106
- chain: this.chain,
107
- });
108
- }
109
- async getBlock() {
110
- if (!this.block)
111
- this.addStat('getBlock');
112
- if (!this.block)
113
- this.block = await (0, blocks_1.getBlockNumber)(this.chain, this.timestamp);
114
- return this.block;
115
- }
116
- log(...args) {
117
- (0, debugLog_1.debugLog)(...args);
118
- }
119
- logTable(...args) {
120
- (0, debugLog_1.debugTable)(...args);
121
- }
122
- add(token, balance, options = {}) {
123
- this._balances.add(token, balance, options);
124
- }
125
- addToken(token, balance, options = {}) {
126
- this.add(token, balance, options);
127
- }
128
- addGasToken(balance, options = {}) {
129
- this.add(nullAddress, balance, options);
130
- }
131
- addUSDValue(balance, options = {}) {
132
- this._balances.addUSDValue(balance, options);
133
- }
134
- addTokens(tokens, balances, options = {}) {
135
- this.add(tokens, balances, options);
136
- }
137
- addBalances(balances, options = {}) {
138
- this._balances.addBalances(balances, options);
139
- }
140
- addCGToken(token, balance, options = {}) {
141
- this._balances.addCGToken(token, balance, options);
142
- }
143
- addTokenVannila(token, balance, options = {}) {
144
- this._balances.addTokenVannila(token, balance, options);
145
- }
146
- getBalances() {
147
- return this._balances.getBalances();
148
- }
149
- getChainId() {
150
- return this.chainId;
151
- }
152
- removeTokenBalance(token) {
153
- this._balances.removeTokenBalance(token);
154
- }
155
- deleteToken(token) {
156
- this._balances.removeTokenBalance(token);
157
- }
158
- deleteTokens(tokens) {
159
- tokens.forEach(i => this.deleteToken(i));
160
- }
161
- async erc4626Sum2(options) {
162
- if (options.isOG4626 !== false)
163
- options.isOG4626 = true;
164
- return this.erc4626Sum(options);
165
- }
166
- async erc4626Sum({ calls, tokenAbi, balanceAbi, balanceCalls, permitFailure = false, isOG4626 = false }) {
167
- if (isOG4626 && !tokenAbi && !balanceAbi) {
168
- tokenAbi = 'asset';
169
- balanceAbi = 'totalAssets';
170
- }
171
- if (!tokenAbi)
172
- tokenAbi = 'address:token';
173
- if (!balanceAbi)
174
- balanceAbi = 'uint256:balance';
175
- if (typeof tokenAbi === 'string' && (!tokenAbi.includes(':') && !tokenAbi.includes('(')))
176
- tokenAbi = `address:${tokenAbi}`;
177
- if (typeof balanceAbi === 'string' && (!balanceAbi.includes(':') && !balanceAbi.includes('(')))
178
- balanceAbi = `uint256:${balanceAbi}`;
179
- const tokens = await this.multiCall({ calls, abi: tokenAbi, permitFailure });
180
- const balances = await this.multiCall({ calls: calls !== null && calls !== void 0 ? calls : balanceCalls, abi: balanceAbi, permitFailure });
181
- if (!permitFailure)
182
- this.addTokens(tokens, balances);
183
- else
184
- tokens.forEach((i, j) => {
185
- if (i && balances[j])
186
- this.addToken(i, balances[j]);
187
- });
188
- return this.getBalances();
189
- }
190
- async getTokenBalances({ token, tokens = [], owners = [], owner, tokensAndOwners = [], tokensAndOwners2 = [], blacklistedTokens = [], blacklistedOwners = [], ownerTokens = [], skipDuplicates = false, permitFailure = false, withTokenData = false, }) {
191
- await this._setBlockFromTimestamp();
192
- if (tokensAndOwners2.length)
193
- tokensAndOwners.push(...tokensAndOwners2[0].map((i, j) => [i, tokensAndOwners2[1][j]]));
194
- if (token)
195
- tokens.push(token);
196
- if (tokens.length) {
197
- if (owner)
198
- owners.push(owner);
199
- tokensAndOwners.push(...tokens.map(i => owners.map(j => [i, j])).flat());
200
- }
201
- for (const [tokens, owner] of ownerTokens)
202
- tokens.forEach((i) => tokensAndOwners.push([i, owner]));
203
- if (skipDuplicates)
204
- tokensAndOwners = getUniqueTokensAndOwners(tokensAndOwners, this.chain);
205
- blacklistedOwners.push(nullAddress); // skip nullAddress owners
206
- blacklistedOwners = (0, common_1.getUniqueAddresses)(blacklistedOwners, this.chain);
207
- blacklistedTokens = (0, common_1.getUniqueAddresses)(blacklistedTokens, this.chain);
208
- tokensAndOwners = tokensAndOwners.filter(i => !blacklistedTokens.includes(i[0]) && !blacklistedOwners.includes(i[1]));
209
- // only when summing: plain balance lookups expect the alias's own (ERC-20 decimals) value back
210
- const nativeAlias = nativeTokenAliases[this.chain];
211
- if (skipDuplicates && nativeAlias)
212
- tokensAndOwners = getUniqueTokensAndOwners(tokensAndOwners.map(([t, o]) => [t === nativeAlias ? nullAddress : t, o]), this.chain);
213
- const tokenBalances = [];
214
- const erc20TokensResponseIndex = [];
215
- const ethBalanceResponseIndex = [];
216
- const erc20TokensAndOwners = [];
217
- const ethBalOwners = [];
218
- tokensAndOwners.forEach((i, j) => {
219
- if (i[0] !== nullAddress) {
220
- erc20TokensAndOwners.push(i);
221
- erc20TokensResponseIndex.push(j);
222
- }
223
- else {
224
- ethBalOwners.push(i[1]);
225
- ethBalanceResponseIndex.push(j);
226
- }
227
- });
228
- this.addStat('sumTokens', erc20TokensAndOwners.length + ethBalOwners.length, true);
229
- const bals = await this.multiCall({
230
- calls: erc20TokensAndOwners.map(([token, owner]) => ({ target: token, params: [owner] })),
231
- abi: 'erc20:balanceOf',
232
- permitFailure,
233
- });
234
- bals.forEach((i, j) => {
235
- if (!i)
236
- i = '0';
237
- const token = erc20TokensAndOwners[j][0];
238
- const responseIndex = erc20TokensResponseIndex[j];
239
- tokenBalances[responseIndex] = [token, i];
240
- });
241
- if (ethBalOwners.length) {
242
- let ethBals = (await (0, eth_1.getBalances)({ chain: this.chain, targets: ethBalOwners, block: this.block, permitFailure })).output.map((i) => i.balance);
243
- ethBals.map((i, idx) => tokenBalances[ethBalanceResponseIndex[idx]] = [nullAddress, i]);
244
- }
245
- if (!withTokenData)
246
- return tokenBalances.map(i => i[1]);
247
- return tokenBalances;
248
- }
249
- async sumTokens({ balancesV2Options = {}, ...tokenBalanceOptions }) {
250
- const tokenBalances = await this.getTokenBalances({ ...tokenBalanceOptions, skipDuplicates: true, withTokenData: true });
251
- tokenBalances.forEach(([token, balance]) => this.addToken(token, balance, balancesV2Options));
252
- return this.getBalances();
253
- }
254
- async getERC20TokenBalances(options) {
255
- return this.getTokenBalances(options);
256
- }
257
- async getGasTokenBalance(owner, options) {
258
- return (await this.getGasTokenBalances({ ...options, owner, }))[0];
259
- }
260
- async getGasTokenBalances(options) {
261
- return this.getTokenBalances({ ...options, token: nullAddress });
262
- }
263
- async getEthBalance(owner, options) {
264
- return this.getGasTokenBalance(owner, options !== null && options !== void 0 ? options : {});
265
- }
266
- async getEthBalances(options) {
267
- return this.getGasTokenBalances(options);
268
- }
269
- async getUSDValue() {
270
- return this._balances.getUSDValue();
271
- }
272
- async getUSDString() {
273
- return this._balances.getUSDString();
274
- }
275
- async getUSDJSONs() {
276
- return this._balances.getUSDJSONs();
277
- }
278
- async getLogs(params) {
279
- var _a;
280
- this.addStat('getLogs', ((_a = params.targets) === null || _a === void 0 ? void 0 : _a.length) || 1);
281
- params.chain = this.chain;
282
- return (0, logs_1.default)(params);
283
- }
284
- getBalancesV2() {
285
- return this._balances;
286
- }
287
- async getTransactions(params) {
288
- this.addStat('getTransactions');
289
- return (0, transactions_1.getTransactions)({ ...params, chain: this.chain });
290
- }
291
- async getTransactionReceipt(tx) {
292
- this.addStat('getTransactionReceipt');
293
- return this.provider.getTransactionReceipt(tx);
294
- }
295
- getStats() {
296
- return this.stats;
297
- }
298
- }
299
- exports.ChainApi = ChainApi;
300
- exports.default = ChainApi;
301
- function getUniqueTokensAndOwners(toa, chain) {
302
- if (!toa.length)
303
- return [];
304
- const mergedToa = toa.map(i => i.join('~'));
305
- const uniqueMerged = (0, common_1.getUniqueAddresses)(mergedToa, chain);
306
- return uniqueMerged.map(i => i.split('~'));
307
- }
308
- function getDebugStats() {
309
- return callStatsByProject;
310
- }
@@ -1,5 +0,0 @@
1
- import { CallOptions, MulticallOptions, FetchListOptions, ByteCodeCallOptions } from "../types";
2
- export declare function call(params: CallOptions): Promise<any>;
3
- export declare function multiCall(params: MulticallOptions): Promise<any[]>;
4
- export declare function fetchList(params: FetchListOptions): Promise<any>;
5
- export declare function bytecodeCall(params: ByteCodeCallOptions): Promise<any>;
package/build/abi/abi2.js DELETED
@@ -1,215 +0,0 @@
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
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.call = call;
37
- exports.multiCall = multiCall;
38
- exports.fetchList = fetchList;
39
- exports.bytecodeCall = bytecodeCall;
40
- const abi1 = __importStar(require("./index"));
41
- async function call(params) {
42
- if (params.abis)
43
- return callWithAlternateAbis();
44
- try {
45
- const response = await abi1.call(params); // abi v1 doesnt have support for 'abis' param
46
- if (params.field)
47
- response.output = response.output[params.field];
48
- if (params.withMetadata)
49
- return response;
50
- return response.output;
51
- }
52
- catch (e) {
53
- if (!params.permitFailure)
54
- throw e;
55
- if (params.withMetadata)
56
- return { success: false, error: e };
57
- return null;
58
- }
59
- async function callWithAlternateAbis() {
60
- const { abis, ...restParams } = params;
61
- if (!abis || abis.length === 0)
62
- throw new Error('No alternate ABIs provided!');
63
- for (let i = 0; i < abis.length - 1; i++) {
64
- const res = await call({ ...restParams, abi: abis[i], permitFailure: true, withMetadata: true });
65
- const response = params.withMetadata ? res : res.output;
66
- if (res.success !== false)
67
- return response;
68
- }
69
- const lastAbi = abis[abis.length - 1];
70
- return call({ ...restParams, abi: lastAbi, });
71
- }
72
- }
73
- async function multiCall(params) {
74
- if (params.excludeFailed)
75
- params.permitFailure = true;
76
- if (params.abis)
77
- return multiCallWithAlternateAbis();
78
- params.calls = params.calls.map(i => {
79
- if (typeof i === 'object')
80
- return i;
81
- if (typeof i === 'string') {
82
- if (params.target)
83
- return { params: i };
84
- return { target: i };
85
- }
86
- return { params: i };
87
- });
88
- let { output } = await abi1.multiCall(params);
89
- if (params.excludeFailed)
90
- output = output.filter((i) => i.success);
91
- if (params.field)
92
- output.forEach((i) => i.output = i.output[params.field]);
93
- if (params.withMetadata)
94
- return output;
95
- return output.map((i) => i.output);
96
- async function multiCallWithAlternateAbis() {
97
- const { abis, ...restParams } = params;
98
- if (!abis || abis.length === 0)
99
- throw new Error('No alternate ABIs provided!');
100
- const outputs = [];
101
- for (let i = 0; i < abis.length; i++) {
102
- const res = await multiCall({ ...restParams, abi: abis[i], permitFailure: true, withMetadata: true, excludeFailed: false, });
103
- outputs.push(res);
104
- }
105
- let finalOutput;
106
- const permitFailure = params.permitFailure || params.excludeFailed;
107
- outputs.forEach((res) => {
108
- if (!finalOutput) { // First iteration
109
- finalOutput = res;
110
- return;
111
- }
112
- res.forEach((callRes, idx) => {
113
- var _a;
114
- if ((_a = finalOutput[idx]) === null || _a === void 0 ? void 0 : _a.success)
115
- return; // Already succeeded with an earlier ABI
116
- finalOutput[idx] = callRes;
117
- });
118
- });
119
- if (!permitFailure)
120
- finalOutput.forEach((data) => {
121
- if (!(data === null || data === void 0 ? void 0 : data.success))
122
- throw new Error(`All ABI alternatives failed for multiCall! Last error: ${data === null || data === void 0 ? void 0 : data.error}`);
123
- });
124
- if (params.excludeFailed)
125
- finalOutput = finalOutput.filter((i) => i === null || i === void 0 ? void 0 : i.success);
126
- if (params.withMetadata)
127
- return finalOutput;
128
- return finalOutput.map((i) => i.output);
129
- }
130
- }
131
- async function fetchList(params) {
132
- // itemAbi2 is used when we need to make a second call to get the final result
133
- let { startFrom = 0, lengthAbi, itemAbi, withMetadata, startFromOne = false, itemCount, target, targets, calls: _targets, chain, block, permitFailure, groupedByInput, excludeFailed, itemAbi2, field, field2, } = params;
134
- if (!targets)
135
- targets = _targets;
136
- const _groupedByInputOrignal = groupedByInput;
137
- if (targets && itemAbi2)
138
- groupedByInput = true;
139
- permitFailure = permitFailure || excludeFailed;
140
- if (excludeFailed && groupedByInput)
141
- throw new Error('excludeFailed and groupedByInput cannot be used together!');
142
- if (withMetadata && groupedByInput)
143
- throw new Error('withMetadata and groupedByInput cannot be used together!');
144
- if (typeof lengthAbi === 'string' && (!lengthAbi.includes(':') && !lengthAbi.includes('(')))
145
- lengthAbi = `uint256:${lengthAbi}`;
146
- if (typeof itemAbi === 'string' && (!itemAbi.includes(':') && !itemAbi.includes('(')))
147
- itemAbi = `function ${itemAbi}(uint256) view returns (address)`;
148
- let itemLength, itemLengths;
149
- const calls = [];
150
- if (!target && !targets)
151
- throw new Error('Need to provide either target or targets parameter!');
152
- if (target) {
153
- if (itemCount)
154
- itemLength = itemCount;
155
- else
156
- itemLength = await call({ chain, block, target, abi: lengthAbi, });
157
- // debugLog('length: ', itemLength)
158
- if (startFromOne) {
159
- itemLength++;
160
- if (startFrom === 0)
161
- startFrom = 1;
162
- }
163
- for (let i = startFrom; i < itemLength; i++)
164
- calls.push({ target, params: [i] });
165
- const response = await multiCall({ chain, block, permitFailure, abi: itemAbi, calls, withMetadata, excludeFailed, field, });
166
- if (!itemAbi2)
167
- return response;
168
- return multiCall({ chain, block, target, permitFailure, abi: itemAbi2, calls: response, withMetadata, excludeFailed, field: field2, });
169
- }
170
- if (itemCount)
171
- itemLengths = targets.map(() => itemCount);
172
- else
173
- itemLengths = await multiCall({ chain, block, calls: targets, abi: lengthAbi, });
174
- // debugLog('itemLengths: ', itemLengths)
175
- let groupedByRes = itemLengths.map(() => []);
176
- const indexToTargetMapping = {};
177
- let k = 0;
178
- for (let i = 0; i < itemLengths.length; i++) {
179
- let itemLength = itemLengths[i];
180
- if (startFromOne) {
181
- itemLength++;
182
- if (startFrom === 0)
183
- startFrom = 1;
184
- }
185
- for (let j = startFrom; j < itemLength; j++) {
186
- calls.push({ target: targets[i], params: [j] });
187
- indexToTargetMapping[k] = i;
188
- k++;
189
- }
190
- }
191
- const res = await multiCall({ chain, block, permitFailure, abi: itemAbi, calls, withMetadata, excludeFailed, field, });
192
- if (!groupedByInput)
193
- return res;
194
- res.forEach((i, idx) => groupedByRes[indexToTargetMapping[idx]].push(i));
195
- if (!itemAbi2)
196
- return groupedByRes;
197
- const calls2 = [];
198
- for (let i = 0; i < targets.length; i++) {
199
- for (let j = 0; j < groupedByRes[i].length; j++) {
200
- calls2.push({ target: targets[i], params: groupedByRes[i][j] });
201
- }
202
- }
203
- const res2 = await multiCall({ chain, block, permitFailure, abi: itemAbi2, calls: calls2, withMetadata, excludeFailed, field: field2, });
204
- if (!_groupedByInputOrignal)
205
- return res2;
206
- groupedByRes = itemLengths.map(() => []);
207
- res2.forEach((i, idx) => groupedByRes[indexToTargetMapping[idx]].push(i));
208
- return groupedByRes;
209
- }
210
- async function bytecodeCall(params) {
211
- const response = await abi1.bytecodeCall(params);
212
- if (params.withMetadata)
213
- return response;
214
- return response.output;
215
- }
@@ -1,4 +0,0 @@
1
- declare const _default: {
2
- [method: string]: any | undefined;
3
- };
4
- export default _default;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = {
4
- "erc20:symbol": "string:symbol",
5
- "erc20:decimals": "uint8:decimals",
6
- "erc20:balanceOf": "function balanceOf(address account) view returns (uint256)",
7
- "erc20:totalSupply": "uint256:totalSupply",
8
- };
@@ -1,5 +0,0 @@
1
- import { ethers } from "ethers";
2
- export default function (results: ethers.Result, { functionABI, chain }?: {
3
- functionABI?: ethers.FunctionFragment;
4
- chain?: string;
5
- }): any;
@@ -1,60 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = default_1;
4
- const common_1 = require("../util/common");
5
- function isNumberOrBigNumber(value) {
6
- return typeof value === 'bigint' || typeof value === "number";
7
- }
8
- function stringifyBigNumbers(result) {
9
- let final = { ...result };
10
- if (Array.isArray(result))
11
- final = [...result];
12
- Object.keys(result).forEach((key) => {
13
- if (isNumberOrBigNumber(result[key]))
14
- final[key] = result[key].toString();
15
- else if (typeof result[key] === "object")
16
- final[key] = stringifyBigNumbers(result[key]);
17
- else
18
- final[key] = result[key];
19
- });
20
- return final;
21
- }
22
- function default_1(results, { functionABI, chain } = {}) {
23
- let response;
24
- if (typeof results === "string" || typeof results === "boolean")
25
- return results;
26
- if (isNumberOrBigNumber(results))
27
- return results.toString();
28
- response = stringifyBigNumbers(results);
29
- if (functionABI && functionABI.outputs) {
30
- functionABI.outputs.map((componentDefinition, i) => {
31
- setComponentDetails(response[i], componentDefinition, chain);
32
- setNameAndTranformAddress({ response, componentDefinition, chain, index: i });
33
- });
34
- }
35
- if (response instanceof Array)
36
- if (response.length === 1)
37
- return response[0];
38
- return response;
39
- }
40
- function setComponentDetails(component, componentDefinition, chain) {
41
- if (componentDefinition.type === "tuple[]")
42
- return component.map((item) => setDetails(item, chain));
43
- if (componentDefinition.type === "tuple")
44
- return setDetails(component, chain);
45
- function setDetails(value, chain) {
46
- const definitions = componentDefinition.components || componentDefinition.arrayChildren.components;
47
- definitions.map((def, i) => {
48
- setComponentDetails(value[i], def, chain);
49
- setNameAndTranformAddress({ response: value, componentDefinition: def, chain, index: i });
50
- });
51
- }
52
- }
53
- function setNameAndTranformAddress({ response, componentDefinition, chain, index }) {
54
- if (chain === 'tron' && componentDefinition.type === 'address') {
55
- response[index] = (0, common_1.evmToTronAddress)(response[index]);
56
- }
57
- if (componentDefinition === null || componentDefinition === void 0 ? void 0 : componentDefinition.name)
58
- response[componentDefinition.name] = response[index];
59
- return response;
60
- }
@@ -1,31 +0,0 @@
1
- import { Address, ByteCodeCallOptions, LogArray } from "../types";
2
- import { Chain } from "../general";
3
- type CallParams = any;
4
- type CallOptions = {
5
- target: Address;
6
- abi: string | any;
7
- block?: number | string;
8
- params?: CallParams;
9
- chain?: Chain | string;
10
- skipCache?: boolean;
11
- logArray?: LogArray;
12
- };
13
- type MulticallOptions = {
14
- abi: string | any;
15
- calls: {
16
- target?: Address;
17
- params?: CallParams;
18
- }[];
19
- block?: number | string;
20
- target?: Address;
21
- chain?: Chain | string;
22
- chunkSize?: number;
23
- skipCache?: boolean;
24
- contractCalls?: any;
25
- permitFailure?: boolean;
26
- logArray?: LogArray;
27
- };
28
- export declare function call(params: CallOptions): Promise<any>;
29
- export declare function bytecodeCall(params: ByteCodeCallOptions): Promise<any>;
30
- export declare function multiCall(params: MulticallOptions): Promise<any>;
31
- export {};