| Crates.io | pinocchio-tkn |
| lib.rs | pinocchio-tkn |
| version | 0.2.2 |
| created_at | 2025-10-27 03:01:40.068168+00 |
| updated_at | 2025-12-30 12:32:54.547007+00 |
| description | Complete Token toolkit for Pinocchio: SPL Token + Token-2022 with unified API, zero deps, zero allocs |
| homepage | |
| repository | https://github.com/8ctag0n/007 |
| max_upload_size | |
| id | 1902167 |
| size | 2,547,846 |
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.
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 extensionspinocchio-tkn provides:
[dependencies]
pinocchio = "0.9"
pinocchio-tkn = "0.2" # Includes: common, state, helpers (default)
Choose only what you need to minimize binary size:
# Minimal: Only transfers and basic instructions
pinocchio-tkn = { version = "0.2", default-features = false, features = ["common"] }
# Common + State parsing
pinocchio-tkn = { version = "0.2", default-features = false, features = ["common", "state"] }
# With specific Token-2022 extensions
pinocchio-tkn = { version = "0.2", features = ["ext-transfer-fee", "ext-metadata"] }
# Everything (all extensions)
pinocchio-tkn = { version = "0.2", features = ["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 - EverythingDefault: ["common", "state", "helpers"]
use pinocchio_tkn::prelude::*;
// Transfer tokens (works with both SPL Token and Token-2022)
Transfer {
source,
destination,
authority,
amount: 1_000_000,
program_id: None, // Auto-detect from account owner
}.invoke()?;
// Initialize Token-2022 with transfer fees
InitializeTransferFeeConfig {
mint,
transfer_fee_config_authority: Some(authority.key()),
withdraw_withheld_authority: Some(withdraw_authority.key()),
transfer_fee_basis_points: 100, // 1%
maximum_fee: 5000,
}.invoke()?;
// Parse mint data (zero-copy)
let mint = Mint::from_account_info(&mint_account)?;
let decimals = mint.decimals();
let supply = mint.supply();
// Calculate transfer fee
let fee = calculate_transfer_fee(1_000_000, 100, 5_000); // 1% fee capped at 5000
// Validate accounts (security checks)
assert_is_mint(&mint_account)?;
assert_is_token_account(&token_account, Some(&mint.key()), Some(&owner.key()))?;
assert_account_not_frozen(&token_account)?;
Common Instructions (20) - Work with both SPL Token and Token-2022:
Transfer, TransferCheckedMintTo, MintToChecked, Burn, BurnCheckedInitializeAccount, InitializeAccount2, InitializeAccount3InitializeMint, InitializeMint2Approve, ApproveChecked, RevokeSetAuthority, CloseAccountFreezeAccount, ThawAccountSyncNative, InitializeMultisigToken-2022 Extensions (37) - Advanced features:
InitializeTransferFeeConfig, TransferCheckedWithFee, etc.InitializeTokenMetadata, UpdateField, RemoveKey, EmitInitializeInterestBearingMint, UpdateInterestRateInitializeTransferHook, SetTransferHookDefaultAccountState, NonTransferable, Pause/ResumeMintCloseAuthority, PermanentDelegateMetadataPointer, GroupPointer, GroupMemberPointerCpiGuard, MemoTransferScaledUiAmount, ImmutableOwneruse pinocchio_tkn::state::{Mint, TokenAccount};
// Parse mint (works with Token-2022 extensions)
let mint = Mint::from_account_info(&mint_account)?;
assert_eq!(mint.decimals(), 6);
assert_eq!(mint.supply(), 1_000_000_000);
// Parse token account
let account = TokenAccount::from_account_info(&token_account)?;
assert_eq!(account.amount(), 500_000);
assert!(!account.is_frozen());
assert_eq!(account.mint(), &mint_pubkey);
No allocations, no copying - just direct byte access.
use pinocchio_tkn::helpers::*;
// UI amount conversions
let raw = ui_amount_to_amount(1.5, 6); // 1.5 USDC -> 1_500_000
let ui = amount_to_ui_amount(1_500_000, 6); // -> 1.5
// Transfer fee calculation
let fee = calculate_transfer_fee(1_000_000, 100, 5_000); // 1% capped
// Inverse fee (amount needed to receive X after fees)
let (amount, fee) = calculate_inverse_transfer_fee(100_000, 100, 5_000);
// Interest calculation
let interest = calculate_accrued_interest(
1_000_000, // balance
500, // 5% APY (basis points)
365 * 24 * 3600, // 1 year
);
// Space calculation for rent
let space = mint_space_for_extensions(&[
ExtensionType::TransferFeeConfig,
ExtensionType::MetadataPointer,
]);
let rent = rent_exempt_minimum(space, 3480);
use pinocchio_tkn::helpers::*;
// Security checks
assert_owned_by(&account, &TOKEN_2022_PROGRAM_ID)?;
assert_is_mint(&mint_account)?;
assert_is_token_account(&token_account, Some(&mint.key()), Some(&owner.key()))?;
// State validation
assert_account_not_frozen(&token_account)?;
assert_mint_authority(&mint, &authority)?;
assert_freeze_authority(&mint, &authority)?;
// Auto-detection
let program_id = get_token_program_id(&account);
if is_token_2022(&account) {
// Use Token-2022 features
}
MaybeUninit#[inline] for optimal performancepinocchio-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.
| 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
use pinocchio_tkn::common::Transfer;
// Works with both SPL Token and Token-2022
Transfer {
source: &source_account,
destination: &destination_account,
authority: &authority_account,
amount: 1_000_000,
program_id: None, // Detects from source.owner()
}.invoke()?;
use pinocchio_tkn::extensions::*;
// Initialize mint with transfer fees
InitializeTransferFeeConfig {
mint: &mint_account,
transfer_fee_config_authority: Some(&authority.key()),
withdraw_withheld_authority: Some(&withdraw_authority.key()),
transfer_fee_basis_points: 100, // 1%
maximum_fee: 5_000,
}.invoke()?;
// Transfer with fees
TransferCheckedWithFee {
source: &source_account,
mint: &mint_account,
destination: &destination_account,
authority: &authority_account,
amount: 1_000_000,
decimals: 6,
}.invoke()?;
use pinocchio_tkn::extensions::*;
InitializeTokenMetadata {
mint: &mint_account,
update_authority: &authority_account,
mint_authority: &mint_authority_account,
name: "My Token",
symbol: "MTK",
uri: "https://example.com/metadata.json",
}.invoke()?;
More examples in examples/ directory.
Comprehensive tests covering:
cargo test
Coverage status is tracked in docs/architecture/overview.md.
benches/instruction_building.rsVersion: 0.2.1 Stability: Production-ready Audit Status: Not audited (use at own risk)
Coverage:
Canonical coverage status: docs/architecture/overview.md
Contributions welcome! Open an issue or PR on GitHub.
Areas for contribution:
MIT OR Apache-2.0
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