Pricing Engine: Weighted Averages & Outlier Filtering
Mobula’s pricing engine aggregates price data from hundreds of liquidity pools across multiple chains to compute a single, reliable USD price for every token. This guide explains the mathematics and algorithms behind accurate price discovery.Why it matters: A token like WETH might trade at slightly different prices on Uniswap, Sushiswap, Curve, and 50 other DEXs. Our engine combines all these prices into one reliable value, filtering out manipulated pools and scams.
Overview: The Pricing Pipeline
- Pool Data Collection: Gather price, volume, reserve, and depth from all pools
- Mode Selection: Choose between volume-based or reserve-based weighting
- Outlier Filtering: Remove scam pools and manipulated prices
- Weight Calculation: Apply stable multiplier and depth adjustments
- Weighted Average: Compute final price
Step 1: Pool Data Collection
For each pool trading a token, we extract:Step 2: Mode Selection
The engine chooses a weighting strategy based on available data:
Reserve mode is a fallback for newly listed or low-activity tokens where volume data isn’t reliable.
Step 3: Outlier Filtering (Two-Phase Median)
This is the most critical step. It removes:- Scam pools with manipulated prices
- Stale pools with outdated prices
- Low-liquidity pools with extreme slippage
Phase 1: Weighted Median Calculation
Phase 2: Log-Space Deviation Check
- A price of 1.00 (50% lower) should be treated the same as 1.00 (100% higher)
- Log space makes these symmetric:
log(0.5) = -0.69,log(2) = 0.69
Filtering Result
After filtering our example:Step 4: Weight Calculation
Stable Multiplier
Pools paired with stablecoins provide more reliable pricing than pools paired with volatile assets:- Stable-paired pools (USDC, USDT) give direct USD prices
- ETH-paired pools require ETH→USD conversion, introducing small errors
- But ETH pairs often have MORE volume, so we boost stable pairs to balance
Depth Weighting (Optional)
WhenponderWithDepth = true:
Final Weights Example
Step 5: Weighted Average
The final price is computed as:Example Calculation
Asset-Level Pricing
For tokens deployed on multiple chains, we aggregate token prices into a single asset price.Why Aggregate?
The same token can have different prices on different chains due to:- Bridge delays and costs
- Chain-specific liquidity
- Arbitrage opportunities
Aggregation Algorithm
Example: USDT Asset Price
Outlier Detection for Assets
When aggregating across chains, we also filter token-level outliers:Performance Optimizations
Pre-allocated Buffers
Selector Caching
Validation & Safety
Price Bounds
Minimum Valid Prices
API Access
Token Price
Real-Time Updates
For real-time price updates, use the WSS Token Details WebSocket stream.Summary
The result: accurate, manipulation-resistant prices updated in real-time across 100+ blockchains.