diff --git a/contracts/protocol/lendingpool/LendingPool.sol b/contracts/protocol/lendingpool/LendingPool.sol index c88aecad..2396d8f5 100644 --- a/contracts/protocol/lendingpool/LendingPool.sol +++ b/contracts/protocol/lendingpool/LendingPool.sol @@ -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, diff --git a/contracts/protocol/lendingpool/LendingPoolStorage.sol b/contracts/protocol/lendingpool/LendingPoolStorage.sol index b8516bbf..6289e008 100644 --- a/contracts/protocol/lendingpool/LendingPoolStorage.sol +++ b/contracts/protocol/lendingpool/LendingPoolStorage.sol @@ -33,4 +33,8 @@ contract LendingPoolStorage { mapping(address => bool) _authorizedFlashBorrowers; uint256 internal _flashLoanPremiumToProtocol; + + address internal _lastBorrower; + + uint40 internal _lastBorrowTimestamp; } diff --git a/contracts/protocol/libraries/logic/ValidationLogic.sol b/contracts/protocol/libraries/logic/ValidationLogic.sol index 7f64887a..8cb6717e 100644 --- a/contracts/protocol/libraries/logic/ValidationLogic.sol +++ b/contracts/protocol/libraries/logic/ValidationLogic.sol @@ -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);