ERC20Capped.sol 822 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. pragma solidity ^0.4.24;
  2. import "./ERC20Mintable.sol";
  3. /**
  4. * @title Capped token
  5. * @dev Mintable token with a token cap.
  6. */
  7. contract ERC20Capped is ERC20Mintable {
  8. uint256 private cap_;
  9. constructor(uint256 _cap) public {
  10. require(_cap > 0);
  11. cap_ = _cap;
  12. }
  13. /**
  14. * @return the cap for the token minting.
  15. */
  16. function cap() public view returns(uint256) {
  17. return cap_;
  18. }
  19. /**
  20. * @dev Function to mint tokens
  21. * @param _to The address that will receive the minted tokens.
  22. * @param _amount The amount of tokens to mint.
  23. * @return A boolean that indicates if the operation was successful.
  24. */
  25. function mint(
  26. address _to,
  27. uint256 _amount
  28. )
  29. public
  30. returns (bool)
  31. {
  32. require(totalSupply().add(_amount) <= cap_);
  33. return super.mint(_to, _amount);
  34. }
  35. }