diff --git a/contracts/protocol/lendingpool/LendingPool.sol b/contracts/protocol/lendingpool/LendingPool.sol index 4bfe23f9..6e1810df 100644 --- a/contracts/protocol/lendingpool/LendingPool.sol +++ b/contracts/protocol/lendingpool/LendingPool.sol @@ -781,8 +781,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage vars.releaseUnderlying ? vars.amount : 0 ); - _lastBorrower = vars.user; - _lastBorrowTimestamp = uint40(block.timestamp); + _usersLastBorrowTimestamp[vars.asset][vars.user] = block.timestamp; if (vars.releaseUnderlying) { IAToken(reserveCache.aTokenAddress).transferUnderlyingTo(vars.user, vars.amount); @@ -901,14 +900,14 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage DataTypes.InterestRateMode interestRateMode = DataTypes.InterestRateMode(rateMode); ValidationLogic.validateRepay( - _lastBorrower, - _lastBorrowTimestamp, reserveCache, + asset, amount, interestRateMode, onBehalfOf, stableDebt, - variableDebt + variableDebt, + _usersLastBorrowTimestamp ); uint256 paybackAmount = diff --git a/contracts/protocol/lendingpool/LendingPoolStorage.sol b/contracts/protocol/lendingpool/LendingPoolStorage.sol index c791e3cf..8a080995 100644 --- a/contracts/protocol/lendingpool/LendingPoolStorage.sol +++ b/contracts/protocol/lendingpool/LendingPoolStorage.sol @@ -36,7 +36,6 @@ contract LendingPoolStorage { uint256 internal _flashLoanPremiumToProtocol; - address internal _lastBorrower; + mapping(address => mapping(address => uint256)) _usersLastBorrowTimestamp; - uint40 internal _lastBorrowTimestamp; } diff --git a/contracts/protocol/libraries/logic/ValidationLogic.sol b/contracts/protocol/libraries/logic/ValidationLogic.sol index 10b7a4f5..1310a591 100644 --- a/contracts/protocol/libraries/logic/ValidationLogic.sol +++ b/contracts/protocol/libraries/logic/ValidationLogic.sol @@ -249,21 +249,23 @@ library ValidationLogic { /** * @dev Validates a repay action * @param reserveCache The cached data of the reserve + * @param asset The asset address * @param amountSent The amount sent for the repayment. Can be an actual value or uint(-1) * @param rateMode the interest rate mode of the debt being repaid * @param onBehalfOf The address of the user msg.sender is repaying for * @param stableDebt The borrow balance of the user * @param variableDebt The borrow balance of the user + * @param lastUsersBorrowTimestamp The data structure that keeps track of all the latest borrowings from the users */ function validateRepay( - address lastBorrower, - uint40 lastBorrowTimestamp, DataTypes.ReserveCache memory reserveCache, + address asset, uint256 amountSent, DataTypes.InterestRateMode rateMode, address onBehalfOf, uint256 stableDebt, - uint256 variableDebt + uint256 variableDebt, + mapping(address => mapping(address => uint256)) storage lastUsersBorrowTimestamp ) external view { (bool isActive, , , , bool isPaused) = reserveCache.reserveConfiguration.getFlagsMemory(); require(isActive, Errors.VL_NO_ACTIVE_RESERVE); @@ -272,7 +274,7 @@ library ValidationLogic { require(amountSent > 0, Errors.VL_INVALID_AMOUNT); require( - lastBorrower != onBehalfOf || lastBorrowTimestamp != uint40(block.timestamp), + lastUsersBorrowTimestamp[asset][onBehalfOf] != uint40(block.timestamp), Errors.VL_SAME_BLOCK_BORROW_REPAY );