Skip to main content

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

Each step is critical for accuracy:
  1. Pool Data Collection: Gather price, volume, reserve, and depth from all pools
  2. Mode Selection: Choose between volume-based or reserve-based weighting
  3. Outlier Filtering: Remove scam pools and manipulated prices
  4. Weight Calculation: Apply stable multiplier and depth adjustments
  5. Weighted Average: Compute final price

Step 1: Pool Data Collection

For each pool trading a token, we extract:
Example: Token XYZ trading on 4 pools:

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

Why log space?
  • A price of 0.50vs0.50 vs 1.00 (50% lower) should be treated the same as 2.00vs2.00 vs 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:
Why boost non-stable pairs?
  • 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)

When ponderWithDepth = true:
This prioritizes pools where large trades can execute with minimal slippage.

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

Response includes:

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.