@defillama/sdk 5.0.236 → 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.
- package/package.json +3 -3
- package/build/Balances.d.ts +0 -139
- package/build/Balances.js +0 -363
- package/build/ChainApi.d.ts +0 -142
- package/build/ChainApi.js +0 -297
- package/build/abi/abi2.d.ts +0 -5
- package/build/abi/abi2.js +0 -215
- package/build/abi/cachedABIs.d.ts +0 -4
- package/build/abi/cachedABIs.js +0 -8
- package/build/abi/convertResults.d.ts +0 -5
- package/build/abi/convertResults.js +0 -60
- package/build/abi/index.d.ts +0 -31
- package/build/abi/index.js +0 -327
- package/build/abi/multicall.d.ts +0 -23
- package/build/abi/multicall.js +0 -382
- package/build/abi/multicall3.d.ts +0 -7
- package/build/abi/multicall3.js +0 -397
- package/build/abi/rpcCall.d.ts +0 -4
- package/build/abi/rpcCall.js +0 -62
- package/build/abi/tron.d.ts +0 -33
- package/build/abi/tron.js +0 -110
- package/build/api.d.ts +0 -10
- package/build/api.js +0 -45
- package/build/api2.d.ts +0 -5
- package/build/api2.js +0 -41
- package/build/chains/algorand.d.ts +0 -277
- package/build/chains/algorand.js +0 -618
- package/build/chains/aptos.d.ts +0 -230
- package/build/chains/aptos.js +0 -612
- package/build/chains/cardano.d.ts +0 -242
- package/build/chains/cardano.js +0 -407
- package/build/chains/cosmos.d.ts +0 -252
- package/build/chains/cosmos.js +0 -618
- package/build/chains/icp.d.ts +0 -235
- package/build/chains/icp.js +0 -1040
- package/build/chains/index.d.ts +0 -23
- package/build/chains/index.js +0 -59
- package/build/chains/near.d.ts +0 -192
- package/build/chains/near.js +0 -446
- package/build/chains/rpc.d.ts +0 -125
- package/build/chains/rpc.js +0 -326
- package/build/chains/starknet.d.ts +0 -205
- package/build/chains/starknet.js +0 -884
- package/build/chains/stellar.d.ts +0 -410
- package/build/chains/stellar.js +0 -1082
- package/build/chains/substrate.d.ts +0 -333
- package/build/chains/substrate.js +0 -1042
- package/build/chains/sui.d.ts +0 -365
- package/build/chains/sui.js +0 -1135
- package/build/chains/svm.d.ts +0 -340
- package/build/chains/svm.js +0 -760
- package/build/chains/tezos.d.ts +0 -225
- package/build/chains/tezos.js +0 -412
- package/build/chains/ton.d.ts +0 -353
- package/build/chains/ton.js +0 -788
- package/build/chains/tron.d.ts +0 -45
- package/build/chains/tron.js +0 -110
- package/build/chains/utxo.d.ts +0 -202
- package/build/chains/utxo.js +0 -592
- package/build/chains/xrpl.d.ts +0 -179
- package/build/chains/xrpl.js +0 -467
- package/build/computeTVL/blocks.d.ts +0 -1
- package/build/computeTVL/blocks.js +0 -12
- package/build/computeTVL/humanizeNumber.d.ts +0 -1
- package/build/computeTVL/humanizeNumber.js +0 -19
- package/build/erc20/index.d.ts +0 -31
- package/build/erc20/index.js +0 -56
- package/build/eth/index.d.ts +0 -22
- package/build/eth/index.js +0 -118
- package/build/general.d.ts +0 -5
- package/build/general.js +0 -20
- package/build/generalUtil.d.ts +0 -8
- package/build/generalUtil.js +0 -73
- package/build/index.d.ts +0 -32
- package/build/index.js +0 -74
- package/build/providers.json +0 -1
- package/build/types.d.ts +0 -76
- package/build/types.js +0 -2
- package/build/util/LlamaProvider.d.ts +0 -46
- package/build/util/LlamaProvider.js +0 -365
- package/build/util/blocks.d.ts +0 -36
- package/build/util/blocks.js +0 -292
- package/build/util/cache.d.ts +0 -45
- package/build/util/cache.js +0 -309
- package/build/util/chainUtils/data.json +0 -1356
- package/build/util/chainUtils/index.d.ts +0 -11
- package/build/util/chainUtils/index.js +0 -136
- package/build/util/coins.d.ts +0 -19
- package/build/util/coins.js +0 -113
- package/build/util/common.d.ts +0 -34
- package/build/util/common.js +0 -373
- package/build/util/computeTVL.d.ts +0 -19
- package/build/util/computeTVL.js +0 -102
- package/build/util/cosmos.d.ts +0 -1
- package/build/util/cosmos.js +0 -8
- package/build/util/debugLog.d.ts +0 -4
- package/build/util/debugLog.js +0 -18
- package/build/util/discord.d.ts +0 -1
- package/build/util/discord.js +0 -33
- package/build/util/elastic.d.ts +0 -43
- package/build/util/elastic.js +0 -113
- package/build/util/env.d.ts +0 -19
- package/build/util/env.js +0 -158
- package/build/util/graph.d.ts +0 -8
- package/build/util/graph.js +0 -50
- package/build/util/index.d.ts +0 -32
- package/build/util/index.js +0 -227
- package/build/util/indexer.compatibility.d.ts +0 -6
- package/build/util/indexer.compatibility.js +0 -64
- package/build/util/indexer.d.ts +0 -92
- package/build/util/indexer.js +0 -744
- package/build/util/indexerSql.d.ts +0 -9
- package/build/util/indexerSql.js +0 -102
- package/build/util/internal-cache.d.ts +0 -11
- package/build/util/internal-cache.js +0 -77
- package/build/util/logs.d.ts +0 -55
- package/build/util/logs.decode.shared.d.ts +0 -8
- package/build/util/logs.decode.shared.js +0 -289
- package/build/util/logs.js +0 -401
- package/build/util/promisePool.d.ts +0 -8
- package/build/util/promisePool.js +0 -31
- package/build/util/r2.d.ts +0 -4
- package/build/util/r2.js +0 -52
- package/build/util/removeRedundantRPCs.d.ts +0 -1
- package/build/util/removeRedundantRPCs.js +0 -49
- package/build/util/transactions.d.ts +0 -35
- package/build/util/transactions.js +0 -22
- package/build/util/updateChainLabels.d.ts +0 -1
- package/build/util/updateChainLabels.js +0 -5
- package/build/util/updateProviderList.d.ts +0 -1
- package/build/util/updateProviderList.js +0 -274
package/build/ChainApi.js
DELETED
|
@@ -1,297 +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
|
-
class ChainApi {
|
|
21
|
-
constructor(params) {
|
|
22
|
-
var _a, _b;
|
|
23
|
-
this.block = params.block;
|
|
24
|
-
this.chain = (_a = params.chain) !== null && _a !== void 0 ? _a : 'ethereum';
|
|
25
|
-
this.timestamp = params.timestamp;
|
|
26
|
-
this.provider = (0, general_1.getProvider)(this.chain);
|
|
27
|
-
this._balances = new Balances_1.default({ chain: this.chain, timestamp: this.timestamp });
|
|
28
|
-
// @ts-ignore
|
|
29
|
-
this.chainId = (_b = providers_json_1.default[this.chain]) === null || _b === void 0 ? void 0 : _b.chainId;
|
|
30
|
-
this.storedKey = params.storedKey;
|
|
31
|
-
this.api = this;
|
|
32
|
-
const uKey = this.storedKey ? `${params.protocol}:${this.storedKey}` : (params.protocol ? `${params.protocol}` : `chain-${this.chain}`);
|
|
33
|
-
const stats = {
|
|
34
|
-
meta: {
|
|
35
|
-
chain: this.chain,
|
|
36
|
-
storedKey: this.storedKey,
|
|
37
|
-
protocol: params.protocol,
|
|
38
|
-
},
|
|
39
|
-
label: uKey,
|
|
40
|
-
total: 0,
|
|
41
|
-
};
|
|
42
|
-
callStatsByProject[uKey] = stats;
|
|
43
|
-
this.stats = stats;
|
|
44
|
-
}
|
|
45
|
-
addStat(method, value = 1, skipTotal = false) {
|
|
46
|
-
if (!skipTotal)
|
|
47
|
-
this.stats.total += value;
|
|
48
|
-
if (!this.stats[method])
|
|
49
|
-
this.stats[method] = 0;
|
|
50
|
-
this.stats[method] += value;
|
|
51
|
-
}
|
|
52
|
-
// autoset block if timestamp is older than 2 hours
|
|
53
|
-
async _setBlockFromTimestamp() {
|
|
54
|
-
if (this.timestamp && !this.block) {
|
|
55
|
-
const twoHoursAgo = Date.now() / 1000 - 2 * 60 * 60;
|
|
56
|
-
if (this.timestamp > twoHoursAgo)
|
|
57
|
-
return;
|
|
58
|
-
await this.getBlock();
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
async call(params) {
|
|
62
|
-
await this._setBlockFromTimestamp();
|
|
63
|
-
this.addStat('call');
|
|
64
|
-
return (0, abi2_1.call)({
|
|
65
|
-
...params,
|
|
66
|
-
block: this.block,
|
|
67
|
-
chain: this.chain,
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
async batchCall(params) {
|
|
71
|
-
return Promise.all(params.map(i => this.call(i)));
|
|
72
|
-
}
|
|
73
|
-
async multiCall(params) {
|
|
74
|
-
this.addStat('multiCall', params.calls.length, true);
|
|
75
|
-
this.addStat('call');
|
|
76
|
-
await this._setBlockFromTimestamp();
|
|
77
|
-
return (0, abi2_1.multiCall)({
|
|
78
|
-
...params,
|
|
79
|
-
block: this.block,
|
|
80
|
-
chain: this.chain,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
async fetchList(params) {
|
|
84
|
-
this.addStat('fetchList');
|
|
85
|
-
await this._setBlockFromTimestamp();
|
|
86
|
-
return (0, abi2_1.fetchList)({
|
|
87
|
-
...params,
|
|
88
|
-
block: this.block,
|
|
89
|
-
chain: this.chain,
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
async bytecodeCall(params) {
|
|
93
|
-
await this._setBlockFromTimestamp();
|
|
94
|
-
return (0, abi2_1.bytecodeCall)({
|
|
95
|
-
...params,
|
|
96
|
-
block: this.block,
|
|
97
|
-
chain: this.chain,
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
async getBlock() {
|
|
101
|
-
if (!this.block)
|
|
102
|
-
this.addStat('getBlock');
|
|
103
|
-
if (!this.block)
|
|
104
|
-
this.block = await (0, blocks_1.getBlockNumber)(this.chain, this.timestamp);
|
|
105
|
-
return this.block;
|
|
106
|
-
}
|
|
107
|
-
log(...args) {
|
|
108
|
-
(0, debugLog_1.debugLog)(...args);
|
|
109
|
-
}
|
|
110
|
-
logTable(...args) {
|
|
111
|
-
(0, debugLog_1.debugTable)(...args);
|
|
112
|
-
}
|
|
113
|
-
add(token, balance, options = {}) {
|
|
114
|
-
this._balances.add(token, balance, options);
|
|
115
|
-
}
|
|
116
|
-
addToken(token, balance, options = {}) {
|
|
117
|
-
this.add(token, balance, options);
|
|
118
|
-
}
|
|
119
|
-
addGasToken(balance, options = {}) {
|
|
120
|
-
this.add(nullAddress, balance, options);
|
|
121
|
-
}
|
|
122
|
-
addUSDValue(balance, options = {}) {
|
|
123
|
-
this._balances.addUSDValue(balance, options);
|
|
124
|
-
}
|
|
125
|
-
addTokens(tokens, balances, options = {}) {
|
|
126
|
-
this.add(tokens, balances, options);
|
|
127
|
-
}
|
|
128
|
-
addBalances(balances, options = {}) {
|
|
129
|
-
this._balances.addBalances(balances, options);
|
|
130
|
-
}
|
|
131
|
-
addCGToken(token, balance, options = {}) {
|
|
132
|
-
this._balances.addCGToken(token, balance, options);
|
|
133
|
-
}
|
|
134
|
-
addTokenVannila(token, balance, options = {}) {
|
|
135
|
-
this._balances.addTokenVannila(token, balance, options);
|
|
136
|
-
}
|
|
137
|
-
getBalances() {
|
|
138
|
-
return this._balances.getBalances();
|
|
139
|
-
}
|
|
140
|
-
getChainId() {
|
|
141
|
-
return this.chainId;
|
|
142
|
-
}
|
|
143
|
-
removeTokenBalance(token) {
|
|
144
|
-
this._balances.removeTokenBalance(token);
|
|
145
|
-
}
|
|
146
|
-
deleteToken(token) {
|
|
147
|
-
this._balances.removeTokenBalance(token);
|
|
148
|
-
}
|
|
149
|
-
deleteTokens(tokens) {
|
|
150
|
-
tokens.forEach(i => this.deleteToken(i));
|
|
151
|
-
}
|
|
152
|
-
async erc4626Sum2(options) {
|
|
153
|
-
if (options.isOG4626 !== false)
|
|
154
|
-
options.isOG4626 = true;
|
|
155
|
-
return this.erc4626Sum(options);
|
|
156
|
-
}
|
|
157
|
-
async erc4626Sum({ calls, tokenAbi, balanceAbi, balanceCalls, permitFailure = false, isOG4626 = false }) {
|
|
158
|
-
if (isOG4626 && !tokenAbi && !balanceAbi) {
|
|
159
|
-
tokenAbi = 'asset';
|
|
160
|
-
balanceAbi = 'totalAssets';
|
|
161
|
-
}
|
|
162
|
-
if (!tokenAbi)
|
|
163
|
-
tokenAbi = 'address:token';
|
|
164
|
-
if (!balanceAbi)
|
|
165
|
-
balanceAbi = 'uint256:balance';
|
|
166
|
-
if (typeof tokenAbi === 'string' && (!tokenAbi.includes(':') && !tokenAbi.includes('(')))
|
|
167
|
-
tokenAbi = `address:${tokenAbi}`;
|
|
168
|
-
if (typeof balanceAbi === 'string' && (!balanceAbi.includes(':') && !balanceAbi.includes('(')))
|
|
169
|
-
balanceAbi = `uint256:${balanceAbi}`;
|
|
170
|
-
const tokens = await this.multiCall({ calls, abi: tokenAbi, permitFailure });
|
|
171
|
-
const balances = await this.multiCall({ calls: calls !== null && calls !== void 0 ? calls : balanceCalls, abi: balanceAbi, permitFailure });
|
|
172
|
-
if (!permitFailure)
|
|
173
|
-
this.addTokens(tokens, balances);
|
|
174
|
-
else
|
|
175
|
-
tokens.forEach((i, j) => {
|
|
176
|
-
if (i && balances[j])
|
|
177
|
-
this.addToken(i, balances[j]);
|
|
178
|
-
});
|
|
179
|
-
return this.getBalances();
|
|
180
|
-
}
|
|
181
|
-
async getTokenBalances({ token, tokens = [], owners = [], owner, tokensAndOwners = [], tokensAndOwners2 = [], blacklistedTokens = [], blacklistedOwners = [], ownerTokens = [], skipDuplicates = false, permitFailure = false, withTokenData = false, }) {
|
|
182
|
-
await this._setBlockFromTimestamp();
|
|
183
|
-
if (tokensAndOwners2.length)
|
|
184
|
-
tokensAndOwners.push(...tokensAndOwners2[0].map((i, j) => [i, tokensAndOwners2[1][j]]));
|
|
185
|
-
if (token)
|
|
186
|
-
tokens.push(token);
|
|
187
|
-
if (tokens.length) {
|
|
188
|
-
if (owner)
|
|
189
|
-
owners.push(owner);
|
|
190
|
-
tokensAndOwners.push(...tokens.map(i => owners.map(j => [i, j])).flat());
|
|
191
|
-
}
|
|
192
|
-
for (const [tokens, owner] of ownerTokens)
|
|
193
|
-
tokens.forEach((i) => tokensAndOwners.push([i, owner]));
|
|
194
|
-
if (skipDuplicates)
|
|
195
|
-
tokensAndOwners = getUniqueTokensAndOwners(tokensAndOwners, this.chain);
|
|
196
|
-
blacklistedOwners.push(nullAddress); // skip nullAddress owners
|
|
197
|
-
blacklistedOwners = (0, common_1.getUniqueAddresses)(blacklistedOwners, this.chain);
|
|
198
|
-
blacklistedTokens = (0, common_1.getUniqueAddresses)(blacklistedTokens, this.chain);
|
|
199
|
-
tokensAndOwners = tokensAndOwners.filter(i => !blacklistedTokens.includes(i[0]) && !blacklistedOwners.includes(i[1]));
|
|
200
|
-
const tokenBalances = [];
|
|
201
|
-
const erc20TokensResponseIndex = [];
|
|
202
|
-
const ethBalanceResponseIndex = [];
|
|
203
|
-
const erc20TokensAndOwners = [];
|
|
204
|
-
const ethBalOwners = [];
|
|
205
|
-
tokensAndOwners.forEach((i, j) => {
|
|
206
|
-
if (i[0] !== nullAddress) {
|
|
207
|
-
erc20TokensAndOwners.push(i);
|
|
208
|
-
erc20TokensResponseIndex.push(j);
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
ethBalOwners.push(i[1]);
|
|
212
|
-
ethBalanceResponseIndex.push(j);
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
this.addStat('sumTokens', erc20TokensAndOwners.length + ethBalOwners.length, true);
|
|
216
|
-
const bals = await this.multiCall({
|
|
217
|
-
calls: erc20TokensAndOwners.map(([token, owner]) => ({ target: token, params: [owner] })),
|
|
218
|
-
abi: 'erc20:balanceOf',
|
|
219
|
-
permitFailure,
|
|
220
|
-
});
|
|
221
|
-
bals.forEach((i, j) => {
|
|
222
|
-
if (!i)
|
|
223
|
-
i = '0';
|
|
224
|
-
const token = erc20TokensAndOwners[j][0];
|
|
225
|
-
const responseIndex = erc20TokensResponseIndex[j];
|
|
226
|
-
tokenBalances[responseIndex] = [token, i];
|
|
227
|
-
});
|
|
228
|
-
if (ethBalOwners.length) {
|
|
229
|
-
let ethBals = (await (0, eth_1.getBalances)({ chain: this.chain, targets: ethBalOwners, block: this.block, permitFailure })).output.map((i) => i.balance);
|
|
230
|
-
ethBals.map((i, idx) => tokenBalances[ethBalanceResponseIndex[idx]] = [nullAddress, i]);
|
|
231
|
-
}
|
|
232
|
-
if (!withTokenData)
|
|
233
|
-
return tokenBalances.map(i => i[1]);
|
|
234
|
-
return tokenBalances;
|
|
235
|
-
}
|
|
236
|
-
async sumTokens({ balancesV2Options = {}, ...tokenBalanceOptions }) {
|
|
237
|
-
const tokenBalances = await this.getTokenBalances({ ...tokenBalanceOptions, skipDuplicates: true, withTokenData: true });
|
|
238
|
-
tokenBalances.forEach(([token, balance]) => this.addToken(token, balance, balancesV2Options));
|
|
239
|
-
return this.getBalances();
|
|
240
|
-
}
|
|
241
|
-
async getERC20TokenBalances(options) {
|
|
242
|
-
return this.getTokenBalances(options);
|
|
243
|
-
}
|
|
244
|
-
async getGasTokenBalance(owner, options) {
|
|
245
|
-
return (await this.getGasTokenBalances({ ...options, owner, }))[0];
|
|
246
|
-
}
|
|
247
|
-
async getGasTokenBalances(options) {
|
|
248
|
-
return this.getTokenBalances({ ...options, token: nullAddress });
|
|
249
|
-
}
|
|
250
|
-
async getEthBalance(owner, options) {
|
|
251
|
-
return this.getGasTokenBalance(owner, options !== null && options !== void 0 ? options : {});
|
|
252
|
-
}
|
|
253
|
-
async getEthBalances(options) {
|
|
254
|
-
return this.getGasTokenBalances(options);
|
|
255
|
-
}
|
|
256
|
-
async getUSDValue() {
|
|
257
|
-
return this._balances.getUSDValue();
|
|
258
|
-
}
|
|
259
|
-
async getUSDString() {
|
|
260
|
-
return this._balances.getUSDString();
|
|
261
|
-
}
|
|
262
|
-
async getUSDJSONs() {
|
|
263
|
-
return this._balances.getUSDJSONs();
|
|
264
|
-
}
|
|
265
|
-
async getLogs(params) {
|
|
266
|
-
var _a;
|
|
267
|
-
this.addStat('getLogs', ((_a = params.targets) === null || _a === void 0 ? void 0 : _a.length) || 1);
|
|
268
|
-
params.chain = this.chain;
|
|
269
|
-
return (0, logs_1.default)(params);
|
|
270
|
-
}
|
|
271
|
-
getBalancesV2() {
|
|
272
|
-
return this._balances;
|
|
273
|
-
}
|
|
274
|
-
async getTransactions(params) {
|
|
275
|
-
this.addStat('getTransactions');
|
|
276
|
-
return (0, transactions_1.getTransactions)({ ...params, chain: this.chain });
|
|
277
|
-
}
|
|
278
|
-
async getTransactionReceipt(tx) {
|
|
279
|
-
this.addStat('getTransactionReceipt');
|
|
280
|
-
return this.provider.getTransactionReceipt(tx);
|
|
281
|
-
}
|
|
282
|
-
getStats() {
|
|
283
|
-
return this.stats;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
exports.ChainApi = ChainApi;
|
|
287
|
-
exports.default = ChainApi;
|
|
288
|
-
function getUniqueTokensAndOwners(toa, chain) {
|
|
289
|
-
if (!toa.length)
|
|
290
|
-
return [];
|
|
291
|
-
const mergedToa = toa.map(i => i.join('~'));
|
|
292
|
-
const uniqueMerged = (0, common_1.getUniqueAddresses)(mergedToa, chain);
|
|
293
|
-
return uniqueMerged.map(i => i.split('~'));
|
|
294
|
-
}
|
|
295
|
-
function getDebugStats() {
|
|
296
|
-
return callStatsByProject;
|
|
297
|
-
}
|
package/build/abi/abi2.d.ts
DELETED
|
@@ -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
|
-
}
|
package/build/abi/cachedABIs.js
DELETED
|
@@ -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,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
|
-
}
|
package/build/abi/index.d.ts
DELETED
|
@@ -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 {};
|