From 6cebf50f1114e39daa302e372c92bea3307903df Mon Sep 17 00:00:00 2001 From: andyk Date: Thu, 21 Jan 2021 17:44:48 +0300 Subject: [PATCH 1/2] add special quotation flow --- contracts/adapters/BaseUniswapAdapter.sol | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/contracts/adapters/BaseUniswapAdapter.sol b/contracts/adapters/BaseUniswapAdapter.sol index b04bc8a1..cb277f2c 100644 --- a/contracts/adapters/BaseUniswapAdapter.sol +++ b/contracts/adapters/BaseUniswapAdapter.sol @@ -346,6 +346,18 @@ abstract contract BaseUniswapAdapter is FlashLoanReceiverBase, IBaseUniswapAdapt // Subtract flash loan fee uint256 finalAmountIn = amountIn.sub(amountIn.mul(FLASHLOAN_PREMIUM_TOTAL).div(10000)); + if (reserveIn == reserveOut) { + uint256 reserveDecimals = _getDecimals(reserveIn); + return + AmountCalc( + finalAmountIn, + finalAmountIn.mul(10**18).div(amountIn), + _calcUsdValue(reserveIn, amountIn, reserveDecimals), + _calcUsdValue(reserveIn, finalAmountIn, reserveDecimals), + [reserveIn] + ); + } + address[] memory simplePath = new address[](2); simplePath[0] = reserveIn; simplePath[1] = reserveOut; @@ -420,6 +432,20 @@ abstract contract BaseUniswapAdapter is FlashLoanReceiverBase, IBaseUniswapAdapt address reserveOut, uint256 amountOut ) internal view returns (AmountCalc memory) { + if (reserveIn == reserveOut) { + // Add flash loan fee + uint256 amountIn = amountOut.add(amountOut.mul(FLASHLOAN_PREMIUM_TOTAL).div(10000)); + uint256 reserveDecimals = _getDecimals(reserveIn); + return + AmountCalc( + amountIn, + amountOut.mul(10**18).div(amountIn), + _calcUsdValue(reserveIn, amountIn, reserveDecimals), + _calcUsdValue(reserveIn, amountOut, reserveDecimals), + [reserveIn] + ); + } + (uint256[] memory amounts, address[] memory path) = _getAmountsInAndPath(reserveIn, reserveOut, amountOut); From d6059938bbf855d504097a24f448aa5356ea83c1 Mon Sep 17 00:00:00 2001 From: eboado Date: Mon, 25 Jan 2021 09:29:07 +0100 Subject: [PATCH 2/2] - Fixed array init on BaseUniswapAdapter --- contracts/adapters/BaseUniswapAdapter.sol | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/contracts/adapters/BaseUniswapAdapter.sol b/contracts/adapters/BaseUniswapAdapter.sol index cb277f2c..1a962473 100644 --- a/contracts/adapters/BaseUniswapAdapter.sol +++ b/contracts/adapters/BaseUniswapAdapter.sol @@ -348,13 +348,16 @@ abstract contract BaseUniswapAdapter is FlashLoanReceiverBase, IBaseUniswapAdapt if (reserveIn == reserveOut) { uint256 reserveDecimals = _getDecimals(reserveIn); + address[] memory path = new address[](1); + path[0] = reserveIn; + return AmountCalc( finalAmountIn, finalAmountIn.mul(10**18).div(amountIn), _calcUsdValue(reserveIn, amountIn, reserveDecimals), _calcUsdValue(reserveIn, finalAmountIn, reserveDecimals), - [reserveIn] + path ); } @@ -436,13 +439,16 @@ abstract contract BaseUniswapAdapter is FlashLoanReceiverBase, IBaseUniswapAdapt // Add flash loan fee uint256 amountIn = amountOut.add(amountOut.mul(FLASHLOAN_PREMIUM_TOTAL).div(10000)); uint256 reserveDecimals = _getDecimals(reserveIn); + address[] memory path = new address[](1); + path[0] = reserveIn; + return AmountCalc( amountIn, amountOut.mul(10**18).div(amountIn), _calcUsdValue(reserveIn, amountIn, reserveDecimals), _calcUsdValue(reserveIn, amountOut, reserveDecimals), - [reserveIn] + path ); }