Borrowing/Repaying Liquidity

Borrowing

Borrowers can borrow from discretized bins chosen by the indexer, 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.

Drawing
First two bins of the position is borrowed. Liquidity subsequently reduced in those regions

For a given x_b amount of token_x the borrower is borrowing from bin i, the liquidity subsequently lowered in that bin is

Lb=xbPi+1PiPi+1PiL_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.

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.

Repaying

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.

Loan Info

A position's loan info is stored inside an array of struct LiquidityLoan.

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.

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.

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%.

Last updated