mirror of
https://github.com/Instadapp/smart-contract.git
synced 2024-07-29 22:08:07 +00:00
Allowance in leverage & small edits
This commit is contained in:
parent
e5a50109bd
commit
869c12c110
|
|
@ -80,7 +80,7 @@ contract Helper {
|
||||||
) public view returns (
|
) public view returns (
|
||||||
uint expectedRate,
|
uint expectedRate,
|
||||||
uint slippageRate
|
uint slippageRate
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
(expectedRate,) = KyberInterface(getAddressKyber()).getExpectedRate(src, dest, srcAmt);
|
(expectedRate,) = KyberInterface(getAddressKyber()).getExpectedRate(src, dest, srcAmt);
|
||||||
slippageRate = (expectedRate / 100) * 99; // changing slippage rate upto 99%
|
slippageRate = (expectedRate / 100) * 99; // changing slippage rate upto 99%
|
||||||
|
|
@ -114,7 +114,7 @@ contract Helper {
|
||||||
tknContract.approve(getAddressKyber(), 2**255);
|
tknContract.approve(getAddressKyber(), 2**255);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -229,7 +229,7 @@ contract Swap is Helper {
|
||||||
contract InstaTrade is Swap {
|
contract InstaTrade is Swap {
|
||||||
|
|
||||||
uint public version;
|
uint public version;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev setting up variables on deployment
|
* @dev setting up variables on deployment
|
||||||
* 1...2...3 versioning in each subsequent deployments
|
* 1...2...3 versioning in each subsequent deployments
|
||||||
|
|
|
||||||
|
|
@ -180,13 +180,13 @@ contract CDPResolver is Helpers {
|
||||||
tub.free(cup, ink);
|
tub.free(cup, ink);
|
||||||
|
|
||||||
setAllowance(peth, tubAddr);
|
setAllowance(peth, tubAddr);
|
||||||
|
|
||||||
tub.exit(ink);
|
tub.exit(ink);
|
||||||
uint freeJam = weth.balanceOf(address(this)); // withdraw possible previous stuck WETH as well
|
uint freeJam = weth.balanceOf(address(this)); // withdraw possible previous stuck WETH as well
|
||||||
weth.withdraw(freeJam);
|
weth.withdraw(freeJam);
|
||||||
|
|
||||||
address(msg.sender).transfer(freeJam);
|
address(msg.sender).transfer(freeJam);
|
||||||
|
|
||||||
emit LogFree(
|
emit LogFree(
|
||||||
cdpNum,
|
cdpNum,
|
||||||
freeJam,
|
freeJam,
|
||||||
|
|
@ -203,7 +203,7 @@ contract CDPResolver is Helpers {
|
||||||
|
|
||||||
tub.draw(cup, _wad);
|
tub.draw(cup, _wad);
|
||||||
tub.sai().transfer(msg.sender, _wad);
|
tub.sai().transfer(msg.sender, _wad);
|
||||||
|
|
||||||
emit LogDraw(cdpNum, _wad, address(this));
|
emit LogDraw(cdpNum, _wad, address(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -298,7 +298,7 @@ contract CDPCluster is CDPResolver {
|
||||||
contract InstaMaker is CDPCluster {
|
contract InstaMaker is CDPCluster {
|
||||||
|
|
||||||
uint public version;
|
uint public version;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev setting up variables on deployment
|
* @dev setting up variables on deployment
|
||||||
* 1...2...3 versioning in each subsequent deployments
|
* 1...2...3 versioning in each subsequent deployments
|
||||||
|
|
|
||||||
|
|
@ -189,7 +189,7 @@ contract Helpers is DSMath {
|
||||||
) public view returns (
|
) public view returns (
|
||||||
uint expectedRate,
|
uint expectedRate,
|
||||||
uint slippageRate
|
uint slippageRate
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
(expectedRate,) = KyberInterface(getAddressKyber()).getExpectedRate(src, dest, srcAmt);
|
(expectedRate,) = KyberInterface(getAddressKyber()).getExpectedRate(src, dest, srcAmt);
|
||||||
slippageRate = (expectedRate / 100) * 99; // changing slippage rate upto 99%
|
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) {
|
function getCDPStats(bytes32 cup) internal view returns (uint ethCol, uint daiDebt, uint usdPerEth) {
|
||||||
TubInterface tub = TubInterface(getSaiTubAddress());
|
TubInterface tub = TubInterface(getSaiTubAddress());
|
||||||
usdPerEth = uint(oracleInterface(getOracleAddress()).read());
|
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
|
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 LogDraw(uint cdpNum, uint amtDAI, address owner);
|
||||||
event LogWipe(uint cdpNum, uint daiAmt, uint mkrFee, uint daiFee, 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)) {
|
if (_token.allowance(address(this), _spender) != uint(-1)) {
|
||||||
_token.approve(_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);
|
bytes32 cup = bytes32(cdpID);
|
||||||
(uint ethCol, uint daiDebt, uint usdPerEth) = getCDPStats(cup);
|
(uint ethCol, uint daiDebt, uint usdPerEth) = getCDPStats(cup);
|
||||||
(finalEthCol, finalDaiDebt, finalColToUSD, canLeverage) = checkLeverage(
|
(finalEthCol, finalDaiDebt, finalColToUSD, canLeverage) = checkLeverage(
|
||||||
|
|
@ -500,6 +510,7 @@ contract Save is GetDetails {
|
||||||
debtToBorrow = daiToSwap;
|
debtToBorrow = daiToSwap;
|
||||||
}
|
}
|
||||||
draw(cdpID, debtToBorrow);
|
draw(cdpID, debtToBorrow);
|
||||||
|
setAllowance(TokenInterface(getAddressDAI()), getAddressKyber());
|
||||||
uint destAmt = KyberInterface(getAddressKyber()).trade.value(0)(
|
uint destAmt = KyberInterface(getAddressKyber()).trade.value(0)(
|
||||||
getAddressDAI(),
|
getAddressDAI(),
|
||||||
debtToBorrow,
|
debtToBorrow,
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ contract Helper {
|
||||||
erc20Contract.approve(to, 2**255);
|
erc20Contract.approve(to, 2**255);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -222,7 +222,7 @@ contract Pool is Helper {
|
||||||
contract InstaUniswapPool is Pool {
|
contract InstaUniswapPool is Pool {
|
||||||
|
|
||||||
uint public version;
|
uint public version;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev setting up variables on deployment
|
* @dev setting up variables on deployment
|
||||||
* 1...2...3 versioning in each subsequent deployments
|
* 1...2...3 versioning in each subsequent deployments
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user