# Under the Hood of a Lending Network

There are many parameters that go into the creation of a custom lending network. These parameters can broadly be divided into two categories:

* **Tunable Parameters:** those that can be customized and changed to fit the creator's needs
* **State Parameters:**  those that apply to each Money Market and define their overall state

This section goes over all the parameters in these two categories and their definitions.

## **Tunable Parameters of a MM**

<table><thead><tr><th width="280">Parameter Name</th><th width="465.33333333333326">Description</th></tr></thead><tbody><tr><td><mark style="background-color:yellow;"><strong><code>collateralFactor</code></strong></mark></td><td>A multiplier representing the amount you can borrow against your collateral (eg. <mark style="background-color:yellow;"><code>collateralFactor</code></mark> of 0.8 to allow borrowing 80% of collateral value). Must be between 0 and 1.</td></tr><tr><td><strong><code>liquidationFactor</code></strong></td><td>A multiplier representing the liquidation threshold. For example, <code>liquidationFactor</code> of 0.9 means that if the amount you borrow is worth (at least) 0.9 of your collateral, your position is subject to liquidation. Must follow: <code>collateralFactor</code> &#x3C;= <code>liquidationFactor</code>&#x3C; 1.</td></tr><tr><td><strong><code>liquidationIncentive</code></strong></td><td>A multiplier representing the additional percent value that a user calling liquidate receives, eg. 1.05 for a 5% bonus. This discount applies to the asset being seized (that is, what was used as collateral).</td></tr><tr><td><strong><code>reserveFactor</code></strong></td><td>The portion of borrower-paid interest (per block) that goes to the reserve. The remainder of the borrower-paid interest goes to the MM's suppliers.</td></tr><tr><td><strong><code>activeCollateralCapUSD</code></strong></td><td>The maximum value (in USD) that can be used as collateral to borrow against. To be used as collateral, the total active collateral in said asset must be smaller than <code>activeCollateralCapUSD</code>.</td></tr><tr><td><strong><code>borrowCap</code></strong></td><td>The maximum number of tokens that can be borrowed from a MM (best thought of in terms of a percentage of tokens in circulation, eg. if there are 100,000,000 tokens in circulation, then a <code>borrowCap</code> of 5,000,000 is 5%)</td></tr><tr><td><strong><code>closeFactor</code></strong></td><td>The maximum percentage of the loan that the liquidator can repay; in Ola, the <code>closeFactor</code> is a constant set at 50% across all lending networks.</td></tr></tbody></table>

## State Parameters of a MM

At this time, there is a maximum of 30 Money Markets allowed per lending network. Every MM's smart contract includes the following components:

<table><thead><tr><th width="242.85461522402028">Parameter Name</th><th width="465.33333333333326">Description</th></tr></thead><tbody><tr><td><strong><code>underlyingToken</code></strong></td><td>The token that can be lent/borrowed in the MM .</td></tr><tr><td><strong><code>cash</code></strong></td><td>The amount of <code>underlyingToken</code> held by the MM. The balance increases whenever tokens are deposited into the MM, and decreases whenever tokens are borrowed from the MM.</td></tr><tr><td><strong><code>borrowedBalance</code></strong></td><td>The total amount of <code>underlyingToken</code> that has been lent to borrowers. This amount grows, on a per-block basis, according to the interest rate that borrowers need to pay.</td></tr><tr><td><strong><code>reserveBalance</code></strong></td><td>The total amount of <code>underlyingToken</code> that the MM has set aside as a protocol fee. This amount increases as borrowers pay interest and decreases when the admin withdraws these tokens. The reserve can be used, among other things, as an insurance fund to cover bad debt incurred by the MM.</td></tr><tr><td><strong><code>oToken</code></strong></td><td>A receipt token that's minted and credited to the depositor of <code>underlyingToken</code> in a MM. Whoever holds <code>oToken</code> can claim the <code>underlyingToken</code> from the MM. The conversion rate from <code>oToken</code> to <code>underlyingToken</code> absorbs the interest that borrowers pay. This means that 1 <code>oToken</code> is worth more <code>underlyingToken</code> as time passes.</td></tr></tbody></table>

In addition to the parameters found in the MM's smart contract, other variables pertaining to each MM must be determined before launching a Lending Network.

### Interest Rate Model

The interest rate model is a function implemented in each MM; it takes the **utilization rate** of the MM as input and outputs the interest rate (per block) that borrowers pay.

* Utilization Rate: The ratio between the total amount deposited into a MM and the amount borrowed from it, calculated as:\
  \
  `borrowedBalance / (underlyingBalance + borrowedBalance - reserveBalance)`

An interest rate model needs to make sense, so Ola has pre-approved a few interest rate models from which LeN creators can choose. You can view the approved Interest Rate Models and see which model is used by each money market here:[  Whitelisted Interest Rate Models](https://docs.google.com/spreadsheets/d/11JXP8NcsTVozrMn4Xc1WXcNvlgRAnOKFjBkr075yLos/edit?usp=sharing)

### Price Oracles

A price oracle is a smart contract that can be queried for the real-time price of the `underlyingToken`. The comptroller can this way get the updated price whenever it's needed. Some oracles rely on off-chain services that regularly report the asset's price and write it on-chain. Other oracles are purely on-chain, relying on an AMM.

At Ola, there are three options for oracles to enable an accurate price feed for a MM:

* A responsive price feed system from an **oracle provider** with which Ola is integrated:
  * Chainlink
  * Band
  * Witnet
  * DIA
  * More coming soon
* A low-resolution period **TWAP** price oracle, based on on-chain AMMs (eg. UniswapV2 Pairs)
* A combination of an **oracle provider backed by an anchor price**
  * Coinbase Pro price feed with a UniswapV2 Pair TWAP as anchor price.

#### Oracle Provider&#x20;

Using data feeds from reliable oracle providers, Ola's smart contracts can retrieve the latest pricing data of an asset by querying the provider's data registry.

#### TWAP

When possible, using one of Ola's integrated oracle providers is preferred. When a token is not supported by one of these oracles, a TWAP from a token pair containing sufficient liquidity can be used instead. The period is a configurable parameter per asset; for example, stablecoins might have a longer period of time (eg. 3 hours) and more volatile tokens might have a shorter period (eg. 20-30 minutes). We can use any type of UniswapV2 Pair clone in order to calculate TWAPs. UniswapV3 and BalancerV2 Pools will be supported soon.&#x20;

#### Oracle Provider + Anchor Price

Compound's Open Price Feed is a system that "allows Reporters to sign price data using a known public key, which Posters (any Ethereum address) can submit on-chain." At present, the only accepted reporter is Coinbase Pro, but we intend to add more reporters soon.

The price indicated by the price feed is not accepted automatically; rather, it must be within a predefined range across the anchor price. The band is a configurable parameter per asset; for example, stablecoins might have a tighter band (eg. 1%) and more volatile tokens a wider band (eg. 10-15%). Every time a poster reports the price of an asset, the system checks the anchor price, and if within the accepted band, the official price of the asset updates.
