minimum_balance.sol 1.4 KB

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