.updateInterestRates
Last updated
Last updated
The updateInterestRates
function serves to update the following interest rates
liquidity interest rate
variable borrow interest rate
stable borrow interest rate
Typically, this function is executed after state-changes have been done (borrow, repay, supply, etc), to reflect updated rates, accounting for said action taken.
updateInterestRates
will modify system-wide rates according to whether
liquidity added: supply or repay
liquidity removed: borrow or redeem
In most instances, either liquidityAdded
or liquidityRemoved
will be a zero value, while the other is a non-zero value.
The core logic is wrapped within .calculateInterestRates
, which returns the updated rates.
get necessary ratios which will be used in the later section to examine if utilization has exceeded certain thresholds
If borrow utilization exceeds optimal utilization, {...}, else {...}
OPTIMAL_USAGE_RATIO and MAX_EXCESS_USAGE_RATIO are immutable; values are set within constructor.
For in-depth explanation on why the increments are done as above, see:
there is an additional check for stable rates
getOverallBorrowRate simply calculates the weighted average borrow rate based off variable and stable components
currentLiquidityRate is calculated as a component of overallBorrowRate, accounting for the portion that goes to the treasury.