# Determining which ticks to borrow from

When a user seeks to obtain leverage in Limitless, the system selects specific ticks from which to borrow. This selection via our indexing algorithm is designed to ensure LPs' solvency in any market conditions. Limitless's innovative approach to utilizing discretized ticks and an indexing algorithm allows a streamlined process for one to obtain leverage from order books like AMMs.

**Necessity of Discretization**

The discretization of liquidity positions is pivotal for two key reasons:

1. **Efficient Indexing**: The system must efficiently identify tick ranges that fulfill solvency criteria,&#x20;
2. **Computational Efficiency**: Discretizing tick ranges streamlines the process of tracking, managing, and adjusting borrowed and repaid liquidity.

**Example Scenario**

A trader wants a 20x long position on ETH, at the current price of 2000 USD/ETH. In this case, the indexing algorithm says the trader should ideally be borrowing from the 1900-1910 and 1910-1920 USD bins.

If liquidity is available across a broader range, say 1800-2200 USD, the lending process would involve: a. Withdrawing liquidity from 1800-2200 USD. b. Lending liquidity within the 1900-1910 and 1910-1920 USD ticks. c. Reproviding liquidity in segmented positions (1800-1900, 1900-1910, 1910-1920, 1920-2200 USD), since liquidity is no longer uniform in 1800-2200.&#x20;

This naive approach is more computationally demanding than just withdrawing and lending from the 1900-1910 and 1910-1920 ticks

**Indexing Algorithm**

Therefore Limitless uses an algorithm that, given a collateral amount and a desired leverage, will output one or more ticks that&#x20;

* [ensure LPs' solvency](#solvency-criteria)(more information below)
* cumulatively equate to the borrowed amount while satisfying the solvency criterion.
* [minimizes the premiums quoted to borrowers](#minimizing)(more information below)

{% hint style="info" %}
The indexing algorithm determines which discretized tick ranges(bins) to borrow from, given desired leverage and collateral amount.&#x20;
{% endhint %}

### Ensuring LP Solvency&#x20;

Every debt originated in Limitless begins overcollateralized. However, as price fluctuates, the system needs to ensure the LPs are always made whole, or that the LP's loss is capped by his impermanent loss. This is achieved by enforcing the collateral amount to be greater than or equal to what the LP  would expect for his liquidity to be converted to.&#x20;

For all borrowed ticks _i_, this is represented via enforcing the invariant below;&#x20;

1. Borrowing token y with token x as collateral, the system necessitates collateralAmount\_x

$$
collateralAmount_x>=\sum_i L_i *\frac{\sqrt{P_{a_{i+1}}} -\sqrt{P_{a_i}} } {\sqrt{P_{a_{i+1}}} \sqrt{P_{a_i}} }
$$

when debt amount in token y is&#x20;

$$
debt_y=\sum_i L_i  *({\sqrt{P_{a_{i+1}}} -\sqrt{P_{a_i}} })
$$

2.  Borrowing token x with token y as collateral, the system necessitates collateralAmount\_y

    &#x20;

$$
collateralAmount_y>=\sum_i L_i  *({\sqrt{P_{a_{i+1}}} -\sqrt{P_{a_i}} })
$$

when debt amount in token x is

$$
debt_x=\sum_i L_i  *\frac{\sqrt{P_{a_{i+1}}} -\sqrt{P_{a_i}} } {\sqrt{P_{a_{i+1}}} \sqrt{P_{a_i}} }
$$

and where _L\_i_ denotes the liquidity borrowed and [reduced](borrowing-repaying-liquidity) in tick i.&#x20;



### Minimizing Premiums Quoted&#x20;

When determining which ticks to borrow from, the indexing algorithm is designed to

1. skip the highly utilized ticks&#x20;
2. borrow from ticks the farthest possible tick ranges from current prices([since premiums quoted are proportional to the distance to current price from the borrowed price](premiums)), subject to the solvency condition above.





