# TwoKinksInterestRateModel

## TwoKinksInterestRateModel

An interest rate model with two different slope increase or decrease each after a certain utilization threshold called **kink** is reached.

## Solidity API

#### MULTIPLIER\_PER\_BLOCK\_OR\_SECOND

The multiplier of utilization rate per block or second that gives the slope 1 of the interest rate scaled by EXP\_SCALE

```solidity
int256 MULTIPLIER_PER_BLOCK_OR_SECOND
```

***

#### BASE\_RATE\_PER\_BLOCK\_OR\_SECOND

The base interest rate per block or second which is the y-intercept when utilization rate is 0 scaled by EXP\_SCALE

```solidity
int256 BASE_RATE_PER_BLOCK_OR_SECOND
```

***

#### KINK\_1

The utilization point at which the multiplier2 is applied

```solidity
int256 KINK_1
```

***

#### MULTIPLIER\_2\_PER\_BLOCK\_OR\_SECOND

The multiplier of utilization rate per block or second that gives the slope 2 of the interest rate scaled by EXP\_SCALE

```solidity
int256 MULTIPLIER_2_PER_BLOCK_OR_SECOND
```

***

#### BASE\_RATE\_2\_PER\_BLOCK\_OR\_SECOND

The base interest rate per block or second which is the y-intercept when utilization rate hits KINK\_1 scaled by EXP\_SCALE

```solidity
int256 BASE_RATE_2_PER_BLOCK_OR_SECOND
```

***

#### RATE\_1

The maximum kink interest rate scaled by EXP\_SCALE

```solidity
int256 RATE_1
```

***

#### KINK\_2

The utilization point at which the jump multiplier is applied

```solidity
int256 KINK_2
```

***

#### JUMP\_MULTIPLIER\_PER\_BLOCK\_OR\_SECOND

The multiplier of utilization rate per block or second that gives the slope 3 of interest rate scaled by EXP\_SCALE

```solidity
int256 JUMP_MULTIPLIER_PER_BLOCK_OR_SECOND
```

***

#### RATE\_2

The maximum kink interest rate scaled by EXP\_SCALE

```solidity
int256 RATE_2
```

***

#### constructor

Construct an interest rate model

```solidity
constructor(int256 baseRatePerYear_, int256 multiplierPerYear_, int256 kink1_, int256 multiplier2PerYear_, int256 baseRate2PerYear_, int256 kink2_, int256 jumpMultiplierPerYear_, bool timeBased_, uint256 blocksPerYear_) public
```

**Parameters**

| Name                    | Type    | Description                                                                                                    |
| ----------------------- | ------- | -------------------------------------------------------------------------------------------------------------- |
| baseRatePerYear\_       | int256  | The approximate target base APR, as a mantissa (scaled by EXP\_SCALE)                                          |
| multiplierPerYear\_     | int256  | The rate of increase or decrease in interest rate wrt utilization (scaled by EXP\_SCALE)                       |
| kink1\_                 | int256  | The utilization point at which the multiplier2 is applied                                                      |
| multiplier2PerYear\_    | int256  | The rate of increase or decrease in interest rate wrt utilization after hitting KINK\_1 (scaled by EXP\_SCALE) |
| baseRate2PerYear\_      | int256  | The additonal base APR after hitting KINK\_1, as a mantissa (scaled by EXP\_SCALE)                             |
| kink2\_                 | int256  | The utilization point at which the jump multiplier is applied                                                  |
| jumpMultiplierPerYear\_ | int256  | The multiplier after hitting KINK\_2                                                                           |
| timeBased\_             | bool    | A boolean indicating whether the contract is based on time or block.                                           |
| blocksPerYear\_         | uint256 | The number of blocks per year                                                                                  |

***

#### getBorrowRate

Calculates the current borrow rate per slot (block or second)

```solidity
function getBorrowRate(uint256 cash, uint256 borrows, uint256 reserves, uint256 badDebt) external view returns (uint256)
```

**Parameters**

| Name     | Type    | Description                          |
| -------- | ------- | ------------------------------------ |
| cash     | uint256 | The amount of cash in the market     |
| borrows  | uint256 | The amount of borrows in the market  |
| reserves | uint256 | The amount of reserves in the market |
| badDebt  | uint256 | The amount of badDebt in the market  |

**Return Values**

| Name | Type    | Description                                                                                |
| ---- | ------- | ------------------------------------------------------------------------------------------ |
| \[0] | uint256 | The borrow rate percentage per slot (block or second) as a mantissa (scaled by EXP\_SCALE) |

***

#### getSupplyRate

Calculates the current supply rate per slot (block or second)

```solidity
function getSupplyRate(uint256 cash, uint256 borrows, uint256 reserves, uint256 reserveFactorMantissa, uint256 badDebt) public view virtual returns (uint256)
```

**Parameters**

| Name                  | Type    | Description                               |
| --------------------- | ------- | ----------------------------------------- |
| cash                  | uint256 | The amount of cash in the market          |
| borrows               | uint256 | The amount of borrows in the market       |
| reserves              | uint256 | The amount of reserves in the market      |
| reserveFactorMantissa | uint256 | The current reserve factor for the market |
| badDebt               | uint256 | The amount of badDebt in the market       |

**Return Values**

| Name | Type    | Description                                                                                |
| ---- | ------- | ------------------------------------------------------------------------------------------ |
| \[0] | uint256 | The supply rate percentage per slot (block or second) as a mantissa (scaled by EXP\_SCALE) |

***

#### utilizationRate

Calculates the utilization rate of the market: `(borrows + badDebt) / (cash + borrows + badDebt - reserves)`

```solidity
function utilizationRate(uint256 cash, uint256 borrows, uint256 reserves, uint256 badDebt) public pure returns (uint256)
```

**Parameters**

| Name     | Type    | Description                                             |
| -------- | ------- | ------------------------------------------------------- |
| cash     | uint256 | The amount of cash in the market                        |
| borrows  | uint256 | The amount of borrows in the market                     |
| reserves | uint256 | The amount of reserves in the market (currently unused) |
| badDebt  | uint256 | The amount of badDebt in the market                     |

**Return Values**

| Name | Type    | Description                                                    |
| ---- | ------- | -------------------------------------------------------------- |
| \[0] | uint256 | The utilization rate as a mantissa between \[0, MANTISSA\_ONE] |

***
