feat(token-2022/metadata): add pinocchio example - #706
Open
MarkFeder wants to merge 1 commit into
Open
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.
Contributor
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.