From af1e0760fa2b84f5528a9599e87b3d4d17e12b60 Mon Sep 17 00:00:00 2001 From: Samyak Jain Date: Mon, 6 May 2019 19:25:00 +0530 Subject: [PATCH] maxETH fixed --- contracts/ProxyLogics/InstaSave.sol | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/contracts/ProxyLogics/InstaSave.sol b/contracts/ProxyLogics/InstaSave.sol index 48daec1..6cd26e2 100644 --- a/contracts/ProxyLogics/InstaSave.sol +++ b/contracts/ProxyLogics/InstaSave.sol @@ -325,6 +325,13 @@ contract GetDetails is MakerHelpers { uint maxDebtLimit = wdiv(colToUSD, 1500000000000000000) - 10; maxDaiToDraw = sub(maxDebtLimit, daiDebt); ethInUSD = usdPerEth; + + (uint expectedRate,) = KyberInterface(getAddressKyber()).getExpectedRate(getAddressETH(), getAddressDAI(), maxColToFree); + uint expectedDai = wmul(maxColToFree, expectedRate); + if (expectedDai > maxDaiToDraw) { + maxColToFree = wmul(maxColToFree, wdiv(maxDaiToDraw, expectedDai)); + } + } function getSave(uint cdpID, uint ethToSwap) public view returns (uint finalEthCol, uint finalDaiDebt, uint finalColToUSD, bool canSave) {