Mint debt token
Overview

If stable interest was selected -> mint stable debt tokens
Else -> mint variable debt tokens
mint stableDebtTokens

_calculateBalanceIncrease
For a user, calculates the increase in stable debt, due to interest accrued from timestamp of their last update, to current time.
Serves to update user's prior stable debt
totalSupply
vars.previousSupply = totalSupply();
vars.currentAvgStableRate = _avgStableRate;
vars.nextSupply = _totalSupply = vars.previousSupply + amount;vars.previousSupply = totalSupply();
totalSupply returns the updated supply value, by accounting for recently accrued interest, from _totalSupplyTimestamp till now, based on the _avgStableRate.
_avgStableRate: internal storage variable on StableDebtToken.solpreviousSupply: updated supply value

principalSupply=>super.totalSupplycallstotalSupplyonIncentivizedERC20which returns_totalSupply
With recent interest accounted for, the storage variable _totalSupply is updated with the incoming stable debt, amount.
vars.nextSupply = _totalSupply =
vars.previousSupply + amount;Calculate new stable rate
nextStableRateis new stable rate, specific to the user

nextStableRate =
(_avgStableRate * currentBalance) + (amount * rate / currentBalance + amount)nextStableRatestored in the user'sUserState.additionalDatastruct.userStatemapping collects all users'UserStatestructs.Store update time in
_timestamps._timestampsmapping collects the last update timestamp for all users.Update the timestamp of the last update of
_totalSupply.
Update average Stable rate
_avgStableRate: internal uint128 on StableDebtToken.solvars.currentAvgStableRatewas set to_avgStableRateat the start ofmint

newAvgStableRate =
(_avgStableRate * previousSupply) + [(rate * amountInRay) / nextSupply]mint tokens

Notice that we do not just mint as per the incoming stable debt amount; but also mint for balanceIncrease. This serves to update user's prior stable debt based on interest accrued over time elapsed since last update.
Since we going to mint, mint to update the user's entire position
mint calls the internal function _mint:

mint variableDebtTokens

amountScaled: scale the borrow amount against variableBorrowIndexSee variableDebtToken mint
Last updated
Was this helpful?