@rialo/spl-token 0.3.0-alpha.0 → 0.3.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.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { PublicKey, RialoClient, TransactionBuilder, Signer } from '@rialo/ts-cdk';
1
+ import { PublicKey, RialoClient, TransactionBuilder, Signer, Keypair } from '@rialo/ts-cdk';
2
2
 
3
3
  /**
4
4
  * TransferChecked instruction for SPL Token-2022.
@@ -11,22 +11,16 @@ import { PublicKey, RialoClient, TransactionBuilder, Signer } from '@rialo/ts-cd
11
11
  * Account metadata for an instruction account.
12
12
  */
13
13
  interface AccountMeta {
14
- /** The account's public key */
15
14
  pubkey: PublicKey;
16
- /** Whether this account must sign the transaction */
17
15
  isSigner: boolean;
18
- /** Whether this account's data can be modified */
19
16
  isWritable: boolean;
20
17
  }
21
18
  /**
22
19
  * A single instruction to be included in a transaction.
23
20
  */
24
21
  interface Instruction {
25
- /** The program that will process this instruction */
26
22
  programId: PublicKey;
27
- /** Accounts required by this instruction */
28
23
  accounts: AccountMeta[];
29
- /** Instruction data */
30
24
  data: Uint8Array;
31
25
  }
32
26
  /**
@@ -47,6 +41,8 @@ interface TransferCheckedInstructionOptions {
47
41
  decimals: number;
48
42
  /** Token program ID (defaults to Token-2022) */
49
43
  programId?: PublicKey;
44
+ /** Optional multisig signer accounts */
45
+ signers?: PublicKey[];
50
46
  }
51
47
  /**
52
48
  * Creates a TransferChecked instruction.
@@ -76,7 +72,7 @@ interface TransferCheckedInstructionOptions {
76
72
  * .build();
77
73
  * ```
78
74
  */
79
- declare function transferCheckedInstruction({ source, mint, destination, authority, amount, decimals, programId, }: TransferCheckedInstructionOptions): Instruction;
75
+ declare function transferCheckedInstruction({ source, mint, destination, authority, amount, decimals, signers, programId, }: TransferCheckedInstructionOptions): Instruction;
80
76
  /**
81
77
  * Options for creating a Transfer instruction.
82
78
  */
@@ -91,6 +87,8 @@ interface TransferInstructionOptions {
91
87
  amount: bigint;
92
88
  /** Token program ID (defaults to Token-2022) */
93
89
  programId?: PublicKey;
90
+ /** Optional multisig signer accounts */
91
+ signers?: PublicKey[];
94
92
  }
95
93
  /**
96
94
  * Creates a Transfer instruction (deprecated, prefer TransferChecked).
@@ -101,7 +99,7 @@ interface TransferInstructionOptions {
101
99
  * @param options - Options for the instruction
102
100
  * @returns The Transfer instruction
103
101
  */
104
- declare function transferInstruction({ source, destination, authority, amount, programId, }: TransferInstructionOptions): Instruction;
102
+ declare function transferInstruction({ source, destination, authority, amount, signers, programId, }: TransferInstructionOptions): Instruction;
105
103
 
106
104
  /**
107
105
  * Create Associated Token Account instruction for SPL Token-2022.
@@ -190,6 +188,49 @@ interface CreateAssociatedTokenAccountIdempotentInstructionOptions {
190
188
  */
191
189
  declare function createAssociatedTokenAccountIdempotentInstruction({ payer, associatedToken, owner, mint, programId, }: CreateAssociatedTokenAccountIdempotentInstructionOptions): Instruction;
192
190
 
191
+ /**
192
+ * Options for creating a MetadataPointer Initialize instruction.
193
+ */
194
+ interface InitializeMetadataPointerInstructionOptions {
195
+ /** Mint account to initialize */
196
+ mint: PublicKey;
197
+ /** Optional authority that can update the metadata address */
198
+ authority?: PublicKey | null;
199
+ /** Optional metadata address */
200
+ metadataAddress?: PublicKey | null;
201
+ /** Token program ID (defaults to Token-2022) */
202
+ programId?: PublicKey;
203
+ }
204
+ /**
205
+ * Creates a MetadataPointer Initialize instruction.
206
+ *
207
+ * Instruction data format:
208
+ * [token_instruction(1), metadata_pointer_instruction(1), authority(32), metadata_address(32)]
209
+ */
210
+ declare function initializeMetadataPointerInstruction({ mint, authority, metadataAddress, programId, }: InitializeMetadataPointerInstructionOptions): Instruction;
211
+ /**
212
+ * Options for creating a MetadataPointer Update instruction.
213
+ */
214
+ interface UpdateMetadataPointerInstructionOptions {
215
+ /** Mint account to update */
216
+ mint: PublicKey;
217
+ /** Authority that can update the metadata address */
218
+ authority: PublicKey;
219
+ /** Optional metadata address */
220
+ metadataAddress?: PublicKey | null;
221
+ /** Optional multisig signer accounts */
222
+ signers?: PublicKey[];
223
+ /** Token program ID (defaults to Token-2022) */
224
+ programId?: PublicKey;
225
+ }
226
+ /**
227
+ * Creates a MetadataPointer Update instruction.
228
+ *
229
+ * Instruction data format:
230
+ * [token_instruction(1), metadata_pointer_instruction(1), metadata_address(32)]
231
+ */
232
+ declare function updateMetadataPointerInstruction({ mint, authority, metadataAddress, signers, programId, }: UpdateMetadataPointerInstructionOptions): Instruction;
233
+
193
234
  /**
194
235
  * Options for creating an InitializeMint2 instruction.
195
236
  *
@@ -246,6 +287,8 @@ interface MintToInstructionOptions {
246
287
  amount: bigint;
247
288
  /** Token program ID (defaults to Token-2022) */
248
289
  programId?: PublicKey;
290
+ /** Optional multisig signer accounts */
291
+ signers?: PublicKey[];
249
292
  }
250
293
  /**
251
294
  * Creates a MintTo instruction for Token-2022.
@@ -270,7 +313,196 @@ interface MintToInstructionOptions {
270
313
  * });
271
314
  * ```
272
315
  */
