From 796dc8ee3fbf5beca24aaa3dcc798966ffd47107 Mon Sep 17 00:00:00 2001 From: The3D Date: Fri, 21 Aug 2020 19:10:48 +0200 Subject: [PATCH] Updated repay function --- contracts/flashloan/base/FlashLoanReceiverBase.sol | 2 +- contracts/lendingpool/LendingPool.sol | 6 ++++-- contracts/libraries/logic/ValidationLogic.sol | 12 ++++++------ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/contracts/flashloan/base/FlashLoanReceiverBase.sol b/contracts/flashloan/base/FlashLoanReceiverBase.sol index 9bccc014..c4aaecd6 100644 --- a/contracts/flashloan/base/FlashLoanReceiverBase.sol +++ b/contracts/flashloan/base/FlashLoanReceiverBase.sol @@ -20,7 +20,7 @@ abstract contract FlashLoanReceiverBase is IFlashLoanReceiver { receive() external payable {} - function transferFundsBackInternal( + function _transferFundsBack( address reserve, address destination, uint256 amount diff --git a/contracts/lendingpool/LendingPool.sol b/contracts/lendingpool/LendingPool.sol index d51f2e2a..bfbe9546 100644 --- a/contracts/lendingpool/LendingPool.sol +++ b/contracts/lendingpool/LendingPool.sol @@ -239,12 +239,14 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool { ) external override nonReentrant { ReserveLogic.ReserveData storage reserve = _reserves[asset]; + (uint256 stableDebt, uint256 variableDebt) = Helpers.getUserCurrentDebt(_onBehalfOf, reserve); + ReserveLogic.InterestRateMode rateMode = ReserveLogic.InterestRateMode(_rateMode); //default to max amount uint256 paybackAmount = rateMode == ReserveLogic.InterestRateMode.STABLE - ? IERC20(reserve.stableDebtTokenAddress).balanceOf(_onBehalfOf) - : IERC20(reserve.variableDebtTokenAddress).balanceOf(_onBehalfOf); + ? stableDebt + : variableDebt; if (amount != UINT_MAX_VALUE && amount < paybackAmount) { paybackAmount = amount; diff --git a/contracts/libraries/logic/ValidationLogic.sol b/contracts/libraries/logic/ValidationLogic.sol index b7b16ddd..abba4592 100644 --- a/contracts/libraries/logic/ValidationLogic.sol +++ b/contracts/libraries/logic/ValidationLogic.sol @@ -217,16 +217,16 @@ library ValidationLogic { * @param reserve the reserve state from which the user is repaying * @param amountSent the amount sent for the repayment. Can be an actual value or uint(-1) * @param onBehalfOf the address of the user msg.sender is repaying for - * @param stableBorrowBalance the borrow balance of the user - * @param variableBorrowBalance the borrow balance of the user + * @param stableDebt the borrow balance of the user + * @param variableDebt the borrow balance of the user */ function validateRepay( ReserveLogic.ReserveData storage reserve, uint256 amountSent, ReserveLogic.InterestRateMode rateMode, address onBehalfOf, - uint256 stableBorrowBalance, - uint256 variableBorrowBalance + uint256 stableDebt, + uint256 variableDebt ) external view { bool isActive = reserve.configuration.getActive(); @@ -235,9 +235,9 @@ library ValidationLogic { require(amountSent > 0, 'Amount must be greater than 0'); require( - (stableBorrowBalance > 0 && + (stableDebt > 0 && ReserveLogic.InterestRateMode(rateMode) == ReserveLogic.InterestRateMode.STABLE) || - (variableBorrowBalance > 0 && + (variableDebt > 0 && ReserveLogic.InterestRateMode(rateMode) == ReserveLogic.InterestRateMode.VARIABLE), '16' );