DEX Quote Aggregator Development: Off-Chain Indexing and Realtime API
Picture this: you need the best rate to swap 50 ETH into USDC. Uniswap v3 gives one price, Curve another, Balancer a third. A 0.3% difference on 50 ETH is $150 lost on a single transaction. We offer professional development of a DEX quote comparison system that saves up to 2% on each trade. Our team has extensive experience in blockchain development and numerous successful projects. The system integrates with any chain and DEX, ensuring real-time quotes. Contact us to order development and get an architecture consultation. The key goal of a quote aggregator is to minimize latency and guarantee accurate calculations, including fees and slippage. Our system solves this with a hybrid architecture.
Problems with Naive Aggregator Implementations
On-Chain Calls in Real Time: Slow and Expensive
The first approach: call quoteExactInputSingle on Uniswap v3 Quoter, get_dy on Curve, queryBatchSwap on Balancer — and compare. The issue is that this simulates on-chain execution via eth_call. On mainnet with 8-12 DEXes and 3-4 route options, that's 30+ RPC calls per user request. At 200ms per call, you get 6 seconds of waiting. By then, the price has already changed.
A concrete case from our practice: an aggregator with a naive last-write-wins cache lost quote freshness within 3-5 blocks. Users saw price X, clicked swap, got revert due to slippage, and paid wasted gas. Conversion dropped by 40%.
Stale Data and Block Drift
The price in a Uniswap v3 pool changes with every swap. If the cache updates every 12 seconds (one block on Ethereum), several large trades can occur between updates. This is especially critical for low-liquidity pools, where a 1-2% price shift per block is not uncommon.
Curve uses a different pricing model — the StableSwap invariant. The formula A * n^n * sum(x_i) + D = A * D * n^n + D^(n+1) / (n^n * prod(x_i)) is sensitive to pool balances, which change differently. You cannot apply the same slippage logic for Uniswap v3 concentrated liquidity and Curve stable pools.
A typical mistake in aggregation is ignoring slippage, especially for large orders. Without considering pool depth, users may see a price unattainable at swap time. Our system always calculates slippage individually for each DEX.
Architecture of the Quote Comparison System
Two Data Layers: Off-Chain Indexing + On-Chain Verification
The working scheme: The Graph subgraphs for indexing pool state — liquidity, current prices, volumes. Data updates per block and is available via GraphQL without RPC load. For Uniswap v3, use the official subgraph with pools, ticks, positions. For Curve, a custom subgraph or parsing TokenExchange events.
On-chain verification is only needed at execution time: a final quoteExactInput before the user's transaction with the current block state.
| Source | Latency | Accuracy | RPC Load |
|---|---|---|---|
| The Graph subgraph | 2-5 sec (1 block) | High | Minimal |
| Multicall + Quoter | 200-500 ms | Exact | High |
| DEX SDK (off-chain math) | <10 ms | Calculated | None |
| WebSocket events | Real-time | Event-based | Medium |
Why Off-Chain Math is Faster Than On-Chain?
Uniswap v3 provides @uniswap/v3-sdk and @uniswap/smart-order-router — full route calculation with split routing happens locally, without RPC, based on loaded pool state. Similarly for Curve — a Python SDK or TypeScript port of the StableSwap formula allows computing get_dy locally. According to official Uniswap v3 documentation, off-chain calculations provide accuracy up to 0.01%.
This approach reduces latency to 10-50 ms and eliminates RPC provider dependency on the hot path.
How to Ensure Realtime Updates?
For interfaces needing real-time price updates — WebSocket subscription via ethers.js provider.on('block', ...) or viem watchBlocks. On each new block, recalculate quotes only for active trading pairs in the UI, not the entire marketplace. This reduces server load and speeds up display.
Gas Cost Consideration in Aggregation
Gas cost can change the attractiveness of a route. One DEX may offer a better price but cost 500k gas to execute, while another is slightly worse but costs 200k — the latter could be more profitable. We use eth_gasPrice and historical data to estimate gas costs, including EIP-1559 parameters. The calculation module compares net output after gas deduction.
Example: at 50 Gwei gas price, a 300k gas difference equals 0.015 ETH (~$30). On a 10 ETH trade, that's 0.3% — significant.
How Off-Chain Indexing Speeds Up Quote Comparison
The Graph subgraph allows fetching the state of thousands of pools in a single GraphQL query, without sequential RPC calls. Data updates every 2-5 seconds (depending on block speed). This is sufficient for most traders, as the price does not change critically within 2-5 seconds. For ultra-fast operations (e.g., MEV), you can add WebSocket subscription to pool events.
Supported DEXes and Individual Slippage Calculation
We connect any DEX on Ethereum, Polygon, Arbitrum, Optimism, Base. The base version includes Uniswap v3, Curve, Balancer. Slippage is calculated individually: for Uniswap v3 — tick-based model considering tick spacing and range liquidity; for Curve — StableSwap formula; for Balancer — weighted pool formula. For each DEX, we use the corresponding SDK and verify calculations with fork tests.
What's Included in the Price Comparison System Development?
- Analysis (1-2 days). Determine the DEX list for a specific chain, required trading pairs, and latency needs. Ethereum mainnet, Polygon, Arbitrum, Base each have their own active DEXes and liquidity structures.
- Backend development (3-5 days). Indexing service with The Graph + Multicall, pool state cache, REST/WebSocket API. Stack: Node.js + TypeScript, viem for on-chain interaction, Redis for caching.
- Calculation module development (2-3 days). Off-chain math for each connected DEX, split routing algorithm, gas cost consideration when comparing.
- Frontend integration (1-2 days). wagmi hooks for fetching quotes, displaying comparison, integrating with the transaction flow.
- Testing. Fork tests on Hardhat/Foundry with real mainnet state — verify calculation accuracy against real on-chain results.
- Documentation and handover. Provide full technical documentation, infrastructure access, and training for your team. We offer support for one month after launch.
Comparison of Aggregation Approaches
| Parameter | Naive Approach | Our Approach |
|---|---|---|
| Latency | 6 seconds | 10-50 ms |
| Accuracy | Low with cache | Up to 0.01% |
| RPC dependency | High | Minimal |
| Gas cost | High | Up to 30% savings |
Our system updates quotes 10x faster than the naive approach thanks to off-chain indexing and local calculations. Gas savings in testing reached up to 30% due to minimizing on-chain calls. Compare with competitors that use only on-chain queries — our system shows lower latency and lower transaction costs. Average savings on a 10 ETH trade reach 0.1 ETH, and for a 100 ETH trade, exceed 1 ETH.
Example of savings calculation
A trader wants to swap 50 ETH to USDC. Best prices: Uniswap v3: 3400.50 USDC per ETH, Curve: 3400.20, Balancer: 3400.40. After accounting for gas and slippage, Uniswap is the best. Our system shows a net difference of 0.15 ETH.Timeline Estimates
Basic system for 3-5 DEXes on one chain: 3-5 days. Full aggregator with multi-chain, split routing, and realtime UI: from 2 weeks. Timelines depend on the number of DEXes and latency requirements.
Contact us to discuss your specific case. Order development and get an architecture consultation.







