1+ // SPDX-License-Identifier: Apache-2.0
2+
3+ // Disclaimer: This library provides functions for working with storage rent. Although it is production ready,
4+ // it has not been audited for security, so use it at your own risk.
5+
6+ // This is the Solidity version of the rust module rent:
7+ // https://github.com/solana-labs/solana/blob/master/sdk/program/src/rent.rs
8+ // As rent is currently not implemented on Solana, only the minimum balance is required.
9+
10+ /// Default rental rate in lamports/byte-year.
11+ ///
12+ /// This calculation is based on:
13+ /// - 10^9 lamports per SOL
14+ /// - $1 per SOL
15+ /// - $0.01 per megabyte day
16+ /// - $3.65 per megabyte year
17+ uint64 constant DEFAULT_LAMPORTS_PER_BYTE_YEAR = 1_000_000_000 / 100 * 365 / (1024 * 1024);
18+
19+ /// Default amount of time (in years) the balance has to include rent for the
20+ /// account to be rent exempt.
21+ uint64 constant DEFAULT_EXEMPTION_THRESHOLD = 2;
22+
23+ /// Account storage overhead for calculation of base rent.
24+ ///
25+ /// This is the number of bytes required to store an account with no data. It is
26+ /// added to an accounts data length when calculating [`Rent::minimum_balance`].
27+ uint64 constant ACCOUNT_STORAGE_OVERHEAD = 128;
28+
29+ /// Minimum balance due for rent-exemption of a given account data size.
30+ function minimum_balance(uint64 data_len) pure returns (uint64) {
31+ return ((ACCOUNT_STORAGE_OVERHEAD + data_len) * DEFAULT_LAMPORTS_PER_BYTE_YEAR)
32+ * DEFAULT_EXEMPTION_THRESHOLD;
33+ }
0 commit comments