Mint debt token
Overview
If stable interest was selected -> mint stable debt tokens
Else -> mint variable debt tokens
mint stableDebtTokens
rate: reserve.currentStableBorrowRate
_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
balanceIncrease
reflects interest accrued from lastUpdate till current block.timestamp.
Does not relate to incoming borrow action.
totalSupply
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.totalSupply
callstotalSupply
onIncentivizedERC20
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
.
Calculate new stable rate
nextStableRate
is new stable rate, specific to the user
nextStableRate
stored in the user'sUserState.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
Update average Stable rate
_avgStableRate
: internal uint128 on StableDebtToken.solvars.currentAvgStableRate
was set to_avgStableRate
at the start ofmint
previousSupply: updated
totalSupply
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