JumpRateModelV4

Git Source

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

NameTypeDescription
blocksPerYear_uint256The estimated number of blocks per year
baseRatePerBlock_uint256The base APR, scaled by 1e18 (can be zero)
multiplierPerBlock_uint256The rate increase in interest wrt utilization, scaled by 1e18
jumpMultiplierPerBlock_uint256The multiplier per block after utilization point
kink_uint256The utilization point where the jump multiplier applies
owner_addressThe owner of the contract
name_stringA 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

NameTypeDescription
baseRatePerBlock_uint256The approximate target base APR, as a mantissa (scaled by 1e18)
multiplierPerBlock_uint256The rate of increase in interest rate wrt utilization (scaled by 1e18)
jumpMultiplierPerBlock_uint256The multiplierPerBlock after hitting a specified utilization point
kink_uint256The 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

NameTypeDescription
baseRatePerYearuint256The approximate target base APR, as a mantissa (scaled by 1e18)
multiplierPerYearuint256The rate of increase in interest rate wrt utilization (scaled by 1e18)
jumpMultiplierPerYearuint256The multiplierPerBlock after hitting a specified utilization point
kink_uint256The 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

NameTypeDescription
blocksPerYear_uint256The 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

NameTypeDescription
cashuint256The total cash in the market
borrowsuint256The total borrows in the market
reservesuint256The total reserves in the market
reserveFactorMantissauint256The current reserve factor for the market

Returns

NameTypeDescription
<none>uint256The current supply rate per block, scaled by 1e18

isInterestRateModel

Should return true

function isInterestRateModel() external pure override returns (bool);

Returns

NameTypeDescription
<none>boolisModel 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

NameTypeDescription
cashuint256The total cash in the market
borrowsuint256The total borrows in the market
reservesuint256The total reserves in the market

Returns

NameTypeDescription
<none>uint256The 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

NameTypeDescription
cashuint256The total cash in the market
borrowsuint256The total borrows in the market
reservesuint256The total reserves in the market

Returns

NameTypeDescription
<none>uint256The utilization rate as a mantissa between [0, 1e18]

_updateBlocksPerYear

Internal function to update blocks per year

function _updateBlocksPerYear(uint256 blocksPerYear_) private;

Parameters

NameTypeDescription
blocksPerYear_uint256The 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

NameTypeDescription
basePerBlock_uint256The base rate per block (can be zero)
multiplierPerBlock_uint256The multiplier per block
jumpMultiplierPerBlock_uint256The jump multiplier per block
kink_uint256The 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

NameTypeDescription
baseRatePerYearuint256The base APR, scaled by 1e18
multiplierPerYearuint256The rate increase wrt utilization, scaled by 1e18
jumpMultiplierPerYearuint256The multiplier per block after utilization point
kink_uint256The utilization point where the jump multiplier applies