Browse Source

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>
Kevin Upton 3 years ago
parent
commit
e298476a90
1 changed files with 4 additions and 21 deletions
  1. 4 21
      contracts/token/ERC777/ERC777.sol

+ 4 - 21
contracts/token/ERC777/ERC777.sol

@@ -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");
-
-        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;
         return true;
     }
     }
 
 
@@ -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 {
             }
             }
         }
         }
 
 
-        _move(spender, holder, recipient, amount, "", "");
-
-        _callTokensReceived(spender, holder, recipient, amount, "", "", false);
+        _send(holder, recipient, amount, "", "", false);
 
 
         return true;
         return true;
     }
     }
@@ -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(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();
         address operator = _msgSender();