feat(token-2022/metadata): add pinocchio example - #706
Conversation
Ports the metadata Token-2022 example to Pinocchio (the anchor example has no native sibling). The single instruction creates a mint with the MetadataPointer extension pointing at itself, then writes on-chain TokenMetadata into the same account via the SPL Token Metadata interface (which Token-2022 implements). The metadata is variable-length, so the account is created sized for the base mint and metadata pointer only, and the metadata Initialize CPI reallocates it to fit; the program tops up the mint's rent for the larger size beforehand. name/symbol/uri arrive Borsh-encoded in the instruction data and are forwarded verbatim after the interface's 8-byte discriminator. The litesvm test decodes the mint with the official Token-2022 codec and asserts the pointer and the stored name/symbol/uri.
Greptile SummaryThe PR adds a Pinocchio implementation of the Token-2022 metadata example.
Confidence Score: 5/5The PR appears safe to merge; no concrete changed-code defect or security issue was identified. The implementation keeps extension initialization order, serialized layouts, CPI account roles, account sizing, and rent funding aligned, while the end-to-end test validates the resulting mint with the official Token-2022 decoder. Important Files Changed
Reviews (1): Last reviewed commit: "feat(token-2022/metadata): add pinocchio..." | Re-trigger Greptile |
|
@amilz could you take a look at this one when you get a chance? No open review threads left on it, so it is ready for maintainer review. It is one of 23 open Pinocchio ports I have up — they are independent and self-contained, so they can be reviewed and merged in any order: https://github.com/solana-developers/program-examples/pulls/MarkFeder |
What
Adds a Pinocchio implementation of the Token-2022
metadataexample (the anchor example has nonativesibling), following the same kit + litesvm template as the other Token-2022 pinocchio examples. This is the last of the token-2022 mint extensions.How it works
The single instruction creates a mint that stores its own on-chain metadata:
MetadataPointerextension (234 bytes).39) — points the mint at itself as the metadata account.20) — decimals 2, payer as mint authority.name/symbol/uri.Two things worth noting:
sha256("spl_token_metadata_interface:initialize_account")[..8]), not the 1-byte Token-2022 variants.name/symbol/urifrom its instruction data verbatim after the discriminator.Test
litesvm+@solana/kit. The test encodesname/symbol/uri, invokes the program, then decodes the mint with the official@solana-program/token-2022codec and asserts theMetadataPointerpoints at the mint and theTokenMetadataholds the expected fields.Verified locally:
cargo build-sbf, the litesvm test,tsc --noEmit, Prettier,cargo fmt --check, Clippy, andpnpm install --frozen-lockfileall clean. (Thedeployscript uses the*.soglob per #702.)AI use: I directed the design (the CPI sequence, the realloc + rent top-up, the instruction-data passthrough) and verified every encoding against the
spl-token-2022-interface/spl-token-metadata-interfacesources; implementation and tests were written with Claude Code and reviewed by me.