What Changes
| Area | Change |
|---|---|
| State struct | Derive LightAccount and add a compression_info: Option<CompressionInfo> field |
| Accounts | Derive LightAccounts and add #[light_account] on init accounts |
| Program module | Add #[light_program] on top of #[program] |
| Instructions (swap, deposit, withdraw, …) | No changes |
You can find a complete rent-free AMM reference implementation here.
Step 1: Dependencies
Step 2: State Struct
Addcompression_info field and derive LightAccount:
Step 3: Program
Add#[light_program] above #[program]:
Step 4: Accounts Struct
DeriveLightAccounts on your Accounts struct and add #[light_account(...)] next to #[account(...)].
- PDAs
- Token Account
- Associated Token Account (ATA)
- Mint
Full Accounts Struct
Full Accounts Struct
We also need to add
light_token_interface_config, rent_sponsor, and light_token_cpi_authority.Step 5: Instructions
Replacespl_token with light_token instructions as you need. The API is a superset of SPL-token so switching is straightforward.
Examples include: MintToCpi, TransferCpi, TransferInterfaceCpi,
CreateTokenAccountCpi, and CreateTokenAtaCpi.
Example: Initialize
Example: Initialize
Client SDK
To make it easy for clients to integrate with your program, ship an SDK crate implementing theLightProgramInterface trait.
For a detailed example of how clients use this trait, check out the Router Integration page.
Example: Trait Implementation
Example: Trait Implementation
| Resource | Link |
|---|---|
| Trait Implementation Example | CpSwapSdk |
Testing
Example: Integration Test
Example: Integration Test
| Resource | Link |
|---|---|
| Test example | program.rs |
How it works
The SDK pays the rent-exemption cost. Inactive (cold) accounts auto-compress. Your program only ever interacts with hot accounts. Clients can load cold accounts back when needed viacreate_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.
| Hot (active) | Cold (inactive) | |
|---|---|---|
| Storage | On-chain | Compressed |
| Latency/CU | No change | +load instruction |
| Your program code | No change | No change |
Existing programs
If you have an existing program that you would like to migrate to rent-free accounts, join our tech Discord for migration support.FAQ
How does it prevent re-init attacks?
How does it prevent re-init attacks?
When
you create an account, under the hood, the SDK auto-provides a proof that
verifies that the account does not yet exist in the compressed address space.
The SVM takes care of uniqueness in the onchain space. This way both account
spaces are covered, preventing re-init attacks.
Who triggers compression?
Who triggers compression?
Miners automatically compress when
virtual rent is below threshold (eg 24h without write bump).
Can active pools get compressed?
Can active pools get compressed?
No. Any write bumps the virtual rent balance. Active pools never compress.
Do I need to run infrastructure?
Do I need to run infrastructure?
No. Helius and Triton run the Interface RPC endpoints, self-hosting optional.
What if indexer is down?
What if indexer is down?
Hot pools work normally. Cold pools can’t load until recovery. No data or safety loss.