273
- declare function mintToInstruction({ mint, destination, authority, amount, programId, }: MintToInstructionOptions): Instruction;
316
+ declare function mintToInstruction({ mint, destination, authority, amount, signers, programId, }: MintToInstructionOptions): Instruction;
317
+
318
+ /**
319
+ * Options for creating an InitializeNonTransferableMint instruction.
320
+ */
321
+ interface InitializeNonTransferableMintInstructionOptions {
322
+ /** Mint to initialize */
323
+ mint: PublicKey;
324
+ /** Token program ID (defaults to Token-2022) */
325
+ programId?: PublicKey;
326
+ }
327
+ /**
328
+ * Creates an InitializeNonTransferableMint instruction.
329
+ *
330
+ * Instruction data format:
331
+ * [token_instruction(1)]
332
+ */
333
+ declare function initializeNonTransferableMintInstruction({ mint, programId, }: InitializeNonTransferableMintInstructionOptions): Instruction;
334
+
335
+ /**
336
+ * Options for creating an InitializePermanentDelegate instruction.
337
+ */
338
+ interface InitializePermanentDelegateInstructionOptions {
339
+ /** Mint to initialize */
340
+ mint: PublicKey;
341
+ /** Permanent delegate authority */
342
+ delegate: PublicKey;
343
+ /** Token program ID (defaults to Token-2022) */
344
+ programId?: PublicKey;
345
+ }
346
+ /**
347
+ * Creates an InitializePermanentDelegate instruction.
348
+ *
349
+ * Instruction data format:
350
+ * [token_instruction(1), delegate_pubkey(32)]
351
+ */
352
+ declare function initializePermanentDelegateInstruction({ mint, delegate, programId, }: InitializePermanentDelegateInstructionOptions): Instruction;
353
+
354
+ /**
355
+ * Computes the size of TokenMetadata extension data.
356
+ */
357
+ declare function getTokenMetadataDataSize({ name, symbol, uri, additionalMetadata, }: {
358
+ name: string;
359
+ symbol: string;
360
+ uri: string;
361
+ additionalMetadata?: Array<[string, string]>;
362
+ }): number;
363
+ /**
364
+ * Options for creating a TokenMetadata Initialize instruction.
365
+ */
366
+ interface InitializeTokenMetadataInstructionOptions {
367
+ /** Mint account to initialize */
368
+ mint: PublicKey;
369
+ /** Authority allowed to update metadata */
370
+ updateAuthority: PublicKey;
371
+ /** Mint authority */
372
+ mintAuthority: PublicKey;
373
+ /** Token name */
374
+ name: string;
375
+ /** Token symbol */
376
+ symbol: string;
377
+ /** Token URI */
378
+ uri: string;
379
+ /** Optional additional metadata entries */
380
+ additionalMetadata?: Array<[string, string]>;
381
+ /** Token program ID (defaults to Token-2022) */
382
+ programId?: PublicKey;
383
+ }
384
+ /**
385
+ * Creates a TokenMetadata Initialize instruction.
386
+ *
387
+ * Instruction data format:
388
+ * [discriminator(8), name, symbol, uri]
389
+ * or with additional metadata:
390
+ * [discriminator(8), name, symbol, uri, additional_metadata]
391
+ */
392
+ declare function initializeTokenMetadataInstruction({ mint, updateAuthority, mintAuthority, name, symbol, uri, additionalMetadata, programId, }: InitializeTokenMetadataInstructionOptions): {
393
+ programId: PublicKey;
394
+ accounts: Array<{
395
+ pubkey: PublicKey;
396
+ isSigner: boolean;
397
+ isWritable: boolean;
398
+ }>;
399
+ data: Uint8Array;
400
+ };
401
+
402
+ /**
403
+ * Options for creating a TransferFee InitializeConfig instruction.
404
+ */
405
+ interface InitializeTransferFeeConfigInstructionOptions {
406
+ /** Mint to initialize */
407
+ mint: PublicKey;
408
+ /** Optional authority allowed to update transfer fees */
409
+ transferFeeConfigAuthority?: PublicKey | null;
410
+ /** Optional authority allowed to withdraw withheld fees */
411
+ withdrawWithheldAuthority?: PublicKey | null;
412
+ /** Fee rate in basis points */
413
+ transferFeeBasisPoints: number;
414
+ /** Maximum fee assessed on transfers */
415
+ maximumFee: bigint;
416
+ /** Token program ID (defaults to Token-2022) */
417
+ programId?: PublicKey;
418
+ }
419
+ /**
420
+ * Creates a TransferFee InitializeConfig instruction.
421
+ *
422
+ * Instruction data format:
423
+ * [token_instruction(1), transfer_fee_instruction(1),
424
+ * transfer_fee_config_authority(COption<Pubkey>),
425
+ * withdraw_withheld_authority(COption<Pubkey>),
426
+ * transfer_fee_basis_points(2), maximum_fee(8)]
427
+ */
428
+ declare function initializeTransferFeeConfigInstruction({ mint, transferFeeConfigAuthority, withdrawWithheldAuthority, transferFeeBasisPoints, maximumFee, programId, }: InitializeTransferFeeConfigInstructionOptions): Instruction;
429
+ /**
430
+ * Options for creating a TransferCheckedWithFee instruction.
431
+ */
432
+ interface TransferCheckedWithFeeInstructionOptions {
433
+ /** Source token account */
434
+ source: PublicKey;
435
+ /** Mint address */
436
+ mint: PublicKey;
437
+ /** Destination token account */
438
+ destination: PublicKey;
439
+ /** Authority that can transfer (owner or delegate) */
440
+ authority: PublicKey;
441
+ /** Amount to transfer */
442
+ amount: bigint;
443
+ /** Expected number of decimals */
444
+ decimals: number;
445
+ /** Expected fee assessed */
446
+ fee: bigint;
447
+ /** Optional multisig signer accounts */
448
+ signers?: PublicKey[];
449
+ /** Token program ID (defaults to Token-2022) */
450
+ programId?: PublicKey;
451
+ }
452
+ /**
453
+ * Creates a TransferCheckedWithFee instruction.
454
+ *
455
+ * Instruction data format:
456
+ * [token_instruction(1), transfer_fee_instruction(1),
457
+ * amount(8), decimals(1), fee(8)]
458
+ */
459
+ declare function transferCheckedWithFeeInstruction({ source, mint, destination, authority, amount, decimals, fee, signers, programId, }: TransferCheckedWithFeeInstructionOptions): Instruction;
460
+ /**
461
+ * Options for creating a TransferFee SetTransferFee instruction.
462
+ */
463
+ interface SetTransferFeeInstructionOptions {
464
+ /** Mint to update */
465
+ mint: PublicKey;
466
+ /** Authority allowed to set transfer fees */
467
+ authority: PublicKey;
468
+ /** Fee rate in basis points */
469
+ transferFeeBasisPoints: number;
470
+ /** Maximum fee assessed on transfers */
471
+ maximumFee: bigint;
472
+ /** Optional multisig signer accounts */
473
+ signers?: PublicKey[];
474
+ /** Token program ID (defaults to Token-2022) */
475
+ programId?: PublicKey;
476
+ }
477
+ /**
478
+ * Creates a TransferFee SetTransferFee instruction.
479
+ *
480
+ * Instruction data format:
481
+ * [token_instruction(1), transfer_fee_instruction(1),
482
+ * transfer_fee_basis_points(2), maximum_fee(8)]
483
+ */
484
+ declare function setTransferFeeInstruction({ mint, authority, transferFeeBasisPoints, maximumFee, signers, programId, }: SetTransferFeeInstructionOptions): Instruction;
485
+
486
+ /**
487
+ * Options for creating an InitializeTransferHook instruction.
488
+ */
489
+ interface InitializeTransferHookInstructionOptions {
490
+ /** Mint to initialize */
491
+ mint: PublicKey;
492
+ /** Authority that can update the hook program */
493
+ authority: PublicKey;
494
+ /** The program invoked on every transfer */
495
+ hookProgramId: PublicKey;
496
+ /** Token program ID (defaults to Token-2022) */
497
+ programId?: PublicKey;
498
+ }
499
+ /**
500
+ * Creates an InitializeTransferHook instruction.
501
+ *
502
+ * Instruction data format:
503
+ * [token_instruction(1), transfer_hook_instruction(1), authority(32), hook_program_id(32)]
504
+ */
505
+ declare function initializeTransferHookInstruction({ mint, authority, hookProgramId, programId, }: InitializeTransferHookInstructionOptions): Instruction;
274
506
 
275
507
  /**
276
508
  * Constants for SPL Token-2022 operations.
@@ -409,11 +641,25 @@ declare enum TokenInstruction {
409
641
  /** Initialize multisig with rent sysvar */
410
642
  InitializeMultisig2 = 19,
411
643
  /** Initialize mint with rent sysvar */
412
- InitializeMint2 = 20
644
+ InitializeMint2 = 20,
645
+ /** Transfer fee extension prefix */
646
+ TransferFeeExtension = 26,
647
+ /** Initialize non-transferable mint */
648
+ InitializeNonTransferableMint = 32,
649
+ /** Initialize permanent delegate */
650
+ InitializePermanentDelegate = 35,
651
+ /** Transfer hook extension prefix */
652
+ TransferHookExtension = 36,
653
+ /** Metadata pointer extension prefix */
654
+ MetadataPointerExtension = 39
413
655
  }
656
+ /** Size of extension type field in TLV (2 bytes LE u16) */
657
+ declare const TLV_TYPE_SIZE = 2;
658
+ /** Size of extension length field in TLV (2 bytes LE u16) */
659
+ declare const TLV_LENGTH_SIZE = 2;
414
660
 
415
661
  /**
416
- * TypeScript interfaces for SPL Token-2022 accounts and operations.
662
+ * TypeScript interfaces for MVP SPL Token-2022 accounts and operations.
417
663
  */
418
664
 
419
665
  /**
@@ -496,6 +742,15 @@ interface TransferParams {
496
742
  decimals: number;
497
743
  /** Whether to create destination ATA if it doesn't exist */
498
744
  createDestinationAta?: boolean;
745
+ /** Transfer fee to apply to the transfer */
746
+ transferFee?: {
747
+ fee: bigint;
748
+ };
749
+ /** Transfer hook configuration when the mint has a TransferHook extension */
750
+ transferHook?: {
751
+ /** The program invoked on every transfer (from TransferHook extension) */
752
+ hookProgramId: PublicKey;
753
+ };
499
754
  }
500
755
  /**
501
756
  * Result of deriving an Associated Token Address.
@@ -533,6 +788,73 @@ interface MetadataPointerExtension {
533
788
  /** Address where metadata is stored (usually same as mint for embedded) */
534
789
  metadataAddress: PublicKey | null;
535
790
  }
791
+ interface TransferFee {
792
+ /** First epoch where the fee applies */
793
+ epoch: bigint;
794
+ /** Maximum fee assessed on transfers */
795
+ maximumFee: bigint;
796
+ /** Fee rate in basis points */
797
+ transferFeeBasisPoints: number;
798
+ }
799
+ interface TransferFeeConfigExtension {
800
+ /** Authority allowed to update fees */
801
+ transferFeeConfigAuthority: PublicKey | null;
802
+ /** Authority allowed to withdraw withheld fees */
803
+ withdrawWithheldAuthority: PublicKey | null;
804
+ /** Withheld fees already harvested to the mint */
805
+ withheldAmount: bigint;
806
+ /** Older transfer fee parameters */
807
+ olderTransferFee: TransferFee;
808
+ /** Newer transfer fee parameters */
809
+ newerTransferFee: TransferFee;
810
+ }
811
+ interface TransferFeeAmountExtension {
812
+ /** Withheld transfer fees on the account */
813
+ withheldAmount: bigint;
814
+ }
815
+ interface NonTransferableExtension {
816
+ /** Marker indicating the mint is non-transferable */
817
+ isNonTransferable: true;
818
+ }
819
+ interface NonTransferableAccountExtension {
820
+ /** Marker indicating the account belongs to a non-transferable mint */
821
+ isNonTransferableAccount: true;
822
+ }
823
+ interface PermanentDelegateExtension {
824
+ /** The permanent delegate authority (null if set to zero pubkey) */
825
+ delegate: PublicKey | null;
826
+ }
827
+ interface TransferHookExtension {
828
+ /** Authority that can update the hook program (null if set to zero pubkey) */
829
+ authority: PublicKey | null;
830
+ /** The program invoked on every transfer (null if set to zero pubkey) */
831
+ programId: PublicKey | null;
832
+ }
833
+ type ParsedExtension = {
834
+ type: ExtensionType.TransferFeeConfig;
835
+ value: TransferFeeConfigExtension;
836
+ } | {
837
+ type: ExtensionType.TransferFeeAmount;
838
+ value: TransferFeeAmountExtension;
839
+ } | {
840
+ type: ExtensionType.NonTransferable;
841
+ value: NonTransferableExtension;
842
+ } | {
843
+ type: ExtensionType.NonTransferableAccount;
844
+ value: NonTransferableAccountExtension;
845
+ } | {
846
+ type: ExtensionType.MetadataPointer;
847
+ value: MetadataPointerExtension;
848
+ } | {
849
+ type: ExtensionType.TokenMetadata;
850
+ value: TokenMetadata;
851
+ } | {
852
+ type: ExtensionType.PermanentDelegate;
853
+ value: PermanentDelegateExtension;
854
+ } | {
855
+ type: ExtensionType.TransferHook;
856
+ value: TransferHookExtension;
857
+ };
536
858
 
537
859
  /**
538
860
  * High-level SPL Token-2022 client for token operations.
@@ -541,6 +863,25 @@ interface MetadataPointerExtension {
541
863
  * balances, reading mint info, and building transfer transactions.
542
864
  */
543
865
 
