# Borrowing

As established in the AMM section, X (or Y) refers to the supplied asset of a pool. Z refers to the interest per second of the pool. Depending on the spot price of the assets and the transition price of the pool, X can be the borrowable asset and Y the collateral asset, or vice versa, in any case, the borrowable asset will always be either X or Y (but not both of them).

## Borrowing ΔY (or ΔX) represents the borrower's locked collateral. ΔZ*d represents the change in the pool's reserve of the total interest. ΔX (or ΔY) represents the change in the pool's reserve for the borrowable asset (i.e., the principal amount borrowed by borrowers).
Borrowers lock the collateral asset and takes the borrowable asset from the pool, while paying interest upfront in the form of the collateral asset.
In other words, borrowers add Z*d to the AMM and remove X (or Y) from the AMM. Note that the collateral asset Y (or X) is completely isolated from the pool.
A borrow transaction is denoted by the following formula:
$(X + Y - ΔX - ΔY)(Z + ΔZ) = K$
The borrowed amount along with their interest is represented by an ERC-1155 token (called the Collateral Claim Token, CCT). CCT represents the locked collateral and borrowing position.
A borrowing transaction increases the pool's interest rate for the next transactions. The larger the borrowed size relative to the available liquidity of the pool, the higher the interest rate for the next transactions will be. This is known as price impact. However, note that this does not affect the interest rate of borrowers/lenders prior to this transaction.
The exact calculations of the new interest rate (after a borrowing transaction) is as follows:
$I = (Z +ΔZ)/(X+Y-ΔX-ΔY)$
Where,
• Z represents the original reserves of interest per second in the AMM
• ΔZ represents the change in interest per second (w.r.t. the AMM), which in this scenario, is positive
• X represents the original reserves of Token A in the AMM
• ΔX represents the change in Token A (w.r.t. the AMM), which in this scenario, is negative
• Y represents the original reserves of Token B in the AMM, which in this scenario, is zero
• ΔY represents the change in Token B (w.r.t. the AMM), which in this scenario, is zero
Thus, the pool's interest rate increases as more borrowing happens.

## Closing a borrow position

### Closing after maturity

At maturity, the CCT held by borrowers will be worthless as it could not be used to claim the locked collateral anymore. The locked collateral is forfeited and distributed to lenders and LPs.
Hence, borrowers have to repay their debts before maturity in order to claim their locked collateral.

### Closing before maturity When repaying their debts, borrowers add X (or Y) to the AMM, while removing Z*d from the AMM and unlocking their locked collateral. As a result, after closing a borrow position, the pool's interest rate will decrease.
Note that closing their borrowing positions early does not charge interest in a pro-rated manner. The variables determining how much interest a borrower has to pay to close their debts (before maturity) are: 1) how long the borrower has been borrowing for, 2) the interest rates at entry and exit, and 3) the amount of liquidity available at exit.
The longer the borrower has been borrowing for, and the higher the interest rate at exit (relative to entry), the higher the proportion of the interest rate the borrower has to pay. Additionally, there is price impact based on the available liquidity.

## Risks

Borrowers have to repay their debts before maturity, else their collateral will be forfeited.
The CCTs held by borrowers will be worthless at maturity and the forfeited collateral will be distributed to lenders and LPs.