Refactored duplicated code

This commit is contained in:
The3D 2020-11-03 12:14:09 +01:00
parent 43c66dc5cd
commit f513ebee37

View File

@ -232,15 +232,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
_whenNotPaused();
ReserveLogic.ReserveData storage reserve = _reserves[asset];
if (onBehalfOf != msg.sender) {
address debtToken = reserve.getDebtTokenAddress(interestRateMode);
_borrowAllowance[debtToken][onBehalfOf][msg
.sender] = _borrowAllowance[debtToken][onBehalfOf][msg.sender].sub(
amount,
Errors.LP_BORROW_ALLOWANCE_ARE_NOT_ENOUGH
);
}
_executeBorrow(
ExecuteBorrowParams(
asset,
@ -583,14 +574,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
vars.currentAmountPlusPremium
);
} else {
if (msg.sender != onBehalfOf) {
vars.debtToken = _reserves[vars.currentAsset].getDebtTokenAddress(modes[vars.i]);
_borrowAllowance[vars.debtToken][onBehalfOf][msg.sender] = _borrowAllowance[vars
.debtToken][onBehalfOf][msg.sender]
.sub(vars.currentAmount, Errors.LP_BORROW_ALLOWANCE_ARE_NOT_ENOUGH);
}
//if the user didn't choose to return the funds, the system checks if there
//is enough collateral and eventually open a position
_executeBorrow(
@ -915,6 +898,14 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
oracle
);
if (vars.onBehalfOf != msg.sender) {
address debtToken = reserve.getDebtTokenAddress(vars.interestRateMode);
_borrowAllowance[debtToken][vars.onBehalfOf][msg.sender] = _borrowAllowance[debtToken][vars
.onBehalfOf][msg.sender]
.sub(vars.amount, Errors.LP_BORROW_ALLOWANCE_ARE_NOT_ENOUGH);
}
reserve.updateState();
//caching the current stable borrow rate