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
|
|
@ -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,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user