ERC20Capped.sol [Code Snippet]
Enforces a fixed maximum token supply.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../ERC20.sol";
abstract contract ERC20Capped is ERC20 {
uint256 private immutable _cap;
constructor(uint256 cap_) {
require(cap_ > 0, "ERC20Capped: cap is 0");
_cap = cap_;
}
function cap() public view returns (uint256) {
return _cap;
}
// Override _mint to enforce the cap.
function _mint(address account, uint256 amount) internal virtual {
require(totalSupply() + amount <= _cap, "ERC20Capped: cap exceeded");
// Call parent _mint function (not shown here)
}
}