---
# System prepended metadata

title: Tezos Lending Platform Architecture

---

# Tezos Lending Platform Architecture

## Deposits
Users can deposit funds into pools that can be lent out.

## Borrowing 
Users have to overcollateralise the loans. They have to maintain a health factor above 1 (see Health Factor section below) before their collateral starts to get liquidated to cover their position.

### Health factor of a borrow position

Every borrow position has an associated *health factor*, which must be kept above 1 in order to keep the position from being liquidated.

The health factor is calculated as follows:

$$ H_f = \frac{\textrm{TotalCollateralInTez} \cdot L_Q^a}{\textrm{TotalBorrowedInTez} \cdot \textrm{TotalFeesInTez}} $$

- TotalCollateralInTez, TotalBorrowedInTez, and TotalFeesInTez are all denominated in Tez, regardless of whether or not the collateral or loan is in Tez. (We'll have to use an oracle of some kind for that.)
    - This means if someone chooses to borrow or put as collateral a highly volatile asset they should be aware that their position could be liquidated if the price moves too much.
- $L_Q^a$ is a time-weighted average of a liquidation constant, $L_Q$, which denotes the amount by which one has to overcollateralize their loans. For example, if we set $L_Q$ at 1.3, collateral must be 30% more than total borrowed and total fees in order to prevent liquidation.

### Collateral
Collateral can be in any asset that has a pool. If you want to deposit funds, you can use those as collateral.


## Interest Rates

The following is how Aave calculates variable interest rates.

Interest rates depend on utilisation *U*, or the proportion of deposited funds in a particular pool that are being lent out. The idea is that the more liquidity there is, the cheaper it is to borrow--or in other words, that interest rates go up with U. 

There are some global constants we need to define (presumably maintained by governance?):

- $U_\textrm{op}$ : the optimal utilisation ratio
- $R_0$ : The base interest rate
- $R_1$ : The rate below optimal utilisation
- $R_2$ : The rate above optimal utilisation 

If utilisation *of a given pool* (the proportion of deposited funds being borrowed) is $U \leq U_\textrm{op}$ (leq optimal), then interest rates are calculated as follows:

$$ R_\textrm{var} = R_0 + \frac{U}{U_\textrm{op}} R_1 $$ 

If utilisation is above optimal, rates go up faster to try to keep the system roughly at equilibrium.

$$ R_\textrm{var} = R_0 + R_1 + \frac{U - U_\textrm{op}}{1 - U_\textrm{op}} R_2 $$ 


### Compounding 
Total accumulated interest can be calculated and updated at every block. Loans are perpetual, in that they don't have a date by which they need to be repaid.

### Liquidation 
If the health factor of any borrow position goes below 1 then it will be automatically liquidated until its health factor goes below 1.

Details TBD.

## Rewards
Splitting up the rewards might be as simple as giving every liquidity provider the same rate of returns, proportional to their stake in the pool.


## Withdrawing Liquidity 
It might make sense to have withdrawal fees to discourage people from moving money in and out of the pools too quickly.

The optimal utilisation ratio $U_\textrm{op}$ should be chosen so that no one is impeded from withdrawing their liquidity because it's been lent out. I'd guess around 0.8 or 0.9? That could be updated dynamically too.