Skip to main content

CryptopoolLPOracle

The source code of the CryptopoolLPOracle.vy contract can be found on GitHub. The contract is written with Vyper version 0.4.3.

Overview

The CryptopoolLPOracle is a price oracle contract that provides LP token pricing for Curve cryptopools. It combines the LP token price from a Curve cryptopool with a price aggregator to return the LP token value in aggregated USD terms. This oracle is used by the Yield Basis protocol to determine the value of LP tokens for various calculations including debt limits, collateral values, and trading operations.

Oracle Principle and Reliability

The oracle operates on a crvUSD price normalization principle that enhances reliability and reduces manipulation risks:

  1. Curve Pool LP Price: The underlying Curve Cryptoswap Pool provides the LP token price relative to the 0th index coin (crvUSD in YieldBasis)
  2. crvUSD Price Aggregation: A price aggregator provides the "real" price of crvUSD across multiple major liquidity pools
  3. Price Normalization: The final LP price is calculated as lp_price = 2 * self.virtual_price * isqrt(self.internal_price_oracle() * 10**18) // 10**18

This approach is reliable because:

  • Curve pools are battle-tested and provide accurate LP pricing based on actual liquidity. The same "normalization" happens on crvUSD mint and lending markets.
  • crvUSD price aggregation uses multiple major liquidity pools to avoid price swings from any single pool
  • Price normalization ensures we use the "real" crvUSD price rather than pool-specific pricing

Function Documentation

Public Variables

The CryptopoolLPOracle contract exposes several public variables for reading contract state and configuration.

Immutable Variables

  • POOL (Cryptopool) - Curve cryptopool contract address (immutable)
  • AGG (PriceOracle) - Price aggregator contract address (immutable)

price()

Description:
Returns the current LP token price in aggregated USD terms. This is a view function that calculates the price by multiplying the LP token price from the cryptopool with the price aggregator's USD value.

Returns:
uint256 - LP token price in aggregated USD (scaled by 10^18).

📄 View Source Code
@external
@view
def price() -> uint256:
return staticcall POOL.lp_price() * staticcall AGG.price() // 10**18

price_w()

Description:
Returns the current LP token price in aggregated USD terms. This function can update the price aggregator's state and is used when fresh pricing data is needed for transactions.

Returns:
uint256 - LP token price in aggregated USD (scaled by 10^18).

📄 View Source Code
@external
def price_w() -> uint256:
return staticcall POOL.lp_price() * extcall AGG.price_w() // 10**18