light_instruction_decoder/programs/
spl_token.rs

1//! SPL Token program instruction decoder.
2//!
3//! This module provides a macro-derived decoder for the SPL Token program,
4//! which uses single-byte discriminators based on variant indices.
5
6// Allow the macro-generated code to reference types from this crate
7extern crate self as light_instruction_decoder;
8
9use light_instruction_decoder_derive::InstructionDecoder;
10
11/// SPL Token program instructions.
12///
13/// The SPL Token program uses a 1-byte discriminator (variant index).
14/// Each variant's discriminator is its position in this enum (0, 1, 2, ...).
15///
16/// Note: Complex types (Pubkey, COption<Pubkey>) are not fully parsed;
17/// only primitive fields are extracted.
18#[derive(InstructionDecoder)]
19#[instruction_decoder(
20    program_id = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
21    program_name = "SPL Token",
22    discriminator_size = 1
23)]
24pub enum SplTokenInstruction {
25    /// Initialize a new mint (index 0)
26    /// Fields: decimals: u8, mint_authority: Pubkey, freeze_authority: COption<Pubkey>
27    #[instruction_decoder(account_names = ["mint", "rent"])]
28    InitializeMint { decimals: u8 },
29
30    /// Initialize a new token account (index 1)
31    #[instruction_decoder(account_names = ["account", "mint", "owner", "rent"])]
32    InitializeAccount,
33
34    /// Initialize a multisig account (index 2)
35    #[instruction_decoder(account_names = ["multisig", "rent"])]
36    InitializeMultisig { m: u8 },
37
38    /// Transfer tokens (index 3)
39    #[instruction_decoder(account_names = ["source", "destination", "authority"])]
40    Transfer { amount: u64 },
41
42    /// Approve a delegate (index 4)
43    #[instruction_decoder(account_names = ["source", "delegate", "owner"])]
44    Approve { amount: u64 },
45
46    /// Revoke delegate authority (index 5)
47    #[instruction_decoder(account_names = ["source", "owner"])]
48    Revoke,
49
50    /// Set a new authority (index 6)
51    /// Fields: authority_type: u8, new_authority: COption<Pubkey>
52    #[instruction_decoder(account_names = ["account_or_mint", "current_authority"])]
53    SetAuthority { authority_type: u8 },
54
55    /// Mint new tokens (index 7)
56    #[instruction_decoder(account_names = ["mint", "destination", "authority"])]
57    MintTo { amount: u64 },
58
59    /// Burn tokens (index 8)
60    #[instruction_decoder(account_names = ["source", "mint", "authority"])]
61    Burn { amount: u64 },
62
63    /// Close a token account (index 9)
64    #[instruction_decoder(account_names = ["account", "destination", "authority"])]
65    CloseAccount,
66
67    /// Freeze a token account (index 10)
68    #[instruction_decoder(account_names = ["account", "mint", "authority"])]
69    FreezeAccount,
70
71    /// Thaw a frozen token account (index 11)
72    #[instruction_decoder(account_names = ["account", "mint", "authority"])]
73    ThawAccount,
74
75    /// Transfer tokens with decimals check (index 12)
76    #[instruction_decoder(account_names = ["source", "mint", "destination", "authority"])]
77    TransferChecked { amount: u64, decimals: u8 },
78
79    /// Approve delegate with decimals check (index 13)
80    #[instruction_decoder(account_names = ["source", "mint", "delegate", "owner"])]
81    ApproveChecked { amount: u64, decimals: u8 },
82
83    /// Mint tokens with decimals check (index 14)
84    #[instruction_decoder(account_names = ["mint", "destination", "authority"])]
85    MintToChecked { amount: u64, decimals: u8 },
86
87    /// Burn tokens with decimals check (index 15)
88    #[instruction_decoder(account_names = ["source", "mint", "authority"])]
89    BurnChecked { amount: u64, decimals: u8 },
90
91    /// Initialize account with owner in data (index 16)
92    /// Fields: owner: Pubkey (32 bytes)
93    #[instruction_decoder(account_names = ["account", "mint", "rent"])]
94    InitializeAccount2,
95
96    /// Sync native SOL balance (index 17)
97    #[instruction_decoder(account_names = ["account"])]
98    SyncNative,
99
100    /// Initialize account without rent sysvar (index 18)
101    /// Fields: owner: Pubkey (32 bytes)
102    #[instruction_decoder(account_names = ["account", "mint"])]
103    InitializeAccount3,
104
105    /// Initialize multisig without rent sysvar (index 19)
106    #[instruction_decoder(account_names = ["multisig"])]
107    InitializeMultisig2 { m: u8 },
108
109    /// Initialize mint without rent sysvar (index 20)
110    /// Fields: decimals: u8, mint_authority: Pubkey, freeze_authority: COption<Pubkey>
111    #[instruction_decoder(account_names = ["mint"])]
112    InitializeMint2 { decimals: u8 },
113
114    /// Get required account size (index 21)
115    #[instruction_decoder(account_names = ["mint"])]
116    GetAccountDataSize,
117
118    /// Initialize immutable owner extension (index 22)
119    #[instruction_decoder(account_names = ["account"])]
120    InitializeImmutableOwner,
121
122    /// Convert amount to UI amount string (index 23)
123    #[instruction_decoder(account_names = ["mint"])]
124    AmountToUiAmount { amount: u64 },
125
126    /// Convert UI amount string to amount (index 24)
127    /// Fields: ui_amount: &str (variable length)
128    #[instruction_decoder(account_names = ["mint"])]
129    UiAmountToAmount,
130}