Permalink
Browse files

audit 5.2.1, opted for adding increaseApproval and decreaseApproval

endpoints
  • Loading branch information...
conejoninja committed Jun 5, 2018
1 parent f0caecb commit 88334ebf11883723dbd256388449358f0a3f2447
Showing with 37 additions and 0 deletions.
  1. +37 −0 contracts/tokens.sol
@@ -153,6 +153,43 @@ contract Tokens is HardcodedWallets, ERC20 {
return allowed[_someone][_spender];
}

/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_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
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}

/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_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
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}

/**
* @notice This is out of ERC20 standard but it is necessary to build market escrow contracts of assets
* @notice Send _amount amount of tokens to from tx.origin to address _to

0 comments on commit 88334eb

Please sign in to comment.