866
+ /**
867
+ * Complete mint account data from a single RPC call.
868
+ *
869
+ * Combines mint info, token metadata, and raw extension data
870
+ * to avoid redundant `getAccountInfo` calls per mint.
871
+ */
872
+ interface MintAccountData {
873
+ /** Parsed mint information (supply, decimals, authorities) */
874
+ mintInfo: MintInfo;
875
+ /** Token metadata if the TokenMetadata extension exists, null otherwise */
876
+ metadata: TokenMetadata | null;
877
+ /** Raw TLV extensions present on this mint (all types, including unparsed ones) */
878
+ rawExtensions: RawExtension[];
879
+ }
880
+ /**
881
+ * Type alias for a built transaction from TransactionBuilder.
882
+ * Using a local alias for clarity rather than inline ReturnType extraction.
883
+ */
884
+ type BuiltTransaction = ReturnType<typeof TransactionBuilder.prototype.build>;
544
885
  /**
545
886
  * Options for creating an SplTokenClient.
546
887
  */
@@ -583,9 +924,16 @@ declare class SplTokenClient {
583
924
  */
584
925
  constructor({ client, programId, }: SplTokenClientOptions);
585
926
  /**
586
- * Gets the token program ID this client is configured to use.
927
+ * Returns the Token-2022 program ID used by this client.
587
928
  */
588
929
  getProgramId(): PublicKey;
930
+ /**
931
+ * Returns the underlying RialoClient.
932
+ *
933
+ * Useful for advanced operations that need direct RPC access,
934
+ * such as MintBuilder which needs to calculate rent.
935
+ */
936
+ getRialoClient(): RialoClient;
589
937
  /**
590
938
  * Retrieves mint account information.
591
939
  *
@@ -595,10 +943,8 @@ declare class SplTokenClient {
595
943
  *
596
944
  * @example
597
945
  * ```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'}`);
946
+ * const mintInfo = await tokenClient.getMintInfo({ mint });
947
+ * console.log(mintInfo.decimals);
602
948
  * ```
603
949
  */
604
950
  getMintInfo({ mint }: {
@@ -613,17 +959,33 @@ declare class SplTokenClient {
613
959
  *
614
960
  * @example
615
961
  * ```typescript
616
- * const metadata = await tokenClient.getTokenMetadata({ mint: mintPubkey });
962
+ * const metadata = await tokenClient.getTokenMetadata({ mint });
617
963
  * if (metadata) {
618
- * console.log(`Name: ${metadata.name}`);
619
- * console.log(`Symbol: ${metadata.symbol}`);
620
- * console.log(`URI: ${metadata.uri}`);
964
+ * console.log(metadata.name, metadata.symbol);
621
965
  * }
622
966
  * ```
623
967
  */
624
- getTokenMetadata({ mint }: {
968
+ getTokenMetadata({ mint, }: {
625
969
  mint: PublicKey;
626
970
  }): Promise<TokenMetadata | null>;
971
+ /**
972
+ * Retrieves complete mint account data in a single RPC call.
973
+ *
974
+ * Returns parsed mint info, token metadata, and raw extensions from one
975
+ * `getAccountInfo` call, avoiding the redundant RPC calls that occur when
976
+ * calling `getMintInfo()` and `getTokenMetadata()` separately.
977
+ *
978
+ * Raw extensions include ALL extension types (including PermanentDelegate,
979
+ * TransferHook, etc.) unlike `getMintExtensionStates()` which only parses
980
+ * a subset.
981
+ *
982
+ * @param options - Options containing the mint public key
983
+ * @returns Combined mint info, metadata, and raw extensions
984
+ * @throws {SplTokenError} If the mint account doesn't exist
985
+ */
986
+ getMintAccountData({ mint, }: {
987
+ mint: PublicKey;
988
+ }): Promise<MintAccountData>;
627
989
  /**
628
990
  * Retrieves token account information.
629
991
  *
@@ -649,7 +1011,7 @@ declare class SplTokenClient {
649
1011
  * console.log(`Token balance: ${balance}`);
650
1012
  * ```
651
1013
  */
652
- getBalance({ wallet, mint }: {
1014
+ getBalance({ wallet, mint, }: {
653
1015
  wallet: PublicKey;
654
1016
  mint: PublicKey;
655
1017
  }): Promise<bigint>;
@@ -658,6 +1020,7 @@ declare class SplTokenClient {
658
1020
  *
659
1021
  * @param options - Options containing wallet and mint public keys
660
1022
  * @returns The derived ATA address and bump seed
1023
+ * @throws {SplTokenError} If the ATA derivation fails
661
1024
  *
662
1025
  * @example
663
1026
  * ```typescript
@@ -675,19 +1038,18 @@ declare class SplTokenClient {
675
1038
  * @param options - Options containing wallet and mint public keys
676
1039
  * @returns True if the ATA exists, false otherwise
677
1040
  */
678
- ataExists({ wallet, mint }: {
1041
+ ataExists({ wallet, mint, }: {
679
1042
  wallet: PublicKey;
680
1043
  mint: PublicKey;
681
1044
  }): Promise<boolean>;
682
1045
  /**
683
1046
  * Creates instructions for a token transfer.
684
1047
  *
685
- * This builds the necessary instructions for transferring tokens,
1048
+ * Builds the necessary instructions for transferring tokens,
686
1049
  * optionally creating the destination ATA if it doesn't exist.
687
1050
  *
688
1051
  * @param params - Transfer parameters
689
1052
  * @returns Array of instructions to execute
690
- * @throws {SplTokenError} If the mint doesn't exist
691
1053
  *
692
1054
  * @example
693
1055
  * ```typescript
@@ -702,9 +1064,6 @@ declare class SplTokenClient {
702
1064
  * ```
703
1065
  */
704
1066
  createTransferInstructions(params: TransferParams): Promise<Instruction[]>;
705
- /**
706
- * Options for creating a transfer transaction.
707
- */
708
1067
  /**
709
1068
  * Creates a transaction for a token transfer.
710
1069
  *
@@ -735,13 +1094,14 @@ declare class SplTokenClient {
735
1094
  * const signature = await rialoClient.sendTransaction(signedTx.serialize());
736
1095
  * ```
737
1096
  */
738
- createTransferTransaction({ params, validFrom, configHashPrefix, }: {
1097
+ createTransferTransaction({ params, payer, validFrom, configHashPrefix, }: {
739
1098
  params: TransferParams;
1099
+ payer: PublicKey;
740
1100
  validFrom: bigint;
741
1101
  configHashPrefix: bigint;
742
- }): Promise<ReturnType<typeof TransactionBuilder.prototype.build>>;
1102
+ }): Promise<BuiltTransaction>;
743
1103
  /**
744
- * Transfers tokens from one wallet to another.
1104
+ * Transfers tokens and sends the transaction.
745
1105
  *
746
1106
  * This is a high-level convenience method that:
747
1107
  * 1. Creates the destination ATA if needed
@@ -749,7 +1109,7 @@ declare class SplTokenClient {
749
1109
  * 3. Signs and sends the transaction
750
1110
  * 4. Waits for confirmation
751
1111
  *
752
- * @param options - Options containing params, validFrom, and signer
1112
+ * @param options - Transfer params, payer, validFrom, and signers
753
1113
  * @returns Transaction signature
754
1114
  *
755
1115
  * @example
@@ -771,85 +1131,435 @@ declare class SplTokenClient {
771
1131
  * console.log(`Transfer complete: ${signature}`);
772
1132
  * ```
773
1133
  */
774
- transfer({ params, validFrom, configHashPrefix, signer, }: {
1134
+ transfer({ params, payer, validFrom, configHashPrefix, signers, }: {
775
1135
  params: TransferParams;
1136
+ payer: PublicKey;
776
1137
  validFrom: bigint;
777
1138
  configHashPrefix: bigint;
778
- signer: Signer;
1139
+ signers: Signer[];
1140
+ }): Promise<string>;
1141
+ /**
1142
+ * Initializes a mint and sends the transaction.
1143
+ *
1144
+ * @param options - Initialize mint params, payer, validFrom, and signers
1145
+ * @returns Transaction signature
1146
+ */
1147
+ initializeMint({ params, payer, validFrom, signers, }: {
1148
+ params: InitializeMintInstructionOptions;
1149
+ payer: PublicKey;
1150
+ validFrom: bigint;
1151
+ signers: Signer[];
1152
+ }): Promise<string>;
1153
+ /**
1154
+ * Mints tokens and sends the transaction.
1155
+ *
1156
+ * @param options - Mint-to params, payer, validFrom, and signers
1157
+ * @returns Transaction signature
1158
+ */
1159
+ mintTo({ params, payer, validFrom, signers, }: {
1160
+ params: MintToInstructionOptions;
1161
+ payer: PublicKey;
1162
+ validFrom: bigint;
1163
+ signers: Signer[];
1164
+ }): Promise<string>;
1165
+ /**
1166
+ * Initializes token metadata on a mint.
1167
+ *
1168
+ * Use this for the on-mint TokenMetadata extension flow.
1169
+ *
1170
+ * @param options - Token metadata params, payer, validFrom, and signers
1171
+ * @returns Transaction signature
1172
+ */
1173
+ initializeTokenMetadata({ params, payer, validFrom, signers, }: {
1174
+ params: InitializeTokenMetadataInstructionOptions;
1175
+ payer: PublicKey;
1176
+ validFrom: bigint;
1177
+ signers: Signer[];
1178
+ }): Promise<string>;
1179
+ /**
1180
+ * Initializes a metadata pointer extension on a mint.
1181
+ *
1182
+ * Use this for the Metadata Pointer flow, where metadata lives in
1183
+ * a separate account and the mint stores a pointer to it.
1184
+ *
1185
+ * @param options - Metadata pointer params, payer, validFrom, and signers
1186
+ * @returns Transaction signature
1187
+ */
1188
+ initializeMetadataPointer({ params, payer, validFrom, signers, }: {
1189
+ params: InitializeMetadataPointerInstructionOptions;
1190
+ payer: PublicKey;
1191
+ validFrom: bigint;
1192
+ signers: Signer[];
1193
+ }): Promise<string>;
1194
+ /**
1195
+ * Updates a metadata pointer extension on a mint.
1196
+ *
1197
+ * @param options - Metadata pointer params, payer, validFrom, and signers
1198
+ * @returns Transaction signature
1199
+ */
1200
+ updateMetadataPointer({ params, payer, validFrom, signers, }: {
1201
+ params: UpdateMetadataPointerInstructionOptions;
1202
+ payer: PublicKey;
1203
+ validFrom: bigint;
1204
+ signers: Signer[];
1205
+ }): Promise<string>;
1206
+ /**
1207
+ * Initializes a transfer fee config on a mint.
1208
+ *
1209
+ * @param options - Transfer fee config params, payer, validFrom, and signers
1210
+ * @returns Transaction signature
1211
+ */
1212
+ initializeTransferFeeConfig({ params, payer, validFrom, signers, }: {
1213
+ params: InitializeTransferFeeConfigInstructionOptions;
1214
+ payer: PublicKey;
1215
+ validFrom: bigint;
1216
+ signers: Signer[];
1217
+ }): Promise<string>;
1218
+ /**
1219
+ * Transfers tokens with a fee and sends the transaction.
1220
+ *
1221
+ * @param options - Transfer params, payer, validFrom, and signers
1222
+ * @returns Transaction signature
1223
+ */
1224
+ transferCheckedWithFee({ params, payer, validFrom, signers, }: {
1225
+ params: TransferCheckedWithFeeInstructionOptions;
1226
+ payer: PublicKey;
1227
+ validFrom: bigint;
1228
+ signers: Signer[];
1229
+ }): Promise<string>;
1230
+ /**
1231
+ * Initializes a non-transferable mint.
1232
+ *
1233
+ * @param options - Non-transferable mint params, payer, validFrom, and signers
1234
+ * @returns Transaction signature
1235
+ */
1236
+ initializeNonTransferableMint({ params, payer, validFrom, signers, }: {
1237
+ params: InitializeNonTransferableMintInstructionOptions;
1238
+ payer: PublicKey;
1239
+ validFrom: bigint;
1240
+ signers: Signer[];
779
1241
  }): Promise<string>;
1242
+ private signAndSend;
780
1243
  }
781
1244
  /**
782
- * Options for creating an SplTokenClient via the factory function.
1245
+ * Factory function to create a SplTokenClient.
1246
+ *
1247
+ * @example
1248
+ * ```typescript
1249
+ * const tokenClient = createSplTokenClient({ client: rialoClient });
1250
+ * ```
783
1251
  */
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
- }
1252
+ declare function createSplTokenClient(options: SplTokenClientOptions): SplTokenClient;
1253
+
790
1254
  /**
791
- * Creates a new SplTokenClient.
1255
+ * Fluent builder for creating SPL Token-2022 mints with extensions.
792
1256
  *
793
- * Factory function for creating an SplTokenClient instance.
794
- *
795
- * @param options - Options for creating the client
796
- * @returns Configured SplTokenClient instance
1257
+ * MintBuilder simplifies the process of creating mints by providing a
1258
+ * chainable API that handles:
1259
+ * - Account size calculation
1260
+ * - Rent-exempt balance calculation
1261
+ * - Instruction ordering (extensions must be initialized before mint)
1262
+ * - Transaction building
797
1263
  *
798
1264
  * @example
799
1265
  * ```typescript
800
- * import { createRialoClient, RIALO_DEVNET_CHAIN } from '@rialo/ts-cdk';
801
- * import { createSplTokenClient } from '@rialo/spl-token';
1266
+ * import { MintBuilder, createSplTokenClient } from "@rialo/spl-token";
802
1267
  *
803
- * const rialoClient = createRialoClient({ chain: RIALO_DEVNET_CHAIN });
804
- * const tokenClient = createSplTokenClient({ client: rialoClient });
1268
+ * const tokenClient = createSplTokenClient({ client });
1269
+ *
1270
+ * const { signature, mintAddress } = await MintBuilder.create(tokenClient)
1271
+ * .withDecimals(9)
1272
+ * .withMintAuthority(authority)
1273
+ * .withMetadata({
1274
+ * name: "My Token",
1275
+ * symbol: "MTK",
1276
+ * uri: "https://example.com/metadata.json",
1277
+ * })
1278
+ * .send({
1279
+ * payer: authority,
1280
+ * mintKeypair,
1281
+ * validFrom: BigInt(Date.now()),
1282
+ * signers: [authorityKeypair, mintKeypair],
1283
+ * });
805
1284
  * ```
806
1285
  */
807
- declare function createSplTokenClient({ client, programId, }: CreateSplTokenClientOptions): SplTokenClient;
808
1286
 
809
1287
  /**
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.
1288
+ * Token metadata configuration for MintBuilder.
814
1289
  */
1290
+ interface MintMetadataConfig {
1291
+ /** Token name */
1292
+ name: string;
1293
+ /** Token symbol */
1294
+ symbol: string;
1295
+ /** Token URI (typically points to JSON metadata) */
1296
+ uri: string;
1297
+ /** Optional additional metadata key-value pairs */
1298
+ additionalMetadata?: Array<[string, string]>;
1299
+ }
815
1300
  /**
816
- * Error codes for SPL Token operations.
1301
+ * Transfer fee configuration for MintBuilder.
817
1302
  */
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"
1303
+ interface MintTransferFeeConfig {
1304
+ /** Transfer fee authority */
1305
+ transferFeeConfigAuthority: PublicKey;
1306
+ /** Withdraw withheld authority */
1307
+ withdrawWithheldAuthority: PublicKey;
1308
+ /** Fee rate in basis points (100 = 1%) */
1309
+ transferFeeBasisPoints: number;
1310
+ /** Maximum fee in smallest units */
1311
+ maximumFee: bigint;
839
1312
  }
840
1313
  /**
841
- * Constructor options for SplTokenError.
1314
+ * Initial mint configuration for MintBuilder.
842
1315
  */
843
- interface SplTokenErrorOptions {
844
- code: SplTokenErrorCode;
845
- message: string;
846
- details?: Record<string, unknown>;
1316
+ interface MintInitialSupplyConfig {
1317
+ /** Wallet address to receive initial tokens (ATA will be derived) */
1318
+ destination: PublicKey;
1319
+ /** Amount to mint in smallest units */
1320
+ amount: bigint;
847
1321
  }
848
1322
  /**
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.
1323
+ * Options for building a mint transaction.
1324
+ */
1325
+ interface MintBuildOptions {
1326
+ /** Fee payer for the transaction */
1327
+ payer: PublicKey;
1328
+ /** Keypair for the new mint account */
1329
+ mintKeypair: Keypair;
1330
+ /** Transaction validity timestamp */
1331
+ validFrom: bigint;
1332
+ }
1333
+ /**
1334
+ * Options for sending a mint transaction.
1335
+ */
1336
+ interface MintSendOptions extends MintBuildOptions {
1337
+ /** Keypairs for signing the transaction (must include payer and mintKeypair) */
1338
+ signers: Keypair[];
1339
+ }
1340
+ /**
1341
+ * Result of building a mint transaction.
1342
+ */
1343
+ interface MintBuildResult {
1344
+ /** The built transaction, ready for signing */
1345
+ transaction: ReturnType<typeof TransactionBuilder.prototype.build>;
1346
+ /** The mint address */
1347
+ mintAddress: PublicKey;
1348
+ /** The ATA address if initial supply was configured */
1349
+ ataAddress?: PublicKey;
1350
+ }
1351
+ /**
1352
+ * Result of sending a mint transaction.
1353
+ */
1354
+ interface MintSendResult {
1355
+ /** Transaction signature */
1356
+ signature: string;
1357
+ /** The mint address */
1358
+ mintAddress: PublicKey;
1359
+ /** The ATA address if initial supply was configured */
1360
+ ataAddress?: PublicKey;
1361
+ }
1362
+ /**
1363
+ * Fluent builder for creating SPL Token-2022 mints with extensions.
1364
+ *
1365
+ * Use `MintBuilder.create(tokenClient)` to start building.
1366
+ */
1367
+ declare class MintBuilder {
1368
+ private readonly client;
1369
+ private readonly programId;
1370
+ private decimals;
1371
+ private mintAuthority;
1372
+ private freezeAuthority;
1373
+ private metadata;
1374
+ private transferFee;
1375
+ private nonTransferable;
1376
+ private permanentDelegate;
1377
+ private transferHook;
1378
+ private initialSupply;
1379
+ private constructor();
1380
+ /**
1381
+ * Creates a new MintBuilder instance.
1382
+ *
1383
+ * @param tokenClient - SplTokenClient instance
1384
+ * @returns A new MintBuilder
1385
+ *
1386
+ * @example
1387
+ * ```typescript
1388
+ * const builder = MintBuilder.create(tokenClient);
1389
+ * ```
1390
+ */
1391
+ static create(tokenClient: SplTokenClient): MintBuilder;
1392
+ /**
1393
+ * Sets the number of decimals for the token.
1394
+ *
1395
+ * SPL Token-2022 stores decimals as a u8, so values from 0 to 255 are
1396
+ * valid at the protocol level. Common choices are 6 (USDC-style) or 9
1397
+ * (SOL-style). Values above 9 are uncommon on Solana but fully supported.
1398
+ *
1399
+ * @param decimals - Number of decimals (0-255)
1400
+ * @returns this for chaining
1401
+ */
1402
+ withDecimals(decimals: number): this;
1403
+ /**
1404
+ * Sets the mint authority.
1405
+ *
1406
+ * @param authority - Public key of the mint authority
1407
+ * @returns this for chaining
1408
+ */
1409
+ withMintAuthority(authority: PublicKey): this;
1410
+ /**
1411
+ * Sets the freeze authority.
1412
+ *
1413
+ * @param authority - Public key of the freeze authority
1414
+ * @returns this for chaining
1415
+ */
1416
+ withFreezeAuthority(authority: PublicKey): this;
1417
+ /**
1418
+ * Configures token metadata extension.
1419
+ *
1420
+ * This enables both MetadataPointer and TokenMetadata extensions,
1421
+ * with the metadata stored directly on the mint account.
1422
+ *
1423
+ * @param metadata - Token metadata configuration
1424
+ * @returns this for chaining
1425
+ */
1426
+ withMetadata(metadata: MintMetadataConfig): this;
1427
+ /**
1428
+ * Configures transfer fee extension.
1429
+ *
1430
+ * @param config - Transfer fee configuration
1431
+ * @returns this for chaining
1432
+ */
1433
+ withTransferFee(config: MintTransferFeeConfig): this;
1434
+ /**
1435
+ * Makes the mint non-transferable.
1436
+ *
1437
+ * Non-transferable tokens (soulbound tokens) cannot be transferred
1438
+ * after minting.
1439
+ *
1440
+ * @returns this for chaining
1441
+ */
1442
+ withNonTransferable(): this;
1443
+ /**
1444
+ * Configures permanent delegate extension.
1445
+ *
1446
+ * A permanent delegate has unrestricted transfer and burn authority
1447
+ * over all token accounts for this mint.
1448
+ *
1449
+ * @param delegate - Public key of the permanent delegate
1450
+ * @returns this for chaining
1451
+ */
1452
+ withPermanentDelegate(delegate: PublicKey): this;
1453
+ /**
1454
+ * Configures transfer hook extension.
1455
+ *
1456
+ * A transfer hook invokes a specified program on every token transfer,
1457
+ * enabling custom transfer logic (e.g., compliance checks, royalties).
1458
+ *
1459
+ * @param config - Transfer hook configuration
1460
+ * @returns this for chaining
1461
+ */
1462
+ withTransferHook(config: {
1463
+ authority: PublicKey;
1464
+ programId: PublicKey;
1465
+ }): this;
1466
+ /**
1467
+ * Configures initial token supply to mint after creation.
1468
+ *
1469
+ * The tokens will be minted to an Associated Token Account (ATA)
1470
+ * derived from the destination wallet.
1471
+ *
1472
+ * @param config - Initial supply configuration
1473
+ * @returns this for chaining
1474
+ */
1475
+ withInitialSupply(config: MintInitialSupplyConfig): this;
1476
+ /**
1477
+ * Builds the mint transaction without sending.
1478
+ *
1479
+ * @param options - Build options
1480
+ * @returns Build result with transaction and addresses
1481
+ *
1482
+ * @example
1483
+ * ```typescript
1484
+ * const { transaction, mintAddress } = await builder.build({
1485
+ * payer: authority,
1486
+ * mintKeypair,
1487
+ * validFrom: BigInt(Date.now()),
1488
+ * });
1489
+ *
1490
+ * // Sign manually
1491
+ * const signed = transaction.sign(authorityKeypair).sign(mintKeypair);
1492
+ * await client.sendAndConfirmTransaction(signed.serialize());
1493
+ * ```
1494
+ */
1495
+ build(options: MintBuildOptions): Promise<MintBuildResult>;
1496
+ /**
1497
+ * Builds, signs, and sends the mint transaction.
1498
+ *
1499
+ * @param options - Send options including signers
1500
+ * @returns Send result with signature and addresses
1501
+ *
1502
+ * @example
1503
+ * ```typescript
1504
+ * const { signature, mintAddress } = await builder.send({
1505
+ * payer: authority,
1506
+ * mintKeypair,
1507
+ * validFrom: BigInt(Date.now()),
1508
+ * signers: [authorityKeypair, mintKeypair],
1509
+ * });
1510
+ * ```
1511
+ */
1512
+ send(options: MintSendOptions): Promise<MintSendResult>;
1513
+ /**
1514
+ * Returns the list of extensions that will be enabled.
1515
+ */
1516
+ private getExtensions;
1517
+ }
1518
+
1519
+ /**
1520
+ * Error handling for SPL Token operations.
1521
+ *
1522
+ * This module defines the error types and factory methods for all
1523
+ * SPL Token-related operations, following the same pattern as RialoError.
1524
+ */
1525
+ /**
1526
+ * Error codes for SPL Token operations.
1527
+ */
1528
+ declare enum SplTokenErrorCode {
1529
+ /** Invalid mint account data */
1530
+ INVALID_MINT = "INVALID_MINT",
1531
+ /** Invalid token account data */
1532
+ INVALID_TOKEN_ACCOUNT = "INVALID_TOKEN_ACCOUNT",
1533
+ /** Token account not found */
1534
+ TOKEN_ACCOUNT_NOT_FOUND = "TOKEN_ACCOUNT_NOT_FOUND",
1535
+ /** Mint account not found */
1536
+ MINT_NOT_FOUND = "MINT_NOT_FOUND",
1537
+ /** Token account is frozen */
1538
+ ACCOUNT_FROZEN = "ACCOUNT_FROZEN",
1539
+ /** Insufficient token balance */
1540
+ INSUFFICIENT_BALANCE = "INSUFFICIENT_BALANCE",
1541
+ /** Invalid extension data */
1542
+ INVALID_EXTENSION = "INVALID_EXTENSION",
1543
+ /** PDA derivation failed */
1544
+ PDA_DERIVATION_FAILED = "PDA_DERIVATION_FAILED",
1545
+ /** Invalid metadata */
1546
+ INVALID_METADATA = "INVALID_METADATA",
1547
+ /** Account not initialized */
1548
+ ACCOUNT_NOT_INITIALIZED = "ACCOUNT_NOT_INITIALIZED"
1549
+ }
1550
+ /**
1551
+ * Constructor options for SplTokenError.
1552
+ */
1553
+ interface SplTokenErrorOptions {
1554
+ code: SplTokenErrorCode;
1555
+ message: string;
1556
+ details?: Record<string, unknown>;
1557
+ }
1558
+ /**
1559
+ * Error class for SPL Token operations.
1560
+ *
1561
+ * Provides structured error handling with error codes and optional details.
1562
+ * Use the static factory methods for consistent error creation.
853
1563
  *
854
1564
  * @example
855
1565
  * ```typescript
@@ -956,68 +1666,378 @@ declare class SplTokenError extends Error {
956
1666
  }
957
1667
 
958
1668
  /**
959
- * Mint account parsing for SPL Token-2022.
1669
+ * Size calculation helpers for SPL Token-2022 accounts with extensions.
1670
+ *
1671
+ * These utilities simplify the process of calculating account sizes and
1672
+ * rent-exempt balances when creating mints with Token-2022 extensions.
1673
+ *
1674
+ * @example
1675
+ * ```typescript
1676
+ * import { getMintSizeWithExtensions, ExtensionType } from "@rialo/spl-token";
1677
+ *
1678
+ * const size = getMintSizeWithExtensions({
1679
+ * extensions: [ExtensionType.MetadataPointer],
1680
+ * metadataSize: getMetadataExtensionSize({ name: "My Token", symbol: "MTK", uri: "https://..." }),
1681
+ * });
1682
+ * ```
960
1683
  */
961
1684
 
962
1685
  /**
963
- * Options for parsing a mint account.
1686
+ * Options for calculating mint size with extensions.
964
1687
  */
965
- interface ParseMintAccountOptions {
966
- /** The mint account's public key */
967
- address: PublicKey;
968
- /** Raw account data bytes (minimum 82 bytes) */
969
- data: Uint8Array;
1688
+ interface GetMintSizeWithExtensionsOptions {
1689
+ /** Array of extension types to include */
1690
+ extensions: ExtensionType[];
1691
+ /**
1692
+ * Size of token metadata data in bytes.
1693
+ * Required if extensions includes ExtensionType.TokenMetadata.
1694
+ * Use getMetadataExtensionSize() to calculate this.
1695
+ */
1696
+ metadataSize?: number;
970
1697
  }
971
1698
  /**
972
- * Parses raw mint account data into a structured MintInfo object.
1699
+ * Calculates the total size of a mint account with the specified extensions.
973
1700
  *
974
- * @param options - Options containing address and data
975
- * @returns Parsed mint information
976
- * @throws {SplTokenError} If the data is invalid or too short
1701
+ * The size includes:
1702
+ * - Base mint size (82 bytes)
1703
+ * - Account type discriminator (1 byte)
1704
+ * - TLV headers and data for each extension
1705
+ *
1706
+ * Note: The base mint account is padded to TOKEN_ACCOUNT_SIZE (165 bytes) when
1707
+ * extensions are present, to maintain alignment.
1708
+ *
1709
+ * @param options - Extension configuration
1710
+ * @returns Total account size in bytes
977
1711
  *
978
1712
  * @example
979
1713
  * ```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
- * }
1714
+ * // Mint with metadata pointer only
1715
+ * const sizePointerOnly = getMintSizeWithExtensions({
1716
+ * extensions: [ExtensionType.MetadataPointer],
1717
+ * });
1718
+ *
1719
+ * // Mint with metadata pointer + full metadata
1720
+ * const metadataSize = getMetadataExtensionSize({
1721
+ * name: "My Token",
1722
+ * symbol: "MTK",
1723
+ * uri: "https://example.com/metadata.json",
1724
+ * });
1725
+ * const sizeWithMetadata = getMintSizeWithExtensions({
1726
+ * extensions: [ExtensionType.MetadataPointer, ExtensionType.TokenMetadata],
1727
+ * metadataSize,
1728
+ * });
986
1729
  * ```
987
1730
  */
988
- declare function parseMintAccount({ address, data }: ParseMintAccountOptions): MintInfo;
1731
+ declare function getMintSizeWithExtensions({ extensions, metadataSize, }: GetMintSizeWithExtensionsOptions): number;
1732
+ /**
1733
+ * Calculates the size of token metadata extension data.
1734
+ *
1735
+ * This is a convenience re-export of getTokenMetadataDataSize for use
1736
+ * with getMintSizeWithExtensions.
1737
+ *
1738
+ * @param metadata - Token metadata fields
1739
+ * @returns Size of the metadata data in bytes (excluding TLV header)
1740
+ *
1741
+ * @example
1742
+ * ```typescript
1743
+ * const metadataSize = getMetadataExtensionSize({
1744
+ * name: "Rialo Test Token",
1745
+ * symbol: "RTST",
1746
+ * uri: "https://picsum.photos/id/237/50/50",
1747
+ * });
1748
+ * // metadataSize can now be passed to getMintSizeWithExtensions
1749
+ * ```
1750
+ */
1751
+ declare function getMetadataExtensionSize({ name, symbol, uri, additionalMetadata, }: {
1752
+ name: string;
1753
+ symbol: string;
1754
+ uri: string;
1755
+ additionalMetadata?: Array<[string, string]>;
1756
+ }): number;
1757
+ /**
1758
+ * Calculates the minimum lamports required for a mint account to be rent-exempt.
1759
+ *
1760
+ * @param client - Rialo client for RPC calls
1761
+ * @param options - Extension configuration
1762
+ * @returns Minimum balance for rent exemption in lamports
1763
+ *
1764
+ * @example
1765
+ * ```typescript
1766
+ * const rent = await getMinRentForMint(client, {
1767
+ * extensions: [ExtensionType.MetadataPointer, ExtensionType.TokenMetadata],
1768
+ * metadataSize: getMetadataExtensionSize({ name, symbol, uri }),
1769
+ * });
1770
+ * ```
1771
+ */
1772
+ declare function getMinRentForMint(client: RialoClient, options: GetMintSizeWithExtensionsOptions): Promise<bigint>;
1773
+ /**
1774
+ * Calculates the size of a mint account with metadata pointer and token metadata.
1775
+ *
1776
+ * This is a convenience function for the common case of creating a mint
1777
+ * with embedded metadata (metadata pointer pointing to self + token metadata).
1778
+ *
1779
+ * @param metadata - Token metadata fields
1780
+ * @returns Total account size in bytes
1781
+ *
1782
+ * @example
1783
+ * ```typescript
1784
+ * const size = getMintSizeWithMetadata({
1785
+ * name: "Rialo Test Token",
1786
+ * symbol: "RTST",
1787
+ * uri: "https://example.com/metadata.json",
1788
+ * });
1789
+ * const rent = await client.getMinimumBalanceForRentExemption(BigInt(size));
1790
+ * ```
1791
+ */
1792
+ declare function getMintSizeWithMetadata({ name, symbol, uri, additionalMetadata, }: {
1793
+ name: string;
1794
+ symbol: string;
1795
+ uri: string;
1796
+ additionalMetadata?: Array<[string, string]>;
1797
+ }): number;
1798
+ /**
1799
+ * Calculates the minimum lamports required for a mint with metadata to be rent-exempt.
1800
+ *
1801
+ * Convenience function that combines size calculation and rent lookup for the
1802
+ * common case of creating a mint with embedded metadata.
1803
+ *
1804
+ * @param client - Rialo client for RPC calls
1805
+ * @param metadata - Token metadata fields
1806
+ * @returns Minimum balance for rent exemption in lamports
1807
+ *
1808
+ * @example
1809
+ * ```typescript
1810
+ * const rent = await getMinRentForMintWithMetadata(client, {
1811
+ * name: "Rialo Test Token",
1812
+ * symbol: "RTST",
1813
+ * uri: "https://example.com/metadata.json",
1814
+ * });
1815
+ * ```
1816
+ */
1817
+ declare function getMinRentForMintWithMetadata(client: RialoClient, metadata: {
1818
+ name: string;
1819
+ symbol: string;
1820
+ uri: string;
1821
+ additionalMetadata?: Array<[string, string]>;
1822
+ }): Promise<bigint>;
989
1823
 
990
1824
  /**
991
- * Token account parsing for SPL Token-2022.
1825
+ * Options for finding an Associated Token Address.
1826
+ */
1827
+ interface FindAssociatedTokenAddressOptions {
1828
+ /** The wallet's public key (owner of the token account) */
1829
+ wallet: PublicKey;
1830
+ /** The token mint's public key */
1831
+ mint: PublicKey;
1832
+ /** The token program ID (defaults to Token-2022) */
1833
+ programId?: PublicKey;
1834
+ }
1835
+ /**
1836
+ * Finds the Associated Token Address for a wallet and mint.
1837
+ *
1838
+ * The ATA is derived using the following seeds:
1839
+ * - wallet address (32 bytes)
1840
+ * - token program ID (32 bytes)
1841
+ * - mint address (32 bytes)
1842
+ *
1843
+ * @param options - Options containing wallet, mint, and optional programId
1844
+ * @returns The derived ATA address and bump seed
1845
+ * @throws {SplTokenError} If PDA derivation fails
1846
+ *
1847
+ * @example
1848
+ * ```typescript
1849
+ * const { address, bump } = findAssociatedTokenAddress({ wallet: walletPubkey, mint: mintPubkey });
1850
+ * console.log(`ATA: ${address.toString()}`);
1851
+ * console.log(`Bump: ${bump}`);
1852
+ * ```
1853
+ */
1854
+ declare function findAssociatedTokenAddress({ wallet, mint, programId, }: FindAssociatedTokenAddressOptions): AtaDerivationResult;
1855
+ /**
1856
+ * Options for getting the Associated Token Address synchronously.
992
1857
  */
1858
+ interface GetAssociatedTokenAddressSyncOptions {
1859
+ /** The wallet's public key */
1860
+ wallet: PublicKey;
1861
+ /** The token mint's public key */
1862
+ mint: PublicKey;
1863
+ /** The token program ID (defaults to Token-2022) */
1864
+ programId?: PublicKey;
1865
+ }
1866
+ /**
1867
+ * Gets the Associated Token Address without the bump seed.
1868
+ *
1869
+ * Convenience function when you only need the address.
1870
+ *
1871
+ * @param options - Options containing wallet, mint, and optional programId
1872
+ * @returns The derived ATA address
1873
+ */
1874
+ declare function getAssociatedTokenAddressSync({ wallet, mint, programId, }: GetAssociatedTokenAddressSyncOptions): PublicKey;
993
1875
 
994
1876
  /**
995
- * Options for parsing a token account.
1877
+ * High-level recipe for creating a Token-2022 mint with metadata.
1878
+ *
1879
+ * This module provides a simple, one-call function to create a new token
1880
+ * with metadata extension, optionally minting initial supply.
1881
+ *
1882
+ * @example
1883
+ * ```typescript
1884
+ * import { createSplTokenClient, createTokenWithMetadata } from "@rialo/spl-token";
1885
+ *
1886
+ * const tokenClient = createSplTokenClient({ client });
1887
+ *
1888
+ * const { signature, mintAddress } = await createTokenWithMetadata(tokenClient, {
1889
+ * decimals: 9,
1890
+ * mintAuthority: masterPubkey,
1891
+ * metadata: {
1892
+ * name: "Rialo Test Token",
1893
+ * symbol: "RTST",
1894
+ * uri: "https://example.com/image.png",
1895
+ * },
1896
+ * initialMint: {
1897
+ * destination: masterPubkey,
1898
+ * amount: 1_000_000_000_000_000n,
1899
+ * },
1900
+ * }, {
1901
+ * payer: masterPubkey,
1902
+ * mintKeypair,
1903
+ * validFrom: BigInt(Date.now()),
1904
+ * signers: [masterKeypair, mintKeypair],
1905
+ * });
1906
+ * ```
996
1907
  */
997
- interface ParseTokenAccountOptions {
998
- /** The token account's public key */
999
- address: PublicKey;
1000
- /** Raw account data bytes (minimum 165 bytes) */
1001
- data: Uint8Array;
1908
+
1909
+ /**
1910
+ * Token metadata configuration.
1911
+ */
1912
+ interface TokenMetadataParams {
1913
+ /** Token name */
1914
+ name: string;
1915
+ /** Token symbol */
1916
+ symbol: string;
1917
+ /** Token URI (typically points to JSON metadata or an image) */
1918
+ uri: string;
1919
+ /** Optional additional metadata key-value pairs */
1920
+ additionalMetadata?: Array<[string, string]>;
1002
1921
  }
1003
1922
  /**
1004
- * Parses raw token account data into a structured TokenAccountInfo object.
1923
+ * Parameters for creating a token with metadata.
1924
+ */
1925
+ interface CreateTokenWithMetadataParams {
1926
+ /** Number of decimals for the token (0-255, SPL Token-2022 stores this as a u8) */
1927
+ decimals: number;
1928
+ /** Public key of the mint authority */
1929
+ mintAuthority: PublicKey;
1930
+ /** Optional freeze authority */
1931
+ freezeAuthority?: PublicKey;
1932
+ /** Token metadata configuration */
1933
+ metadata: TokenMetadataParams;
1934
+ /**
1935
+ * Optional initial mint configuration.
1936
+ * If provided, tokens will be minted to the destination wallet's ATA.
1937
+ */
1938
+ initialMint?: {
1939
+ /** Wallet address to receive initial tokens */
1940
+ destination: PublicKey;
1941
+ /** Amount to mint in smallest units */
1942
+ amount: bigint;
1943
+ };
1944
+ }
1945
+ /**
1946
+ * Transaction options for creating a token.
1947
+ */
1948
+ interface CreateTokenWithMetadataOptions {
1949
+ /** Fee payer for the transaction */
1950
+ payer: PublicKey;
1951
+ /** Keypair for the new mint account */
1952
+ mintKeypair: Keypair;
1953
+ /** Transaction validity timestamp (milliseconds since epoch) */
1954
+ validFrom: bigint;
1955
+ /** Keypairs for signing the transaction (must include payer and mintKeypair) */
1956
+ signers: Keypair[];
1957
+ }
1958
+ /**
1959
+ * Result of creating a token with metadata.
1960
+ */
1961
+ interface CreateTokenWithMetadataResult {
1962
+ /** Transaction signature */
1963
+ signature: string;
1964
+ /** The mint address */
1965
+ mintAddress: PublicKey;
1966
+ /** The ATA address if initial mint was configured */
1967
+ ataAddress?: PublicKey;
1968
+ }
1969
+ /**
1970
+ * Creates a new SPL Token-2022 mint with metadata extension.
1005
1971
  *
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
1972
+ * This is a high-level convenience function that handles:
1973
+ * - Account size calculation for metadata
1974
+ * - Rent-exempt balance calculation
1975
+ * - Creating the mint account
1976
+ * - Initializing metadata pointer and metadata extensions
1977
+ * - Optionally creating an ATA and minting initial supply
1978
+ *
1979
+ * @param tokenClient - SplTokenClient instance
1980
+ * @param params - Token configuration parameters
1981
+ * @param options - Transaction options
1982
+ * @returns Result with signature and addresses
1009
1983
  *
1010
1984
  * @example
1011
1985
  * ```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
- * }
1986
+ * // Simple token creation
1987
+ * const { mintAddress } = await createTokenWithMetadata(tokenClient, {
1988
+ * decimals: 9,
1989
+ * mintAuthority: authority,
1990
+ * metadata: { name: "My Token", symbol: "MTK", uri: "https://..." },
1991
+ * }, { payer: authority, mintKeypair, validFrom: BigInt(Date.now()), signers: [authorityKeypair, mintKeypair] });
1992
+ *
1993
+ * // With initial supply
1994
+ * const { mintAddress, ataAddress } = await createTokenWithMetadata(tokenClient, {
1995
+ * decimals: 9,
1996
+ * mintAuthority: authority,
1997
+ * metadata: { name: "My Token", symbol: "MTK", uri: "https://..." },
1998
+ * initialMint: { destination: authority, amount: 1_000_000_000n },
1999
+ * }, { payer: authority, mintKeypair, validFrom: BigInt(Date.now()), signers: [authorityKeypair, mintKeypair] });
1018
2000
  * ```
1019
2001
  */
1020
- declare function parseTokenAccount({ address, data }: ParseTokenAccountOptions): TokenAccountInfo;
2002
+ declare function createTokenWithMetadata(tokenClient: SplTokenClient, params: CreateTokenWithMetadataParams, options: CreateTokenWithMetadataOptions): Promise<CreateTokenWithMetadataResult>;
2003
+
2004
+ declare function parseTransferFeeConfigExtension({ data, }: {
2005
+ data: Uint8Array;
2006
+ }): TransferFeeConfigExtension;
2007
+ declare function parsePermanentDelegateExtension({ data, }: {
2008
+ data: Uint8Array;
2009
+ }): PermanentDelegateExtension;
2010
+ declare function parseTransferHookExtension({ data }: {
2011
+ data: Uint8Array;
2012
+ }): TransferHookExtension;
2013
+ declare function parseMetadataPointerExtensionData({ data, }: {
2014
+ data: Uint8Array;
2015
+ }): MetadataPointerExtension;
2016
+ declare function parseTokenMetadataExtensionData({ data }: {
2017
+ data: Uint8Array;
2018
+ }): TokenMetadata;
2019
+ declare function parseExtension({ extension }: {
2020
+ extension: RawExtension;
2021
+ }): ParsedExtension | null;
2022
+ declare function getMintExtensionStates({ data }: {
2023
+ data: Uint8Array;
2024
+ }): ParsedExtension[];
2025
+ declare function getTokenAccountExtensionStates({ data }: {
2026
+ data: Uint8Array;
2027
+ }): ParsedExtension[];
2028
+
2029
+ /**
2030
+ * Gets all raw extensions from a mint account.
2031
+ */
2032
+ declare function getMintExtensions({ data }: {
2033
+ data: Uint8Array;
2034
+ }): RawExtension[];
2035
+ /**
2036
+ * Gets all raw extensions from a token account.
2037
+ */
2038
+ declare function getTokenAccountExtensions({ data }: {
2039
+ data: Uint8Array;
2040
+ }): RawExtension[];
1021
2041
 
1022
2042
  /**
1023
2043
  * Token metadata parsing for SPL Token-2022 native metadata extension.
@@ -1073,71 +2093,261 @@ interface ParseMetadataPointerExtensionOptions {
1073
2093
  * @returns Parsed metadata pointer, or null if not present
1074
2094
  */
1075
2095
  declare function parseMetadataPointerExtension({ data, }: ParseMetadataPointerExtensionOptions): MetadataPointerExtension | null;
2096
+
2097
+ /**
2098
+ * Mint account parsing for SPL Token-2022.
2099
+ */
2100
+
1076
2101
  /**
1077
- * Options for getting mint extensions.
2102
+ * Options for parsing a mint account.
1078
2103
  */
1079
- interface GetMintExtensionsOptions {
1080
- /** Raw mint account data */
2104
+ interface ParseMintAccountOptions {
2105
+ /** The mint account's public key */
2106
+ address: PublicKey;
2107
+ /** Raw account data bytes (minimum 82 bytes) */
1081
2108
  data: Uint8Array;
1082
2109
  }
1083
2110
  /**
1084
- * Gets all raw extensions from a mint account.
2111
+ * Parses raw mint account data into a structured MintInfo object.
1085
2112
  *
1086
- * @param options - Options containing data
1087
- * @returns Array of raw extensions, or empty array if no extensions
2113
+ * @param options - Options containing address and data
2114
+ * @returns Parsed mint information
2115
+ * @throws {SplTokenError} If the data is invalid or too short
2116
+ *
2117
+ * @example
2118
+ * ```typescript
2119
+ * const accountInfo = await client.getAccountInfo(mintPubkey);
2120
+ * if (accountInfo) {
2121
+ * const mintInfo = parseMintAccount({ address: mintPubkey, data: accountInfo.data });
2122
+ * console.log(`Supply: ${mintInfo.supply}`);
2123
+ * console.log(`Decimals: ${mintInfo.decimals}`);
2124
+ * }
2125
+ * ```
1088
2126
  */
1089
- declare function getMintExtensions({ data }: GetMintExtensionsOptions): RawExtension[];
2127
+ declare function parseMintAccount({ address, data }: ParseMintAccountOptions): MintInfo;
1090
2128
 
1091
2129
  /**
1092
- * Options for finding an Associated Token Address.
2130
+ * Token account parsing for SPL Token-2022.
1093
2131
  */
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;
2132
+
2133
+ /**
2134
+ * Options for parsing a token account.
2135
+ */
2136
+ interface ParseTokenAccountOptions {
2137
+ /** The token account's public key */
2138
+ address: PublicKey;
2139
+ /** Raw account data bytes (minimum 165 bytes) */
2140
+ data: Uint8Array;
1101
2141
  }
1102
2142
  /**
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)
2143
+ * Parses raw token account data into a structured TokenAccountInfo object.
1109
2144
  *
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
2145
+ * @param options - Options containing address and data
2146
+ * @returns Parsed token account information
2147
+ * @throws {SplTokenError} If the data is invalid or too short
1113
2148
  *
1114
2149
  * @example
1115
2150
  * ```typescript
1116
- * const { address, bump } = findAssociatedTokenAddress({ wallet: walletPubkey, mint: mintPubkey });
1117
- * console.log(`ATA: ${address.toString()}`);
1118
- * console.log(`Bump: ${bump}`);
2151
+ * const accountInfo = await client.getAccountInfo(tokenAccountPubkey);
2152
+ * if (accountInfo) {
2153
+ * const tokenAccount = parseTokenAccount({ address: tokenAccountPubkey, data: accountInfo.data });
2154
+ * console.log(`Balance: ${tokenAccount.amount}`);
2155
+ * console.log(`Owner: ${tokenAccount.owner.toString()}`);
2156
+ * }
1119
2157
  * ```
1120
2158
  */
1121
- declare function findAssociatedTokenAddress({ wallet, mint, programId, }: FindAssociatedTokenAddressOptions): AtaDerivationResult;
2159
+ declare function parseTokenAccount({ address, data }: ParseTokenAccountOptions): TokenAccountInfo;
2160
+
1122
2161
  /**
1123
- * Options for getting the Associated Token Address synchronously.
2162
+ * ExtraAccountMeta type definition and parser for Token-2022 transfer hooks.
2163
+ *
2164
+ * Each ExtraAccountMeta is a 35-byte fixed-size struct stored in the
2165
+ * validation account's TLV data. It describes an additional account that
2166
+ * must be included in the transfer instruction.
2167
+ *
2168
+ * Layout: [discriminator: u8] [addressConfig: [u8; 32]] [isSigner: u8] [isWritable: u8]
2169
+ *
2170
+ * Discriminator values:
2171
+ * - 0: Static address (addressConfig is the pubkey)
2172
+ * - 1: PDA derived from the hook program
2173
+ * - 2: Pubkey extracted from on-chain account data
2174
+ * - 128+i: PDA derived from account[i]'s pubkey as the program ID
1124
2175
  */
1125
- interface GetAssociatedTokenAddressSyncOptions {
1126
- /** The wallet's public key */
1127
- wallet: PublicKey;
1128
- /** The token mint's public key */
2176
+ /**
2177
+ * A single extra account descriptor from the ExtraAccountMetaList.
2178
+ */
2179
+ interface ExtraAccountMeta {
2180
+ /** Discriminator indicating how to resolve the address. */
2181
+ discriminator: number;
2182
+ /** 32-byte address configuration (pubkey or packed seeds). */
2183
+ addressConfig: Uint8Array;
2184
+ /** Whether this account must be a signer. */
2185
+ isSigner: boolean;
2186
+ /** Whether this account must be writable. */
2187
+ isWritable: boolean;
2188
+ }
2189
+ /** Size of a single ExtraAccountMeta entry in bytes (1 + 32 + 1 + 1). */
2190
+ declare const EXTRA_ACCOUNT_META_SIZE = 35;
2191
+
2192
+ /**
2193
+ * The Execute instruction discriminator.
2194
+ *
2195
+ * First 8 bytes of SHA-256("rialo-s-spl-transfer-hook-interface:execute").
2196
+ * This matches the on-chain Rialo Transfer Hook Interface namespace.
2197
+ */
2198
+ declare const EXECUTE_DISCRIMINATOR: Uint8Array;
2199
+ /**
2200
+ * Parses the validation account's TLV data into ExtraAccountMeta entries.
2201
+ *
2202
+ * Format: [8-byte discriminator][4-byte u32 LE length][4-byte u32 LE count][N x 35-byte entries]
2203
+ *
2204
+ * Returns an empty array if the data is too short or the count is zero.
2205
+ *
2206
+ * @param data - Raw validation account data
2207
+ * @returns Array of parsed ExtraAccountMeta entries
2208
+ */
2209
+ declare function parseExtraAccountMetaList(data: Uint8Array): ExtraAccountMeta[];
2210
+ /**
2211
+ * Builds the 16-byte Execute instruction data.
2212
+ *
2213
+ * Format: [8-byte EXECUTE_DISCRIMINATOR][8-byte amount as u64 LE]
2214
+ *
2215
+ * @param amount - The transfer amount
2216
+ * @returns 16-byte instruction data buffer
2217
+ */
2218
+ declare function buildExecuteInstructionData(amount: bigint): Uint8Array;
2219
+ /**
2220
+ * Derives the ExtraAccountMetaList validation account PDA.
2221
+ *
2222
+ * Seeds: ["extra-account-metas", mint_pubkey]
2223
+ * Program: hookProgramId
2224
+ *
2225
+ * @param mint - The token mint public key
2226
+ * @param hookProgramId - The transfer hook program ID
2227
+ * @returns The derived validation account public key
2228
+ */
2229
+ declare function getExtraAccountMetaAddress(mint: PublicKey, hookProgramId: PublicKey): PublicKey;
2230
+
2231
+ /**
2232
+ * Dynamic account resolution for Token-2022 transfer hook ExtraAccountMetas.
2233
+ *
2234
+ * This module resolves each ExtraAccountMeta into a concrete AccountMeta
2235
+ * (pubkey + isSigner + isWritable) by handling all discriminator types:
2236
+ * - 0: Static address (addressConfig is the pubkey directly)
2237
+ * - 1: PDA derived from the hook program with unpacked seeds
2238
+ * - 2: Pubkey extracted from on-chain account data
2239
+ * - 128+: PDA derived from a previously-resolved account's pubkey as program ID
2240
+ *
2241
+ * The top-level `resolveTransferHookExtraAccounts` function orchestrates the full
2242
+ * resolution algorithm: fetch validation PDA, parse TLV, resolve each meta
2243
+ * sequentially, de-escalate signers, and append trailing accounts.
2244
+ */
2245
+
2246
+ /**
2247
+ * Callback type for fetching on-chain account data.
2248
+ */
2249
+ type FetchAccountDataFn = (pubkey: PublicKey) => Promise<Uint8Array | null>;
2250
+ /**
2251
+ * Parameters for resolving a single ExtraAccountMeta.
2252
+ */
2253
+ interface ResolveExtraAccountMetaParams {
2254
+ /** The ExtraAccountMeta to resolve */
2255
+ meta: ExtraAccountMeta;
2256
+ /** All accounts resolved so far (base 5 + previous extras) */
2257
+ previousMetas: AccountMeta[];
2258
+ /** The Execute instruction data */
2259
+ instructionData: Uint8Array;
2260
+ /** The transfer hook program ID */
2261
+ hookProgramId: PublicKey;
2262
+ /** Callback to fetch on-chain account data */
2263
+ fetchAccountData: FetchAccountDataFn;
2264
+ }
2265
+ /**
2266
+ * Parameters for resolving transfer hook extra accounts.
2267
+ */
2268
+ interface ResolveTransferHookExtraAccountsParams {
2269
+ /** The token mint public key */
1129
2270
  mint: PublicKey;
1130
- /** The token program ID (defaults to Token-2022) */
1131
- programId?: PublicKey;
2271
+ /** The transfer hook program ID */
2272
+ hookProgramId: PublicKey;
2273
+ /** Source associated token account */
2274
+ sourceAta: PublicKey;
2275
+ /** Destination associated token account */
2276
+ destinationAta: PublicKey;
2277
+ /** Transfer authority (source account owner) */
2278
+ authority: PublicKey;
2279
+ /** Transfer amount in smallest units */
2280
+ amount: bigint;
2281
+ /** Token decimals (unused in resolution, kept for API consistency) */
2282
+ decimals: number;
2283
+ /** Callback to fetch on-chain account data */
2284
+ fetchAccountData: FetchAccountDataFn;
1132
2285
  }
1133
2286
  /**
1134
- * Gets the Associated Token Address without the bump seed.
2287
+ * Resolves a single ExtraAccountMeta into a concrete AccountMeta.
1135
2288
  *
1136
- * Convenience function when you only need the address.
2289
+ * Handles all discriminator types:
2290
+ * - 0: Static address
2291
+ * - 1: Hook program PDA
2292
+ * - 2: Pubkey from on-chain account data
2293
+ * - 128+: External PDA (program ID from a previously-resolved account)
1137
2294
  *
1138
- * @param options - Options containing wallet, mint, and optional programId
1139
- * @returns The derived ATA address
2295
+ * @param params - Resolution parameters for a single meta
2296
+ * @returns The resolved AccountMeta
1140
2297
  */
1141
- declare function getAssociatedTokenAddressSync({ wallet, mint, programId, }: GetAssociatedTokenAddressSyncOptions): PublicKey;
2298
+ declare function resolveExtraAccountMeta(params: ResolveExtraAccountMetaParams): Promise<AccountMeta>;
2299
+ /**
2300
+ * Resolves all extra accounts required for a transfer hook instruction.
2301
+ *
2302
+ * This is the top-level entry point that:
2303
+ * 1. Derives the validation PDA
2304
+ * 2. Fetches the validation account data
2305
+ * 3. Parses the ExtraAccountMetaList TLV
2306
+ * 4. Builds Execute instruction data
2307
+ * 5. Resolves each ExtraAccountMeta sequentially (incremental build)
2308
+ * 6. De-escalates all resolved extras (isSigner = false)
2309
+ * 7. Appends hook program ID and validation PDA as trailing accounts
2310
+ *
2311
+ * @param params - Resolution parameters
2312
+ * @returns Array of extra AccountMetas to append to the transfer instruction
2313
+ */
2314
+ declare function resolveTransferHookExtraAccounts(params: ResolveTransferHookExtraAccountsParams): Promise<AccountMeta[]>;
2315
+
2316
+ /**
2317
+ * Seed unpacking for Token-2022 transfer hook ExtraAccountMeta PDA resolution.
2318
+ *
2319
+ * The addressConfig field of a PDA-type ExtraAccountMeta contains packed seed
2320
+ * descriptors. Each seed starts with a discriminator byte followed by type-specific
2321
+ * parameters. Seeds are parsed sequentially until a terminator (0) is encountered
2322
+ * or the 32-byte boundary is reached.
2323
+ *
2324
+ * Seed types:
2325
+ * - 0: Terminator (stop parsing)
2326
+ * - 1 (Literal): [length: u8, ...bytes]
2327
+ * - 2 (InstructionData): [offset: u8, length: u8] -- slice of Execute instruction data
2328
+ * - 3 (AccountKey): [accountIndex: u8] -- 32-byte pubkey of a resolved account
2329
+ * - 4 (AccountData): [accountIndex: u8, dataOffset: u8, length: u8] -- slice of on-chain data
2330
+ */
2331
+
2332
+ /**
2333
+ * Parameters for unpacking seeds from an ExtraAccountMeta addressConfig.
2334
+ */
2335
+ interface UnpackSeedsParams {
2336
+ /** The 32-byte packed seed configuration */
2337
+ addressConfig: Uint8Array;
2338
+ /** All previously resolved accounts (base 5 + resolved extras) */
2339
+ previousMetas: AccountMeta[];
2340
+ /** The Execute instruction data (16 bytes) */
2341
+ instructionData: Uint8Array;
2342
+ /** Callback to fetch on-chain account data */
2343
+ fetchAccountData: (pubkey: PublicKey) => Promise<Uint8Array | null>;
2344
+ }
2345
+ /**
2346
+ * Unpacks seed descriptors from a 32-byte addressConfig into concrete byte arrays.
2347
+ *
2348
+ * @param params - Seed unpacking parameters
2349
+ * @returns Array of seed byte arrays for PDA derivation
2350
+ */
2351
+ declare function unpackSeeds(params: UnpackSeedsParams): Promise<Uint8Array[]>;
1142
2352
 
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 };
2353
+ export { ASSOCIATED_TOKEN_PROGRAM_ID, type AccountMeta, AccountType, type AtaDerivationResult, type CreateTokenWithMetadataOptions, type CreateTokenWithMetadataParams, type CreateTokenWithMetadataResult, EXECUTE_DISCRIMINATOR, EXTRA_ACCOUNT_META_SIZE, ExtensionType, type ExtraAccountMeta, type FetchAccountDataFn, type GetMintSizeWithExtensionsOptions, type InitializePermanentDelegateInstructionOptions, type InitializeTransferHookInstructionOptions, type Instruction, MINT_SIZE, type MetadataPointerExtension, type MintAccountData, type MintBuildOptions, type MintBuildResult, MintBuilder, type MintInfo, type MintInitialSupplyConfig, type MintMetadataConfig, type MintSendOptions, type MintSendResult, type MintTransferFeeConfig, type NonTransferableAccountExtension, type NonTransferableExtension, type ParsedExtension, type PermanentDelegateExtension, type RawExtension, type ResolveExtraAccountMetaParams, type ResolveTransferHookExtraAccountsParams, SplTokenClient, SplTokenError, SplTokenErrorCode, TLV_LENGTH_SIZE, TLV_TYPE_SIZE, TOKEN_2022_PROGRAM_ID, TOKEN_ACCOUNT_SIZE, TOKEN_PROGRAM_ID, type TokenAccountFilter, type TokenAccountInfo, TokenAccountState, TokenInstruction, type TokenMetadata, type TokenMetadataParams, type TransferFee, type TransferFeeAmountExtension, type TransferFeeConfigExtension, type TransferHookExtension, type TransferParams, type UnpackSeedsParams, buildExecuteInstructionData, createAssociatedTokenAccountIdempotentInstruction, createAssociatedTokenAccountInstruction, createSplTokenClient, createTokenWithMetadata, findAssociatedTokenAddress, getAssociatedTokenAddressSync, getExtraAccountMetaAddress, getMetadataExtensionSize, getMinRentForMint, getMinRentForMintWithMetadata, getMintExtensionStates, getMintExtensions, getMintSizeWithExtensions, getMintSizeWithMetadata, getTokenAccountExtensionStates, getTokenAccountExtensions, getTokenMetadataDataSize, initializeMetadataPointerInstruction, initializeMintInstruction, initializeNonTransferableMintInstruction, initializePermanentDelegateInstruction, initializeTokenMetadataInstruction, initializeTransferFeeConfigInstruction, initializeTransferHookInstruction, mintToInstruction, parseExtension, parseExtraAccountMetaList, parseMetadataPointerExtension, parseMetadataPointerExtensionData, parseMintAccount, parsePermanentDelegateExtension, parseTokenAccount, parseTokenMetadata, parseTokenMetadataExtensionData, parseTransferFeeConfigExtension, parseTransferHookExtension, resolveExtraAccountMeta, resolveTransferHookExtraAccounts, setTransferFeeInstruction, transferCheckedInstruction, transferCheckedWithFeeInstruction, transferInstruction, unpackSeeds, updateMetadataPointerInstruction };