commented uniswap

This commit is contained in:
Samyak Jain 2019-06-29 19:19:36 +05:30
parent d1cdf2198a
commit a43a7ed802
2 changed files with 33 additions and 31 deletions

View File

@ -170,7 +170,7 @@ contract Helpers is DSMath {
* @dev get admin address * @dev get admin address
*/ */
function getAddressSplitSwap() public pure returns (address payable splitSwap) { function getAddressSplitSwap() public pure returns (address payable splitSwap) {
splitSwap = 0x7CFB3DFb0F7eEE91576eb492FF964B1B59be0713; splitSwap = 0xdAA26F94C5185538830A84eF3B533743afD4baad;
} }
/** /**
@ -484,10 +484,12 @@ contract Save is GetDetails {
colToFree = colToSwap; colToFree = colToSwap;
} }
free(cdpID, colToFree); free(cdpID, colToFree);
uint destAmt = SplitSwapInterface(getAddressSplitSwap()).ethToDaiSwap.value(colToFree)(splitAmt, slippageAmt); uint ethToSwap = address(this).balance;
ethToSwap = ethToSwap < colToFree ? ethToSwap : colToFree;
uint destAmt = SplitSwapInterface(getAddressSplitSwap()).ethToDaiSwap.value(ethToSwap)(splitAmt, slippageAmt);
wipe(cdpID, destAmt); wipe(cdpID, destAmt);
emit LogSaveCDP(cdpID, colToFree, destAmt); emit LogSaveCDP(cdpID, ethToSwap, destAmt);
} }
function leverage( function leverage(

View File

@ -156,16 +156,16 @@ contract SplitHelper is AdminStuffs {
} }
uint eth2DaiPrice = getRateEth2Dai(src, dest, finalSrcAmt); uint eth2DaiPrice = getRateEth2Dai(src, dest, finalSrcAmt);
uint kyberPrice = getRateKyber(src, dest, finalSrcAmt); uint kyberPrice = getRateKyber(src, dest, finalSrcAmt);
uint uniswapPrice = getRateUniswap(src, dest, finalSrcAmt); // uint uniswapPrice = getRateUniswap(src, dest, finalSrcAmt);
if (eth2DaiPrice > kyberPrice && eth2DaiPrice > uniswapPrice) { if (eth2DaiPrice > kyberPrice) {
destAmt = eth2DaiPrice; destAmt = eth2DaiPrice;
bestExchange = 0; bestExchange = 0;
} else if (kyberPrice > uniswapPrice && kyberPrice > eth2DaiPrice) { } else if (kyberPrice >= eth2DaiPrice) {
destAmt = kyberPrice; destAmt = kyberPrice;
bestExchange = 1; bestExchange = 1;
} else { // } else {
destAmt = uniswapPrice; // destAmt = uniswapPrice;
bestExchange = 2; // bestExchange = 2;
} }
if (dest == daiAddr) { if (dest == daiAddr) {
destAmt = wmul(destAmt, cut); destAmt = wmul(destAmt, cut);
@ -186,13 +186,13 @@ contract SplitHelper is AdminStuffs {
destAmt = wmul(srcAmt, kyberPrice); destAmt = wmul(srcAmt, kyberPrice);
} }
function getRateUniswap(address src, address dest, uint srcAmt) internal view returns (uint destAmt) { // function getRateUniswap(address src, address dest, uint srcAmt) internal view returns (uint destAmt) {
if (src == ethAddr) { // if (src == ethAddr) {
destAmt = UniswapExchange(uniswapAddr).getEthToTokenInputPrice(srcAmt); // destAmt = UniswapExchange(uniswapAddr).getEthToTokenInputPrice(srcAmt);
} else if (dest == ethAddr) { // } else if (dest == ethAddr) {
destAmt = UniswapExchange(uniswapAddr).getTokenToEthInputPrice(srcAmt); // destAmt = UniswapExchange(uniswapAddr).getTokenToEthInputPrice(srcAmt);
} // }
} // }
} }
@ -207,15 +207,15 @@ contract SplitResolver is SplitHelper {
uint amtToSwap = splitAmt; uint amtToSwap = splitAmt;
uint nextSrcAmt = srcAmt - splitAmt; uint nextSrcAmt = srcAmt - splitAmt;
(uint bestExchange,) = getBest(ethAddr, daiAddr, amtToSwap); (uint bestExchange,) = getBest(ethAddr, daiAddr, amtToSwap);
uint ethBought = finalAmt; uint daiBought = finalAmt;
if (bestExchange == 0) { if (bestExchange == 0) {
ethBought += swapEth2Dai(wethAddr, daiAddr, amtToSwap); daiBought += swapEth2Dai(wethAddr, daiAddr, amtToSwap);
} else if (bestExchange == 1) { } else if (bestExchange == 1) {
ethBought += swapKyber(ethAddr, daiAddr, amtToSwap); daiBought += swapKyber(ethAddr, daiAddr, amtToSwap);
} else { // } else {
ethBought += swapUniswap(ethAddr, daiAddr, amtToSwap); // daiBought += swapUniswap(ethAddr, daiAddr, amtToSwap);
} }
destAmt = ethToDaiLoop(nextSrcAmt, splitAmt, ethBought); destAmt = ethToDaiLoop(nextSrcAmt, splitAmt, daiBought);
} else if (srcAmt > 0) { } else if (srcAmt > 0) {
destAmt = finalAmt; destAmt = finalAmt;
destAmt += swapKyber(ethAddr, daiAddr, srcAmt); destAmt += swapKyber(ethAddr, daiAddr, srcAmt);
@ -234,8 +234,8 @@ contract SplitResolver is SplitHelper {
ethBought += swapEth2Dai(daiAddr, wethAddr, amtToSwap); ethBought += swapEth2Dai(daiAddr, wethAddr, amtToSwap);
} else if (bestExchange == 1) { } else if (bestExchange == 1) {
ethBought += swapKyber(daiAddr, ethAddr, amtToSwap); ethBought += swapKyber(daiAddr, ethAddr, amtToSwap);
} else { // } else {
ethBought += swapUniswap(daiAddr, ethAddr, amtToSwap); // ethBought += swapUniswap(daiAddr, ethAddr, amtToSwap);
} }
destAmt = daiToEthLoop(nextSrcAmt, splitAmt, ethBought); destAmt = daiToEthLoop(nextSrcAmt, splitAmt, ethBought);
} else if (srcAmt > 0) { } else if (srcAmt > 0) {
@ -281,13 +281,13 @@ contract SplitResolver is SplitHelper {
); );
} }
function swapUniswap(address src, address dest, uint srcAmt) internal returns (uint destAmt) { // function swapUniswap(address src, address dest, uint srcAmt) internal returns (uint destAmt) {
if (src == ethAddr) { // if (src == ethAddr) {
destAmt = UniswapExchange(uniswapAddr).ethToTokenSwapInput.value(srcAmt)(uint(0), uint(1899063809)); // destAmt = UniswapExchange(uniswapAddr).ethToTokenSwapInput.value(srcAmt)(uint(0), uint(1899063809));
} else if (dest == ethAddr) { // } else if (dest == ethAddr) {
destAmt = UniswapExchange(uniswapAddr).tokenToEthSwapInput(srcAmt, uint(0), uint(1899063809)); // destAmt = UniswapExchange(uniswapAddr).tokenToEthSwapInput(srcAmt, uint(0), uint(1899063809));
} // }
} // }
} }