Executed dapp based fee model.

This commit is contained in:
Sowmayjain 2018-11-30 12:20:50 +05:30
parent b1c3e807d5
commit 99a1fc199e
2 changed files with 37 additions and 14 deletions

View File

@ -79,7 +79,9 @@ contract Trade is Registry {
uint destAmt, uint destAmt,
address beneficiary, address beneficiary,
uint minConversionRate, uint minConversionRate,
address affiliate address referral,
uint cut,
address partner
); );
function getExpectedPrice( function getExpectedPrice(
@ -106,14 +108,16 @@ contract Trade is Registry {
address src, // token to sell address src, // token to sell
address dest, // token to buy address dest, // token to buy
uint srcAmt, // amount of token for sell 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 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) ) public payable returns (uint destAmt)
{ {
address eth = getAddress("eth"); address eth = getAddress("eth");
uint ethQty = getToken( uint ethQty = getToken(
msg.sender, src, srcAmt, eth msg.sender, src, srcAmt, srcAmtToFetch, eth
); );
// Interacting with Kyber Proxy Contract // Interacting with Kyber Proxy Contract
@ -129,18 +133,27 @@ contract Trade is Registry {
); );
// maxDestAmt usecase implementated // maxDestAmt usecase implementated
if (src == eth && address(this).balance > 0) { uint cut = srcAmtToFetch - srcAmt;
msg.sender.transfer(address(this).balance); 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 } else if (src != eth) { // as there is no balanceOf of eth
IERC20 srcTkn = IERC20(src); IERC20 srcTkn = IERC20(src);
uint srcBal = srcTkn.balanceOf(address(this)); uint srcBal = srcTkn.balanceOf(address(this));
if (srcBal > 0) { if ((srcBal - cut) > 0) {
srcTkn.transfer(msg.sender, srcBal); srcTkn.transfer(msg.sender, srcBal - cut);
} }
} }
emit KyberTrade( 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 trader,
address src, address src,
uint srcAmt, uint srcAmt,
uint srcAmtToFetch,
address eth address eth
) internal returns (uint ethQty) ) internal returns (uint ethQty)
{ {
@ -157,7 +171,7 @@ contract Trade is Registry {
ethQty = srcAmt; ethQty = srcAmt;
} else { } else {
IERC20 tokenFunctions = IERC20(src); IERC20 tokenFunctions = IERC20(src);
tokenFunctions.transferFrom(trader, address(this), srcAmt); tokenFunctions.transferFrom(trader, address(this), srcAmtToFetch);
ethQty = 0; ethQty = 0;
} }
} }

View File

@ -57,8 +57,10 @@ interface InstaKyber {
address src, address src,
address dest, address dest,
uint srcAmt, uint srcAmt,
uint srcAmtToFetch,
uint minConversionRate, uint minConversionRate,
uint maxDestAmt uint maxDestAmt,
address partner
) external payable returns (uint destAmt); ) external payable returns (uint destAmt);
function getExpectedPrice( function getExpectedPrice(
@ -207,12 +209,15 @@ contract RepayLoan is IssueLoan {
uint minRate; uint minRate;
(, minRate) = instak.getExpectedPrice(eth, mkr, ethQty); (, minRate) = instak.getExpectedPrice(eth, mkr, ethQty);
uint mkrBought = instak.executeTrade.value(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."); 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); emit MKRCollected(amount);
} }
function collectETH(uint amount) public onlyAdmin {
msg.sender.transfer(amount);
}
} }