feat: added storage and check that repayer is not the last borrower of a reserve

This commit is contained in:
Hadrien Charlanes 2021-06-21 12:25:33 +02:00
parent 6a69a00372
commit 09233d09bf
3 changed files with 13 additions and 2 deletions

View File

@ -240,7 +240,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
///@inheritdoc ILendingPool
function rebalanceStableBorrowRate(address asset, address user) external override whenNotPaused {
DataTypes.ReserveData storage reserve = _reserves[asset];
DataTypes.ReserveCache memory reserveCache = reserve.cache();
@ -793,6 +792,9 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
vars.releaseUnderlying ? vars.amount : 0
);
_lastBorrower = vars.user;
_lastBorrowTimestamp = uint40(block.timestamp);
if (vars.releaseUnderlying) {
IAToken(reserveCache.aTokenAddress).transferUnderlyingTo(vars.user, vars.amount);
}
@ -908,6 +910,8 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
DataTypes.InterestRateMode interestRateMode = DataTypes.InterestRateMode(rateMode);
ValidationLogic.validateRepay(
_lastBorrower,
_lastBorrowTimestamp,
reserveCache,
amount,
interestRateMode,

View File

@ -33,4 +33,8 @@ contract LendingPoolStorage {
mapping(address => bool) _authorizedFlashBorrowers;
uint256 internal _flashLoanPremiumToProtocol;
address internal _lastBorrower;
uint40 internal _lastBorrowTimestamp;
}

View File

@ -255,6 +255,8 @@ library ValidationLogic {
* @param variableDebt The borrow balance of the user
*/
function validateRepay(
address lastBorrower,
uint40 lastBorrowTimestamp,
DataTypes.ReserveCache memory reserveCache,
uint256 amountSent,
DataTypes.InterestRateMode rateMode,
@ -268,6 +270,8 @@ library ValidationLogic {
require(amountSent > 0, Errors.VL_INVALID_AMOUNT);
require(lastBorrower != onBehalfOf || lastBorrowTimestamp != uint40(block.timestamp));
require(
(stableDebt > 0 &&
DataTypes.InterestRateMode(rateMode) == DataTypes.InterestRateMode.STABLE) ||
@ -347,7 +351,6 @@ library ValidationLogic {
IERC20 variableDebtToken,
address aTokenAddress
) external view {
// to avoid potential abuses using flashloans, the rebalance stable rate must happen through an EOA
require(!address(msg.sender).isContract(), Errors.LP_CALLER_NOT_EOA);