💬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.

You can find current approved DEX pools here

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...

//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:

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

The above formula is used to find out the assets value if it is sold on a DEX

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

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

The above formula is used to find out how much ADA you buy assets on DEX

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.That's the value would be seen on Lenfi if you borrow 100,000.

Last updated