Expand description
§Light Accounts Pinocchio
Rent-free Light Accounts and Light Token Accounts for Pinocchio programs.
§How It Works
Light Accounts (PDAs)
- Create a Solana PDA normally
- Register it with
#[derive(LightProgramPinocchio)]- becomes a Light Account - Use it as normal Solana account
- When rent runs out, account compresses (cold state)
- State preserved on-chain, client loads when needed (hot state)
Light Token Accounts (associated token accounts, Vaults)
- Use
#[light_account(associated_token)]for associated token accounts - Use
#[light_account(token::seeds = [...], token::owner_seeds = [...])]for vaults - Cold/hot lifecycle
Light Mints
- Created via
invoke_create_mints - Cold/hot lifecycle
§Quick Start
§1. Program Setup
ⓘ
use light_account_pinocchio::{derive_light_cpi_signer, CpiSigner, LightProgramPinocchio};
use pinocchio_pubkey::pubkey;
pub const ID: Pubkey = pubkey!("Your11111111111111111111111111111111111111");
pub const LIGHT_CPI_SIGNER: CpiSigner =
derive_light_cpi_signer!("Your11111111111111111111111111111111111111");§2. State Definition
ⓘ
use borsh::{BorshDeserialize, BorshSerialize};
use light_account_pinocchio::{CompressionInfo, LightDiscriminator, LightHasherSha};
#[derive(BorshSerialize, BorshDeserialize, LightDiscriminator, LightHasherSha)]
pub struct MyRecord {
pub compression_info: CompressionInfo, // Required first or last field
pub owner: [u8; 32],
pub data: u64,
}§3. Program Accounts Enum
ⓘ
#[derive(LightProgramPinocchio)]
pub enum ProgramAccounts {
#[light_account(pda::seeds = [b"record", ctx.owner])]
MyRecord(MyRecord),
}§Account Types
§1. Light Account (PDA)
ⓘ
#[light_account(pda::seeds = [b"record", ctx.owner])]
MyRecord(MyRecord),§2. Light Account (zero-copy)
ⓘ
#[light_account(pda::seeds = [b"record", ctx.owner], pda::zero_copy)]
ZeroCopyRecord(ZeroCopyRecord),§3. Light Token Account (vault)
ⓘ
#[light_account(token::seeds = [b"vault", ctx.mint], token::owner_seeds = [b"vault_auth"])]
Vault,§4. Light Token Account (associated token account)
ⓘ
#[light_account(associated_token)]
Ata,§Required Derives
| Derive | Use |
|---|---|
LightDiscriminator | State structs (8-byte discriminator) |
LightHasherSha | State structs (compression hashing) |
LightProgramPinocchio | Program accounts enum |
§Required Macros
| Macro | Use |
|---|---|
derive_light_cpi_signer! | CPI signer PDA constant |
pinocchio_pubkey::pubkey! | Program ID as Pubkey |
For a complete example, see sdk-tests/pinocchio-light-program-test.
Re-exports§
pub extern crate light_account_checks;
Modules§
Macros§
- derive_
light_ cpi_ signer - Derives a complete Light Protocol CPI configuration at runtime
- derive_
light_ cpi_ signer_ pda - Derives a Light Protocol CPI signer PDA at compile time
- pubkey_
array - Converts a base58 encoded public key into a raw byte array [u8; 32].
Structs§
- Account
Info - Wrapper struct for an
Account. - Compress
AndClose Params - Parameters for compress_and_close instruction. Matches SDK’s SaveAccountsData field order for compatibility.
- Compressed
Account Data - Compressed account data used when decompressing.
- Compressed
CpiContext - Compression
Info - SDK CompressionInfo - a compact 24-byte struct for custom zero-copy PDAs.
- CpiAccounts
Config - CpiSigner
- Configuration struct containing program ID, CPI signer, and bump for Light Protocol
- Create
Accounts Proof - Proof data for instruction params when creating new compressed accounts.
Used in the INIT flow - pass directly to instruction data.
All accounts use the same address tree, so only one
address_tree_infois needed. - Decompress
Idempotent Params - Parameters for decompress_idempotent instruction.
Generic over the variant type - each program defines its own
PackedProgramAccountVariant. - Initialize
Light Config Params - Parameters for initialize_compression_config instruction.
Uses
[u8; 32]for pubkeys - borsh-compatible withsolana_pubkey::Pubkey. - Instruction
Data Invoke CpiWith Account Info - Light
Config - Global configuration for compressible accounts
- Owned
Account Meta - Owned account meta for pinocchio.
- Packed
Address Tree Info - Packed address tree info for instruction data. Contains indices to address tree accounts and root index.
- Packed
State Tree Info - Update
Light Config Params - Parameters for update_compression_config instruction.
- Validity
Proof
Enums§
- Account
Type - Compression
State - Compression state for SDK CompressionInfo.
- Light
SdkTypes Error
Constants§
- COMPRESSION_
INFO_ SIZE - Size of SDK CompressionInfo in bytes (24 bytes). Used for stripping CompressionInfo from Pod data during packing.
- LIGHT_
CONFIG_ SEED - MAX_
ADDRESS_ TREES_ PER_ SPACE - OPTION_
COMPRESSION_ INFO_ SPACE - Space required for Option
when Some (1 byte discriminator + INIT_SPACE). Use this constant in account space calculations.
Traits§
- Account
Info Trait - Trait to abstract over different AccountInfo implementations (pinocchio vs solana)
- Account
Meta Trait - Trait abstracting over AccountMeta implementations (solana vs pinocchio).
- Compress
As - Override what gets stored when compressing. Return Self or a different type.
- Compressed
Init Space - Account space when compressed.
- Compression
Info Field - Simple field accessor trait for types with a
compression_info: Option<CompressionInfo>field. Implement this trait and getHasCompressionInfofor free via blanket impl. - CpiAccounts
Trait - Trait for types that can provide account infos and metas for Light system program CPI.
- Decompress
Variant - Trait for packed program account variants that support decompression.
- HasCompression
Info - HasToken
Variant - Trait for account variants that can be checked for token or PDA type.
- Into
Variant - Trait for seeds that can construct a compressed account variant.
- Invoke
Light System Program - Trait for invoking the Light system program via CPI.
- Light
Account - Trait for compressible account data structs.
- Light
Account Variant Trait - Trait for unpacked compressed account variants with seeds.
- Light
Cpi - Base trait for Light CPI instruction types.
- Light
Discriminator - Light
Finalize - Trait for finalizing compression operations on accounts.
- Light
PreInit - Trait for pre-initialization operations (mint creation).
- Packed
Address Tree Info Ext - Extension trait for PackedAddressTreeInfo SDK-specific methods. Since PackedAddressTreeInfo is defined in light-compressed-account, we use an extension trait to add methods that depend on SDK types.
- Packed
Light Account Variant Trait - Trait for packed compressed account variants.
- PdaSeed
Derivation - Trait for PDA types that can derive seeds with full account context access.
- Size
- Trait to get the serialized size of a compressed account.
- Space
- Unpack
Functions§
- claim_
completed_ epoch_ rent - Claim completed-epoch rent to the provided rent sponsor and update last_claimed_slot. Returns Some(claimed) if any lamports were claimed; None if account is compressible or nothing to claim. Generic over AccountInfoTrait to work with both solana and pinocchio.
- close_
account - Close a native Solana account by transferring lamports and clearing data.
- derive_
rent_ sponsor_ pda - Derives the rent sponsor PDA for a given program.
- extract_
tail_ accounts - Extract PDA accounts from the tail of remaining_accounts.
- invoke_
light_ system_ program - Low-level function to invoke the Light system program with a PDA signer.
- invoke_
write_ pdas_ to_ cpi_ context - Write compressed PDA data to CPI context for chaining with subsequent operations.
- is_
pda_ initialized - Check if PDA account is already initialized (has non-zero discriminator).
- light_
err - Converts a
LightSdkTypesErrorinto apinocchio::program_error::ProgramError. - prepare_
account_ for_ compression - Generic prepare_account_for_compression.
- prepare_
account_ for_ decompression - Generic prepare_account_for_decompression.
- prepare_
compressed_ account_ on_ init - Prepare a compressed account for a PDA during initialization.
- process_
compress_ pda_ accounts_ idempotent - Process compress-and-close for PDA accounts (idempotent).
- process_
decompress_ pda_ accounts_ idempotent - Process decompression for PDA accounts (idempotent, PDA-only).
- process_
initialize_ light_ config - Creates a new compressible config PDA.
- process_
initialize_ light_ config_ checked - Initialize a LightConfig PDA with upgrade authority check.
- process_
update_ light_ config - Update an existing LightConfig PDA.
- reimburse_
rent - Reimburse the fee_payer for rent paid during PDA creation.
- should_
skip_ compression - Check if account should be skipped during compression.
- split_
at_ system_ accounts_ offset - Validate and split remaining_accounts at system_accounts_offset.
- validate_
compress_ accounts - Extract and validate accounts for compress operations (4 accounts including compression_authority).
- validate_
decompress_ accounts - Extract and validate accounts for decompress operations (3 accounts, no compression_authority).
Type Aliases§
Derive Macros§
- Compress
As - Legacy CompressAs trait implementation (use Compressible instead).
- Discriminator
- Derives a discriminator using SHA256(“account:{struct_name}”)[0..8].
- HasCompression
Info - Automatically implements the HasCompressionInfo trait for structs that have a
compression_info: Option<CompressionInfo>field. - Light
Account - Generates a unified
LightAccounttrait implementation for light account structs. - Light
Discriminator - Derives a discriminator using SHA256(“{struct_name}”)[0..8].
- Light
Hasher - Makes the annotated struct hashable by implementing the following traits:
- Light
Hasher Sha - SHA256 variant of the LightHasher derive macro.
- Light
Pinocchio Account - Pinocchio variant of
LightAccountderive macro. - Light
Program Pinocchio - Pinocchio variant of
#[derive(LightProgram)].