Remove hooks from ERC20 (#3838)

Co-authored-by: Francisco <frangio.1@gmail.com>
This commit is contained in:
JulissaDantes
2022-12-14 14:43:45 -05:00
committed by GitHub
parent e2d2ebc8fc
commit 3c80a42866
10 changed files with 121 additions and 150 deletions

View File

@ -28,10 +28,17 @@ abstract contract ERC20Capped is ERC20 {
}
/**
* @dev See {ERC20-_mint}.
* @dev See {ERC20-_transfer}.
*/
function _mint(address account, uint256 amount) internal virtual override {
require(ERC20.totalSupply() + amount <= cap(), "ERC20Capped: cap exceeded");
super._mint(account, amount);
function _update(
address from,
address to,
uint256 amount
) internal virtual override {
if (from == address(0)) {
require(ERC20.totalSupply() + amount <= cap(), "ERC20Capped: cap exceeded");
}
super._update(from, to, amount);
}
}

View File

@ -15,19 +15,18 @@ import "../../../security/Pausable.sol";
*/
abstract contract ERC20Pausable is ERC20, Pausable {
/**
* @dev See {ERC20-_beforeTokenTransfer}.
* @dev See {ERC20-_update}.
*
* Requirements:
*
* - the contract must not be paused.
*/
function _beforeTokenTransfer(
function _update(
address from,
address to,
uint256 amount
) internal virtual override {
super._beforeTokenTransfer(from, to, amount);
require(!paused(), "ERC20Pausable: token transfer while paused");
super._update(from, to, amount);
}
}

View File

@ -118,15 +118,13 @@ abstract contract ERC20Snapshot is ERC20 {
return snapshotted ? value : totalSupply();
}
// Update balance and/or total supply snapshots before the values are modified. This is implemented
// in the _beforeTokenTransfer hook, which is executed for _mint, _burn, and _transfer operations.
function _beforeTokenTransfer(
// Update balance and/or total supply snapshots before the values are modified. This is executed
// for _mint, _burn, and _transfer operations.
function _update(
address from,
address to,
uint256 amount
) internal virtual override {
super._beforeTokenTransfer(from, to, amount);
if (from == address(0)) {
// mint
_updateAccountSnapshot(to);
@ -140,6 +138,7 @@ abstract contract ERC20Snapshot is ERC20 {
_updateAccountSnapshot(from);
_updateAccountSnapshot(to);
}
super._update(from, to, amount);
}
function _valueAt(uint256 snapshotId, Snapshots storage snapshots) private view returns (bool, uint256) {

View File

@ -35,13 +35,16 @@ abstract contract ERC20Votes is ERC20, Votes {
*
* Emits a {IVotes-DelegateVotesChanged} event.
*/
function _afterTokenTransfer(
function _update(
address from,
address to,
uint256 amount
) internal virtual override {
super._update(from, to, amount);
if (from == address(0)) {
require(totalSupply() <= _maxSupply(), "ERC20Votes: total supply risks overflowing votes");
}
_transferVotingUnits(from, to, amount);
super._afterTokenTransfer(from, to, amount);
}
/**
@ -64,12 +67,4 @@ abstract contract ERC20Votes is ERC20, Votes {
function _getVotingUnits(address account) internal view virtual override returns (uint256) {
return balanceOf(account);
}
/**
* @dev Snapshots the totalSupply after it has been increased.
*/
function _mint(address account, uint256 amount) internal virtual override {
super._mint(account, amount);
require(totalSupply() <= _maxSupply(), "ERC20Votes: total supply risks overflowing votes");
}
}