@heyanon/sdk 2.3.1 → 2.3.3

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 (30) hide show
  1. package/dist/adapter/misc.d.ts +35 -0
  2. package/dist/adapter/transformers/toResult.d.ts +24 -0
  3. package/dist/adapter/types.d.ts +123 -7
  4. package/dist/blockchain/constants/chains.d.ts +96 -2
  5. package/dist/blockchain/constants/types.d.ts +33 -0
  6. package/dist/blockchain/evm/constants/chains.d.ts +57 -0
  7. package/dist/blockchain/evm/constants/misc.d.ts +69 -0
  8. package/dist/blockchain/evm/constants/weth9.d.ts +77 -1
  9. package/dist/blockchain/evm/types.d.ts +273 -0
  10. package/dist/blockchain/evm/utils/checkToApprove.d.ts +86 -0
  11. package/dist/blockchain/evm/utils/getChainFromName.d.ts +81 -0
  12. package/dist/blockchain/evm/utils/getChainName.d.ts +114 -0
  13. package/dist/blockchain/evm/utils/getUnwrapData.d.ts +114 -0
  14. package/dist/blockchain/evm/utils/getWrapAddress.d.ts +147 -0
  15. package/dist/blockchain/evm/utils/getWrapData.d.ts +189 -0
  16. package/dist/blockchain/evm/utils/getWrappedNative.d.ts +198 -0
  17. package/dist/blockchain/evm/utils/isEvmChain.d.ts +183 -0
  18. package/dist/blockchain/evm/utils/isNativeAddress.d.ts +221 -0
  19. package/dist/blockchain/evm/utils/isNativeAddress.test.d.ts +1 -0
  20. package/dist/blockchain/solana/types.d.ts +291 -0
  21. package/dist/blockchain/solana/utils/buildV0Transaction.d.ts +184 -0
  22. package/dist/blockchain/solana/utils/toPublicKey.d.ts +194 -0
  23. package/dist/blockchain/ton/types.d.ts +410 -0
  24. package/dist/index.js +37 -2
  25. package/dist/index.mjs +37 -2
  26. package/dist/utils/retry.d.ts +218 -0
  27. package/dist/utils/sleep.d.ts +239 -0
  28. package/dist/utils/stringify.d.ts +235 -0
  29. package/dist/utils/stringify.spec.d.ts +1 -0
  30. package/package.json +1 -1
@@ -1,8 +1,192 @@
1
1
  import { Connection, PublicKey, TransactionInstruction, VersionedTransaction } from '@solana/web3.js';
2
+ /**
3
+ * Properties for building a Solana v0 transaction
4
+ * @interface Props
5
+ */
2
6
  interface Props {
7
+ /** Solana connection to fetch recent blockhash */
3
8
  connection: Connection;
9
+ /** Public key of the account that will pay for the transaction */
4
10
  payer: PublicKey;
11
+ /** Array of transaction instructions to include */
5
12
  instructions: TransactionInstruction[];
6
13
  }
