@cryptorubic/web3 0.9.0-alpha-exolix.0 → 0.9.0-alpha-exolix.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,24 +1,25 @@
1
1
  {
2
2
  "name": "@cryptorubic/web3",
3
- "version": "0.9.0-alpha-exolix.0",
3
+ "version": "0.9.0-alpha-exolix.1",
4
4
  "dependencies": {
5
5
  "tslib": "^2.3.0",
6
6
  "bignumber.js": "9.1.2",
7
- "@cryptorubic/core": "0.9.0-alpha-exolix.0",
7
+ "@cryptorubic/core": "0.9.0-alpha-exolix.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.9.0-alpha-exolix.0",
14
+ "@cryptorubic/tron-types": "0.9.0-alpha-exolix.1",
15
15
  "bitcoin-address-validation": "^2.2.3",
16
16
  "axios": "0.27.2",
17
17
  "crc-32": "^1.2.2",
18
18
  "tronweb": "^6.0.0-beta.4",
19
19
  "@solana/spl-token": "0.2.0",
20
20
  "@mysten/sui": "^1.24.0",
21
- "@suiet/wallet-sdk": "^0.3.3"
21
+ "@suiet/wallet-sdk": "^0.3.3",
22
+ "bs58": "^6.0.0"
22
23
  },
23
24
  "type": "commonjs",
24
25
  "main": "./src/index.js",
@@ -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, Keypair, PublicKey, 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,9 @@ 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
+ getAtaAddress(walletAddress: string, tokenAddress: string): Promise<PublicKey>;
31
+ getKeypairFromSecret(pk?: string): Keypair | null;
32
+ getTxWithPayer(tx: VersionedTransaction, feePayer: string): Promise<VersionedTransaction>;
33
+ deserializeTransaction(data: string): VersionedTransaction;
34
+ serializeTransactionToBase58(tx: VersionedTransaction): string;
30
35
  }
@@ -8,6 +8,8 @@ const core_1 = require("@cryptorubic/core");
8
8
  const web3_pure_1 = require("../../utils/web3-pure");
9
9
  const bignumber_js_1 = require("bignumber.js");
10
10
  const solana_tokens_service_1 = require("./utils/solana-tokens-service");
11
+ const bs58_1 = require("bs58");
12
+ const utils_1 = require("ethers/lib/utils");
11
13
  exports.NATIVE_SOLANA_MINT_ADDRESS = 'So11111111111111111111111111111111111111111';
12
14
  class SolanaAdapter extends abstract_adapter_1.AbstractAdapter {
13
15
  constructor(rpcList, httpClient, logger) {
@@ -121,5 +123,45 @@ class SolanaAdapter extends abstract_adapter_1.AbstractAdapter {
121
123
  }).compileToV0Message(addressLookupTableAccounts);
122
124
  return new web3_js_1.VersionedTransaction(message);
123
125
  }
126
+ getAtaAddress(walletAddress, tokenAddress) {
127
+ return (0, spl_token_1.getAssociatedTokenAddress)(new web3_js_1.PublicKey(tokenAddress), new web3_js_1.PublicKey(walletAddress));
128
+ }
129
+ getKeypairFromSecret(pk) {
130
+ if (!pk) {
131
+ return null;
132
+ }
133
+ const array = pk.split(',').map((s) => parseInt(s, 10));
134
+ const secretKey = Uint8Array.from(array);
135
+ return web3_js_1.Keypair.fromSecretKey(secretKey);
136
+ }
137
+ async getTxWithPayer(tx, feePayer) {
138
+ const altAccounts = [];
139
+ for (const lookup of tx.message.addressTableLookups) {
140
+ const { value } = await this.public.getAddressLookupTable(lookup.accountKey);
141
+ if (value) {
142
+ altAccounts.push(value);
143
+ }
144
+ else {
145
+ throw new Error(`ALT not found: ${lookup.accountKey.toBase58()}`);
146
+ }
147
+ }
148
+ const decompiled = web3_js_1.TransactionMessage.decompile(tx.message, {
149
+ addressLookupTableAccounts: altAccounts
150
+ });
151
+ const { blockhash } = await this.public.getLatestBlockhash();
152
+ const newMsg = new web3_js_1.TransactionMessage({
153
+ instructions: decompiled.instructions,
154
+ payerKey: new web3_js_1.PublicKey(feePayer),
155
+ recentBlockhash: blockhash
156
+ }).compileToV0Message(altAccounts);
157
+ return new web3_js_1.VersionedTransaction(newMsg);
158
+ }
159
+ deserializeTransaction(data) {
160
+ const decodedData = data.startsWith('0x') ? Buffer.from(data.slice(2), 'hex') : utils_1.base64.decode(data);
161
+ return web3_js_1.VersionedTransaction.deserialize(decodedData);
162
+ }
163
+ serializeTransactionToBase58(tx) {
164
+ return bs58_1.default.encode(tx.serialize());
165
+ }
124
166
  }
125
167
  exports.SolanaAdapter = SolanaAdapter;