From 38bb760112fe23f09eb5efb88e1ee24900c59fa7 Mon Sep 17 00:00:00 2001 From: eboado Date: Thu, 29 Oct 2020 14:55:11 +0100 Subject: [PATCH] - Added return of is first borrowing on debt tokens mint() --- contracts/lendingpool/LendingPool.sol | 17 +++++++++-------- contracts/tokenization/StableDebtToken.sol | 4 +++- .../interfaces/IStableDebtToken.sol | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/contracts/lendingpool/LendingPool.sol b/contracts/lendingpool/LendingPool.sol index 3f490365..1a589091 100644 --- a/contracts/lendingpool/LendingPool.sol +++ b/contracts/lendingpool/LendingPool.sol @@ -857,34 +857,35 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage oracle ); - uint256 reserveId = reserve.id; - if (!userConfig.isBorrowing(reserveId)) { - userConfig.setBorrowing(reserveId, true); - } - reserve.updateState(); //caching the current stable borrow rate uint256 currentStableRate = 0; - + + bool isFirstBorrowing = false; if ( ReserveLogic.InterestRateMode(vars.interestRateMode) == ReserveLogic.InterestRateMode.STABLE ) { currentStableRate = reserve.currentStableBorrowRate; - IStableDebtToken(reserve.stableDebtTokenAddress).mint( + isFirstBorrowing = IStableDebtToken(reserve.stableDebtTokenAddress).mint( vars.onBehalfOf, vars.amount, currentStableRate ); } else { - IVariableDebtToken(reserve.variableDebtTokenAddress).mint( + isFirstBorrowing = IVariableDebtToken(reserve.variableDebtTokenAddress).mint( vars.onBehalfOf, vars.amount, reserve.variableBorrowIndex ); } + uint256 reserveId = reserve.id; + if (isFirstBorrowing) { + userConfig.setBorrowing(reserveId, true); + } + reserve.updateInterestRates( vars.asset, vars.aTokenAddress, diff --git a/contracts/tokenization/StableDebtToken.sol b/contracts/tokenization/StableDebtToken.sol index 346d9719..29781919 100644 --- a/contracts/tokenization/StableDebtToken.sol +++ b/contracts/tokenization/StableDebtToken.sol @@ -97,7 +97,7 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase { address user, uint256 amount, uint256 rate - ) external override onlyLendingPool { + ) external override onlyLendingPool returns(bool) { MintLocalVars memory vars; //cumulates the user debt @@ -148,6 +148,8 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase { vars.newStableRate, vars.currentAvgStableRate ); + + return currentBalance == 0; } /** diff --git a/contracts/tokenization/interfaces/IStableDebtToken.sol b/contracts/tokenization/interfaces/IStableDebtToken.sol index 4c0d5940..4e04f704 100644 --- a/contracts/tokenization/interfaces/IStableDebtToken.sol +++ b/contracts/tokenization/interfaces/IStableDebtToken.sol @@ -62,7 +62,7 @@ interface IStableDebtToken { address user, uint256 amount, uint256 rate - ) external; + ) external returns(bool); /** * @dev burns debt of the target user.