light_instruction_decoder/programs/
system.rs

1//! Solana System Program instruction decoder.
2//!
3//! This module provides a macro-derived decoder for the Solana System Program,
4//! which uses 4-byte (u32) discriminators for instruction types.
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/// Solana System Program instructions.
12///
13/// The System Program uses a 4-byte discriminator (u32 little-endian).
14/// Each variant's discriminator is its position in this enum (0, 1, 2, ...).
15#[derive(InstructionDecoder)]
16#[instruction_decoder(
17    program_id = "11111111111111111111111111111111",
18    program_name = "System Program",
19    discriminator_size = 4
20)]
21pub enum SystemInstruction {
22    /// Create a new account (index 0)
23    /// Data: lamports (u64) + space (u64) + owner (Pubkey)
24    #[instruction_decoder(account_names = ["funding_account", "new_account"])]
25    CreateAccount { lamports: u64, space: u64 },
26
27    /// Assign account to a program (index 1)
28    /// Data: owner (Pubkey)
29    #[instruction_decoder(account_names = ["account"])]
30    Assign,
31
32    /// Transfer lamports (index 2)
33    /// Data: lamports (u64)
34    #[instruction_decoder(account_names = ["from", "to"])]
35    Transfer { lamports: u64 },
36
37    /// Create account with seed (index 3)
38    /// Data: base (Pubkey) + seed (String) + lamports (u64) + space (u64) + owner (Pubkey)
39    #[instruction_decoder(account_names = ["funding_account", "created_account", "base_account"])]
40    CreateAccountWithSeed { lamports: u64, space: u64 },
41
42    /// Advance nonce account (index 4)
43    #[instruction_decoder(account_names = ["nonce_account", "recent_blockhashes_sysvar", "nonce_authority"])]
44    AdvanceNonceAccount,
45
46    /// Withdraw from nonce account (index 5)
47    /// Data: lamports (u64)
48    #[instruction_decoder(account_names = ["nonce_account", "recipient", "recent_blockhashes_sysvar", "rent_sysvar", "nonce_authority"])]
49    WithdrawNonceAccount { lamports: u64 },
50
51    /// Initialize nonce account (index 6)
52    /// Data: authority (Pubkey)
53    #[instruction_decoder(account_names = ["nonce_account", "recent_blockhashes_sysvar", "rent_sysvar"])]
54    InitializeNonceAccount,
55
56    /// Authorize nonce account (index 7)
57    /// Data: new_authority (Pubkey)
58    #[instruction_decoder(account_names = ["nonce_account", "nonce_authority"])]
59    AuthorizeNonceAccount,
60
61    /// Allocate space for account (index 8)
62    /// Data: space (u64)
63    #[instruction_decoder(account_names = ["account"])]
64    Allocate { space: u64 },
65
66    /// Allocate space with seed (index 9)
67    /// Data: base (Pubkey) + seed (String) + space (u64) + owner (Pubkey)
68    #[instruction_decoder(account_names = ["account", "base_account"])]
69    AllocateWithSeed { space: u64 },
70
71    /// Assign account with seed (index 10)
72    /// Data: base (Pubkey) + seed (String) + owner (Pubkey)
73    #[instruction_decoder(account_names = ["account", "base_account"])]
74    AssignWithSeed,
75
76    /// Transfer with seed (index 11)
77    /// Data: lamports (u64) + from_seed (String) + from_owner (Pubkey)
78    #[instruction_decoder(account_names = ["funding_account", "base_account", "recipient"])]
79    TransferWithSeed { lamports: u64 },
80
81    /// Upgrade nonce account (index 12)
82    #[instruction_decoder(account_names = ["nonce_account"])]
83    UpgradeNonceAccount,
84}