Unverified Commit e298476a by Kevin Upton Committed by GitHub

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>
parent a5e042ce
...@@ -144,16 +144,7 @@ contract ERC777 is Context, IERC777, IERC20 { ...@@ -144,16 +144,7 @@ contract ERC777 is Context, IERC777, IERC20 {
* Also emits a {Sent} event. * Also emits a {Sent} event.
*/ */
function transfer(address recipient, uint256 amount) public virtual override returns (bool) { function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address"); _send(_msgSender(), recipient, amount, "", "", false);
address from = _msgSender();
_callTokensToSend(from, from, recipient, amount, "", "");
_move(from, from, recipient, amount, "", "");
_callTokensReceived(from, from, recipient, amount, "", "", false);
return true; return true;
} }
...@@ -286,13 +277,7 @@ contract ERC777 is Context, IERC777, IERC20 { ...@@ -286,13 +277,7 @@ contract ERC777 is Context, IERC777, IERC20 {
address recipient, address recipient,
uint256 amount uint256 amount
) public virtual override returns (bool) { ) 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(); address spender = _msgSender();
_callTokensToSend(spender, holder, recipient, amount, "", "");
uint256 currentAllowance = _allowances[holder][spender]; uint256 currentAllowance = _allowances[holder][spender];
if (currentAllowance != type(uint256).max) { if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "ERC777: transfer amount exceeds allowance"); require(currentAllowance >= amount, "ERC777: transfer amount exceeds allowance");
...@@ -301,9 +286,7 @@ contract ERC777 is Context, IERC777, IERC20 { ...@@ -301,9 +286,7 @@ contract ERC777 is Context, IERC777, IERC20 {
} }
} }
_move(spender, holder, recipient, amount, "", ""); _send(holder, recipient, amount, "", "", false);
_callTokensReceived(spender, holder, recipient, amount, "", "", false);
return true; return true;
} }
...@@ -392,8 +375,8 @@ contract ERC777 is Context, IERC777, IERC20 { ...@@ -392,8 +375,8 @@ contract ERC777 is Context, IERC777, IERC20 {
bytes memory operatorData, bytes memory operatorData,
bool requireReceptionAck bool requireReceptionAck
) internal virtual { ) internal virtual {
require(from != address(0), "ERC777: send from the zero address"); require(from != address(0), "ERC777: transfer from the zero address");
require(to != address(0), "ERC777: send to the zero address"); require(to != address(0), "ERC777: transfer to the zero address");
address operator = _msgSender(); address operator = _msgSender();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment