From 99a1fc199e31647fdda9809e4a4d6f90ddccd929 Mon Sep 17 00:00:00 2001 From: Sowmayjain Date: Fri, 30 Nov 2018 12:20:50 +0530 Subject: [PATCH] Executed dapp based fee model. --- contracts/protocols/InstaKyber.sol | 32 +++++++++++++++++++++--------- contracts/protocols/InstaMaker.sol | 19 +++++++++++++----- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/contracts/protocols/InstaKyber.sol b/contracts/protocols/InstaKyber.sol index beb1a9e..d3a8091 100644 --- a/contracts/protocols/InstaKyber.sol +++ b/contracts/protocols/InstaKyber.sol @@ -79,7 +79,9 @@ contract Trade is Registry { uint destAmt, address beneficiary, uint minConversionRate, - address affiliate + address referral, + uint cut, + address partner ); function getExpectedPrice( @@ -106,14 +108,16 @@ contract Trade is Registry { address src, // token to sell address dest, // token to buy uint srcAmt, // amount of token for sell + uint srcAmtToFetch, // amount of token for sell + fees // equal to srcAmt or greater uint minConversionRate, // minimum slippage rate - uint maxDestAmt // max amount of dest token + uint maxDestAmt, // max amount of dest token + address partner // affiliate partner ) public payable returns (uint destAmt) { address eth = getAddress("eth"); uint ethQty = getToken( - msg.sender, src, srcAmt, eth + msg.sender, src, srcAmt, srcAmtToFetch, eth ); // Interacting with Kyber Proxy Contract @@ -129,18 +133,27 @@ contract Trade is Registry { ); // maxDestAmt usecase implementated - if (src == eth && address(this).balance > 0) { - msg.sender.transfer(address(this).balance); + uint cut = srcAmtToFetch - srcAmt; + if (src == eth && (address(this).balance - cut) > 0) { + msg.sender.transfer(address(this).balance - cut); } else if (src != eth) { // as there is no balanceOf of eth IERC20 srcTkn = IERC20(src); uint srcBal = srcTkn.balanceOf(address(this)); - if (srcBal > 0) { - srcTkn.transfer(msg.sender, srcBal); + if ((srcBal - cut) > 0) { + srcTkn.transfer(msg.sender, srcBal - cut); } } emit KyberTrade( - src, srcAmt, dest, destAmt, msg.sender, minConversionRate, getAddress("admin") + src, + srcAmt, + dest, + destAmt, + msg.sender, + minConversionRate, + getAddress("admin"), + cut, + partner ); } @@ -149,6 +162,7 @@ contract Trade is Registry { address trader, address src, uint srcAmt, + uint srcAmtToFetch, address eth ) internal returns (uint ethQty) { @@ -157,7 +171,7 @@ contract Trade is Registry { ethQty = srcAmt; } else { IERC20 tokenFunctions = IERC20(src); - tokenFunctions.transferFrom(trader, address(this), srcAmt); + tokenFunctions.transferFrom(trader, address(this), srcAmtToFetch); ethQty = 0; } } diff --git a/contracts/protocols/InstaMaker.sol b/contracts/protocols/InstaMaker.sol index c4b58b4..ad0643a 100644 --- a/contracts/protocols/InstaMaker.sol +++ b/contracts/protocols/InstaMaker.sol @@ -57,8 +57,10 @@ interface InstaKyber { address src, address dest, uint srcAmt, + uint srcAmtToFetch, uint minConversionRate, - uint maxDestAmt + uint maxDestAmt, + address partner ) external payable returns (uint destAmt); function getExpectedPrice( @@ -207,12 +209,15 @@ contract RepayLoan is IssueLoan { uint minRate; (, minRate) = instak.getExpectedPrice(eth, mkr, ethQty); uint mkrBought = instak.executeTrade.value(ethQty)( - eth, mkr, ethQty, minRate, mkrCharged + eth, + mkr, + ethQty, + ethQty, + minRate, + mkrCharged, + address(this) ); require(mkrCharged == mkrBought, "ETH not sufficient to cover the MKR fees."); - if (address(this).balance > 0) { - msg.sender.transfer(address(this).balance); - } } } @@ -278,4 +283,8 @@ contract InstaMaker is BorrowTasks { emit MKRCollected(amount); } + function collectETH(uint amount) public onlyAdmin { + msg.sender.transfer(amount); + } + } \ No newline at end of file