Comment on page

# Liquidation and Liquidity Theoretical

## Enter Markets (Use fTokens as collateral)

We require users to specify whether they want to use a lent asset as liquidity for borrowing.

## How does liquidity work?

Every open borrow is subject to be liquidated by a third party (that is, anyone) if the underlying value of the collateral locked in relation to the current value of the borrowed assets, falls under a certain level.
The following values are in the user's balances
$collatUnderlyingMantissa_{n} = \\\frac{\#fTokenSupplied_{n}*exchangeRateMantissa_{n}*collateralFactorMantissa}{mantissa}$

### NOTE: fTokenSupplied_n references fTokens supplied in entered markets.

$debtUnderlyingMantissa_{n}= \#borrowedTokensInUnderlying_{n}*mantissa_{n}$
Note the n subscript implies the specific token

#### totalCollatDollarMantissa

$totalCollatDollarMantissa =\\\sum_{i=1}^n\frac{collatUnderlyingMantissa_{n}*dollarPerUnderlying_{n}}{underlyingDecimal_{n}}$

#### totalDebtDollarMantissa

$totalDebtDollarMantisssa = \\\sum_{i=1}^{n}\frac{debtUnderlyingMantissa_{n}*dollarPerUnderlying_{n}}{underlyingDecimal_{n}}$

#### Zero Liquidity Point

$\\totalDebtDollarMantissa =totalCollatDollarMantissa$

### Liquidation

Liquidation is a process in which one user repays the debt of the a borrower and essentially purchases some of the borrowers collateral at a discounted rate relative to the amount of repayment. On the Finterest protocol, we consider a user as underwater when they hit the liquidation point specified below:

#### Liquidation Point

$liquidationPoint =\\(totalDebtDollarMantissa >\\\frac{liquidationThresholdMantissa*totalCollatDollarMantissa}{mantissa})$
When you hit liquidation point, a user may repay your debt until:
$totalDebtDollarMantissa <=\\\frac{liquidationThresholdMantissa*totalCollatDollarMantissa}{mantissa}$
Liquidation/Repayment of a borrower's debt happens on an individual token and not for all assets at once.

#### Discounted Collateral Purchase/Seizure

Let n = the token that is being borrowed and m = the token that the liquidator wants to seize from the borrower
$amountRepayDollarMantissa=\\\frac{repayedAmount_{n}*dollarPerUnderlying_{n}*mantissa}{underlyingTokenDecimal_{n}}$
$collatSiezedDollarsMantissa_{m}= \\\frac{repaymentAmount_{n}*dollarPerUnderlying_{n}*liquidationDiscountMantissa_{n}}{underlyingTokenDecimal_{n}}$
$collatSiezedfTokens_{m} = \\\frac{repaymentAmountDollarsMantissa_{m}*decimal_{m}}{dollarPerUnderlying_{m}*exchangeRateMantissa_{m}}$
A portion of seized collateral gets sent to the #Reserves and another portion to the liquidator
$amountfTokensToReserves_{m}= \\\frac{collatSeizedfTokens_{m}*protocolSeizeShare_{m}}{mantissa}$
$amountfTokensToLiquidator_{m}=\\collatSeizedfTokens _{m}-amountfTokensToReserves_{m}$

### Liquidation Checks

1. 1.
NOTE:
$repayedAmount_{n} =\\ min[(closeFactorMantissa_{n}*borrowBalanceBorrower_{n}/mantissa)\\,specifiedAmount_{n}]$
Only the amount repaid will be taken from your balance so rest assured you are not being charged anymore than whats repaid.
1. 2.
Borrower hit liquidation point
2. 3.
$amoutRepayDollarMantissa <=\\(totalDebtDollarMantissa\\-\frac{liquidationThresholdMantissa*totalCollatDollarMantissa}{mantissa})$
1. 4.
$collatSiezedfTokens_{n} <=fTokenCollatBalanceBorrower_{n}$