---description: Add rent-free accounts to a Pinocchio DeFi programallowed-tools: Bash, Read, Write, Edit, Glob, Grep, WebFetch, AskUserQuestion, Task, TaskCreate, TaskGet, TaskList, TaskUpdate, TaskOutput, mcp__deepwiki, mcp__zkcompression---## Add rent-free accounts to a Pinocchio DeFi programContext:- Guide: https://zkcompression.com/light-token/defi/programs-pinocchio- Skills and resources index: https://zkcompression.com/skill.md- Dedicated skill: https://github.com/Lightprotocol/skills/tree/main/skills/light-sdk- Crates: light-account-pinocchio (features: token, std), light-token-pinocchio, pinocchio- Swap reference: https://github.com/Lightprotocol/examples-light-token/tree/simplify-trait/pinocchio/swapKey macros/APIs: LightPinocchioAccount, LightProgramPinocchio, CreateTokenAccountCpi, derive_light_cpi_signer!### 1. Index project- Grep `pinocchio|entrypoint!|ProgramError|AccountInfo|process_instruction` across src/- Glob `**/*.rs` and `**/Cargo.toml` for project structure- Identify: existing program module, account structs, PDA seeds, token accounts, init instructions- Read Cargo.toml — note existing dependencies and framework version- Task subagent (Grep/Read/WebFetch) if project has multiple crates to scan in parallel### 2. Read references- WebFetch the guide above- WebFetch skill.md — check for a dedicated skill and resources matching this task- TaskCreate one todo per phase below to track progress### 3. Clarify intention- AskUserQuestion: what is the goal? (new program from scratch, migrate existing program to rent-free, add rent-free accounts to specific instructions)- AskUserQuestion: which account types need to be rent-free? (PDAs, token accounts, ATAs, mints)- Summarize findings and wait for user confirmation before implementing### 4. Create plan- Based on steps 1–3, draft an implementation plan- Follow the guide's step order: Dependencies → State Struct → Program Enum → Entrypoint → Init Handler- Identify which existing structs need changes (CompressionInfo field, LightPinocchioAccount derive, etc.)- If anything is unclear or ambiguous, loop back to step 3 (AskUserQuestion)- Present the plan to the user for approval before proceeding### 5. Implement- Add deps if missing: Bash `cargo add light-account-pinocchio@0.20 --features token,std` and `cargo add light-token-pinocchio@0.20` and `cargo add pinocchio@0.9`- Follow the guide and the approved plan- Write/Edit to create or modify files- TaskUpdate to mark each step done### 6. Verify- Bash `cargo build-sbf`- Bash `cargo test-sbf` if tests exist- TaskUpdate to mark complete### Tools- mcp__zkcompression__SearchLightProtocol("<query>") for API details- mcp__deepwiki__ask_question("Lightprotocol/light-protocol", "<q>") for architecture- Task subagent with Grep/Read/WebFetch for parallel lookups- TaskList to check remaining work
The SDK pays the rent-exemption cost. After extended inactivity, cold accounts auto-compress. Your program only ever
interacts with hot accounts. Clients can safely load cold accounts back into the
onchain Solana account space when needed via create_load_instructions.Under the hood, clients use AccountInterface - a superset of Solana’s
Account that unifies hot and cold state. See Router Integration
for details.
Do I have to manually handle compression/decompression?
No. LightProgramPinocchio generates the handlers. Simply add the generated handlers to your entrypoint, and update your init instruction.
How does it prevent re-init attacks?
When creating an
account for the first time, the SDK provides a proof that the account doesn’t
exist in the cold address space. The SVM already verifies this for the onchain
space. Both address spaces are checked before creation, preventing re-init
attacks, even if the account is currently cold.
Who triggers compression?
Miners (Forester nodes) compress accounts that have been inactive for an extended period of time (when their virtual rent balance drops below threshold).
In practice, having to load cold accounts should be rare. The common path (hot) has no extra overhead and does not increase CU or txn size.
How is the SDK able to sponsor rent exemption?
When accounts compress after extended inactivity, the on-chain rent-exemption is released back
to the rent sponsor. This creates a revolving lifecycle: active “hot” accounts hold a
rent-exempt lamports balance, inactive “cold” accounts release it back. The
rent sponsor must be derived from the program owner. For all mint, ATA, and
token accounts, the Light Token Program is the rent sponsor. For your own program-owned PDAs, the SDK derives a rent sponsor address automatically.
Do rent-free accounts increase CU?
Hot path (e.g. swap, deposit, withdraw): No. Active accounts do not add CU overhead to your instructions.First time init + loading cold accounts: Yes, adds up to 15k-400k CU,
depending on number and type of accounts being initialized or loaded.
API is in Beta and subject to change.Questions or need hands-on support? Telegram | email | Discord