ERC20CappedUpgradeable.sol 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. __Context_init_unchained();
  17. __ERC20Capped_init_unchained(cap_);
  18. }
  19. function __ERC20Capped_init_unchained(uint256 cap_) internal onlyInitializing {
  20. require(cap_ > 0, "ERC20Capped: cap is 0");
  21. _cap = cap_;
  22. }
  23. /**
  24. * @dev Returns the cap on the token's total supply.
  25. */
  26. function cap() public view virtual returns (uint256) {
  27. return _cap;
  28. }
  29. /**
  30. * @dev See {ERC20-_mint}.
  31. */
  32. function _mint(address account, uint256 amount) internal virtual override {
  33. require(ERC20Upgradeable.totalSupply() + amount <= cap(), "ERC20Capped: cap exceeded");
  34. super._mint(account, amount);
  35. }
  36. uint256[50] private __gap;
  37. }