@cryptorubic/web3 1.0.0-alpha.no-sdk.22 → 1.0.0-alpha.no-sdk.24

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.
Files changed (41) hide show
  1. package/package.json +1 -1
  2. package/src/index.d.ts +7 -7
  3. package/src/index.js +7 -7
  4. package/src/lib/adapter/adapters/adapter-bitcoin/bitcoin-adapter.d.ts +4 -2
  5. package/src/lib/adapter/adapters/adapter-bitcoin/bitcoin-adapter.js +11 -6
  6. package/src/lib/adapter/adapters/adapter-bitcoin/{client/bitcoin-adapter-client.d.ts → signer/bitcoin-adapter-signer.d.ts} +2 -3
  7. package/src/lib/adapter/adapters/adapter-bitcoin/{client/bitcoin-adapter-client.js → signer/bitcoin-adapter-signer.js} +6 -9
  8. package/src/lib/adapter/adapters/adapter-evm/evm-adapter.d.ts +36 -4
  9. package/src/lib/adapter/adapters/adapter-evm/evm-adapter.js +110 -84
  10. package/src/lib/adapter/adapters/adapter-evm/{client/evm-adapter-client.d.ts → signer/evm-adapter-signer.d.ts} +3 -36
  11. package/src/lib/adapter/adapters/adapter-evm/{client/evm-adapter-client.js → signer/evm-adapter-signer.js} +13 -120
  12. package/src/lib/adapter/adapters/adapter-solana/{client/solana-adapter-client.d.ts → signer/solana-adapter-signer.d.ts} +2 -3
  13. package/src/lib/adapter/adapters/adapter-solana/{client/solana-adapter-client.js → signer/solana-adapter-signer.js} +5 -8
  14. package/src/lib/adapter/adapters/adapter-solana/solana-adapter.d.ts +3 -2
  15. package/src/lib/adapter/adapters/adapter-solana/solana-adapter.js +5 -2
  16. package/src/lib/adapter/adapters/adapter-sui/{client/sui-adapter-client.d.ts → signer/sui-adapter-signer.d.ts} +2 -3
  17. package/src/lib/adapter/adapters/adapter-sui/{client/sui-adapter-client.js → signer/sui-adapter-signer.js} +6 -9
  18. package/src/lib/adapter/adapters/adapter-sui/sui-adapter.d.ts +3 -2
  19. package/src/lib/adapter/adapters/adapter-sui/sui-adapter.js +5 -2
  20. package/src/lib/adapter/adapters/adapter-ton/{client/ton-adapter-client.d.ts → signer/ton-adapter-signer.d.ts} +4 -5
  21. package/src/lib/adapter/adapters/adapter-ton/{client/ton-adapter-client.js → signer/ton-adapter-signer.js} +7 -11
  22. package/src/lib/adapter/adapters/adapter-ton/ton-adapter.d.ts +3 -2
  23. package/src/lib/adapter/adapters/adapter-ton/ton-adapter.js +6 -2
  24. package/src/lib/adapter/adapters/adapter-tron/signer/tron-adapter-signer.d.ts +21 -0
  25. package/src/lib/adapter/adapters/adapter-tron/signer/tron-adapter-signer.js +67 -0
  26. package/src/lib/adapter/adapters/adapter-tron/tron-adapter.d.ts +9 -2
  27. package/src/lib/adapter/adapters/adapter-tron/tron-adapter.js +52 -3
  28. package/src/lib/adapter/adapters/common/abstract-adapter.d.ts +3 -2
  29. package/src/lib/adapter/adapters/common/abstract-adapter.js +1 -25
  30. package/src/lib/adapter/adapters/common/{client/abstract-adapter-client.d.ts → signer/abstract-adapter-signer.d.ts} +4 -5
  31. package/src/lib/adapter/adapters/common/{client/abstract-adapter-client.js → signer/abstract-adapter-signer.js} +7 -7
  32. package/src/lib/adapter/adapters/models/approve-adapter.d.ts +7 -6
  33. package/src/lib/adapter/adapters/models/approve-adapter.js +46 -3
  34. package/src/lib/adapter/blockchain-adapter-factory.service.js +3 -3
  35. package/src/lib/adapter/constants/chain-configs/chain-configs.d.ts +1 -1
  36. package/src/lib/adapter/constants/chain-configs/chain-configs.js +27 -0
  37. package/src/lib/adapter/constants/viem-blockchain-mapping.d.ts +1 -1
  38. package/src/lib/adapter/constants/viem-blockchain-mapping.js +3 -2
  39. package/src/lib/adapter/models/create-factory-params.d.ts +3 -3
  40. package/src/lib/adapter/adapters/adapter-tron/client/tron-adapter-client.d.ts +0 -30
  41. package/src/lib/adapter/adapters/adapter-tron/client/tron-adapter-client.js +0 -119
@@ -1,122 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EvmAdapterClient = void 0;
3
+ exports.EvmAdapterSigner = void 0;
4
4
  const core_1 = require("@cryptorubic/core");
5
- const abstract_adapter_client_1 = require("../../common/client/abstract-adapter-client");
5
+ const abstract_adapter_signer_1 = require("../../common/signer/abstract-adapter-signer");
6
6
  const viem_1 = require("viem");
7
7
  const actions_1 = require("viem/actions");