14
+ /**
15
+ * Builds a Solana v0 transaction with the provided instructions
16
+ * @param props - The transaction building parameters
17
+ * @returns A versioned transaction ready for signing and sending
18
+ * @description Creates a v0 transaction with recent blockhash and compiles instructions into a transaction message
19
+ * @example
20
+ * ```typescript
21
+ * import {
22
+ * SystemProgram,
23
+ * LAMPORTS_PER_SOL,
24
+ * PublicKey
25
+ * } from '@solana/web3.js';
26
+ *
27
+ * // Simple SOL transfer
28
+ * const transferInstruction = SystemProgram.transfer({
29
+ * fromPubkey: senderPublicKey,
30
+ * toPubkey: new PublicKey('11111111111111111111111111111112'),
31
+ * lamports: 0.1 * LAMPORTS_PER_SOL // 0.1 SOL
32
+ * });
33
+ *
34
+ * const transaction = await buildV0Transaction({
35
+ * connection: options.solana.getConnection(),
36
+ * payer: await options.solana.getPublicKey(),
37
+ * instructions: [transferInstruction]
38
+ * });
39
+ *
40
+ * // SPL Token transfer
41
+ * import { createTransferInstruction, getAssociatedTokenAddress } from '@solana/spl-token';
42
+ *
43
+ * const tokenMint = new PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'); // USDC
44
+ * const fromTokenAccount = await getAssociatedTokenAddress(tokenMint, senderPublicKey);
45
+ * const toTokenAccount = await getAssociatedTokenAddress(tokenMint, recipientPublicKey);
46
+ *
47
+ * const tokenTransferInstruction = createTransferInstruction(
48
+ * fromTokenAccount,
49
+ * toTokenAccount,
50
+ * senderPublicKey,
51
+ * 100_000, // 0.1 USDC (6 decimals)
52
+ * );
53
+ *
54
+ * const tokenTransaction = await buildV0Transaction({
55
+ * connection: options.solana.getConnection(),
56
+ * payer: senderPublicKey,
57
+ * instructions: [tokenTransferInstruction]
58
+ * });
59
+ *
60
+ * // Multi-instruction transaction (swap on Jupiter)
61
+ * const swapInstructions = await jupiterApi.getSwapInstructions({
62
+ * inputMint: 'So11111111111111111111111111111111111111112', // SOL
63
+ * outputMint: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v', // USDC
64
+ * amount: 0.1 * LAMPORTS_PER_SOL,
65
+ * slippageBps: 50 // 0.5%
66
+ * });
67
+ *
68
+ * const swapTransaction = await buildV0Transaction({
69
+ * connection: options.solana.getConnection(),
70
+ * payer: await options.solana.getPublicKey(),
71
+ * instructions: swapInstructions
72
+ * });
73
+ *
74
+ * // DeFi operations (lending on Solend)
75
+ * const lendingInstructions = [
76
+ * // Create user obligation account
77
+ * createInitObligationInstruction({
78
+ * obligation: obligationAccount.publicKey,
79
+ * lendingMarket: SOLEND_MAIN_MARKET,
80
+ * obligationOwner: userPublicKey
81
+ * }),
82
+ * // Deposit collateral
83
+ * createDepositObligationCollateralInstruction({
84
+ * sourceLiquidity: userTokenAccount,
85
+ * destinationCollateral: collateralAccount,
86
+ * depositReserve: solReserve,
87
+ * obligation: obligationAccount.publicKey,
88
+ * lendingMarket: SOLEND_MAIN_MARKET,
89
+ * obligationOwner: userPublicKey,
90
+ * transferAuthority: userPublicKey,
91
+ * liquidityAmount: depositAmount
92
+ * })
93
+ * ];
94
+ *
95
+ * const lendingTransaction = await buildV0Transaction({
96
+ * connection: options.solana.getConnection(),
97
+ * payer: userPublicKey,
98
+ * instructions: lendingInstructions
99
+ * });
100
+ *
101
+ * // NFT operations
102
+ * import { createMintToInstruction, createAssociatedTokenAccountInstruction } from '@solana/spl-token';
103
+ *
104
+ * const nftMintInstructions = [
105
+ * // Create associated token account for NFT
106
+ * createAssociatedTokenAccountInstruction(
107
+ * userPublicKey, // payer
108
+ * nftTokenAccount, // associated token account
109
+ * userPublicKey, // owner
110
+ * nftMint // mint
111
+ * ),
112
+ * // Mint NFT to user
113
+ * createMintToInstruction(
114
+ * nftMint, // mint
115
+ * nftTokenAccount, // destination
116
+ * mintAuthority, // authority
117
+ * 1 // amount (1 for NFT)
118
+ * )
119
+ * ];
120
+ *
121
+ * const nftTransaction = await buildV0Transaction({
122
+ * connection: options.solana.getConnection(),
123
+ * payer: userPublicKey,
124
+ * instructions: nftMintInstructions
125
+ * });
126
+ *
127
+ * // Usage in adapter function
128
+ * async function executeSolanaTransaction(instructions: TransactionInstruction[]) {
129
+ * const transaction = await buildV0Transaction({
130
+ * connection: options.solana.getConnection(),
131
+ * payer: await options.solana.getPublicKey(),
132
+ * instructions
133
+ * });
134
+ *
135
+ * return await options.solana.sendTransactions({
136
+ * transactions: [transaction]
137
+ * });
138
+ * }
139
+ *
140
+ * // Batch operations with multiple transactions
141
+ * async function executeBatchOperations(
142
+ * operationBatches: TransactionInstruction[][]
143
+ * ) {
144
+ * const transactions = await Promise.all(
145
+ * operationBatches.map(instructions =>
146
+ * buildV0Transaction({
147
+ * connection: options.solana.getConnection(),
148
+ * payer: await options.solana.getPublicKey(),
149
+ * instructions
150
+ * })
151
+ * )
152
+ * );
153
+ *
154
+ * return await options.solana.sendTransactions({
155
+ * transactions
156
+ * });
157
+ * }
158
+ *
159
+ * // Error handling and validation
160
+ * async function safeBuildTransaction(
161
+ * connection: Connection,
162
+ * payer: PublicKey,
163
+ * instructions: TransactionInstruction[]
164
+ * ) {
165
+ * try {
166
+ * // Validate instructions
167
+ * if (instructions.length === 0) {
168
+ * throw new Error('No instructions provided');
169
+ * }
170
+ *
171
+ * // Check account balance for fees
172
+ * const balance = await connection.getBalance(payer);
173
+ * const minBalance = 5000; // Minimum lamports for transaction fees
174
+ *
175
+ * if (balance < minBalance) {
176
+ * throw new Error(`Insufficient balance for transaction fees. Required: ${minBalance}, Available: ${balance}`);
177
+ * }
178
+ *
179
+ * return await buildV0Transaction({
180
+ * connection,
181
+ * payer,
182
+ * instructions
183
+ * });
184
+ * } catch (error) {
185
+ * console.error('Failed to build transaction:', error);
186
+ * throw error;
187
+ * }
188
+ * }
189
+ * ```
190
+ */
7
191
  export declare function buildV0Transaction({ connection, payer, instructions }: Props): Promise<VersionedTransaction>;
