@cryptorubic/web3 1.6.3 → 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 +1 -1
- package/src/lib/adapter/adapters/adapter-solana/signer/solana-adapter-signer.d.ts +2 -0
- package/src/lib/adapter/adapters/adapter-solana/signer/solana-adapter-signer.js +26 -0
- package/src/lib/adapter/adapters/adapter-tron/signer/tron-adapter-signer.d.ts +1 -1
- package/src/lib/adapter/adapters/models/transfer-tx-params.d.ts +13 -0
- package/src/lib/adapter/constants/models/solana-web3.d.ts +1 -1
- package/src/lib/adapter/adapters/adapter-tron/models/tron-transfer-tx-params.d.ts +0 -7
- /package/src/lib/adapter/adapters/{adapter-tron/models/tron-transfer-tx-params.js → models/transfer-tx-params.js} +0 -0
package/package.json
CHANGED
|
@@ -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 '
|
|
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
|
|
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;
|
|
File without changes
|