Add Token-2022 memo-transfer Pinocchio example - #700
Conversation
Ports the memo-transfer Token-2022 example to Pinocchio (the anchor example has no native sibling), matching the token-2022 pinocchio account-extension template (kit + litesvm, official @solana-program packages, real Rent::get()). The program hand-rolls three Token-2022 CPIs to create a token account with the MemoTransfer extension enabled: it creates the account, runs InitializeAccount3, then (unlike ImmutableOwner, which is pre-init) enables required memo transfers via EnableRequiredMemoTransfers after initialization, which the account owner signs. The owner is the payer. Account size is 171 bytes (a 1-byte MemoTransfer TLV value). The litesvm test decodes the account with the official Token-2022 codec and asserts the requirement is enabled.
Greptile SummaryThe PR adds a Pinocchio Token-2022 memo-transfer example that creates an extended token account and enables required incoming-transfer memos.
Confidence Score: 5/5The PR appears safe to merge. The previously reported memo-enforcement coverage gap is fixed by explicit rejection and successful-transfer cases, and no blocking failure remains. Important Files Changed
Reviews (2): Last reviewed commit: "token-2022 memo-transfer pinocchio: test..." | Re-trigger Greptile |
Adds a behavior test alongside the extension-state assertion: it funds a source account, then verifies a TransferChecked into the memo-required account is rejected without a preceding memo and succeeds when preceded by one (SPL Memo program, bundled by LiteSVM). Addresses review feedback that the example's advertised transfer behavior was untested.
|
@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
memo-transferexample. The example previously had only ananchorversion (nonative), so this is a fresh port. It follows the same kit + litesvm + official-@solana-program-packages template as the merged Token-2022 pinocchio examples, and builds directly on the account-extension shape fromimmutable-owner(#696).How it works
The single instruction creates a Token-2022 token account with the
MemoTransferextension enabled. Once enabled, every transfer into the account must be preceded by a memo instruction, or the transfer fails.The program hand-rolls three CPIs:
CreateAccount— with space for the extension.InitializeAccount3(variant 18):[18] + owner(32).EnableRequiredMemoTransfers— wrapperMemoTransferExtension(variant30), subEnable(0), empty data →[30, 0].Unlike
ImmutableOwner(which must be initialized beforeInitializeAccount), this extension is enabled after the account is initialized, and the enable must be signed by the account owner (here, the payer). The owner is the payer, so a single signature covers funding and the enable.The extended token account is 171 bytes (base 165 + account-type byte 1 + a 5-byte
MemoTransferTLV entry whose value is a singlebool).Test
litesvm+@solana/kit. The test creates a plain Token-2022 mint client-side, invokes the program to create the token account, then decodes it with the official@solana-program/token-2022codec and asserts:mintandowner, andMemoTransferextension'srequireIncomingTransferMemosistrue.Verified locally:
cargo build-sbf, the litesvm test,tsc --noEmit, Prettier,cargo fmt --check, Clippy, andpnpm install --frozen-lockfileall clean.