8
192
  export {};
@@ -1,2 +1,196 @@
1
1
  import { PublicKey } from '@solana/web3.js';
2
+ /**
3
+ * Converts a string representation to a Solana PublicKey object with validation
4
+ * @param publicKey - String representation of the public key (base58 encoded)
5
+ * @returns A valid PublicKey object
6
+ * @throws {Error} When the provided string is not a valid Solana public key
7
+ * @example
8
+ * ```typescript
9
+ * // Valid Solana public keys
10
+ * const userPublicKey = toPublicKey('11111111111111111111111111111112');
11
+ * const tokenMint = toPublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'); // USDC
12
+ * const programId = toPublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'); // SPL Token Program
13
+ *
14
+ * // Use in token operations
15
+ * async function getTokenBalance(mintAddress: string, ownerAddress: string) {
16
+ * const mint = toPublicKey(mintAddress);
17
+ * const owner = toPublicKey(ownerAddress);
18
+ * const connection = options.solana.getConnection();
19
+ *
20
+ * const tokenAccounts = await connection.getParsedTokenAccountsByOwner(owner, {
21
+ * mint: mint
22
+ * });
23
+ *
24
+ * if (tokenAccounts.value.length === 0) {
25
+ * return 0;
26
+ * }
27
+ *
28
+ * return tokenAccounts.value[0].account.data.parsed.info.tokenAmount.uiAmount;
29
+ * }
30
+ *
31
+ * // Validate user input addresses
32
+ * function validateSolanaAddress(address: string): { valid: boolean; publicKey?: PublicKey; error?: string } {
33
+ * try {
34
+ * const publicKey = toPublicKey(address);
35
+ * return { valid: true, publicKey };
36
+ * } catch (error) {
37
+ * return { valid: false, error: error.message };
38
+ * }
39
+ * }
40
+ *
41
+ * // Use in transaction building
42
+ * async function createTransferTransaction(
43
+ * fromAddress: string,
44
+ * toAddress: string,
45
+ * amount: number
46
+ * ) {
47
+ * const fromPubkey = toPublicKey(fromAddress);
48
+ * const toPubkey = toPublicKey(toAddress);
49
+ *
50
+ * const transferInstruction = SystemProgram.transfer({
51
+ * fromPubkey,
52
+ * toPubkey,
53
+ * lamports: amount * LAMPORTS_PER_SOL
54
+ * });
55
+ *
56
+ * return await buildV0Transaction({
57
+ * connection: options.solana.getConnection(),
58
+ * payer: fromPubkey,
59
+ * instructions: [transferInstruction]
60
+ * });
61
+ * }
62
+ *
63
+ * // Use with associated token accounts
64
+ * import { getAssociatedTokenAddress } from '@solana/spl-token';
65
+ *
66
+ * async function getOrCreateAssociatedTokenAccount(
67
+ * mintAddress: string,
68
+ * ownerAddress: string
69
+ * ) {
70
+ * const mint = toPublicKey(mintAddress);
71
+ * const owner = toPublicKey(ownerAddress);
72
+ * const connection = options.solana.getConnection();
73
+ *
74
+ * const associatedTokenAddress = await getAssociatedTokenAddress(mint, owner);
75
+ *
76
+ * // Check if account exists
77
+ * const accountInfo = await connection.getAccountInfo(associatedTokenAddress);
78
+ *
79
+ * if (!accountInfo) {
80
+ * // Account doesn't exist, need to create it
81
+ * const createInstruction = createAssociatedTokenAccountInstruction(
82
+ * owner, // payer
83
+ * associatedTokenAddress, // associated token account
84
+ * owner, // owner
85
+ * mint // mint
86
+ * );
87
+ *
88
+ * return { address: associatedTokenAddress, instruction: createInstruction };
89
+ * }
90
+ *
91
+ * return { address: associatedTokenAddress, instruction: null };
92
+ * }
93
+ *
94
+ * // Batch address validation
95
+ * function validateMultipleAddresses(addresses: string[]): {
96
+ * valid: PublicKey[];
97
+ * invalid: Array<{ address: string; error: string }>;
98
+ * } {
99
+ * const valid: PublicKey[] = [];
100
+ * const invalid: Array<{ address: string; error: string }> = [];
101
+ *
102
+ * addresses.forEach(address => {
103
+ * try {
104
+ * valid.push(toPublicKey(address));
105
+ * } catch (error) {
106
+ * invalid.push({ address, error: error.message });
107
+ * }
108
+ * });
109
+ *
110
+ * return { valid, invalid };
111
+ * }
112
+ *
113
+ * // Use in NFT operations
114
+ * async function getNFTMetadata(nftMintAddress: string) {
115
+ * const mint = toPublicKey(nftMintAddress);
116
+ * const connection = options.solana.getConnection();
117
+ *
118
+ * // Get metadata account address
119
+ * const metadataPDA = PublicKey.findProgramAddressSync(
120
+ * [
121
+ * Buffer.from('metadata'),
122
+ * toPublicKey('metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s').toBuffer(), // Metaplex program
123
+ * mint.toBuffer()
124
+ * ],
125
+ * toPublicKey('metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s')
126
+ * )[0];
127
+ *
128
+ * const metadataAccount = await connection.getAccountInfo(metadataPDA);
129
+ * return metadataAccount;
130
+ * }
131
+ *
132
+ * // Use in program interactions
133
+ * async function interactWithCustomProgram(
134
+ * programIdString: string,
135
+ * accountStrings: string[],
136
+ * instructionData: Buffer
137
+ * ) {
138
+ * const programId = toPublicKey(programIdString);
139
+ * const accounts = accountStrings.map(addr => ({
140
+ * pubkey: toPublicKey(addr),
141
+ * isSigner: false,
142
+ * isWritable: false
143
+ * }));
144
+ *
145
+ * const instruction = new TransactionInstruction({
146
+ * keys: accounts,
147
+ * programId,
148
+ * data: instructionData
149
+ * });
150
+ *
151
+ * return await buildV0Transaction({
152
+ * connection: options.solana.getConnection(),
153
+ * payer: await options.solana.getPublicKey(),
154
+ * instructions: [instruction]
155
+ * });
156
+ * }
157
+ *
158
+ * // Error handling with detailed messages
159
+ * function safeToPublicKey(address: string): PublicKey | null {
160
+ * try {
161
+ * return toPublicKey(address);
162
+ * } catch (error) {
163
+ * console.warn(`Invalid Solana address: ${address} - ${error.message}`);
164
+ * return null;
165
+ * }
166
+ * }
167
+ *
168
+ * // Use in adapter configuration
169
+ * async function setupSolanaAdapter(config: {
170
+ * userAddress: string;
171
+ * tokenMints: string[];
172
+ * programIds: string[];
173
+ * }) {
174
+ * // Validate all addresses upfront
175
+ * const userPubkey = toPublicKey(config.userAddress);
176
+ * const mintPubkeys = config.tokenMints.map(toPublicKey);
177
+ * const programPubkeys = config.programIds.map(toPublicKey);
178
+ *
179
+ * return {
180
+ * user: userPubkey,
181
+ * supportedMints: mintPubkeys,
182
+ * programs: programPubkeys
183
+ * };
184
+ * }
185
+ *
186
+ * // Common Solana addresses as constants
187
+ * const COMMON_ADDRESSES = {
188
+ * SYSTEM_PROGRAM: toPublicKey('11111111111111111111111111111112'),
189
+ * TOKEN_PROGRAM: toPublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'),
190
+ * ASSOCIATED_TOKEN_PROGRAM: toPublicKey('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'),
191
+ * USDC_MINT: toPublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'),
192
+ * WSOL_MINT: toPublicKey('So11111111111111111111111111111111111111112')
193
+ * };
194
+ * ```
195
+ */
2
196
  export declare function toPublicKey(publicKey: string): PublicKey;