Expand description
Rent-exemption helpers.
Solana’s rent model charges accounts for storage on a per-byte-year
basis. An account that holds at least
(data_len + ACCOUNT_STORAGE_OVERHEAD) * LAMPORTS_PER_BYTE_YEAR * EXEMPTION_THRESHOLD lamports is rent-exempt and never loses
balance to rent collection.
This module exposes two things:
-
minimum_balance— a pure function computing the rent-exempt threshold for a givendata_len, using the cluster constants that have been in effect on Solana mainnet since launch (lamports_per_byte_year = 3480,exemption_threshold = 2 years,account_storage_overhead = 128 bytes). These values are governed on-chain but have never been changed. If the cluster ever re-governs them, the check will be conservative (strictly requiring at least the pre-governance threshold) — still safe, just not tight. -
check_rent_exempt— the runtime guard backing the#[account(rent_exempt = enforce)]field keyword emitted by#[hopper::context]. Comparesaccount.lamports()tominimum_balance(account.data_len())and returnsProgramError::AccountNotRentExempt(Solana’s canonical error code, routed throughProgramError::Custom) on failure.
§Why not use sol_get_rent_sysvar?
The syscall is ~100 CU and returns the same values this module hard-codes. Using the constants inline lets the check run at zero additional CU beyond the comparison. Programs that need to read the live Rent sysvar for other reasons (rent-collection scheduling, etc.) can still invoke the syscall directly; this helper is specifically for the rent-exemption gate where the constants suffice.
Constants§
- ACCOUNT_
STORAGE_ OVERHEAD - Fixed per-account storage overhead the cluster charges on top of user data. 128 bytes (header + metadata).
- EXEMPTION_
THRESHOLD_ YEARS - Years of rent an account must prepay to be exempt.
- LAMPORTS_
PER_ BYTE_ YEAR - Lamports charged per byte of account storage per year.
Functions§
- check_
rent_ exempt - Assert that
accountholds enough lamports to be rent-exempt for its current data length. Used by the#[account(rent_exempt = enforce)]constraint lowering inhopper-macros-proc. - minimum_
balance - Minimum lamport balance for an account with
data_lenbytes of data to be rent-exempt under the current Solana cluster constants.