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 |
| } | ||
|
|
||
| // The extension was enabled by the post-init CPI. | ||
| assert.equal(memoTransfer.requireIncomingTransferMemos, true); |
There was a problem hiding this comment.
Memo enforcement remains untested
The test only checks that requireIncomingTransferMemos is stored as true; it never verifies that an incoming transfer without a memo fails and one preceded by a memo succeeds. A regression in the example's advertised transfer behavior would therefore lack direct test coverage, so add both negative and positive transfer cases as in the Anchor example.
Knowledge Base Used: Token-2022 extension patterns
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Good call — addressed in 80a66dac. Added a second test that funds a source account and verifies a TransferChecked into the memo-required account is rejected without a preceding memo and succeeds when preceded by one (SPL Memo program, which LiteSVM bundles), then asserts the destination balance. Both tests pass.
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.
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.