Skip to content

Commit

Permalink
Merge branch 'feat/101-first-borrowing-on-debt-tokens' into 'master'
Browse files Browse the repository at this point in the history
Added return of is first borrowing on debt tokens mint()

Closes #101

See merge request aave-tech/protocol-v2!110
  • Loading branch information
The-3D committed Oct 30, 2020
2 parents 4ed808e + decf652 commit 386138c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
16 changes: 8 additions & 8 deletions contracts/lendingpool/LendingPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -888,34 +888,34 @@ 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
);
}

if (isFirstBorrowing) {
userConfig.setBorrowing(reserve.id, true);
}

reserve.updateInterestRates(
vars.asset,
vars.aTokenAddress,
Expand Down
4 changes: 3 additions & 1 deletion contracts/tokenization/StableDebtToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -148,6 +148,8 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase {
vars.newStableRate,
vars.currentAvgStableRate
);

return currentBalance == 0;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion contracts/tokenization/interfaces/IStableDebtToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ interface IStableDebtToken {
address user,
uint256 amount,
uint256 rate
) external;
) external returns(bool);

/**
* @dev burns debt of the target user.
Expand Down

0 comments on commit 386138c

Please sign in to comment.