Simplification of ERC777's transfer & transferFrom by using _send (#3128)

* Update ERC777.sol

* Update ERC777.sol

* Update ERC777.sol

* Update ERC777.sol

* fix revert reasons

Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
This commit is contained in:
Kevin Upton
2022-01-26 00:56:13 +11:00
committed by GitHub
parent a5e042cedf
commit e298476a90

View File

@ -144,16 +144,7 @@ contract ERC777 is Context, IERC777, IERC20 {
* Also emits a {Sent} event.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
address from = _msgSender();
_callTokensToSend(from, from, recipient, amount, "", "");
_move(from, from, recipient, amount, "", "");
_callTokensReceived(from, from, recipient, amount, "", "", false);
_send(_msgSender(), recipient, amount, "", "", false);
return true;
}
@ -286,13 +277,7 @@ contract ERC777 is Context, IERC777, IERC20 {
address recipient,
uint256 amount
) public virtual override returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
require(holder != address(0), "ERC777: transfer from the zero address");
address spender = _msgSender();
_callTokensToSend(spender, holder, recipient, amount, "", "");
uint256 currentAllowance = _allowances[holder][spender];
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "ERC777: transfer amount exceeds allowance");
@ -301,9 +286,7 @@ contract ERC777 is Context, IERC777, IERC20 {
}
}
_move(spender, holder, recipient, amount, "", "");
_callTokensReceived(spender, holder, recipient, amount, "", "", false);
_send(holder, recipient, amount, "", "", false);
return true;
}
@ -392,8 +375,8 @@ contract ERC777 is Context, IERC777, IERC20 {
bytes memory operatorData,
bool requireReceptionAck
) internal virtual {
require(from != address(0), "ERC777: send from the zero address");
require(to != address(0), "ERC777: send to the zero address");
require(from != address(0), "ERC777: transfer from the zero address");
require(to != address(0), "ERC777: transfer to the zero address");
address operator = _msgSender();