mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
- Fixed calculation on _getAmountsOutData().
- Optimizing outcome of _getAmountsInAndPath().
This commit is contained in:
parent
1fec2aa5d1
commit
ab5303bc7c
|
@ -342,22 +342,23 @@ abstract contract BaseUniswapAdapter is FlashLoanReceiverBase, IBaseUniswapAdapt
|
||||||
uint256[] memory amountsWithWeth;
|
uint256[] memory amountsWithWeth;
|
||||||
|
|
||||||
address[] memory pathWithWeth = new address[](3);
|
address[] memory pathWithWeth = new address[](3);
|
||||||
|
pathWithWeth[0] = reserveIn;
|
||||||
|
pathWithWeth[1] = WETH_ADDRESS;
|
||||||
|
pathWithWeth[2] = reserveOut;
|
||||||
|
amountsWithWeth = UNISWAP_ROUTER.getAmountsOut(finalAmountIn, pathWithWeth);
|
||||||
|
|
||||||
|
uint256 bestAmountOut;
|
||||||
try UNISWAP_ROUTER.getAmountsOut(finalAmountIn, simplePath) returns (
|
try UNISWAP_ROUTER.getAmountsOut(finalAmountIn, simplePath) returns (
|
||||||
uint256[] memory resultAmounts
|
uint256[] memory resultAmounts
|
||||||
) {
|
) {
|
||||||
amountsWithoutWeth = resultAmounts;
|
amountsWithoutWeth = resultAmounts;
|
||||||
} catch {
|
|
||||||
pathWithWeth[0] = reserveIn;
|
|
||||||
pathWithWeth[1] = WETH_ADDRESS;
|
|
||||||
pathWithWeth[2] = reserveOut;
|
|
||||||
|
|
||||||
amountsWithWeth = UNISWAP_ROUTER.getAmountsOut(finalAmountIn, pathWithWeth);
|
bestAmountOut = (amountsWithWeth[2] > amountsWithoutWeth[1])
|
||||||
}
|
|
||||||
|
|
||||||
uint256 bestAmountOut =
|
|
||||||
(amountsWithWeth.length > 0 && amountsWithWeth[2] > amountsWithoutWeth[1])
|
|
||||||
? amountsWithWeth[2]
|
? amountsWithWeth[2]
|
||||||
: amountsWithoutWeth[1];
|
: amountsWithoutWeth[1];
|
||||||
|
} catch {
|
||||||
|
bestAmountOut = amountsWithWeth[2];
|
||||||
|
}
|
||||||
|
|
||||||
uint256 reserveInDecimals = _getDecimals(reserveIn);
|
uint256 reserveInDecimals = _getDecimals(reserveIn);
|
||||||
uint256 reserveOutDecimals = _getDecimals(reserveOut);
|
uint256 reserveOutDecimals = _getDecimals(reserveOut);
|
||||||
|
@ -433,20 +434,26 @@ abstract contract BaseUniswapAdapter is FlashLoanReceiverBase, IBaseUniswapAdapt
|
||||||
simplePath[0] = reserveIn;
|
simplePath[0] = reserveIn;
|
||||||
simplePath[1] = reserveOut;
|
simplePath[1] = reserveOut;
|
||||||
|
|
||||||
uint256[] memory amounts;
|
uint256[] memory amountsWithoutWeth;
|
||||||
|
uint256[] memory amountsWithWeth;
|
||||||
|
|
||||||
address[] memory pathWithWeth = new address[](3);
|
address[] memory pathWithWeth = new address[](3);
|
||||||
try UNISWAP_ROUTER.getAmountsIn(amountOut, simplePath) returns (
|
|
||||||
uint256[] memory resultAmounts
|
|
||||||
) {
|
|
||||||
amounts = resultAmounts;
|
|
||||||
return (amounts, simplePath);
|
|
||||||
} catch {
|
|
||||||
pathWithWeth[0] = reserveIn;
|
pathWithWeth[0] = reserveIn;
|
||||||
pathWithWeth[1] = WETH_ADDRESS;
|
pathWithWeth[1] = WETH_ADDRESS;
|
||||||
pathWithWeth[2] = reserveOut;
|
pathWithWeth[2] = reserveOut;
|
||||||
|
amountsWithWeth = UNISWAP_ROUTER.getAmountsIn(amountOut, pathWithWeth);
|
||||||
|
|
||||||
amounts = UNISWAP_ROUTER.getAmountsIn(amountOut, pathWithWeth);
|
try UNISWAP_ROUTER.getAmountsIn(amountOut, simplePath) returns (
|
||||||
return (amounts, pathWithWeth);
|
uint256[] memory resultAmounts
|
||||||
|
) {
|
||||||
|
amountsWithoutWeth = resultAmounts;
|
||||||
|
|
||||||
|
return
|
||||||
|
(amountsWithWeth[2] > amountsWithoutWeth[1])
|
||||||
|
? (amountsWithWeth, pathWithWeth)
|
||||||
|
: (amountsWithoutWeth, simplePath);
|
||||||
|
} catch {
|
||||||
|
return (amountsWithWeth, pathWithWeth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user