Merge branch 'master' into feat/light-deployments-update

This commit is contained in:
Zer0dot 2021-02-05 10:01:26 -05:00
commit 6a2d383c94
5 changed files with 60 additions and 19 deletions

View File

@ -34,6 +34,7 @@ A more detailed and technical description of the protocol can be found in this r
- CertiK (28/09/2020 - 02/12/2020): [report](./audits/Certik-aave-v2-03-12-2020.pdf)
- Consensys Diligence (09/09/2020 - 09/10/2020): [report](https://consensys.net/diligence/audits/2020/09/aave-protocol-v2/)
- Certora, formal verification (02/08/2020 - 29/10/2020): [report](./audits/Certora-FV-aave-v2-03-12-2020.pdf)
- SigmaPrime (January 2021): [report](./audits/SigmaPrime-aave-v2-01-2021.pdf)
## Connect with the community

Binary file not shown.

View File

@ -24,6 +24,7 @@ import {IBaseUniswapAdapter} from './interfaces/IBaseUniswapAdapter.sol';
abstract contract BaseUniswapAdapter is FlashLoanReceiverBase, IBaseUniswapAdapter, Ownable {
using SafeMath for uint256;
using PercentageMath for uint256;
using SafeERC20 for IERC20;
// Max slippage percent allowed
@ -346,6 +347,20 @@ 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 _reserveIn = new address[](1);
_reserveIn[0] = 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 +435,22 @@ 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 _reserveIn = new address[](1);
_reserveIn[0] = 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);

View File

@ -187,16 +187,16 @@ contract UniswapLiquiditySwapAdapter is BaseUniswapAdapter {
* @param permitSignature List of struct containing the permit signature
* @param useEthPath true if the swap needs to occur using ETH in the routing, false otherwise
*/
struct SwapLiquidityLocalVars {
address aToken;
uint256 aTokenInitiatorBalance;
uint256 amountToSwap;
uint256 receivedAmount;
uint256 flashLoanDebt;
uint256 amountToPull;
address aToken;
uint256 aTokenInitiatorBalance;
uint256 amountToSwap;
uint256 receivedAmount;
uint256 flashLoanDebt;
uint256 amountToPull;
}
function _swapLiquidity(
address assetFrom,
address assetTo,
@ -208,19 +208,22 @@ contract UniswapLiquiditySwapAdapter is BaseUniswapAdapter {
PermitSignature memory permitSignature,
bool useEthPath
) internal {
SwapLiquidityLocalVars memory vars;
vars.aToken = _getReserveData(assetFrom).aTokenAddress;
vars.aTokenInitiatorBalance = IERC20(vars.aToken).balanceOf(initiator);
vars.amountToSwap =
swapAllBalance && vars.aTokenInitiatorBalance.sub(premium) <= amount
? vars.aTokenInitiatorBalance.sub(premium)
: amount;
vars.amountToSwap = swapAllBalance && vars.aTokenInitiatorBalance.sub(premium) <= amount
? vars.aTokenInitiatorBalance.sub(premium)
: amount;
vars.receivedAmount =
_swapExactTokensForTokens(assetFrom, assetTo, vars.amountToSwap, minAmountToReceive, useEthPath);
vars.receivedAmount = _swapExactTokensForTokens(
assetFrom,
assetTo,
vars.amountToSwap,
minAmountToReceive,
useEthPath
);
// Deposit new reserve
IERC20(assetTo).safeApprove(address(LENDING_POOL), 0);
@ -277,4 +280,4 @@ contract UniswapLiquiditySwapAdapter is BaseUniswapAdapter {
useEthPath
);
}
}
}

View File

@ -200,7 +200,13 @@ contract UniswapRepayAdapter is BaseUniswapAdapter {
);
// Swap collateral asset to the debt asset
_swapTokensForExactTokens(collateralAsset, debtAsset, amounts[0], neededForFlashLoanDebt, useEthPath);
_swapTokensForExactTokens(
collateralAsset,
debtAsset,
amounts[0],
neededForFlashLoanDebt,
useEthPath
);
} else {
// Pull aTokens from user
_pullAToken(
@ -256,4 +262,4 @@ contract UniswapRepayAdapter is BaseUniswapAdapter {
useEthPath
);
}
}
}