Skip to main content

Oracle Overview

Drift Protocol relies on decentralized oracle networks to provide accurate, manipulation-resistant price feeds for all markets. Oracles are critical for:
  • Marking positions to market for PnL calculations
  • Calculating margin requirements and liquidation thresholds
  • Determining funding rates for perpetual markets
  • Validating order prices and preventing market manipulation

Supported Oracle Sources

Drift supports multiple oracle providers:
sdk/src/types.ts

Pyth Network

Pyth is the primary oracle provider for Drift:
  • High-frequency updates: Sub-second price updates
  • Confidence intervals: Built-in uncertainty quantification
  • Pull model: Users submit price updates in transactions
  • Push model: Traditional on-chain price updates
  • Multiple price feeds: Standard, 1K precision, 1M precision for different asset types
Pyth Pull oracles require the user to submit a price update in the same transaction as their trade. This ensures the latest price is always used.

Switchboard

Switchboard provides decentralized oracle aggregation:
  • On-demand: Users can trigger updates when needed
  • Aggregated data: Multiple data sources combined
  • Lower latency: Fast price updates

Prelaunch Oracle

For markets before official price feeds exist:
sdk/src/types.ts
Admins can set and update prices for prelaunch markets.

Oracle Price Data

Oracle data includes price, confidence, and timing information:

MM Oracle Price Data

For market making, additional data is included:

Oracle Validity Checks

The protocol validates oracle data before use:
sdk/src/types.ts

Validity Guard Rails

The protocol enforces guard rails on oracle data:
sdk/src/types.ts
Example Checks:

Historical Oracle Data

Markets maintain historical oracle data for TWAP calculations:
sdk/src/types.ts

TWAP Calculation

Time-Weighted Average Price provides manipulation resistance: TWAPnew=TWAPold+(pricecurrentTWAPold)×ΔtperiodTWAP_{new} = TWAP_{old} + \frac{(price_{current} - TWAP_{old}) \times \Delta t}{period} Where:
  • period = TWAP window (e.g., 3600 seconds for 1-hour TWAP)
  • Δt = time since last update
TWAPs are used for:
  • Funding rate calculations
  • Detecting price manipulation
  • Guard rails against oracle divergence

Oracle Price in Margin Calculations

For margin calculations, conservative oracle prices are used:
sdk/src/math/margin.ts
For Long Positions: marginPrice=oraclePriceoffsetmarginPrice = oraclePrice - offset For Short Positions: marginPrice=oraclePrice+offsetmarginPrice = oraclePrice + offset Where: offset=min(maxSpread×oraclePrice,confidence+baseSpread×oraclePrice)offset = \min(maxSpread \times oraclePrice, confidence + baseSpread \times oraclePrice) This provides a safety buffer against adverse price movements.

Oracle Price for AMM Operations

The AMM uses oracle prices to determine repegging targets:
The AMM continuously adjusts its peg multiplier to track the oracle price, minimizing arbitrage opportunities.

Oracle Confidence Intervals

Confidence intervals represent price uncertainty:
Usage:
  • Margin calculations: Use worst-case price (minPrice for longs, maxPrice for shorts)
  • Liquidations: Use conservative prices to avoid premature liquidation
  • Order validation: Reject orders if confidence too wide
Wide confidence intervals during high volatility can prevent trading or trigger stricter margin requirements.

Oracle Update Frequency

Different oracle types have different update frequencies:

Staleness Thresholds

The protocol defines staleness thresholds:
Stale prices are rejected to prevent exploitation.

Oracle Precision

Different oracle variants have different precision:
  • Standard: 6 decimals (e.g., $100.000000)
  • 1K: 3 decimals (e.g., $100.000) - for higher-priced assets
  • 1M: 0 decimals (e.g., $100) - for very high-priced assets
  • StableCoin: 6 decimals with tighter bounds for stablecoins
The protocol normalizes all prices to PRICE_PRECISION (1e6) internally.

Oracle Fallbacks

If primary oracle fails, the protocol has fallback mechanisms:
  1. Use last valid price: Within staleness threshold
  2. Use TWAP: If available and recent
  3. Use alternative oracle: If configured
  4. Pause operations: If no valid price available

Market Maker Oracle Updates

Market makers can submit their own oracle updates:
This is enabled via feature flags and allows designated market makers to provide additional price data.

Oracle Integration Example

Reading oracle data:

Oracle Security Considerations

TWAPs and confidence intervals make flash loan attacks and single-block manipulation ineffective. The protocol uses multiple data points and time-weighted averages.
Strict staleness checks prevent use of outdated prices during oracle downtime. Operations are paused rather than using stale data.
Wide confidence intervals during volatility prevent risky operations. The protocol waits for confidence to narrow before allowing certain actions.
Supporting multiple oracle providers (Pyth, Switchboard) provides redundancy and reduces single points of failure.

Oracle Price Examples

Standard Asset (SOL):
High-Priced Asset (BTC):
Stablecoin (USDC):

Next Steps

Markets

See how oracles are configured per market

Margin System

Understand oracle price usage in margin

AMM

Learn about AMM repegging with oracles

Integration Guide

Integrate oracle data in your app