Skip to content

Add Token-2022 default-account-state Pinocchio example - #652

Open
MarkFeder wants to merge 3 commits into
solana-foundation:mainfrom
MarkFeder:tokens-token-2022-default-account-state-pinocchio
Open

Add Token-2022 default-account-state Pinocchio example#652
MarkFeder wants to merge 3 commits into
solana-foundation:mainfrom
MarkFeder:tokens-token-2022-default-account-state-pinocchio

Conversation

@MarkFeder

Copy link
Copy Markdown
Contributor

What

Adds a Pinocchio implementation of the Token-2022 default-account-state example, alongside the existing anchor and native versions. This continues the Token-2022 Pinocchio sub-series (after mint-close-authority #624 and non-transferable #630) and follows the same kit + litesvm + official-@solana-program-packages template.

How it works

The single instruction creates a Token-2022 mint carrying the DefaultAccountState extension. New token accounts for the mint inherit this default state, so a Frozen default requires the freeze authority to thaw each account before use.

To exercise both extension instructions (mirroring the native example), the program hand-rolls two DefaultAccountStateExtension (variant 28) CPIs around InitializeMint:

  1. Initialize the default state to Frozenbefore InitializeMint (extensions must be initialized before the mint).
  2. Update the default state to Initializedafter InitializeMint, signed by the mint's freeze authority.

The mint authority doubles as the freeze authority and is supplied as the same key as the payer, so a single signature covers funding the account and signing the update. The extended mint is 171 bytes (base 166 + a 5-byte TLV entry whose value is a single AccountState byte).

Test

litesvm + @solana/kit. The test builds the mint, then decodes it with the official @solana-program/token-2022 codec and asserts:

  • the account is owned by Token-2022 and sized to 171 bytes,
  • the decoded decimals, and
  • the DefaultAccountState extension's stored state is Initialized.
Token-2022 Default Account State (Pinocchio)
  ✔ Creates a Token-2022 mint with a default account state
1 passing

Verified locally: cargo build-sbf, ts-mocha, tsc --noEmit, biome, cargo fmt --check, clippy, and pnpm install --frozen-lockfile all clean.

@MarkFeder
MarkFeder requested a review from dev-jodee as a code owner July 26, 2026 16:19
@greptile-apps

greptile-apps Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR adds a Pinocchio implementation of the Token-2022 default-account-state example.

  • Creates and funds a 171-byte Token-2022 mint account.
  • Initializes the default state as Frozen before mint initialization, then updates it to Initialized using the freeze authority.
  • Adds a LiteSVM integration test, independent package configuration, and root Cargo workspace registration.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
tokens/token-2022/default-account-state/pinocchio/program/src/instructions/create_mint.rs Implements account creation and the ordered Token-2022 extension, mint-initialization, and authority-signed update CPIs.
tokens/token-2022/default-account-state/pinocchio/program/src/instructions/mod.rs Defines the Token-2022 program ID, extended mint size, and one-byte instruction argument parser.
tokens/token-2022/default-account-state/pinocchio/program/src/processor.rs Routes the program's sole instruction directly to the mint-creation handler.
tokens/token-2022/default-account-state/pinocchio/tests/test.ts Exercises the program in LiteSVM and verifies ownership, account length, decimals, and the final decoded extension state.
tokens/token-2022/default-account-state/pinocchio/package.json Adds the standard independent build, deployment, and LiteSVM test configuration for the example.
Cargo.toml Registers the new Pinocchio program as a root Rust workspace member.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Example as Pinocchio Program
    participant System as System Program
    participant Token as Token-2022

    Client->>Example: Create mint(decimals, mint, authority/payer)
    Example->>System: CreateAccount(171 bytes, Token-2022 owner)
    System-->>Example: Mint account created
    Example->>Token: InitializeDefaultAccountState(Frozen)
    Token-->>Example: Extension initialized
    Example->>Token: InitializeMint(decimals, authority, freeze authority)
    Token-->>Example: Mint initialized
    Example->>Token: UpdateDefaultAccountState(Initialized)
    Token-->>Example: Default state updated
    Example-->>Client: Success
Loading

Reviews (3): Last reviewed commit: "token-2022 default-account-state pinocch..." | Re-trigger Greptile

@dev-jodee

Copy link
Copy Markdown
Collaborator

Still want this one. Heads up though — #656 changed the ground rules: pinocchio is 0.11 (workspace deps), and tests are mocha+tsx with @solana/kit + litesvm 1.x now. tokens/token-2022/non-transferable/pinocchio shows the current pattern, AGENTS.md has the rest. Rebase when you get a chance and I'll review.

MarkFeder and others added 2 commits August 5, 2026 10:34
Ports the default-account-state Token-2022 example to Pinocchio, matching
the mint-close-authority template (kit + litesvm, official @solana-program
packages, real Rent::get()).

The program hand-rolls two DefaultAccountStateExtension (variant 28) CPIs
around InitializeMint: it initializes the default state to Frozen before the
mint is initialized, then updates it to Initialized afterwards (which the
freeze authority signs). Mint size is 171 bytes (one 1-byte AccountState TLV
value). The litesvm test decodes the mint with the official Token-2022 codec
and asserts the stored default state is Initialized.
… + prettier

Rebased onto main (pinocchio 0.10 -> 0.11): handlers take &mut [AccountView]
and CPI account-infos are passed as copies. Also apply prettier formatting to
test.ts and tsconfig.json to satisfy the repo's Prettier check.
@MarkFeder
MarkFeder force-pushed the tokens-token-2022-default-account-state-pinocchio branch from 8b3cb5f to 53f4ff6 Compare August 5, 2026 08:38
…a+tsx

Per solana-foundation#656 / AGENTS.md 'do not deviate' rule: replace ts-mocha with
'mocha --import=tsx', bump @solana/kit to ^7 and the mocha/chai/tsx/types
devDeps to match the token-2022/non-transferable reference, and align tsconfig.
Regenerated pnpm-lock.yaml. Verified: tsc --noEmit clean and 'pnpm build-and-test'
passes on the litesvm path.
@MarkFeder

Copy link
Copy Markdown
Contributor Author

Rebased onto main and updated per your #656 heads-up:

  • pinocchio 0.11 (workspace deps): handlers now take &mut [AccountView] and CPI account-infos are passed as copies.
  • Test stack aligned to the non-transferable pattern: mocha --import=tsx (dropped ts-mocha), @solana/kit ^7, litesvm 1.x, updated tsconfig, regenerated pnpm-lock.yaml.

Verified locally on the litesvm path: cargo build-sbf + pnpm build-and-test passes (1 passing), tsc --noEmit clean, and clippy/rustfmt/prettier clean. Ready for review.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants