@cryptorubic/web3 1.0.0-alpha.no-sdk.40 → 1.0.0-alpha.no-sdk.42
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
|
@@ -25,7 +25,7 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
25
25
|
}
|
|
26
26
|
initWeb3Client() {
|
|
27
27
|
const rpc = typeof this.rpcList[0] === 'string' ? this.rpcList[0] : this.rpcList[0].fullHost;
|
|
28
|
-
this.public = new tronweb_1.TronWeb({ fullHost: rpc });
|
|
28
|
+
this.public = new tronweb_1.TronWeb({ fullHost: rpc, headers: { 'TRON-PRO-API-KEY': '' } });
|
|
29
29
|
}
|
|
30
30
|
async callContractMethod(contractAddress, contractAbi, methodName, methodArguments = []) {
|
|
31
31
|
this.public.setAddress(contractAddress);
|
|
@@ -57,7 +57,7 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
57
57
|
tokensAddresses.splice(indexOfNativeCoin, 1);
|
|
58
58
|
promises[1] = this.getBalance(userAddress);
|
|
59
59
|
}
|
|
60
|
-
promises[0] = this.batchMulticallTokenBalance(userAddress, tokensAddresses,
|
|
60
|
+
promises[0] = this.batchMulticallTokenBalance(userAddress, tokensAddresses, 10);
|
|
61
61
|
const results = await Promise.all(promises);
|
|
62
62
|
const tokensBalances = results[0].map((tokenResults) => {
|
|
63
63
|
const { success, output } = tokenResults[0];
|
|
@@ -69,32 +69,32 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
69
69
|
return tokensBalances;
|
|
70
70
|
}
|
|
71
71
|
async batchMulticallTokenBalance(userAddress, tokensAddresses, batchSize) {
|
|
72
|
-
if (tokensAddresses.length
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
methodsData: [
|
|
89
|
-
{
|
|
90
|
-
methodName: 'balanceOf',
|
|
91
|
-
methodArguments: [userAddress]
|
|
92
|
-
}
|
|
93
|
-
]
|
|
94
|
-
})));
|
|
95
|
-
balances.push(...batchResult);
|
|
72
|
+
if (tokensAddresses.length > 100) {
|
|
73
|
+
const balances = [];
|
|
74
|
+
for (let i = 0; i < tokensAddresses.length; i += batchSize) {
|
|
75
|
+
const batchRequest = tokensAddresses.slice(i, i + batchSize);
|
|
76
|
+
const batchResult = await this.multicallContractsMethods(trc_20_contract_abi_1.TRC20_CONTRACT_ABI, batchRequest.map((tokenAddress) => ({
|
|
77
|
+
contractAddress: tokenAddress,
|
|
78
|
+
methodsData: [
|
|
79
|
+
{
|
|
80
|
+
methodName: 'balanceOf',
|
|
81
|
+
methodArguments: [userAddress]
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
})));
|
|
85
|
+
balances.push(...batchResult);
|
|
86
|
+
}
|
|
87
|
+
return balances;
|
|
96
88
|
}
|
|
97
|
-
return
|
|
89
|
+
return this.multicallContractsMethods(trc_20_contract_abi_1.TRC20_CONTRACT_ABI, tokensAddresses.map((tokenAddress) => ({
|
|
90
|
+
contractAddress: tokenAddress,
|
|
91
|
+
methodsData: [
|
|
92
|
+
{
|
|
93
|
+
methodName: 'balanceOf',
|
|
94
|
+
methodArguments: [userAddress]
|
|
95
|
+
}
|
|
96
|
+
]
|
|
97
|
+
})));
|
|
98
98
|
}
|
|
99
99
|
async multicallContractsMethods(contractAbi, contractsData) {
|
|
100
100
|
const calls = contractsData.map(({ contractAddress, methodsData }) => {
|
|
@@ -125,7 +125,8 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
125
125
|
this.logger
|
|
126
126
|
? this.logger.customError('[TronAdapter_multicallContractsMethods] Error: ', err)
|
|
127
127
|
: console.debug('[TronAdapter_multicallContractsMethods] Error:', err);
|
|
128
|
-
|
|
128
|
+
throw new Error('[TronAdapter_multicallContractsMethods]' + err.toString());
|
|
129
|
+
// return this.multicallContractsMethodsByOne(contractAbi, contractsData);
|
|
129
130
|
}
|
|
130
131
|
}
|
|
131
132
|
async getBlockNumber() {
|