mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
RepayLocalVars removal
This commit is contained in:
parent
3a24d4e434
commit
26115b4601
|
@ -392,14 +392,6 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RepayLocalVars {
|
|
||||||
uint256 stableDebt;
|
|
||||||
uint256 variableDebt;
|
|
||||||
uint256 paybackAmount;
|
|
||||||
uint256 currentStableRate;
|
|
||||||
uint256 totalDebt;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @notice repays a borrow on the specific reserve, for the specified amount (or for the whole amount, if uint256(-1) is specified).
|
* @notice repays a borrow on the specific reserve, for the specified amount (or for the whole amount, if uint256(-1) is specified).
|
||||||
* @dev the target user is defined by _onBehalfOf. If there is no repayment on behalf of another account,
|
* @dev the target user is defined by _onBehalfOf. If there is no repayment on behalf of another account,
|
||||||
|
@ -414,22 +406,19 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool {
|
||||||
uint256 _rateMode,
|
uint256 _rateMode,
|
||||||
address _onBehalfOf
|
address _onBehalfOf
|
||||||
) external override nonReentrant {
|
) external override nonReentrant {
|
||||||
RepayLocalVars memory vars;
|
|
||||||
ReserveLogic.ReserveData storage reserve = reserves[_reserve];
|
ReserveLogic.ReserveData storage reserve = reserves[_reserve];
|
||||||
|
|
||||||
(vars.stableDebt, vars.variableDebt) = Helpers.getUserCurrentDebt(_onBehalfOf, reserve);
|
(uint256 stableDebt, uint256 variableDebt) = Helpers.getUserCurrentDebt(_onBehalfOf, reserve);
|
||||||
|
|
||||||
vars.totalDebt = vars.stableDebt.add(vars.variableDebt);
|
|
||||||
|
|
||||||
ReserveLogic.InterestRateMode rateMode = ReserveLogic.InterestRateMode(_rateMode);
|
ReserveLogic.InterestRateMode rateMode = ReserveLogic.InterestRateMode(_rateMode);
|
||||||
|
|
||||||
//default to max amount
|
//default to max amount
|
||||||
vars.paybackAmount = rateMode == ReserveLogic.InterestRateMode.STABLE
|
uint256 paybackAmount = rateMode == ReserveLogic.InterestRateMode.STABLE
|
||||||
? vars.stableDebt
|
? stableDebt
|
||||||
: vars.variableDebt;
|
: variableDebt;
|
||||||
|
|
||||||
if (_amount != UINT_MAX_VALUE && _amount < vars.paybackAmount) {
|
if (_amount != UINT_MAX_VALUE && _amount < paybackAmount) {
|
||||||
vars.paybackAmount = _amount;
|
paybackAmount = _amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
ValidationLogic.validateRepay(
|
ValidationLogic.validateRepay(
|
||||||
|
@ -438,33 +427,33 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool {
|
||||||
_amount,
|
_amount,
|
||||||
rateMode,
|
rateMode,
|
||||||
_onBehalfOf,
|
_onBehalfOf,
|
||||||
vars.stableDebt,
|
stableDebt,
|
||||||
vars.variableDebt,
|
variableDebt,
|
||||||
vars.paybackAmount
|
paybackAmount
|
||||||
);
|
);
|
||||||
|
|
||||||
reserve.updateCumulativeIndexesAndTimestamp();
|
reserve.updateCumulativeIndexesAndTimestamp();
|
||||||
|
|
||||||
//burns an equivalent amount of debt tokens
|
//burns an equivalent amount of debt tokens
|
||||||
if (rateMode == ReserveLogic.InterestRateMode.STABLE) {
|
if (rateMode == ReserveLogic.InterestRateMode.STABLE) {
|
||||||
IStableDebtToken(reserve.stableDebtTokenAddress).burn(_onBehalfOf, vars.paybackAmount);
|
IStableDebtToken(reserve.stableDebtTokenAddress).burn(_onBehalfOf, paybackAmount);
|
||||||
} else {
|
} else {
|
||||||
IVariableDebtToken(reserve.variableDebtTokenAddress).burn(_onBehalfOf, vars.paybackAmount);
|
IVariableDebtToken(reserve.variableDebtTokenAddress).burn(_onBehalfOf, paybackAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
reserve.updateInterestRates(_reserve, vars.paybackAmount, 0);
|
reserve.updateInterestRates(_reserve, paybackAmount, 0);
|
||||||
|
|
||||||
if (vars.totalDebt.sub(vars.paybackAmount) == 0) {
|
if (stableDebt.add(variableDebt).sub(paybackAmount) == 0) {
|
||||||
usersConfig[_onBehalfOf].setBorrowing(reserve.index, false);
|
usersConfig[_onBehalfOf].setBorrowing(reserve.index, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
IERC20(_reserve).safeTransferFrom(msg.sender, reserve.aTokenAddress, vars.paybackAmount);
|
IERC20(_reserve).safeTransferFrom(msg.sender, reserve.aTokenAddress, paybackAmount);
|
||||||
|
|
||||||
emit Repay(
|
emit Repay(
|
||||||
_reserve,
|
_reserve,
|
||||||
_onBehalfOf,
|
_onBehalfOf,
|
||||||
msg.sender,
|
msg.sender,
|
||||||
vars.paybackAmount,
|
paybackAmount,
|
||||||
//solium-disable-next-line
|
//solium-disable-next-line
|
||||||
block.timestamp
|
block.timestamp
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user