minimum_balance.sol 1.4 KB

1234567891011121314151617181920212223242526272829303132
  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 needs in rent to be rent exempt.
  16. uint64 constant DEFAULT_EXEMPTION_THRESHOLD = 2;
  17. /// Account storage overhead for calculation of base rent.
  18. ///
  19. /// This is the number of bytes required to store an account with no data. It is
  20. /// added to an account's data length when calculating [`Rent::minimum_balance`].
  21. uint64 constant ACCOUNT_STORAGE_OVERHEAD = 128;
  22. /// Minimum balance due for rent-exemption of a given account data size.
  23. function minimum_balance(uint64 data_len) pure returns (uint64) {
  24. return ((ACCOUNT_STORAGE_OVERHEAD + data_len) * DEFAULT_LAMPORTS_PER_BYTE_YEAR)
  25. * DEFAULT_EXEMPTION_THRESHOLD;
  26. }