Updated repay function

This commit is contained in:
The3D 2020-08-21 19:10:48 +02:00
parent 9a4ccde6a2
commit 796dc8ee3f
3 changed files with 11 additions and 9 deletions

View File

@ -20,7 +20,7 @@ abstract contract FlashLoanReceiverBase is IFlashLoanReceiver {
receive() external payable {}
function transferFundsBackInternal(
function _transferFundsBack(
address reserve,
address destination,
uint256 amount

View File

@ -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;

View File

@ -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'
);