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_stdcompatible — 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
AccountViewreferences (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 viasolana-program-log.derive(default) — enables thepina_macrosproc-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
Addressfrom a base-58 string literal. Convenience macro to define a staticAddressvalue. - declare_
id - Macro for declaring a program ID constant with associated
IDandid()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_stdSolana program entrypoint. - program_
entrypoint - Macro for declaring a Solana program entrypoint. Declare the program entrypoint.
Structs§
- Account
View - 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.
- Instruction
Account - An account reference passed as part of an instruction. Describes an account during instruction execution.
- Instruction
View - 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
boolis not aPod, define a replacement that is. - PodI16
i16type that can be used inPods.- PodI32
i32type that can be used inPods.- PodI64
i64type that can be used inPods.- PodI128
i128type that can be used inPods.- PodU16
u16type that can be used inPods.- PodU32
u32type that can be used inPods.- PodU64
u64type that can be used inPods.- PodU128
u128type that can be used inPods.- 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§
- Pina
Program Error - Built-in framework error types. Built-in pina framework errors.
- Program
Error - 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
Addressseed
Traits§
- Account
Deserialize - Core traits for account validation, deserialization, and instruction processing. Zero-copy deserialization for on-chain account data.
- Account
Info Validation - Core traits for account validation, deserialization, and instruction
processing.
Validation trait for raw
AccountViewreferences. - Account
Validation - 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
AccountViewdata into a typed account reference. - Close
Account With Recipient - 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.
- Into
Discriminator - Core traits for account validation, deserialization, and instruction processing. Low-level discriminator codec.
- Lamport
Transfer - 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”.
- Process
Account Infos - Core traits for account validation, deserialization, and instruction processing. Instruction processor.
- TryFrom
Account Infos - Core traits for account validation, deserialization, and instruction
processing.
Destructures a slice of
AccountViewinto 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
addressand the canonicalbump. - 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
msgand returningerron 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_ address Deprecated - 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
logsfeature 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_sizebytes, adjusting rent automatically. - realloc_
account_ zero - CPI helpers for account creation, PDA allocation, and account closure.
Reallocates an account to
new_sizebytes 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§
- Program
Result - The result type returned by Solana program entrypoints and instruction handlers.
Attribute Macros§
- account
- Re-export all proc macros from
pina_macroswhen thederivefeature 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_macroswhen thederivefeature 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_macroswhen thederivefeature 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_macroswhen thederivefeature 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_macroswhen thederivefeature 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_macroswhen thederivefeature 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
Podtrait for a struct - Typed
Builder - 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
Zeroabletrait for a type.