mirror of
https://github.com/Instadapp/InstaContract.git
synced 2024-07-29 22:47:45 +00:00
Fixed minimum variable error.
This commit is contained in:
parent
9433a394c6
commit
15fbd1768c
|
@ -18,6 +18,12 @@ library SafeMath {
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
|
||||||
|
require(b <= a, "Assertion Failed");
|
||||||
|
uint256 c = a - b;
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IERC20 {
|
interface IERC20 {
|
||||||
|
@ -84,6 +90,8 @@ contract Trade is Registry {
|
||||||
address partner
|
address partner
|
||||||
);
|
);
|
||||||
|
|
||||||
|
address public eth = 0x00eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee;
|
||||||
|
|
||||||
function getExpectedPrice(
|
function getExpectedPrice(
|
||||||
address src,
|
address src,
|
||||||
address dest,
|
address dest,
|
||||||
|
@ -104,25 +112,44 @@ contract Trade is Registry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct TradeUints {
|
||||||
|
uint srcAmt;
|
||||||
|
uint ethQty;
|
||||||
|
uint srcAmtWithFees;
|
||||||
|
uint cut;
|
||||||
|
uint destAmt;
|
||||||
|
int ethBalAfterTrade; // it can be neagtive
|
||||||
|
}
|
||||||
|
|
||||||
function executeTrade(
|
function executeTrade(
|
||||||
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 srcAmtWithFees, // amount of token for sell + fees // equal or greater than srcAmt
|
||||||
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
|
address partner // affiliate partner
|
||||||
) public payable returns (uint destAmt)
|
) public payable returns (uint destAmt)
|
||||||
{
|
{
|
||||||
|
|
||||||
address eth = getAddress("eth");
|
require(srcAmtWithFees >= srcAmt, "srcAmtWithFees can't be small than scrAmt");
|
||||||
uint ethQty = getToken(
|
if (src == eth) {
|
||||||
msg.sender, src, srcAmt, srcAmtToFetch, eth
|
require(srcAmtWithFees == msg.value, "Not enough ETH to cover the trade.");
|
||||||
);
|
}
|
||||||
|
|
||||||
// Interacting with Kyber Proxy Contract
|
TradeUints memory tradeSpecs;
|
||||||
Kyber kyberFunctions = Kyber(getAddress("kyber"));
|
Kyber kyberFunctions = Kyber(getAddress("kyber"));
|
||||||
destAmt = kyberFunctions.trade.value(ethQty)(
|
|
||||||
|
tradeSpecs.srcAmt = srcAmt;
|
||||||
|
tradeSpecs.srcAmtWithFees = srcAmtWithFees;
|
||||||
|
tradeSpecs.cut = srcAmtWithFees.sub(srcAmt);
|
||||||
|
tradeSpecs.ethQty = getToken(
|
||||||
|
msg.sender,
|
||||||
|
src,
|
||||||
|
srcAmt,
|
||||||
|
srcAmtWithFees
|
||||||
|
);
|
||||||
|
tradeSpecs.destAmt = kyberFunctions.trade.value(tradeSpecs.ethQty)(
|
||||||
src,
|
src,
|
||||||
srcAmt,
|
srcAmt,
|
||||||
dest,
|
dest,
|
||||||
|
@ -132,15 +159,14 @@ contract Trade is Registry {
|
||||||
getAddress("admin")
|
getAddress("admin")
|
||||||
);
|
);
|
||||||
|
|
||||||
// maxDestAmt usecase implementated
|
// factoring maxDestAmt situation
|
||||||
uint cut = srcAmtToFetch - srcAmt;
|
if (src == eth && address(this).balance > tradeSpecs.cut) {
|
||||||
if (src == eth && (address(this).balance - cut) > 0) {
|
msg.sender.transfer(address(this).balance.sub(tradeSpecs.cut));
|
||||||
msg.sender.transfer(address(this).balance - cut);
|
} else if (src != 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 - cut) > 0) {
|
if (srcBal > tradeSpecs.cut) {
|
||||||
srcTkn.transfer(msg.sender, srcBal - cut);
|
srcTkn.transfer(msg.sender, srcBal.sub(tradeSpecs.cut));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,7 +178,7 @@ contract Trade is Registry {
|
||||||
msg.sender,
|
msg.sender,
|
||||||
minConversionRate,
|
minConversionRate,
|
||||||
getAddress("admin"),
|
getAddress("admin"),
|
||||||
cut,
|
tradeSpecs.cut,
|
||||||
partner
|
partner
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -162,8 +188,7 @@ contract Trade is Registry {
|
||||||
address trader,
|
address trader,
|
||||||
address src,
|
address src,
|
||||||
uint srcAmt,
|
uint srcAmt,
|
||||||
uint srcAmtToFetch,
|
uint srcAmtWithFees
|
||||||
address eth
|
|
||||||
) internal returns (uint ethQty)
|
) internal returns (uint ethQty)
|
||||||
{
|
{
|
||||||
if (src == eth) {
|
if (src == eth) {
|
||||||
|
@ -171,8 +196,7 @@ contract Trade is Registry {
|
||||||
ethQty = srcAmt;
|
ethQty = srcAmt;
|
||||||
} else {
|
} else {
|
||||||
IERC20 tokenFunctions = IERC20(src);
|
IERC20 tokenFunctions = IERC20(src);
|
||||||
tokenFunctions.transferFrom(trader, address(this), srcAmtToFetch);
|
tokenFunctions.transferFrom(trader, address(this), srcAmtWithFees);
|
||||||
ethQty = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -162,7 +162,7 @@ contract RepayLoan is IssueLoan {
|
||||||
function wipeDAI(uint daiWipe, address borrower) public payable returns (uint mkrCharged) {
|
function wipeDAI(uint daiWipe, address borrower) public payable returns (uint mkrCharged) {
|
||||||
address dai = getAddress("dai");
|
address dai = getAddress("dai");
|
||||||
address mkr = getAddress("mkr");
|
address mkr = getAddress("mkr");
|
||||||
address eth = getAddress("eth");
|
address eth = 0x00eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee;
|
||||||
|
|
||||||
IERC20 daiTkn = IERC20(dai);
|
IERC20 daiTkn = IERC20(dai);
|
||||||
IERC20 mkrTkn = IERC20(mkr);
|
IERC20 mkrTkn = IERC20(mkr);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user