pragma solidity ^0.4.15; contract ERC20 { uint256 public totalSupply; function balanceOf(address who) constant returns (uint256); function allowance(address owner, address spender) constant returns (uint256); function transfer(address to, uint256 value) returns (bool ok); function transferFrom(address from, address to, uint256 value) returns (bool ok); function approve(address spender, uint256 value) returns (bool ok); event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner, address indexed spender, uint256 value); } contract MultiSigTokenWallet { address[] public owners; mapping (uint => Transaction) public transactions; mapping (uint => mapping (address => bool)) public confirmations; mapping (address => bool) public isOwner; mapping (address => uint) public tokenBalances; mapping (address => address[]) public userList; address[] public tokens; uint public required; uint public transactionCount; uint nonce; struct Transaction { address destination; uint value; bytes data; bool executed; } uint constant public MAX_OWNER_COUNT = 50; event Confirmation(address indexed _sender, uint indexed _transactionId); event Revocation(address indexed _sender, uint indexed _transactionId); event Submission(uint indexed _transactionId); event Execution(uint indexed _transactionId); event ExecutionFailure(uint indexed _transactionId); event Deposit(address indexed _sender, uint _value); event TokenDeposit(address _token, address indexed _sender, uint _value); event OwnerAddition(address indexed _owner); event OwnerRemoval(address indexed _owner); event RequirementChange(uint _required); modifier onlyWallet() { require (msg.sender == address(this)); _; } modifier ownerDoesNotExist(address owner) { require (!isOwner[owner]); _; } modifier ownerExists(address owner) { require (isOwner[owner]); _; } modifier transactionExists(uint transactionId) { require (transactions[transactionId].destination != 0); _; } modifier confirmed(uint transactionId, address owner) { require (confirmations[transactionId][owner]); _; } modifier notConfirmed(uint transactionId, address owner) { require(!confirmations[transactionId][owner]); _; } modifier notExecuted(uint transactionId) { require (!transactions[transactionId].executed); _; } modifier notNull(address _address) { require (_address != 0); _; } modifier validRequirement(uint ownerCount, uint _required) { require (ownerCount <= MAX_OWNER_COUNT && _required <= ownerCount && _required != 0 && ownerCount != 0); _; } /// @dev Fallback function allows to deposit ether. function() payable { if (msg.value > 0) Deposit(msg.sender, msg.value); } /** * Public functions * **/ /// @dev Contract constructor sets initial owners and required number of confirmations. /// @param _owners List of initial owners. /// @param _required Number of required confirmations. function Constructor(address[] _owners, uint _required) public validRequirement(_owners.length, _required) { require(owners.length == 0 && required == 0); for (uint i=0; i<_owners.length; i++) { require (!isOwner[_owners[i]] && _owners[i] != 0); isOwner[_owners[i]] = true; } owners = _owners; required = _required; } /** * @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 **/ function depositToken(address _token, bytes _data) public { 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 **/ function deposit(address _from, uint256 _amount, address _token, bytes _data) public { if(_from == address(this)) return; uint _nonce = nonce; assert(ERC20(_token).transferFrom(_from, this, _amount)); if(nonce == _nonce){ //ERC23 not executed _deposited tokenFallback by _deposited(_from, _amount, _token, _data); } } /** * @notice watches for balance in a token contract * @param _tokenAddr the token contract address * @param _data any data **/ function watch(address _tokenAddr, bytes _data) ownerExists(msg.sender) { uint oldBal = tokenBalances[_tokenAddr]; uint newBal = ERC20(_tokenAddr).balanceOf(this); if(newBal > oldBal){ _deposited(0x0, newBal-oldBal, _tokenAddr, _data); } } function setMyTokenList(address[] _tokenList) { userList[msg.sender] = _tokenList; } function setTokenList(address[] _tokenList) onlyWallet { tokens = _tokenList; } /** * @notice ERC23 Token fallback * @param _from address incoming token * @param _amount incoming amount **/ function tokenFallback(address _from, uint _amount, bytes _data) public { _deposited(_from, _amount, msg.sender, _data); } /** * @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) { deposit(_from, _amount, _token, _data); } /// @dev Allows to add a new owner. Transaction has to be sent by wallet. /// @param owner Address of new owner. function addOwner(address owner) public onlyWallet ownerDoesNotExist(owner) notNull(owner) validRequirement(owners.length + 1, required) { isOwner[owner] = true; owners.push(owner); OwnerAddition(owner); } /// @dev Allows to remove an owner. Transaction has to be sent by wallet. /// @param owner Address of owner. function removeOwner(address owner) public onlyWallet ownerExists(owner) { isOwner[owner] = false; for (uint i=0; i owners.length) changeRequirement(owners.length); OwnerRemoval(owner); } /// @dev Allows to replace an owner with a new owner. Transaction has to be sent by wallet. /// @param owner Address of owner to be replaced. /// @param owner Address of new owner. function replaceOwner(address owner, address newOwner) public onlyWallet ownerExists(owner) ownerDoesNotExist(newOwner) { for (uint i=0; i 0){ _tokenList = userList[_dest]; } else { _tokenList = tokens; } uint len = _tokenList.length; for(uint i = 0;i< len; i++){ address _tokenAddr = _tokenList[i]; uint _amount = tokenBalances[_tokenAddr]; if(_amount > 0) { delete tokenBalances[_tokenAddr]; ERC20(_tokenAddr).transfer(_dest, _amount); } } } /** * @dev withdraw `_tokenAddr` `_amount` to `_dest` * @param _tokenAddr the address of the token * @param _dest the address of receiver * @param _amount the number of tokens to send **/ function withdrawToken(address _tokenAddr, address _dest, uint _amount) public notNull(_dest) onlyWallet { require(_amount > 0); uint _balance = tokenBalances[_tokenAddr]; require(_amount <= _balance); tokenBalances[_tokenAddr] = _balance - _amount; assert(ERC20(_tokenAddr).transfer(_dest, _amount)); } /// @dev Returns the confirmation status of a transaction. /// @param transactionId Transaction ID. /// @return Confirmation status. function isConfirmed(uint transactionId) public constant returns (bool) { uint count = 0; for (uint i=0; i