From 7a5a64f477d9d99055b4480a39783576c6f88618 Mon Sep 17 00:00:00 2001 From: Mark van Voorden Date: Thu, 8 Oct 2020 15:42:51 +0200 Subject: [PATCH 1/2] Changed swap functionality to always use WETH as an intermediary for token to token transactions. --- assets/scripts/uniswapOps.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/assets/scripts/uniswapOps.js b/assets/scripts/uniswapOps.js index c8caa87..e62e85c 100644 --- a/assets/scripts/uniswapOps.js +++ b/assets/scripts/uniswapOps.js @@ -399,21 +399,30 @@ ${fixedInflation.swapCouples.map((it, i) => ` stateHolder.setAddress("fix from.approve(address(uniswapV2Router), 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff); } } - address[] memory path = new address[](2); - path[0] = fromAddress; - path[1] = stateHolder.getAddress(string(abi.encodePacked("fixedInflation.swapCouples[", iString, "].to"))); - if(path[1] == address(0)) { + address toAddress = stateHolder.getAddress(string(abi.encodePacked("fixedInflation.swapCouples[", iString, "].to"))); + if(toAddress == address(0)) { return; } - if(path[0] == wethAddress) { + if(fromAddress == wethAddress) { + address[] memory path = new address[](2); + path[0] = fromAddress; + path[1] = toAddress; uniswapV2Router.swapExactETHForTokens{value: amount}(uniswapV2Router.getAmountsOut(amount, path)[1], path, dfoWalletAddress, block.timestamp + 1000); return; } if(path[1] == wethAddress) { + address[] memory path = new address[](2); + path[0] = fromAddress; + path[1] = toAddress; uniswapV2Router.swapExactTokensForETH(amount, uniswapV2Router.getAmountsOut(amount, path)[1], path, dfoWalletAddress, block.timestamp + 1000); return; } - uniswapV2Router.swapExactTokensForTokens(amount, uniswapV2Router.getAmountsOut(amount, path)[1], path, dfoWalletAddress, block.timestamp + 1000); + // force swap to go through WETH + address[] memory path = new address[](3); + path[0] = fromAddress; + path[1] = wethAddress; + path[2] = toAddress; + uniswapV2Router.swapExactTokensForTokens(amount, uniswapV2Router.getAmountsOut(amount, path)[2], path, dfoWalletAddress, block.timestamp + 1000); } function _toUint256(bytes memory bs) private pure returns(uint256 x) { @@ -747,4 +756,4 @@ interface IStateHolder { functionalityReplace: '', functionalityOutputParameters: '[]', }, window.context.oneTimeProposalTemplate, lines, descriptions, undefined, undefined, postFixedLines); -}; \ No newline at end of file +}; From 152412bcb09ef5bcf41f203958fce758448d8d9c Mon Sep 17 00:00:00 2001 From: Mark van Voorden Date: Thu, 8 Oct 2020 16:28:39 +0200 Subject: [PATCH 2/2] Changed swap functionality to always use WETH as an intermediary for token to token transfers --- assets/scripts/uniswapOps.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/scripts/uniswapOps.js b/assets/scripts/uniswapOps.js index e62e85c..8a8b4b5 100644 --- a/assets/scripts/uniswapOps.js +++ b/assets/scripts/uniswapOps.js @@ -417,9 +417,9 @@ ${fixedInflation.swapCouples.map((it, i) => ` stateHolder.setAddress("fix uniswapV2Router.swapExactTokensForETH(amount, uniswapV2Router.getAmountsOut(amount, path)[1], path, dfoWalletAddress, block.timestamp + 1000); return; } - // force swap to go through WETH + // force swap to go through WETH address[] memory path = new address[](3); - path[0] = fromAddress; + path[0] = fromAddress; path[1] = wethAddress; path[2] = toAddress; uniswapV2Router.swapExactTokensForTokens(amount, uniswapV2Router.getAmountsOut(amount, path)[2], path, dfoWalletAddress, block.timestamp + 1000);