mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Revert "add withFlash flage to getAmountIn/Out"
This reverts commit 3d2a877770
.
This commit is contained in:
parent
46c753cea1
commit
63ce8bc2bb
|
@ -63,8 +63,7 @@ abstract contract BaseUniswapAdapter is FlashLoanReceiverBase, IBaseUniswapAdapt
|
||||||
function getAmountsOut(
|
function getAmountsOut(
|
||||||
uint256 amountIn,
|
uint256 amountIn,
|
||||||
address reserveIn,
|
address reserveIn,
|
||||||
address reserveOut,
|
address reserveOut
|
||||||
bool withFlash
|
|
||||||
)
|
)
|
||||||
external
|
external
|
||||||
view
|
view
|
||||||
|
@ -77,7 +76,7 @@ abstract contract BaseUniswapAdapter is FlashLoanReceiverBase, IBaseUniswapAdapt
|
||||||
address[] memory
|
address[] memory
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
AmountCalc memory results = _getAmountsOutData(reserveIn, reserveOut, amountIn, withFlash);
|
AmountCalc memory results = _getAmountsOutData(reserveIn, reserveOut, amountIn);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
results.calculatedAmount,
|
results.calculatedAmount,
|
||||||
|
@ -101,8 +100,7 @@ abstract contract BaseUniswapAdapter is FlashLoanReceiverBase, IBaseUniswapAdapt
|
||||||
function getAmountsIn(
|
function getAmountsIn(
|
||||||
uint256 amountOut,
|
uint256 amountOut,
|
||||||
address reserveIn,
|
address reserveIn,
|
||||||
address reserveOut,
|
address reserveOut
|
||||||
bool withFlash
|
|
||||||
)
|
)
|
||||||
external
|
external
|
||||||
view
|
view
|
||||||
|
@ -115,7 +113,7 @@ abstract contract BaseUniswapAdapter is FlashLoanReceiverBase, IBaseUniswapAdapt
|
||||||
address[] memory
|
address[] memory
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
AmountCalc memory results = _getAmountsInData(reserveIn, reserveOut, amountOut, withFlash);
|
AmountCalc memory results = _getAmountsInData(reserveIn, reserveOut, amountOut);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
results.calculatedAmount,
|
results.calculatedAmount,
|
||||||
|
@ -318,14 +316,6 @@ abstract contract BaseUniswapAdapter is FlashLoanReceiverBase, IBaseUniswapAdapt
|
||||||
return amount.mul(reservePrice).div(10**decimals).mul(ethUsdPrice).div(10**18);
|
return amount.mul(reservePrice).div(10**decimals).mul(ethUsdPrice).div(10**18);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct AmountOutVars {
|
|
||||||
uint256 finalAmountIn;
|
|
||||||
address[] simplePath;
|
|
||||||
uint256[] amountsWithoutWeth;
|
|
||||||
uint256[] amountsWithWeth;
|
|
||||||
address[] pathWithWeth;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Given an input asset amount, returns the maximum output amount of the other asset
|
* @dev Given an input asset amount, returns the maximum output amount of the other asset
|
||||||
* @param reserveIn Address of the asset to be swap from
|
* @param reserveIn Address of the asset to be swap from
|
||||||
|
@ -340,55 +330,54 @@ abstract contract BaseUniswapAdapter is FlashLoanReceiverBase, IBaseUniswapAdapt
|
||||||
function _getAmountsOutData(
|
function _getAmountsOutData(
|
||||||
address reserveIn,
|
address reserveIn,
|
||||||
address reserveOut,
|
address reserveOut,
|
||||||
uint256 amountIn,
|
uint256 amountIn
|
||||||
bool withFlash
|
|
||||||
) internal view returns (AmountCalc memory) {
|
) internal view returns (AmountCalc memory) {
|
||||||
AmountOutVars memory vars;
|
|
||||||
// Subtract flash loan fee
|
// Subtract flash loan fee
|
||||||
vars.finalAmountIn = amountIn.sub(
|
uint256 finalAmountIn = amountIn.sub(amountIn.mul(FLASHLOAN_PREMIUM_TOTAL).div(10000));
|
||||||
withFlash ? amountIn.mul(FLASHLOAN_PREMIUM_TOTAL).div(10000) : 0
|
|
||||||
);
|
|
||||||
|
|
||||||
vars.simplePath = new address[](2);
|
address[] memory simplePath = new address[](2);
|
||||||
vars.simplePath[0] = reserveIn;
|
simplePath[0] = reserveIn;
|
||||||
vars.simplePath[1] = reserveOut;
|
simplePath[1] = reserveOut;
|
||||||
|
|
||||||
vars.pathWithWeth = new address[](3);
|
uint256[] memory amountsWithoutWeth;
|
||||||
|
uint256[] memory amountsWithWeth;
|
||||||
|
|
||||||
|
address[] memory pathWithWeth = new address[](3);
|
||||||
if (reserveIn != WETH_ADDRESS && reserveOut != WETH_ADDRESS) {
|
if (reserveIn != WETH_ADDRESS && reserveOut != WETH_ADDRESS) {
|
||||||
vars.pathWithWeth[0] = reserveIn;
|
pathWithWeth[0] = reserveIn;
|
||||||
vars.pathWithWeth[1] = WETH_ADDRESS;
|
pathWithWeth[1] = WETH_ADDRESS;
|
||||||
vars.pathWithWeth[2] = reserveOut;
|
pathWithWeth[2] = reserveOut;
|
||||||
|
|
||||||
try UNISWAP_ROUTER.getAmountsOut(vars.finalAmountIn, vars.pathWithWeth) returns (
|
try UNISWAP_ROUTER.getAmountsOut(finalAmountIn, pathWithWeth) returns (
|
||||||
uint256[] memory resultsWithWeth
|
uint256[] memory resultsWithWeth
|
||||||
) {
|
) {
|
||||||
vars.amountsWithWeth = resultsWithWeth;
|
amountsWithWeth = resultsWithWeth;
|
||||||
} catch {
|
} catch {
|
||||||
vars.amountsWithWeth = new uint256[](3);
|
amountsWithWeth = new uint256[](3);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
vars.amountsWithWeth = new uint256[](3);
|
amountsWithWeth = new uint256[](3);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint256 bestAmountOut;
|
uint256 bestAmountOut;
|
||||||
try UNISWAP_ROUTER.getAmountsOut(vars.finalAmountIn, vars.simplePath) returns (
|
try UNISWAP_ROUTER.getAmountsOut(finalAmountIn, simplePath) returns (
|
||||||
uint256[] memory resultAmounts
|
uint256[] memory resultAmounts
|
||||||
) {
|
) {
|
||||||
vars.amountsWithoutWeth = resultAmounts;
|
amountsWithoutWeth = resultAmounts;
|
||||||
|
|
||||||
bestAmountOut = (vars.amountsWithWeth[2] > vars.amountsWithoutWeth[1])
|
bestAmountOut = (amountsWithWeth[2] > amountsWithoutWeth[1])
|
||||||
? vars.amountsWithWeth[2]
|
? amountsWithWeth[2]
|
||||||
: vars.amountsWithoutWeth[1];
|
: amountsWithoutWeth[1];
|
||||||
} catch {
|
} catch {
|
||||||
vars.amountsWithoutWeth = new uint256[](2);
|
amountsWithoutWeth = new uint256[](2);
|
||||||
bestAmountOut = vars.amountsWithWeth[2];
|
bestAmountOut = amountsWithWeth[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
uint256 reserveInDecimals = _getDecimals(reserveIn);
|
uint256 reserveInDecimals = _getDecimals(reserveIn);
|
||||||
uint256 reserveOutDecimals = _getDecimals(reserveOut);
|
uint256 reserveOutDecimals = _getDecimals(reserveOut);
|
||||||
|
|
||||||
uint256 outPerInPrice =
|
uint256 outPerInPrice =
|
||||||
vars.finalAmountIn.mul(10**18).mul(10**reserveOutDecimals).div(
|
finalAmountIn.mul(10**18).mul(10**reserveOutDecimals).div(
|
||||||
bestAmountOut.mul(10**reserveInDecimals)
|
bestAmountOut.mul(10**reserveInDecimals)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -398,9 +387,9 @@ abstract contract BaseUniswapAdapter is FlashLoanReceiverBase, IBaseUniswapAdapt
|
||||||
outPerInPrice,
|
outPerInPrice,
|
||||||
_calcUsdValue(reserveIn, amountIn, reserveInDecimals),
|
_calcUsdValue(reserveIn, amountIn, reserveInDecimals),
|
||||||
_calcUsdValue(reserveOut, bestAmountOut, reserveOutDecimals),
|
_calcUsdValue(reserveOut, bestAmountOut, reserveOutDecimals),
|
||||||
(bestAmountOut == 0) ? new address[](2) : (bestAmountOut == vars.amountsWithoutWeth[1])
|
(bestAmountOut == 0) ? new address[](2) : (bestAmountOut == amountsWithoutWeth[1])
|
||||||
? vars.simplePath
|
? simplePath
|
||||||
: vars.pathWithWeth
|
: pathWithWeth
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -418,15 +407,13 @@ abstract contract BaseUniswapAdapter is FlashLoanReceiverBase, IBaseUniswapAdapt
|
||||||
function _getAmountsInData(
|
function _getAmountsInData(
|
||||||
address reserveIn,
|
address reserveIn,
|
||||||
address reserveOut,
|
address reserveOut,
|
||||||
uint256 amountOut,
|
uint256 amountOut
|
||||||
bool withFlash
|
|
||||||
) internal view returns (AmountCalc memory) {
|
) internal view returns (AmountCalc memory) {
|
||||||
(uint256[] memory amounts, address[] memory path) =
|
(uint256[] memory amounts, address[] memory path) =
|
||||||
_getAmountsInAndPath(reserveIn, reserveOut, amountOut);
|
_getAmountsInAndPath(reserveIn, reserveOut, amountOut);
|
||||||
|
|
||||||
// Add flash loan fee
|
// Add flash loan fee
|
||||||
uint256 finalAmountIn =
|
uint256 finalAmountIn = amounts[0].add(amounts[0].mul(FLASHLOAN_PREMIUM_TOTAL).div(10000));
|
||||||
amounts[0].add(withFlash ? amounts[0].mul(FLASHLOAN_PREMIUM_TOTAL).div(10000) : 0);
|
|
||||||
|
|
||||||
uint256 reserveInDecimals = _getDecimals(reserveIn);
|
uint256 reserveInDecimals = _getDecimals(reserveIn);
|
||||||
uint256 reserveOutDecimals = _getDecimals(reserveOut);
|
uint256 reserveOutDecimals = _getDecimals(reserveOut);
|
||||||
|
|
|
@ -50,8 +50,7 @@ interface IBaseUniswapAdapter {
|
||||||
function getAmountsOut(
|
function getAmountsOut(
|
||||||
uint256 amountIn,
|
uint256 amountIn,
|
||||||
address reserveIn,
|
address reserveIn,
|
||||||
address reserveOut,
|
address reserveOut
|
||||||
bool withFlash
|
|
||||||
)
|
)
|
||||||
external
|
external
|
||||||
view
|
view
|
||||||
|
@ -77,8 +76,7 @@ interface IBaseUniswapAdapter {
|
||||||
function getAmountsIn(
|
function getAmountsIn(
|
||||||
uint256 amountOut,
|
uint256 amountOut,
|
||||||
address reserveIn,
|
address reserveIn,
|
||||||
address reserveOut,
|
address reserveOut
|
||||||
bool withFlash
|
|
||||||
)
|
)
|
||||||
external
|
external
|
||||||
view
|
view
|
||||||
|
|
|
@ -19,6 +19,10 @@ task(`deploy-${CONTRACT_NAME}`, `Deploys the ${CONTRACT_NAME} contract`)
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`\n- ${CONTRACT_NAME} deployment`);
|
console.log(`\n- ${CONTRACT_NAME} deployment`);
|
||||||
|
// const args = [
|
||||||
|
// '0x88757f2f99175387aB4C6a4b3067c77A695b0349', // lending provider kovan address
|
||||||
|
// '0xfcd87315f0e4067070ade8682fcdbc3006631441', // uniswap router address
|
||||||
|
// ];
|
||||||
const uniswapRepayAdapter = await new UniswapRepayAdapterFactory(await getFirstSigner()).deploy(
|
const uniswapRepayAdapter = await new UniswapRepayAdapterFactory(await getFirstSigner()).deploy(
|
||||||
provider,
|
provider,
|
||||||
router,
|
router,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user