open-bounty/contracts/MultiSigTokenWallet.sol

113 lines
3.1 KiB
Solidity
Raw Normal View History

2017-08-16 09:00:24 +00:00
pragma solidity ^0.4.15;
2017-08-02 03:10:54 +00:00
2017-11-08 19:36:15 +00:00
import "./MultiSigWallet.sol";
2017-08-20 18:29:37 +00:00
import "./ERC20.sol";
2017-08-02 03:10:54 +00:00
2017-11-08 19:36:15 +00:00
contract MultiSigTokenWallet is MultiSigWallet {
2017-08-01 08:37:25 +00:00
event TokenDeposit(address indexed token, address indexed sender, uint value);
2017-08-01 08:37:25 +00:00
2017-08-16 09:00:24 +00:00
/**
* Public functions
*
**/
2017-08-01 08:37:25 +00: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 03:10:54 +00:00
function depositToken(address _token, bytes _data)
public
{
2017-08-01 08:37:25 +00: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 03:10:54 +00:00
function deposit(address _from, uint256 _amount, address _token, bytes _data)
public
{
2017-08-20 18:29:37 +00:00
if (_from == address(this))
return;
bool result = ERC20(_token).transferFrom(_from, this, _amount);
require(result);
2017-11-09 08:21:06 +00:00
TokenDeposit(_token, _from, _amount);
}
2017-08-01 08:37:25 +00: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 03:10:54 +00:00
public
returns (bool)
2017-08-02 03:10:54 +00:00
{
2017-11-09 08:21:06 +00:00
TokenDeposit(msg.sender, _from, _amount);
return true;
2017-08-01 08:37:25 +00: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 08:37:25 +00:00
deposit(_from, _amount, _token, _data);
}
2017-08-02 03:10:54 +00:00
2017-08-02 03:10:54 +00:00
/**
* @dev withdraw all tokens in list and ether to `_dest`
2017-08-02 03:10:54 +00:00
* @param _dest the address of receiver
* @param _tokenList the list of tokens to withdraw all balance
2017-08-02 03:10:54 +00:00
**/
function withdrawEverything(address _dest, address[] _tokenList)
2017-08-02 03:10:54 +00:00
public
notNull(_dest)
onlyWallet
{
withdrawAllTokens(_dest, _tokenList);
2017-08-02 03:10:54 +00:00
_dest.transfer(this.balance);
}
/**
* @dev withdraw all listed tokens balances to `_dest`
2017-08-02 03:10:54 +00:00
* @param _dest the address of receiver
* @param _tokenList the list of tokens to withdraw all balance
2017-08-02 03:10:54 +00:00
**/
function withdrawAllTokens(address _dest, address[] _tokenList)
2017-08-02 03:10:54 +00:00
public
notNull(_dest)
onlyWallet
{
uint len = _tokenList.length;
2017-08-20 18:29:37 +00:00
for (uint i = 0;i < len; i++) {
address _tokenAddr = _tokenList[i];
uint _amount = ERC20(_tokenAddr).balanceOf(address(this));
2017-08-20 18:29:37 +00:00
if (_amount > 0) {
ERC20(_tokenAddr).call(bytes4(keccak256("transfer(address,uint256)")), _dest, _amount);
2017-08-01 08:37:25 +00:00
}
}
}
2017-08-02 03:10:54 +00:00
}