This article explores the mechanics of internal "price oracles" within Curve Finance Cryptoswap pools, with additional insights into LLAMMA price oracles. Curve's Stableswap and Cryptoswap pools operate without external price oracles—a design choice that enhances security against DeFi exploits.
👉 Learn more about decentralized finance security
Purpose of Internal Price Oracles
CryptoSwap pools facilitate trading between volatile assets, necessitating an internal price tracking mechanism. Unlike external oracles, these pools derive asset prices from their own trading activity. Two key parameters govern this process:
- Price Oracle: The pool's estimated fair price for an asset
- Price Scale: The actual liquidity distribution price
The system tracks recent trades via last_prices
, with price_oracle
calculated as an exponential moving average (EMA) of these values. This EMA approach ensures the oracle responds dynamically to market trends while price_scale
gradually aligns with oracle values through liquidity rebalancing.
Exponential Moving Average Explained
The price_oracle
employs an EMA—a weighted average prioritizing recent data—unlike simple moving averages that treat all data points equally. This method:
- Reacts faster to price trends
- Reduces lag in price updates
- Mitigates manipulation attempts
Example: If ETH price jumps 10% in a day, EMA will reflect this change more prominently than a 30-day simple average.
Oracle Update Mechanism
The gas-intensive tweak_price
function triggers during liquidity operations:
add_liquidity
remove_liquidity_one_coin
exchange
operations
Key Update Features:
- Block-level updates:
price_oracle
refreshes just once per block - Profit-based rebalancing: Liquidity adjusts only when pool profits exceed the
allowed_extra_profit
threshold - Safety checks: Prevents unnecessary rebalancing during price pegs
Manipulation Resistance
While not foolproof, Curve's oracle design incorporates multiple anti-manipulation measures:
- Block-rate limiting: Single-block price spikes are dampened
- EMA smoothing: Requires sustained attack across multiple blocks
- Liquidity thresholds: Larger pools are inherently more secure
👉 Discover advanced DeFi security strategies
Stableswap Pools Implementation
Newer Stableswap pools feature:
- Moving average price oracles
- Real-time price calculations
- Important distinction: No
price_scale
parameter exists
Note: Older Stableswap pools may lack oracle functionality entirely.
LLAMMA's Oracle Approach
LLAMMA introduces a hybrid model:
- Utilizes external price oracles for collateral valuation
- Implements EMA smoothing on oracle prices
- Enables automatic conversions between ETH/crvUSD based on band ranges
The system creates arbitrage opportunities when external prices diverge from pool prices, with mechanisms to absorb volatility.
FAQ Section
Why doesn't Curve use external oracles?
External oracles introduce single points of failure and have been exploited in past DeFi hacks. Internal oracles derive prices directly from pool activity.
How often do price oracles update?
Oracle values refresh at most once per block, regardless of trading frequency.
Can price oracles be manipulated?
While possible in low-liquidity pools, EMA smoothing and block-level updates make sustained manipulation costly.
What's the difference between CryptoSwap and Stableswap oracles?
CryptoSwap tracks both oracle and scale prices, while Stableswap only maintains oracle prices.
How does LLAMMA handle oracle failures?
LLAMMA's EMA smoothing and banding mechanism provide buffers against sudden price disruptions.
Key Takeaways
- Curve's internal oracles offer security advantages over external systems
- EMA calculations provide responsive yet stable price feeds
- Multiple safeguards exist against manipulation attempts
- Different pool types implement oracles with varying approaches
For developers: Always validate oracle data against multiple sources when building dApps.