From e8f8530c8c3a9de5a9de6b6be70700051375790b Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Wed, 10 Jul 2019 17:39:38 -0400 Subject: [PATCH] feat: added fee burner contract --- contracts/fees/KyberFeeBurner.sol | 72 +++++++++++++++++++ .../{test => fees}/KyberNetworkProxy.sol | 26 +++++++ embarkConfig/contracts.js | 3 + 3 files changed, 101 insertions(+) create mode 100644 contracts/fees/KyberFeeBurner.sol rename contracts/{test => fees}/KyberNetworkProxy.sol (55%) diff --git a/contracts/fees/KyberFeeBurner.sol b/contracts/fees/KyberFeeBurner.sol new file mode 100644 index 00000000..cc143fc8 --- /dev/null +++ b/contracts/fees/KyberFeeBurner.sol @@ -0,0 +1,72 @@ +/* solium-disable security/no-block-members */ +pragma solidity >=0.5.0 <0.6.0; + +import "../common/Ownable.sol"; +import "../token/ERC20Token.sol"; +import "./KyberNetworkProxy.sol"; + +contract KyberFeeBurner is Ownable { + + address public SNT; + address public burnAddress; + KyberNetworkProxy public kyberNetworkProxy; + + constructor(address _snt, address _burnAddress, address _kyberNetworkProxy) public { + SNT = _snt; + burnAddress = _burnAddress; + kyberNetworkProxy = KyberNetworkProxy(_kyberNetworkProxy); + } + + event SNTAddressChanged(address sender, address prevSNTAddress, address newSNTAddress); + + function setSNT(address _snt) external onlyOwner { + emit SNTAddressChanged(msg.sender, SNT, _snt); + SNT = _snt; + } + + event BurnAddressChanged(address sender, address prevBurnAddress, address newBurnAddress); + + function setBurnAddress(address _burnAddress) external onlyOwner { + emit BurnAddressChanged(msg.sender, burnAddress, _burnAddress); + burnAddress = _burnAddress; + } + + event KyberNetworkProxyAddressChanged(address sender, address prevKyberAddress, address newKyberAddress); + + function setKyberNetworkProxyAddress(address _kyberNetworkProxy) external onlyOwner { + emit KyberNetworkProxyAddressChanged(msg.sender, address(kyberNetworkProxy), _kyberNetworkProxy); + kyberNetworkProxy = KyberNetworkProxy(_kyberNetworkProxy); + } + + function swap(address _token) external { + if(_token == address(0)){ + uint ethBalance = address(this).balance; + (uint minConversionRate,) = kyberNetworkProxy.getExpectedRate(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE, SNT, ethBalance); + kyberNetworkProxy.swapEtherToToken.value(ethBalance)(SNT, minConversionRate); + } else { + ERC20Token t = ERC20Token(_token); + uint tokenBalance = t.balanceOf(address(this)); + if(_token == SNT){ + t.transfer(burnAddress, tokenBalance); + } else { + // TODO: swapTokenToToken() + } + } + } + + event EscapeTriggered(address sender, address token, uint amount); + + function escape(address _token) external onlyOwner { + if(_token == address(0)){ + uint ethBalance = address(this).balance; + address(uint160(owner())).transfer(ethBalance); + emit EscapeTriggered(msg.sender, _token, ethBalance); + } else { + ERC20Token t = ERC20Token(_token); + uint tokenBalance = t.balanceOf(address(this)); + require(t.transfer(owner(), tokenBalance), "Token transfer error"); + emit EscapeTriggered(msg.sender, _token, tokenBalance); + } + } + +} \ No newline at end of file diff --git a/contracts/test/KyberNetworkProxy.sol b/contracts/fees/KyberNetworkProxy.sol similarity index 55% rename from contracts/test/KyberNetworkProxy.sol rename to contracts/fees/KyberNetworkProxy.sol index b60d07eb..d4f7013d 100644 --- a/contracts/test/KyberNetworkProxy.sol +++ b/contracts/fees/KyberNetworkProxy.sol @@ -37,4 +37,30 @@ contract KyberNetworkProxy { { return maxDestAmount; } + + /// @dev makes a trade between src and dest token and send dest tokens to msg sender + /// @param src Src token + /// @param srcAmount amount of src tokens + /// @param dest Destination token + /// @param minConversionRate The minimal conversion rate. If actual rate is lower, trade is canceled. + /// @return amount of actual dest tokens + function swapTokenToToken( + address src, + uint srcAmount, + address dest, + uint minConversionRate + ) + public + returns(uint) + { + return 100; + } + + /// @dev makes a trade from Ether to token. Sends token to msg sender + /// @param token Destination token + /// @param minConversionRate The minimal conversion rate. If actual rate is lower, trade is canceled. + /// @return amount of actual dest tokens + function swapEtherToToken(address token, uint minConversionRate) public payable returns(uint) { + return 200; + } } \ No newline at end of file diff --git a/embarkConfig/contracts.js b/embarkConfig/contracts.js index 31cb7207..6670656d 100644 --- a/embarkConfig/contracts.js +++ b/embarkConfig/contracts.js @@ -132,6 +132,9 @@ module.exports = { OwnedUpgradeabilityProxy: { }, KyberNetworkProxy: { + }, + KyberFeeBurner: { + args: ["$SNT", "0x0000000000000000000000000000000000000002", "$KyberNetworkProxy"] } } },