# APY Calculation

The worst APY that you can get with NillaConnect is the underlying pool's APY, so in other words, using NillaConnect is like using any other lending/borrowing protocols, but you just have a chance of getting better rates!

NillaConnect uses the 3-step slope model to derive its P2P APY. However, since matching P2P results in 100% capital utilization, the utilization rate will not be used as a factor to calculate APY like in the traditional P2P model.

Instead, NillaConnect implements its own interest rate model, where the underlying pool’s (eg. Aave, Compound) real time interest rate is used as a base for the calculation of our P2P APY. NillaConnect's interest rate model is calculated modularly using the length of time that the N-Account is open as the factor to calculate the APY further from the base rate.

The base rate is calculated as:

Where:

$R$= real time base interest rate from the underlying pool

$Supply_u$= the real time supply rate of the underlying pool

$Borrow_u$= the real time borrow rate of the underlying pool

$c$= a constant which represents the index cursor taking the value between {0,1}, ensuring the base rate is between the underlying pool's borrow and supply rate, and determining where the base rate will be between the underlying pool's spread

The P2P APY is given as:

where:

$y$= the P2P APY

$m$= slope

$x$= the period that the N-Account is opened for (in days)

$b$ = a constant

The APY calculation is divided into 3 phases.

**Phase 1**

**Phase 1**

Phase 1 takes place in the early stages of the borrower's open position. In this phase, both borrowers and suppliers enjoy the same P2P rate, which is in between the spreads of the underlying pool, thus, creating a win-win situation between the two parties.

The P2P APY in this phase is defined as:

The P2P APY is given as:

Where:

$m$= 0

$x$= the period that the N-Account is opened for (in days)

$b=R$ (the base rate)

This means that the rate remains locked in between the spreads of the underlying pool's rates until the end of phase 1.

**Phase 2**

**Phase 2**

Phase 2 introduces a mild gamification aspect into the play. In this phase, the borrower's APY will start to increase until it reaches the borrow rate of the underlying pool. However, borrowers can slow down this increase by staking NLL tokens. More NLL tokens staked means that the Max APY in a phase is decreased according to a multiplier - meaning that the more NLL tokens staked, the less the multiplier is, which is used to multiply the max APY to calculate a new slope that slows down the increase of the APY.

**For borrowers with NO NLL tokens staked (original curve):**

**For borrowers with NO NLL tokens staked (original curve):**

Where:

$y_b$= the P2P APY that the borrowers use without NLL tokens staked

$m_2b$= the slope derived from the max APY (underlying pool’s borrow rate) at the end of phase 2

$x$= the period that the N-Account is opened for (in days)

$b_2b$= the constant for borrowers without staked NLL tokens

**For borrowers WITH NLL tokens staked (new curve):**

**For borrowers WITH NLL tokens staked (new curve):**

This new curve is adjusted for the multiplier so it has a lower max APY and therefore, a new slope, which means a slower increase in the APY over the duration of this phase.

Where:

$y_b^*$= the P2P APY adjusted for staked NLL tokens

$m_2^*b$= the new slope adjusted by the change in max APY due to the staking of NLL tokens, which means $m_2^*b=m_2b*z_2b$

$x$= the period that the N-Account is opened for (in days)

$b_2^*b$= a new constant from the equation adjusted for the staked NLL tokens

**Borrower's multiplier for phase 2:**

**Borrower's multiplier for phase 2:**

Where:

$z_2b$= the borrower’s multiplier which takes value between {0.5,1}

$u_b$= a constant representing the rate at which the multiplier (zb) decreases as more NLL tokens are staked.

$n_b$= the amount of NLL tokens staked in the protocol. More NLL tokens staked, means less multiplier, and therefore, a decrease in Borrower’s P2P APY (yb).

If $n_b=0$, then $z_2b=1$

**Max APY for phase 2:**

**Max APY for phase 2:**

Where:

$y^*_2$= the maximum APY used to calculate the slope for the new line for phase 2

$m_2b$= the slope from the original curve

$z_2b$= the borrower’s multiplier which takes value between {0.5,1}

$x$= the period that the N-Account is opened for (in days)

$b_2b$= the constant for borrowers without staked NLL tokens

We know that the max APY always occurs at the last period of phase 2. From here, we use the max APY to determine the new slope ($m^*_2b$) and the new constant ($b^*_2b$) to derive the equation for the new line that takes staked NLL tokens into account into the gamification of the reduction in interest rate. The max APY equation cannot be used as the line equation directly as it still contains elements from the original curve which would be inconsistent with the changed max APY, therefore, a new linear equation has to be created for this to work.

**For Suppliers**

**For Suppliers**

In phase 2, the supplier’s APY is still at the original P2P rate:

Where:

$m$= 0

$x$= the period that the N-Account is opened for (in days)

$b=R$ (the base rate)

