Skip to main content

Crate pina

Crate pina 

Source
Expand description

§pina

A performant Solana smart contract framework built on top of pinocchio — a lightweight alternative to solana-program that massively reduces dependency bloat and compute units.

§Features

  • Zero-copy account deserialization via bytemuck — no heap allocation.
  • no_std compatible — designed for on-chain deployment to the SBF target.
  • Discriminator system — every account, instruction, and event type carries a discriminator as its first field, enabling safe type identification.
  • Validation chaining — chain assertions on AccountView references (e.g. account.assert_signer()?.assert_writable()?.assert_owner(&id)?).
  • Proc-macro sugar#[account], #[instruction], #[event], #[error], #[discriminator], and #[derive(Accounts)] reduce boilerplate.
  • CPI helpers — account creation, PDA allocation, and token operations.

§Crate features

  • logs (default) — enables on-chain logging via solana-program-log.
  • derive (default) — enables the pina_macros proc-macro crate.
  • token — enables SPL token / token-2022 helpers and associated token account utilities.

Re-exports§

pub use crate::transaction::InstructionBuilder;
pub use bytemuck;
pub use pinocchio;
pub use pinocchio_system as system;
pub use solana_program_log;
pub use typed_builder;

Modules§

entrypoint
The Solana program entrypoint attribute. Macros and functions for defining the program entrypoint and setting up global handlers.
introspection
Instruction introspection helpers for reading the Instructions sysvar.
prelude
Re-exports commonly used traits and helpers for instruction modules.
sysvars
Solana sysvar access utilities. Provides access to cluster system accounts.
transaction
Typed instruction construction helpers for client-side usage.

Macros§

address
Macro for creating a compile-time Address from a base-58 string literal. Convenience macro to define a static Address value.
declare_id
Macro for declaring a program ID constant with associated ID and id() items. Convenience macro to declare a static address and functions to interact with it.
impl_int_conversion
Macro for implementing bidirectional conversion between Pod wrappers and standard integers. Implements bidirectional conversion between a Pod* wrapper type and its corresponding standard integer.
into_discriminator
Wrap an enum to automatically make it into a discriminator.
log
Logs a message to the Solana runtime.
nostd_entrypoint
Sets up a no_std Solana program entrypoint.
program_entrypoint
Macro for declaring a Solana program entrypoint. Declare the program entrypoint.

Structs§

AccountView
A Solana account as seen by the runtime during instruction execution. Wrapper struct for a RuntimeAccount.
Address
A 32-byte Solana public key / address. The address of a Solana account.
InstructionAccount
An account reference passed as part of an instruction. Describes an account during instruction execution.
InstructionView
A view of a cross-program invocation instruction. Information about an instruction.
Logger
A logger instance for formatting on-chain log messages. Logger to efficiently format log messages.
PodBool
The standard bool is not a Pod, define a replacement that is.
PodI16
i16 type that can be used in Pods.
PodI32
i32 type that can be used in Pods.
PodI64
i64 type that can be used in Pods.
PodI128
i128 type that can be used in Pods.
PodU16
u16 type that can be used in Pods.
PodU32
u32 type that can be used in Pods.
PodU64
u64 type that can be used in Pods.
PodU128
u128 type that can be used in Pods.
Seed
A single seed byte slice used in PDA signing. Represents a signer seed.
Signer
A set of seeds that identifies a PDA signer for CPI calls. Represents a program derived address (PDA) signer controlled by the calling program.

Enums§

PinaProgramError
Built-in framework error types. Built-in pina framework errors.
ProgramError
Error type returned by Solana programs. Reasons the program may fail

Constants§

ADDRESS_BYTES
Number of bytes in a Solana address (32). Number of bytes in an address.
MAX_DISCRIMINATOR_SPACE
Core traits for account validation, deserialization, and instruction processing. The maximum number of bytes that a discriminator can occupy, chosen to prevent alignment issues. Since the largest alignment size is u64 (8 bytes), this constant ensures the discriminator never causes alignment errors.
MAX_PERMITTED_DATA_INCREASE
CPI helpers for account creation, PDA allocation, and account closure. Maximum number of bytes an account may grow by in a single instruction.
MAX_SEEDS
Maximum number of seeds allowed when deriving a PDA. Maximum number of seeds
MAX_SEED_LEN
Maximum length in bytes of a single PDA seed. maximum length of derived Address seed

Traits§

