From f40f31879a91d9d1ae86d85cc8749ffebda80f4d Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Sat, 17 Mar 2018 10:35:02 -0300 Subject: [PATCH 1/3] Better fee recycler contract --- contracts/democracy/FeeRecycler.sol | 89 +++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 contracts/democracy/FeeRecycler.sol diff --git a/contracts/democracy/FeeRecycler.sol b/contracts/democracy/FeeRecycler.sol new file mode 100644 index 0000000..7011a77 --- /dev/null +++ b/contracts/democracy/FeeRecycler.sol @@ -0,0 +1,89 @@ +pragma solidity ^0.4.17; + +import "../common/Controlled.sol"; +import "../token/ERC20Token.sol"; +import "../token/MiniMeToken.sol"; + +/** + * @title FeeRecycler + * @author Ricardo Guilherme Schmidt (Status Research & Development GmBH) + * @dev Allow user selecting predefined destinations to where this fees will be invested + */ +contract FeeRecycler is Controlled { + + //allowed democratically choosen destinations + mapping (address => bool) public destinations; + //balances of users + mapping (address => uint256) public balances; + //used for withdrawing lost tokens + uint256 public totalLocked; + //base token + MiniMeToken public token; + + /** + * @notice Constructor defines the unchangable (?) baseToken + * @param _token base token + */ + function FeeRecycler(MiniMeToken _token) public { + token = _token; + } + + /** + * @notice Lock a fee in name of someone + * @param _from who would be able to recycle this funds + * @param _amount to be locked + */ + function lock(address _from, uint256 _amount) external { + require(token.transferFrom(msg.sender, address(this), _amount)); + balances[_from] += _amount; + totalLocked += _amount; + } + + /** + * @notice Unlock and approveAndCall + * @param _to Allowed destination to get tokens + * @param _amount that will be transfered + */ + function recycle(address _to, uint256 _amount) external { + require(destinations[_to]); + require(balances[msg.sender] >= _amount); + balances[msg.sender] -= _amount; + totalLocked -= _amount; + token.approveAndCall(_to, _amount, new bytes(0)); + } + + /** + * @notice Controller should enable destinations to recycle + * @param _destination that would be available to recycle + * @param _allowed users can recycle to this address? + */ + function setDestination(address _destination, bool _allowed) + external + onlyController + { + destinations[_destination] = _allowed; + } + + /** + * @notice Withdraw lost tokens in the contract + * @param _token if is base token than can only transfer unlocked amount + * @param _destination address receiving this tokens + * @param _amount the amount to be transfered + */ + function withdraw(ERC20Token _token, address _destination, uint256 _amount) + external + onlyController + { + if (address(_token) == address(token)) { + require(_amount <= _token.balanceOf(address(this)) - totalLocked); + } else if (address(_token) == address(0)) { + require(this.balance <= _amount); + } + if (address(_token) != address(0)) { + _token.transfer(_destination, _amount); + } else { + _destination.transfer(_amount); + } + } + +} \ No newline at end of file From d7b6c0f964ad627a054fccb89ec7a5cd6f0567e4 Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Tue, 27 Mar 2018 23:16:51 -0300 Subject: [PATCH 2/3] democracy , constitution and factory refactor --- contracts/democracy/FeeRecycler.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/democracy/FeeRecycler.sol b/contracts/democracy/FeeRecycler.sol index 7011a77..626b6f8 100644 --- a/contracts/democracy/FeeRecycler.sol +++ b/contracts/democracy/FeeRecycler.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.17; +pragma solidity ^0.4.21; import "../common/Controlled.sol"; import "../token/ERC20Token.sol"; From 31cabbb83bf81fa91d5ee06a917a3596430474f7 Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Thu, 29 Mar 2018 16:09:30 -0300 Subject: [PATCH 3/3] included fee collector, moved executed flag to democracy and + --- contracts/democracy/FeeCollector.sol | 26 +++++++++++++++++++++ contracts/democracy/FeeRecycler.sol | 35 ++++++++++++++++++++++------ 2 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 contracts/democracy/FeeCollector.sol diff --git a/contracts/democracy/FeeCollector.sol b/contracts/democracy/FeeCollector.sol new file mode 100644 index 0000000..2ae272e --- /dev/null +++ b/contracts/democracy/FeeCollector.sol @@ -0,0 +1,26 @@ +pragma solidity ^0.4.21; + +/** @notice Interface for fee collector */ +contract FeeCollector { + + /** + * @notice Collect a fee from yourself in your address + * @param _amount to be collected + */ + function collect(uint256 _amount) external; + + /** + * @notice Collect a fee from your address in name of someone + * @param _from to which address fee will be registered to + * @param _amount to be collected + */ + function collectFor(address _from, uint256 _amount) external; + + /** + * @notice Collect a fee from someone + * @param _from who allowed collection + * @param _amount to be collected + */ + function collectFrom(address _from, uint256 _amount) external; + +} \ No newline at end of file diff --git a/contracts/democracy/FeeRecycler.sol b/contracts/democracy/FeeRecycler.sol index 626b6f8..7c8fafd 100644 --- a/contracts/democracy/FeeRecycler.sol +++ b/contracts/democracy/FeeRecycler.sol @@ -2,14 +2,14 @@ pragma solidity ^0.4.21; import "../common/Controlled.sol"; import "../token/ERC20Token.sol"; -import "../token/MiniMeToken.sol"; - +import "../token/MiniMeTokenInterface.sol"; +import "./FeeCollector.sol"; /** * @title FeeRecycler * @author Ricardo Guilherme Schmidt (Status Research & Development GmBH) * @dev Allow user selecting predefined destinations to where this fees will be invested */ -contract FeeRecycler is Controlled { +contract FeeRecycler is Controlled, FeeCollector { //allowed democratically choosen destinations mapping (address => bool) public destinations; @@ -18,22 +18,43 @@ contract FeeRecycler is Controlled { //used for withdrawing lost tokens uint256 public totalLocked; //base token - MiniMeToken public token; + MiniMeTokenInterface public token; /** * @notice Constructor defines the unchangable (?) baseToken * @param _token base token */ - function FeeRecycler(MiniMeToken _token) public { + function FeeRecycler(MiniMeTokenInterface _token) public { token = _token; } + /** + * @notice Collect a fee from yourself in your address + * @param _amount to be collected + */ + function collect(uint256 _amount) external { + require(token.transferFrom(msg.sender, address(this), _amount)); + balances[msg.sender] += _amount; + totalLocked += _amount; + } + + /** + * @notice Collect a fee from someone + * @param _from who allowed collection + * @param _amount to be collected + */ + function collectFrom(address _from, uint256 _amount) external { + require(token.transferFrom(_from, address(this), _amount)); + balances[_from] += _amount; + totalLocked += _amount; + } + /** * @notice Lock a fee in name of someone * @param _from who would be able to recycle this funds * @param _amount to be locked */ - function lock(address _from, uint256 _amount) external { + function collectFor(address _from, uint256 _amount) external { require(token.transferFrom(msg.sender, address(this), _amount)); balances[_from] += _amount; totalLocked += _amount; @@ -77,7 +98,7 @@ contract FeeRecycler is Controlled { if (address(_token) == address(token)) { require(_amount <= _token.balanceOf(address(this)) - totalLocked); } else if (address(_token) == address(0)) { - require(this.balance <= _amount); + require(address(this).balance <= _amount); } if (address(_token) != address(0)) { _token.transfer(_destination, _amount);