Borrowing/Repaying Liquidity
Last updated
Last updated
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.
For a given x_b amount of token_x the borrower is borrowing from bin i, the liquidity subsequently lowered in that bin is
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 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.
A position's loan info is stored inside an array of struct LiquidityLoan
.
The following diagrams depict the evolution of a position's loan. Data for each bin is contained in the LiquidityLoan
struct.
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%.