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 snapshot calculation using the launch-era constants (lamports_per_byte_year = 3480,exemption_threshold = 2 years,account_storage_overhead = 128 bytes). It is useful for host tests and fixed-config calculations, but is not authoritative after an on-chain rent reprice. -
check_rent_exempt- the runtime guard backing the#[account(rent_exempt = enforce)]field keyword emitted by#[hopper::context]. Comparesaccount.lamports()to the live Rent sysvar minimum and returnsProgramError::AccountNotRentExempt(a builtin variant mapping to Solana’s canonical code) on failure.
The enforcement path deliberately reads sol_get_rent_sysvar. Rent is a
runtime-owned parameter, so a safety gate must fail closed if that read
fails rather than accepting an account against stale constants.
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-derive. - minimum_
balance - Minimum lamport balance for an account with
data_lenbytes of data under Solana’s launch-era rent snapshot. - minimum_
balance_ live - Rent-exempt minimum read from the live Rent sysvar on-chain. Host tests use the compile-time snapshot because no runtime sysvar exists.