Optimize implementation of ERC20Capped (#2524)
(cherry picked from commit 36b855972b)
This commit is contained in:
committed by
Francisco Giordano
parent
d5f4862405
commit
15214a53ce
@ -27,17 +27,10 @@ abstract contract ERC20Capped is ERC20 {
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {ERC20-_beforeTokenTransfer}.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - minted tokens must not cause the total supply to go over the cap.
|
||||
* @dev See {ERC20-_mint}.
|
||||
*/
|
||||
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override {
|
||||
super._beforeTokenTransfer(from, to, amount);
|
||||
|
||||
if (from == address(0)) { // When minting tokens
|
||||
require(totalSupply() + amount <= cap(), "ERC20Capped: cap exceeded");
|
||||
}
|
||||
function _mint(address account, uint256 amount) internal virtual override {
|
||||
require(ERC20.totalSupply() + amount <= cap(), "ERC20Capped: cap exceeded");
|
||||
super._mint(account, amount);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user