pragma solidity ^0.4.18; import "./Controller.sol"; import "./Reputation.sol"; import "./DAOToken.sol"; import "zeppelin-solidity/contracts/ownership/Ownable.sol"; import "zeppelin-solidity/contracts/token/StandardToken.sol"; contract ActionInterface { function action(bytes32[] _params) public returns(bool); } /** * @title An Avatar holds tokens, reputation and ether for a controller */ contract Avatar is Ownable { bytes32 public orgName; DAOToken public nativeToken; Reputation public nativeReputation; event GenericAction(address indexed _action, bytes32[] _params); event SendEther(uint _amountInWei, address indexed _to); event ExternalTokenTransfer(address indexed _externalToken, address indexed _to, uint _value); event ExternalTokenTransferFrom(address indexed _externalToken, address _from, address _to, uint _value); event ExternalTokenIncreaseApproval(StandardToken indexed _externalToken, address _spender, uint _addedValue); event ExternalTokenDecreaseApproval(StandardToken indexed _externalToken, address _spender, uint _subtractedValue); event ReceiveEther(address indexed _sender, uint _value); /** * @dev the constructor takes organization name, native token and reputation system and creates an avatar for a controller */ function Avatar(bytes32 _orgName, DAOToken _nativeToken, Reputation _nativeReputation) public { orgName = _orgName; nativeToken = _nativeToken; nativeReputation = _nativeReputation; } /** * @dev enables an avatar to receive ethers */ function() public payable { ReceiveEther(msg.sender, msg.value); } /** * @dev call an action function on an ActionInterface. * This function use delegatecall and might expose the organization to security * risk. Use this function only if you really knows what you are doing. * @param _action the address of the contract to call. * @param _params the params for the call. * @return bool which represents success */ function genericAction(address _action, bytes32[] _params) public onlyOwner returns(bool) { GenericAction(_action, _params); // solium-disable-next-line security/no-low-level-calls return _action.delegatecall(bytes4(keccak256("action(bytes32[])")), uint256(32),// length of length of the array uint256(_params.length), // length of the array _params); // array itself); } /** * @dev send ethers from the avatar's wallet * @param _amountInWei amount to send in Wei units * @param _to send the ethers to this address * @return bool which represents success */ function sendEther(uint _amountInWei, address _to) public onlyOwner returns(bool) { _to.transfer(_amountInWei); SendEther(_amountInWei, _to); return true; } /** * @dev external token transfer * @param _externalToken the token contract * @param _to the destination address * @param _value the amount of tokens to transfer * @return bool which represents success */ function externalTokenTransfer(StandardToken _externalToken, address _to, uint _value) public onlyOwner returns(bool) { _externalToken.transfer(_to, _value); ExternalTokenTransfer(_externalToken, _to, _value); return true; } /** * @dev external token transfer from a specific account * @param _externalToken the token contract * @param _from the account to spend token from * @param _to the destination address * @param _value the amount of tokens to transfer * @return bool which represents success */ function externalTokenTransferFrom( StandardToken _externalToken, address _from, address _to, uint _value ) public onlyOwner returns(bool) { _externalToken.transferFrom(_from, _to, _value); ExternalTokenTransferFrom(_externalToken, _from, _to, _value); return true; } /** * @dev increase approval for the spender address to spend a specified amount of tokens * on behalf of msg.sender. * @param _externalToken the address of the Token Contract * @param _spender address * @param _addedValue the amount of ether (in Wei) which the approval is referring to. * @return bool which represents a success */ function externalTokenIncreaseApproval(StandardToken _externalToken, address _spender, uint _addedValue) public onlyOwner returns(bool) { _externalToken.increaseApproval(_spender, _addedValue); ExternalTokenIncreaseApproval(_externalToken, _spender, _addedValue); return true; } /** * @dev decrease approval for the spender address to spend a specified amount of tokens * on behalf of msg.sender. * @param _externalToken the address of the Token Contract * @param _spender address * @param _subtractedValue the amount of ether (in Wei) which the approval is referring to. * @return bool which represents a success */ function externalTokenDecreaseApproval(StandardToken _externalToken, address _spender, uint _subtractedValue ) public onlyOwner returns(bool) { _externalToken.decreaseApproval(_spender, _subtractedValue); ExternalTokenDecreaseApproval(_externalToken,_spender, _subtractedValue); return true; } }