@cryptorubic/web3 1.5.1-alpha.tron.6 → 1.5.1-alpha.tron.8
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
|
@@ -43,7 +43,6 @@ export declare class TronAdapter extends AbstractAdapter<TronWeb, TronWeb, TronB
|
|
|
43
43
|
}>;
|
|
44
44
|
checkEnoughBalance(token: TokenAmount | PriceTokenAmount, walletAddress: string): Promise<boolean>;
|
|
45
45
|
private multicall;
|
|
46
|
-
private multicallContractsMethodsByOne;
|
|
47
46
|
callForTokensInfo(tokenAddresses: string[] | ReadonlyArray<string>): Promise<Token[]>;
|
|
48
47
|
getBalance(userAddress: string, tokenAddress?: string): Promise<BigNumber>;
|
|
49
48
|
getTokenBalance(userAddress: string, tokenAddress: string): Promise<BigNumber>;
|
|
@@ -21,7 +21,6 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
21
21
|
super(core_1.BLOCKCHAIN_NAME.TRON, logger);
|
|
22
22
|
this.rpcList = rpcList;
|
|
23
23
|
this.clientParams = clientParams;
|
|
24
|
-
// private readonly multicallAddress = 'T9ziQU4EBteJzjzMzhHELdhgWFqwzS5Vki';
|
|
25
24
|
this.multicallAddress = 'TEazPvZwDjDtFeJupyo7QunvnrnUjPH8ED';
|
|
26
25
|
this.signer = new tron_adapter_signer_1.TronAdapterSigner(this.publicRef, httpClient, logger, clientParams);
|
|
27
26
|
}
|
|
@@ -63,7 +62,7 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
63
62
|
tokensAddresses.splice(indexOfNativeCoin, 1);
|
|
64
63
|
promises[1] = this.getBalance(userAddress);
|
|
65
64
|
}
|
|
66
|
-
promises[0] = this.batchMulticallTokenBalance(userAddress, tokensAddresses,
|
|
65
|
+
promises[0] = this.batchMulticallTokenBalance(userAddress, tokensAddresses, 20);
|
|
67
66
|
const results = await Promise.all(promises);
|
|
68
67
|
const tokensBalances = results[0].map((tokenResults) => {
|
|
69
68
|
const { success, output } = tokenResults[0];
|
|
@@ -91,45 +90,6 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
91
90
|
}
|
|
92
91
|
return balances;
|
|
93
92
|
}
|
|
94
|
-
// public async multicallContractsMethods<Output extends TronWeb3PrimitiveType>(
|
|
95
|
-
// contractAbi: any,
|
|
96
|
-
// contractsData: {
|
|
97
|
-
// contractAddress: string;
|
|
98
|
-
// methodsData: MethodData[];
|
|
99
|
-
// }[]
|
|
100
|
-
// ): Promise<ContractMulticallResponse<any>[][]> {
|
|
101
|
-
// const calls: TronCall[][] = contractsData.map(({ contractAddress, methodsData }) => {
|
|
102
|
-
// return methodsData.map(({ methodName, methodArguments }) => [
|
|
103
|
-
// contractAddress,
|
|
104
|
-
// TronWeb3Pure.encodeFunctionCall(contractAbi as any, methodName, methodArguments)
|
|
105
|
-
// ]);
|
|
106
|
-
// });
|
|
107
|
-
// try {
|
|
108
|
-
// const outputs = await this.multicall(calls.flat());
|
|
109
|
-
// let outputIndex = 0;
|
|
110
|
-
// return contractsData.map((contractData) =>
|
|
111
|
-
// contractData.methodsData.map((methodData) => {
|
|
112
|
-
// const success = outputs.results[outputIndex]!;
|
|
113
|
-
// const returnData = outputs.returnData[outputIndex]!;
|
|
114
|
-
// outputIndex++;
|
|
115
|
-
// const methodOutputAbi = contractAbi.find(
|
|
116
|
-
// // @ts-ignore
|
|
117
|
-
// (funcSignature) => funcSignature.name === methodData.methodName
|
|
118
|
-
// // @ts-ignore
|
|
119
|
-
// )!.outputs!;
|
|
120
|
-
// return {
|
|
121
|
-
// output: success ? (TronWeb3Pure.decodeMethodOutput(methodOutputAbi, returnData) as Output) : null,
|
|
122
|
-
// success
|
|
123
|
-
// };
|
|
124
|
-
// })
|
|
125
|
-
// );
|
|
126
|
-
// } catch (err) {
|
|
127
|
-
// this.logger
|
|
128
|
-
// ? this.logger.customError('[TronAdapter_multicallContractsMethods] Error: ', err)
|
|
129
|
-
// : console.debug('[TronAdapter_multicallContractsMethods] Error:', err);
|
|
130
|
-
// return this.multicallContractsMethodsByOne(contractAbi, contractsData);
|
|
131
|
-
// }
|
|
132
|
-
// }
|
|
133
93
|
async multicallContractsMethods(contractAbi, contractsData) {
|
|
134
94
|
const calls = contractsData.map(({ contractAddress, methodsData }) => {
|
|
135
95
|
return methodsData.map(({ methodName, methodArguments }) => [
|
|
@@ -138,17 +98,13 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
138
98
|
tron_web3_pure_1.TronWeb3Pure.encodeFunctionCall(contractAbi, methodName, methodArguments)
|
|
139
99
|
]);
|
|
140
100
|
});
|
|
141
|
-
console.log('[multicallContractsMethods] calls ==>', calls);
|
|
142
101
|
try {
|
|
143
102
|
const outputs = await this.multicall(calls.flat());
|
|
144
|
-
console.log('[multicallContractsMethods] outputs ==>', outputs);
|
|
145
103
|
let outputIndex = 0;
|
|
146
104
|
return contractsData.map((contractData) => contractData.methodsData.map((methodData) => {
|
|
147
|
-
const output = outputs[outputIndex];
|
|
148
|
-
if (!output)
|
|
149
|
-
console.log('[multicallContractsMethods] Error index:', { outputIndex, outputs });
|
|
105
|
+
const output = outputs.returnData[outputIndex];
|
|
106
|
+
if (!output)
|
|
150
107
|
return { output: null, success: false };
|
|
151
|
-
}
|
|
152
108
|
const methodOutputAbi = contractAbi.find((funcSignature) => funcSignature.name === methodData.methodName).outputs;
|
|
153
109
|
outputIndex++;
|
|
154
110
|
return {
|
|
@@ -171,37 +127,12 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
171
127
|
const balance = await this.getBalance(walletAddress, token.address);
|
|
172
128
|
return balance.gte(token.weiAmount);
|
|
173
129
|
}
|
|
174
|
-
// private async multicall(calls: TronCall[]): Promise<TronMulticallResponse> {
|
|
175
|
-
// this.public.setAddress(this.multicallAddress);
|
|
176
|
-
// const contract = await this.public.contract(TRON_MULTICALL_ABI as any, this.multicallAddress);
|
|
177
|
-
// // @ts-ignore
|
|
178
|
-
// return contract.aggregateViewCalls(calls).call();
|
|
179
|
-
// }
|
|
180
130
|
async multicall(calls) {
|
|
181
131
|
this.public.setAddress(this.multicallAddress);
|
|
182
132
|
const contract = await this.public.contract(tron_multicall_abi_1.TRON_MULTICALL_ABI, this.multicallAddress);
|
|
183
133
|
// @ts-ignore
|
|
184
134
|
return contract['aggregate3'](calls).call();
|
|
185
135
|
}
|
|
186
|
-
multicallContractsMethodsByOne(contractAbi, contractsData) {
|
|
187
|
-
return Promise.all(contractsData.map((contractData) => {
|
|
188
|
-
return Promise.all(contractData.methodsData.map(async (methodData) => {
|
|
189
|
-
try {
|
|
190
|
-
const output = (await this.read(contractData.contractAddress, contractAbi, methodData.methodName, methodData.methodArguments));
|
|
191
|
-
return {
|
|
192
|
-
output,
|
|
193
|
-
success: true
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
catch {
|
|
197
|
-
return {
|
|
198
|
-
output: null,
|
|
199
|
-
success: false
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
}));
|
|
203
|
-
}));
|
|
204
|
-
}
|
|
205
136
|
async callForTokensInfo(tokenAddresses) {
|
|
206
137
|
const tokenFields = ['decimals', 'symbol', 'name'];
|
|
207
138
|
const nativeTokenIndex = tokenAddresses.findIndex((address) => web3_pure_1.Web3Pure.isNativeAddress(core_1.CHAIN_TYPE.TRON, address));
|
|
@@ -1,29 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TRON_MULTICALL_ABI = void 0;
|
|
4
|
-
// export const TRON_MULTICALL_ABI = [
|
|
5
|
-
// {
|
|
6
|
-
// inputs: [
|
|
7
|
-
// {
|
|
8
|
-
// components: [
|
|
9
|
-
// { internalType: 'address', name: 'target', type: 'address' },
|
|
10
|
-
// { internalType: 'bytes', name: 'callData', type: 'bytes' }
|
|
11
|
-
// ],
|
|
12
|
-
// internalType: 'struct Multicall.Call[]',
|
|
13
|
-
// name: 'calls',
|
|
14
|
-
// type: 'tuple[]'
|
|
15
|
-
// }
|
|
16
|
-
// ],
|
|
17
|
-
// name: 'aggregateViewCalls',
|
|
18
|
-
// outputs: [
|
|
19
|
-
// { internalType: 'uint256', name: 'blockNumber', type: 'uint256' },
|
|
20
|
-
// { internalType: 'bytes[]', name: 'returnData', type: 'bytes[]' },
|
|
21
|
-
// { internalType: 'bool[]', name: 'results', type: 'bool[]' }
|
|
22
|
-
// ],
|
|
23
|
-
// stateMutability: 'view',
|
|
24
|
-
// type: 'function'
|
|
25
|
-
// }
|
|
26
|
-
// ] as AbiItem[];
|
|
27
4
|
exports.TRON_MULTICALL_ABI = [
|
|
28
5
|
{
|
|
29
6
|
inputs: [
|