Mint debt token
Last updated
Last updated
If stable interest was selected -> mint stable debt tokens
Else -> mint variable debt tokens
rate: reserve.currentStableBorrowRate
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
balanceIncrease
reflects interest accrued from lastUpdate till current block.timestamp.
Does not relate to incoming borrow action.
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.sol
previousSupply
: updated supply value
principalSupply
=> super.totalSupply
calls totalSupply
on IncentivizedERC20
which returns _totalSupply
previousSupply
is set to totalSupply()
instead of _totalSupply
directly, so that the updated supply value can be obtained.
With recent interest accounted for, the storage variable _totalSupply
is updated with the incoming stable debt, amount
.
nextStableRate
is new stable rate, specific to the user
nextStableRate
stored in the user's UserState.additionalData
struct. userState
mapping collects all users' UserState
structs.
Store update time in _timestamps
._timestamps
mapping collects the last update timestamp for all users.
Update the timestamp of the last update of _totalSupply.
rate: reserve.currentStableBorrowRate
_avgStableRate
: internal uint128 on StableDebtToken.sol
vars.currentAvgStableRate
was set to _avgStableRate
at the start of mint
previousSupply: updatedtotalSupply
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
:
amountScaled
: scale the borrow amount against variableBorrowIndex
See variableDebtToken mint