feat(token-2022/nft-meta-data-pointer): add pinocchio example - #718
Open
MarkFeder wants to merge 2 commits into
Open
feat(token-2022/nft-meta-data-pointer): add pinocchio example#718MarkFeder wants to merge 2 commits into
MarkFeder wants to merge 2 commits into
Conversation
Contributor
Greptile SummaryThe PR adds a Pinocchio implementation of the Token-2022 metadata-pointer NFT game.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Important Files Changed
Reviews (2): Last reviewed commit: "nft-meta-data-pointer: bind the mint to ..." | Re-trigger Greptile |
…program chop_tree accepted any Token-2022 mint, and every NFT this program mints shares one metadata authority, so a valid player could rewrite another player's wood. It also invoked the metadata CPI against the caller-supplied program slot. The reference pins that slot with Program<'info, Token2022> and builds the instruction against spl_token_2022::id(); its mint account documents the holder check in a CHECK comment but never enforces it.
Contributor
Author
|
@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 |
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.
Ports
tokens/token-2022/nft-meta-data-pointerto Pinocchio.An NFT whose metadata lives in the mint itself via the Token-2022
MetadataPointerextension (pointing at the mint), so there is no separate metadata account. A small chop-the-tree game writes the player's bankedwoodonto that metadata as they play, which is what makes the pointer worth demonstrating: the token's own data tracks progress, no indexer involved.init_player— creates the player PDA and the shared level PDA (only the first player pays for the level)mint_nft— 234-byte mint,MetadataPointer→ mint,InitializeMint2(0 decimals), metadata initialize +level=1, ATA, mint 1, thenSetAuthority(MintTokens, None)so the supply is fixed at one. The metadata authority stays with the program PDA, which is what letschop_treekeep updating it.chop_tree— spends energy, banks wood, rewriteswoodon the mint's metadataThere is no pinocchio crate for Token-2022 or the token-metadata interface, so those CPIs are built by hand; the discriminators are documented from their preimages rather than pasted.
One deliberate omission: the Anchor example routes
chop_treethrough gum session keys, which have no Pinocchio equivalent and are orthogonal to what this example teaches. Herechop_treerequires the player's own signature (player.authority == signer). Everything else matches the reference, includingon_tree_chopped's pre-add level comparison.Tests use LiteSVM +
@solana/kit; 8 tests cover both instructions plus the energy refill and the authority check. Rent is topped up after metadata writes, sinceUpdateFieldgrows the mint.