open-bounty/contracts/MultiSigTokenWallet.sol

126 lines
3.5 KiB
Solidity
Raw Normal View History

2017-11-09 13:50:54 -02:00
pragma solidity ^0.4.18;
2017-08-02 00:10:54 -03:00
2017-11-08 17:36:15 -02:00
import "./MultiSigWallet.sol";
2017-08-20 15:29:37 -03:00
import "./ERC20.sol";
2017-08-02 00:10:54 -03:00
2017-11-09 13:50:54 -02:00
/**
* @title MultiSigTokenWallet
* @author Ricardo Guilherme Schmidt (Status Research & Development GmbH)
* MultiSigWallet that supports withdrawing all ERC20 tokens at once.
*/
2017-11-08 17:36:15 -02:00
contract MultiSigTokenWallet is MultiSigWallet {
2017-08-01 05:37:25 -03:00
event TokenDeposit(address indexed token, address indexed sender, uint value);
2017-08-01 05:37:25 -03:00
2017-08-16 06:00:24 -03:00
/**
* Public functions
*
**/
2017-11-09 13:06:24 -02:00
/**
* @dev only call parent constructor
*/
function MultiSigTokenWallet(address[] _owners, uint _required)
MultiSigWallet(_owners,_required)
public
{
//does nothing
}
2017-08-01 05:37:25 -03:00
/**
* @notice deposit a ERC20 token. The amount of deposit is the allowance set to this contract.
* @param _token the token contract address
* @param _data might be used by child implementations
**/
2017-08-02 00:10:54 -03:00
function depositToken(address _token, bytes _data)
public
{
2017-08-01 05:37:25 -03:00
address sender = msg.sender;
uint amount = ERC20(_token).allowance(sender, this);
deposit(sender, amount, _token, _data);
}
/**
* @notice deposit a ERC20 token. The amount of deposit is the allowance set to this contract.
* @param _token the token contract address
* @param _data might be used by child implementations
**/
2017-08-02 00:10:54 -03:00
function deposit(address _from, uint256 _amount, address _token, bytes _data)
public
{
2017-08-20 15:29:37 -03:00
if (_from == address(this))
return;
bool result = ERC20(_token).transferFrom(_from, this, _amount);
require(result);
2017-11-09 06:21:06 -02:00
TokenDeposit(_token, _from, _amount);
}
2017-08-01 05:37:25 -03:00
/**
* @notice ERC23 Token fallback
* @param _from address incoming token
* @param _amount incoming amount
**/
function tokenFallback(
address _from,
uint _amount,
bytes _data
)
2017-08-02 00:10:54 -03:00
public
returns (bool)
2017-08-02 00:10:54 -03:00
{
2017-11-09 06:21:06 -02:00
TokenDeposit(msg.sender, _from, _amount);
return true;
2017-08-01 05:37:25 -03:00
}
/**
* @notice Called MiniMeToken approvesAndCall to this contract, calls deposit.
* @param _from address incoming token
* @param _amount incoming amount
* @param _token the token contract address
* @param _data (might be used by child classes)
*/
function receiveApproval(
address _from,
uint256 _amount,
address _token,
bytes _data
)
public
{
2017-08-01 05:37:25 -03:00
deposit(_from, _amount, _token, _data);
}
2017-08-02 00:10:54 -03:00
2017-08-02 00:10:54 -03:00
/**
* @dev withdraw all tokens in list and ether to `_dest`
2017-08-02 00:10:54 -03:00
* @param _dest the address of receiver
* @param _tokenList the list of tokens to withdraw all balance
2017-08-02 00:10:54 -03:00
**/
function withdrawEverything(address _dest, address[] _tokenList)
2017-08-02 00:10:54 -03:00
public
notNull(_dest)
onlyWallet
{
withdrawAllTokens(_dest, _tokenList);
2017-08-02 00:10:54 -03:00
_dest.transfer(this.balance);
}
/**
* @dev withdraw all listed tokens balances to `_dest`
2017-08-02 00:10:54 -03:00
* @param _dest the address of receiver
* @param _tokenList the list of tokens to withdraw all balance
2017-08-02 00:10:54 -03:00
**/
function withdrawAllTokens(address _dest, address[] _tokenList)
2017-08-02 00:10:54 -03:00
public
notNull(_dest)
onlyWallet
{
uint len = _tokenList.length;
2017-08-20 15:29:37 -03:00
for (uint i = 0;i < len; i++) {
address _tokenAddr = _tokenList[i];
uint _amount = ERC20(_tokenAddr).balanceOf(address(this));
2017-08-20 15:29:37 -03:00
if (_amount > 0) {
2017-11-09 13:06:24 -02:00
ERC20(_tokenAddr).transfer(_dest, _amount);
2017-08-01 05:37:25 -03:00
}
}
}
2017-08-02 00:10:54 -03:00
}