Skip to main content

Module rent

Module rent 

Source
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:

  1. 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.

  2. check_rent_exempt - the runtime guard backing the #[account(rent_exempt = enforce)] field keyword emitted by #[hopper::context]. Compares account.lamports() to the live Rent sysvar minimum and returns ProgramError::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 account holds enough lamports to be rent-exempt for its current data length. Used by the #[account(rent_exempt = enforce)] constraint lowering in hopper-derive.
minimum_balance
Minimum lamport balance for an account with data_len bytes 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.