@cryptorubic/web3 0.0.22 → 0.0.23
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/abstract-adapter.d.ts +0 -3
- package/src/lib/adapter/adapters/abstract-adapter.js +0 -12
- package/src/lib/adapter/adapters/evm-adapter.d.ts +1 -2
- package/src/lib/adapter/adapters/evm-adapter.js +2 -6
- package/src/lib/adapter/adapters/models/approve-adapter.d.ts +4 -10
- package/src/lib/adapter/adapters/tron-adapter.d.ts +6 -5
- package/src/lib/adapter/adapters/tron-adapter.js +18 -20
- package/src/lib/adapter/adapters/utils/ton-api.service.js +11 -11
- package/src/lib/adapter/blockchain-adapter-factory.service.d.ts +1 -3
- package/src/lib/adapter/blockchain-adapter-factory.service.js +0 -4
- package/src/lib/utils/web3-types/tron-web3-pure.d.ts +0 -3
- package/src/lib/utils/web3-types/tron-web3-pure.js +0 -14
- package/src/lib/adapter/adapters/models/basic-transaction-options.d.ts +0 -7
- package/src/lib/adapter/adapters/models/basic-transaction-options.js +0 -2
package/package.json
CHANGED
|
@@ -9,9 +9,6 @@ export declare abstract class AbstractAdapter<P, W, B extends BlockchainName> {
|
|
|
9
9
|
private _wallet;
|
|
10
10
|
set wallet(value: W | null);
|
|
11
11
|
get wallet(): W;
|
|
12
|
-
private _walletAddress;
|
|
13
|
-
set walletAddress(value: string | null);
|
|
14
|
-
get walletAddress(): string;
|
|
15
12
|
protected constructor(blockchain: B, logger?: ICustomLogger);
|
|
16
13
|
abstract callForTokensInfo(tokenAddresses: string[] | ReadonlyArray<string>): Promise<Token<BlockchainName>[]>;
|
|
17
14
|
needPreswapAction(token: TokenAmount, contractAddress: string, walletAddress: string, amount: string | BigNumber): Promise<boolean>;
|
|
@@ -25,21 +25,9 @@ class AbstractAdapter {
|
|
|
25
25
|
}
|
|
26
26
|
return this._wallet;
|
|
27
27
|
}
|
|
28
|
-
set walletAddress(value) {
|
|
29
|
-
this._walletAddress = value;
|
|
30
|
-
}
|
|
31
|
-
get walletAddress() {
|
|
32
|
-
if (!this._walletAddress) {
|
|
33
|
-
const msg = 'Trying to access undefined walletAddress';
|
|
34
|
-
this.logger?.customLog(msg);
|
|
35
|
-
throw new Error(msg);
|
|
36
|
-
}
|
|
37
|
-
return this._walletAddress;
|
|
38
|
-
}
|
|
39
28
|
constructor(blockchain, logger) {
|
|
40
29
|
this._public = null;
|
|
41
30
|
this._wallet = null;
|
|
42
|
-
this._walletAddress = null;
|
|
43
31
|
this.blockchain = blockchain;
|
|
44
32
|
if (logger) {
|
|
45
33
|
this.logger = logger;
|
|
@@ -6,7 +6,7 @@ import { EvmAdapterOptions } from "./models/evm-adapter-options";
|
|
|
6
6
|
import { EvmTransactionConfig } from "../../utils/models/evm-transaction-config";
|
|
7
7
|
import { ApproveAdapter } from "./models/approve-adapter";
|
|
8
8
|
import { AllowanceInfo } from "./models/common-types";
|
|
9
|
-
export declare class EvmAdapter extends AbstractAdapter<PublicActions & PublicClient, WalletClient & WalletActions, EvmBlockchainName> implements ApproveAdapter
|
|
9
|
+
export declare class EvmAdapter extends AbstractAdapter<PublicActions & PublicClient, WalletClient & WalletActions, EvmBlockchainName> implements ApproveAdapter {
|
|
10
10
|
needPreswapAction(token: TokenAmount, contractAddress: string, walletAddress: string, amount: string): Promise<boolean>;
|
|
11
11
|
handlePreswap(contractAddress: string, walletAddress: string, tokenAmount: TokenAmount): Promise<void>;
|
|
12
12
|
constructor(adapterOptions: EvmAdapterOptions, logger?: ICustomLogger);
|
|
@@ -31,5 +31,4 @@ export declare class EvmAdapter extends AbstractAdapter<PublicActions & PublicCl
|
|
|
31
31
|
getAllowance(fromTokenAddress: string, walletAddress: string, spenderAddress: string): Promise<AllowanceInfo>;
|
|
32
32
|
encodeApprove(tokenAddress: string, spenderAddress: string, amount?: string): EvmTransactionConfig;
|
|
33
33
|
needApprove(token: TokenAmount, contractAddress: string, walletAddress: string, amount: string): Promise<boolean>;
|
|
34
|
-
approve(fromAddress: string, tokenAddress: string, spenderAddress: string, amount?: string): Promise<string>;
|
|
35
34
|
}
|
|
@@ -136,7 +136,8 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
136
136
|
to: config.to,
|
|
137
137
|
...(config.value && { value: BigInt(config.value) })
|
|
138
138
|
};
|
|
139
|
-
|
|
139
|
+
// @ts-ignore
|
|
140
|
+
await this.core.call(callParams);
|
|
140
141
|
}
|
|
141
142
|
catch (err) {
|
|
142
143
|
this.logger?.customError('Error while simulating transaction', err);
|
|
@@ -242,10 +243,5 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
242
243
|
return allowanceWei.lt(token.weiAmount);
|
|
243
244
|
}
|
|
244
245
|
;
|
|
245
|
-
async approve(fromAddress, tokenAddress, spenderAddress, amount) {
|
|
246
|
-
const config = this.encodeApprove(tokenAddress, spenderAddress, amount);
|
|
247
|
-
return this.write(fromAddress, config.to, config.value, config.data);
|
|
248
|
-
}
|
|
249
|
-
;
|
|
250
246
|
}
|
|
251
247
|
exports.EvmAdapter = EvmAdapter;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TokenAmount } from "@cryptorubic/core";
|
|
2
2
|
import { AllowanceInfo } from "./common-types";
|
|
3
|
-
|
|
3
|
+
import { EvmTransactionConfig } from "../../../utils/models/evm-transaction-config";
|
|
4
|
+
export interface ApproveAdapter {
|
|
4
5
|
/**
|
|
5
6
|
* @param fromTokenAddress erc20 address of checked token
|
|
6
7
|
* @param walletAddress owner wallet address
|
|
@@ -9,12 +10,12 @@ export interface ApproveAdapter<T> {
|
|
|
9
10
|
*/
|
|
10
11
|
getAllowance(fromTokenAddress: string, walletAddress: string, spenderAddress: string): Promise<AllowanceInfo>;
|
|
11
12
|
/**
|
|
12
|
-
*
|
|
13
|
+
*
|
|
13
14
|
* @param tokenAddress erc20 token address
|
|
14
15
|
* @param spenderAddress spender address
|
|
15
16
|
* @param amount amount in non wei
|
|
16
17
|
*/
|
|
17
|
-
encodeApprove(tokenAddress: string, spenderAddress: string, amount?: string):
|
|
18
|
+
encodeApprove(tokenAddress: string, spenderAddress: string, amount?: string): EvmTransactionConfig;
|
|
18
19
|
/**
|
|
19
20
|
* Check if approve needed.
|
|
20
21
|
* @param token
|
|
@@ -23,11 +24,4 @@ export interface ApproveAdapter<T> {
|
|
|
23
24
|
* @param amount
|
|
24
25
|
*/
|
|
25
26
|
needApprove(token: TokenAmount, contractAddress: string, walletAddress: string, amount: string): Promise<boolean>;
|
|
26
|
-
/**
|
|
27
|
-
* Get data for tokens approve
|
|
28
|
-
* @param tokenAddress erc20 token address
|
|
29
|
-
* @param spenderAddress spender address
|
|
30
|
-
* @param amount amount in non wei
|
|
31
|
-
*/
|
|
32
|
-
approve(walletAddress: string, tokenAddress: string, spenderAddress: string, amount?: string): Promise<string>;
|
|
33
27
|
}
|
|
@@ -9,7 +9,8 @@ import { TronParameters } from "../../utils/models/tron-parameters";
|
|
|
9
9
|
import { Abi } from "viem";
|
|
10
10
|
import { ApproveAdapter } from "./models/approve-adapter";
|
|
11
11
|
import { AllowanceInfo } from "./models/common-types";
|
|
12
|
-
|
|
12
|
+
import { EvmTransactionConfig } from "../../utils/models/evm-transaction-config";
|
|
13
|
+
export declare class TronAdapter extends AbstractAdapter<TronWeb, TronWeb, TronBlockchainName> implements ApproveAdapter {
|
|
13
14
|
private readonly multicallAddress;
|
|
14
15
|
needPreswapAction(token: TokenAmount, contractAddress: string, walletAddress: string, amount: string): Promise<boolean>;
|
|
15
16
|
constructor(rpcList: string[], logger?: ICustomLogger);
|
|
@@ -18,18 +19,18 @@ export declare class TronAdapter extends AbstractAdapter<TronWeb, TronWeb, TronB
|
|
|
18
19
|
methodsData: MethodData[];
|
|
19
20
|
}[]): Promise<ContractMulticallResponse<Output>[][]>;
|
|
20
21
|
private multicall;
|
|
21
|
-
|
|
22
|
+
callContractMethod<T extends TronWeb3PrimitiveType = string>(contractAddress: string, contractAbi: readonly AbiFragment[], methodName: string, methodArguments?: unknown[]): Promise<T>;
|
|
22
23
|
private multicallContractsMethodsByOne;
|
|
23
24
|
getTokensBalances(userAddress: string, tokensAddresses: string[]): Promise<BigNumber[]>;
|
|
24
25
|
callForTokensInfo(tokenAddresses: string[] | ReadonlyArray<string>): Promise<Token[]>;
|
|
25
26
|
getBalance(userAddress: string, tokenAddress?: string): Promise<BigNumber>;
|
|
26
27
|
getTokenBalance(userAddress: string, tokenAddress: string): Promise<BigNumber>;
|
|
27
28
|
convertTronAddressToHex(address: string): Promise<string>;
|
|
28
|
-
|
|
29
|
+
read<T>(): Promise<T>;
|
|
30
|
+
write(): Promise<string>;
|
|
29
31
|
static encodeMethodCall(contractAddress: string, contractAbi: Abi, methodName: string, methodArguments: TronParameters, callValue?: string, feeLimit?: number): TronTransactionConfig;
|
|
30
32
|
private static flattenTypesToString;
|
|
31
33
|
needApprove(from: TokenAmount | PriceTokenAmount, walletAddress: string, spender: string): Promise<boolean>;
|
|
32
|
-
encodeApprove(tokenAddress: string, spenderAddress: string, amount?: string):
|
|
34
|
+
encodeApprove(tokenAddress: string, spenderAddress: string, amount?: string): EvmTransactionConfig;
|
|
33
35
|
getAllowance(fromTokenAddress: string, walletAddress: string, spender: string): Promise<AllowanceInfo>;
|
|
34
|
-
approve(fromAddress: string, tokenAddress: string, spenderAddress: string, amount?: string): Promise<string>;
|
|
35
36
|
}
|
|
@@ -51,7 +51,7 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
51
51
|
// @ts-ignore
|
|
52
52
|
return contract.aggregateViewCalls(calls).call();
|
|
53
53
|
}
|
|
54
|
-
async
|
|
54
|
+
async callContractMethod(contractAddress, contractAbi, methodName, methodArguments = []) {
|
|
55
55
|
this.public.setAddress(contractAddress);
|
|
56
56
|
const contract = await this.public.contract(contractAbi, contractAddress);
|
|
57
57
|
const response = await contract[methodName](...methodArguments).call();
|
|
@@ -61,7 +61,7 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
61
61
|
return Promise.all(contractsData.map((contractData) => {
|
|
62
62
|
return Promise.all(contractData.methodsData.map(async (methodData) => {
|
|
63
63
|
try {
|
|
64
|
-
const output = (await this.
|
|
64
|
+
const output = (await this.callContractMethod(contractData.contractAddress, contractAbi, methodData.methodName, methodData.methodArguments));
|
|
65
65
|
return {
|
|
66
66
|
output,
|
|
67
67
|
success: true
|
|
@@ -161,11 +161,12 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
161
161
|
async convertTronAddressToHex(address) {
|
|
162
162
|
return this.public.address.toHex(address);
|
|
163
163
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
164
|
+
read() {
|
|
165
|
+
throw new Error('Method is not implemented');
|
|
166
|
+
}
|
|
167
|
+
;
|
|
168
|
+
write() {
|
|
169
|
+
throw new Error('Method is not implemented');
|
|
169
170
|
}
|
|
170
171
|
;
|
|
171
172
|
static encodeMethodCall(contractAddress, contractAbi, methodName, methodArguments, callValue, feeLimit) {
|
|
@@ -200,25 +201,22 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
200
201
|
}
|
|
201
202
|
encodeApprove(tokenAddress, spenderAddress, amount) {
|
|
202
203
|
const amountWei = amount ?? new bignumber_js_1.default(2).pow(256).minus(1).toFixed();
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
204
|
+
const callData = tron_web3_pure_1.TronWeb3Pure.encodeFunctionCall(trc_20_contract_abi_1.TRC20_CONTRACT_ABI, 'approve', [spenderAddress, amountWei]);
|
|
205
|
+
return {
|
|
206
|
+
data: callData,
|
|
207
|
+
to: tokenAddress,
|
|
208
|
+
value: '0'
|
|
209
|
+
};
|
|
207
210
|
}
|
|
208
211
|
async getAllowance(fromTokenAddress, walletAddress, spender) {
|
|
209
|
-
const [contract, decimals
|
|
212
|
+
const [contract, decimals] = await Promise.all([
|
|
210
213
|
this.public.contract(trc_20_contract_abi_1.TRC20_CONTRACT_ABI, fromTokenAddress),
|
|
211
|
-
this.
|
|
212
|
-
this.read(fromTokenAddress, trc_20_contract_abi_1.TRC20_CONTRACT_ABI, 'allowance', [spender])
|
|
214
|
+
this.callContractMethod(fromTokenAddress, trc_20_contract_abi_1.TRC20_CONTRACT_ABI, 'decimals')
|
|
213
215
|
]);
|
|
214
|
-
const
|
|
216
|
+
const allowance = await this.getAllowance(fromTokenAddress, walletAddress, spender);
|
|
217
|
+
const allowanceWeiBN = new bignumber_js_1.default(allowance?.toString());
|
|
215
218
|
const allowanceNonWei = core_1.Token.fromWei(allowanceWeiBN, Number(decimals));
|
|
216
219
|
return { allowanceNonWei, allowanceWei: allowanceWeiBN };
|
|
217
220
|
}
|
|
218
|
-
async approve(fromAddress, tokenAddress, spenderAddress, amount) {
|
|
219
|
-
const config = this.encodeApprove(tokenAddress, spenderAddress, amount);
|
|
220
|
-
return this.write(config.to, config.signature, config.arguments);
|
|
221
|
-
}
|
|
222
|
-
;
|
|
223
221
|
}
|
|
224
222
|
exports.TronAdapter = TronAdapter;
|
|
@@ -14,7 +14,7 @@ class TonApiService {
|
|
|
14
14
|
async getAllFormatsOfAddress(walletAddress) {
|
|
15
15
|
const res = await this.httpClient.get(`${this.tonApiUrl}/v2/address/${walletAddress}/parse`, {
|
|
16
16
|
headers: {
|
|
17
|
-
|
|
17
|
+
apiKey: this.apiKey
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
20
|
if ('error' in res) {
|
|
@@ -28,7 +28,7 @@ class TonApiService {
|
|
|
28
28
|
*/
|
|
29
29
|
async fetchWalletSeqno(walletAddress) {
|
|
30
30
|
const res = await this.httpClient.get(`${this.tonApiUrl}/v2/wallet/${walletAddress}/seqno`, {
|
|
31
|
-
headers: {
|
|
31
|
+
headers: { apiKey: this.apiKey }
|
|
32
32
|
});
|
|
33
33
|
if ('error' in res) {
|
|
34
34
|
throw new Error(`[TonApiService] Error in fetchWalletSeqno - ${res.error}`);
|
|
@@ -37,7 +37,7 @@ class TonApiService {
|
|
|
37
37
|
}
|
|
38
38
|
async fetchTxInfo(txHash) {
|
|
39
39
|
const res = await this.httpClient.get(`${this.tonApiUrl}/v2/blockchain/transactions/${txHash}`, {
|
|
40
|
-
headers: {
|
|
40
|
+
headers: { apiKey: this.apiKey }
|
|
41
41
|
});
|
|
42
42
|
if ('error' in res) {
|
|
43
43
|
throw new Error(`[TonApiService] Error in fetchTxInfo - ${res.error}`);
|
|
@@ -45,7 +45,7 @@ class TonApiService {
|
|
|
45
45
|
return res;
|
|
46
46
|
}
|
|
47
47
|
async fetchTxInfoByMessageHash(txHash) {
|
|
48
|
-
const res = await this.httpClient.get(`${this.tonApiUrl}/v2/blockchain/messages/${txHash}/transaction`, { headers: {
|
|
48
|
+
const res = await this.httpClient.get(`${this.tonApiUrl}/v2/blockchain/messages/${txHash}/transaction`, { headers: { apiKey: this.apiKey } });
|
|
49
49
|
if ('error' in res) {
|
|
50
50
|
throw new Error(`[TonApiService] Error in fetchTxInfoByMessageHash - ${res.error}`);
|
|
51
51
|
}
|
|
@@ -54,7 +54,7 @@ class TonApiService {
|
|
|
54
54
|
async checkIsTxCompleted(txHash) {
|
|
55
55
|
try {
|
|
56
56
|
const res = await this.httpClient.get(`${this.tonApiUrl}/v2/events/${txHash}`, {
|
|
57
|
-
headers: {
|
|
57
|
+
headers: { apiKey: this.apiKey }
|
|
58
58
|
});
|
|
59
59
|
if ('error' in res) {
|
|
60
60
|
throw new Error(`[TonApiService] Error in checkIsTxCompleted - ${res.error}`);
|
|
@@ -67,7 +67,7 @@ class TonApiService {
|
|
|
67
67
|
}
|
|
68
68
|
async healthcheck() {
|
|
69
69
|
const res = await this.httpClient.get(`${this.tonApiUrl}/v2/status`, {
|
|
70
|
-
headers: {
|
|
70
|
+
headers: { apiKey: this.apiKey }
|
|
71
71
|
});
|
|
72
72
|
if ('error' in res || !res.rest_online) {
|
|
73
73
|
return false;
|
|
@@ -96,7 +96,7 @@ class TonApiService {
|
|
|
96
96
|
if (methodArgs.length) {
|
|
97
97
|
argsParam += '?' + methodArgs.map((param) => `args=${param}`).join('&');
|
|
98
98
|
}
|
|
99
|
-
const res = await this.httpClient.get(`${this.tonApiUrl}/v2/blockchain/accounts/${address}/methods/${methodName}${argsParam}`, { headers: {
|
|
99
|
+
const res = await this.httpClient.get(`${this.tonApiUrl}/v2/blockchain/accounts/${address}/methods/${methodName}${argsParam}`, { headers: { apiKey: this.apiKey } });
|
|
100
100
|
if ('error' in res) {
|
|
101
101
|
throw new Error(`[TonApiService] Error in callContractMethod - ${res.error}`);
|
|
102
102
|
}
|
|
@@ -104,7 +104,7 @@ class TonApiService {
|
|
|
104
104
|
}
|
|
105
105
|
async fetchTokenInfo(tokenAddress) {
|
|
106
106
|
const res = await this.httpClient.get(`${this.tonApiUrl}/v2/jettons/${tokenAddress}`, {
|
|
107
|
-
headers: {
|
|
107
|
+
headers: { apiKey: this.apiKey }
|
|
108
108
|
});
|
|
109
109
|
if ('error' in res) {
|
|
110
110
|
throw new Error(`[TonApiService] Error in fetchTokenInfo - ${res.error}`);
|
|
@@ -117,7 +117,7 @@ class TonApiService {
|
|
|
117
117
|
* @returns balance, decimals, name, symbol, walletJettonAddress, jettonAddress
|
|
118
118
|
*/
|
|
119
119
|
async fetchTokenInfoForWallet(walletAddress, tokenAddress) {
|
|
120
|
-
const res = await this.httpClient.get(`${this.tonApiUrl}/v2/accounts/${walletAddress}/jettons/${tokenAddress}`, { headers: {
|
|
120
|
+
const res = await this.httpClient.get(`${this.tonApiUrl}/v2/accounts/${walletAddress}/jettons/${tokenAddress}`, { headers: { apiKey: this.apiKey } });
|
|
121
121
|
if ('error' in res) {
|
|
122
122
|
throw new Error(`[TonApiService] Error in fetchTokenInfoForWallet - ${res.error}`);
|
|
123
123
|
}
|
|
@@ -125,7 +125,7 @@ class TonApiService {
|
|
|
125
125
|
}
|
|
126
126
|
async fetchAllNonNullableTokensInfoForWallet(walletAddress) {
|
|
127
127
|
const res = await this.httpClient.get(`${this.tonApiUrl}/v2/accounts/${walletAddress}/jettons`, {
|
|
128
|
-
headers: {
|
|
128
|
+
headers: { apiKey: this.apiKey }
|
|
129
129
|
});
|
|
130
130
|
if ('error' in res) {
|
|
131
131
|
throw new Error(`[TonApiService] Error in fetchAllNonNullableTokensInfoForWallet - ${res.error}`);
|
|
@@ -137,7 +137,7 @@ class TonApiService {
|
|
|
137
137
|
*/
|
|
138
138
|
async fetchAccountInfo(walletAddress) {
|
|
139
139
|
const res = await this.httpClient.get(`${this.tonApiUrl}/v2/accounts/${walletAddress}`, {
|
|
140
|
-
headers: {
|
|
140
|
+
headers: { apiKey: this.apiKey }
|
|
141
141
|
});
|
|
142
142
|
if ('error' in res) {
|
|
143
143
|
throw new Error(`[TonApiService] Error in fetchAccountInfo - ${res.error}`);
|
|
@@ -2,8 +2,7 @@ import { SolanaAdapter } from './adapters/solana-adapter';
|
|
|
2
2
|
import { TronAdapter } from './adapters/tron-adapter';
|
|
3
3
|
import { AbstractAdapter } from './adapters/abstract-adapter';
|
|
4
4
|
import { WalletProvider } from "./constants/models/wallet-provider";
|
|
5
|
-
import { BlockchainName, EvmBlockchainName, SolanaBlockchainName, TronBlockchainName, ICustomLogger, HttpClient
|
|
6
|
-
import { TonAdapter } from "./adapters/ton-adapter";
|
|
5
|
+
import { BlockchainName, EvmBlockchainName, SolanaBlockchainName, TronBlockchainName, ICustomLogger, HttpClient } from "@cryptorubic/core";
|
|
7
6
|
import { TonAdapterConfig } from "./adapters/models/ton-adapter-config";
|
|
8
7
|
import { EvmAdapter } from "./adapters/evm-adapter";
|
|
9
8
|
export declare class BlockchainAdapterFactoryService {
|
|
@@ -18,7 +17,6 @@ export declare class BlockchainAdapterFactoryService {
|
|
|
18
17
|
getAdapter(blockchain: SolanaBlockchainName): SolanaAdapter;
|
|
19
18
|
getAdapter(blockchain: EvmBlockchainName): EvmAdapter;
|
|
20
19
|
getAdapter(blockchain: TronBlockchainName): TronAdapter;
|
|
21
|
-
getAdapter(blockchain: TonBlockchainName): TonAdapter;
|
|
22
20
|
private createStorage;
|
|
23
21
|
private createAdapter;
|
|
24
22
|
connectWallet(walletProvider: WalletProvider): void;
|
|
@@ -92,23 +92,19 @@ class BlockchainAdapterFactoryService {
|
|
|
92
92
|
chain: chain,
|
|
93
93
|
transport: (0, viem_1.custom)(provider)
|
|
94
94
|
});
|
|
95
|
-
adapter.walletAddress = walletProvider[core_1.CHAIN_TYPE.EVM].address;
|
|
96
95
|
});
|
|
97
96
|
}
|
|
98
97
|
if (walletProvider?.[core_1.CHAIN_TYPE.SOLANA]?.core && this.adapterStore?.[core_1.BLOCKCHAIN_NAME.SOLANA]) {
|
|
99
98
|
const store = this.adapterStore[core_1.BLOCKCHAIN_NAME.SOLANA];
|
|
100
99
|
store.wallet = walletProvider[core_1.CHAIN_TYPE.SOLANA].core;
|
|
101
|
-
store.walletAddress = walletProvider[core_1.CHAIN_TYPE.SOLANA].address;
|
|
102
100
|
}
|
|
103
101
|
if (walletProvider?.[core_1.CHAIN_TYPE.TRON]?.core && this.adapterStore?.[core_1.BLOCKCHAIN_NAME.TRON]) {
|
|
104
102
|
const store = this.adapterStore[core_1.BLOCKCHAIN_NAME.TRON];
|
|
105
103
|
store.wallet = walletProvider[core_1.CHAIN_TYPE.TRON].core;
|
|
106
|
-
store.walletAddress = walletProvider[core_1.CHAIN_TYPE.TRON].address;
|
|
107
104
|
}
|
|
108
105
|
if (walletProvider?.[core_1.CHAIN_TYPE.TON]?.core && this.adapterStore?.[core_1.BLOCKCHAIN_NAME.TON]) {
|
|
109
106
|
const store = this.adapterStore[core_1.BLOCKCHAIN_NAME.TON];
|
|
110
107
|
store.wallet = walletProvider[core_1.CHAIN_TYPE.TON].core;
|
|
111
|
-
store.walletAddress = walletProvider[core_1.CHAIN_TYPE.TON].address;
|
|
112
108
|
}
|
|
113
109
|
}
|
|
114
110
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { CommonWeb3Pure } from "./common-web3-pure";
|
|
2
|
-
import { TronTransactionConfig } from "../models/tron-transaction-config";
|
|
3
2
|
import { TronParameters } from "../models/tron-parameters";
|
|
4
3
|
import { TronWeb3PrimitiveType, Web3PrimitiveType } from "../models/primitive-types";
|
|
5
4
|
import { FunctionFragment } from "tronweb/src/types/ABI";
|
|
6
|
-
import { AbiItem } from "../models/abi-types";
|
|
7
5
|
export declare class TronWeb3Pure extends CommonWeb3Pure {
|
|
8
6
|
constructor();
|
|
9
7
|
isAddressCorrect(address: string): Promise<boolean>;
|
|
@@ -17,7 +15,6 @@ export declare class TronWeb3Pure extends CommonWeb3Pure {
|
|
|
17
15
|
* @returns An ABI encoded function call. Means function signature + parameters.
|
|
18
16
|
*/
|
|
19
17
|
static encodeFunctionCall(contractAbi: FunctionFragment[], methodName: string, methodArguments: unknown[]): string;
|
|
20
|
-
static encodeMethodCall(contractAddress: string, contractAbi: AbiItem[], methodName: string, methodArguments: TronParameters, callValue?: string, feeLimit?: number): TronTransactionConfig;
|
|
21
18
|
static encodeMethodSignature(methodSignature: string, parameters: TronParameters): string;
|
|
22
19
|
/**
|
|
23
20
|
* Decodes method result using its JSON interface object and given parameters.
|
|
@@ -33,20 +33,6 @@ class TronWeb3Pure extends common_web3_pure_1.CommonWeb3Pure {
|
|
|
33
33
|
const encodedParameters = tronweb_1.utils.abi.encodeParamsV2ByABI(methodSignature, methodArguments);
|
|
34
34
|
return encodedMethodSignature + encodedParameters.slice(2);
|
|
35
35
|
}
|
|
36
|
-
static encodeMethodCall(contractAddress, contractAbi, methodName, methodArguments, callValue, feeLimit) {
|
|
37
|
-
const methodAbi = contractAbi.find(abiItem => abiItem.name === methodName);
|
|
38
|
-
if (!methodAbi) {
|
|
39
|
-
throw new Error('Encode fail. No method in ABI');
|
|
40
|
-
}
|
|
41
|
-
const signature = `${methodAbi.name}(${this.flattenTypesToString(methodAbi.inputs).join(',')})`;
|
|
42
|
-
return {
|
|
43
|
-
to: contractAddress,
|
|
44
|
-
arguments: methodArguments,
|
|
45
|
-
signature,
|
|
46
|
-
...(callValue && { callValue }),
|
|
47
|
-
...(feeLimit && { feeLimit })
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
36
|
static encodeMethodSignature(methodSignature, parameters) {
|
|
51
37
|
const encodedMethodSignature = tronweb_1.TronWeb.sha3(methodSignature).slice(0, 10);
|
|
52
38
|
const flattenedParameters = this.flattenParameters(parameters);
|