diff --git a/contracts/adapters/BaseUniswapAdapter.sol b/contracts/adapters/BaseUniswapAdapter.sol index b04bc8a1..1a962473 100644 --- a/contracts/adapters/BaseUniswapAdapter.sol +++ b/contracts/adapters/BaseUniswapAdapter.sol @@ -346,6 +346,21 @@ 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); + 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), + path + ); + } + address[] memory simplePath = new address[](2); simplePath[0] = reserveIn; simplePath[1] = reserveOut; @@ -420,6 +435,23 @@ 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); + 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), + path + ); + } + (uint256[] memory amounts, address[] memory path) = _getAmountsInAndPath(reserveIn, reserveOut, amountOut);