> For the complete documentation index, see [llms.txt](https://limitless.gitbook.io/limitless/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://limitless.gitbook.io/limitless/advanced/borrowing-repaying-liquidity.md).

# Borrowing/Repaying Liquidity

## Borrowing

Borrowers can borrow from discretized bins chosen by the [indexer](/limitless/advanced/determining-which-ticks-to-borrow-from.md), and this is illustrated in the diagram below. Once the liquidity is lowered in the borrowed tick ranges it won't be used for trading until they are repaid.&#x20;

<img src="/files/oJQUWP6yG18et3C9qKth" alt="First two bins of the position is borrowed. Liquidity subsequently reduced in those regions" class="gitbook-drawing">

For a given x\_b amount of token\_x the borrower is borrowing from bin i, the liquidity subsequently lowered in that bin is

$$
L\_b =x\_b \frac{\sqrt{P\_{{i+1}}} \sqrt{P\_{i}} } {\sqrt{P\_{{i+1}}} -\sqrt{P\_{i}} }
$$

where P\_i+1 and P\_i is the starting price of the next bin and bin i, respectively. &#x20;

The system ensures that bins that are lent out are always either fully in token0 or token1, which means the current tick is always outside the borrowed ranges.&#x20;

## Repaying

<img src="/files/ISWuaCzubmoenwm20Lnu" alt="" class="gitbook-drawing">

Repaying will simply revert the changes made to the liquidity distribution made from borrowing. Unlike when in borrowing where the current price is always outside the borrowed ranges, [when a trader or a borrower repays the current tick can be anywhere](/limitless/intro/participants/leverage-traders.md).&#x20;

### Loan Info

A position's loan info is stored inside an array of struct `LiquidityLoan`.&#x20;

```solidity
struct LiquidityLoan {
    int24 tick; // the first tick of the bin borrowed from 
    uint128 liquidity; // amount of borrowed liquidity
    uint256 lastGrowth; // accumulated growth at last premium payment 
}
```

The following diagrams depict the evolution of a position's loan. Data for **each** bin is contained in the `LiquidityLoan` struct.&#x20;

<img src="/files/IW0KvUz3cIQJEH4XIWzD" alt="" class="gitbook-drawing">

When a position is added to, the array can grow in length **and** the bins can grow in size. This means a trader can borrow from bins other than the currently borrowed bins.&#x20;

When a position is reduced, the bins can shrink in size, with the same proportion among all borrowed bins. If `reducePercentage` is 50% in the example above, all three bins' `liquidity` will be reduced by 50%.&#x20;

####


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://limitless.gitbook.io/limitless/advanced/borrowing-repaying-liquidity.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
