Skip to content

Add Token-2022 memo-transfer Pinocchio example - #700

Closed
MarkFeder wants to merge 2 commits into
solana-foundation:mainfrom
MarkFeder:tokens-token-2022-memo-transfer-pinocchio
Closed

MarkFeder wants to merge 2 commits into
solana-foundation:mainfrom
MarkFeder:tokens-token-2022-memo-transfer-pinocchio

Conversation

@MarkFeder

@MarkFeder MarkFeder commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Linked issue

Fixes #785

What and why

Adds a Pinocchio version of tokens/token-2022/memo-transfer, which only had an Anchor one. It follows the same kit + LiteSVM + @solana-program template as the merged Token-2022 Pinocchio examples and builds on the account-extension shape from immutable-owner (#696).

The single instruction creates a Token-2022 token account with the MemoTransfer extension enabled, so every transfer into it must be preceded by a memo. The program hand-builds three CPIs:

  1. CreateAccount, with space for the extension.
  2. InitializeAccount3 (variant 18): [18] + owner(32).
  3. EnableRequiredMemoTransfers: MemoTransferExtension (30), sub-instruction Enable (0) → [30, 0].

Unlike ImmutableOwner, this extension is enabled after the account is initialized, and the enable must be signed by the account owner (the payer here). The account is 171 bytes: 165 base + 1 account-type byte + a 5-byte MemoTransfer TLV.

The JS dependencies match the versions #765 set for the other non-anchor examples.

Testing

pnpm install --frozen-lockfile, tsc --noEmit, pnpm build, pnpm build-and-test and pnpm audit in a Linux container, plus cargo fmt --check, cargo clippy -D warnings and prettier --check:

Token-2022 Memo Transfer (Pinocchio)
  ✔ Creates a Token-2022 token account with required memo transfers enabled
  ✔ Requires a memo on incoming transfers
2 passing
No known vulnerabilities found

The first test decodes the account with the official Token-2022 codec and checks owner, size, mint, owner and requireIncomingTransferMemos. The second checks that a transfer without a memo is rejected and the same transfer with a memo moves the balance.

AI disclosure

Check exactly one. See CONTRIBUTING.md.

  • No AI tooling was used beyond editor autocomplete.
  • AI tooling was used. Tool and extent: Claude Code helped write the program, the tests and this description; I reviewed the changes and the build and test results.

@MarkFeder
MarkFeder requested a review from dev-jodee as a code owner August 26, 2026 20:13
@greptile-apps

greptile-apps Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The changes stay within a new Token-2022 example and its workspace setup.

Fix the two deployment paths before merging so users can deploy the example after building it.

Findings

  1. P1 Deployment uses the wrong filename ▶

Summary

Adds a Pinocchio example that creates a Token-2022 account with required incoming memos.

  • The Pinocchio example creates Token-2022 accounts that require memos for incoming transfers.

Reviews (3) · Last reviewed commit: "token-2022 memo-transfer pinocchio: test..." · Reviewed by Greptile

@MarkFeder

Copy link
Copy Markdown
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

@MarkFeder

Copy link
Copy Markdown
Contributor Author

@dev-jodee friendly ping, could you review this when you get a chance? CI is green and it's mergeable. Thanks!

@MarkFeder

Copy link
Copy Markdown
Contributor Author

@dev-jodee gentle ping: this has been open since Aug 26 with no review. It's still green and mergeable, and I'm happy to rebase or change anything. These 3 are also what's blocking me from reopening the closed ports under the 3-PR limit. Thanks!

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.
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.
@MarkFeder
MarkFeder force-pushed the tokens-token-2022-memo-transfer-pinocchio branch from 80a66da to 1778ffb Compare November 4, 2026 18:21
@github-actions github-actions Bot added the needs-issue PR does not reference an issue a maintainer has accepted label Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Hi @MarkFeder,

Thanks for the pull request. We ask that every change references an issue a maintainer has accepted, and there isn't one linked here.

These examples are a teaching resource and each one has to stay small enough to read in one sitting, so whether a new example or framework flavor belongs here is worth settling before anyone writes it. Agreeing on the approach in an issue first means nobody writes code that can't be merged. See CONTRIBUTING.md for the full workflow.

Please open an issue describing the change, or comment on the existing one. Once a maintainer has labelled it accepted, put Fixes #<issue> in this description and reopen this pull request; the check runs again and clears itself. Typos, broken links and comment-only fixes are exempt: write Linked issue: trivial instead.

@github-actions github-actions Bot closed this Nov 4, 2026
# Run this bad boy with "bash cicd.sh" or "./cicd.sh"

cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./program/target/so
solana program deploy ./program/target/so/program.so

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Deployment uses the wrong filename

Both deployment commands point to program.so, but this crate builds as token_2022_memo_transfer_pinocchio_program.so. After a clean build, bash cicd.sh and the deploy script in package.json fail because the named file does not exist. Update both commands to use the built filename.

@MarkFeder

Copy link
Copy Markdown
Contributor Author

Superseded by #792 (the bot closed this one and GitHub won't let me reopen it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-issue PR does not reference an issue a maintainer has accepted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

token-2022/memo-transfer: add a Pinocchio version

1 participant