ERC20Capped.sol 957 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. pragma solidity ^0.5.0;
  2. import "./ERC20Mintable.sol";
  3. /**
  4. * @dev Extension of `ERC20Mintable` that adds a cap to the supply of tokens.
  5. */
  6. contract ERC20Capped is ERC20Mintable {
  7. uint256 private _cap;
  8. /**
  9. * @dev Sets the value of the `cap`. This value is immutable, it can only be
  10. * set once during construction.
  11. */
  12. constructor (uint256 cap) public {
  13. require(cap > 0, "ERC20Capped: cap is 0");
  14. _cap = cap;
  15. }
  16. /**
  17. * @dev Returns the cap on the token's total supply.
  18. */
  19. function cap() public view returns (uint256) {
  20. return _cap;
  21. }
  22. /**
  23. * @dev See `ERC20Mintable.mint`.
  24. *
  25. * Requirements:
  26. *
  27. * - `value` must not cause the total supply to go over the cap.
  28. */
  29. function _mint(address account, uint256 value) internal {
  30. require(totalSupply().add(value) <= _cap, "ERC20Capped: cap exceeded");
  31. super._mint(account, value);
  32. }
  33. }