code re-structuring

This commit is contained in:
Samyak Jain 2019-12-13 21:58:36 +05:30
parent d65da6bec7
commit 5ec71a0f31

View File

@ -500,9 +500,7 @@ contract GetDetails is MakerHelpers {
uint colToUSD = sub(wmul(ethCol, usdPerEth), 10); uint colToUSD = sub(wmul(ethCol, usdPerEth), 10);
uint minColNeeded = add(wmul(daiDebt, 1500000000000000000), 10); uint minColNeeded = add(wmul(daiDebt, 1500000000000000000), 10);
uint colToFree = wdiv(sub(colToUSD, minColNeeded), usdPerEth); uint colToFree = wdiv(sub(colToUSD, minColNeeded), usdPerEth);
if (ethToSwap < colToFree) { colToFree = ethToSwap < colToFree ? ethToSwap : colToFree;
colToFree = ethToSwap;
}
(, uint expectedDAI) = SplitSwapInterface(getAddressSplitSwap()).getBest(getAddressETH(), getAddressDAI(), colToFree); (, uint expectedDAI) = SplitSwapInterface(getAddressSplitSwap()).getBest(getAddressETH(), getAddressDAI(), colToFree);
if (expectedDAI < daiDebt) { if (expectedDAI < daiDebt) {
finalEthCol = sub(ethCol, colToFree); finalEthCol = sub(ethCol, colToFree);
@ -533,9 +531,7 @@ contract GetDetails is MakerHelpers {
uint colToUSD = sub(wmul(ethCol, usdPerEth), 10); uint colToUSD = sub(wmul(ethCol, usdPerEth), 10);
uint maxDebtLimit = sub(wdiv(colToUSD, 1500000000000000000), 10); uint maxDebtLimit = sub(wdiv(colToUSD, 1500000000000000000), 10);
uint debtToBorrow = sub(maxDebtLimit, daiDebt); uint debtToBorrow = sub(maxDebtLimit, daiDebt);
if (daiToSwap < debtToBorrow) { debtToBorrow = daiToSwap < debtToBorrow ? daiToSwap : debtToBorrow;
debtToBorrow = daiToSwap;
}
(, uint expectedETH) = SplitSwapInterface(getAddressSplitSwap()).getBest(getAddressDAI(), getAddressETH(), debtToBorrow); (, uint expectedETH) = SplitSwapInterface(getAddressSplitSwap()).getBest(getAddressDAI(), getAddressETH(), debtToBorrow);
if (ethCol != 0) { if (ethCol != 0) {
finalEthCol = add(ethCol, expectedETH); finalEthCol = add(ethCol, expectedETH);
@ -592,9 +588,7 @@ contract Save is GetDetails {
(uint ethCol, uint daiDebt, uint usdPerEth) = getVaultStats(cdpID); (uint ethCol, uint daiDebt, uint usdPerEth) = getVaultStats(cdpID);
uint colToFree = getColToFree(ethCol, daiDebt, usdPerEth); uint colToFree = getColToFree(ethCol, daiDebt, usdPerEth);
require(colToFree != 0, "no-collatral-to-free"); require(colToFree != 0, "no-collatral-to-free");
if (colToSwap < colToFree) { colToFree = colToSwap < colToFree ? colToSwap : colToFree;
colToFree = colToSwap;
}
free(cdpID, colToFree); free(cdpID, colToFree);
uint ethToSwap = address(this).balance; uint ethToSwap = address(this).balance;
ethToSwap = ethToSwap < colToFree ? ethToSwap : colToFree; ethToSwap = ethToSwap < colToFree ? ethToSwap : colToFree;
@ -616,9 +610,7 @@ contract Save is GetDetails {
(uint ethCol, uint daiDebt, uint usdPerEth) = getVaultStats(cdpID); (uint ethCol, uint daiDebt, uint usdPerEth) = getVaultStats(cdpID);
uint debtToBorrow = getDebtToBorrow(ethCol, daiDebt, usdPerEth); uint debtToBorrow = getDebtToBorrow(ethCol, daiDebt, usdPerEth);
require(debtToBorrow != 0, "No-debt-to-borrow"); require(debtToBorrow != 0, "No-debt-to-borrow");
if (daiToSwap < debtToBorrow) { debtToBorrow = daiToSwap < debtToBorrow ? daiToSwap : debtToBorrow;
debtToBorrow = daiToSwap;
}
draw(cdpID, debtToBorrow); draw(cdpID, debtToBorrow);
TokenInterface(getAddressDAI()).approve(getAddressSplitSwap(), debtToBorrow); TokenInterface(getAddressDAI()).approve(getAddressSplitSwap(), debtToBorrow);
uint destAmt = SplitSwapInterface(getAddressSplitSwap()).daiToEthSwap(debtToBorrow, splitAmt, slippageAmt); uint destAmt = SplitSwapInterface(getAddressSplitSwap()).daiToEthSwap(debtToBorrow, splitAmt, slippageAmt);