Add ERC20 compatibility to ERC777. (#1735)

* Add ERC20 compatibility.

* Reusing ERC20 tests for ERC777.

* Improve documentation.

* Add changelog entry.

* Improved ERC20 behavior tests.

* Add revert reasons to ERC777.

* ERC20 methods allow sending tokens to contracts with no interface.

* Register ERC20 interface.

* Add comment about avoidLockingTokens.

* Improve revert reason string.

* Make ERC777 implement IERC20.

* Fix test revert string.

* Remove unnecesary require.

* Add private _transfer.

* Update contracts/drafts/ERC777/ERC777.sol

Co-Authored-By: nventuro <nicolas.venturo@gmail.com>

* Update private helper names.
This commit is contained in:
Nicolás Venturo
2019-05-08 13:13:19 -03:00
committed by GitHub
parent 86f214b7a3
commit aa4c9feabd
7 changed files with 501 additions and 316 deletions

View File

@ -20,7 +20,7 @@ contract ERC20 is IERC20 {
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowed;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
@ -47,7 +47,7 @@ contract ERC20 is IERC20 {
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowed[owner][spender];
return _allowances[owner][spender];
}
/**
@ -84,13 +84,13 @@ contract ERC20 is IERC20 {
*/
function transferFrom(address from, address to, uint256 value) public returns (bool) {
_transfer(from, to, value);
_approve(from, msg.sender, _allowed[from][msg.sender].sub(value));
_approve(from, msg.sender, _allowances[from][msg.sender].sub(value));
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowed[msg.sender][spender] == 0. To increment
* approve should be called when _allowances[msg.sender][spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
@ -99,13 +99,13 @@ contract ERC20 is IERC20 {
* @param addedValue The amount of tokens to increase the allowance by.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].add(addedValue));
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowed[msg.sender][spender] == 0. To decrement
* approve should be called when _allowances[msg.sender][spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
@ -114,7 +114,7 @@ contract ERC20 is IERC20 {
* @param subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].sub(subtractedValue));
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
@ -171,7 +171,7 @@ contract ERC20 is IERC20 {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowed[owner][spender] = value;
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
@ -185,6 +185,6 @@ contract ERC20 is IERC20 {
*/
function _burnFrom(address account, uint256 value) internal {
_burn(account, value);
_approve(account, msg.sender, _allowed[account][msg.sender].sub(value));
_approve(account, msg.sender, _allowances[account][msg.sender].sub(value));
}
}