Oracles

The Oracle module in CAP is responsible for providing reliable, up-to-date price and rate data to the protocol. It acts as the backbone for all value calculations, including minting, burning, borrowing, and liquidation processes.

Oracle Data Sources

The protocol leverages multiple oracle sources for different types of data:

Architecture

The Cap oracle system uses a unified approach where both price and rate oracles are combined into a single Oracle contract:

contract Oracle is IOracle, UUPSUpgradeable, Access, PriceOracle, RateOracle
  1. Oracle Contract - Main contract combining PriceOracle and RateOracle functionality

  2. PriceOracle Module - Handles asset price data with dual oracle configuration

  3. RateOracle Module - Manages interest rate data for lending operations

  4. Modular Adapters - Pluggable adapters for different data sources

  5. Access Control - Role-based access control for oracle configuration

Price Oracle

The price oracle provides asset price data with the following features:

  • Primary and Backup Sources: Dual oracle configuration for reliability

  • Staleness Protection: Configurable staleness periods for each asset

  • Modular Adapters: Pluggable price source adapters

  • Error Handling: Graceful fallback to backup sources

getPrice: retrieves price, falls back to backup oracle if prices are stale. If both timestamps revert, then relevant protocol functions are disabled until updated.

  • Returns: Current price and last updated timestamp

Rate Oracle

The rate oracle provides interest rate data for lending operations:

  • Market Rates: Returns the current borrow rate from external markets (e.g., Aave). Uses the AaveAdapter to fetch and relay the rate

  • Utilization Rates: Returns the interest rate based on asset utilization

  • Benchmark Rates: Returns the Cap’s minimum rate floors, set by admin

  • Restaker Rates: Agent-specific fixed delegation rates

Core Functions

marketRate: Fetches current market borrow rate for an asset

utilizationRate: Fetches utilization-based interest rate for an asset

benchmarkRate: Gets the minimum interest rate floor for an asset

restakerRate: Gets the restaker rate for a specific agent

Admin Functions

  • setPriceOracleData: Sets primary oracle data for an asset

  • setPriceBackupOracleData: Sets backup oracle data for an asset

  • setStaleness: Sets staleness period for asset prices in seconds

  • setMarketOracleData: Sets market rate oracle data for an asset

  • setUtilizationOracleData: Sets utilization rate oracle data for an asset

  • setBenchmarkRate: Sets minimum interest rate floor for an asset

  • setRestakerRate: Sets restaker rate for an agent

View Functions

  • priceOracleData: Gets primary oracle data for an asset

  • priceBackupOracleData: Gets backup oracle data for an asset

  • staleness: Gets staleness period for an asset

  • marketOracleData: Gets market rate oracle data for an asset

  • utilizationOracleData: Gets utilization rate oracle data for an asset

Data Structures

PriceOracleStorage

RateOracleStorage

OracleData

Last updated