Skip to main content

Crate jiminy

Crate jiminy 

Source
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/std for 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 programexamples/jiminy-vaultuse jiminy::prelude::*
Harden a Pinocchio codebaseMIGRATION_COOKBOOK
Read external / Anchor accountsload_foreign / jiminy_interface!
Build off-chain toolingjiminy-schema@jiminy/ts

§Modules

§Ring 1 – jiminy_core

Module
accountHeader, reader, writer, cursor, lifecycle, pod, overlay, collection, list, bits
abiAlignment-safe LE wire types (LeU64, FieldRef, FieldMut)
checkValidation checks, asserts, PDA derivation & verification
mathChecked arithmetic, BPS, scaling
instructionTransaction introspection (sysvar Instructions)
interfaceRead-only foreign account interface macro
stateState machine transition checks
sysvarClock & Rent sysvar readers
timeDeadline, cooldown, staleness checks
eventZero-alloc event emission via sol_log_data
programsWell-known program IDs (feature: programs)

§Ring 2 – jiminy_solana

Module
tokenSPL Token account readers, mint readers, Token-2022 extension screening
cpiSafe CPI wrappers, reentrancy guards, return data readers
cryptoEd25519 precompile verification, Merkle proof verification
authorityTwo-step authority rotation (propose + accept)
balancePre/post CPI balance delta guards
computeCompute budget guards
composeTransaction composition guards (flash-loan detection)
introspectRaw transaction introspection
oraclePyth V2 price feed readers
twapTWAP accumulators
upgradeProgram 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_financeAMM math, slippage / economic bounds
jiminy_lendingLending protocol primitives
jiminy_stakingStaking reward accumulators
jiminy_vestingVesting schedule helpers
jiminy_multisigM-of-N multi-signer threshold
jiminy_distributeDust-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, and layout_id are 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 const seeds 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 Pod for 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 via Into) if false.
require_accounts_ne
Require two accounts to have different addresses.
require_eq
Require a == b for scalar types.
require_flag
Require bit n to be set in $byte, else return $err.
require_gt
Require a > b.
require_gte
Require a >= b.
require_keys_eq
Require two Address values to be equal.
require_keys_neq
Require two Address values to be different.
require_lt
Require a < b.
require_lte
Require a <= b.
require_neq
Require a != b for scalar types.
require_pda
Derive a PDA from seeds, verify the account matches, and return the bump.

Structs§

AccountView
Wrapper struct for a RuntimeAccount.
Address
The address of a Solana account.

Enums§

ProgramError
Reasons the program may fail

Type Aliases§

ProgramResult