@cryptorubic/web3 1.5.1-alpha.tron.4 → 1.5.1-alpha.tron.6
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
CHANGED
|
@@ -63,7 +63,7 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
63
63
|
tokensAddresses.splice(indexOfNativeCoin, 1);
|
|
64
64
|
promises[1] = this.getBalance(userAddress);
|
|
65
65
|
}
|
|
66
|
-
promises[0] = this.batchMulticallTokenBalance(userAddress, tokensAddresses,
|
|
66
|
+
promises[0] = this.batchMulticallTokenBalance(userAddress, tokensAddresses, 10);
|
|
67
67
|
const results = await Promise.all(promises);
|
|
68
68
|
const tokensBalances = results[0].map((tokenResults) => {
|
|
69
69
|
const { success, output } = tokenResults[0];
|
|
@@ -75,32 +75,21 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
75
75
|
return tokensBalances;
|
|
76
76
|
}
|
|
77
77
|
async batchMulticallTokenBalance(userAddress, tokensAddresses, batchSize) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
balances.push(...batchResult);
|
|
92
|
-
}
|
|
93
|
-
return balances;
|
|
78
|
+
const balances = [];
|
|
79
|
+
for (let i = 0; i < tokensAddresses.length; i += batchSize) {
|
|
80
|
+
const batchRequest = tokensAddresses.slice(i, i + batchSize);
|
|
81
|
+
const batchResult = await this.multicallContractsMethods(trc_20_contract_abi_1.TRC20_CONTRACT_ABI, batchRequest.map((tokenAddress) => ({
|
|
82
|
+
contractAddress: tokenAddress,
|
|
83
|
+
methodsData: [
|
|
84
|
+
{
|
|
85
|
+
methodName: 'balanceOf',
|
|
86
|
+
methodArguments: [userAddress]
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
})));
|
|
90
|
+
balances.push(...batchResult);
|
|
94
91
|
}
|
|
95
|
-
return
|
|
96
|
-
contractAddress: tokenAddress,
|
|
97
|
-
methodsData: [
|
|
98
|
-
{
|
|
99
|
-
methodName: 'balanceOf',
|
|
100
|
-
methodArguments: [userAddress]
|
|
101
|
-
}
|
|
102
|
-
]
|
|
103
|
-
})));
|
|
92
|
+
return balances;
|
|
104
93
|
}
|
|
105
94
|
// public async multicallContractsMethods<Output extends TronWeb3PrimitiveType>(
|
|
106
95
|
// contractAbi: any,
|
|
@@ -156,6 +145,10 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
156
145
|
let outputIndex = 0;
|
|
157
146
|
return contractsData.map((contractData) => contractData.methodsData.map((methodData) => {
|
|
158
147
|
const output = outputs[outputIndex];
|
|
148
|
+
if (!output) {
|
|
149
|
+
console.log('[multicallContractsMethods] Error index:', { outputIndex, outputs });
|
|
150
|
+
return { output: null, success: false };
|
|
151
|
+
}
|
|
159
152
|
const methodOutputAbi = contractAbi.find((funcSignature) => funcSignature.name === methodData.methodName).outputs;
|
|
160
153
|
outputIndex++;
|
|
161
154
|
return {
|
|
@@ -165,11 +158,10 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
165
158
|
}));
|
|
166
159
|
}
|
|
167
160
|
catch (err) {
|
|
168
|
-
console.log('[multicallContractsMethods] err ==>', err);
|
|
169
161
|
this.logger
|
|
170
162
|
? this.logger.customError('[TronAdapter_multicallContractsMethods] Error: ', err)
|
|
171
163
|
: console.debug('[TronAdapter_multicallContractsMethods] Error:', err);
|
|
172
|
-
return
|
|
164
|
+
return contractsData.map((contractData) => contractData.methodsData.map(() => ({ output: null, success: false })));
|
|
173
165
|
}
|
|
174
166
|
}
|
|
175
167
|
async getBlockNumber() {
|
|
@@ -54,239 +54,3 @@ exports.TRON_MULTICALL_ABI = [
|
|
|
54
54
|
type: 'function'
|
|
55
55
|
}
|
|
56
56
|
];
|
|
57
|
-
[
|
|
58
|
-
{
|
|
59
|
-
inputs: [
|
|
60
|
-
{
|
|
61
|
-
components: [
|
|
62
|
-
{ internalType: 'address', name: 'target', type: 'address' },
|
|
63
|
-
{ internalType: 'bytes', name: 'callData', type: 'bytes' }
|
|
64
|
-
],
|
|
65
|
-
internalType: 'struct Multicall3.Call[]',
|
|
66
|
-
name: 'calls',
|
|
67
|
-
type: 'tuple[]'
|
|
68
|
-
}
|
|
69
|
-
],
|
|
70
|
-
name: 'aggregate',
|
|
71
|
-
outputs: [
|
|
72
|
-
{ internalType: 'uint256', name: 'blockNumber', type: 'uint256' },
|
|
73
|
-
{ internalType: 'bytes[]', name: 'returnData', type: 'bytes[]' }
|
|
74
|
-
],
|
|
75
|
-
stateMutability: 'payable',
|
|
76
|
-
type: 'function'
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
inputs: [
|
|
80
|
-
{
|
|
81
|
-
components: [
|
|
82
|
-
{ internalType: 'address', name: 'target', type: 'address' },
|
|
83
|
-
{ internalType: 'bool', name: 'allowFailure', type: 'bool' },
|
|
84
|
-
{ internalType: 'bytes', name: 'callData', type: 'bytes' }
|
|
85
|
-
],
|
|
86
|
-
internalType: 'struct Multicall3.Call3[]',
|
|
87
|
-
name: 'calls',
|
|
88
|
-
type: 'tuple[]'
|
|
89
|
-
}
|
|
90
|
-
],
|
|
91
|
-
name: 'aggregate3',
|
|
92
|
-
outputs: [
|
|
93
|
-
{
|
|
94
|
-
components: [
|
|
95
|
-
{ internalType: 'bool', name: 'success', type: 'bool' },
|
|
96
|
-
{ internalType: 'bytes', name: 'returnData', type: 'bytes' }
|
|
97
|
-
],
|
|
98
|
-
internalType: 'struct Multicall3.Result[]',
|
|
99
|
-
name: 'returnData',
|
|
100
|
-
type: 'tuple[]'
|
|
101
|
-
}
|
|
102
|
-
],
|
|
103
|
-
stateMutability: 'payable',
|
|
104
|
-
type: 'function'
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
inputs: [
|
|
108
|
-
{
|
|
109
|
-
components: [
|
|
110
|
-
{ internalType: 'address', name: 'target', type: 'address' },
|
|
111
|
-
{ internalType: 'bool', name: 'allowFailure', type: 'bool' },
|
|
112
|
-
{ internalType: 'uint256', name: 'value', type: 'uint256' },
|
|
113
|
-
{ internalType: 'bytes', name: 'callData', type: 'bytes' }
|
|
114
|
-
],
|
|
115
|
-
internalType: 'struct Multicall3.Call3Value[]',
|
|
116
|
-
name: 'calls',
|
|
117
|
-
type: 'tuple[]'
|
|
118
|
-
}
|
|
119
|
-
],
|
|
120
|
-
name: 'aggregate3Value',
|
|
121
|
-
outputs: [
|
|
122
|
-
{
|
|
123
|
-
components: [
|
|
124
|
-
{ internalType: 'bool', name: 'success', type: 'bool' },
|
|
125
|
-
{ internalType: 'bytes', name: 'returnData', type: 'bytes' }
|
|
126
|
-
],
|
|
127
|
-
internalType: 'struct Multicall3.Result[]',
|
|
128
|
-
name: 'returnData',
|
|
129
|
-
type: 'tuple[]'
|
|
130
|
-
}
|
|
131
|
-
],
|
|
132
|
-
stateMutability: 'payable',
|
|
133
|
-
type: 'function'
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
inputs: [
|
|
137
|
-
{
|
|
138
|
-
components: [
|
|
139
|
-
{ internalType: 'address', name: 'target', type: 'address' },
|
|
140
|
-
{ internalType: 'bytes', name: 'callData', type: 'bytes' }
|
|
141
|
-
],
|
|
142
|
-
internalType: 'struct Multicall3.Call[]',
|
|
143
|
-
name: 'calls',
|
|
144
|
-
type: 'tuple[]'
|
|
145
|
-
}
|
|
146
|
-
],
|
|
147
|
-
name: 'blockAndAggregate',
|
|
148
|
-
outputs: [
|
|
149
|
-
{ internalType: 'uint256', name: 'blockNumber', type: 'uint256' },
|
|
150
|
-
{ internalType: 'bytes32', name: 'blockHash', type: 'bytes32' },
|
|
151
|
-
{
|
|
152
|
-
components: [
|
|
153
|
-
{ internalType: 'bool', name: 'success', type: 'bool' },
|
|
154
|
-
{ internalType: 'bytes', name: 'returnData', type: 'bytes' }
|
|
155
|
-
],
|
|
156
|
-
internalType: 'struct Multicall3.Result[]',
|
|
157
|
-
name: 'returnData',
|
|
158
|
-
type: 'tuple[]'
|
|
159
|
-
}
|
|
160
|
-
],
|
|
161
|
-
stateMutability: 'payable',
|
|
162
|
-
type: 'function'
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
inputs: [],
|
|
166
|
-
name: 'getBasefee',
|
|
167
|
-
outputs: [{ internalType: 'uint256', name: 'basefee', type: 'uint256' }],
|
|
168
|
-
stateMutability: 'view',
|
|
169
|
-
type: 'function'
|
|
170
|
-
},
|
|
171
|
-
{
|
|
172
|
-
inputs: [{ internalType: 'uint256', name: 'blockNumber', type: 'uint256' }],
|
|
173
|
-
name: 'getBlockHash',
|
|
174
|
-
outputs: [{ internalType: 'bytes32', name: 'blockHash', type: 'bytes32' }],
|
|
175
|
-
stateMutability: 'view',
|
|
176
|
-
type: 'function'
|
|
177
|
-
},
|
|
178
|
-
{
|
|
179
|
-
inputs: [],
|
|
180
|
-
name: 'getBlockNumber',
|
|
181
|
-
outputs: [{ internalType: 'uint256', name: 'blockNumber', type: 'uint256' }],
|
|
182
|
-
stateMutability: 'view',
|
|
183
|
-
type: 'function'
|
|
184
|
-
},
|
|
185
|
-
{
|
|
186
|
-
inputs: [],
|
|
187
|
-
name: 'getChainId',
|
|
188
|
-
outputs: [{ internalType: 'uint256', name: 'chainid', type: 'uint256' }],
|
|
189
|
-
stateMutability: 'view',
|
|
190
|
-
type: 'function'
|
|
191
|
-
},
|
|
192
|
-
{
|
|
193
|
-
inputs: [],
|
|
194
|
-
name: 'getCurrentBlockCoinbase',
|
|
195
|
-
outputs: [{ internalType: 'address', name: 'coinbase', type: 'address' }],
|
|
196
|
-
stateMutability: 'view',
|
|
197
|
-
type: 'function'
|
|
198
|
-
},
|
|
199
|
-
{
|
|
200
|
-
inputs: [],
|
|
201
|
-
name: 'getCurrentBlockDifficulty',
|
|
202
|
-
outputs: [{ internalType: 'uint256', name: 'difficulty', type: 'uint256' }],
|
|
203
|
-
stateMutability: 'view',
|
|
204
|
-
type: 'function'
|
|
205
|
-
},
|
|
206
|
-
{
|
|
207
|
-
inputs: [],
|
|
208
|
-
name: 'getCurrentBlockGasLimit',
|
|
209
|
-
outputs: [{ internalType: 'uint256', name: 'gaslimit', type: 'uint256' }],
|
|
210
|
-
stateMutability: 'view',
|
|
211
|
-
type: 'function'
|
|
212
|
-
},
|
|
213
|
-
{
|
|
214
|
-
inputs: [],
|
|
215
|
-
name: 'getCurrentBlockTimestamp',
|
|
216
|
-
outputs: [{ internalType: 'uint256', name: 'timestamp', type: 'uint256' }],
|
|
217
|
-
stateMutability: 'view',
|
|
218
|
-
type: 'function'
|
|
219
|
-
},
|
|
220
|
-
{
|
|
221
|
-
inputs: [{ internalType: 'address', name: 'addr', type: 'address' }],
|
|
222
|
-
name: 'getEthBalance',
|
|
223
|
-
outputs: [{ internalType: 'uint256', name: 'balance', type: 'uint256' }],
|
|
224
|
-
stateMutability: 'view',
|
|
225
|
-
type: 'function'
|
|
226
|
-
},
|
|
227
|
-
{
|
|
228
|
-
inputs: [],
|
|
229
|
-
name: 'getLastBlockHash',
|
|
230
|
-
outputs: [{ internalType: 'bytes32', name: 'blockHash', type: 'bytes32' }],
|
|
231
|
-
stateMutability: 'view',
|
|
232
|
-
type: 'function'
|
|
233
|
-
},
|
|
234
|
-
{
|
|
235
|
-
inputs: [
|
|
236
|
-
{ internalType: 'bool', name: 'requireSuccess', type: 'bool' },
|
|
237
|
-
{
|
|
238
|
-
components: [
|
|
239
|
-
{ internalType: 'address', name: 'target', type: 'address' },
|
|
240
|
-
{ internalType: 'bytes', name: 'callData', type: 'bytes' }
|
|
241
|
-
],
|
|
242
|
-
internalType: 'struct Multicall3.Call[]',
|
|
243
|
-
name: 'calls',
|
|
244
|
-
type: 'tuple[]'
|
|
245
|
-
}
|
|
246
|
-
],
|
|
247
|
-
name: 'tryAggregate',
|
|
248
|
-
outputs: [
|
|
249
|
-
{
|
|
250
|
-
components: [
|
|
251
|
-
{ internalType: 'bool', name: 'success', type: 'bool' },
|
|
252
|
-
{ internalType: 'bytes', name: 'returnData', type: 'bytes' }
|
|
253
|
-
],
|
|
254
|
-
internalType: 'struct Multicall3.Result[]',
|
|
255
|
-
name: 'returnData',
|
|
256
|
-
type: 'tuple[]'
|
|
257
|
-
}
|
|
258
|
-
],
|
|
259
|
-
stateMutability: 'payable',
|
|
260
|
-
type: 'function'
|
|
261
|
-
},
|
|
262
|
-
{
|
|
263
|
-
inputs: [
|
|
264
|
-
{ internalType: 'bool', name: 'requireSuccess', type: 'bool' },
|
|
265
|
-
{
|
|
266
|
-
components: [
|
|
267
|
-
{ internalType: 'address', name: 'target', type: 'address' },
|
|
268
|
-
{ internalType: 'bytes', name: 'callData', type: 'bytes' }
|
|
269
|
-
],
|
|
270
|
-
internalType: 'struct Multicall3.Call[]',
|
|
271
|
-
name: 'calls',
|
|
272
|
-
type: 'tuple[]'
|
|
273
|
-
}
|
|
274
|
-
],
|
|
275
|
-
name: 'tryBlockAndAggregate',
|
|
276
|
-
outputs: [
|
|
277
|
-
{ internalType: 'uint256', name: 'blockNumber', type: 'uint256' },
|
|
278
|
-
{ internalType: 'bytes32', name: 'blockHash', type: 'bytes32' },
|
|
279
|
-
{
|
|
280
|
-
components: [
|
|
281
|
-
{ internalType: 'bool', name: 'success', type: 'bool' },
|
|
282
|
-
{ internalType: 'bytes', name: 'returnData', type: 'bytes' }
|
|
283
|
-
],
|
|
284
|
-
internalType: 'struct Multicall3.Result[]',
|
|
285
|
-
name: 'returnData',
|
|
286
|
-
type: 'tuple[]'
|
|
287
|
-
}
|
|
288
|
-
],
|
|
289
|
-
stateMutability: 'payable',
|
|
290
|
-
type: 'function'
|
|
291
|
-
}
|
|
292
|
-
];
|