8
8
  const options_1 = require("../../utils/options");
9
9
  const viem_blockchain_mapping_1 = require("../../../constants/viem-blockchain-mapping");
10
- const bignumber_js_1 = require("bignumber.js");
11
- const uni_v3_permit_abi_1 = require("../../constants/uni-v3-permit-abi");
12
- const erc20_token_abi_1 = require("../../constants/erc20-token-abi");
13
10
  const parse_evm_error_1 = require("../utils/parse-evm-error");
14
11
  const rubic_sdk_error_1 = require("../../../../errors/rubic-sdk.error");
15
- const evm_adapter_1 = require("../evm-adapter");
16
12
  const tx_status_1 = require("../../models/web3-public-models/tx-status");
17
- const insufficient_funds_gas_price_value_error_1 = require("../../../../errors/cross-chain/insufficient-funds-gas-price-value.error");
18
- class EvmAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
13
+ class EvmAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigner {
19
14
  constructor(evmPublic, httpClient, logger, clientParams) {
20
15
  super(httpClient, logger, clientParams);
21
16
  this.evmPublic = evmPublic;
22
17
  }
23
18
  async getBlockchainName() {
24
- const userChainId = await this.clientWallet.getChainId();
19
+ const userChainId = await this.wallet.getChainId();
25
20
  return core_1.BlockchainsInfo.getBlockchainNameById(userChainId);
26
21
  }
27
- async getAllowance(fromTokenAddress, walletAddress, spenderAddress) {
28
- const [decimals, allowance] = await Promise.all([
29
- this.read(fromTokenAddress, erc20_token_abi_1.erc20TokenAbi, 'decimals'),
30
- this.read(fromTokenAddress, erc20_token_abi_1.erc20TokenAbi, 'allowance', [walletAddress, spenderAddress])
31
- ]);
32
- const allowanceWeiBN = new bignumber_js_1.default(allowance);
33
- const allowanceNonWei = core_1.Token.fromWei(allowanceWeiBN, Number(decimals));
34
- return { allowanceNonWei, allowanceWei: allowanceWeiBN };
35
- }
36
- async needApprove(token, contractAddress, walletAddress, amount) {
37
- // Native coin in METIS can be Token required approve
38
- if (token.isNative && token.blockchain !== core_1.BLOCKCHAIN_NAME.METIS) {
39
- return false;
40
- }
41
- // Special native address for METIS native coin
42
- const fromTokenAddress = token.isNative && token.blockchain === core_1.BLOCKCHAIN_NAME.METIS ? '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000' : token.address;
43
- const { allowanceWei } = await this.getAllowance(fromTokenAddress, walletAddress, contractAddress);
44
- return allowanceWei.lt(token.weiAmount);
45
- }
46
- /**
47
- * Executes approve method in ERC-20 token contract.
48
- * @param tokenAddress Address of the smart-contract corresponding to the token.
49
- * @param spenderAddress Wallet or contract address to approve.
50
- * @param amount Token amount to approve in wei.
51
- * @param [options] Additional options.
52
- * @returns Approval transaction hash.
53
- */
54
- async approveTokens(tokenAddress, spenderAddress, amount = 'infinity', options = {}) {
55
- try {
56
- const rawValue = amount === 'infinity' ? new bignumber_js_1.default(2).pow(256).minus(1) : amount;
57
- const encodedApprove = this.encodeApprove(tokenAddress, spenderAddress, rawValue.toFixed(0));
58
- const gaslessParams = {
59
- account: this.walletAddress,
60
- to: tokenAddress,
61
- value: BigInt('0'),
62
- data: encodedApprove.data
63
- };
64
- const gas = await this.evmPublic.estimateGas({
65
- ...gaslessParams,
66
- ...(0, options_1.getViemGasOptions)(options)
67
- });
68
- const gasfulViemOptions = {
69
- ...gaslessParams,
70
- ...(0, options_1.getViemGasOptions)(options),
71
- gas: gas.toString()
72
- };
73
- const receipt = await this.executeContractMethod(tokenAddress, erc20_token_abi_1.erc20TokenAbi, 'approve', [spenderAddress, BigInt(rawValue.toFixed(0))], gasfulViemOptions);
74
- return receipt.transactionHash;
75
- }
76
- catch (err) {
77
- if (err?.message?.includes('gas required exceeds allowance') || err?.message?.includes('insufficient balance to pay for gas')) {
78
- throw new insufficient_funds_gas_price_value_error_1.InsufficientFundsGasPriceValueError();
79
- }
80
- console.debug(err);
81
- throw err;
82
- }
83
- }
84
- /**
85
- * Build encoded approve transaction config.
86
- * @param tokenAddress Address of the smart-contract corresponding to the token.
87
- * @param spenderAddress Wallet or contract address to approve.
88
- * @param amount wei amount of tokens in approval window in spending cap field
89
- * @returns Encoded approve transaction config.
90
- */
91
- encodeApprove(tokenAddress, spenderAddress, amount) {
92
- const amountWei = amount ?? new bignumber_js_1.default(2).pow(256).minus(1).toFixed();
93
- const tx = evm_adapter_1.EvmAdapter.encodeMethodCall(tokenAddress, erc20_token_abi_1.erc20TokenAbi, 'approve', [spenderAddress, amountWei]);
94
- return {
95
- data: tx.data,
96
- to: tx.to,
97
- value: tx.value
98
- };
99
- }
100
- async needPermit2Approve(token, permit2Address, walletAddress, spenderAddress) {
101
- const res = await this.read(permit2Address, uni_v3_permit_abi_1.UNI_V3_PERMIT_2_ABI, 'allowance', [
102
- walletAddress,
103
- token.address,
104
- spenderAddress
105
- ]);
106
- const [amount, expiration, _nonce] = res;
107
- return token.weiAmount.gt(amount) || new bignumber_js_1.default(Date.now()).gt(Number(expiration) * 1000);
108
- }
109
- /**
110
- * @param tokenAddress Token address you want to approve for spending
111
- * @param permit2Address Addres of permit2 contract
112
- * @param spenderAddress Contract address spending your tokens
113
- * @param amount Approved amount
114
- * @param deadline Ms number added to current time (Date.now()) until approve expiration
115
- */
116
- async approveOnPermit2(tokenAddress, spenderAddress, amount = 'infinity', options = {}) {
117
- const rawValue = amount === 'infinity' ? new bignumber_js_1.default(2).pow(256).minus(1) : amount;
118
- return this.executeContractMethod(tokenAddress, uni_v3_permit_abi_1.UNI_V3_PERMIT_2_ABI, 'approve', [spenderAddress, BigInt(rawValue.toString())], options);
119
- }
120
22
  async getTransactionStatus(hash) {
121
23
  const txReceipt = await this.getTransactionReceipt(hash);
122
24
  if (txReceipt === null) {
@@ -154,9 +56,9 @@ class EvmAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
154
56
  ...(params.txOptions.gas && { gas: BigInt(params.txOptions.gas) }),
155
57
  chain
156
58
  };
157
- const hash = await this.clientWallet.sendTransaction(viemParams);
59
+ const hash = await this.wallet.sendTransaction(viemParams);
158
60
  params.txOptions?.onTransactionHash?.(hash);
159
- return (0, actions_1.waitForTransactionReceipt)(this.clientWallet, { hash });
61
+ return (0, actions_1.waitForTransactionReceipt)(this.wallet, { hash });
160
62
  }
161
63
  catch (err) {
162
64
  console.error('Send transaction error', err);
@@ -242,9 +144,9 @@ class EvmAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
242
144
  account: account,
243
145
  chain: chain
244
146
  };
245
- const hash = await this.clientWallet.writeContract(sendParams);
147
+ const hash = await this.wallet.writeContract(sendParams);
246
148
  options?.onTransactionHash?.(hash);
247
- return (0, actions_1.waitForTransactionReceipt)(this.clientWallet, { hash });
149
+ return (0, actions_1.waitForTransactionReceipt)(this.wallet, { hash });
248
150
  }
