Interests accrual and position accounting granularity

Liquidity ratios and token amounts

The right of a position to claim interests is represented by a liquidity ratio, that grows with each interest payment. Each tick of an order book has its own liquidity ratio.

When a lender deposits funds, they send a normalised amount of tokens to the Position contract - an actual amount of tokens. This amount is adjusted to (divided by) the target interest rate tick liquidity ratio, to be eligible for future fees. The normalised amount equivalent to the adjusted amount is obtained by multiplying the latter to the updated liquidity ratio, that can only grow.

The liquidity ratio is then updated progressively when interests are paid to the target tick. While the liquidity ratio grows, and as the adjusted amount of a position stays the same, the normalised amount within the position grows.

The liquidity ratios helps to mutualise the computation for all positions. Instead of dividing the fees between all positions and updating them all separately, the Atlendis protocol can simply update one parameter that will be used to compute all balances within the tick in question.

Liquidity ratio calculations

The basic formula is the following, for position i and interest rate r for a target pool:

AdjustedAmounti=NormalizedAmountiβˆ—LiquidityRatiorAdjustedAmount_{i} = NormalizedAmount_{i} * LiquidityRatio_{r}

The liquidity ratio evolves with the following formula, when a fee is paid to the interest rate tick r:

liquidityRatio(t+1)=liquidityRatio(t)+fee/totalAdjustedAmountrliquidityRatio(t+1) = liquidityRatio(t) + fee /totalAdjustedAmount_{r}

Note that in the case above, the fee is distributed to all the positions within that tick. That is the reason why the total adjusted amount deposited within a tick is used, instead of iterating over all positions.

Deposits after a Loan and Epochs accounting

During a loan, lenders can still deposit funds. However, these funds will not be directly borrowed, and thus will not earn the same amount of fees that funds within that same tick that are already borrowed.

A strong assumption of the Atlendis protocol is that every position should get exactly the interests that it's owed. The interests that a position can get depend on the amount that was borrowed, and the duration for which is was borrowed. In order to keep exact calculations, the ticks track another level of granularity within it's data structure, which is the epoch.

When a tick is not borrowed, then all funds are located within the Base Epoch, which obeys to the liquidity ratio formula above. After the tick is borrowed, all new deposits will be made within a New Epoch, which constitutes funds that are not borrowed yet, and waiting to be matched. These positions will accrue interests at a different (lower) pace that previously borrowed positions, hence the difference in accounting. If a new epoch is borrowed, then all funds deposited after the further borrow will be located in another new epoch, which will have its own accounting. That way, the data structures can keep an exact accounting of what each position is owed.

When the loan is repaid, all positions are adjusted to the liquidity ratio, and sent back to the base epoch. The process can happen again for upcoming cycles. The data structures of the pool keep track of when each position was deposited, in order to be able to get to the exact interests repartition between all positions within a tick.

More details on the concepts described above can be found in the Atlendis v2 whitepaper.

Last updated