@cryptorubic/web3 1.0.0-alpha.no-sdk.6 → 1.0.0-alpha.no-sdk.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 +1 -1
- package/src/lib/adapter/adapters/adapter-bitcoin/bitcoin-adapter.d.ts +0 -2
- package/src/lib/adapter/adapters/adapter-bitcoin/bitcoin-adapter.js +0 -6
- package/src/lib/adapter/adapters/adapter-bitcoin/client/bitcoin-adapter-client.d.ts +2 -0
- package/src/lib/adapter/adapters/adapter-bitcoin/client/bitcoin-adapter-client.js +6 -0
- package/src/lib/adapter/adapters/adapter-evm/client/evm-adapter-client.d.ts +6 -4
- package/src/lib/adapter/adapters/adapter-evm/client/evm-adapter-client.js +43 -11
- package/src/lib/adapter/adapters/adapter-evm/evm-adapter.d.ts +0 -3
- package/src/lib/adapter/adapters/adapter-evm/evm-adapter.js +3 -34
- package/src/lib/adapter/adapters/adapter-solana/client/solana-adapter-client.d.ts +2 -0
- package/src/lib/adapter/adapters/adapter-solana/client/solana-adapter-client.js +6 -0
- package/src/lib/adapter/adapters/adapter-solana/solana-adapter.d.ts +0 -3
- package/src/lib/adapter/adapters/adapter-solana/solana-adapter.js +0 -6
- package/src/lib/adapter/adapters/adapter-sui/client/sui-adapter-client.d.ts +2 -0
- package/src/lib/adapter/adapters/adapter-sui/client/sui-adapter-client.js +6 -0
- package/src/lib/adapter/adapters/adapter-sui/sui-adapter.d.ts +0 -2
- package/src/lib/adapter/adapters/adapter-sui/sui-adapter.js +0 -6
- package/src/lib/adapter/adapters/adapter-ton/client/ton-adapter-client.d.ts +2 -0
- package/src/lib/adapter/adapters/adapter-ton/client/ton-adapter-client.js +6 -0
- package/src/lib/adapter/adapters/adapter-ton/ton-adapter.d.ts +0 -2
- package/src/lib/adapter/adapters/adapter-ton/ton-adapter.js +0 -6
- package/src/lib/adapter/adapters/adapter-tron/client/tron-adapter-client.d.ts +5 -3
- package/src/lib/adapter/adapters/adapter-tron/client/tron-adapter-client.js +24 -11
- package/src/lib/adapter/adapters/adapter-tron/tron-adapter.d.ts +0 -2
- package/src/lib/adapter/adapters/adapter-tron/tron-adapter.js +2 -14
- package/src/lib/adapter/adapters/common/abstract-adapter.d.ts +0 -2
- package/src/lib/adapter/adapters/common/client/abstract-adapter-client.d.ts +2 -0
- package/src/lib/utils/models/evm-transaction-config.d.ts +2 -0
package/package.json
CHANGED
|
@@ -27,8 +27,6 @@ export declare class BitcoinAdapter extends AbstractAdapter<BtcWallet, BtcWallet
|
|
|
27
27
|
getPublicKey(userAddress: string): Promise<string | null>;
|
|
28
28
|
checkEnoughBalance(token: TokenAmount | PriceTokenAmount, walletAddress: string): Promise<boolean>;
|
|
29
29
|
callForTokensInfo(tokenAddresses: string[] | ReadonlyArray<string>): Promise<Token<BlockchainName>[]>;
|
|
30
|
-
read<T>(args: unknown): Promise<T>;
|
|
31
|
-
write(args: unknown): Promise<string>;
|
|
32
30
|
getPublicKeyFromWallet(): Promise<string>;
|
|
33
31
|
transfer(recipient: string, amount: string, fromAddress: string, memo?: string, options?: BasicSendTransactionOptions): Promise<string>;
|
|
34
32
|
sendPsbtTransaction(psbt: string, userAddress: string, inputIndexes: number[], options?: BasicSendTransactionOptions): Promise<string>;
|
|
@@ -61,12 +61,6 @@ class BitcoinAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
61
61
|
async callForTokensInfo(tokenAddresses) {
|
|
62
62
|
return [core_1.nativeTokensList[core_1.BLOCKCHAIN_NAME.BITCOIN]];
|
|
63
63
|
}
|
|
64
|
-
read(args) {
|
|
65
|
-
throw new Error('Not implemented');
|
|
66
|
-
}
|
|
67
|
-
write(args) {
|
|
68
|
-
throw new Error('Not implemented');
|
|
69
|
-
}
|
|
70
64
|
async getPublicKeyFromWallet() {
|
|
71
65
|
const res = await this.client.clientWallet.request({
|
|
72
66
|
method: 'request_accounts_and_keys',
|
|
@@ -6,6 +6,8 @@ import { BtcWallet } from '../../models/btc-wallet-provider';
|
|
|
6
6
|
import { TxStatus } from '../../models/web3-public-models/tx-status';
|
|
7
7
|
export declare class BitcoinAdapterClient extends AbstractAdapterClient<BtcWallet, BitconSendTxParams, string> {
|
|
8
8
|
constructor(httpClient: HttpClient, logger?: ICustomLogger, rubicAppParams?: RubicAppAdaptersFactoryParams);
|
|
9
|
+
read<T>(args: unknown): Promise<T>;
|
|
10
|
+
write(args: unknown): Promise<string>;
|
|
9
11
|
getBlockchainName(): Promise<BlockchainName>;
|
|
10
12
|
getTransactionStatus(txHash: string): Promise<TxStatus>;
|
|
11
13
|
sendTransaction(params: BitconSendTxParams): Promise<string>;
|
|
@@ -9,6 +9,12 @@ class BitcoinAdapterClient extends abstract_adapter_client_1.AbstractAdapterClie
|
|
|
9
9
|
constructor(httpClient, logger, rubicAppParams) {
|
|
10
10
|
super(httpClient, logger, rubicAppParams);
|
|
11
11
|
}
|
|
12
|
+
read(args) {
|
|
13
|
+
throw new Error('Not implemented');
|
|
14
|
+
}
|
|
15
|
+
write(args) {
|
|
16
|
+
throw new Error('Not implemented');
|
|
17
|
+
}
|
|
12
18
|
getBlockchainName() {
|
|
13
19
|
return Promise.resolve(core_1.BLOCKCHAIN_NAME.BITCOIN);
|
|
14
20
|
}
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { BlockchainName, HttpClient, ICustomLogger, TokenAmount } from '@cryptorubic/core';
|
|
2
2
|
import { RubicAppAdaptersFactoryParams } from '../../../constants/models/create-factory-params';
|
|
3
3
|
import { AbstractAdapterClient } from '../../common/client/abstract-adapter-client';
|
|
4
|
-
import { Abi, TransactionReceipt, WalletActions, WalletClient } from 'viem';
|
|
4
|
+
import { Abi, PublicActions, PublicClient, TransactionReceipt, WalletActions, WalletClient } from 'viem';
|
|
5
5
|
import { EvmSendTxParams, EvmTransactionOptions } from '../models/evm-send-tx-params';
|
|
6
6
|
import BigNumber from 'bignumber.js';
|
|
7
7
|
import { Web3Error } from '../utils/parse-evm-error';
|
|
8
8
|
import { EvmTransactionConfig } from 'packages/web3/src/lib/utils/models/evm-transaction-config';
|
|
9
|
-
import { EvmAdapter } from '../evm-adapter';
|
|
10
9
|
import { TxStatus } from '../../models/web3-public-models/tx-status';
|
|
11
10
|
import { ApproveAdapterClient } from '../../models/approve-adapter';
|
|
12
11
|
import { AllowanceInfo } from '../../models/common-types';
|
|
13
12
|
export declare class EvmAdapterClient extends AbstractAdapterClient<WalletClient & WalletActions, EvmSendTxParams, TransactionReceipt> implements ApproveAdapterClient<EvmTransactionConfig> {
|
|
14
|
-
private readonly
|
|
15
|
-
constructor(
|
|
13
|
+
private readonly evmPublic;
|
|
14
|
+
constructor(evmPublic: PublicActions & PublicClient, httpClient: HttpClient, logger?: ICustomLogger, rubicAppParams?: RubicAppAdaptersFactoryParams);
|
|
16
15
|
getBlockchainName(): Promise<BlockchainName | undefined>;
|
|
17
16
|
getAllowance(fromTokenAddress: string, walletAddress: string, spenderAddress: string): Promise<AllowanceInfo>;
|
|
18
17
|
needApprove(token: TokenAmount, contractAddress: string, walletAddress: string, amount: string): Promise<boolean>;
|
|
@@ -77,4 +76,7 @@ export declare class EvmAdapterClient extends AbstractAdapterClient<WalletClient
|
|
|
77
76
|
private shouldIgnoreError;
|
|
78
77
|
signMessage(message: string): Promise<string>;
|
|
79
78
|
private getChainAndAccount;
|
|
79
|
+
read<T>(address: string, abi: Abi, method: string, methodArgs?: unknown[]): Promise<T>;
|
|
80
|
+
writeContract(address: string, abi: Abi, method: string, value?: string, methodArgs?: unknown[]): Promise<string>;
|
|
81
|
+
write(address: string, to: string, value: string, data: string): Promise<string>;
|
|
80
82
|
}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.EvmAdapterClient = void 0;
|
|
4
4
|
const core_1 = require("@cryptorubic/core");
|
|
5
5
|
const abstract_adapter_client_1 = require("../../common/client/abstract-adapter-client");
|
|
6
|
+
const viem_1 = require("viem");
|
|
6
7
|
const waitForTransactionReceipt_1 = require("viem/_types/actions/public/waitForTransactionReceipt");
|
|
7
8
|
const options_1 = require("../../utils/options");
|
|
8
9
|
const viem_blockchain_mapping_1 = require("../../../constants/viem-blockchain-mapping");
|
|
@@ -14,9 +15,9 @@ const rubic_sdk_error_1 = require("packages/web3/src/lib/errors/rubic-sdk.error"
|
|
|
14
15
|
const evm_adapter_1 = require("../evm-adapter");
|
|
15
16
|
const tx_status_1 = require("../../models/web3-public-models/tx-status");
|
|
16
17
|
class EvmAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
|
|
17
|
-
constructor(
|
|
18
|
+
constructor(evmPublic, httpClient, logger, rubicAppParams) {
|
|
18
19
|
super(httpClient, logger, rubicAppParams);
|
|
19
|
-
this.
|
|
20
|
+
this.evmPublic = evmPublic;
|
|
20
21
|
}
|
|
21
22
|
async getBlockchainName() {
|
|
22
23
|
const userChainId = await this.clientWallet.getChainId();
|
|
@@ -24,8 +25,8 @@ class EvmAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
|
|
|
24
25
|
}
|
|
25
26
|
async getAllowance(fromTokenAddress, walletAddress, spenderAddress) {
|
|
26
27
|
const [decimals, allowance] = await Promise.all([
|
|
27
|
-
this.
|
|
28
|
-
this.
|
|
28
|
+
this.read(fromTokenAddress, erc20_token_abi_1.erc20TokenAbi, 'decimals'),
|
|
29
|
+
this.read(fromTokenAddress, erc20_token_abi_1.erc20TokenAbi, 'allowance', [walletAddress, spenderAddress])
|
|
29
30
|
]);
|
|
30
31
|
const allowanceWeiBN = new bignumber_js_1.default(allowance);
|
|
31
32
|
const allowanceNonWei = core_1.Token.fromWei(allowanceWeiBN, Number(decimals));
|
|
@@ -43,7 +44,7 @@ class EvmAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
|
|
|
43
44
|
}
|
|
44
45
|
async approve(fromAddress, tokenAddress, spenderAddress, amount) {
|
|
45
46
|
const config = this.encodeApprove(tokenAddress, spenderAddress, amount);
|
|
46
|
-
return this.
|
|
47
|
+
return this.write(fromAddress, config.to, config.value, config.data);
|
|
47
48
|
}
|
|
48
49
|
/**
|
|
49
50
|
* Build encoded approve transaction config.
|
|
@@ -62,7 +63,7 @@ class EvmAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
|
|
|
62
63
|
};
|
|
63
64
|
}
|
|
64
65
|
async needPermit2Approve(token, permit2Address, walletAddress, spenderAddress) {
|
|
65
|
-
const res = await this.
|
|
66
|
+
const res = await this.read(permit2Address, uni_v3_permit_abi_1.UNI_V3_PERMIT_2_ABI, 'allowance', [
|
|
66
67
|
walletAddress,
|
|
67
68
|
token.address,
|
|
68
69
|
spenderAddress
|
|
@@ -96,7 +97,7 @@ class EvmAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
|
|
|
96
97
|
* @param hash Transaction hash
|
|
97
98
|
*/
|
|
98
99
|
async getTransactionReceipt(hash) {
|
|
99
|
-
return this.
|
|
100
|
+
return this.evmPublic.getTransactionReceipt({ hash: hash });
|
|
100
101
|
}
|
|
101
102
|
/**
|
|
102
103
|
* Sends Eth in transaction and resolve the promise when the transaction is included in the block.
|
|
@@ -144,7 +145,7 @@ class EvmAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
|
|
|
144
145
|
value,
|
|
145
146
|
...(params.txOptions.data && { data: params.txOptions.data })
|
|
146
147
|
};
|
|
147
|
-
const gas = await this.
|
|
148
|
+
const gas = await this.evmPublic.estimateGas(gaslessParams);
|
|
148
149
|
const gasfulParams = {
|
|
149
150
|
...gaslessParams,
|
|
150
151
|
...(0, options_1.getGasOptions)(params.txOptions),
|
|
@@ -156,7 +157,7 @@ class EvmAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
|
|
|
156
157
|
gas
|
|
157
158
|
};
|
|
158
159
|
try {
|
|
159
|
-
await this.
|
|
160
|
+
await this.evmPublic.estimateGas(gasfulViemParams);
|
|
160
161
|
}
|
|
161
162
|
catch {
|
|
162
163
|
throw new rubic_sdk_error_1.RubicSdkError('Low native value');
|
|
@@ -237,7 +238,7 @@ class EvmAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
|
|
|
237
238
|
}),
|
|
238
239
|
account: this.walletAddress
|
|
239
240
|
};
|
|
240
|
-
const gas = await this.
|
|
241
|
+
const gas = await this.evmPublic.estimateContractGas(gaslessParams);
|
|
241
242
|
const gasfulParams = {
|
|
242
243
|
...gaslessParams,
|
|
243
244
|
...(0, options_1.getGasOptions)(options),
|
|
@@ -249,7 +250,7 @@ class EvmAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
|
|
|
249
250
|
gas
|
|
250
251
|
};
|
|
251
252
|
try {
|
|
252
|
-
await this.
|
|
253
|
+
await this.evmPublic.estimateContractGas(gasfulViemParams);
|
|
253
254
|
}
|
|
254
255
|
catch {
|
|
255
256
|
throw new rubic_sdk_error_1.RubicSdkError('Low native value');
|
|
@@ -305,5 +306,36 @@ class EvmAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
|
|
|
305
306
|
}
|
|
306
307
|
return { account, chain };
|
|
307
308
|
}
|
|
309
|
+
async read(address, abi, method, methodArgs = []) {
|
|
310
|
+
const result = await this.evmPublic.readContract({
|
|
311
|
+
abi,
|
|
312
|
+
address: address,
|
|
313
|
+
args: methodArgs,
|
|
314
|
+
functionName: method
|
|
315
|
+
});
|
|
316
|
+
return result;
|
|
317
|
+
}
|
|
318
|
+
async writeContract(address, abi, method, value = '0', methodArgs = []) {
|
|
319
|
+
const result = await this.clientWallet.writeContract({
|
|
320
|
+
abi,
|
|
321
|
+
address: address,
|
|
322
|
+
account: address,
|
|
323
|
+
args: methodArgs,
|
|
324
|
+
functionName: method,
|
|
325
|
+
chain: this.evmPublic.chain,
|
|
326
|
+
value: (0, viem_1.parseEther)(value)
|
|
327
|
+
});
|
|
328
|
+
return result;
|
|
329
|
+
}
|
|
330
|
+
async write(address, to, value, data) {
|
|
331
|
+
const result = await this.clientWallet.sendTransaction({
|
|
332
|
+
account: address,
|
|
333
|
+
to: to,
|
|
334
|
+
value: (0, viem_1.parseEther)(value),
|
|
335
|
+
data: data,
|
|
336
|
+
chain: this.evmPublic.chain
|
|
337
|
+
});
|
|
338
|
+
return result;
|
|
339
|
+
}
|
|
308
340
|
}
|
|
309
341
|
exports.EvmAdapterClient = EvmAdapterClient;
|
|
@@ -31,9 +31,6 @@ export declare class EvmAdapter extends AbstractAdapter<PublicActions & PublicCl
|
|
|
31
31
|
workchain: number;
|
|
32
32
|
}>;
|
|
33
33
|
protected createPublicClient(rpcList: string[]): (PublicActions & PublicClient) | null;
|
|
34
|
-
read<T>(address: string, abi: Abi, method: string, methodArgs?: unknown[]): Promise<T>;
|
|
35
|
-
writeContract(address: string, abi: Abi, method: string, value?: string, methodArgs?: unknown[]): Promise<string>;
|
|
36
|
-
write(address: string, to: string, value: string, data: string): Promise<string>;
|
|
37
34
|
multicallByContract<T>(contracts: MulticallParameters, allowErrors?: boolean): Promise<MulticallResponse<T>[]>;
|
|
38
35
|
multicallByAddress<T>(address: string, abi: Abi, method: string, methodArgs?: unknown[][], allowErrors?: boolean): Promise<MulticallResponse<T>[]>;
|
|
39
36
|
static encodeMethodCall(contractAddress: string, contractAbi: Abi, method: string, parameters?: unknown[], value?: string): EvmTransactionConfig;
|
|
@@ -23,12 +23,12 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
23
23
|
const fromTokenAddress = isNative && tokenAmount.blockchain === core_1.BLOCKCHAIN_NAME.METIS
|
|
24
24
|
? '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000'
|
|
25
25
|
: tokenAmount.blockchain;
|
|
26
|
-
await this.writeContract(fromTokenAddress, erc20_token_abi_1.erc20TokenAbi, 'approve', '0', [approveAmount]);
|
|
26
|
+
await this.client.writeContract(fromTokenAddress, erc20_token_abi_1.erc20TokenAbi, 'approve', '0', [approveAmount]);
|
|
27
27
|
}
|
|
28
28
|
constructor(httpClient, adapterOptions, logger, rubicAppParams) {
|
|
29
29
|
super(adapterOptions.blockchain, logger);
|
|
30
30
|
this.public = this.createPublicClient(adapterOptions.rpcList);
|
|
31
|
-
this.client = new evm_adapter_client_1.EvmAdapterClient(this, httpClient, logger, rubicAppParams);
|
|
31
|
+
this.client = new evm_adapter_client_1.EvmAdapterClient(this.public, httpClient, logger, rubicAppParams);
|
|
32
32
|
}
|
|
33
33
|
async callContractMethod(contractAddress, contractAbi, methodName, methodArguments = [], options = {}) {
|
|
34
34
|
return this.public.readContract({
|
|
@@ -124,37 +124,6 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
124
124
|
})
|
|
125
125
|
});
|
|
126
126
|
}
|
|
127
|
-
async read(address, abi, method, methodArgs = []) {
|
|
128
|
-
const result = await this.public.readContract({
|
|
129
|
-
abi,
|
|
130
|
-
address: address,
|
|
131
|
-
args: methodArgs,
|
|
132
|
-
functionName: method
|
|
133
|
-
});
|
|
134
|
-
return result;
|
|
135
|
-
}
|
|
136
|
-
async writeContract(address, abi, method, value = '0', methodArgs = []) {
|
|
137
|
-
const result = await this.client.clientWallet.writeContract({
|
|
138
|
-
abi,
|
|
139
|
-
address: address,
|
|
140
|
-
account: address,
|
|
141
|
-
args: methodArgs,
|
|
142
|
-
functionName: method,
|
|
143
|
-
chain: this.public.chain,
|
|
144
|
-
value: (0, viem_1.parseEther)(value)
|
|
145
|
-
});
|
|
146
|
-
return result;
|
|
147
|
-
}
|
|
148
|
-
async write(address, to, value, data) {
|
|
149
|
-
const result = await this.client.clientWallet.sendTransaction({
|
|
150
|
-
account: address,
|
|
151
|
-
to: to,
|
|
152
|
-
value: (0, viem_1.parseEther)(value),
|
|
153
|
-
data: data,
|
|
154
|
-
chain: this.public.chain
|
|
155
|
-
});
|
|
156
|
-
return result;
|
|
157
|
-
}
|
|
158
127
|
async multicallByContract(contracts, allowErrors = true) {
|
|
159
128
|
const results = await this.public.multicall(contracts);
|
|
160
129
|
const rpcRequestFail = results.every((result) => result?.status === 'failure');
|
|
@@ -295,7 +264,7 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
295
264
|
});
|
|
296
265
|
return new bignumber_js_1.default(nativeBalance.toString());
|
|
297
266
|
}
|
|
298
|
-
const tokenBalance = await this.read(tokenAddress, erc20_token_abi_1.erc20TokenAbi, 'balanceOf', [walletAddress]);
|
|
267
|
+
const tokenBalance = await this.client.read(tokenAddress, erc20_token_abi_1.erc20TokenAbi, 'balanceOf', [walletAddress]);
|
|
299
268
|
return new bignumber_js_1.default(tokenBalance);
|
|
300
269
|
}
|
|
301
270
|
async getTransactionCount(walletAddress) {
|
|
@@ -8,6 +8,8 @@ import { TxStatus } from '../../models/web3-public-models/tx-status';
|
|
|
8
8
|
export declare class SolanaAdapterClient extends AbstractAdapterClient<SolanaWeb3, SolanaSendTxParams, string> {
|
|
9
9
|
private readonly connection;
|
|
10
10
|
constructor(connection: Connection, httpClient: HttpClient, logger?: ICustomLogger, rubicAppParams?: RubicAppAdaptersFactoryParams);
|
|
11
|
+
read<T>(): Promise<T>;
|
|
12
|
+
write<T>(): Promise<T>;
|
|
11
13
|
getBlockchainName(): Promise<BlockchainName>;
|
|
12
14
|
getTransactionStatus(txHash: string): Promise<TxStatus>;
|
|
13
15
|
sendTransaction(params: SolanaSendTxParams): Promise<string>;
|
|
@@ -15,6 +15,12 @@ class SolanaAdapterClient extends abstract_adapter_client_1.AbstractAdapterClien
|
|
|
15
15
|
super(httpClient, logger, rubicAppParams);
|
|
16
16
|
this.connection = connection;
|
|
17
17
|
}
|
|
18
|
+
async read() {
|
|
19
|
+
throw new Error('Method read is not supported');
|
|
20
|
+
}
|
|
21
|
+
async write() {
|
|
22
|
+
throw new Error('Method write is not supported');
|
|
23
|
+
}
|
|
18
24
|
getBlockchainName() {
|
|
19
25
|
return Promise.resolve(core_1.BLOCKCHAIN_NAME.SOLANA);
|
|
20
26
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Abi } from 'viem';
|
|
2
1
|
import { AddressLookupTableAccount, Connection, Keypair, PublicKey, Transaction, TransactionInstruction, VersionedTransaction } from '@solana/web3.js';
|
|
3
2
|
import { HttpClient, ICustomLogger, PriceTokenAmount, SolanaBlockchainName, Token, TokenAmount } from '@cryptorubic/core';
|
|
4
3
|
import BigNumber from 'bignumber.js';
|
|
@@ -27,8 +26,6 @@ export declare class SolanaAdapter extends AbstractAdapter<Connection, SolanaWeb
|
|
|
27
26
|
workchain: number;
|
|
28
27
|
}>;
|
|
29
28
|
private createConection;
|
|
30
|
-
read<T>(_address: string, _abi: Abi, _method: string, _methodArgs?: unknown[]): Promise<T>;
|
|
31
|
-
write<T>(_address: string, _abi: Abi, _method: string, _methodArgs?: unknown[]): Promise<T>;
|
|
32
29
|
simulateTransaction(_config: object, _from: string): Promise<void>;
|
|
33
30
|
checkEnoughBalance(token: TokenAmount | PriceTokenAmount, walletAddress: string): Promise<boolean>;
|
|
34
31
|
getBalance(userAddress: string, tokenAddress: string): Promise<BigNumber>;
|
|
@@ -57,12 +57,6 @@ class SolanaAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
57
57
|
return new web3_js_1.Connection(rpcList[0], 'confirmed');
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
-
async read(_address, _abi, _method, _methodArgs = []) {
|
|
61
|
-
throw new Error('Method multicall is not supported');
|
|
62
|
-
}
|
|
63
|
-
async write(_address, _abi, _method, _methodArgs = []) {
|
|
64
|
-
throw new Error('Method multicall is not supported');
|
|
65
|
-
}
|
|
66
60
|
async simulateTransaction(_config, _from) { }
|
|
67
61
|
async checkEnoughBalance(token, walletAddress) {
|
|
68
62
|
const balance = await this.getBalance(walletAddress, token.address);
|
|
@@ -8,6 +8,8 @@ import { ExecuteTransactionBlockParams, SuiClient, SuiTransactionBlockResponse }
|
|
|
8
8
|
export declare class SuiAdapterClient extends AbstractAdapterClient<WalletAdapter, SuiSendTxParams, string> {
|
|
9
9
|
private readonly suiClient;
|
|
10
10
|
constructor(suiClient: SuiClient, httpClient: HttpClient, logger?: ICustomLogger, rubicAppParams?: RubicAppAdaptersFactoryParams);
|
|
11
|
+
read<T>(): Promise<T>;
|
|
12
|
+
write<T>(): Promise<T>;
|
|
11
13
|
getBlockchainName(): Promise<BlockchainName>;
|
|
12
14
|
getTransactionStatus(srcTxHash: string): Promise<TxStatus>;
|
|
13
15
|
sendTransaction(params: SuiSendTxParams): Promise<string>;
|
|
@@ -11,6 +11,12 @@ class SuiAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
|
|
|
11
11
|
super(httpClient, logger, rubicAppParams);
|
|
12
12
|
this.suiClient = suiClient;
|
|
13
13
|
}
|
|
14
|
+
async read() {
|
|
15
|
+
throw new Error('Method read is not supported');
|
|
16
|
+
}
|
|
17
|
+
async write() {
|
|
18
|
+
throw new Error('Method write is not supported');
|
|
19
|
+
}
|
|
14
20
|
getBlockchainName() {
|
|
15
21
|
return Promise.resolve(core_1.BLOCKCHAIN_NAME.SUI);
|
|
16
22
|
}
|
|
@@ -18,8 +18,6 @@ export declare class SuiAdapter extends AbstractAdapter<SuiClient, WalletAdapter
|
|
|
18
18
|
blockNumber: number;
|
|
19
19
|
workchain: number;
|
|
20
20
|
}>;
|
|
21
|
-
read<T>(_address: string, _abi: Abi, _method: string, _methodArgs?: unknown[]): Promise<T>;
|
|
22
|
-
write<T>(_address: string, _abi: Abi, _method: string, _methodArgs?: unknown[]): Promise<T>;
|
|
23
21
|
multicallByAddress<T>(_address: string, _abi: Abi, _method: string, _methodArgs?: unknown[][], _allowErrors?: boolean): Promise<MulticallResponse<T>[]>;
|
|
24
22
|
simulateTransaction(_config: object, _from: string): Promise<void>;
|
|
25
23
|
callForTokensInfo(tokenAddresses: string[] | ReadonlyArray<string>): Promise<Token<SuiBlockchainName>[]>;
|
|
@@ -31,12 +31,6 @@ class SuiAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
31
31
|
const stringEpoch = epochInfo.data[0].epoch;
|
|
32
32
|
return Number(stringEpoch);
|
|
33
33
|
}
|
|
34
|
-
async read(_address, _abi, _method, _methodArgs = []) {
|
|
35
|
-
throw new Error('Method read is not supported');
|
|
36
|
-
}
|
|
37
|
-
async write(_address, _abi, _method, _methodArgs = []) {
|
|
38
|
-
throw new Error('Method write is not supported');
|
|
39
|
-
}
|
|
40
34
|
async multicallByAddress(_address, _abi, _method, _methodArgs = [], _allowErrors = true) {
|
|
41
35
|
throw new Error('Method multicall is not supported');
|
|
42
36
|
}
|
|
@@ -13,6 +13,8 @@ export declare class TonAdapterClient extends AbstractAdapterClient<TonConnectUI
|
|
|
13
13
|
private readonly tonApi;
|
|
14
14
|
private readonly tonClient;
|
|
15
15
|
constructor(tonApi: TonApiService, config: TonAdapterConfig, httpClient: HttpClient, logger?: ICustomLogger, rubicAppParams?: RubicAppAdaptersFactoryParams);
|
|
16
|
+
read<T>(): Promise<T>;
|
|
17
|
+
write<T>(): Promise<T>;
|
|
16
18
|
getBlockchainName(): Promise<BlockchainName>;
|
|
17
19
|
getTransactionStatus(srcTxHash: string): Promise<TxStatus>;
|
|
18
20
|
sendTransaction(params: TonSendTxParams): Promise<string>;
|
|
@@ -16,6 +16,12 @@ class TonAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
|
|
|
16
16
|
this.tonApi = tonApi;
|
|
17
17
|
this.tonClient = new ton_1.TonClient(config.tonClientConfig);
|
|
18
18
|
}
|
|
19
|
+
async read() {
|
|
20
|
+
throw new Error('Method read is not supported');
|
|
21
|
+
}
|
|
22
|
+
async write() {
|
|
23
|
+
throw new Error('Method write is not supported');
|
|
24
|
+
}
|
|
19
25
|
getBlockchainName() {
|
|
20
26
|
return Promise.resolve(core_1.BLOCKCHAIN_NAME.TON);
|
|
21
27
|
}
|
|
@@ -21,8 +21,6 @@ export declare class TonAdapter extends AbstractAdapter<TonClient, TonConnectUI,
|
|
|
21
21
|
workchain: number;
|
|
22
22
|
}>;
|
|
23
23
|
callForTokensInfo(tokenAddresses: string[] | ReadonlyArray<string>): Promise<Token<BlockchainName>[]>;
|
|
24
|
-
read<T>(args: unknown): Promise<T>;
|
|
25
|
-
write(args: unknown): Promise<string>;
|
|
26
24
|
getAllFormatsOfAddress(walletAddress: string): Promise<TonApiParseAddressResp>;
|
|
27
25
|
checkEnoughBalance(token: TokenAmount | PriceTokenAmount, walletAddress: string): Promise<boolean>;
|
|
28
26
|
getBalance(walletAddress: string, tokenAddress?: string): Promise<BigNumber>;
|
|
@@ -70,12 +70,6 @@ class TonAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
70
70
|
}));
|
|
71
71
|
return necessaryInfo;
|
|
72
72
|
}
|
|
73
|
-
read(args) {
|
|
74
|
-
throw new Error('Not implemented');
|
|
75
|
-
}
|
|
76
|
-
write(args) {
|
|
77
|
-
throw new Error('Not implemented');
|
|
78
|
-
}
|
|
79
73
|
async getAllFormatsOfAddress(walletAddress) {
|
|
80
74
|
return this.tonApi.getAllFormatsOfAddress(walletAddress);
|
|
81
75
|
}
|
|
@@ -5,12 +5,14 @@ import { RubicAppAdaptersFactoryParams } from '../../../constants/models/create-
|
|
|
5
5
|
import { TronSendTxParams } from '../models/tron-send-tx-params';
|
|
6
6
|
import { TxStatus } from '../../models/web3-public-models/tx-status';
|
|
7
7
|
import { TronTransactionConfig } from 'packages/web3/src/lib/utils/models/tron-transaction-config';
|
|
8
|
-
import { TronAdapter } from '../tron-adapter';
|
|
9
8
|
import { ApproveAdapterClient } from '../../models/approve-adapter';
|
|
10
9
|
import { AllowanceInfo } from '../../models/common-types';
|
|
10
|
+
import { TronParameters } from 'packages/web3/src/lib/utils/models/tron-parameters';
|
|
11
11
|
export declare class TronAdapterClient extends AbstractAdapterClient<TronWeb, TronSendTxParams, string> implements ApproveAdapterClient<TronTransactionConfig> {
|
|
12
|
-
private readonly
|
|
13
|
-
constructor(
|
|
12
|
+
private readonly tronWeb;
|
|
13
|
+
constructor(tronWeb: TronWeb, httpClient: HttpClient, logger?: ICustomLogger, rubicAppParams?: RubicAppAdaptersFactoryParams);
|
|
14
|
+
read<T>(contractAddress: string, contractAbi: any, methodName: string, methodArguments?: unknown[]): Promise<T>;
|
|
15
|
+
write(contractAddress: string, methodSignature: string, parameters: TronParameters): Promise<string>;
|
|
14
16
|
getBlockchainName(): Promise<BlockchainName>;
|
|
15
17
|
getAllowance(fromTokenAddress: string, walletAddress: string, spender: string): Promise<AllowanceInfo>;
|
|
16
18
|
needApprove(from: TokenAmount, walletAddress: string, spender: string): Promise<boolean>;
|
|
@@ -8,19 +8,32 @@ const trc_20_contract_abi_1 = require("../../constants/trc-20-contract-abi");
|
|
|
8
8
|
const tx_status_1 = require("../../models/web3-public-models/tx-status");
|
|
9
9
|
const parse_tron_error_1 = require("../utils/parse-tron-error");
|
|
10
10
|
const tron_adapter_1 = require("../tron-adapter");
|
|
11
|
+
const tron_web3_pure_1 = require("packages/web3/src/lib/utils/web3-types/tron-web3-pure");
|
|
11
12
|
class TronAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
|
|
12
|
-
constructor(
|
|
13
|
+
constructor(tronWeb, httpClient, logger, rubicAppParams) {
|
|
13
14
|
super(httpClient, logger, rubicAppParams);
|
|
14
|
-
this.
|
|
15
|
+
this.tronWeb = tronWeb;
|
|
16
|
+
}
|
|
17
|
+
async read(contractAddress, contractAbi, methodName, methodArguments = []) {
|
|
18
|
+
this.tronWeb.setAddress(contractAddress);
|
|
19
|
+
const contract = await this.tronWeb.contract(contractAbi, contractAddress);
|
|
20
|
+
const response = await contract[methodName](...methodArguments).call();
|
|
21
|
+
return tron_web3_pure_1.TronWeb3Pure.flattenParameterToPrimitive(response);
|
|
22
|
+
}
|
|
23
|
+
async write(contractAddress, methodSignature, parameters) {
|
|
24
|
+
const transaction = await this.clientWallet.transactionBuilder.triggerSmartContract(contractAddress, methodSignature, {}, parameters, this.walletAddress);
|
|
25
|
+
const signedTransaction = await this.clientWallet.trx.sign(transaction.transaction);
|
|
26
|
+
const receipt = await this.clientWallet.trx.sendRawTransaction(signedTransaction);
|
|
27
|
+
return receipt.transaction.txID;
|
|
15
28
|
}
|
|
16
29
|
getBlockchainName() {
|
|
17
30
|
return Promise.resolve(core_1.BLOCKCHAIN_NAME.TRON);
|
|
18
31
|
}
|
|
19
32
|
async getAllowance(fromTokenAddress, walletAddress, spender) {
|
|
20
33
|
const [contract, decimals, allowance] = await Promise.all([
|
|
21
|
-
this.
|
|
22
|
-
this.
|
|
23
|
-
this.
|
|
34
|
+
this.tronWeb.contract(trc_20_contract_abi_1.TRC20_CONTRACT_ABI, fromTokenAddress),
|
|
35
|
+
this.read(fromTokenAddress, trc_20_contract_abi_1.TRC20_CONTRACT_ABI, 'decimals'),
|
|
36
|
+
this.read(fromTokenAddress, trc_20_contract_abi_1.TRC20_CONTRACT_ABI, 'allowance', [spender])
|
|
24
37
|
]);
|
|
25
38
|
const allowanceWeiBN = new bignumber_js_1.default(allowance);
|
|
26
39
|
const allowanceNonWei = core_1.Token.fromWei(allowanceWeiBN, Number(decimals));
|
|
@@ -34,7 +47,7 @@ class TronAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient
|
|
|
34
47
|
}
|
|
35
48
|
async approve(fromAddress, tokenAddress, spenderAddress, amount) {
|
|
36
49
|
const config = this.encodeApprove(tokenAddress, spenderAddress, amount);
|
|
37
|
-
return this.
|
|
50
|
+
return this.write(config.to, config.signature, config.arguments);
|
|
38
51
|
}
|
|
39
52
|
encodeApprove(tokenAddress, spenderAddress, amount) {
|
|
40
53
|
const amountWei = amount ?? new bignumber_js_1.default(2).pow(256).minus(1).toFixed();
|
|
@@ -58,13 +71,13 @@ class TronAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient
|
|
|
58
71
|
* @param hash Transaction hash.
|
|
59
72
|
*/
|
|
60
73
|
async getTransactionInfo(hash) {
|
|
61
|
-
return this.
|
|
74
|
+
return this.tronWeb.trx.getTransactionInfo(hash);
|
|
62
75
|
}
|
|
63
76
|
async sendTransaction(params) {
|
|
64
77
|
try {
|
|
65
|
-
const transaction = await this.
|
|
66
|
-
const signedTransaction = await this.
|
|
67
|
-
const receipt = await this.
|
|
78
|
+
const transaction = await this.tronWeb.transactionBuilder.triggerSmartContract(params.contractAddress, params.methodSignature, params.txOptions, params.parameters, this.walletAddress);
|
|
79
|
+
const signedTransaction = await this.tronWeb.trx.sign(transaction.transaction);
|
|
80
|
+
const receipt = await this.tronWeb.trx.sendRawTransaction(signedTransaction);
|
|
68
81
|
if (params.txOptions.onTransactionHash) {
|
|
69
82
|
params.txOptions.onTransactionHash(receipt.transaction.txID);
|
|
70
83
|
}
|
|
@@ -77,7 +90,7 @@ class TronAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient
|
|
|
77
90
|
}
|
|
78
91
|
async trySendTransaction(params) {
|
|
79
92
|
try {
|
|
80
|
-
await this.
|
|
93
|
+
await this.tronWeb.transactionBuilder.estimateEnergy(params.contractAddress, params.methodSignature, {}, params.parameters, this.walletAddress);
|
|
81
94
|
}
|
|
82
95
|
catch (err) {
|
|
83
96
|
const errMessage = typeof err === 'object' ? err.message : err;
|
|
@@ -27,7 +27,6 @@ export declare class TronAdapter extends AbstractAdapter<TronWeb, TronWeb, TronB
|
|
|
27
27
|
}>;
|
|
28
28
|
checkEnoughBalance(token: TokenAmount | PriceTokenAmount, walletAddress: string): Promise<boolean>;
|
|
29
29
|
private multicall;
|
|
30
|
-
read<T>(contractAddress: string, contractAbi: any, methodName: string, methodArguments?: unknown[]): Promise<T>;
|
|
31
30
|
private multicallContractsMethodsByOne;
|
|
32
31
|
callForTokensInfo(tokenAddresses: string[] | ReadonlyArray<string>): Promise<Token[]>;
|
|
33
32
|
getBalance(userAddress: string, tokenAddress?: string): Promise<BigNumber>;
|
|
@@ -35,5 +34,4 @@ export declare class TronAdapter extends AbstractAdapter<TronWeb, TronWeb, TronB
|
|
|
35
34
|
convertTronAddressToHex(address: string): Promise<string>;
|
|
36
35
|
static encodeMethodCall(contractAddress: string, contractAbi: Abi, methodName: string, methodArguments: TronParameters, callValue?: string, feeLimit?: number): TronTransactionConfig;
|
|
37
36
|
private static flattenTypesToString;
|
|
38
|
-
write(contractAddress: string, methodSignature: string, parameters: TronParameters): Promise<string>;
|
|
39
37
|
}
|
|
@@ -18,7 +18,7 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
18
18
|
super(core_1.BLOCKCHAIN_NAME.TRON, logger);
|
|
19
19
|
this.multicallAddress = 'T9ziQU4EBteJzjzMzhHELdhgWFqwzS5Vki';
|
|
20
20
|
this.public = new tronweb_1.TronWeb({ fullHost: rpcList[0] });
|
|
21
|
-
this.client = new tron_adapter_client_1.TronAdapterClient(this, httpClient, logger, rubicAppParams);
|
|
21
|
+
this.client = new tron_adapter_client_1.TronAdapterClient(this.public, httpClient, logger, rubicAppParams);
|
|
22
22
|
}
|
|
23
23
|
async callContractMethod(contractAddress, contractAbi, methodName, methodArguments = []) {
|
|
24
24
|
this.public.setAddress(contractAddress);
|
|
@@ -94,17 +94,11 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
94
94
|
// @ts-ignore
|
|
95
95
|
return contract.aggregateViewCalls(calls).call();
|
|
96
96
|
}
|
|
97
|
-
async read(contractAddress, contractAbi, methodName, methodArguments = []) {
|
|
98
|
-
this.public.setAddress(contractAddress);
|
|
99
|
-
const contract = await this.public.contract(contractAbi, contractAddress);
|
|
100
|
-
const response = await contract[methodName](...methodArguments).call();
|
|
101
|
-
return tron_web3_pure_1.TronWeb3Pure.flattenParameterToPrimitive(response);
|
|
102
|
-
}
|
|
103
97
|
multicallContractsMethodsByOne(contractAbi, contractsData) {
|
|
104
98
|
return Promise.all(contractsData.map((contractData) => {
|
|
105
99
|
return Promise.all(contractData.methodsData.map(async (methodData) => {
|
|
106
100
|
try {
|
|
107
|
-
const output = (await this.read(contractData.contractAddress, contractAbi, methodData.methodName, methodData.methodArguments));
|
|
101
|
+
const output = (await this.client.read(contractData.contractAddress, contractAbi, methodData.methodName, methodData.methodArguments));
|
|
108
102
|
return {
|
|
109
103
|
output,
|
|
110
104
|
success: true
|
|
@@ -205,11 +199,5 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
205
199
|
return abiInput.type;
|
|
206
200
|
}) || []);
|
|
207
201
|
}
|
|
208
|
-
async write(contractAddress, methodSignature, parameters) {
|
|
209
|
-
const transaction = await this.client.clientWallet.transactionBuilder.triggerSmartContract(contractAddress, methodSignature, {}, parameters, this.client.walletAddress);
|
|
210
|
-
const signedTransaction = await this.client.clientWallet.trx.sign(transaction.transaction);
|
|
211
|
-
const receipt = await this.client.clientWallet.trx.sendRawTransaction(signedTransaction);
|
|
212
|
-
return receipt.transaction.txID;
|
|
213
|
-
}
|
|
214
202
|
}
|
|
215
203
|
exports.TronAdapter = TronAdapter;
|
|
@@ -57,7 +57,5 @@ export declare abstract class AbstractAdapter<P, W, B extends BlockchainName, Se
|
|
|
57
57
|
}>;
|
|
58
58
|
needPreswapAction(token: TokenAmount, contractAddress: string, walletAddress: string, amount: string | BigNumber): Promise<boolean>;
|
|
59
59
|
handlePreswap(contractAddress: string, walletAddress: string, tokenAmount: TokenAmount): Promise<void>;
|
|
60
|
-
abstract read<T>(...args: unknown[]): Promise<T>;
|
|
61
|
-
abstract write(...args: unknown[]): Promise<string>;
|
|
62
60
|
static getRandomBytes(bytes: number): string;
|
|
63
61
|
}
|
|
@@ -14,6 +14,8 @@ export declare abstract class AbstractAdapterClient<ClientWallet, SendTxParams,
|
|
|
14
14
|
abstract getBlockchainName(): Promise<BlockchainName | undefined>;
|
|
15
15
|
abstract sendTransaction(params: SendTxParams): Promise<SendTxResponse>;
|
|
16
16
|
abstract getTransactionStatus(srcTxHash: string): Promise<TxStatus>;
|
|
17
|
+
abstract read<T>(...args: unknown[]): Promise<T>;
|
|
18
|
+
abstract write(...args: unknown[]): Promise<string>;
|
|
17
19
|
/**
|
|
18
20
|
* Checks, that selected blockchain in wallet is equal to passed blockchain.
|
|
19
21
|
*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ErrorInterface } from '@cryptorubic/core';
|
|
1
2
|
export interface EvmTransactionConfig {
|
|
2
3
|
to: string;
|
|
3
4
|
data: string;
|
|
@@ -6,4 +7,5 @@ export interface EvmTransactionConfig {
|
|
|
6
7
|
gasPrice?: string;
|
|
7
8
|
maxFeePerGas?: string;
|
|
8
9
|
maxPriorityFeePerGas?: string;
|
|
10
|
+
warnings?: ErrorInterface[];
|
|
9
11
|
}
|