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

@ -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,