@rialo/spl-token 0.3.0-alpha.0

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.
@@ -0,0 +1,1143 @@
1
+ import { PublicKey, RialoClient, TransactionBuilder, Signer } from '@rialo/ts-cdk';
2
+
3
+ /**
4
+ * TransferChecked instruction for SPL Token-2022.
5
+ *
6
+ * TransferChecked is the preferred transfer instruction as it includes
7
+ * a decimals check to prevent user error.
8
+ */
9
+
10
+ /**
11
+ * Account metadata for an instruction account.
12
+ */
13
+ interface AccountMeta {
14
+ /** The account's public key */
15
+ pubkey: PublicKey;
16
+ /** Whether this account must sign the transaction */
17
+ isSigner: boolean;
18
+ /** Whether this account's data can be modified */
19
+ isWritable: boolean;
20
+ }
21
+ /**
22
+ * A single instruction to be included in a transaction.
23
+ */
24
+ interface Instruction {
25
+ /** The program that will process this instruction */
26
+ programId: PublicKey;
27
+ /** Accounts required by this instruction */
28
+ accounts: AccountMeta[];
29
+ /** Instruction data */
30
+ data: Uint8Array;
31
+ }
32
+ /**
33
+ * Options for creating a TransferChecked instruction.
34
+ */
35
+ interface TransferCheckedInstructionOptions {
36
+ /** Source token account (must be owned by authority) */
37
+ source: PublicKey;
38
+ /** The token mint */
39
+ mint: PublicKey;
40
+ /** Destination token account */
41
+ destination: PublicKey;
42
+ /** Owner of the source account (signer) */
43
+ authority: PublicKey;
44
+ /** Amount to transfer in smallest units */
45
+ amount: bigint;
46
+ /** Expected decimals of the mint (for verification) */
47
+ decimals: number;
48
+ /** Token program ID (defaults to Token-2022) */
49
+ programId?: PublicKey;
50
+ }
51
+ /**
52
+ * Creates a TransferChecked instruction.
53
+ *
54
+ * TransferChecked transfers tokens from one token account to another,
55
+ * with a decimals check to prevent accidental transfers of the wrong amount.
56
+ *
57
+ * Instruction data format: [discriminator(1), amount(8 LE), decimals(1)]
58
+ *
59
+ * @param options - Options for the instruction
60
+ * @returns The TransferChecked instruction
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * const instruction = transferCheckedInstruction({
65
+ * source: sourceTokenAccount,
66
+ * mint: mintPubkey,
67
+ * destination: destinationTokenAccount,
68
+ * authority: walletPubkey,
69
+ * amount: 1000000n, // 1 token with 6 decimals
70
+ * decimals: 6,
71
+ * });
72
+ *
73
+ * const tx = TransactionBuilder.create()
74
+ * .setPayer(walletPubkey)
75
+ * .addInstruction(instruction)
76
+ * .build();
77
+ * ```
78
+ */
79
+ declare function transferCheckedInstruction({ source, mint, destination, authority, amount, decimals, programId, }: TransferCheckedInstructionOptions): Instruction;
80
+ /**
81
+ * Options for creating a Transfer instruction.
82
+ */
83
+ interface TransferInstructionOptions {
84
+ /** Source token account */
85
+ source: PublicKey;
86
+ /** Destination token account */
87
+ destination: PublicKey;
88
+ /** Owner of the source account (signer) */
89
+ authority: PublicKey;
90
+ /** Amount to transfer in smallest units */
91
+ amount: bigint;
92
+ /** Token program ID (defaults to Token-2022) */
93
+ programId?: PublicKey;
94
+ }
95
+ /**
96
+ * Creates a Transfer instruction (deprecated, prefer TransferChecked).
97
+ *
98
+ * This is the legacy transfer instruction without decimals verification.
99
+ * Use transferCheckedInstruction instead for safety.
100
+ *
101
+ * @param options - Options for the instruction
102
+ * @returns The Transfer instruction
103
+ */
104
+ declare function transferInstruction({ source, destination, authority, amount, programId, }: TransferInstructionOptions): Instruction;
105
+
106
+ /**
107
+ * Create Associated Token Account instruction for SPL Token-2022.
108
+ *
109
+ * Creates an Associated Token Account (ATA) for a wallet and mint combination.
110
+ */
111
+
112
+ /**
113
+ * Options for creating an Associated Token Account instruction.
114
+ */
115
+ interface CreateAssociatedTokenAccountInstructionOptions {
116
+ /** Account paying for the new account's rent */
117
+ payer: PublicKey;
118
+ /** The ATA address (derived via findAssociatedTokenAddress) */
119
+ associatedToken: PublicKey;
120
+ /** The wallet that will own the new token account */
121
+ owner: PublicKey;
122
+ /** The token mint */
123
+ mint: PublicKey;
124
+ /** Token program ID (defaults to Token-2022) */
125
+ programId?: PublicKey;
126
+ }
127
+ /**
128
+ * Creates an instruction to create an Associated Token Account.
129
+ *
130
+ * The ATA is a PDA derived from the wallet, token program, and mint.
131
+ * This instruction will create the account if it doesn't exist.
132
+ *
133
+ * Note: This instruction has no data - all information is in the accounts.
134
+ *
135
+ * @param options - Options for the instruction
136
+ * @returns The CreateAssociatedTokenAccount instruction
137
+ *
138
+ * @example
139
+ * ```typescript
140
+ * const { address: ata } = findAssociatedTokenAddress({ wallet: walletPubkey, mint: mintPubkey });
141
+ *
142
+ * const instruction = createAssociatedTokenAccountInstruction({
143
+ * payer: payerPubkey,
144
+ * associatedToken: ata,
145
+ * owner: walletPubkey,
146
+ * mint: mintPubkey,
147
+ * });
148
+ *
149
+ * const tx = TransactionBuilder.create()
150
+ * .setPayer(payerPubkey)
151
+ * .addInstruction(instruction)
152
+ * .build();
153
+ * ```
154
+ */
155
+ declare function createAssociatedTokenAccountInstruction({ payer, associatedToken, owner, mint, programId, }: CreateAssociatedTokenAccountInstructionOptions): Instruction;
156
+ /**
157
+ * Options for creating an idempotent Associated Token Account instruction.
158
+ */
159
+ interface CreateAssociatedTokenAccountIdempotentInstructionOptions {
160
+ /** Account paying for the new account's rent */
161
+ payer: PublicKey;
162
+ /** The ATA address (derived via findAssociatedTokenAddress) */
163
+ associatedToken: PublicKey;
164
+ /** The wallet that will own the new token account */
165
+ owner: PublicKey;
166
+ /** The token mint */
167
+ mint: PublicKey;
168
+ /** Token program ID (defaults to Token-2022) */
169
+ programId?: PublicKey;
170
+ }
171
+ /**
172
+ * Creates an instruction to create an Associated Token Account idempotently.
173
+ *
174
+ * This variant will succeed even if the ATA already exists, making it safe
175
+ * to call without checking if the account exists first.
176
+ *
177
+ * @param options - Options for the instruction
178
+ * @returns The CreateAssociatedTokenAccountIdempotent instruction
179
+ *
180
+ * @example
181
+ * ```typescript
182
+ * // Safe to call even if ATA already exists
183
+ * const instruction = createAssociatedTokenAccountIdempotentInstruction({
184
+ * payer: payerPubkey,
185
+ * associatedToken: ata,
186
+ * owner: walletPubkey,
187
+ * mint: mintPubkey,
188
+ * });
189
+ * ```
190
+ */
191
+ declare function createAssociatedTokenAccountIdempotentInstruction({ payer, associatedToken, owner, mint, programId, }: CreateAssociatedTokenAccountIdempotentInstructionOptions): Instruction;
192
+
193
+ /**
194
+ * Options for creating an InitializeMint2 instruction.
195
+ *
196
+ * InitializeMint2 does not require a rent sysvar account, but does require
197
+ * the tombstone PDA derived from ["mint_tombstone", mint_pubkey].
198
+ */
199
+ interface InitializeMintInstructionOptions {
200
+ /** Mint account to initialize */
201
+ mint: PublicKey;
202
+ /** Number of decimals for the mint */
203
+ decimals: number;
204
+ /** Authority allowed to mint new tokens */
205
+ mintAuthority: PublicKey;
206
+ /** Optional freeze authority for the mint */
207
+ freezeAuthority?: PublicKey;
208
+ /** Token program ID (defaults to Token-2022) */
209
+ programId?: PublicKey;
210
+ }
211
+ /**
212
+ * Creates an InitializeMint2 instruction for Token-2022.
213
+ *
214
+ * Instruction data format:
215
+ * [discriminator(1), decimals(1), mint_authority(32), freeze_option(1), freeze_authority(32)]
216
+ *
217
+ * Accounts:
218
+ * - mint (writable)
219
+ * - tombstone_pda (readonly)
220
+ *
221
+ * @param options - Options for the instruction
222
+ * @returns The InitializeMint2 instruction
223
+ *
224
+ * @example
225
+ * ```typescript
226
+ * const instruction = initializeMintInstruction({
227
+ * mint,
228
+ * decimals: 6,
229
+ * mintAuthority,
230
+ * freezeAuthority,
231
+ * });
232
+ * ```
233
+ */
234
+ declare function initializeMintInstruction({ mint, decimals, mintAuthority, freezeAuthority, programId, }: InitializeMintInstructionOptions): Instruction;
235
+ /**
236
+ * Options for creating a MintTo instruction.
237
+ */
238
+ interface MintToInstructionOptions {
239
+ /** Mint account to mint tokens from */
240
+ mint: PublicKey;
241
+ /** Destination token account to receive minted tokens */
242
+ destination: PublicKey;
243
+ /** Mint authority (signer) */
244
+ authority: PublicKey;
245
+ /** Amount to mint in smallest units */
246
+ amount: bigint;
247
+ /** Token program ID (defaults to Token-2022) */
248
+ programId?: PublicKey;
249
+ }
250
+ /**
251
+ * Creates a MintTo instruction for Token-2022.
252
+ *
253
+ * Instruction data format: [discriminator(1), amount(8 LE)]
254
+ *
255
+ * Accounts:
256
+ * - mint (writable)
257
+ * - destination (writable)
258
+ * - authority (signer)
259
+ *
260
+ * @param options - Options for the instruction
261
+ * @returns The MintTo instruction
262
+ *
263
+ * @example
264
+ * ```typescript
265
+ * const instruction = mintToInstruction({
266
+ * mint,
267
+ * destination,
268
+ * authority,
269
+ * amount: 1_000_000n,
270
+ * });
271
+ * ```
272
+ */
273
+ declare function mintToInstruction({ mint, destination, authority, amount, programId, }: MintToInstructionOptions): Instruction;
274
+
275
+ /**
276
+ * Constants for SPL Token-2022 operations.
277
+ *
278
+ * This module defines program IDs, byte offsets for account parsing,
279
+ * and instruction discriminators for the Token-2022 program.
280
+ */
281
+ /** Token-2022 program ID */
282
+ declare const TOKEN_2022_PROGRAM_ID = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";
283
+ /** Associated Token Account program ID */
284
+ declare const ASSOCIATED_TOKEN_PROGRAM_ID = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
285
+ /** Legacy Token program ID (SPL Token) */
286
+ declare const TOKEN_PROGRAM_ID = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
287
+ /** Size of a Mint account (without extensions) */
288
+ declare const MINT_SIZE = 82;
289
+ /** Size of a Token Account (without extensions) */
290
+ declare const TOKEN_ACCOUNT_SIZE = 165;
291
+ /**
292
+ * State of a token account.
293
+ */
294
+ declare enum TokenAccountState {
295
+ /** Account is not yet initialized */
296
+ Uninitialized = 0,
297
+ /** Account is initialized and active */
298
+ Initialized = 1,
299
+ /** Account is frozen */
300
+ Frozen = 2
301
+ }
302
+ /**
303
+ * Extension types for Token-2022 accounts.
304
+ * Extensions start after the base account data with an AccountType byte.
305
+ */
306
+ declare enum ExtensionType {
307
+ /** Uninitialized extension slot */
308
+ Uninitialized = 0,
309
+ /** Transfer fee configuration */
310
+ TransferFeeConfig = 1,
311
+ /** Transfer fee amount tracking */
312
+ TransferFeeAmount = 2,
313
+ /** Mint close authority */
314
+ MintCloseAuthority = 3,
315
+ /** Confidential transfer configuration */
316
+ ConfidentialTransferMint = 4,
317
+ /** Confidential transfer account state */
318
+ ConfidentialTransferAccount = 5,
319
+ /** Default account state */
320
+ DefaultAccountState = 6,
321
+ /** Immutable owner */
322
+ ImmutableOwner = 7,
323
+ /** Memo required on transfer */
324
+ MemoTransfer = 8,
325
+ /** Non-transferable tokens */
326
+ NonTransferable = 9,
327
+ /** Interest-bearing configuration */
328
+ InterestBearingConfig = 10,
329
+ /** CPI guard */
330
+ CpiGuard = 11,
331
+ /** Permanent delegate */
332
+ PermanentDelegate = 12,
333
+ /** Non-transferable account marker */
334
+ NonTransferableAccount = 13,
335
+ /** Transfer hook configuration */
336
+ TransferHook = 14,
337
+ /** Transfer hook account state */
338
+ TransferHookAccount = 15,
339
+ /** Confidential transfer fee configuration */
340
+ ConfidentialTransferFeeConfig = 16,
341
+ /** Confidential transfer fee amount */
342
+ ConfidentialTransferFeeAmount = 17,
343
+ /** Metadata pointer extension */
344
+ MetadataPointer = 18,
345
+ /** Token metadata extension */
346
+ TokenMetadata = 19,
347
+ /** Group pointer extension */
348
+ GroupPointer = 20,
349
+ /** Token group extension */
350
+ TokenGroup = 21,
351
+ /** Group member pointer extension */
352
+ GroupMemberPointer = 22,
353
+ /** Token group member extension */
354
+ TokenGroupMember = 23
355
+ }
356
+ /**
357
+ * Account type byte that precedes extensions.
358
+ */
359
+ declare enum AccountType {
360
+ /** Account is uninitialized */
361
+ Uninitialized = 0,
362
+ /** This is a mint account */
363
+ Mint = 1,
364
+ /** This is a token account */
365
+ Account = 2
366
+ }
367
+ /**
368
+ * SPL Token instruction discriminators.
369
+ */
370
+ declare enum TokenInstruction {
371
+ /** Initialize a new mint */
372
+ InitializeMint = 0,
373
+ /** Initialize a new token account */
374
+ InitializeAccount = 1,
375
+ /** Initialize a multisig */
376
+ InitializeMultisig = 2,
377
+ /** Transfer tokens (deprecated, use TransferChecked) */
378
+ Transfer = 3,
379
+ /** Approve a delegate */
380
+ Approve = 4,
381
+ /** Revoke a delegate */
382
+ Revoke = 5,
383
+ /** Set a new authority */
384
+ SetAuthority = 6,
385
+ /** Mint new tokens */
386
+ MintTo = 7,
387
+ /** Burn tokens */
388
+ Burn = 8,
389
+ /** Close a token account */
390
+ CloseAccount = 9,
391
+ /** Freeze a token account */
392
+ FreezeAccount = 10,
393
+ /** Thaw a frozen account */
394
+ ThawAccount = 11,
395
+ /** Transfer tokens with decimals check */
396
+ TransferChecked = 12,
397
+ /** Approve with amount check */
398
+ ApproveChecked = 13,
399
+ /** Mint with amount check */
400
+ MintToChecked = 14,
401
+ /** Burn with amount check */
402
+ BurnChecked = 15,
403
+ /** Initialize account with specified owner */
404
+ InitializeAccount2 = 16,
405
+ /** Sync native token balance */
406
+ SyncNative = 17,
407
+ /** Initialize account with rent sysvar */
408
+ InitializeAccount3 = 18,
409
+ /** Initialize multisig with rent sysvar */
410
+ InitializeMultisig2 = 19,
411
+ /** Initialize mint with rent sysvar */
412
+ InitializeMint2 = 20
413
+ }
414
+
415
+ /**
416
+ * TypeScript interfaces for SPL Token-2022 accounts and operations.
417
+ */
418
+
419
+ /**
420
+ * Parsed mint account information.
421
+ *
422
+ * Contains the core mint data including supply, decimals, and authorities.
423
+ */
424
+ interface MintInfo {
425
+ /** The mint's public key address */
426
+ address: PublicKey;
427
+ /** Total token supply in smallest units */
428
+ supply: bigint;
429
+ /** Number of decimal places for display (0-9) */
430
+ decimals: number;
431
+ /** Whether the mint has been initialized */
432
+ isInitialized: boolean;
433
+ /** Authority that can mint new tokens (null if disabled) */
434
+ mintAuthority: PublicKey | null;
435
+ /** Authority that can freeze token accounts (null if disabled) */
436
+ freezeAuthority: PublicKey | null;
437
+ }
438
+ /**
439
+ * Parsed token account information.
440
+ *
441
+ * Represents a token holding account with balance, owner, and delegation info.
442
+ */
443
+ interface TokenAccountInfo {
444
+ /** The token account's public key address */
445
+ address: PublicKey;
446
+ /** The mint this account holds tokens for */
447
+ mint: PublicKey;
448
+ /** The wallet that owns this token account */
449
+ owner: PublicKey;
450
+ /** Current token balance in smallest units */
451
+ amount: bigint;
452
+ /** Delegate authorized to transfer tokens (null if none) */
453
+ delegate: PublicKey | null;
454
+ /** Account state (Uninitialized, Initialized, or Frozen) */
455
+ state: TokenAccountState;
456
+ /** If this is a wrapped native token account, the amount of native tokens */
457
+ isNative: bigint | null;
458
+ /** Amount delegated to the delegate */
459
+ delegatedAmount: bigint;
460
+ /** Authority that can close this account (null if none) */
461
+ closeAuthority: PublicKey | null;
462
+ }
463
+ /**
464
+ * Token metadata from the Token-2022 metadata extension.
465
+ *
466
+ * This is the native metadata format embedded in Token-2022 accounts,
467
+ * not the separate Metaplex Token Metadata program.
468
+ */
469
+ interface TokenMetadata {
470
+ /** Authority that can update the metadata */
471
+ updateAuthority: PublicKey | null;
472
+ /** The mint this metadata belongs to */
473
+ mint: PublicKey;
474
+ /** Token name (e.g., "Wrapped SOL") */
475
+ name: string;
476
+ /** Token symbol (e.g., "SOL") */
477
+ symbol: string;
478
+ /** URI pointing to off-chain metadata (JSON) */
479
+ uri: string;
480
+ /** Additional key-value metadata pairs */
481
+ additionalMetadata: Array<[string, string]>;
482
+ }
483
+ /**
484
+ * Parameters for a token transfer operation.
485
+ */
486
+ interface TransferParams {
487
+ /** Source wallet (owner of the source token account) */
488
+ source: PublicKey;
489
+ /** Destination wallet (will use/create their ATA) */
490
+ destination: PublicKey;
491
+ /** Mint of the token being transferred */
492
+ mint: PublicKey;
493
+ /** Amount to transfer in smallest units */
494
+ amount: bigint;
495
+ /** Token decimals (must match mint) */
496
+ decimals: number;
497
+ /** Whether to create destination ATA if it doesn't exist */
498
+ createDestinationAta?: boolean;
499
+ }
500
+ /**
501
+ * Result of deriving an Associated Token Address.
502
+ */
503
+ interface AtaDerivationResult {
504
+ /** The derived ATA address */
505
+ address: PublicKey;
506
+ /** The bump seed used in derivation */
507
+ bump: number;
508
+ }
509
+ /**
510
+ * Filter options for listing token accounts.
511
+ */
512
+ interface TokenAccountFilter {
513
+ /** Filter by specific mint */
514
+ mint?: PublicKey;
515
+ /** Filter by token program (Token or Token-2022) */
516
+ programId?: PublicKey;
517
+ }
518
+ /**
519
+ * Raw TLV extension data.
520
+ */
521
+ interface RawExtension {
522
+ /** Extension type identifier */
523
+ type: number;
524
+ /** Raw extension data bytes */
525
+ data: Uint8Array;
526
+ }
527
+ /**
528
+ * Metadata pointer extension data.
529
+ */
530
+ interface MetadataPointerExtension {
531
+ /** Authority that can set the metadata address */
532
+ authority: PublicKey | null;
533
+ /** Address where metadata is stored (usually same as mint for embedded) */
534
+ metadataAddress: PublicKey | null;
535
+ }
536
+
537
+ /**
538
+ * High-level SPL Token-2022 client for token operations.
539
+ *
540
+ * Provides a convenient API for common token operations like getting
541
+ * balances, reading mint info, and building transfer transactions.
542
+ */
543
+
544
+ /**
545
+ * Options for creating an SplTokenClient.
546
+ */
547
+ interface SplTokenClientOptions {
548
+ /** The underlying RialoClient for RPC calls */
549
+ client: RialoClient;
550
+ /** Token program ID (defaults to Token-2022) */
551
+ programId?: PublicKey;
552
+ }
553
+ /**
554
+ * High-level client for SPL Token-2022 operations.
555
+ *
556
+ * Wraps a RialoClient to provide token-specific functionality including
557
+ * reading mint/token account data, getting balances, and building transfers.
558
+ *
559
+ * @example
560
+ * ```typescript
561
+ * import { createRialoClient, RIALO_DEVNET_CHAIN } from '@rialo/ts-cdk';
562
+ * import { createSplTokenClient } from '@rialo/spl-token';
563
+ *
564
+ * const rialoClient = createRialoClient({ chain: RIALO_DEVNET_CHAIN });
565
+ * const tokenClient = createSplTokenClient({ client: rialoClient });
566
+ *
567
+ * // Get token balance
568
+ * const balance = await tokenClient.getBalance({ wallet: walletPubkey, mint: mintPubkey });
569
+ * console.log(`Balance: ${balance}`);
570
+ *
571
+ * // Get mint info
572
+ * const mintInfo = await tokenClient.getMintInfo({ mint: mintPubkey });
573
+ * console.log(`Supply: ${mintInfo.supply}, Decimals: ${mintInfo.decimals}`);
574
+ * ```
575
+ */
576
+ declare class SplTokenClient {
577
+ private readonly client;
578
+ private readonly programId;
579
+ /**
580
+ * Creates a new SplTokenClient.
581
+ *
582
+ * @param options - Client configuration options
583
+ */
584
+ constructor({ client, programId, }: SplTokenClientOptions);
585
+ /**
586
+ * Gets the token program ID this client is configured to use.
587
+ */
588
+ getProgramId(): PublicKey;
589
+ /**
590
+ * Retrieves mint account information.
591
+ *
592
+ * @param options - Options containing the mint public key
593
+ * @returns Parsed mint information including supply, decimals, and authorities
594
+ * @throws {SplTokenError} If the mint account doesn't exist or is invalid
595
+ *
596
+ * @example
597
+ * ```typescript
598
+ * const mintInfo = await tokenClient.getMintInfo({ mint: mintPubkey });
599
+ * console.log(`Supply: ${mintInfo.supply}`);
600
+ * console.log(`Decimals: ${mintInfo.decimals}`);
601
+ * console.log(`Mint Authority: ${mintInfo.mintAuthority?.toString() ?? 'disabled'}`);
602
+ * ```
603
+ */
604
+ getMintInfo({ mint }: {
605
+ mint: PublicKey;
606
+ }): Promise<MintInfo>;
607
+ /**
608
+ * Retrieves Token-2022 native metadata from a mint.
609
+ *
610
+ * @param options - Options containing the mint public key
611
+ * @returns Parsed token metadata, or null if no metadata extension exists
612
+ * @throws {SplTokenError} If the mint account doesn't exist
613
+ *
614
+ * @example
615
+ * ```typescript
616
+ * const metadata = await tokenClient.getTokenMetadata({ mint: mintPubkey });
617
+ * if (metadata) {
618
+ * console.log(`Name: ${metadata.name}`);
619
+ * console.log(`Symbol: ${metadata.symbol}`);
620
+ * console.log(`URI: ${metadata.uri}`);
621
+ * }
622
+ * ```
623
+ */
624
+ getTokenMetadata({ mint }: {
625
+ mint: PublicKey;
626
+ }): Promise<TokenMetadata | null>;
627
+ /**
628
+ * Retrieves token account information.
629
+ *
630
+ * @param options - Options containing the token account public key
631
+ * @returns Parsed token account information
632
+ * @throws {SplTokenError} If the account doesn't exist or is invalid
633
+ */
634
+ getTokenAccountInfo({ tokenAccount, }: {
635
+ tokenAccount: PublicKey;
636
+ }): Promise<TokenAccountInfo>;
637
+ /**
638
+ * Gets the token balance for a wallet.
639
+ *
640
+ * Automatically derives the Associated Token Address for the wallet/mint
641
+ * combination and retrieves the balance.
642
+ *
643
+ * @param options - Options containing wallet and mint public keys
644
+ * @returns The token balance in smallest units, or 0n if the ATA doesn't exist
645
+ *
646
+ * @example
647
+ * ```typescript
648
+ * const balance = await tokenClient.getBalance({ wallet: walletPubkey, mint: mintPubkey });
649
+ * console.log(`Token balance: ${balance}`);
650
+ * ```
651
+ */
652
+ getBalance({ wallet, mint }: {
653
+ wallet: PublicKey;
654
+ mint: PublicKey;
655
+ }): Promise<bigint>;
656
+ /**
657
+ * Derives the Associated Token Address for a wallet and mint.
658
+ *
659
+ * @param options - Options containing wallet and mint public keys
660
+ * @returns The derived ATA address and bump seed
661
+ *
662
+ * @example
663
+ * ```typescript
664
+ * const { address, bump } = tokenClient.getAssociatedTokenAddress({ wallet: walletPubkey, mint: mintPubkey });
665
+ * console.log(`ATA: ${address.toString()}`);
666
+ * ```
667
+ */
668
+ getAssociatedTokenAddress({ wallet, mint, }: {
669
+ wallet: PublicKey;
670
+ mint: PublicKey;
671
+ }): AtaDerivationResult;
672
+ /**
673
+ * Checks if an Associated Token Account exists.
674
+ *
675
+ * @param options - Options containing wallet and mint public keys
676
+ * @returns True if the ATA exists, false otherwise
677
+ */
678
+ ataExists({ wallet, mint }: {
679
+ wallet: PublicKey;
680
+ mint: PublicKey;
681
+ }): Promise<boolean>;
682
+ /**
683
+ * Creates instructions for a token transfer.
684
+ *
685
+ * This builds the necessary instructions for transferring tokens,
686
+ * optionally creating the destination ATA if it doesn't exist.
687
+ *
688
+ * @param params - Transfer parameters
689
+ * @returns Array of instructions to execute
690
+ * @throws {SplTokenError} If the mint doesn't exist
691
+ *
692
+ * @example
693
+ * ```typescript
694
+ * const instructions = await tokenClient.createTransferInstructions({
695
+ * source: senderWallet,
696
+ * destination: recipientWallet,
697
+ * mint: mintPubkey,
698
+ * amount: 1000000n,
699
+ * decimals: 6,
700
+ * createDestinationAta: true,
701
+ * });
702
+ * ```
703
+ */
704
+ createTransferInstructions(params: TransferParams): Promise<Instruction[]>;
705
+ /**
706
+ * Options for creating a transfer transaction.
707
+ */
708
+ /**
709
+ * Creates a transaction for a token transfer.
710
+ *
711
+ * Builds a complete transaction with all necessary instructions for
712
+ * transferring tokens, including ATA creation if needed.
713
+ *
714
+ * @param options - Options containing params and validFrom
715
+ * @returns Built transaction ready for signing
716
+ *
717
+ * @example
718
+ * ```typescript
719
+ * const blockHeight = await rialoClient.getBlockHeight();
720
+ * const configHashPrefix = await rialoClient.getConfigHashPrefix();
721
+ * const tx = await tokenClient.createTransferTransaction({
722
+ * params: {
723
+ * source: senderWallet,
724
+ * destination: recipientWallet,
725
+ * mint: mintPubkey,
726
+ * amount: 1000000n,
727
+ * decimals: 6,
728
+ * },
729
+ * validFrom: blockHeight,
730
+ * configHashPrefix,
731
+ * });
732
+ *
733
+ * // Sign and send
734
+ * const signedTx = tx.sign([signer]);
735
+ * const signature = await rialoClient.sendTransaction(signedTx.serialize());
736
+ * ```
737
+ */
738
+ createTransferTransaction({ params, validFrom, configHashPrefix, }: {
739
+ params: TransferParams;
740
+ validFrom: bigint;
741
+ configHashPrefix: bigint;
742
+ }): Promise<ReturnType<typeof TransactionBuilder.prototype.build>>;
743
+ /**
744
+ * Transfers tokens from one wallet to another.
745
+ *
746
+ * This is a high-level convenience method that:
747
+ * 1. Creates the destination ATA if needed
748
+ * 2. Builds the transfer transaction
749
+ * 3. Signs and sends the transaction
750
+ * 4. Waits for confirmation
751
+ *
752
+ * @param options - Options containing params, validFrom, and signer
753
+ * @returns Transaction signature
754
+ *
755
+ * @example
756
+ * ```typescript
757
+ * const blockHeight = await rialoClient.getBlockHeight();
758
+ * const configHashPrefix = await rialoClient.getConfigHashPrefix();
759
+ * const signature = await tokenClient.transfer({
760
+ * params: {
761
+ * source: senderWallet,
762
+ * destination: recipientWallet,
763
+ * mint: mintPubkey,
764
+ * amount: 1000000n,
765
+ * decimals: 6,
766
+ * },
767
+ * validFrom: blockHeight,
768
+ * configHashPrefix,
769
+ * signer: senderSigner,
770
+ * });
771
+ * console.log(`Transfer complete: ${signature}`);
772
+ * ```
773
+ */
774
+ transfer({ params, validFrom, configHashPrefix, signer, }: {
775
+ params: TransferParams;
776
+ validFrom: bigint;
777
+ configHashPrefix: bigint;
778
+ signer: Signer;
779
+ }): Promise<string>;
780
+ }
781
+ /**
782
+ * Options for creating an SplTokenClient via the factory function.
783
+ */
784
+ interface CreateSplTokenClientOptions {
785
+ /** The underlying RialoClient for RPC calls */
786
+ client: RialoClient;
787
+ /** Token program ID (defaults to Token-2022) */
788
+ programId?: PublicKey;
789
+ }
790
+ /**
791
+ * Creates a new SplTokenClient.
792
+ *
793
+ * Factory function for creating an SplTokenClient instance.
794
+ *
795
+ * @param options - Options for creating the client
796
+ * @returns Configured SplTokenClient instance
797
+ *
798
+ * @example
799
+ * ```typescript
800
+ * import { createRialoClient, RIALO_DEVNET_CHAIN } from '@rialo/ts-cdk';
801
+ * import { createSplTokenClient } from '@rialo/spl-token';
802
+ *
803
+ * const rialoClient = createRialoClient({ chain: RIALO_DEVNET_CHAIN });
804
+ * const tokenClient = createSplTokenClient({ client: rialoClient });
805
+ * ```
806
+ */
807
+ declare function createSplTokenClient({ client, programId, }: CreateSplTokenClientOptions): SplTokenClient;
808
+
809
+ /**
810
+ * Error handling for SPL Token operations.
811
+ *
812
+ * This module defines the error types and factory methods for all
813
+ * SPL Token-related operations, following the same pattern as RialoError.
814
+ */
815
+ /**
816
+ * Error codes for SPL Token operations.
817
+ */
818
+ declare enum SplTokenErrorCode {
819
+ /** Invalid mint account data */
820
+ INVALID_MINT = "INVALID_MINT",
821
+ /** Invalid token account data */
822
+ INVALID_TOKEN_ACCOUNT = "INVALID_TOKEN_ACCOUNT",
823
+ /** Token account not found */
824
+ TOKEN_ACCOUNT_NOT_FOUND = "TOKEN_ACCOUNT_NOT_FOUND",
825
+ /** Mint account not found */
826
+ MINT_NOT_FOUND = "MINT_NOT_FOUND",
827
+ /** Token account is frozen */
828
+ ACCOUNT_FROZEN = "ACCOUNT_FROZEN",
829
+ /** Insufficient token balance */
830
+ INSUFFICIENT_BALANCE = "INSUFFICIENT_BALANCE",
831
+ /** Invalid extension data */
832
+ INVALID_EXTENSION = "INVALID_EXTENSION",
833
+ /** PDA derivation failed */
834
+ PDA_DERIVATION_FAILED = "PDA_DERIVATION_FAILED",
835
+ /** Invalid metadata */
836
+ INVALID_METADATA = "INVALID_METADATA",
837
+ /** Account not initialized */
838
+ ACCOUNT_NOT_INITIALIZED = "ACCOUNT_NOT_INITIALIZED"
839
+ }
840
+ /**
841
+ * Constructor options for SplTokenError.
842
+ */
843
+ interface SplTokenErrorOptions {
844
+ code: SplTokenErrorCode;
845
+ message: string;
846
+ details?: Record<string, unknown>;
847
+ }
848
+ /**
849
+ * Error class for SPL Token operations.
850
+ *
851
+ * Provides structured error handling with error codes and optional details.
852
+ * Use the static factory methods for consistent error creation.
853
+ *
854
+ * @example
855
+ * ```typescript
856
+ * // Create errors using factory methods
857
+ * throw SplTokenError.invalidMint({ reason: "Account data too short" });
858
+ * throw SplTokenError.tokenAccountNotFound({ address: "5ZqB9U..." });
859
+ * throw SplTokenError.insufficientBalance({ required: 1000n, available: 500n });
860
+ *
861
+ * // Handle errors with type information
862
+ * try {
863
+ * await client.getBalance({ wallet, mint });
864
+ * } catch (error) {
865
+ * if (error instanceof SplTokenError && error.code === SplTokenErrorCode.TOKEN_ACCOUNT_NOT_FOUND) {
866
+ * console.log("Token account does not exist");
867
+ * }
868
+ * }
869
+ * ```
870
+ */
871
+ declare class SplTokenError extends Error {
872
+ readonly code: SplTokenErrorCode;
873
+ readonly details?: Record<string, unknown>;
874
+ constructor({ code, message, details }: SplTokenErrorOptions);
875
+ /**
876
+ * Creates an invalid mint error.
877
+ *
878
+ * @param options - Error options containing the reason
879
+ */
880
+ static invalidMint({ reason }: {
881
+ reason: string;
882
+ }): SplTokenError;
883
+ /**
884
+ * Creates an invalid token account error.
885
+ *
886
+ * @param options - Error options containing the reason
887
+ */
888
+ static invalidTokenAccount({ reason }: {
889
+ reason: string;
890
+ }): SplTokenError;
891
+ /**
892
+ * Creates a token account not found error.
893
+ *
894
+ * @param options - Error options containing the address
895
+ */
896
+ static tokenAccountNotFound({ address }: {
897
+ address: string;
898
+ }): SplTokenError;
899
+ /**
900
+ * Creates a mint not found error.
901
+ *
902
+ * @param options - Error options containing the address
903
+ */
904
+ static mintNotFound({ address }: {
905
+ address: string;
906
+ }): SplTokenError;
907
+ /**
908
+ * Creates an account frozen error.
909
+ *
910
+ * @param options - Error options containing the address
911
+ */
912
+ static accountFrozen({ address }: {
913
+ address: string;
914
+ }): SplTokenError;
915
+ /**
916
+ * Creates an insufficient balance error.
917
+ *
918
+ * @param options - Error options containing required and available amounts
919
+ */
920
+ static insufficientBalance({ required, available, }: {
921
+ required: bigint;
922
+ available: bigint;
923
+ }): SplTokenError;
924
+ /**
925
+ * Creates an invalid extension error.
926
+ *
927
+ * @param options - Error options containing the reason
928
+ */
929
+ static invalidExtension({ reason }: {
930
+ reason: string;
931
+ }): SplTokenError;
932
+ /**
933
+ * Creates a PDA derivation failed error.
934
+ *
935
+ * @param options - Error options containing the reason
936
+ */
937
+ static pdaDerivationFailed({ reason }: {
938
+ reason: string;
939
+ }): SplTokenError;
940
+ /**
941
+ * Creates an invalid metadata error.
942
+ *
943
+ * @param options - Error options containing the reason
944
+ */
945
+ static invalidMetadata({ reason }: {
946
+ reason: string;
947
+ }): SplTokenError;
948
+ /**
949
+ * Creates an account not initialized error.
950
+ *
951
+ * @param options - Error options containing the address
952
+ */
953
+ static accountNotInitialized({ address }: {
954
+ address: string;
955
+ }): SplTokenError;
956
+ }
957
+
958
+ /**
959
+ * Mint account parsing for SPL Token-2022.
960
+ */
961
+
962
+ /**
963
+ * Options for parsing a mint account.
964
+ */
965
+ interface ParseMintAccountOptions {
966
+ /** The mint account's public key */
967
+ address: PublicKey;
968
+ /** Raw account data bytes (minimum 82 bytes) */
969
+ data: Uint8Array;
970
+ }
971
+ /**
972
+ * Parses raw mint account data into a structured MintInfo object.
973
+ *
974
+ * @param options - Options containing address and data
975
+ * @returns Parsed mint information
976
+ * @throws {SplTokenError} If the data is invalid or too short
977
+ *
978
+ * @example
979
+ * ```typescript
980
+ * const accountInfo = await client.getAccountInfo(mintPubkey);
981
+ * if (accountInfo) {
982
+ * const mintInfo = parseMintAccount({ address: mintPubkey, data: accountInfo.data });
983
+ * console.log(`Supply: ${mintInfo.supply}`);
984
+ * console.log(`Decimals: ${mintInfo.decimals}`);
985
+ * }
986
+ * ```
987
+ */
988
+ declare function parseMintAccount({ address, data }: ParseMintAccountOptions): MintInfo;
989
+
990
+ /**
991
+ * Token account parsing for SPL Token-2022.
992
+ */
993
+
994
+ /**
995
+ * Options for parsing a token account.
996
+ */
997
+ interface ParseTokenAccountOptions {
998
+ /** The token account's public key */
999
+ address: PublicKey;
1000
+ /** Raw account data bytes (minimum 165 bytes) */
1001
+ data: Uint8Array;
1002
+ }
1003
+ /**
1004
+ * Parses raw token account data into a structured TokenAccountInfo object.
1005
+ *
1006
+ * @param options - Options containing address and data
1007
+ * @returns Parsed token account information
1008
+ * @throws {SplTokenError} If the data is invalid or too short
1009
+ *
1010
+ * @example
1011
+ * ```typescript
1012
+ * const accountInfo = await client.getAccountInfo(tokenAccountPubkey);
1013
+ * if (accountInfo) {
1014
+ * const tokenAccount = parseTokenAccount({ address: tokenAccountPubkey, data: accountInfo.data });
1015
+ * console.log(`Balance: ${tokenAccount.amount}`);
1016
+ * console.log(`Owner: ${tokenAccount.owner.toString()}`);
1017
+ * }
1018
+ * ```
1019
+ */
1020
+ declare function parseTokenAccount({ address, data }: ParseTokenAccountOptions): TokenAccountInfo;
1021
+
1022
+ /**
1023
+ * Token metadata parsing for SPL Token-2022 native metadata extension.
1024
+ *
1025
+ * This parses the TokenMetadata extension (ExtensionType=19) embedded in
1026
+ * Token-2022 mint accounts, not the separate Metaplex Token Metadata program.
1027
+ */
1028
+
1029
+ /**
1030
+ * Options for parsing token metadata.
1031
+ */
1032
+ interface ParseTokenMetadataOptions {
1033
+ /** The mint's public key */
1034
+ mint: PublicKey;
1035
+ /** Raw mint account data (including extensions) */
1036
+ data: Uint8Array;
1037
+ }
1038
+ /**
1039
+ * Parses Token-2022 native metadata from a mint account.
1040
+ *
1041
+ * This function looks for the TokenMetadata extension (type 19) in the
1042
+ * account's extension data and parses it if found.
1043
+ *
1044
+ * @param options - Options containing mint and data
1045
+ * @returns Parsed token metadata, or null if no metadata extension exists
1046
+ * @throws {SplTokenError} If the metadata extension is malformed
1047
+ *
1048
+ * @example
1049
+ * ```typescript
1050
+ * const accountInfo = await client.getAccountInfo(mintPubkey);
1051
+ * if (accountInfo) {
1052
+ * const metadata = parseTokenMetadata({ mint: mintPubkey, data: accountInfo.data });
1053
+ * if (metadata) {
1054
+ * console.log(`Name: ${metadata.name}`);
1055
+ * console.log(`Symbol: ${metadata.symbol}`);
1056
+ * console.log(`URI: ${metadata.uri}`);
1057
+ * }
1058
+ * }
1059
+ * ```
1060
+ */
1061
+ declare function parseTokenMetadata({ mint, data, }: ParseTokenMetadataOptions): TokenMetadata | null;
1062
+ /**
1063
+ * Options for parsing metadata pointer extension.
1064
+ */
1065
+ interface ParseMetadataPointerExtensionOptions {
1066
+ /** Raw mint account data (including extensions) */
1067
+ data: Uint8Array;
1068
+ }
1069
+ /**
1070
+ * Parses the MetadataPointer extension from a mint account.
1071
+ *
1072
+ * @param options - Options containing data
1073
+ * @returns Parsed metadata pointer, or null if not present
1074
+ */
1075
+ declare function parseMetadataPointerExtension({ data, }: ParseMetadataPointerExtensionOptions): MetadataPointerExtension | null;
1076
+ /**
1077
+ * Options for getting mint extensions.
1078
+ */
1079
+ interface GetMintExtensionsOptions {
1080
+ /** Raw mint account data */
1081
+ data: Uint8Array;
1082
+ }
1083
+ /**
1084
+ * Gets all raw extensions from a mint account.
1085
+ *
1086
+ * @param options - Options containing data
1087
+ * @returns Array of raw extensions, or empty array if no extensions
1088
+ */
1089
+ declare function getMintExtensions({ data }: GetMintExtensionsOptions): RawExtension[];
1090
+
1091
+ /**
1092
+ * Options for finding an Associated Token Address.
1093
+ */
1094
+ interface FindAssociatedTokenAddressOptions {
1095
+ /** The wallet's public key (owner of the token account) */
1096
+ wallet: PublicKey;
1097
+ /** The token mint's public key */
1098
+ mint: PublicKey;
1099
+ /** The token program ID (defaults to Token-2022) */
1100
+ programId?: PublicKey;
1101
+ }
1102
+ /**
1103
+ * Finds the Associated Token Address for a wallet and mint.
1104
+ *
1105
+ * The ATA is derived using the following seeds:
1106
+ * - wallet address (32 bytes)
1107
+ * - token program ID (32 bytes)
1108
+ * - mint address (32 bytes)
1109
+ *
1110
+ * @param options - Options containing wallet, mint, and optional programId
1111
+ * @returns The derived ATA address and bump seed
1112
+ * @throws {SplTokenError} If PDA derivation fails
1113
+ *
1114
+ * @example
1115
+ * ```typescript
1116
+ * const { address, bump } = findAssociatedTokenAddress({ wallet: walletPubkey, mint: mintPubkey });
1117
+ * console.log(`ATA: ${address.toString()}`);
1118
+ * console.log(`Bump: ${bump}`);
1119
+ * ```
1120
+ */
1121
+ declare function findAssociatedTokenAddress({ wallet, mint, programId, }: FindAssociatedTokenAddressOptions): AtaDerivationResult;
1122
+ /**
1123
+ * Options for getting the Associated Token Address synchronously.
1124
+ */
1125
+ interface GetAssociatedTokenAddressSyncOptions {
1126
+ /** The wallet's public key */
1127
+ wallet: PublicKey;
1128
+ /** The token mint's public key */
1129
+ mint: PublicKey;
1130
+ /** The token program ID (defaults to Token-2022) */
1131
+ programId?: PublicKey;
1132
+ }
1133
+ /**
1134
+ * Gets the Associated Token Address without the bump seed.
1135
+ *
1136
+ * Convenience function when you only need the address.
1137
+ *
1138
+ * @param options - Options containing wallet, mint, and optional programId
1139
+ * @returns The derived ATA address
1140
+ */
1141
+ declare function getAssociatedTokenAddressSync({ wallet, mint, programId, }: GetAssociatedTokenAddressSyncOptions): PublicKey;
1142
+
1143
+ export { ASSOCIATED_TOKEN_PROGRAM_ID, type AccountMeta, AccountType, type AtaDerivationResult, ExtensionType, type Instruction, MINT_SIZE, type MetadataPointerExtension, type MintInfo, type RawExtension, SplTokenClient, SplTokenError, SplTokenErrorCode, TOKEN_2022_PROGRAM_ID, TOKEN_ACCOUNT_SIZE, TOKEN_PROGRAM_ID, type TokenAccountFilter, type TokenAccountInfo, TokenAccountState, TokenInstruction, type TokenMetadata, type TransferParams, createAssociatedTokenAccountIdempotentInstruction, createAssociatedTokenAccountInstruction, createSplTokenClient, findAssociatedTokenAddress, getAssociatedTokenAddressSync, getMintExtensions, initializeMintInstruction, mintToInstruction, parseMetadataPointerExtension, parseMintAccount, parseTokenAccount, parseTokenMetadata, transferCheckedInstruction, transferInstruction };