JumpRateModelV4
Inherits: IInterestRateModel, Ownable
Title: JumpRateModelV4
Author: Merge Layers Inc.
Implementation of the IInterestRateModel interface for calculating interest rates
State Variables
blocksPerYear
The approximate number of blocks per year that is assumed by the interest rate model
uint256 public override blocksPerYear
multiplierPerBlock
The multiplier of utilization rate that gives the slope of the interest rate
uint256 public override multiplierPerBlock
baseRatePerBlock
The base interest rate which is the y-intercept when utilization rate is 0
uint256 public override baseRatePerBlock
jumpMultiplierPerBlock
The multiplierPerBlock after hitting a specified utilization point
uint256 public override jumpMultiplierPerBlock
kink
The utilization point at which the jump multiplier is applied
uint256 public override kink
name
A name for user-friendliness, e.g. WBTC
string public override name
Functions
constructor
Construct an interest rate model
constructor(
uint256 blocksPerYear_,
uint256 baseRatePerBlock_,
uint256 multiplierPerBlock_,
uint256 jumpMultiplierPerBlock_,
uint256 kink_,
address owner_,
string memory name_
) Ownable(owner_);
Parameters
| Name | Type | Description |
|---|---|---|
blocksPerYear_ | uint256 | The estimated number of blocks per year |
baseRatePerBlock_ | uint256 | The base APR, scaled by 1e18 (can be zero) |
multiplierPerBlock_ | uint256 | The rate increase in interest wrt utilization, scaled by 1e18 |
jumpMultiplierPerBlock_ | uint256 | The multiplier per block after utilization point |
kink_ | uint256 | The utilization point where the jump multiplier applies |
owner_ | address | The owner of the contract |
name_ | string | A user-friendly name for the contract |
updateJumpRateModelDirect
Update the parameters of the interest rate model (only callable by owner, i.e. Timelock)
function updateJumpRateModelDirect(
uint256 baseRatePerBlock_,
uint256 multiplierPerBlock_,
uint256 jumpMultiplierPerBlock_,
uint256 kink_
) external onlyOwner;
Parameters
| Name | Type | Description |
|---|---|---|
baseRatePerBlock_ | uint256 | The approximate target base APR, as a mantissa (scaled by 1e18) |
multiplierPerBlock_ | uint256 | The rate of increase in interest rate wrt utilization (scaled by 1e18) |
jumpMultiplierPerBlock_ | uint256 | The multiplierPerBlock after hitting a specified utilization point |
kink_ | uint256 | The utilization point at which the jump multiplier is applied |
updateJumpRateModel
Update the parameters of the interest rate model (only callable by owner, i.e. Timelock)
function updateJumpRateModel(
uint256 baseRatePerYear,
uint256 multiplierPerYear,
uint256 jumpMultiplierPerYear,
uint256 kink_
) external onlyOwner;
Parameters
| Name | Type | Description |
|---|---|---|
baseRatePerYear | uint256 | The approximate target base APR, as a mantissa (scaled by 1e18) |
multiplierPerYear | uint256 | The rate of increase in interest rate wrt utilization (scaled by 1e18) |
jumpMultiplierPerYear | uint256 | The multiplierPerBlock after hitting a specified utilization point |
kink_ | uint256 | The utilization point at which the jump multiplier is applied |
updateBlocksPerYear
Updates the blocksPerYear in order to make interest calculations simpler
function updateBlocksPerYear(uint256 blocksPerYear_) external onlyOwner;
Parameters
| Name | Type | Description |
|---|---|---|
blocksPerYear_ | uint256 | The new estimated eth blocks per year. |
getSupplyRate
Returns the current supply rate per block for the market
function getSupplyRate(uint256 cash, uint256 borrows, uint256 reserves, uint256 reserveFactorMantissa)
external
view
override
returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
cash | uint256 | The total cash in the market |
borrows | uint256 | The total borrows in the market |
reserves | uint256 | The total reserves in the market |
reserveFactorMantissa | uint256 | The current reserve factor for the market |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | The current supply rate per block, scaled by 1e18 |
isInterestRateModel
Should return true
function isInterestRateModel() external pure override returns (bool);
Returns
| Name | Type | Description |
|---|---|---|
<none> | bool | isModel True when contract implements interest rate model |
getBorrowRate
Returns the current borrow rate per block for the market
function getBorrowRate(uint256 cash, uint256 borrows, uint256 reserves) public view override returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
cash | uint256 | The total cash in the market |
borrows | uint256 | The total borrows in the market |
reserves | uint256 | The total reserves in the market |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | The current borrow rate per block, scaled by 1e18 |
utilizationRate
Calculates the utilization rate of the market
function utilizationRate(uint256 cash, uint256 borrows, uint256 reserves) public pure override returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
cash | uint256 | The total cash in the market |
borrows | uint256 | The total borrows in the market |
reserves | uint256 | The total reserves in the market |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | The utilization rate as a mantissa between [0, 1e18] |
_updateBlocksPerYear
Internal function to update blocks per year
function _updateBlocksPerYear(uint256 blocksPerYear_) private;
Parameters
| Name | Type | Description |
|---|---|---|
blocksPerYear_ | uint256 | The new estimated eth blocks per year. |
_updateJumpRateModelWithoutComputation
Internal function to update jump rate model parameters without computation
function _updateJumpRateModelWithoutComputation(
uint256 basePerBlock_,
uint256 multiplierPerBlock_,
uint256 jumpMultiplierPerBlock_,
uint256 kink_
) private;
Parameters
| Name | Type | Description |
|---|---|---|
basePerBlock_ | uint256 | The base rate per block (can be zero) |
multiplierPerBlock_ | uint256 | The multiplier per block |
jumpMultiplierPerBlock_ | uint256 | The jump multiplier per block |
kink_ | uint256 | The kink utilization point |
_updateJumpRateModel
Internal function to update the parameters of the interest rate model
function _updateJumpRateModel(
uint256 baseRatePerYear,
uint256 multiplierPerYear,
uint256 jumpMultiplierPerYear,
uint256 kink_
) private;
Parameters
| Name | Type | Description |
|---|---|---|
baseRatePerYear | uint256 | The base APR, scaled by 1e18 |
multiplierPerYear | uint256 | The rate increase wrt utilization, scaled by 1e18 |
jumpMultiplierPerYear | uint256 | The multiplier per block after utilization point |
kink_ | uint256 | The utilization point where the jump multiplier applies |