Interset Rate Model

Overview

The DefaultRateModel is a rate model contract used by lending pools to calculate the borrow rate per block. This model applies mathematical coefficients to determine how interest rates change based on pool utilization, which is a function of liquidity and borrows.

It’s crucial in DeFi lending protocols as it allows dynamic adjustments to the borrowing cost, maintaining efficient utilization of the pool while adjusting for the increasing or decreasing demand for borrowed assets.


Initialization

Constructor

constructor(uint _c1, uint _c2, uint _c3, uint _secsPerYear)

Initializes the rate model with custom coefficients and the number of seconds in a year.

Parameters:

  • _c1: Constant coefficient that affects the borrow rate (default value: 1 * 1e17).

  • _c2: Constant coefficient that affects the borrow rate (default value: 3 * 1e17).

  • _c3: Constant coefficient that affects the borrow rate (default value: 35 * 1e17).

  • _secsPerYear: Number of seconds in a year (default value: 31556952 * 1e18).


Main Functions

getBorrowRatePerSecond

function getBorrowRatePerSecond(
    uint liquidity,
    uint borrows
) external view returns (uint)

Calculates the borrow rate per second based on the current liquidity and borrowed amount in the lending pool. The rate model adjusts dynamically based on pool utilization, which is a ratio of borrows to total assets (liquidity + borrows).

Formula:

Borrow Rate Per Second = c3 * (util * c1 + util^32 * c1 + util^64 * c2) / secsPerYear

Where util is the utilization factor, calculated as:

util = borrows / (liquidity + borrows)

Parameters:

  • liquidity: The total balance of the underlying asset in the lending pool (in the smallest units of the token).

  • borrows: The balance of the underlying asset borrowed from the pool (in the smallest units of the token).


Internal Functions

_utilization

function _utilization(uint liquidity, uint borrows) internal pure returns (uint)

Calculates the utilization ratio of the pool, which is defined as the proportion of borrows to the total assets in the pool.

Parameters:

  • liquidity: The total liquidity available in the pool (in the smallest units of the token).

  • borrows: The total amount borrowed from the pool (in the smallest units of the token).

Last updated