@cryptorubic/web3 1.6.4-alpha-rub-2694.0 → 1.7.0-alpha.clearswap.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cryptorubic/web3",
3
- "version": "1.6.4-alpha-rub-2694.0",
3
+ "version": "1.7.0-alpha.clearswap.1",
4
4
  "dependencies": {
5
5
  "@ethersproject/bignumber": "^5.8.0",
6
6
  "@mysten/sui": "^1.24.0",
@@ -362,8 +362,8 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
362
362
  });
363
363
  const gasfulViemOptions = {
364
364
  ...gaslessParams,
365
- ...(0, options_1.getViemGasOptions)(options),
366
- gas: gas.toString()
365
+ gas: gas.toString(),
366
+ gasPriceOptions: (0, options_1.getGasOptions)(options)
367
367
  };
368
368
  const receipt = await this.signer.executeContractMethod(tokenAddress, erc20_token_abi_1.erc20TokenAbi, 'approve', [spenderAddress, BigInt(rawValue.toFixed(0))], gasfulViemOptions);
369
369
  return receipt.transactionHash;
@@ -79,8 +79,8 @@ class EvmAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigner {
79
79
  : gas;
80
80
  const gasfulParams = {
81
81
  ...gaslessParams,
82
- ...(0, options_1.getGasOptions)(params.txOptions),
83
- gas: calculatedGas.toString()
82
+ gas: calculatedGas.toString(),
83
+ gasPriceOptions: (0, options_1.getGasOptions)(params.txOptions)
84
84
  };
85
85
  const gasfulViemParams = {
86
86
  ...gaslessParams,
@@ -91,8 +91,7 @@ class EvmAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigner {
91
91
  const sendParams = {
92
92
  ...gasfulParams,
93
93
  ...(params.txOptions.onTransactionHash && {
94
- onTransactionHash: params.txOptions.onTransactionHash,
95
- gasPriceOptions: params.txOptions?.gasPriceOptions
94
+ onTransactionHash: params.txOptions.onTransactionHash
96
95
  })
97
96
  };
98
97
  const receipt = await this.sendTransaction({ txOptions: sendParams });
@@ -4,6 +4,7 @@ import { ClientAdaptersFactoryParams } from '../../../models/create-factory-para
4
4
  import { SolanaSendTxParams } from '../models/solana-send-tx-params';
5
5
  import { Connection } from '@solana/web3.js';
6
6
  import { AbstractAdapterSigner } from '../../common/signer/abstract-adapter-signer';
7
+ import { SolanaTransferTxParams } from '../../models/transfer-tx-params';
7
8
  export declare class SolanaAdapterSigner extends AbstractAdapterSigner<SolanaWeb3, SolanaSendTxParams, string> {
8
9
  private readonly publicRef;
9
10
  get publicClient(): Connection;
@@ -13,5 +14,6 @@ export declare class SolanaAdapterSigner extends AbstractAdapterSigner<SolanaWeb
13
14
  write<T>(): Promise<T>;
14
15
  getBlockchainName(): Promise<BlockchainName>;
15
16
  sendTransaction(params: SolanaSendTxParams): Promise<string>;
17
+ transfer(params: SolanaTransferTxParams): Promise<string>;
16
18
  private waitForTxConfirmation;
17
19
  }
@@ -9,6 +9,7 @@ const user_reject_error_1 = require("../../../../errors/blockchain/user-reject.e
9
9
  const errors_1 = require("../../utils/errors");
10
10
  const abstract_adapter_signer_1 = require("../../common/signer/abstract-adapter-signer");
11
11
  const tx_reverted_in_chain_error_1 = require("../../../../errors/common/tx-reverted-in-chain.error");
12
+ const spl_token_1 = require("@solana/spl-token");
12
13
  class SolanaAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigner {
13
14
  get publicClient() {
14
15
  if (!this.publicRef.public) {
@@ -70,6 +71,31 @@ class SolanaAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigne
70
71
  throw (0, errors_1.parseError)(err);
71
72
  }
72
73
  }
74
+ async transfer(params) {
75
+ const tokenPK = new web3_js_1.PublicKey(params.tokenAddress);
76
+ const senderPK = new web3_js_1.PublicKey(this.walletAddress);
77
+ const receiverPK = new web3_js_1.PublicKey(params.receiver);
78
+ const senderATA = await (0, spl_token_1.getAssociatedTokenAddress)(tokenPK, senderPK, true);
79
+ const receiverATA = await (0, spl_token_1.getAssociatedTokenAddress)(tokenPK, receiverPK, true);
80
+ const receiverAtaInfo = await this.publicClient.getAccountInfo(receiverATA).catch(() => null);
81
+ const instructions = [];
82
+ if (!receiverAtaInfo) {
83
+ instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(senderPK, // payer
84
+ receiverATA, // ATA address
85
+ receiverPK, // owner
86
+ tokenPK // mint
87
+ ));
88
+ }
89
+ instructions.push((0, spl_token_1.createTransferInstruction)(senderATA, receiverATA, senderPK, BigInt(params.tokenWeiAmount), [], spl_token_1.TOKEN_PROGRAM_ID));
90
+ const transaction = new web3_js_1.Transaction().add(...instructions);
91
+ const signedTx = await this.wallet.signTransaction(transaction);
92
+ signedTx.feePayer = new web3_js_1.PublicKey(this.walletAddress);
93
+ signedTx.recentBlockhash = (await this.publicClient.getLatestBlockhash()).blockhash;
94
+ const signature = await this.publicClient.sendRawTransaction(signedTx.serialize(), { maxRetries: 3, skipPreflight: false });
95
+ params.txOptions.onTransactionHash?.(signature);
96
+ await this.waitForTxConfirmation(signature);
97
+ return signature;
98
+ }
73
99
  async waitForTxConfirmation(signature) {
74
100
  const deadline = Date.now() + 3 * 60 * 1000;
75
101
  let fetchedTx = null;
@@ -4,7 +4,7 @@ import { BlockchainName, HttpClient, ICustomLogger } from '@cryptorubic/core';
4
4
  import { ClientAdaptersFactoryParams } from '../../../models/create-factory-params';
5
5
  import { TronSendTxParams } from '../models/tron-send-tx-params';
6
6
  import { TronParameters } from '../../../../utils/models/tron-parameters';
7
- import { TronTransferTxParams } from '../models/tron-transfer-tx-params';
7
+ import { TronTransferTxParams } from '../../models/transfer-tx-params';
8
8
  export declare class TronAdapterSigner extends AbstractAdapterSigner<TronWeb, TronSendTxParams, string> {
9
9
  private readonly publicRef;
10
10
  get publicClient(): TronWeb;
@@ -0,0 +1,13 @@
1
+ import { SolanaTransactionOptions } from '../adapter-solana/models/solana-send-tx-params';
2
+ import { TronTransactionOptions } from '../adapter-tron/models/tron-send-tx-params';
3
+ export interface TransferTxParams {
4
+ receiver: string;
5
+ tokenWeiAmount: string;
6
+ tokenAddress: string;
7
+ }
8
+ export interface TronTransferTxParams extends TransferTxParams {
9
+ txOptions: TronTransactionOptions;
10
+ }
11
+ export interface SolanaTransferTxParams extends TransferTxParams {
12
+ txOptions: SolanaTransactionOptions;
13
+ }
@@ -4,7 +4,7 @@ export interface SolanaWeb3 {
4
4
  toBytes(): Uint8Array;
5
5
  };
6
6
  isConnected: boolean;
7
- signTransaction(transaction: Transaction | VersionedTransaction): Promise<Transaction | VersionedTransaction>;
7
+ signTransaction<T extends Transaction | VersionedTransaction>(transaction: T): Promise<T>;
8
8
  signAllTransactions(transactions: Transaction[]): Promise<Transaction[]>;
9
9
  signMessage(message: Uint8Array, encoding: string): Promise<{
10
10
  signature: Uint8Array;
@@ -1,7 +0,0 @@
1
- import { TronTransactionOptions } from './tron-send-tx-params';
2
- export interface TronTransferTxParams {
3
- receiver: string;
4
- tokenWeiAmount: string;
5
- tokenAddress: string;
6
- txOptions: TronTransactionOptions;
7
- }