This is where the P2P rate between the counterparties starts to diverge, thus creating a spread. This spread is intended to incentivize borrowers to repay the funds after a certain period of time. The spread will be distributed among:

The supplier themselves (30%-40%)

NLL token stakers (30%)

The protocol (30%-40%)

A share of the spread is distributed to the supplier themselves in order to incentivize them to stay for the higher yield. However, with the borrower’s gamification, it means that if the borrower(s) stake more NLL tokens, the max APY decreases, which results in a lower spread, leading to a lower share of spread to the supplier(s). This is where the supplier-side gamification comes in – suppliers can stake NLL tokens to retain their share of the spread or increase it to no more than 40% of the distribution.

#### Original spread:

Where:

$y_b$= the original borrower’s APY given that they do not stake any NLL tokens

$y_s$= the supplier's APY

#### New spread:

Where:

$y^*_b$= the new borrower’s APY after they have NLL tokens staked, which $y^*_b<y_b$

$y_s$= the supplier's APY

Thus $S_*<S$ always. With the decreasing spread, the supplier can retain their spread by staking NLL tokens to boost their spread multiplier, which is multiplied to the new spread $S_*$

**The supplier's multiplier:**

Where:

$z_s$= the supplier’s multiplier which takes value over {1}

$u_s$= the constant representing the rate at which the multiplier (zs) increases as more NLL tokens are staked

$n_s$= the amount of NLL tokens staked in the protocol. More NLL tokens staked, means higher multiplier, and therefore, an increase in the supplier’s spread share

If $n_s=0$, then $z_s=1$ and the supplier receives the decreased spread share

**Supplier's spread share**

Where:

$S_*$= the new spread

$s$= the supplier's share of spread

$z_s$= the supplier’s multiplier which takes value over {1}

**Phase 3**

**Phase 3**

This is the phase where a considerable amount of time has passed and we want to strongly incentivize borrowers to repay the funds while also reinforcing supplier’s incentives to stay with the increasing spread and thus increasing share to the suppliers. This entails a predetermined maximum APY for each asset, which will be used to calculate the linear equation for the final curve.

#### For borrowers

The gamification from phase 2 continues, meaning that the original predetermined maximum APY can be decreased with the multiplier just like in phase 2.

**For borrowers with NO NLL tokens staked (original curve):**

**For borrowers with NO NLL tokens staked (original curve):**

Where:

$y_b$= the P2P APY that the borrowers use without NLL tokens staked

$m_3b$= the slope derived from the max APY (underlying pool’s borrow rate) at the end of phase 2

$x$= the period that the N-Account is opened for (in days)

$b_3b$= the constant for borrowers without staked NLL tokens

**For borrowers WITH NLL tokens staked (new curve):**

**For borrowers WITH NLL tokens staked (new curve):**

This new curve is adjusted for the multiplier so it has a lower max APY and therefore, a new slope, which means a slower increase in the APY over the duration of this phase.

Where:

$y_b^*$= the P2P APY adjusted for staked NLL tokens

$m_3^*b$= the new slope adjusted by the change in max APY due to the staking of NLL tokens, which means $m_3^*b=m_3b*z_3b$

$x$= the period that the N-Account is opened for (in days)

$b_3^*b$= a new constant from the equation adjusted for the staked NLL tokens

#### Borrower's multiplier for phase 3

Where:

$z_3b$= the borrower’s multiplier in **phase 3** which takes value between {0.5,1}

$z_2b$= the borrower’s multiplier in **phase 2** which takes value between {0.5,1}

**Max APY for phase 3:**

**Max APY for phase 3:**

Where:

$y^*_3$= the maximum APY used to calculate the slope for the new line for phase 3

$m_3b$= the slope from the original curve

$z_3b$= the borrower’s multiplier which takes value between {0.5,1}

$x$= the period that the N-Account is opened for (in days)

$b_3b$= the constant for borrowers without staked NLL tokens

#### For suppliers

In phase 3, the supplier’s APY will now increase proportionally to the borrower’s APY.

Where the maximum supplier APY is predetermined to be able to find the slope m3s and eventually the constant b3s for the supplier’s linear equation in phase 3. Phase 3 uses the same spread formula as phase 2.

The **New spread < Original spread** always. To retain the spread, the supplier’s multiplier is multiplied to the new spread.

**The supplier's multiplier:**

Where:

$z_s$= the supplier’s multiplier which takes value over {1}

$u_s$= the constant representing the rate at which the multiplier (zs) increases as more NLL tokens are staked

$n_s$= the amount of NLL tokens staked in the protocol. More NLL tokens staked, means higher multiplier, and therefore, an increase in the supplier’s spread share

If $n_s=0$, then $z_s=1$ and the supplier receives the decreased spread share

**Supplier's spread share**

Where:

$S_*$= the new spread

$s$= the supplier's share of spread

$z_s$= the supplier’s multiplier which takes value over {1}

Last updated