Skip to main content

Crate jiminy

Crate jiminy 

Source
Expand description

§jiminy

The zero-copy standard library for Solana programs.

Every pinocchio needs a conscience.

You chose pinocchio because you wanted raw performance and full control over your on-chain program. No allocator, no borsh, no framework opinions. Just bytes.

But you’re still writing the same signer check for the tenth time. You’re still hand-rolling amount * price / 10_000 and praying it doesn’t overflow at 4.2 billion tokens. And every check you forget to write is one exploit away from draining your vault.

jiminy is the standard library that pinocchio doesn’t ship. Every guard, check, reader, and piece of math that DeFi programs need – packaged as plain functions and declarative macros. no_std, no_alloc, no proc macros, every function #[inline(always)], pinocchio under the hood.

use jiminy::prelude::*;

§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)

§Ring 3+

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

All macros are declarative (macro_rules!). No proc macros, no build dependency, no compile-time surprises.

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
error_codes!Sequential error constants + Into<ProgramError>
instruction_dispatch!Byte-tag dispatch to handler functions
impl_pod!Batch unsafe impl Pod for primitive types

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_accounts_unique
Verify that all passed accounts have unique addresses.
close_account
Close a Jiminy account: transfer lamports and write close sentinel.
error_codes
Define numbered program error codes that map to ProgramError::Custom.
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.

Structs§

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

Enums§

ProgramError
Reasons the program may fail

Type Aliases§

ProgramResult