Skip to content

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

Open
MarkFeder wants to merge 1 commit 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 1 commit 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.

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.
@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

Greptile Summary

Adds a Pinocchio implementation of the Token-2022 default-account-state example.

  • Creates and funds an extended Token-2022 mint account.
  • Initializes the default account state as Frozen before mint initialization, then updates it to Initialized using the freeze authority.
  • Adds LiteSVM coverage, package configuration, CI scripts, and root Cargo workspace registration.

Confidence Score: 5/5

The PR appears safe to merge with no actionable correctness or security defects identified.

The program preserves Token-2022's required initialization ordering, uses the documented shared payer and authority account relationship, and the integration test validates the resulting mint and extension state.

Important Files Changed

Filename Overview
tokens/token-2022/default-account-state/pinocchio/program/src/instructions/create_mint.rs Implements mint allocation and correctly orders the hand-built Token-2022 extension, mint initialization, and authority-signed update CPIs.
tokens/token-2022/default-account-state/pinocchio/program/src/processor.rs Routes the program's single discriminator-free instruction directly to the mint creation handler.
tokens/token-2022/default-account-state/pinocchio/tests/test.ts Exercises mint creation in LiteSVM and verifies ownership, allocation size, decimals, and the decoded extension state.
tokens/token-2022/default-account-state/pinocchio/package.json Adds the standard build, deployment, and test scripts with a frozen per-example dependency lockfile.
Cargo.toml Registers the new program crate in the root Rust workspace.

Sequence Diagram

sequenceDiagram
  participant Client
  participant Example as Pinocchio Program
  participant System as System Program
  participant Token as Token-2022
  Client->>Example: CreateMint(decimals)
  Example->>System: Create 171-byte mint account
  Example->>Token: Initialize DefaultAccountState(Frozen)
  Example->>Token: InitializeMint(authority, freeze authority)
  Example->>Token: Update DefaultAccountState(Initialized)
  Token-->>Example: Mint configured
  Example-->>Client: Success
Loading

Reviews (1): Last reviewed commit: "token-2022 default-account-state: add pi..." | Re-trigger Greptile

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.

1 participant