# Price feeds

Price feeds are a critical component of decentralised lending protocols, enabling the system to function without reliance on a centralized entity. These feeds serve multiple essential functions, including:

1. **Borrowing**, by ensuring that loans are adequately collateralized.
2. **Liquidating**, by confirming that a loan is under-collateralized and that the borrower is compensated fairly.
3. **Withdrawing delegation rewards**, particularly when the assets in the lending pool are not in ADA.

### Key points

* **Liquidity movements on DEX will impact positions**, even if the asset price seems unchanged.
* **If you control a large part of a single asset's liquidity**, it's better to move liquidity in chunks or even notify the team before the movement.

## How it works

When a price feed is requested, the price is provided by the client. The oracle verifies the price and, if it's valid, signs the data. Only signed data can be used by Lenfi V2.

The oracle only validates the values of verified pools. The team is making its best effort to maintain the list up-to-date.

{% hint style="info" %}
You can find current approved DEX pools [here](https://gist.github.com/aada-finance/0baf007fb47d15b64a63ad54b3768eb7)
{% endhint %}

### How the collateral and loan values are calculated

The example below illustrates how the price feed is used in the Lenfi protocol. Assume that the price feed has data of...

```javascript
//LENFI/ADA pair priceFeed data
{
...
tokenAmount: 1,000,000 // verified amount on DEX'es (LENFI)
adaAmount: 7,000,000 // verified amount on DEX'es (ADA)
}
```

Where the spot token price could be seen as 7 ADA/LENFI. However, if someone tries to use 100,000 LENFI as collateral value would be:

```javascript
// Function to find tokenSale value
saleValue = (inputAmount * outputReserve) / (inputReserve + inputAmount * 0.997)
saleValue = (100000 * 7000000) / (1000000 + 100000 * 0.997)
saleValue = 636,537 ADA
```

{% hint style="info" %}
The above formula is used to find out the assets value if it is **sold on a DEX**
{% endhint %}

In case someone tries to borrow 100,000 LENFI tokens it's value would be calculated by:

```javascript
// Function to find tokenPurchase price
purchaseValue = (-outputAmount * inputReserve) / (0.997 * outputAmount - outputReserve)
purchaseValue = (-100000 * 7000000) / (0.997 * 100000 - 1000000)
purchaseValue = 777,518 ADA
```

{% hint style="info" %}
The above formula is used to find out how much ADA you **buy assets on DEX**
{% endhint %}

The above example tells us that:

* If you **sell 100,000 LENFI** you would receive **636,537** **ADA.** That's the value would be seen on Lenfi if you put 100,000 LENFI as collateral.
* If you **buy 100,000 LENFI** you need to pay **777,518** **ADA.**&#x54;hat's the value would be seen on Lenfi if you borrow 100,000.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lenfi.gitbook.io/docs/price-feeds.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