249
151
  catch (err) {
250
152
  console.error(`Method execution error. ${err}`);
@@ -322,14 +224,14 @@ class EvmAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
322
224
  return test;
323
225
  }
324
226
  async signMessage(message) {
325
- return this.clientWallet.signMessage({
227
+ return this.wallet.signMessage({
326
228
  account: this.walletAddress,
327
229
  message: message
328
230
  });
329
231
  }
330
232
  async getChainAndAccount() {
331
233
  const account = this.walletAddress;
332
- const chainId = await this.clientWallet.getChainId();
234
+ const chainId = await this.wallet.getChainId();
333
235
  const chainName = core_1.BlockchainsInfo.getBlockchainNameById(chainId);
334
236
  if (!chainName) {
335
237
  throw Error(`Unsupported chain ID: ${chainId}. Please provide a valid EVM blockchain ID`);
@@ -340,17 +242,8 @@ class EvmAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
340
242
  }
341
243
  return { account, chain };
342
244
  }
343
- async read(address, abi, method, methodArgs = []) {
344
- const result = await this.evmPublic.readContract({
345
- abi,
346
- address: address,
347
- args: methodArgs,
348
- functionName: method
349
- });
350
- return result;
351
- }
352
245
  async writeContract(address, abi, method, value = '0', methodArgs = []) {
353
- const result = await this.clientWallet.writeContract({
246
+ const result = await this.wallet.writeContract({
354
247
  abi,
355
248
  address: address,
356
249
  account: address,
@@ -362,7 +255,7 @@ class EvmAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
362
255
  return result;
363
256
  }
364
257
  async write(address, to, value, data, options = {}) {
365
- const result = await this.clientWallet.sendTransaction({
258
+ const result = await this.wallet.sendTransaction({
366
259
  account: address,
367
260
  to: to,
368
261
  value: (0, viem_1.parseEther)(value),
@@ -374,4 +267,4 @@ class EvmAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
374
267
  return result;
375
268
  }
376
269
  }
377
- exports.EvmAdapterClient = EvmAdapterClient;
270
+ exports.EvmAdapterSigner = EvmAdapterSigner;
@@ -3,12 +3,11 @@ import { SolanaWeb3 } from '../../../constants/models/solana-web3';
3
3
  import { ClientAdaptersFactoryParams } from '../../../models/create-factory-params';
4
4
  import { SolanaSendTxParams } from '../models/solana-send-tx-params';
5
5
  import { Connection } from '@solana/web3.js';
6
- import { AbstractAdapterClient } from '../../common/client/abstract-adapter-client';
6
+ import { AbstractAdapterSigner } from '../../common/signer/abstract-adapter-signer';
7
7
  import { TxStatus } from '../../models/web3-public-models/tx-status';
8
- export declare class SolanaAdapterClient extends AbstractAdapterClient<SolanaWeb3, SolanaSendTxParams, string> {
8
+ export declare class SolanaAdapterSigner extends AbstractAdapterSigner<SolanaWeb3, SolanaSendTxParams, string> {
9
9
  private readonly connection;
10
10
  constructor(connection: Connection, httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
11
- read<T>(): Promise<T>;
12
11
  write<T>(): Promise<T>;
13
12
  getBlockchainName(): Promise<BlockchainName>;
14
13
  getTransactionStatus(txHash: string): Promise<TxStatus>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SolanaAdapterClient = void 0;
3
+ exports.SolanaAdapterSigner = void 0;
4
4
  const core_1 = require("@cryptorubic/core");
5
5
  const web3_js_1 = require("@solana/web3.js");
6
6
  const waitFor_1 = require("../../utils/waitFor");
@@ -8,16 +8,13 @@ const timeout_error_1 = require("../../../../errors/common/timeout.error");
8
8
  const js_base64_1 = require("js-base64");
9
9
  const user_reject_error_1 = require("../../../../errors/blockchain/user-reject.error");
10
10
  const errors_1 = require("../../utils/errors");
11
- const abstract_adapter_client_1 = require("../../common/client/abstract-adapter-client");
11
+ const abstract_adapter_signer_1 = require("../../common/signer/abstract-adapter-signer");
12
12
  const tx_status_1 = require("../../models/web3-public-models/tx-status");
13
- class SolanaAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
13
+ class SolanaAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigner {
14
14
  constructor(connection, httpClient, logger, clientParams) {
15
15
  super(httpClient, logger, clientParams);
16
16
  this.connection = connection;
17
17
  }
18
- async read() {
19
- throw new Error('Method read is not supported');
20
- }
21
18
  async write() {
22
19
  throw new Error('Method write is not supported');
23
20
  }
@@ -45,7 +42,7 @@ class SolanaAdapterClient extends abstract_adapter_client_1.AbstractAdapterClien
45
42
  try {
46
43
  const decodedData = js_base64_1.Base64.toUint8Array(params.txOptions.data);
47
44
  const tx = web3_js_1.VersionedTransaction.deserialize(decodedData);
48
- const signedTx = await this.clientWallet.signTransaction(tx);
45
+ const signedTx = await this.wallet.signTransaction(tx);
49
46
  const txBase64 = js_base64_1.Base64.fromUint8Array(signedTx.serialize());
50
47
  let signature;
51
48
  if (params.txOptions?.sponsorParams) {
@@ -97,4 +94,4 @@ class SolanaAdapterClient extends abstract_adapter_client_1.AbstractAdapterClien
97
94
  throw new timeout_error_1.TimeoutError();
98
95
  }
99
96
  }
100
- exports.SolanaAdapterClient = SolanaAdapterClient;
97
+ exports.SolanaAdapterSigner = SolanaAdapterSigner;
@@ -5,15 +5,16 @@ import { AbstractAdapter } from '../common/abstract-adapter';
5
5
  import { SolanaRawInstruction } from '../models/solana-web3-types';
6
6
  import { ClientAdaptersFactoryParams } from '../../models/create-factory-params';
7
7
  import { SolanaWeb3 } from '../../constants/models/solana-web3';
8
- import { SolanaAdapterClient } from './client/solana-adapter-client';
8
+ import { SolanaAdapterSigner } from './signer/solana-adapter-signer';
9
9
  import { Web3PrimitiveType } from '../../../utils/models/primitive-types';
10
10
  import { ContractMulticallResponse } from '../models/web3-public-models/contract-multicall-response';
11
11
  export declare const NATIVE_SOLANA_MINT_ADDRESS = "So11111111111111111111111111111111111111111";
12
12
  export declare class SolanaAdapter extends AbstractAdapter<Connection, SolanaWeb3, SolanaBlockchainName> {
13
13
  private readonly httpClient;
14
- readonly client: SolanaAdapterClient;
14
+ readonly signer: SolanaAdapterSigner;
15
15
  constructor(rpcList: string[], httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
16
16
  callContractMethod<T extends Web3PrimitiveType = string>(): Promise<T>;
17
+ read<T>(): Promise<T>;
17
18
  /**
18
19
  * Gets balance of multiple tokens.
19
20
  * @param address Wallet address.
@@ -10,18 +10,21 @@ const js_base64_1 = require("js-base64");
10
10
  const abstract_adapter_1 = require("../common/abstract-adapter");
11
11
  const web3_pure_1 = require("../../../utils/web3-pure");
12
12
  const solana_tokens_service_1 = require("./services/solana-tokens-service");
13
- const solana_adapter_client_1 = require("./client/solana-adapter-client");
13
+ const solana_adapter_signer_1 = require("./signer/solana-adapter-signer");
14
14
  exports.NATIVE_SOLANA_MINT_ADDRESS = 'So11111111111111111111111111111111111111111';
15
15
  class SolanaAdapter extends abstract_adapter_1.AbstractAdapter {
16
16
  constructor(rpcList, httpClient, logger, clientParams) {
17
17
  super(core_1.BLOCKCHAIN_NAME.SOLANA, logger);
18
18
  this.httpClient = httpClient;
19
19
  this.public = this.createConection(rpcList);
20
- this.client = new solana_adapter_client_1.SolanaAdapterClient(this.public, httpClient, logger, clientParams);
20
+ this.signer = new solana_adapter_signer_1.SolanaAdapterSigner(this.public, httpClient, logger, clientParams);
21
21
  }
22
22
  async callContractMethod() {
23
23
  throw new Error('Method call is not supported');
24
24
  }
25
+ async read() {
26
+ throw new Error('Method read is not supported');
27
+ }
25
28
  /**
26
29
  * Gets balance of multiple tokens.
27
30
  * @param address Wallet address.
@@ -1,14 +1,13 @@
1
1
  import { BlockchainName, HttpClient, ICustomLogger } from '@cryptorubic/core';
2
- import { AbstractAdapterClient } from '../../common/client/abstract-adapter-client';
2
+ import { AbstractAdapterSigner } from '../../common/signer/abstract-adapter-signer';
3
3
  import { ClientAdaptersFactoryParams } from '../../../models/create-factory-params';
4
4
  import { SuiSendTxParams } from '../models/sui-send-tx-params';
5
5
  import { WalletAdapter } from '@suiet/wallet-sdk';
6
6
  import { TxStatus } from '../../models/web3-public-models/tx-status';
7
7
  import { ExecuteTransactionBlockParams, SuiClient, SuiTransactionBlockResponse } from '@mysten/sui/dist/cjs/client';
8
- export declare class SuiAdapterClient extends AbstractAdapterClient<WalletAdapter, SuiSendTxParams, string> {
8
+ export declare class SuiAdapterSigner extends AbstractAdapterSigner<WalletAdapter, SuiSendTxParams, string> {
9
9
  private readonly suiClient;
10
10
  constructor(suiClient: SuiClient, httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
11
- read<T>(): Promise<T>;
12
11
  write<T>(): Promise<T>;
13
12
  getBlockchainName(): Promise<BlockchainName>;
14
13
  getTransactionStatus(srcTxHash: string): Promise<TxStatus>;
@@ -1,19 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SuiAdapterClient = void 0;
3
+ exports.SuiAdapterSigner = void 0;
4
4
  const core_1 = require("@cryptorubic/core");
5
- const abstract_adapter_client_1 = require("../../common/client/abstract-adapter-client");
5
+ const abstract_adapter_signer_1 = require("../../common/signer/abstract-adapter-signer");
6
6
  const user_reject_error_1 = require("../../../../errors/blockchain/user-reject.error");
7
7
  const parse_evm_error_1 = require("../../adapter-evm/utils/parse-evm-error");
8
8
  const tx_status_1 = require("../../models/web3-public-models/tx-status");
9
- class SuiAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
9
+ class SuiAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigner {
10
10
  constructor(suiClient, httpClient, logger, clientParams) {
11
11
  super(httpClient, logger, clientParams);
12
12
  this.suiClient = suiClient;
13
13
  }
14
- async read() {
15
- throw new Error('Method read is not supported');
16
- }
17
14
  async write() {
18
15
  throw new Error('Method write is not supported');
19
16
  }
@@ -35,8 +32,8 @@ class SuiAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
35
32
  }
36
33
  async sendTransaction(params) {
37
34
  try {
38
- const account = this.clientWallet.accounts[0];
39
- const signedTx = await this.clientWallet.features['sui:signTransaction'].signTransaction({
35
+ const account = this.wallet.accounts[0];
36
+ const signedTx = await this.wallet.features['sui:signTransaction'].signTransaction({
40
37
  account: account,
41
38
  transaction: params.txOptions.transactionBlock,
42
39
  chain: 'sui:mainnet'
@@ -61,4 +58,4 @@ class SuiAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
61
58
  return this.suiClient.executeTransactionBlock(params);
62
59
  }
63
60
  }
64
- exports.SuiAdapterClient = SuiAdapterClient;
61
+ exports.SuiAdapterSigner = SuiAdapterSigner;
@@ -4,14 +4,15 @@ import { SuiClient } from '@mysten/sui/client';
4
4
  import BigNumber from 'bignumber.js';
5
5
  import { AbstractAdapter } from '../common/abstract-adapter';
6
6
  import { WalletAdapter } from '@suiet/wallet-sdk';
7
- import { SuiAdapterClient } from './client/sui-adapter-client';
7
+ import { SuiAdapterSigner } from './signer/sui-adapter-signer';
8
8
  import { ClientAdaptersFactoryParams } from '../../models/create-factory-params';
9
9
  import { Web3PrimitiveType } from '../../../utils/models/primitive-types';
10
10
  import { ContractMulticallResponse } from '../models/web3-public-models/contract-multicall-response';
11
11
  export declare class SuiAdapter extends AbstractAdapter<SuiClient, WalletAdapter, SuiBlockchainName> {
12
- readonly client: SuiAdapterClient;
12
+ readonly signer: SuiAdapterSigner;
13
13
  constructor(rpcList: string[], httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
14
14
  callContractMethod<T extends Web3PrimitiveType = string>(): Promise<T>;
15
+ read<T>(): Promise<T>;
15
16
  getTokensBalances(userAddress: string, tokensAddresses: string[]): Promise<BigNumber[]>;
16
17
  multicallContractsMethods<Output extends Web3PrimitiveType>(): Promise<ContractMulticallResponse<Output>[][]>;
17
18
  getBlockNumber(): Promise<number | {
@@ -6,16 +6,19 @@ const client_1 = require("@mysten/sui/client");
6
6
  const bignumber_js_1 = require("bignumber.js");
7
7
  const abstract_adapter_1 = require("../common/abstract-adapter");
8
8
  const web3_pure_1 = require("../../../utils/web3-pure");
9
- const sui_adapter_client_1 = require("./client/sui-adapter-client");
9
+ const sui_adapter_signer_1 = require("./signer/sui-adapter-signer");
10
10
  class SuiAdapter extends abstract_adapter_1.AbstractAdapter {
11
11
  constructor(rpcList, httpClient, logger, clientParams) {
12
12
  super(core_1.BLOCKCHAIN_NAME.SUI, logger);
13
13
  this.public = new client_1.SuiClient({ url: rpcList[0] });
14
- this.client = new sui_adapter_client_1.SuiAdapterClient(this.public, httpClient, logger, clientParams);
14
+ this.signer = new sui_adapter_signer_1.SuiAdapterSigner(this.public, httpClient, logger, clientParams);
15
15
  }
16
16
  async callContractMethod() {
17
17
  throw new Error('Method call is not supported');
18
18
  }
19
+ async read() {
20
+ throw new Error('Method read is not supported');
21
+ }
19
22
  async getTokensBalances(userAddress, tokensAddresses) {
20
23
  const allUserTokens = await this.public.getAllBalances({ owner: userAddress });
21
24
  return tokensAddresses.map((address) => {
@@ -1,5 +1,5 @@
1
1
  import { BlockchainName, HttpClient, ICustomLogger } from '@cryptorubic/core';
2
- import { AbstractAdapterClient } from '../../common/client/abstract-adapter-client';
2
+ import { AbstractAdapterSigner } from '../../common/signer/abstract-adapter-signer';
3
3
  import { ClientAdaptersFactoryParams } from '../../../models/create-factory-params';
4
4
  import { TxStatus } from '../../models/web3-public-models/tx-status';
5
5
  import { TonSendTxParams } from '../models/ton-send-tx-params';
@@ -7,13 +7,12 @@ import { TonConnectUI } from '@tonconnect/ui';
7
7
  import { BasicSendTransactionOptions } from '../../models/basic-transaction-options';
8
8
  import { Address } from '@ton/core';
9
9
  import { TonApiService } from '../services/ton-api.service';
10
- import { TonAdapterConfig } from '../../models/ton-adapter-config';
10
+ import { TonClient } from '@ton/ton';
11
11
  import { TonTransactionConfig } from '../../../../utils/models/ton-transaction-config';
12
- export declare class TonAdapterClient extends AbstractAdapterClient<TonConnectUI, TonSendTxParams, string> {
12
+ export declare class TonAdapterSigner extends AbstractAdapterSigner<TonConnectUI, TonSendTxParams, string> {
13
13
  private readonly tonApi;
14
14
  private readonly tonClient;
15
- constructor(tonApi: TonApiService, config: TonAdapterConfig, httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
16
- read<T>(): Promise<T>;
15
+ constructor(tonApi: TonApiService, tonClient: TonClient, httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
17
16
  write<T>(): Promise<T>;
18
17
  getBlockchainName(): Promise<BlockchainName>;
19
18
  getTransactionStatus(srcTxHash: string): Promise<TxStatus>;
@@ -1,23 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TonAdapterClient = void 0;
3
+ exports.TonAdapterSigner = void 0;
4
4
  const core_1 = require("@cryptorubic/core");
5
- const abstract_adapter_client_1 = require("../../common/client/abstract-adapter-client");
5
+ const abstract_adapter_signer_1 = require("../../common/signer/abstract-adapter-signer");
6
6
  const user_reject_error_1 = require("../../../../errors/blockchain/user-reject.error");
7
7
  const tx_status_1 = require("../../models/web3-public-models/tx-status");
8
8
  const rubic_sdk_error_1 = require("../../../../errors/rubic-sdk.error");
9
9
  const errors_1 = require("../../utils/errors");
10
10
  const core_2 = require("@ton/core");
11
11
  const waitFor_1 = require("../../utils/waitFor");
12
- const ton_1 = require("@ton/ton");
13
- class TonAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
14
- constructor(tonApi, config, httpClient, logger, clientParams) {
12
+ class TonAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigner {
13
+ constructor(tonApi, tonClient, httpClient, logger, clientParams) {
15
14
  super(httpClient, logger, clientParams);
16
15
  this.tonApi = tonApi;
17
- this.tonClient = new ton_1.TonClient(config.tonClientConfig);
18
- }
19
- async read() {
20
- throw new Error('Method read is not supported');
16
+ this.tonClient = tonClient;
21
17
  }
22
18
  async write() {
23
19
  throw new Error('Method write is not supported');
@@ -34,7 +30,7 @@ class TonAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
34
30
  }
35
31
  async sendTransaction(params) {
36
32
  try {
37
- const { boc } = await this.clientWallet.sendTransaction({
33
+ const { boc } = await this.wallet.sendTransaction({
38
34
  validUntil: Math.floor(Date.now() / 1000) + 360,
39
35
  messages: params.txOptions.messages
40
36
  });
@@ -167,4 +163,4 @@ class TonAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
167
163
  return addressResult.stack.readAddress();
168
164
  }
169
165
  }
170
- exports.TonAdapterClient = TonAdapterClient;
166
+ exports.TonAdapterSigner = TonAdapterSigner;
@@ -5,14 +5,15 @@ import { TonAdapterConfig } from '../models/ton-adapter-config';
5
5
  import BigNumber from 'bignumber.js';
6
6
  import { AbstractAdapter } from '../common/abstract-adapter';
7
7
  import { TonConnectUI } from '@tonconnect/ui';
8
- import { TonAdapterClient } from './client/ton-adapter-client';
8
+ import { TonAdapterSigner } from './signer/ton-adapter-signer';
9
9
  import { ClientAdaptersFactoryParams } from '../../models/create-factory-params';
10
10
  import { Web3PrimitiveType } from '../../../utils/models/primitive-types';
11
11
  import { ContractMulticallResponse } from '../models/web3-public-models/contract-multicall-response';
12
12
  export declare class TonAdapter extends AbstractAdapter<TonClient, TonConnectUI, TonBlockchainName> {
13
- readonly client: TonAdapterClient;
13
+ readonly signer: TonAdapterSigner;
14
14
  private readonly tonApi;
15
15
  constructor(httpClient: HttpClient, config: TonAdapterConfig, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
16
+ read<T>(): Promise<T>;
16
17
  callContractMethod<T extends Web3PrimitiveType = string>(): Promise<T>;
17
18
  getTokensBalances(userAddress: string, tokensAddresses: string[]): Promise<BigNumber[]>;
18
19
  multicallContractsMethods<Output extends Web3PrimitiveType>(): Promise<ContractMulticallResponse<Output>[][]>;
@@ -7,12 +7,16 @@ const ton_1 = require("@ton/ton");
7
7
  const bignumber_js_1 = require("bignumber.js");
8
8
  const abstract_adapter_1 = require("../common/abstract-adapter");
9
9
  const web3_pure_1 = require("../../../utils/web3-pure");
10
- const ton_adapter_client_1 = require("./client/ton-adapter-client");
10
+ const ton_adapter_signer_1 = require("./signer/ton-adapter-signer");
11
11
  class TonAdapter extends abstract_adapter_1.AbstractAdapter {
12
12
  constructor(httpClient, config, logger, clientParams) {
13
13
  super(core_1.BLOCKCHAIN_NAME.TON, logger);
14
14
  this.tonApi = new ton_api_service_1.TonApiService(httpClient, config.tonApiConfig, logger);
15
- this.client = new ton_adapter_client_1.TonAdapterClient(this.tonApi, config, httpClient, logger, clientParams);
15
+ this.public = new ton_1.TonClient(config.tonClientConfig);
16
+ this.signer = new ton_adapter_signer_1.TonAdapterSigner(this.tonApi, this.public, httpClient, logger, clientParams);
17
+ }
18
+ async read() {
19
+ throw new Error('Method read is not supported');
16
20
  }
17
21
  async callContractMethod() {
18
22
  throw new Error('Method call is not supported');
@@ -0,0 +1,21 @@
1
+ import { TronWeb } from 'tronweb';
2
+ import { AbstractAdapterSigner } from '../../common/signer/abstract-adapter-signer';
3
+ import { BlockchainName, HttpClient, ICustomLogger } from '@cryptorubic/core';
4
+ import { ClientAdaptersFactoryParams } from '../../../models/create-factory-params';
5
+ import { TronSendTxParams } from '../models/tron-send-tx-params';
6
+ import { TxStatus } from '../../models/web3-public-models/tx-status';
7
+ import { TronParameters } from '../../../../utils/models/tron-parameters';
8
+ export declare class TronAdapterSigner extends AbstractAdapterSigner<TronWeb, TronSendTxParams, string> {
9
+ private readonly tronWeb;
10
+ constructor(tronWeb: TronWeb, httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
11
+ write(contractAddress: string, methodSignature: string, parameters: TronParameters): Promise<string>;
12
+ getBlockchainName(): Promise<BlockchainName>;
13
+ getTransactionStatus(srcTxHash: string): Promise<TxStatus>;
14
+ /**
15
+ * Gets mined transaction info.
16
+ * @param hash Transaction hash.
17
+ */
18
+ private getTransactionInfo;
19
+ sendTransaction(params: TronSendTxParams): Promise<string>;
20
+ trySendTransaction(params: TronSendTxParams): Promise<string>;
21
+ }
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TronAdapterSigner = void 0;
4
+ const abstract_adapter_signer_1 = require("../../common/signer/abstract-adapter-signer");
5
+ const core_1 = require("@cryptorubic/core");
6
+ const tx_status_1 = require("../../models/web3-public-models/tx-status");
7
+ const parse_tron_error_1 = require("../utils/parse-tron-error");
8
+ class TronAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigner {
9
+ constructor(tronWeb, httpClient, logger, clientParams) {
10
+ super(httpClient, logger, clientParams);
11
+ this.tronWeb = tronWeb;
12
+ }
13
+ async write(contractAddress, methodSignature, parameters) {
14
+ const transaction = await this.wallet.transactionBuilder.triggerSmartContract(contractAddress, methodSignature, {}, parameters, this.walletAddress);
15
+ const signedTransaction = await this.wallet.trx.sign(transaction.transaction);
16
+ const receipt = await this.wallet.trx.sendRawTransaction(signedTransaction);
17
+ return receipt.transaction.txID;
18
+ }
19
+ getBlockchainName() {
20
+ return Promise.resolve(core_1.BLOCKCHAIN_NAME.TRON);
21
+ }
22
+ async getTransactionStatus(srcTxHash) {
23
+ const txReceipt = await this.getTransactionInfo(srcTxHash);
24
+ if (txReceipt?.receipt) {
25
+ if (txReceipt.result === 'FAILED') {
26
+ return tx_status_1.TX_STATUS.FAIL;
27
+ }
28
+ return tx_status_1.TX_STATUS.SUCCESS;
29
+ }
30
+ return tx_status_1.TX_STATUS.PENDING;
31
+ }
32
+ /**
33
+ * Gets mined transaction info.
34
+ * @param hash Transaction hash.
35
+ */
36
+ async getTransactionInfo(hash) {
37
+ return this.tronWeb.trx.getTransactionInfo(hash);
38
+ }
39
+ async sendTransaction(params) {
40
+ try {
41
+ const transaction = await this.tronWeb.transactionBuilder.triggerSmartContract(params.contractAddress, params.methodSignature, params.txOptions, params.parameters, this.walletAddress);
42
+ const signedTransaction = await this.tronWeb.trx.sign(transaction.transaction);
43
+ const receipt = await this.tronWeb.trx.sendRawTransaction(signedTransaction);
44
+ if (params.txOptions.onTransactionHash) {
45
+ params.txOptions.onTransactionHash(receipt.transaction.txID);
46
+ }
47
+ return receipt.transaction.txID;
48
+ }
49
+ catch (err) {
50
+ console.error('Method execution error: ', err);
51
+ throw (0, parse_tron_error_1.parseTronError)(err);
52
+ }
53
+ }
54
+ async trySendTransaction(params) {
55
+ try {
56
+ await this.tronWeb.transactionBuilder.estimateEnergy(params.contractAddress, params.methodSignature, {}, params.parameters, this.walletAddress);
57
+ }
58
+ catch (err) {
59
+ const errMessage = typeof err === 'object' ? err.message : err;
60
+ if (errMessage !== 'this node does not support estimate energy') {
61
+ throw new Error('Tron transaction simulation error');
62
+ }
63
+ }
64
+ return this.sendTransaction(params);
65
+ }
66
+ }
67
+ exports.TronAdapterSigner = TronAdapterSigner;
@@ -9,9 +9,11 @@ import { ContractMulticallResponse } from '../../../utils/models/contract-multic
9
9
  import { TronWeb3PrimitiveType, Web3PrimitiveType } from '../../../utils/models/primitive-types';
10
10
  import { MethodData } from '../../../utils/models/method-data';
11
11
  import { ClientAdaptersFactoryParams } from '../../models/create-factory-params';
12
- import { TronAdapterClient } from './client/tron-adapter-client';
12
+ import { TronAdapterSigner } from './signer/tron-adapter-signer';
13
+ import { TronTransactionOptions } from './models/tron-send-tx-params';
14
+ import { AllowanceInfo } from '../models/common-types';
13
15
  export declare class TronAdapter extends AbstractAdapter<TronWeb, TronWeb, TronBlockchainName> {
14
- readonly client: TronAdapterClient;
16
+ readonly signer: TronAdapterSigner;
15
17
  private readonly multicallAddress;
16
18
  needPreswapAction(): Promise<boolean>;
17
19
  constructor(rpcList: (string | {
@@ -35,5 +37,10 @@ export declare class TronAdapter extends AbstractAdapter<TronWeb, TronWeb, TronB
35
37
  getTokenBalance(userAddress: string, tokenAddress: string): Promise<BigNumber>;
36
38
  convertTronAddressToHex(address: string): Promise<string>;
37
39
  static encodeMethodCall(contractAddress: string, contractAbi: Abi, methodName: string, methodArguments: TronParameters, callValue?: string, feeLimit?: number): TronTransactionConfig;
40
+ read<T>(contractAddress: string, contractAbi: any, methodName: string, methodArguments?: unknown[]): Promise<T>;
38
41
  private static flattenTypesToString;
42
+ getAllowance(fromTokenAddress: string, _walletAddress: string, spender: string): Promise<AllowanceInfo>;
43
+ needApprove(from: TokenAmount, walletAddress: string, spender: string): Promise<boolean>;
44
+ approveTokens(tokenAddress: string, spenderAddress: string, amount?: BigNumber | 'infinity', options?: TronTransactionOptions): Promise<string>;
45
+ encodeApprove(tokenAddress: string, spenderAddress: string, amount?: string): TronTransactionConfig;
39
46
  }