AccountDeserialize
Core traits for account validation, deserialization, and instruction processing. Zero-copy deserialization for on-chain account data.
AccountInfoValidation
Core traits for account validation, deserialization, and instruction processing. Validation trait for raw AccountView references.
AccountValidation
Core traits for account validation, deserialization, and instruction processing. Validation trait for deserialized account data (e.g. EscrowState).
AsAccount
Core traits for account validation, deserialization, and instruction processing. Deserializes raw AccountView data into a typed account reference.
CloseAccountWithRecipient
Core traits for account validation, deserialization, and instruction processing. Close an account and reclaim its rent lamports.
HasDiscriminator
Core traits for account validation, deserialization, and instruction processing. Associates a concrete type (account / instruction / event struct) with its discriminator enum variant.
IntoDiscriminator
Core traits for account validation, deserialization, and instruction processing. Low-level discriminator codec.
LamportTransfer
Core traits for account validation, deserialization, and instruction processing. Direct lamport transfer between accounts.
Pod
Marker trait for types that can be safely cast from any byte pattern. Marker trait for “plain old data”.
ProcessAccountInfos
Core traits for account validation, deserialization, and instruction processing. Instruction processor.
TryFromAccountInfos
Core traits for account validation, deserialization, and instruction processing. Destructures a slice of AccountView into a named accounts struct.
Zeroable
Marker trait for types that can be safely zeroed. Trait for types that can be safely created with zeroed.

Functions§

allocate_account
CPI helpers for account creation, PDA allocation, and account closure. Allocates space for a new program account, returning the derived address and the canonical bump.
allocate_account_with_bump
CPI helpers for account creation, PDA allocation, and account closure. Allocates space for a new program account with user-provided bump.
assert
Utility functions for instruction parsing, assertions, and token address derivation. Asserts a boolean condition, logging msg and returning err on failure.
close_account
CPI helpers for account creation, PDA allocation, and account closure. Closes an account and returns the remaining rent lamports to the provided recipient.
combine_seeds_with_bump
CPI helpers for account creation, PDA allocation, and account closure. Appends a single-byte bump seed to the provided seeds array, returning a fixed-size [Seed; MAX_SEEDS] suitable for PDA signing.
create_account
CPI helpers for account creation, PDA allocation, and account closure. Creates a new system account owned by owner.
create_program_account
CPI helpers for account creation, PDA allocation, and account closure. Creates a new PDA-backed program account and returns (address, bump).
create_program_account_with_bump
CPI helpers for account creation, PDA allocation, and account closure. Creates a new PDA-backed program account using a caller-provided bump.
create_program_address
PDA (Program Derived Address) derivation and verification functions. Create a valid program derived address without searching for a bump seed.
find_program_addressDeprecated
PDA (Program Derived Address) derivation and verification functions. Find a valid program derived address and its corresponding bump seed.
log_caller
Utility functions for instruction parsing, assertions, and token address derivation. Logs caller file/line/column when logs feature is enabled.
parse_instruction
Utility functions for instruction parsing, assertions, and token address derivation. Parses an instruction discriminator from the raw instruction data.
pod_from_bytes
Reinterprets a byte slice as &T (zero-copy). Returns an error if the slice has incorrect length or alignment.
realloc_account
CPI helpers for account creation, PDA allocation, and account closure. Reallocates an account to new_size bytes, adjusting rent automatically.
realloc_account_zero
CPI helpers for account creation, PDA allocation, and account closure. Reallocates an account to new_size bytes with explicit zero-initialization, adjusting rent automatically.
try_find_program_address
PDA (Program Derived Address) derivation and verification functions. Find a valid program derived address and its corresponding bump seed.

Type Aliases§

ProgramResult
The result type returned by Solana program entrypoints and instruction handlers.

Attribute Macros§

account
Re-export all proc macros from pina_macros when the derive feature is enabled. The account macro is used to annotate account data that will exist within a solana account.
discriminator
Re-export all proc macros from pina_macros when the derive feature is enabled. This attribute macro should be used for annotating the globally shared instruction and account discriminators.
error
Re-export all proc macros from pina_macros when the derive feature is enabled. #[error] is a lightweight modification to the provided enum acting as syntactic sugar to make it easier to manage your custom program errors.
event
Re-export all proc macros from pina_macros when the derive feature is enabled. The event macro is used to annotate event data that will be emitted from a solana program.
instruction
Re-export all proc macros from pina_macros when the derive feature is enabled. The instruction macro is used to annotate instruction data that will exist within a solana instruction.
log_cu_usage
Logs the current compute unit usage to the Solana runtime. Attribute macro for instrumenting functions with compute unit logging.

Derive Macros§

Accounts
Re-export all proc macros from pina_macros when the derive feature is enabled. Derives the [TryFromAccountInfos] trait for a named-field struct.
Pod
Marker trait for types that can be safely cast from any byte pattern. Derive the Pod trait for a struct
TypedBuilder
Derive macro that generates a type-safe builder with compile-time field checking.
Zeroable
Marker trait for types that can be safely zeroed. Derive the Zeroable trait for a type.