Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Crates and Features

CratePathDescription
pinacrates/pinaCore framework — traits, account loaders, CPI helpers, Pod types.
pina_macroscrates/pina_macrosProc macros — #[account], #[instruction], #[event], etc.
pina_clicrates/pina_cliCLI/library for IDL generation, Codama integration, scaffolding.
pina_codama_renderercrates/pina_codama_rendererRepository-local Codama Rust renderer for Pina-style clients.
pina_pod_primitivescrates/pina_pod_primitivesno_std POD primitives — integer/bool wrappers, fixed-capacity collections.
pina_profilecrates/pina_profileStatic CU profiler for compiled SBF programs.
pina_sdk_idscrates/pina_sdk_idsTyped constants for well-known Solana program/sysvar IDs.

crates/pina

Core runtime crate for on-chain program logic.

Includes:

  • AccountView and validation chain helpers.
  • Typed account loaders and discriminator checks.
  • CPI/system/token helper utilities.
  • nostd_entrypoint! and instruction parsing helpers.
  • Instruction introspection (flash loan guards, sandwich detection).
  • Pod types with full arithmetic operator support.

Feature flags:

FeatureDefaultDescription
deriveYesEnables proc macros (#[account], #[instruction], etc.)
logsYesEnables on-chain logging via solana-program-log
tokenNoEnables SPL token / token-2022 helpers and ATA utilities
memoNoEnables memo program helpers via pina::memo
account-resizeNoEnables account realloc helpers that call Pinocchio resize APIs

Feature selection tips

  • derive is the normal choice for program crates; disable it only when you want the low-level runtime traits without the proc macros.
  • logs is useful during initial development and debugging, testing, and audits. Disable it when you want the smallest possible binary or completely silent runtime failures.
  • token enables pina::token, pina::token_2022, pina::associated_token_account, and the TokenAccount compatibility aliases over the upstream renamed account types.
  • memo is separate from token, so memo CPI support can be enabled without pulling in the token helper surface.
  • account-resize only unlocks realloc helpers such as realloc_account() and realloc_account_zero(). Close helpers still do not implicitly resize or zero account data.

See ADR 0004 and ADR 0005 for the architectural rationale behind these feature and runtime boundaries. For concrete token CPI patterns, see Token CPI Recipes.

crates/pina_macros

Proc-macro crate used by pina.

Provides:

  • #[discriminator]
  • #[account]
  • #[instruction]
  • #[event]
  • #[error]
  • #[derive(Accounts)]

crates/pina_cli

Developer CLI and library.

Commands:

CommandDescription
pina init <name>Scaffold a new Pina program project
pina idl --path <dir>Generate a Codama IDL JSON from a Pina program
pina profile <path.so>Static CU profiler for compiled SBF binaries
pina codama generateGenerate Codama IDLs and Rust/JS clients for examples

The IDL parser supports multi-file programs — it follows mod declarations from src/lib.rs to discover accounts, instructions, and discriminators across all source files.

Library surface:

  • pina_cli::generate_idl(program_path, name_override)
  • pina_cli::init_project(path, package_name, force)

crates/pina_pod_primitives

no_std crate containing alignment-safe POD primitive wrappers (PodBool, PodU*, PodI*) and fixed-capacity collection types (PodOption, PodString, PodVec) shared by pina and generated clients.

Arithmetic operators (+, -, *) on Pod integer types use wrapping semantics in release builds for CU efficiency and panic on overflow in debug builds. Use checked_add, checked_sub, checked_mul, checked_div where overflow must be detected in all build profiles.

Each Pod integer type provides ZERO, MIN, and MAX constants.

TypePurposeLayout
PodOption<T: Pod>Fixed-size Option<T>1-byte discriminant + T
PodString<N, PFX=1>Fixed-capacity stringPFX-byte length prefix + N data bytes
PodVec<T: Pod, N, PFX=2>Fixed-capacity vecPFX-byte length prefix + N elements

All collection types are #[repr(C)], alignment-1, and implement bytemuck::Pod + bytemuck::Zeroable. Length prefixes (PFX) default to 1 byte for strings (max 255) and 2 bytes for vectors (max 65 535 elements).

Collection types store data inline with a length prefix, enabling zero-copy access inside #[repr(C)] account structs. Overflow is detected at insertion time — try_set / try_push return Err(PodCollectionError::Overflow) when capacity is exceeded.

PodString provides UTF-8 validation via try_as_str(), while PodVec offers slice-based access via as_slice() / as_mut_slice(). PodOption mirrors the Option<T> API with get(), set(), and clear().

crates/pina_profile

The pina profile command analyzes compiled SBF .so binaries to estimate per-function compute unit costs without requiring a running validator.

pina profile target/deploy/my_program.so          # text summary
pina profile target/deploy/my_program.so --json    # JSON for CI
pina profile target/deploy/my_program.so -o r.json # write to file

The profiler decodes each SBF instruction opcode and assigns costs: regular instructions cost 1 CU, syscalls cost 100 CU.

crates/pina_codama_renderer

Repository-local renderer that generates Pina-style Rust client code from Codama JSON IDLs. The renderer is organized into focused modules under src/render/:

  • accounts.rs — account page and PDA helpers
  • instructions.rs — instruction page, account metas
  • types.rs — Pod type rendering, defined types
  • errors.rs — error page rendering
  • discriminator.rs — discriminator rendering
  • seeds.rs — seed parameter/constant rendering

Use this when you want generated Rust models to match Pina’s fixed-size discriminator-first/bytemuck conventions.

crates/pina_sdk_ids

no_std crate that exports well-known Solana program/sysvar IDs as typed constants.

Use this crate to avoid hardcoded base58 literals in validation logic.