# Aave V3 Interest Rate Strategy

Implements the calculation of the interest rates depending on the reserve state. The model of interest rate is based on two slopes, one before the reserve’s optimal usage ratio and another from that point to 100%. Rates are set per reserve through [`PoolConfigurator.setReserveInterestRateData`](./pool-configurator#setreserveinterestratedata).

With utilization _U_ and optimal usage ratio _U_<sub>optimal</sub>, the variable borrow rate is:

<Katex expression="R = \begin{cases} R_{base} + R_{slope1} \cdot \dfrac{U}{U_{optimal}} & U \le U_{optimal} \\ R_{base} + R_{slope1} + R_{slope2} \cdot \dfrac{U - U_{optimal}}{1 - U_{optimal}} & U > U_{optimal} \end{cases}" />

> [!NOTE]
> Each Aave market needs its own instance of this contract, because it caches
> the [PoolAddressesProvider](./pool-addresses-provider).

The source code is available on [GitHub](https://github.com/aave-dao/aave-v3-origin/blob/main/src/contracts/misc/DefaultReserveInterestRateStrategyV2.sol).

## View Methods

### getInterestRateData

```solidity
function getInterestRateData(address reserve) external view returns (InterestRateDataRay memory)
```

Returns the interest rate parameters of the specified reserve, in ray.

**Input Parameters:**

| Name    | Type      | Description                |
| :------ | :-------- | :------------------------- |
| **reserve** | `address` | The address of the reserve |

**Return Values:**

| Type                  | Description                                                                                                         |
| :-------------------- | :------------------------------------------------------------------------------------------------------------------ |
| `InterestRateDataRay` | `optimalUsageRatio`, `baseVariableBorrowRate`, `variableRateSlope1` and `variableRateSlope2`, all expressed in ray |

### getInterestRateDataBps

```solidity
function getInterestRateDataBps(address reserve) external view returns (InterestRateData memory)
```

Returns the interest rate parameters of the specified reserve, in bps.

**Input Parameters:**

| Name    | Type      | Description                |
| :------ | :-------- | :------------------------- |
| **reserve** | `address` | The address of the reserve |

**Return Values:**

| Type               | Description                                                                                                         |
| :----------------- | :------------------------------------------------------------------------------------------------------------------ |
| `InterestRateData` | `optimalUsageRatio`, `baseVariableBorrowRate`, `variableRateSlope1` and `variableRateSlope2`, all expressed in bps |

### getOptimalUsageRatio

```solidity
function getOptimalUsageRatio(address reserve) external view returns (uint256)
```

Returns the optimal usage ratio of the specified reserve.

**Input Parameters:**

| Name    | Type      | Description                |
| :------ | :-------- | :------------------------- |
| **reserve** | `address` | The address of the reserve |

**Return Values:**

| Type      | Description                                   |
| :-------- | :---------------------------------------- |
| `uint256` | The optimal usage ratio, expressed in ray |

### getVariableRateSlope1

```solidity
function getVariableRateSlope1(address reserve) external view returns (uint256)
```

Returns the variable rate slope below the optimal usage ratio for the specified reserve. Applies while the usage ratio is below the optimal usage ratio.

**Input Parameters:**

| Name    | Type      | Description                |
| :------ | :-------- | :------------------------- |
| **reserve** | `address` | The address of the reserve |

**Return Values:**

| Type      | Description                               |
| :-------- | :---------------------------------------- |
| `uint256` | The variable rate slope, expressed in ray |

### getVariableRateSlope2

```solidity
function getVariableRateSlope2(address reserve) external view returns (uint256)
```

Returns the variable rate slope above the optimal usage ratio for the specified reserve. Applies while the usage ratio is above the optimal usage ratio.

**Input Parameters:**

| Name    | Type      | Description                |
| :------ | :-------- | :------------------------- |
| **reserve** | `address` | The address of the reserve |

**Return Values:**

| Type      | Description                               |
| :-------- | :---------------------------------------- |
| `uint256` | The variable rate slope, expressed in ray |

### getBaseVariableBorrowRate

```solidity
function getBaseVariableBorrowRate(address reserve) external view override returns (uint256)
```

Returns the base variable borrow rate for the specified reserve.

**Input Parameters:**

| Name    | Type      | Description                |
| :------ | :-------- | :------------------------- |
| **reserve** | `address` | The address of the reserve |

**Return Values:**

| Type      | Description                                     |
| :-------- | :---------------------------------------------- |
| `uint256` | The base variable borrow rate, expressed in ray |

### getMaxVariableBorrowRate

```solidity
function getMaxVariableBorrowRate(address reserve) external view override returns (uint256)
```

Returns the maximum variable borrow rate for the specified reserve.

**Input Parameters:**

| Name    | Type      | Description                |
| :------ | :-------- | :------------------------- |
| **reserve** | `address` | The address of the reserve |

**Return Values:**

| Type      | Description                                        |
| :-------- | :------------------------------------------------- |
| `uint256` | The maximum variable borrow rate, expressed in ray |

### calculateInterestRates

```solidity
function calculateInterestRates(
    DataTypes.CalculateInterestRatesParams memory params
) external view override returns (uint256, uint256)
```

Calculates the interest rates depending on the reserve’s state and configurations. This function returns only two values: the liquidity rate and the variable borrow rate.

**Input Parameters:**

| Name   | Type                                     | Description                                       |
| :----- | :--------------------------------------- | :------------------------------------------------ |
| **params** | `DataTypes.CalculateInterestRatesParams` | The parameters needed to calculate interest rates |

The `DataTypes.CalculateInterestRatesParams` struct is composed of the following fields:

| Name                     | Type      | Description                                                                 |
| :----------------------- | :-------- | :-------------------------------------------------------------------------- |
| **unbacked**                 | `uint256` | The reserve deficit (field kept under its pre-V3.4 name); added to the denominator of the supply usage ratio |
| **liquidityAdded**           | `uint256` | The liquidity added during the operation                                    |
| **liquidityTaken**           | `uint256` | The liquidity taken during the operation                                    |
| **totalDebt**                | `uint256` | The total borrowed from the reserve                                         |
| **reserveFactor**            | `uint256` | The reserve portion of the interest that goes to the treasury of the market |
| **reserve**                  | `address` | The address of the reserve                                                  |
| **usingVirtualBalance**      | `bool`    | Deprecated since Aave V3.4, always `true`                                   |
| **virtualUnderlyingBalance** | `uint256` | The virtual balance of the underlying asset held by the reserve             |

**Return Values:**

| Name               | Type      | Description                                |
| :----------------- | :-------- | :----------------------------------------- |
| **liquidityRate**      | `uint256` | The liquidity rate, expressed in ray       |
| **variableBorrowRate** | `uint256` | The variable borrow rate, expressed in ray |
