@@ -7,6 +7,27 @@ import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/IERC20.so
77import "../libs/SafeERC20.sol " ;
88import "@openzeppelin/upgrades/contracts/Initializable.sol " ;
99
10+
11+ //Proxy contracts cannot recive eth via fallback function.
12+ //For now , we will use this vault to overcome that
13+ contract Vault is Ownable {
14+ event ReceiveEther (address indexed _sender , uint256 _value );
15+
16+ /**
17+ * @dev enables this contract to receive ethers
18+ */
19+ function () external payable {
20+ emit ReceiveEther (msg .sender , msg .value );
21+ }
22+
23+ function sendEther (uint256 _amountInWei , address payable _to ) external onlyOwner returns (bool ) {
24+ // solhint-disable-next-line avoid-call-value
25+ (bool success , ) = _to.call.value (_amountInWei)("" );
26+ require (success, "sendEther failed. " );
27+ }
28+ }
29+
30+
1031/**
1132 * @title An Avatar holds tokens, reputation and ether for a controller
1233 */
@@ -16,20 +37,24 @@ contract Avatar is Initializable, Ownable {
1637 string public orgName;
1738 DAOToken public nativeToken;
1839 Reputation public nativeReputation;
40+ Vault public vault;
1941
2042 event GenericCall (address indexed _contract , bytes _data , uint _value , bool _success );
2143 event SendEther (uint256 _amountInWei , address indexed _to );
2244 event ExternalTokenTransfer (address indexed _externalToken , address indexed _to , uint256 _value );
2345 event ExternalTokenTransferFrom (address indexed _externalToken , address _from , address _to , uint256 _value );
2446 event ExternalTokenApproval (address indexed _externalToken , address _spender , uint256 _value );
25- event ReceiveEther (address indexed _sender , uint256 _value );
2647 event MetaData (string _metaData );
2748
2849 /**
2950 * @dev enables an avatar to receive ethers
3051 */
3152 function () external payable {
32- emit ReceiveEther (msg .sender , msg .value );
53+ if (msg .sender != address (vault)) {
54+ // solhint-disable-next-line avoid-call-value
55+ (bool success , ) = address (vault).call.value (msg .value )("" );
56+ require (success, "sendEther failed. " );
57+ }
3358 }
3459
3560 /**
@@ -46,6 +71,8 @@ contract Avatar is Initializable, Ownable {
4671 nativeToken = _nativeToken;
4772 nativeReputation = _nativeReputation;
4873 Ownable.initialize (_owner);
74+ vault = new Vault ();
75+ vault.initialize (address (this ));
4976 }
5077
5178 /**
@@ -60,7 +87,10 @@ contract Avatar is Initializable, Ownable {
6087 external
6188 onlyOwner
6289 returns (bool success , bytes memory returnValue ) {
63- // solhint-disable-next-line avoid-call-value
90+ if (_value > 0 ) {
91+ vault.sendEther (_value, address (this ));
92+ }
93+ // solhint-disable-next-line avoid-call-value
6494 (success, returnValue) = _contract.call.value (_value)(_data);
6595 emit GenericCall (_contract, _data, _value, success);
6696 }
@@ -72,7 +102,7 @@ contract Avatar is Initializable, Ownable {
72102 * @return bool which represents success
73103 */
74104 function sendEther (uint256 _amountInWei , address payable _to ) external onlyOwner returns (bool ) {
75- _to. transfer (_amountInWei);
105+ vault. sendEther (_amountInWei, _to );
76106 emit SendEther (_amountInWei, _to);
77107 return true ;
78108 }
0 commit comments