# Fair LP Token Oracles

Switchboard now offers fair LP token pricing oracles based on the work of Alpha Finance Lab!

# The Concern

A liquidity pool is a collection of funds locked in a smart contract, used to facilitate decentralized trading, lending, and many more functions [1]. With DeFi we are able to deposit assets into an LP pool, receive yield bearing LP tokens, and then borrow against our LP tokens. The price of these LP tokens is typically calculated by summing the total liquidity in the pool and dividing by the number of LP tokens issued. This basic calculation works well when the total liquidity in the pool is balanced between each asset but starts to fall apart when the pool liquidity is imbalanced.

Consider the WarpFinance incident where an attacker was able to use a flash loan to manipulate the price of an LP token by taking advantage of the imbalance, for which they used as collateral to borrow a greater amount of capital than was sufficiently allowed [2]. This type of hack takes advantage of the LP token price oracle in order to over-borrow from a lending provider.

# The Solution

Thanks to Alpha Finance Lab we have a solution: Fair LP Token Pricing [3].

Where, r is the amount of reserves, and p is the given price, for each pool member.

The fair LP formula takes into account the weight of each pool member’s liquidity to determine a fair price. What that means is as a pool imbalance grows, the price of the LP token decreases in order to lower the risk of flash loan attacks being able to over-borrow against them.

Switchboard oracles now give you the option to calculate the fair price of an LP token using the LpTokenPriceTask. Switchboard’s solution requires an existing aggregator for each pool member so that the formula is always using the previous aggregator result for each pool member’s price to prevent additional manipulation.

These feeds are live now so check out our feed explorer for an example of what these on-chain jobs look like:

- LP MERCURIAL USDC USDT PAI
- LP MERCURIAL USDC USDT wUST
- LP SABER USDT USDC
- LP SABER wUST USDC
- LP SABER mSOL SOL
- LP ORCA SOL USDC
- LP ORCA USDC USDT
- LP ORCA mSOL SOL
- LP RAYDIUM SOL USDC