pinocchio-tkn
The Complete Token Toolkit for Pinocchio Programs
Zero-dependency, zero-allocation CPI helpers for SPL Token and Token-2022. Built for Pinocchio, the fastest Solana framework.
Why pinocchio-tkn?
While official packages exist (pinocchio-token, pinocchio-token-2022), they are fragmented and incomplete:
pinocchio-token: Legacy SPL Token onlypinocchio-token-2022: Core instructions only, no extensions- No unified interface
pinocchio-tkn provides:
- Complete coverage across core instructions and extensions
- Broad Token-2022 extension coverage (non-confidential; confidential extensions are documented only)
- Unified API: Single interface for both SPL Token and Token-2022
- State parsing: Zero-copy Mint and TokenAccount readers
- Calculation helpers: Fees, interest, space, rent, UI amounts
- Validation helpers: Security checks and assertions
- Battle-tested: Comprehensive tests covering edge cases
- Production-ready: Used in real protocols
Quick Start
Installation
[]
= "0.9"
= "0.2" # Includes: common, state, helpers (default)
Optional Features
Choose only what you need to minimize binary size:
# Minimal: Only transfers and basic instructions
= { = "0.2", = false, = ["common"] }
# Common + State parsing
= { = "0.2", = false, = ["common", "state"] }
# With specific Token-2022 extensions
= { = "0.2", = ["ext-transfer-fee", "ext-metadata"] }
# Everything (all extensions)
= { = "0.2", = ["full"] }
Available features:
common- Common instructions (SPL Token + Token-2022 core)state- State parsing (Mint, TokenAccount)helpers- Calculation, validation, detection helpersext-transfer-fee- Transfer fee instructionsext-metadata- On-chain metadata instructionsext-interest- Interest bearing mintext-pointers- Metadata/Group/Member pointersext-misc- CpiGuard, MemoTransfer, Pause, Reallocate, etcextensions- All non-confidential Token-2022 extensionsfull- Everything
Default: ["common", "state", "helpers"]
Basic Usage
use *;
// Transfer tokens (works with both SPL Token and Token-2022)
Transfer .invoke?;
// Initialize Token-2022 with transfer fees
InitializeTransferFeeConfig .invoke?;
// Parse mint data (zero-copy)
let mint = from_account_info?;
let decimals = mint.decimals;
let supply = mint.supply;
// Calculate transfer fee
let fee = calculate_transfer_fee; // 1% fee capped at 5000
// Validate accounts (security checks)
assert_is_mint?;
assert_is_token_account?;
assert_account_not_frozen?;
Features
Complete Instruction Coverage
Common Instructions (20) - Work with both SPL Token and Token-2022:
Transfer,TransferCheckedMintTo,MintToChecked,Burn,BurnCheckedInitializeAccount,InitializeAccount2,InitializeAccount3InitializeMint,InitializeMint2Approve,ApproveChecked,RevokeSetAuthority,CloseAccountFreezeAccount,ThawAccountSyncNative,InitializeMultisig
Token-2022 Extensions (37) - Advanced features:
- Transfer Fees:
InitializeTransferFeeConfig,TransferCheckedWithFee, etc. - Metadata:
InitializeTokenMetadata,UpdateField,RemoveKey,Emit - Interest:
InitializeInterestBearingMint,UpdateInterestRate - Transfer Hooks:
InitializeTransferHook,SetTransferHook - State Management:
DefaultAccountState,NonTransferable,Pause/Resume - Authorities:
MintCloseAuthority,PermanentDelegate - Pointers:
MetadataPointer,GroupPointer,GroupMemberPointer - Security:
CpiGuard,MemoTransfer - Advanced:
ScaledUiAmount,ImmutableOwner
Zero-Copy State Parsing
use ;
// Parse mint (works with Token-2022 extensions)
let mint = from_account_info?;
assert_eq!;
assert_eq!;
// Parse token account
let account = from_account_info?;
assert_eq!;
assert!;
assert_eq!;
No allocations, no copying - just direct byte access.
Calculation Helpers
use *;
// UI amount conversions
let raw = ui_amount_to_amount; // 1.5 USDC -> 1_500_000
let ui = amount_to_ui_amount; // -> 1.5
// Transfer fee calculation
let fee = calculate_transfer_fee; // 1% capped
// Inverse fee (amount needed to receive X after fees)
let = calculate_inverse_transfer_fee;
// Interest calculation
let interest = calculate_accrued_interest;
// Space calculation for rent
let space = mint_space_for_extensions;
let rent = rent_exempt_minimum;
Validation Helpers
use *;
// Security checks
assert_owned_by?;
assert_is_mint?;
assert_is_token_account?;
// State validation
assert_account_not_frozen?;
assert_mint_authority?;
assert_freeze_authority?;
// Auto-detection
let program_id = get_token_program_id;
if is_token_2022
Architecture
Design Principles
- Zero-copy: All state parsing uses direct byte access (no allocations)
- Zero-allocation: Instruction data built on stack using
MaybeUninit - Unified interface: Single API for SPL Token and Token-2022
- Type-safe: Rust types prevent common errors
- Inline everything: All helpers are
#[inline]for optimal performance
Module Structure
pinocchio-tkn/
├── common/ # Common instructions (SPL + Token-2022)
├── extensions/ # Token-2022 exclusive features
├── state/ # Zero-copy Mint and TokenAccount parsing
└── helpers/ # Calculations, validation, detection
See docs/architecture/overview.md for detailed design decisions.
Comparison
| Feature | pinocchio-tkn | pinocchio-token-2022 | anchor-spl | spl-token |
|---|---|---|---|---|
| SPL Token support | ✅ Full | ❌ No | ✅ Full | ✅ Full |
| Token-2022 core | ✅ Full | ✅ Full | ✅ Full | ✅ Full |
| Token-2022 extensions | ✅ Broad (non-confidential) | ❌ None | ⚠️ Partial | ✅ Full |
| State parsing | ✅ Zero-copy | ❌ No | ✅ Yes | ✅ Yes |
| Unified API | ✅ Yes | ❌ No | ⚠️ Separate | ❌ No |
| Calculation helpers | ✅ Comprehensive | ❌ No | ❌ No | ⚠️ Limited |
| Validation helpers | ✅ Comprehensive | ❌ No | ❌ No | ❌ No |
| Dependencies | ✅ Minimal | ⚠️ Some | ⚠️ Many | ⚠️ Many |
| Proc macros | ❌ No | ❌ No | ✅ Heavy | ❌ No |
| Build time | ✅ Fast | ✅ Fast | ⚠️ Slower | ⚠️ Slower |
| Binary size impact | ✅ Small | ✅ Small | ⚠️ Larger | ⚠️ Larger |
TL;DR: pinocchio-tkn is the only complete solution for Pinocchio programs.
NOTE : ok, let me be honest ... ZK extensions aren't implemented (yet) but will eventually ... 22/22 looks waaaaay better that something incomplete also, i need some time to understand how ZK works, now looks like magic to me tbh
Examples
Transfer with Auto-Detection
use Transfer;
// Works with both SPL Token and Token-2022
Transfer .invoke?;
Token-2022 with Transfer Fees
use *;
// Initialize mint with transfer fees
InitializeTransferFeeConfig .invoke?;
// Transfer with fees
TransferCheckedWithFee .invoke?;
On-Chain Metadata
use *;
InitializeTokenMetadata .invoke?;
More examples in examples/ directory.
Testing
Comprehensive tests covering:
- All instructions (happy path + error cases)
- State parsing (edge cases, invalid data)
- Calculation helpers (overflow, rounding, edge values)
- Validation helpers (security checks)
- Integration workflows
Coverage status is tracked in docs/architecture/overview.md.
Performance
- Zero allocations in core paths
- O(1) state parsing and instruction building
- Benchmarks: See
benches/instruction_building.rs
Status
Version: 0.2.1 Stability: Production-ready Audit Status: Not audited (use at own risk)
Coverage:
- SPL Token core instructions
- Token-2022 core instructions
- Token-2022 extensions (non-confidential)
- Confidential extensions are documented but not implemented
Canonical coverage status: docs/architecture/overview.md
Contributing
Contributions welcome! Open an issue or PR on GitHub.
Areas for contribution:
- Additional examples
- Benchmarks
- Documentation improvements
- Edge case tests
License
MIT OR Apache-2.0
Resources
Disclaimer
NOT AUDITED. USE AT YOUR OWN RISK.
This is an unofficial toolkit. Review the code and test thoroughly before using it in production. We built it because we got tired of writing instruction bytes by hand and wanted a clean, unified API.
Built by 888 Team
Questions? Open an issue on GitHub