From f513ebee370a319af83a38043b3ddce34d2abade Mon Sep 17 00:00:00 2001 From: The3D Date: Tue, 3 Nov 2020 12:14:09 +0100 Subject: [PATCH] Refactored duplicated code --- contracts/lendingpool/LendingPool.sol | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/contracts/lendingpool/LendingPool.sol b/contracts/lendingpool/LendingPool.sol index 5d476ab9..849fb49d 100644 --- a/contracts/lendingpool/LendingPool.sol +++ b/contracts/lendingpool/LendingPool.sol @@ -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