From 899c045238b69a79324360a21862a392bddc5871 Mon Sep 17 00:00:00 2001 From: Samyak Jain Date: Thu, 2 May 2019 00:42:33 +0530 Subject: [PATCH] getMax public function --- contracts/ProxyLogics/InstaSave.sol | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/contracts/ProxyLogics/InstaSave.sol b/contracts/ProxyLogics/InstaSave.sol index 873efaf..2482f3f 100644 --- a/contracts/ProxyLogics/InstaSave.sol +++ b/contracts/ProxyLogics/InstaSave.sol @@ -343,6 +343,16 @@ contract MakerHelpers is Helpers { contract GetDetails is MakerHelpers { + function getMax(uint cdpID) public view returns (uint maxColToFree, uint maxDaiToDraw) { + bytes32 cup = bytes32(cdpID); + (uint ethCol, uint daiDebt, uint usdPerEth) = getCDPStats(cup); + uint colToUSD = wmul(ethCol, usdPerEth) - 10; + uint minColNeeded = wmul(daiDebt, 1500000000000000000) + 10; + maxColToFree = wdiv(sub(colToUSD, minColNeeded), usdPerEth); + uint maxDebtLimit = wdiv(colToUSD, 1500000000000000000) - 10; + maxDaiToDraw = sub(maxDebtLimit, daiDebt); + } + function getSave(uint cdpID, uint ethToSwap) public view returns (uint finalEthCol, uint finalDaiDebt, uint finalColToUSD, bool canSave) { bytes32 cup = bytes32(cdpID); (uint ethCol, uint daiDebt, uint usdPerEth) = getCDPStats(cup);