-
-
Save krsnnik/486f0d2964a2ae2a00d0e4b0c5966839 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @dev See `IERC20.transfer`. | |
* | |
* Unlike `send`, `recipient` is _not_ required to implement the `tokensReceived` | |
* interface if it is a contract. | |
* | |
* Also emits a `Sent` event. | |
*/ | |
function transfer(address recipient, uint256 amount) external returns (bool) { | |
require(recipient != address(0), "ERC777: transfer to the zero address"); | |
address from = msg.sender; | |
_callTokensToSend(from, from, recipient, amount, "", ""); | |
_move(from, from, recipient, amount, "", ""); | |
_callTokensReceived(from, from, recipient, amount, "", "", false); | |
return true; | |
} | |
/** | |
* @dev See `IERC20.allowance`. | |
* | |
* Note that operator and allowance concepts are orthogonal: operators may | |
* not have allowance, and accounts with allowance may not be operators | |
* themselves. | |
*/ | |
function allowance(address holder, address spender) public view returns (uint256) { | |
return _allowances[holder][spender]; | |
} | |
/** | |
* @dev See `IERC20.approve`. | |
* | |
* Note that accounts cannot have allowance issued by their operators. | |
*/ | |
function approve(address spender, uint256 value) external returns (bool) { | |
address holder = msg.sender; | |
_approve(holder, spender, value); | |
return true; | |
} | |
function _approve(address holder, address spender, uint256 value) private { | |
// TODO: restore this require statement if this function becomes internal, or is called at a new callsite. It is | |
// currently unnecessary. | |
//require(holder != address(0), "ERC777: approve from the zero address"); | |
require(spender != address(0), "ERC777: approve to the zero address"); | |
_allowances[holder][spender] = value; | |
emit Approval(holder, spender, value); | |
} | |
/** | |
* @dev See `IERC20.transferFrom`. | |
* | |
* Note that operator and allowance concepts are orthogonal: operators cannot | |
* call `transferFrom` (unless they have allowance), and accounts with | |
* allowance cannot call `operatorSend` (unless they are operators). | |
* | |
* Emits `Sent`, `Transfer` and `Approval` events. | |
*/ | |
function transferFrom(address holder, address recipient, uint256 amount) external returns (bool) { | |
require(recipient != address(0), "ERC777: transfer to the zero address"); | |
require(holder != address(0), "ERC777: transfer from the zero address"); | |
address spender = msg.sender; | |
_callTokensToSend(spender, holder, recipient, amount, "", ""); | |
_move(spender, holder, recipient, amount, "", ""); | |
_approve(holder, spender, _allowances[holder][spender].sub(amount)); | |
_callTokensReceived(spender, holder, recipient, amount, "", "", false); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment