Skip to content

Commit

Permalink
curve LP oracle overview
Browse files Browse the repository at this point in the history
  • Loading branch information
uprotocore committed Dec 3, 2023
1 parent 31b7a13 commit 4df753e
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions doc/dev/oracles/CurveLPOracle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# CurveLPOracle Smart Contract Technical Overview

## Contract Overview
`CurveLPOracle` is a smart contract designed to provide USD pricing for Curve Finance liquidity pool (LP) tokens. It interacts with various Curve and Chainlink interfaces to achieve this.

## Key Features

### 1. Interfaces and Libraries
- Implements `IOracleUsd` for USD pricing functionality.
- Uses `SafeMath` library for safe mathematical operations.
- Interacts with various interfaces including `ERC20Like`, `ICurveProvider`, `ICurveRegistry`, `ICurvePool`, and `IOracleRegistry`.

### 2. State Variables
- `curveProvider`: Immutable address of the Curve Provider contract.
- `oracleRegistry`: Immutable address of the OracleRegistry contract.
- `Q112`: A constant for Q112 encoding, representing a fixed-point number with 112 fractional bits.
- `PRECISION`: A constant representing the precision level (1e18) used in calculations.

### 3. Constructor
Initializes the contract with the addresses of the Curve Provider and OracleRegistry contracts.

### 4. Functions
- `assetToUsd`: Main function of the contract. It takes a Curve LP token address and an amount, returning its USD price in Q112-encoded format. The function performs several checks and calculations:
- Validates that the input amount is non-zero.
- Retrieves the Curve pool associated with the LP token.
- Checks that the LP token has standard 18 decimals.
- Determines the number of coins in the Curve pool.
- Iterates through each coin in the Curve pool to find the minimum USD price using registered oracles.
- Calculates the USD price of the LP token based on the virtual price of the Curve pool and the minimum coin price.

### 5. Error Handling and Validation
- Ensures the Curve pool address for the LP token is valid.
- Validates that the LP token adheres to 18 decimals standard.
- Confirms that the coins count in the Curve pool is non-zero.
- Checks for the existence of a registered oracle for each coin in the Curve pool.

### 6. External Dependencies
- Depends on external Curve and Chainlink contracts for fetching pool information, coin details, and USD pricing.
- Utilizes OracleRegistry for determining the appropriate oracle for each coin in a Curve pool.

## Conclusion
`CurveLPOracle` is a specialized oracle contract for determining the USD price of Curve LP tokens. It leverages Curve's pool mechanics and integrates with Chainlink oracles, ensuring accurate and up-to-date pricing for assets within Curve liquidity pools.

0 comments on commit 4df753e

Please sign in to comment.