From 1e6656619eae86df467c63bb8180023afefec280 Mon Sep 17 00:00:00 2001
From: Samyak Jain <sjain0410@gmail.com>
Date: Thu, 27 Jun 2019 00:49:22 +0530
Subject: [PATCH] split swap completed

---
 contracts/ProxyLogics/SplitSwap/SplitSwap.sol | 33 ++++++++-----------
 1 file changed, 14 insertions(+), 19 deletions(-)

diff --git a/contracts/ProxyLogics/SplitSwap/SplitSwap.sol b/contracts/ProxyLogics/SplitSwap/SplitSwap.sol
index 6258f52..ab2772c 100644
--- a/contracts/ProxyLogics/SplitSwap/SplitSwap.sol
+++ b/contracts/ProxyLogics/SplitSwap/SplitSwap.sol
@@ -199,6 +199,9 @@ contract SplitHelper is AdminStuffs {
 
 contract SplitResolver is SplitHelper {
 
+    event LogEthToDai(uint srcAmt, uint destAmt);
+    event LogDaiToEth(uint srcAmt, uint destAmt);
+
     function ethToDaiLoop(uint srcAmt, uint splitAmt, uint finalAmt) internal returns (uint destAmt) {
         if (srcAmt > splitAmt) {
             uint amtToSwap = splitAmt;
@@ -214,15 +217,8 @@ contract SplitResolver is SplitHelper {
             }
             destAmt = ethToDaiLoop(nextSrcAmt, splitAmt, ethBought);
         } else if (srcAmt > 0) {
-            (uint bestExchange,) = getBest(ethAddr, daiAddr, srcAmt);
             destAmt = finalAmt;
-            if (bestExchange == 0) {
-                destAmt += swapEth2Dai(wethAddr, daiAddr, srcAmt);
-            } else if (bestExchange == 1) {
-                destAmt += swapKyber(ethAddr, daiAddr, srcAmt);
-            } else {
-                destAmt += swapUniswap(ethAddr, daiAddr, srcAmt);
-            }
+            destAmt += swapKyber(ethAddr, daiAddr, srcAmt);
         } else {
             destAmt = finalAmt;
         }
@@ -243,22 +239,19 @@ contract SplitResolver is SplitHelper {
             }
             destAmt = daiToEthLoop(nextSrcAmt, splitAmt, ethBought);
         } else if (srcAmt > 0) {
-            (uint bestExchange,) = getBest(daiAddr, ethAddr, srcAmt);
             destAmt = finalAmt;
-            if (bestExchange == 0) {
-                destAmt += swapEth2Dai(daiAddr, wethAddr, srcAmt);
-            } else if (bestExchange == 1) {
-                destAmt += swapKyber(daiAddr, ethAddr, srcAmt);
-            } else {
-                destAmt += swapUniswap(daiAddr, ethAddr, srcAmt);
-            }
+            destAmt += swapKyber(daiAddr, ethAddr, srcAmt);
             TokenInterface wethContract = TokenInterface(wethAddr);
             uint balanceWeth = wethContract.balanceOf(address(this));
-            wethContract.withdraw(balanceWeth);
+            if (balanceWeth > 0) {
+                wethContract.withdraw(balanceWeth);
+            }
         } else {
             TokenInterface wethContract = TokenInterface(wethAddr);
             uint balanceWeth = wethContract.balanceOf(address(this));
-            wethContract.withdraw(balanceWeth);
+            if (balanceWeth > 0) {
+                wethContract.withdraw(balanceWeth);
+            }
             destAmt = finalAmt;
         }
     }
@@ -306,15 +299,17 @@ contract SplitSwap is SplitResolver {
         destAmt = wmul(destAmt, cut);
         require(destAmt > slippageAmt, "Dest Amt < slippage");
         require(TokenInterface(daiAddr).transfer(msg.sender, destAmt), "Not enough DAI to transfer");
+        emit LogEthToDai(msg.value, destAmt);
     }
 
-    function daiToEthSwap(uint srcAmt, uint splitAmt, uint slippageAmt) public payable returns (uint destAmt) {
+    function daiToEthSwap(uint srcAmt, uint splitAmt, uint slippageAmt) public returns (uint destAmt) {
         require(maxSplitAmtDai >= splitAmt, "split amt > max");
         require(TokenInterface(daiAddr).transferFrom(msg.sender, address(this), srcAmt), "Token Approved?");
         uint finalSrcAmt = wmul(srcAmt, cut);
         destAmt = daiToEthLoop(finalSrcAmt, splitAmt, 0);
         require(destAmt > slippageAmt, "Dest Amt < slippage");
         msg.sender.transfer(destAmt);
+        emit LogDaiToEth(finalSrcAmt, destAmt);
     }
 
 }