@cryptorubic/web3 0.8.9-alpha-rub-70.0 → 0.8.10-alpha-squid-solana.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,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cryptorubic/web3",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.10-alpha-squid-solana.1",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"tslib": "^2.3.0",
|
|
6
6
|
"bignumber.js": "9.1.2",
|
|
7
|
-
"@cryptorubic/core": "0.8.
|
|
7
|
+
"@cryptorubic/core": "0.8.10-alpha-squid-solana.1",
|
|
8
8
|
"viem": "^2.19.1",
|
|
9
9
|
"web3-utils": "^4.3.1",
|
|
10
10
|
"@ton/ton": "^15.1.0",
|
|
11
11
|
"@solana/web3.js": "1.95.3",
|
|
12
12
|
"@solflare-wallet/utl-sdk": "^1.4.0",
|
|
13
13
|
"@ethersproject/bignumber": "^5.7.0",
|
|
14
|
-
"@cryptorubic/tron-types": "0.8.
|
|
14
|
+
"@cryptorubic/tron-types": "0.8.10-alpha-squid-solana.1",
|
|
15
15
|
"bitcoin-address-validation": "^2.2.3",
|
|
16
16
|
"axios": "0.27.2",
|
|
17
17
|
"crc-32": "^1.2.2",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Abi, MulticallResponse, MulticallParameters } from 'viem';
|
|
2
2
|
import { AbstractAdapter } from './abstract-adapter';
|
|
3
|
-
import { AddressLookupTableAccount, Connection, TransactionInstruction, VersionedTransaction } from '@solana/web3.js';
|
|
3
|
+
import { AddressLookupTableAccount, Connection, PublicKey, Transaction, TransactionInstruction, VersionedTransaction } from '@solana/web3.js';
|
|
4
4
|
import { HttpClient, ICustomLogger, PriceTokenAmount, SolanaBlockchainName, Token, TokenAmount } from '@cryptorubic/core';
|
|
5
5
|
import { EvmTransactionConfig } from '../../utils/models/evm-transaction-config';
|
|
6
6
|
import BigNumber from 'bignumber.js';
|
|
@@ -27,4 +27,8 @@ export declare class SolanaAdapter extends AbstractAdapter<Connection, Connectio
|
|
|
27
27
|
parseRawInstruction(rawInstruction: SolanaRawInstruction[], dataFormat: BufferEncoding): TransactionInstruction[];
|
|
28
28
|
parseLUTAddresses(lookupTableAddresses: string[]): Promise<AddressLookupTableAccount[]>;
|
|
29
29
|
createVersionedTransaction(instructions: TransactionInstruction[], walletAddress: string, addressLookupTableAccounts?: AddressLookupTableAccount[]): Promise<VersionedTransaction>;
|
|
30
|
+
createTransferData(fromToken: PriceTokenAmount, walletAddress: string, receiver: string, convertToVersionedTx: boolean): Promise<Transaction | VersionedTransaction>;
|
|
31
|
+
createNativeTransfer(fromAddress: PublicKey, toAddress: PublicKey, fromWeiAmount: string): Transaction;
|
|
32
|
+
createTokenTransfer(fromAddress: PublicKey, toAddress: PublicKey, fromTokenAddress: string, fromWeiAmount: string): Promise<Transaction>;
|
|
33
|
+
getLatestBlockhash(): Promise<string>;
|
|
30
34
|
}
|
|
@@ -113,7 +113,7 @@ class SolanaAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
113
113
|
return accounts.filter((v) => !!v);
|
|
114
114
|
}
|
|
115
115
|
async createVersionedTransaction(instructions, walletAddress, addressLookupTableAccounts = []) {
|
|
116
|
-
const
|
|
116
|
+
const blockhash = await this.getLatestBlockhash();
|
|
117
117
|
const message = new web3_js_1.TransactionMessage({
|
|
118
118
|
instructions,
|
|
119
119
|
payerKey: new web3_js_1.PublicKey(walletAddress),
|
|
@@ -121,5 +121,49 @@ class SolanaAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
121
121
|
}).compileToV0Message(addressLookupTableAccounts);
|
|
122
122
|
return new web3_js_1.VersionedTransaction(message);
|
|
123
123
|
}
|
|
124
|
+
async createTransferData(fromToken, walletAddress, receiver, convertToVersionedTx) {
|
|
125
|
+
const fromAddress = new web3_js_1.PublicKey(walletAddress);
|
|
126
|
+
const toAddress = new web3_js_1.PublicKey(receiver);
|
|
127
|
+
this.logger?.customLog('111111111111111', [fromAddress, toAddress]);
|
|
128
|
+
const transaction = fromToken.isNative
|
|
129
|
+
? this.createNativeTransfer(fromAddress, toAddress, fromToken.stringWeiAmount)
|
|
130
|
+
: await this.createTokenTransfer(fromAddress, toAddress, fromToken.address, fromToken.stringWeiAmount);
|
|
131
|
+
this.logger?.customLog('22222222222222222');
|
|
132
|
+
if (convertToVersionedTx) {
|
|
133
|
+
const blockhash = await this.getLatestBlockhash();
|
|
134
|
+
const message = new web3_js_1.TransactionMessage({
|
|
135
|
+
payerKey: transaction.feePayer,
|
|
136
|
+
recentBlockhash: blockhash,
|
|
137
|
+
instructions: transaction.instructions
|
|
138
|
+
}).compileToV0Message();
|
|
139
|
+
return new web3_js_1.VersionedTransaction(message);
|
|
140
|
+
}
|
|
141
|
+
return transaction;
|
|
142
|
+
}
|
|
143
|
+
createNativeTransfer(fromAddress, toAddress, fromWeiAmount) {
|
|
144
|
+
return new web3_js_1.Transaction().add(web3_js_1.SystemProgram.transfer({
|
|
145
|
+
fromPubkey: fromAddress,
|
|
146
|
+
toPubkey: toAddress,
|
|
147
|
+
lamports: BigInt(fromWeiAmount)
|
|
148
|
+
}));
|
|
149
|
+
}
|
|
150
|
+
async createTokenTransfer(fromAddress, toAddress, fromTokenAddress, fromWeiAmount) {
|
|
151
|
+
const mintTokenAccount = new web3_js_1.PublicKey(fromTokenAddress);
|
|
152
|
+
const [fromATA, toATA] = await Promise.all([
|
|
153
|
+
(0, spl_token_1.getAssociatedTokenAddress)(mintTokenAccount, fromAddress),
|
|
154
|
+
(0, spl_token_1.getAssociatedTokenAddress)(mintTokenAccount, toAddress)
|
|
155
|
+
]);
|
|
156
|
+
const transaction = new web3_js_1.Transaction();
|
|
157
|
+
const receiverAccountInfo = this.public.getAccountInfo(toATA);
|
|
158
|
+
if (!receiverAccountInfo) {
|
|
159
|
+
transaction.add((0, spl_token_1.createAssociatedTokenAccountInstruction)(fromAddress, toATA, toAddress, mintTokenAccount));
|
|
160
|
+
}
|
|
161
|
+
transaction.add((0, spl_token_1.createTransferInstruction)(fromATA, toATA, fromAddress, BigInt(fromWeiAmount)));
|
|
162
|
+
return transaction;
|
|
163
|
+
}
|
|
164
|
+
async getLatestBlockhash() {
|
|
165
|
+
const { blockhash } = await this.public.getLatestBlockhash();
|
|
166
|
+
return blockhash;
|
|
167
|
+
}
|
|
124
168
|
}
|
|
125
169
|
exports.SolanaAdapter = SolanaAdapter;
|