Allowance in leverage & small edits

This commit is contained in:
Samyak Jain 2019-05-01 15:37:18 +05:30
parent e5a50109bd
commit 869c12c110
4 changed files with 25 additions and 14 deletions

View File

@ -80,7 +80,7 @@ contract Helper {
) public view returns (
uint expectedRate,
uint slippageRate
)
)
{
(expectedRate,) = KyberInterface(getAddressKyber()).getExpectedRate(src, dest, srcAmt);
slippageRate = (expectedRate / 100) * 99; // changing slippage rate upto 99%
@ -114,7 +114,7 @@ contract Helper {
tknContract.approve(getAddressKyber(), 2**255);
}
}
}
@ -229,7 +229,7 @@ contract Swap is Helper {
contract InstaTrade is Swap {
uint public version;
/**
* @dev setting up variables on deployment
* 1...2...3 versioning in each subsequent deployments

View File

@ -180,13 +180,13 @@ contract CDPResolver is Helpers {
tub.free(cup, ink);
setAllowance(peth, tubAddr);
tub.exit(ink);
uint freeJam = weth.balanceOf(address(this)); // withdraw possible previous stuck WETH as well
weth.withdraw(freeJam);
address(msg.sender).transfer(freeJam);
emit LogFree(
cdpNum,
freeJam,
@ -203,7 +203,7 @@ contract CDPResolver is Helpers {
tub.draw(cup, _wad);
tub.sai().transfer(msg.sender, _wad);
emit LogDraw(cdpNum, _wad, address(this));
}
}
@ -298,7 +298,7 @@ contract CDPCluster is CDPResolver {
contract InstaMaker is CDPCluster {
uint public version;
/**
* @dev setting up variables on deployment
* 1...2...3 versioning in each subsequent deployments

View File

@ -189,7 +189,7 @@ contract Helpers is DSMath {
) public view returns (
uint expectedRate,
uint slippageRate
)
)
{
(expectedRate,) = KyberInterface(getAddressKyber()).getExpectedRate(src, dest, srcAmt);
slippageRate = (expectedRate / 100) * 99; // changing slippage rate upto 99%
@ -198,8 +198,9 @@ contract Helpers is DSMath {
function getCDPStats(bytes32 cup) internal view returns (uint ethCol, uint daiDebt, uint usdPerEth) {
TubInterface tub = TubInterface(getSaiTubAddress());
usdPerEth = uint(oracleInterface(getOracleAddress()).read());
(, uint pethCol, uint daiDebt,) = tub.cups(cup);
(, uint pethCol, uint debt,) = tub.cups(cup);
ethCol = rmul(pethCol, tub.per()); // get ETH col from PETH col
daiDebt = debt;
}
}
@ -212,7 +213,7 @@ contract MakerHelpers is Helpers {
event LogDraw(uint cdpNum, uint amtDAI, address owner);
event LogWipe(uint cdpNum, uint daiAmt, uint mkrFee, uint daiFee, address owner);
function setAllowance(TokenInterface _token, address _spender) private {
function setAllowance(TokenInterface _token, address _spender) internal {
if (_token.allowance(address(this), _spender) != uint(-1)) {
_token.approve(_spender, uint(-1));
}
@ -388,7 +389,16 @@ contract GetDetails is MakerHelpers {
}
}
function getLeverage(uint cdpID, uint daiToSwap) public view returns (uint finalEthCol, uint finalDaiDebt, uint finalColToUSD, bool canLeverage) {
function getLeverage(
uint cdpID,
uint daiToSwap
) public view returns (
uint finalEthCol,
uint finalDaiDebt,
uint finalColToUSD,
bool canLeverage
)
{
bytes32 cup = bytes32(cdpID);
(uint ethCol, uint daiDebt, uint usdPerEth) = getCDPStats(cup);
(finalEthCol, finalDaiDebt, finalColToUSD, canLeverage) = checkLeverage(
@ -500,6 +510,7 @@ contract Save is GetDetails {
debtToBorrow = daiToSwap;
}
draw(cdpID, debtToBorrow);
setAllowance(TokenInterface(getAddressDAI()), getAddressKyber());
uint destAmt = KyberInterface(getAddressKyber()).trade.value(0)(
getAddressDAI(),
debtToBorrow,

View File

@ -78,7 +78,7 @@ contract Helper {
erc20Contract.approve(to, 2**255);
}
}
}
@ -222,7 +222,7 @@ contract Pool is Helper {
contract InstaUniswapPool is Pool {
uint public version;
/**
* @dev setting up variables on deployment
* 1...2...3 versioning in each subsequent deployments