DeFi Pricing Engine
Blockchain2024

DEFIPRICINGENGINE

Sub-second USD valuations for 5,000+ tokens via multi-hop Uniswap v3 sqrtPriceX96 paths.

10×
Faster vs GraphQL path
5K+
Tokens with USD paths
50K+
Pricing queries per day
SCROLL
Client
Revert Finance
Domain
Onchain Analytics
Platform
ClickHouse Service
Duration
Mar 2024 — Present
Core Stack
ClickHouse · Rust · Substreams
The Brief

THE
PROBLEM

Institutional DeFi position tracking requires real-time USD valuations for thousands of tokens. The legacy GraphQL subgraph approach couldn't handle query load.

ClickHouse Materialized Views computing multi-hop token pricing, migrating from legacy GraphQL to custom OLAP architecture achieving 10× query performance.

Core Engineering Challenge

Resolve USD valuations through direct, 1-hop, and 2-hop Uniswap v3 liquidity paths (sqrtPriceX96) for 5,000+ tokens at sub-second response and 50,000+ daily queries.

10×
Performance Gain
5,000+
Tokens Priced
50K+
Daily Queries
Extended stack
database
ClickHouse
backend
Rust
blockchain
Substreams
Pricing Engine
Pricing Engine
How we built it

THE ARCHITECTURE

01
sqrtPriceX96 resolution

Parse pool state from raw sqrtPriceX96, tick spacing, and token ordering with defensive checks for misconfigured pools.

Uniswap v3sqrtPriceX96
02
Liquidity graph & hops

Build adjacency over blue-chip pairs, score paths by depth and TVL, and cap expensive traversals.

Path FindingLiquidity
03
ClickHouse materialized views

Pre-aggregate token→USD rows on ingest; nightly or streaming refreshes keep staleness bounded.

ClickHouseMaterialized Views
04
Substreams → sink

Rust Substreams modules emit normalized swap and mint events into the pricing pipeline with replay-safe cursors.

SubstreamsRust
05
Validation & alerts

Cross-check spot prices against reference pools; page on divergence beyond thresholds.

ObservabilityDeFi
System Data Flow
Ingestion
CrawlerContent Hash10K+ pages
Processing
ChunkerDeduplicatorEmbedding API
Storage
pgvectorPostgreSQLRedis Cache
Auth
Identity ProviderJWT BridgeSessions
Query
HNSW SearchRe-rankerLLM Stream
Delivery
Web AppMobile AppUsers
What we delivered

THE RESULTS

10×

Tenfold improvement over legacy GraphQL subgraph read paths by shifting sqrtPriceX96 math and hop resolution into ingest-time ClickHouse materializations so dashboards stopped recomputing liquidity graphs per request.

10×
Performance Gain

Tenfold improvement over legacy GraphQL subgraph read paths by shifting sqrtPriceX96 math and hop resolution into ingest-time ClickHouse materializations so dashboards stopped recomputing liquidity graphs per request.

5,000+
Tokens Priced

Direct, one-hop, and two-hop Uniswap v3 routes with liquidity-aware intermediates — covering long-tail tokens institutional desks still held without manual oracle overrides.

50K+
Daily Queries

Sustained institutional DeFi position tracking with predictable p95 latency because pricing snapshots were already merged in ClickHouse rather than assembled from RPC at query time.

Visual documentation

SCREENS &
INTERFACES

Token Price Charts
Token Price Charts
Engineering decisions

TECH
DEEP DIVE

OLAP
ClickHouse over query-time GraphQL

GraphQL subgraphs recomputed pricing per request; OLAP materializations amortize math once per block batch.

50K+ daily queries made read-time graph walks economically impossible without pre-aggregation.

HOP
Bounded multi-hop search

Two-hop cap with liquidity scoring avoided exponential blow-ups on fragmented v3 pools.

Institutional users preferred a stable USD band over chasing illusory precision through dead-end pools.

SUB
Substreams for ingest

Deterministic replay and parallel map stages beat bespoke chain listeners for reorg handling.

Sharing hop logic with Uniswap jump detectors kept pricing and anomaly feeds consistent.

Next Case Study
Web Platform
Nonillion

Spatial Meeting Platform

Next.jsNode.jsLiveKit
Start a project

LET'S
BUILD
SOMETHING.

We take on a small number of projects at a time. If the problem is hard, we're interested.

Email
hello@techmusketeers.com
Response time
Within 24 hours
Availability
Open for new projects · 2025