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
*/
function getAddressSplitSwap() public pure returns (address payable splitSwap) {
splitSwap = 0x7CFB3DFb0F7eEE91576eb492FF964B1B59be0713;
splitSwap = 0xdAA26F94C5185538830A84eF3B533743afD4baad;
}
/**
@ -484,10 +484,12 @@ contract Save is GetDetails {
colToFree = colToSwap;
}
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);
emit LogSaveCDP(cdpID, colToFree, destAmt);
emit LogSaveCDP(cdpID, ethToSwap, destAmt);
}
function leverage(

View File

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