ERC20CappedUpgradeable.sol 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/ERC20Capped.sol)
  3. pragma solidity ^0.8.0;
  4. import "../ERC20Upgradeable.sol";
  5. import "../../../proxy/utils/Initializable.sol";
  6. /**
  7. * @dev Extension of {ERC20} that adds a cap to the supply of tokens.
  8. */
  9. abstract contract ERC20CappedUpgradeable is Initializable, ERC20Upgradeable {
  10. uint256 private _cap;
  11. /**
  12. * @dev Sets the value of the `cap`. This value is immutable, it can only be
  13. * set once during construction.
  14. */
  15. function __ERC20Capped_init(uint256 cap_) internal onlyInitializing {
  16. __ERC20Capped_init_unchained(cap_);
  17. }
  18. function __ERC20Capped_init_unchained(uint256 cap_) internal onlyInitializing {
  19. require(cap_ > 0, "ERC20Capped: cap is 0");
  20. _cap = cap_;
  21. }
  22. /**
  23. * @dev Returns the cap on the token's total supply.
  24. */
  25. function cap() public view virtual returns (uint256) {
  26. return _cap;
  27. }
  28. /**
  29. * @dev See {ERC20-_mint}.
  30. */
  31. function _mint(address account, uint256 amount) internal virtual override {
  32. require(ERC20Upgradeable.totalSupply() + amount <= cap(), "ERC20Capped: cap exceeded");
  33. super._mint(account, amount);
  34. }
  35. /**
  36. * This empty reserved space is put in place to allow future versions to add new
  37. * variables without shifting down storage in the inheritance chain.
  38. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
  39. */
  40. uint256[50] private __gap;
  41. }