@cryptorubic/web3 1.5.1-alpha.tron.7 → 1.5.1-alpha.tron.9
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 +1 -1
- package/src/lib/adapter/adapters/adapter-tron/tron-adapter.d.ts +0 -1
- package/src/lib/adapter/adapters/adapter-tron/tron-adapter.js +5 -73
- package/src/lib/adapter/adapters/constants/tron-multicall-abi.js +0 -23
- package/src/lib/adapter/models/create-factory-params.d.ts +3 -1
- package/src/lib/utils/models/tron-call.d.ts +0 -5
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,16 +21,16 @@ 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
|
}
|
|
28
27
|
initWeb3Client() {
|
|
29
28
|
const rpc = typeof this.rpcList[0] === 'string' ? this.rpcList[0] : this.rpcList[0].fullHost;
|
|
30
|
-
const
|
|
29
|
+
const headers = this.clientParams?.tronwebHeaders;
|
|
31
30
|
this.public = new tronweb_1.TronWeb({
|
|
32
31
|
fullHost: rpc,
|
|
33
|
-
|
|
32
|
+
...(headers && { headers })
|
|
33
|
+
// headers: { ...(tronApiKey && { 'TRON-PRO-API-KEY': tronApiKey }) }
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
36
|
async callContractMethod(contractAddress, contractAbi, methodName, methodArguments = []) {
|
|
@@ -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, 20);
|
|
67
67
|
const results = await Promise.all(promises);
|
|
68
68
|
const tokensBalances = results[0].map((tokenResults) => {
|
|
69
69
|
const { success, output } = tokenResults[0];
|
|
@@ -91,45 +91,6 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
91
91
|
}
|
|
92
92
|
return balances;
|
|
93
93
|
}
|
|
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
94
|
async multicallContractsMethods(contractAbi, contractsData) {
|
|
134
95
|
const calls = contractsData.map(({ contractAddress, methodsData }) => {
|
|
135
96
|
return methodsData.map(({ methodName, methodArguments }) => [
|
|
@@ -138,17 +99,13 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
138
99
|
tron_web3_pure_1.TronWeb3Pure.encodeFunctionCall(contractAbi, methodName, methodArguments)
|
|
139
100
|
]);
|
|
140
101
|
});
|
|
141
|
-
console.log('[multicallContractsMethods] calls ==>', calls);
|
|
142
102
|
try {
|
|
143
103
|
const outputs = await this.multicall(calls.flat());
|
|
144
|
-
console.log('[multicallContractsMethods] outputs ==>', outputs);
|
|
145
104
|
let outputIndex = 0;
|
|
146
105
|
return contractsData.map((contractData) => contractData.methodsData.map((methodData) => {
|
|
147
106
|
const output = outputs.returnData[outputIndex];
|
|
148
|
-
if (!output)
|
|
149
|
-
console.log('[multicallContractsMethods] Error index:', { outputIndex, outputs });
|
|
107
|
+
if (!output)
|
|
150
108
|
return { output: null, success: false };
|
|
151
|
-
}
|
|
152
109
|
const methodOutputAbi = contractAbi.find((funcSignature) => funcSignature.name === methodData.methodName).outputs;
|
|
153
110
|
outputIndex++;
|
|
154
111
|
return {
|
|
@@ -171,37 +128,12 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
171
128
|
const balance = await this.getBalance(walletAddress, token.address);
|
|
172
129
|
return balance.gte(token.weiAmount);
|
|
173
130
|
}
|
|
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
131
|
async multicall(calls) {
|
|
181
132
|
this.public.setAddress(this.multicallAddress);
|
|
182
133
|
const contract = await this.public.contract(tron_multicall_abi_1.TRON_MULTICALL_ABI, this.multicallAddress);
|
|
183
134
|
// @ts-ignore
|
|
184
135
|
return contract['aggregate3'](calls).call();
|
|
185
136
|
}
|
|
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
137
|
async callForTokensInfo(tokenAddresses) {
|
|
206
138
|
const tokenFields = ['decimals', 'symbol', 'name'];
|
|
207
139
|
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: [
|
|
@@ -16,7 +16,9 @@ export interface ClientAdaptersFactoryParams {
|
|
|
16
16
|
envType: EnvType;
|
|
17
17
|
viemConfig?: ViemChainConfig;
|
|
18
18
|
lazyLoadWeb3?: boolean;
|
|
19
|
-
|
|
19
|
+
tronwebHeaders?: {
|
|
20
|
+
[key: string]: string;
|
|
21
|
+
};
|
|
20
22
|
}
|
|
21
23
|
export type ViemChainConfig = Partial<Record<EvmBlockchainName, ViemConfig>>;
|
|
22
24
|
export interface ViemConfig {
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* First argument is `target`, that is contract address to execute on.
|
|
3
|
-
* Second argument is `data`, that is encoded contract method.
|
|
4
|
-
*/
|
|
5
|
-
export type TronCall = [string, string];
|
|
6
1
|
/**
|
|
7
2
|
* First argument is `target`, that is contract address to execute on
|
|
8
3
|
* Second argument is `allowFailure`. If false, the entire call will revert if the call fails.
|