> ## Documentation Index
> Fetch the complete documentation index at: https://docs.vanna.finance/llms.txt
> Use this file to discover all available pages before exploring further.

# RateModel

> Interest rate model contract. Computes per-second borrow rates as a polynomial function of pool utilization.

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

```rust theme={null}
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:**

| Parameter       | Type   | Description                       |
| --------------- | ------ | --------------------------------- |
| `liquidity_wad` | `U256` | Pool's available liquidity in WAD |
| `borrows_wad`   | `U256` | Total 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

```rust theme={null}
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
```

| Coefficient | WAD Value    | Decimal |
| ----------- | ------------ | ------- |
| `c1`        | `10^17`      | 0.1     |
| `c2`        | `3 × 10^17`  | 0.3     |
| `c3`        | `35 × 10^17` | 3.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:

| Utilization | Approximate 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

| Constant        | Value                |
| --------------- | -------------------- |
| `WAD_U128`      | `10^18`              |
| `C1`            | `10^17` (= 0.1)      |
| `C2`            | `3 × 10^17` (= 0.3)  |
| `C3`            | `35 × 10^17` (= 3.5) |
| `SECS_PER_YEAR` | `31,556,952 × 10^18` |

***

## Error Codes

```rust theme={null}
enum RateModelError {
    InterestRateNotInitialized,
}
```

***

## Calling Pattern

LendingPools call the RateModel on every `update_state()`:

```rust theme={null}
// 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;
```

***

## Related

* [Math Reference](/developers/math-reference#interest-rate-model) — full formula derivation
* [Lending Pools](/developers/contracts/lending-pools) — `update_state()` integration
* [Interest Rate Model](/learn/interest-rate-model) — user-facing explanation of the curve shape
