Expand description
§jiminy
Zero-copy account layouts, safety checks, and ABI tooling for Solana programs built on pinocchio.
Sits between raw pinocchio and higher-level frameworks like Anchor. You get deterministic account layouts, verified zero-copy access, explicit safety tiers for account loading, and reusable validation functions for on-chain correctness. No framework, no proc macros, no hidden control flow.
no_std. no_alloc. Declarative macros only. Every function
#[inline(always)]. Built on pinocchio.
§Permanent non-goals
- Jiminy will never be a framework that owns your control flow.
- Jiminy will never require
alloc/stdfor core ABI + validation. - Jiminy will never make unsafe account loading the default.
- Jiminy will never make domain crates a dependency of core.
§Start Here
| I want to… | Start with |
|---|---|
| Start a new program | examples/jiminy-vault → use jiminy::prelude::* |
| Harden a Pinocchio codebase | MIGRATION_COOKBOOK |
| Read external / Anchor accounts | load_foreign / jiminy_interface! |
| Build off-chain tooling | jiminy-schema → @jiminy/ts |
§Modules
§Ring 1 – jiminy_core
| Module | |
|---|---|
account | Header, reader, writer, cursor, lifecycle, pod, overlay, collection, list, bits |
abi | Alignment-safe LE wire types (LeU64, FieldRef, FieldMut) |
check | Validation checks, asserts, PDA derivation & verification |
math | Checked arithmetic, BPS, scaling |
instruction | Transaction introspection (sysvar Instructions) |
interface | Read-only foreign account interface macro |
state | State machine transition checks |
sysvar | Clock & Rent sysvar readers |
time | Deadline, cooldown, staleness checks |
event | Zero-alloc event emission via sol_log_data |
programs | Well-known program IDs (feature: programs) |
§Ring 2 – jiminy_solana
| Module | |
|---|---|
token | SPL Token account readers, mint readers, Token-2022 extension screening |
cpi | Safe CPI wrappers, reentrancy guards, return data readers |
crypto | Ed25519 precompile verification, Merkle proof verification |
authority | Two-step authority rotation (propose + accept) |
balance | Pre/post CPI balance delta guards |
compute | Compute budget guards |
compose | Transaction composition guards (flash-loan detection) |
introspect | Raw transaction introspection |
oracle | Pyth V2 price feed readers |
twap | TWAP accumulators |
upgrade | Program upgrade authority verification (feature: programs) |
§Community / Domain Extensions (Not Core)
These crates demonstrate patterns built using Jiminy. They are not part of the core, and Jiminy does not depend on them.
| Crate | |
|---|---|
jiminy_finance | AMM math, slippage / economic bounds |
jiminy_lending | Lending protocol primitives |
jiminy_staking | Staking reward accumulators |
jiminy_vesting | Vesting schedule helpers |
jiminy_multisig | M-of-N multi-signer threshold |
jiminy_distribute | Dust-safe proportional distribution |
§Macros
Macros in Jiminy exist to reduce repetitive safety code, not to introduce
abstraction layers. All macros are declarative (macro_rules!). No proc
macros, no build dependency, no compile-time surprises.
§Account ABI
| Macro | |
|---|---|
zero_copy_layout! | Define #[repr(C)] account struct with Pod, overlay, tiered loaders, LAYOUT_ID |
segmented_layout! | Extend zero_copy_layout! with dynamic variable-length segments |
jiminy_interface! | Declare read-only view of a foreign program’s account (cross-program ABI) |
init_account! | CPI create + zero-init + header write in one call |
close_account! | Safe close with lamport drain and sentinel byte |
check_account! | Disc + version + layout_id validation |
check_account_strict! | Mandatory owner + disc + layout_id (compile error if missing) |
impl_pod! | Batch unsafe impl Pod for #[repr(C)] types |
§Safety guards
| Macro | |
|---|---|
require! | if !cond { return Err(e) } – the universal guard |
require_keys_eq! | Two addresses must match |
require_keys_neq! | Two addresses must differ |
require_gte! | a >= b |
require_gt! | a > b |
require_lt! | a < b |
require_lte! | a <= b |
require_eq! | Scalar equality |
require_neq! | Scalar inequality |
require_flag! | Bit must be set |
check_accounts_unique! | Pairwise uniqueness for any N accounts |
§Program structure
| Macro | |
|---|---|
error_codes! | Sequential error constants + Into<ProgramError> |
instruction_dispatch! | Byte-tag dispatch to handler functions |
§PDA
| Macro | |
|---|---|
find_pda! | Find canonical PDA + bump via syscall |
derive_pda! | Derive PDA with known bump (~100 CU) |
derive_pda_const! | Compile-time PDA derivation |
derive_ata_const! | Compile-time ATA derivation |
require_pda! | Derive + assert PDA match, return bump |
§Events
| Macro | |
|---|---|
emit! | Zero-alloc event emission via sol_log_data |
Re-exports§
pub use jiminy_core;pub use jiminy_solana;pub use jiminy_finance;pub use jiminy_lending;pub use jiminy_staking;pub use jiminy_vesting;pub use jiminy_multisig;pub use jiminy_distribute;pub use pinocchio;pub use pinocchio_system;pub use pinocchio_token;
Modules§
- abi
- Jiminy ABI field primitives — alignment-1 wire types.
- account
- Account-centric types: header, zero-copy IO, lifecycle, POD, iteration.
- amm
- AMM math: integer square root, constant-product swap formulas, LP minting.
- authority
- Two-step authority handoff (propose + accept).
- balance
- Balance delta checks for CPI composition.
- check
- Account and instruction validation checks.
- compat
- Compatibility modules for optional external crate integrations.
- compose
- Transaction composition guards.
- compute
- Compute unit budget guards.
- cpi
- Safe CPI wrappers, reentrancy guards, and return data readers.
- crypto
- Cryptographic verification: Ed25519 precompile and Merkle proofs.
- distribute
- Dust-safe proportional distribution and fee extraction.
- event
- Zero-alloc event emission via
sol_log_data. - instruction
- Unified instruction access via Sysvar Instructions.
- interface
- Cross-program ABI interface for read-only foreign account access.
- introspect
- Transaction introspection via Sysvar Instructions.
- lending
- Lending protocol primitives: collateralization, liquidation, interest.
- math
- multisig
- M-of-N multi-signer threshold checks.
- oracle
- Zero-copy Pyth V2 price feed readers.
- prelude
- Convenience re-exports for the common Jiminy usage pattern.
- programs
- slippage
- Slippage and economic bound checks.
- staking
- Staking reward accumulators (MasterChef-style).
- state
- State machine transition checks.
- sysvar
- Zero-copy sysvar readers.
- time
- Time and deadline constraint checks for DeFi programs.
- token
- SPL Token readers, mint readers, and Token-2022 extension screening.
- twap
- TWAP (time-weighted average price) accumulator math.
- upgrade
- Program upgrade authority verification.
- vesting
- Vesting schedule helpers: linear, cliff, stepped, periodic.
Macros§
- check_
account - Composable account constraint macro.
- check_
account_ strict - Strict account validation macro —
owner,disc, andlayout_idare mandatory positional arguments. Forgetting any of them is a compile error. - check_
accounts_ unique - Verify that all passed accounts have unique addresses.
- close_
account - Close a Jiminy account: transfer lamports and write close sentinel.
- derive_
pda - Derive a PDA with a known bump. Cheap (~100 CU, no curve check).
- derive_
pda_ const - Derive a PDA at compile time. Requires
constseeds and bump. - error_
codes - Define numbered program error codes that map to
ProgramError::Custom. - find_
pda - Find a PDA and return
(Address, u8)with the canonical bump. - impl_
pod - Batch
unsafe impl Podfor a list of types. - init_
account - Initialize a Jiminy account: CPI CreateAccount, zero-init, write header.
- instruction_
dispatch - Route instruction data to handler functions based on a single-byte tag.
- require
- Require a boolean condition: return
$err(converted viaInto) if false. - require_
accounts_ ne - Require two accounts to have different addresses.
- require_
eq - Require
a == bfor scalar types. - require_
flag - Require bit
nto be set in$byte, else return$err. - require_
gt - Require
a > b. - require_
gte - Require
a >= b. - require_
keys_ eq - Require two
Addressvalues to be equal. - require_
keys_ neq - Require two
Addressvalues to be different. - require_
lt - Require
a < b. - require_
lte - Require
a <= b. - require_
neq - Require
a != bfor scalar types. - require_
pda - Derive a PDA from seeds, verify the account matches, and return the bump.
Structs§
- Account
View - Wrapper struct for a
RuntimeAccount. - Address
- The address of a Solana account.
Enums§
- Program
Error - Reasons the program may fail