Optimize implementation of ERC20Capped (#2524)
(cherry picked from commit 36b855972b)
This commit is contained in:
committed by
Francisco Giordano
parent
d5f4862405
commit
15214a53ce
@ -14,6 +14,7 @@
|
|||||||
* `AccessControl`: removed enumerability by default for a more lightweight contract. It is now opt-in through `AccessControlEnumerable`. ([#2512](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2512))
|
* `AccessControl`: removed enumerability by default for a more lightweight contract. It is now opt-in through `AccessControlEnumerable`. ([#2512](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2512))
|
||||||
* Meta Transactions: add `ERC2771Context` and a `MinimalForwarder` for meta-transactions. ([#2508](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2508))
|
* Meta Transactions: add `ERC2771Context` and a `MinimalForwarder` for meta-transactions. ([#2508](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2508))
|
||||||
* Overall reorganisation of the contract folder to improve clarity and discoverability. ([#2503](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2503))
|
* Overall reorganisation of the contract folder to improve clarity and discoverability. ([#2503](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2503))
|
||||||
|
* `ERC20Capped`: optimize gas usage of by enforcing te check directly in `_mint`. ([#2524](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2524))
|
||||||
|
|
||||||
### How to upgrade from 3.x
|
### How to upgrade from 3.x
|
||||||
|
|
||||||
|
|||||||
@ -27,17 +27,10 @@ abstract contract ERC20Capped is ERC20 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev See {ERC20-_beforeTokenTransfer}.
|
* @dev See {ERC20-_mint}.
|
||||||
*
|
|
||||||
* Requirements:
|
|
||||||
*
|
|
||||||
* - minted tokens must not cause the total supply to go over the cap.
|
|
||||||
*/
|
*/
|
||||||
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override {
|
function _mint(address account, uint256 amount) internal virtual override {
|
||||||
super._beforeTokenTransfer(from, to, amount);
|
require(ERC20.totalSupply() + amount <= cap(), "ERC20Capped: cap exceeded");
|
||||||
|
super._mint(account, amount);
|
||||||
if (from == address(0)) { // When minting tokens
|
|
||||||
require(totalSupply() + amount <= cap(), "ERC20Capped: cap exceeded");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user