1- pragma solidity ^ 0.4.25 ;
1+ pragma solidity ^ 0.5.2 ;
22
33import "@daostack/infra/contracts/Reputation.sol " ;
44import "./DAOToken.sol " ;
55import "openzeppelin-solidity/contracts/ownership/Ownable.sol " ;
6- import "openzeppelin-solidity/contracts/token/ERC20/StandardToken .sol " ;
6+ import "openzeppelin-solidity/contracts/token/ERC20/ERC20 .sol " ;
77import "openzeppelin-solidity/contracts/token/ERC20/SafeERC20.sol " ;
88
99
1010/**
1111 * @title An Avatar holds tokens, reputation and ether for a controller
1212 */
1313contract Avatar is Ownable {
14- using SafeERC20 for StandardToken ;
14+ using SafeERC20 for ERC20 ;
1515
1616 string public orgName;
1717 DAOToken public nativeToken;
@@ -21,15 +21,14 @@ contract Avatar is Ownable {
2121 event SendEther (uint256 _amountInWei , address indexed _to );
2222 event ExternalTokenTransfer (address indexed _externalToken , address indexed _to , uint256 _value );
2323 event ExternalTokenTransferFrom (address indexed _externalToken , address _from , address _to , uint256 _value );
24- event ExternalTokenIncreaseApproval (StandardToken indexed _externalToken , address _spender , uint256 _addedValue );
25- event ExternalTokenDecreaseApproval (StandardToken indexed _externalToken , address _spender , uint256 _subtractedValue );
24+ event ExternalTokenApproval (ERC20 indexed _externalToken , address _spender , uint256 _value );
2625 event ReceiveEther (address indexed _sender , uint256 _value );
2726
2827 /**
2928 * @dev the constructor takes organization name, native token and reputation system
3029 and creates an avatar for a controller
3130 */
32- constructor (string _orgName , DAOToken _nativeToken , Reputation _nativeReputation ) public {
31+ constructor (string memory _orgName , DAOToken _nativeToken , Reputation _nativeReputation ) public {
3332 orgName = _orgName;
3433 nativeToken = _nativeToken;
3534 nativeReputation = _nativeReputation;
@@ -38,7 +37,7 @@ contract Avatar is Ownable {
3837 /**
3938 * @dev enables an avatar to receive ethers
4039 */
41- function () public payable {
40+ function () external payable {
4241 emit ReceiveEther (msg .sender , msg .value );
4342 }
4443
@@ -48,20 +47,12 @@ contract Avatar is Ownable {
4847 * @param _data ABI-encoded contract call to call `_contract` address.
4948 * @return the return bytes of the called contract's function.
5049 */
51- function genericCall (address _contract ,bytes _data ) public onlyOwner {
52- emit GenericCall (_contract,_data);
53- // solium-disable-next-line security/no-low-level-calls
54- bool result = _contract.call (_data);
55- // solium-disable-next-line security/no-inline-assembly
56- assembly {
57- // Copy the returned data.
58- returndatacopy (0 , 0 , returndatasize)
59-
60- switch result
61- // call returns 0 on error.
62- case 0 { revert (0 , returndatasize) }
63- default { return (0 , returndatasize) }
64- }
50+ function genericCall (address _contract , bytes memory _data ) public onlyOwner returns (bytes memory ) {
51+ emit GenericCall (_contract, _data);
52+ // solhint-disable-next-line avoid-low-level-calls
53+ (bool success , bytes memory returnValue ) = _contract.call (_data);
54+ require (success);
55+ return returnValue;
6556 }
6657
6758 /**
@@ -70,7 +61,7 @@ contract Avatar is Ownable {
7061 * @param _to send the ethers to this address
7162 * @return bool which represents success
7263 */
73- function sendEther (uint256 _amountInWei , address _to ) public onlyOwner returns (bool ) {
64+ function sendEther (uint256 _amountInWei , address payable _to ) public onlyOwner returns (bool ) {
7465 _to.transfer (_amountInWei);
7566 emit SendEther (_amountInWei, _to);
7667 return true ;
@@ -83,11 +74,11 @@ contract Avatar is Ownable {
8374 * @param _value the amount of tokens to transfer
8475 * @return bool which represents success
8576 */
86- function externalTokenTransfer (StandardToken _externalToken , address _to , uint256 _value )
77+ function externalTokenTransfer (ERC20 _externalToken , address _to , uint256 _value )
8778 public onlyOwner returns (bool )
8879 {
8980 _externalToken.safeTransfer (_to, _value);
90- emit ExternalTokenTransfer (_externalToken, _to, _value);
81+ emit ExternalTokenTransfer (address ( _externalToken) , _to, _value);
9182 return true ;
9283 }
9384
@@ -100,47 +91,31 @@ contract Avatar is Ownable {
10091 * @return bool which represents success
10192 */
10293 function externalTokenTransferFrom (
103- StandardToken _externalToken ,
94+ ERC20 _externalToken ,
10495 address _from ,
10596 address _to ,
10697 uint256 _value
10798 )
10899 public onlyOwner returns (bool )
109100 {
110101 _externalToken.safeTransferFrom (_from, _to, _value);
111- emit ExternalTokenTransferFrom (_externalToken, _from, _to, _value);
112- return true ;
113- }
114-
115- /**
116- * @dev increase approval for the spender address to spend a specified amount of tokens
117- * on behalf of msg.sender.
118- * @param _externalToken the address of the Token Contract
119- * @param _spender address
120- * @param _addedValue the amount of ether (in Wei) which the approval is referring to.
121- * @return bool which represents a success
122- */
123- function externalTokenIncreaseApproval (StandardToken _externalToken , address _spender , uint256 _addedValue )
124- public onlyOwner returns (bool )
125- {
126- require (_externalToken.increaseApproval (_spender, _addedValue),"increase approval must succeed " );
127- emit ExternalTokenIncreaseApproval (_externalToken, _spender, _addedValue);
102+ emit ExternalTokenTransferFrom (address (_externalToken), _from, _to, _value);
128103 return true ;
129104 }
130105
131106 /**
132- * @dev decrease approval for the spender address to spend a specified amount of tokens
107+ * @dev externalTokenApproval approve the spender address to spend a specified amount of tokens
133108 * on behalf of msg.sender.
134109 * @param _externalToken the address of the Token Contract
135110 * @param _spender address
136- * @param _subtractedValue the amount of ether (in Wei) which the approval is referring to.
111+ * @param _value the amount of ether (in Wei) which the approval is referring to.
137112 * @return bool which represents a success
138113 */
139- function externalTokenDecreaseApproval (StandardToken _externalToken , address _spender , uint256 _subtractedValue )
114+ function externalTokenApproval ( ERC20 _externalToken , address _spender , uint256 _value )
140115 public onlyOwner returns (bool )
141116 {
142- require (_externalToken.decreaseApproval (_spender, _subtractedValue), " decrease approval must succeed " );
143- emit ExternalTokenDecreaseApproval (_externalToken,_spender, _subtractedValue );
117+ require (_externalToken.approve (_spender, _value), " approve must succeed " );
118+ emit ExternalTokenApproval (_externalToken, _spender, _value );
144119 return true ;
145120 }
146121
0 commit comments