Add Token-2022 default-account-state Pinocchio example - #652
Conversation
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.
Greptile SummaryAdds a Pinocchio implementation of the Token-2022 default-account-state example.
Confidence Score: 5/5The 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
Sequence DiagramsequenceDiagram
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
Reviews (1): Last reviewed commit: "token-2022 default-account-state: add pi..." | Re-trigger Greptile |
|
Still want this one. Heads up though — #656 changed the ground rules: pinocchio is 0.11 (workspace deps), and tests are mocha+tsx with |
What
Adds a Pinocchio implementation of the Token-2022
default-account-stateexample, alongside the existinganchorandnativeversions. This continues the Token-2022 Pinocchio sub-series (aftermint-close-authority#624 andnon-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
DefaultAccountStateextension. New token accounts for the mint inherit this default state, so aFrozendefault requires the freeze authority to thaw each account before use.To exercise both extension instructions (mirroring the
nativeexample), the program hand-rolls twoDefaultAccountStateExtension(variant28) CPIs aroundInitializeMint:Initializethe default state toFrozen— beforeInitializeMint(extensions must be initialized before the mint).Updatethe default state toInitialized— afterInitializeMint, 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
AccountStatebyte).Test
litesvm+@solana/kit. The test builds the mint, then decodes it with the official@solana-program/token-2022codec and asserts:decimals, andDefaultAccountStateextension's stored state isInitialized.Verified locally:
cargo build-sbf,ts-mocha,tsc --noEmit, biome,cargo fmt --check, clippy, andpnpm install --frozen-lockfileall clean.