burned fee locker/recycler

This commit is contained in:
Ricardo Guilherme Schmidt 2018-03-11 18:39:57 +07:00
parent 5be48d084c
commit 4a8f336c7c
1 changed files with 46 additions and 0 deletions

View File

@ -0,0 +1,46 @@
pragma solidity ^0.4.17;
import "../token/MiniMeToken.sol";
import "../token/ApproveAndCallFallBack.sol";
contract BurnedFeeLocker is ApproveAndCallFallBack {
address public SNT;
address public recyclerManager;
mapping (address => uint256) burnedFee;
uint256 availableToRecycle;
function BurnedFeeLocker(address _recyclerManager, address _SNT) public {
SNT = _SNT;
recyclerManager = _recyclerManager;
}
function recycleFee(address _from, address _to, uint256 _amount) external {
require(msg.sender == recyclerManager);
require(burnedFee[_from] >= _amount);
MiniMeToken(SNT).approveAndCall(_to, _amount, new bytes(0));
availableToRecycle -= _amount;
}
function withdrawToken(address _token, address _to) external {
require(msg.sender == recyclerManager);
uint256 available = MiniMeToken(_token).balanceOf(address(this));
if (_token == SNT) {
available -= availableToRecycle;
}
if (available > 0) {
MiniMeToken(_token).transfer(_to, available);
}
}
function receiveApproval(address _from, uint256 _amount, address _token, bytes _data) public {
require(_token == SNT);
if (_amount == 0 || _data.length > 0) {
require(msg.sender == _token);
}
if (MiniMeToken(SNT).transferFrom(_from, address(this), _amount)) {
burnedFee[_from] += _amount;
availableToRecycle += _amount;
}
}
}