# 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](/limitless/advanced/borrowing-repaying-liquidity.md) 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](/limitless/advanced/premiums.md)), subject to the solvency condition above.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://limitless.gitbook.io/limitless/advanced/determining-which-ticks-to-borrow-from.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
