Add Token-2022 basics Pinocchio example - #705
Conversation
Greptile SummaryThe PR adds a Pinocchio implementation of the Token-2022 basics example, covering mint creation, token-account creation, associated accounts, minting, and checked transfers.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Important Files Changed
Reviews (2): Last reviewed commit: "token-2022 basics: reject oversized toke..." | Re-trigger Greptile |
| // Derive the mint PDA and confirm the supplied account matches it. | ||
| let (mint_pda, bump) = | ||
| Address::find_program_address(&[TOKEN_SEED, signer.address().as_ref(), token_name], program_id); |
There was a problem hiding this comment.
token_name contains all instruction bytes after the discriminator and is passed directly to find_program_address. Names longer than Solana's 32-byte per-seed limit reach invalid PDA derivation instead of returning a deliberate InvalidInstructionData error.
| // Derive the mint PDA and confirm the supplied account matches it. | |
| let (mint_pda, bump) = | |
| Address::find_program_address(&[TOKEN_SEED, signer.address().as_ref(), token_name], program_id); | |
| // Derive the mint PDA and confirm the supplied account matches it. | |
| if token_name.len() > 32 { | |
| return Err(ProgramError::InvalidInstructionData); | |
| } | |
| let (mint_pda, bump) = | |
| Address::find_program_address(&[TOKEN_SEED, signer.address().as_ref(), token_name], program_id); |
Knowledge Base Used: Program-derived address design
|
Good catch — pushed 766e743: |
Ports the anchor
tokens/token-2022/basicsexample to Pinocchio.Exposes the same five instructions, dispatched on a leading discriminator byte:
[b"token-2022-token", signer, token_name]PDA, signed by the PDA; signer is the mint authority, no freeze authority.[b"token-2022-token-account", signer, mint]PDA (the anchor example's non-ATA reference path).pinocchio-associated-token-account(program-agnostic; the Token-2022 program is passed through).MintToandTransferChecked; transfer creates the recipient's ATA idempotently first.There is no Pinocchio crate for Token-2022, so its instructions (
InitializeMint2,InitializeAccount3,MintTo,TransferChecked) are built by hand and CPI'd — matching the siblingimmutable-owner/groupexamples.A single LiteSVM test drives all five instructions end to end and asserts balances, account sizes, and owners with the official Token-2022 codec.