# Borrowing/Repaying Liquidity

## Borrowing

Borrowers can borrow from discretized bins chosen by the [indexer](determining-which-ticks-to-borrow-from), 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="https://20107516-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhzaQpygyckQc1GpfmDWt%2Fuploads%2F25kADRqQZMg1wh3XBePE%2Ffile.excalidraw.svg?alt=media&#x26;token=9e2c4ac0-b3a4-4566-b720-2bb333e832e9" 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="https://20107516-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhzaQpygyckQc1GpfmDWt%2Fuploads%2FgfGg20mRV3hgWtTEfksU%2Ffile.excalidraw.svg?alt=media&#x26;token=eaa22aee-5e50-4fad-8d0e-326c06b4e1c4" 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](../intro/participants/leverage-traders).&#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="https://20107516-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhzaQpygyckQc1GpfmDWt%2Fuploads%2FcKm5xn8fmBdLnMWP2xeX%2Ffile.excalidraw.svg?alt=media&#x26;token=296f18ad-6fac-4c9f-9879-9a0da675027c" 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;





####





