You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.4 KiB
56 lines
1.4 KiB
// SPDX-License-Identifier: MIT
|
|
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/ERC20Capped.sol)
|
|
|
|
pragma solidity ^0.8.19;
|
|
|
|
import "../ERC20.sol";
|
|
|
|
/**
|
|
* @dev Extension of {ERC20} that adds a cap to the supply of tokens.
|
|
*/
|
|
abstract contract ERC20Capped is ERC20 {
|
|
uint256 private immutable _cap;
|
|
|
|
/**
|
|
* @dev Total supply cap has been exceeded.
|
|
*/
|
|
error ERC20ExceededCap(uint256 increasedSupply, uint256 cap);
|
|
|
|
/**
|
|
* @dev The supplied cap is not a valid cap.
|
|
*/
|
|
error ERC20InvalidCap(uint256 cap);
|
|
|
|
/**
|
|
* @dev Sets the value of the `cap`. This value is immutable, it can only be
|
|
* set once during construction.
|
|
*/
|
|
constructor(uint256 cap_) {
|
|
if (cap_ == 0) {
|
|
revert ERC20InvalidCap(0);
|
|
}
|
|
_cap = cap_;
|
|
}
|
|
|
|
/**
|
|
* @dev Returns the cap on the token's total supply.
|
|
*/
|
|
function cap() public view virtual returns (uint256) {
|
|
return _cap;
|
|
}
|
|
|
|
/**
|
|
* @dev See {ERC20-_update}.
|
|
*/
|
|
function _update(address from, address to, uint256 amount) internal virtual override {
|
|
super._update(from, to, amount);
|
|
|
|
if (from == address(0)) {
|
|
uint256 maxSupply = cap();
|
|
uint256 supply = totalSupply();
|
|
if (supply > maxSupply) {
|
|
revert ERC20ExceededCap(supply, maxSupply);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|