Skip to content

feat: light account (pinocchio)#2230

Merged
ananas-block merged 14 commits intomainfrom
jorrit/feat-light-pda-pinocchio2
Feb 4, 2026
Merged

feat: light account (pinocchio)#2230
ananas-block merged 14 commits intomainfrom
jorrit/feat-light-pda-pinocchio2

Conversation

@ananas-block
Copy link
Contributor

@ananas-block ananas-block commented Feb 3, 2026

Motivation

  1. Create pinocchio SDKs for light-accounts and light-tokens
  2. Create a LightProgramPinocchio derive macro to derive seed structs, pack, unpack, compress and decompress traits and helpers
  3. Enable the same compressed account logic to work across Solana and Pinocchio frameworks

New Crates

light-account (sdk-libs/account/)

Re-exports macros and generic types specialized with Solana's AccountInfo<'info>:

  • Type aliases: CpiAccounts<'c, 'info>, CompressCtx<'a, 'info>, DecompressCtx<'a, 'info>, ValidatedPdaContext<'info>, PackedAccounts
  • Re-exports all macros from light-sdk-macros: #[light_program], #[derive(LightAccount)], #[derive(LightAccounts)], #[derive(LightProgram)], etc.
  • Utility functions: light_err(), derive_rent_sponsor_pda(), find_mint_address(), derive_associated_token_account()

light-account-pinocchio (sdk-libs/account-pinocchio/)

Re-exports macros and generic types specialized with Pinocchio's AccountInfo (no lifetime):

  • Type aliases: CpiAccounts<'c>, CompressCtx<'a>, DecompressCtx<'a>, ValidatedPdaContext
  • Re-exports macros including #[derive(LightProgramPinocchio)] (replaces #[derive(LightProgram)])
  • Utility functions adapted for [u8; 32] byte arrays instead of Pubkey

light-sdk-types Changes

Added interface/ directory with generic interface types:

sdk-libs/sdk-types/src/interface/
├── account/           # LightAccount trait, compression_info, pack/unpack
├── accounts/          # LightPreInit/LightFinalize traits
├── cpi/               # CpiAccountsTrait, invoke helpers, mint/token creation
├── program/
│   ├── compression/   # CompressCtx, CompressDispatchFn, prepare_account_for_compression
│   ├── config/        # LightConfig, process_initialize_light_config
│   ├── decompression/ # DecompressCtx, DecompressVariant, prepare_account_for_decompression
│   └── validation.rs  # Account validation helpers
└── create_accounts_proof.rs

Key generic types:

  • CompressCtx<'a, AI: AccountInfoTrait> - Compression context
  • DecompressCtx<'a, AI: AccountInfoTrait> - Decompression context
  • CpiAccounts<'a, T: AccountInfoTrait> - CPI account collection
  • ValidatedPdaContext<AI: AccountInfoTrait> - Validated PDA accounts

Test Programs

manual-test-pinocchio (sdk-tests/manual-test-pinocchio/)

  • Pure Pinocchio program with manual instruction dispatch
  • Tests: pda, account_loader, ata, token_account, two_mints, all
  • Validates manual account handling patterns without derive macros

pinocchio-light-program-test (sdk-tests/pinocchio-light-program-test/)

  • Uses #[derive(LightProgramPinocchio)] on enum
  • Auto-generates compress/decompress dispatch, config handlers, variant types
  • Tests: create_pda, create_ata, create_token_vault, create_zero_copy_record, create_mint, create_two_mints, create_all, stress_test

anchor-semi-manual-test (sdk-tests/anchor-semi-manual-test/)

  • Uses #[derive(LightProgram)] with standard Anchor #[program]
  • Uses #[derive(Accounts, LightAccounts)] on instruction account structs
  • Tests same scenarios as pinocchio-light-program-test for feature parity

light-account-checks Changes

New AccountMetaTrait

pub trait AccountMetaTrait: Clone + Debug {
type Pubkey: Copy;
fn new(pubkey: Self::Pubkey, is_signer: bool, is_writable: bool) -> Self;
fn pubkey_to_bytes(pubkey: Self::Pubkey) -> [u8; 32];
fn pubkey_from_bytes(bytes: [u8; 32]) -> Self::Pubkey;
// ...
}

New Generic Functions

  • invoke_cpi() - Generic CPI invocation abstraction
  • transfer_lamports_cpi() - Transfer via system program CPI
  • create_pda_account() - Generic PDA creation
  • close_account() - Account closure
  • transfer_lamports() - Direct lamport manipulation

PackedAccounts<AM: AccountMetaTrait>

Generic instruction account packing with deduplication:

  • insert_or_get() - Insert or get existing account index
  • add_pre_accounts_signer() / add_pre_accounts_meta() - Pre-account management
  • add_system_accounts_raw() - System account insertion

Implementations

  • Solana: AccountMetaTrait for solana_instruction::AccountMeta
  • Pinocchio: OwnedAccountMeta wrapper + AccountMetaTrait implementation

light-compressible Changes

  • Moved CreateAccountsProof to light-sdk-types

light-sdk-macros Changes

Removed

  • #[derive(Compressible)] - unused macro removed

Updated

  • Import paths: light_sdk::interface -> light_account
  • Added #[derive(LightProgramPinocchio)] for Pinocchio programs

Renamings

Old New
COMPRESSIBLE_CONFIG_SEED LIGHT_CONFIG_SEED

Summary by CodeRabbit

  • New Features

    • Framework-agnostic Light Accounts SDK with Pinocchio support, packed-accounts helpers, and extensive token CPI builders (create ATA/token accounts, mint(s), transfer, burn, freeze, close, batch mints).
  • New Features

    • Idempotent compression & decompression processors, validation utilities, and a consolidated LightConfig / CreateAccountsProof interface.
  • Improvements

    • Broader, more descriptive error variants and unified account/CPI/meta abstractions across runtimes.
  • Documentation

    • Added comprehensive READMEs and usage examples; cleaned obsolete entries.
  • Chores

    • Public API reorganization and removals; expect some breaking surface changes.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants