@cryptorubic/web3 1.5.1-alpha.tron.1 → 1.5.1-alpha.tron.2
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
|
@@ -21,7 +21,8 @@ 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
|
-
|
|
24
|
+
// private readonly multicallAddress = 'T9ziQU4EBteJzjzMzhHELdhgWFqwzS5Vki';
|
|
25
|
+
this.multicallAddress = 'TEazPvZwDjDtFeJupyo7QunvnrnUjPH8ED';
|
|
25
26
|
this.signer = new tron_adapter_signer_1.TronAdapterSigner(this.publicRef, httpClient, logger, clientParams);
|
|
26
27
|
}
|
|
27
28
|
initWeb3Client() {
|
|
@@ -101,32 +102,70 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
101
102
|
]
|
|
102
103
|
})));
|
|
103
104
|
}
|
|
105
|
+
// public async multicallContractsMethods<Output extends TronWeb3PrimitiveType>(
|
|
106
|
+
// contractAbi: any,
|
|
107
|
+
// contractsData: {
|
|
108
|
+
// contractAddress: string;
|
|
109
|
+
// methodsData: MethodData[];
|
|
110
|
+
// }[]
|
|
111
|
+
// ): Promise<ContractMulticallResponse<any>[][]> {
|
|
112
|
+
// const calls: TronCall[][] = contractsData.map(({ contractAddress, methodsData }) => {
|
|
113
|
+
// return methodsData.map(({ methodName, methodArguments }) => [
|
|
114
|
+
// contractAddress,
|
|
115
|
+
// TronWeb3Pure.encodeFunctionCall(contractAbi as any, methodName, methodArguments)
|
|
116
|
+
// ]);
|
|
117
|
+
// });
|
|
118
|
+
// try {
|
|
119
|
+
// const outputs = await this.multicall(calls.flat());
|
|
120
|
+
// let outputIndex = 0;
|
|
121
|
+
// return contractsData.map((contractData) =>
|
|
122
|
+
// contractData.methodsData.map((methodData) => {
|
|
123
|
+
// const success = outputs.results[outputIndex]!;
|
|
124
|
+
// const returnData = outputs.returnData[outputIndex]!;
|
|
125
|
+
// outputIndex++;
|
|
126
|
+
// const methodOutputAbi = contractAbi.find(
|
|
127
|
+
// // @ts-ignore
|
|
128
|
+
// (funcSignature) => funcSignature.name === methodData.methodName
|
|
129
|
+
// // @ts-ignore
|
|
130
|
+
// )!.outputs!;
|
|
131
|
+
// return {
|
|
132
|
+
// output: success ? (TronWeb3Pure.decodeMethodOutput(methodOutputAbi, returnData) as Output) : null,
|
|
133
|
+
// success
|
|
134
|
+
// };
|
|
135
|
+
// })
|
|
136
|
+
// );
|
|
137
|
+
// } catch (err) {
|
|
138
|
+
// this.logger
|
|
139
|
+
// ? this.logger.customError('[TronAdapter_multicallContractsMethods] Error: ', err)
|
|
140
|
+
// : console.debug('[TronAdapter_multicallContractsMethods] Error:', err);
|
|
141
|
+
// return this.multicallContractsMethodsByOne(contractAbi, contractsData);
|
|
142
|
+
// }
|
|
143
|
+
// }
|
|
104
144
|
async multicallContractsMethods(contractAbi, contractsData) {
|
|
105
145
|
const calls = contractsData.map(({ contractAddress, methodsData }) => {
|
|
106
|
-
return methodsData.map(({ methodName, methodArguments }) =>
|
|
107
|
-
contractAddress,
|
|
108
|
-
|
|
109
|
-
|
|
146
|
+
return methodsData.map(({ methodName, methodArguments }) => ({
|
|
147
|
+
target: contractAddress,
|
|
148
|
+
allowFailure: true,
|
|
149
|
+
callData: tron_web3_pure_1.TronWeb3Pure.encodeFunctionCall(contractAbi, methodName, methodArguments)
|
|
150
|
+
}));
|
|
110
151
|
});
|
|
152
|
+
console.log('[multicallContractsMethods] calls ==>', calls);
|
|
111
153
|
try {
|
|
112
154
|
const outputs = await this.multicall(calls.flat());
|
|
155
|
+
console.log('[multicallContractsMethods] outputs ==>', outputs);
|
|
113
156
|
let outputIndex = 0;
|
|
114
157
|
return contractsData.map((contractData) => contractData.methodsData.map((methodData) => {
|
|
115
|
-
const
|
|
116
|
-
const
|
|
158
|
+
const output = outputs[outputIndex];
|
|
159
|
+
const methodOutputAbi = contractAbi.find((funcSignature) => funcSignature.name === methodData.methodName).outputs;
|
|
117
160
|
outputIndex++;
|
|
118
|
-
const methodOutputAbi = contractAbi.find(
|
|
119
|
-
// @ts-ignore
|
|
120
|
-
(funcSignature) => funcSignature.name === methodData.methodName
|
|
121
|
-
// @ts-ignore
|
|
122
|
-
).outputs;
|
|
123
161
|
return {
|
|
124
|
-
output: success ? tron_web3_pure_1.TronWeb3Pure.decodeMethodOutput(methodOutputAbi, returnData) : null,
|
|
125
|
-
success
|
|
162
|
+
output: output.success ? tron_web3_pure_1.TronWeb3Pure.decodeMethodOutput(methodOutputAbi, output.returnData) : null,
|
|
163
|
+
success: output.success
|
|
126
164
|
};
|
|
127
165
|
}));
|
|
128
166
|
}
|
|
129
167
|
catch (err) {
|
|
168
|
+
console.log('[multicallContractsMethods] err ==>', err);
|
|
130
169
|
this.logger
|
|
131
170
|
? this.logger.customError('[TronAdapter_multicallContractsMethods] Error: ', err)
|
|
132
171
|
: console.debug('[TronAdapter_multicallContractsMethods] Error:', err);
|
|
@@ -140,11 +179,17 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
140
179
|
const balance = await this.getBalance(walletAddress, token.address);
|
|
141
180
|
return balance.gte(token.weiAmount);
|
|
142
181
|
}
|
|
182
|
+
// private async multicall(calls: TronCall[]): Promise<TronMulticallResponse> {
|
|
183
|
+
// this.public.setAddress(this.multicallAddress);
|
|
184
|
+
// const contract = await this.public.contract(TRON_MULTICALL_ABI as any, this.multicallAddress);
|
|
185
|
+
// // @ts-ignore
|
|
186
|
+
// return contract.aggregateViewCalls(calls).call();
|
|
187
|
+
// }
|
|
143
188
|
async multicall(calls) {
|
|
144
189
|
this.public.setAddress(this.multicallAddress);
|
|
145
190
|
const contract = await this.public.contract(tron_multicall_abi_1.TRON_MULTICALL_ABI, this.multicallAddress);
|
|
146
191
|
// @ts-ignore
|
|
147
|
-
return contract
|
|
192
|
+
return contract['aggregate3'](calls).call();
|
|
148
193
|
}
|
|
149
194
|
multicallContractsMethodsByOne(contractAbi, contractsData) {
|
|
150
195
|
return Promise.all(contractsData.map((contractData) => {
|
|
@@ -1,26 +1,56 @@
|
|
|
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[];
|
|
4
27
|
exports.TRON_MULTICALL_ABI = [
|
|
5
28
|
{
|
|
6
29
|
inputs: [
|
|
7
30
|
{
|
|
8
31
|
components: [
|
|
9
32
|
{ internalType: 'address', name: 'target', type: 'address' },
|
|
33
|
+
{ internalType: 'bool', name: 'allowFailure', type: 'bool' },
|
|
10
34
|
{ internalType: 'bytes', name: 'callData', type: 'bytes' }
|
|
11
35
|
],
|
|
12
|
-
internalType: 'struct
|
|
36
|
+
internalType: 'struct Multicall3.Call3[]',
|
|
13
37
|
name: 'calls',
|
|
14
38
|
type: 'tuple[]'
|
|
15
39
|
}
|
|
16
40
|
],
|
|
17
|
-
name: '
|
|
41
|
+
name: 'aggregate3',
|
|
18
42
|
outputs: [
|
|
19
|
-
{
|
|
20
|
-
|
|
21
|
-
|
|
43
|
+
{
|
|
44
|
+
components: [
|
|
45
|
+
{ internalType: 'bool', name: 'success', type: 'bool' },
|
|
46
|
+
{ internalType: 'bytes', name: 'returnData', type: 'bytes' }
|
|
47
|
+
],
|
|
48
|
+
internalType: 'struct Multicall3.Result[]',
|
|
49
|
+
name: 'returnData',
|
|
50
|
+
type: 'tuple[]'
|
|
51
|
+
}
|
|
22
52
|
],
|
|
23
|
-
stateMutability: '
|
|
53
|
+
stateMutability: 'payable',
|
|
24
54
|
type: 'function'
|
|
25
55
|
}
|
|
26
56
|
];
|
|
@@ -3,3 +3,21 @@
|
|
|
3
3
|
* Second argument is `data`, that is encoded contract method.
|
|
4
4
|
*/
|
|
5
5
|
export type TronCall = [string, string];
|
|
6
|
+
export type TronCall3Request = {
|
|
7
|
+
/**
|
|
8
|
+
* that is contract address to execute on
|
|
9
|
+
*/
|
|
10
|
+
target: string;
|
|
11
|
+
/**
|
|
12
|
+
* If false, the entire call will revert if the call fails.
|
|
13
|
+
*/
|
|
14
|
+
allowFailure: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Data to call on the target contract
|
|
17
|
+
*/
|
|
18
|
+
callData: string;
|
|
19
|
+
};
|
|
20
|
+
export type TronCall3Result = {
|
|
21
|
+
success: boolean;
|
|
22
|
+
returnData: string;
|
|
23
|
+
};
|