Skip to main content
The RateModel contract computes the borrow rate per second for a given pool utilization. It is called by every LendingPool during update_state() to determine how much interest has accrued since the last update. Testnet address: CCJAUPCU6EIFQK6GTAAYLW3Y4YETJAAUPAGBPFGQ2OUJPSW3WWHUCL2Z

Functions

get_utilisation_ratio

fn get_utilisation_ratio(
    env: Env,
    liquidity_wad: U256,
    borrows_wad: U256,
) -> U256
Returns the pool’s current utilization ratio in WAD format.
util = borrows_wad / (liquidity_wad + borrows_wad)
Parameters:
ParameterTypeDescription
liquidity_wadU256Pool’s available liquidity in WAD
borrows_wadU256Total outstanding borrows in WAD
Returns: Utilization in WAD (0 = 0%, 10¹⁸ = 100%) Edge case: If both liquidity_wad and borrows_wad are zero, returns 0 (empty pool, 0% utilization).

get_borrow_rate_per_sec

fn get_borrow_rate_per_sec(
    env: Env,
    liquidity_wad: U256,
    borrows_wad: U256,
) -> U256
Returns the per-second borrow rate in WAD format. Formula:
util = borrows / (liquidity + borrows)

rate_per_sec = c3 × (util×c1 + util^32×c1 + util^64×c2) / SECS_PER_YEAR
CoefficientWAD ValueDecimal
c110^170.1
c23 × 10^170.3
c335 × 10^173.5
Returns: Borrow rate per ledger second in WAD. Multiply by SECS_PER_YEAR to get the annual rate.

Rate Curve Behavior

The polynomial curve produces the following behavior:
UtilizationApproximate Annual Rate
0%~0%
20%~7%
50%~18%
70%~35%
80%~60%
90%~150%
95%~300%+
The util^32 and util^64 terms are nearly zero at low utilization but dominate at high utilization, creating a sharp increase in rates as the pool approaches full capacity. This is intentional — high rates at high utilization attract new deposits and incentivize repayments.

Exponentiation

The util^32 and util^64 terms are computed via rpow_wad(util, n), which uses repeated squaring (exponentiation by squaring) in WAD arithmetic:
rpow_wad(x, 0) = WAD   (= 1.0)
rpow_wad(x, n) = x × rpow_wad(x, n-1)  [iterative, via squaring]
This preserves WAD scale at each step.

Constants

ConstantValue
WAD_U12810^18
C110^17 (= 0.1)
C23 × 10^17 (= 0.3)
C335 × 10^17 (= 3.5)
SECS_PER_YEAR31,556,952 × 10^18

Error Codes

enum RateModelError {
    InterestRateNotInitialized,
}

Calling Pattern

LendingPools call the RateModel on every update_state():
// Inside LendingPool.update_state():
let liquidity = get_total_liquidity_in_pool(env);
let borrows   = get_borrows_wad(env);
let rate_per_sec = rate_model_client.get_borrow_rate_per_sec(liquidity, borrows);

let elapsed = now - last_updated;
let rate_factor = elapsed × rate_per_sec;   // in WAD
let interest = mul_wad_down(borrows, rate_factor);
borrows_wad += interest;
last_updated = now;