PRD: DEX Aggregator Router
Summary
One-liner: Route trades across multiple DEXs to find optimal prices with minimal slippage and gas costs
Domain: Cryptocurrency / DeFi Trading
Users: DeFi Traders, Arbitrage Bots, Portfolio Managers, MEV-Aware Users
Problem Statement
DeFi traders face fragmented liquidity across dozens of decentralized exchanges. A single trade on one DEX may have 5% price impact, while splitting across multiple venues could reduce it to 0.5%. Without aggregation tools, traders:
- Overpay due to poor price discovery across DEXs
- Suffer unnecessary slippage from suboptimal routing
- Miss multi-hop opportunities (ETH→USDC→TOKEN cheaper than ETH→TOKEN)
- Waste gas on inefficient transaction paths
- Fall victim to MEV extraction (sandwich attacks, frontrunning)
Target Users
Persona 1: Active DeFi Trader
- Profile: Trades $1K-$50K weekly across multiple tokens
- Pain Points: Manually checking 5+ DEXs is time-consuming; misses optimal routes
- Goals: Best execution price with minimal effort; understand true cost of trades
- Usage Pattern: Multiple trades daily, needs quick comparisons
Persona 2: Arbitrage Bot Operator
- Profile: Runs automated trading strategies exploiting price differences
- Pain Points: Needs real-time route optimization; gas efficiency is critical
- Goals: Programmatic access to optimal routes; sub-second decisions
- Usage Pattern: High frequency, API-first, cost-sensitive
Persona 3: Whale / Treasury Manager
- Profile: Executes large trades ($100K+) for DAOs or personal portfolios
- Pain Points: Large trades create massive price impact; MEV exposure
- Goals: Minimize market impact; protect against sandwich attacks
- Usage Pattern: Infrequent but high-value trades requiring careful execution
User Stories
Critical (P0)
As a DeFi trader, I want to compare prices across multiple DEXs for a token pair, so that I can execute at the best available rate.
- Acceptance Criteria:
- Query returns prices from at least 5 major DEXs (Uniswap V2/V3, SushiSwap, Curve, Balancer)
- Response includes price, liquidity depth, and estimated gas cost per venue
- Results sorted by effective rate (price after gas)
As a trader, I want to see optimal route recommendations including multi-hop paths, so that I can minimize price impact on larger trades.
- Acceptance Criteria:
- System identifies multi-hop routes (e.g., ETH→USDC→TOKEN)
- Compares direct vs. multi-hop with total cost analysis
- Shows price impact at each hop
As a large trader, I want split-order recommendations across multiple DEXs, so that I can reduce market impact on whale-sized trades.
- Acceptance Criteria:
- For trades >$10K, analyze split order strategies
- Show percentage allocation per DEX to minimize total slippage
- Calculate aggregate vs. single-venue price improvement
Important (P1)
As a MEV-aware user, I want to see MEV protection recommendations, so that I can avoid sandwich attacks.
- Acceptance Criteria:
- Flag high-MEV-risk routes (low liquidity, pending large orders)
- Recommend private transaction options (Flashbots, CoW Swap)
- Show estimated MEV exposure per route
As a gas-conscious trader, I want gas-optimized route selection, so that I don't waste ETH on complex routes for small trades.
- Acceptance Criteria:
- Calculate break-even point for multi-hop vs. direct routes
- Factor current gas prices into recommendations
- Warn when gas cost exceeds 2% of trade value
Nice-to-Have (P2)
- As a trader, I want historical route performance data, so that I can trust the recommendations.
- Acceptance Criteria:
- Show average slippage vs. quoted for each DEX
- Display route success rates
- Track execution vs. quoted price variance
Functional Requirements
Core Features
REQ-1: Multi-DEX Price Fetching
- Query Uniswap V2, Uniswap V3, SushiSwap, Curve, Balancer
- Integrate aggregator APIs (1inch, Paraswap, 0x)
- Support major chains: Ethereum, Arbitrum, Polygon, Optimism
REQ-2: Route Discovery Engine
- Direct swap path identification
- Multi-hop route construction (up to 3 hops)
- Split order optimization (2-5 venue splits)
REQ-3: Price Impact Analysis
- Calculate slippage at various trade sizes
- Identify liquidity depth per venue
- Show impact curves for trade sizing decisions
REQ-4: Gas Cost Optimization
- Estimate gas per route (simple vs. complex)
- Calculate effective rate including gas
- Dynamic gas price integration
REQ-5: MEV Protection Assessment
- Risk scoring for sandwich attack exposure
- Private transaction recommendations
- CoW Swap / Flashbots integration guidance
Trade Size Recommendations
| Trade Size |
Recommended Strategy |
| < $1K |
Direct swap on highest liquidity DEX |
| $1K - $10K |
Compare direct vs. multi-hop; single venue |
| $10K - $100K |
Multi-hop + potential 2-3 way split |
| > $100K |
Algorithmic splitting; private transactions; OTC consideration |
Non-Goals
- NOT executing trades (read-only analysis and recommendations)
- NOT providing financial advice or trade signals
- NOT supporting centralized exchanges
- NOT real-time order book streaming (snapshot-based)
- NOT building trading bots (analysis only)
API Integrations
| API |
Purpose |
Auth |
Rate Limits |
| 1inch API |
Aggregated quotes, optimal routes |
API Key (optional) |
1 req/sec (free) |
| Paraswap API |
Alternative aggregator quotes |
None |
10 req/sec |
| 0x API |
Swap quotes with affiliate fees |
API Key |
3 req/sec |
| The Graph |
DEX subgraph queries |
None |
Varies by hosted/decentralized |
| DeFiLlama |
TVL and liquidity data |
None |
Generous |
| Etherscan |
Gas price oracle |
API Key |
5 req/sec |
Success Metrics
| Metric |
Target |
Measurement |
| Route Accuracy |
Quoted vs. executed within 0.5% |
Backtesting against historical |
| Coverage |
90%+ of trade volume covered |
DEX market share analysis |
| Response Time |
<3 seconds for full analysis |
Performance monitoring |
| User Satisfaction |
Recommendations followed >70% |
Usage analytics |
UX Flow
1. User Input
├── Token pair (ETH/USDC)
├── Trade amount ($5,000)
├── Chain (Ethereum mainnet)
└── Preferences (gas sensitivity, MEV protection)
2. Data Collection (parallel)
├── Query 1inch API
├── Query Paraswap API
├── Query DEX subgraphs
└── Fetch gas prices
3. Route Analysis
├── Direct routes ranked
├── Multi-hop routes discovered
├── Split strategies calculated
└── MEV risk assessed
4. Results Presentation
├── Best route highlighted
├── Alternative options shown
├── Cost breakdown (price + gas + slippage)
└── MEV protection recommendations
Constraints & Assumptions
Constraints
- API rate limits require caching and request optimization
- Gas prices volatile; recommendations valid for ~30 seconds
- Some DEXs have different liquidity on different chains
Assumptions
- User has basic understanding of DEX trading
- User can execute recommended trades manually or via preferred interface
- Real-time prices acceptable (not tick-by-tick precision)
Risk Assessment
| Risk |
Likelihood |
Impact |
Mitigation |
| API rate limiting |
Medium |
High |
Multi-source fallback; caching |
| Stale price data |
Medium |
Medium |
Timestamp warnings; refresh prompts |
| Route becomes suboptimal |
High |
Low |
Clear validity window; refresh before execution |
| MEV exposure on recommended route |
Low |
High |
Conservative recommendations; private TX options |
Version History
| Version |
Date |
Author |
Changes |
| 1.0.0 |
2025-01-15 |
Claude |
Initial PRD |
1---2name: 027-prd-08bf03283description: PRD: DEX Aggregator Router4---5# PRD: DEX Aggregator Router67## Summary89**One-liner**: Route trades across multiple DEXs to find optimal prices with minimal slippage and gas costs10**Domain**: Cryptocurrency / DeFi Trading11**Users**: DeFi Traders, Arbitrage Bots, Portfolio Managers, MEV-Aware Users1213## Problem Statement1415DeFi traders face fragmented liquidity across dozens of decentralized exchanges. A single trade on one DEX may have 5% price impact, while splitting across multiple venues could reduce it to 0.5%. Without aggregation tools, traders:16171. Overpay due to poor price discovery across DEXs182. Suffer unnecessary slippage from suboptimal routing193. Miss multi-hop opportunities (ETH→USDC→TOKEN cheaper than ETH→TOKEN)204. Waste gas on inefficient transaction paths215. Fall victim to MEV extraction (sandwich attacks, frontrunning)2223## Target Users2425### Persona 1: Active DeFi Trader26- **Profile**: Trades $1K-$50K weekly across multiple tokens27- **Pain Points**: Manually checking 5+ DEXs is time-consuming; misses optimal routes28- **Goals**: Best execution price with minimal effort; understand true cost of trades29- **Usage Pattern**: Multiple trades daily, needs quick comparisons3031### Persona 2: Arbitrage Bot Operator32- **Profile**: Runs automated trading strategies exploiting price differences33- **Pain Points**: Needs real-time route optimization; gas efficiency is critical34- **Goals**: Programmatic access to optimal routes; sub-second decisions35- **Usage Pattern**: High frequency, API-first, cost-sensitive3637### Persona 3: Whale / Treasury Manager38- **Profile**: Executes large trades ($100K+) for DAOs or personal portfolios39- **Pain Points**: Large trades create massive price impact; MEV exposure40- **Goals**: Minimize market impact; protect against sandwich attacks41- **Usage Pattern**: Infrequent but high-value trades requiring careful execution4243## User Stories4445### Critical (P0)46471. **As a DeFi trader**, I want to compare prices across multiple DEXs for a token pair, so that I can execute at the best available rate.48 - **Acceptance Criteria**:49 - Query returns prices from at least 5 major DEXs (Uniswap V2/V3, SushiSwap, Curve, Balancer)50 - Response includes price, liquidity depth, and estimated gas cost per venue51 - Results sorted by effective rate (price after gas)52532. **As a trader**, I want to see optimal route recommendations including multi-hop paths, so that I can minimize price impact on larger trades.54 - **Acceptance Criteria**:55 - System identifies multi-hop routes (e.g., ETH→USDC→TOKEN)56 - Compares direct vs. multi-hop with total cost analysis57 - Shows price impact at each hop58593. **As a large trader**, I want split-order recommendations across multiple DEXs, so that I can reduce market impact on whale-sized trades.60 - **Acceptance Criteria**:61 - For trades >$10K, analyze split order strategies62 - Show percentage allocation per DEX to minimize total slippage63 - Calculate aggregate vs. single-venue price improvement6465### Important (P1)66674. **As a MEV-aware user**, I want to see MEV protection recommendations, so that I can avoid sandwich attacks.68 - **Acceptance Criteria**:69 - Flag high-MEV-risk routes (low liquidity, pending large orders)70 - Recommend private transaction options (Flashbots, CoW Swap)71 - Show estimated MEV exposure per route72735. **As a gas-conscious trader**, I want gas-optimized route selection, so that I don't waste ETH on complex routes for small trades.74 - **Acceptance Criteria**:75 - Calculate break-even point for multi-hop vs. direct routes76 - Factor current gas prices into recommendations77 - Warn when gas cost exceeds 2% of trade value7879### Nice-to-Have (P2)80816. **As a trader**, I want historical route performance data, so that I can trust the recommendations.82 - **Acceptance Criteria**:83 - Show average slippage vs. quoted for each DEX84 - Display route success rates85 - Track execution vs. quoted price variance8687## Functional Requirements8889### Core Features9091- **REQ-1**: Multi-DEX Price Fetching92 - Query Uniswap V2, Uniswap V3, SushiSwap, Curve, Balancer93 - Integrate aggregator APIs (1inch, Paraswap, 0x)94 - Support major chains: Ethereum, Arbitrum, Polygon, Optimism9596- **REQ-2**: Route Discovery Engine97 - Direct swap path identification98 - Multi-hop route construction (up to 3 hops)99 - Split order optimization (2-5 venue splits)100101- **REQ-3**: Price Impact Analysis102 - Calculate slippage at various trade sizes103 - Identify liquidity depth per venue104 - Show impact curves for trade sizing decisions105106- **REQ-4**: Gas Cost Optimization107 - Estimate gas per route (simple vs. complex)108 - Calculate effective rate including gas109 - Dynamic gas price integration110111- **REQ-5**: MEV Protection Assessment112 - Risk scoring for sandwich attack exposure113 - Private transaction recommendations114 - CoW Swap / Flashbots integration guidance115116### Trade Size Recommendations117118| Trade Size | Recommended Strategy |119|------------|---------------------|120| < $1K | Direct swap on highest liquidity DEX |121| $1K - $10K | Compare direct vs. multi-hop; single venue |122| $10K - $100K | Multi-hop + potential 2-3 way split |123| > $100K | Algorithmic splitting; private transactions; OTC consideration |124125## Non-Goals126127- **NOT** executing trades (read-only analysis and recommendations)128- **NOT** providing financial advice or trade signals129- **NOT** supporting centralized exchanges130- **NOT** real-time order book streaming (snapshot-based)131- **NOT** building trading bots (analysis only)132133## API Integrations134135| API | Purpose | Auth | Rate Limits |136|-----|---------|------|-------------|137| 1inch API | Aggregated quotes, optimal routes | API Key (optional) | 1 req/sec (free) |138| Paraswap API | Alternative aggregator quotes | None | 10 req/sec |139| 0x API | Swap quotes with affiliate fees | API Key | 3 req/sec |140| The Graph | DEX subgraph queries | None | Varies by hosted/decentralized |141| DeFiLlama | TVL and liquidity data | None | Generous |142| Etherscan | Gas price oracle | API Key | 5 req/sec |143144## Success Metrics145146| Metric | Target | Measurement |147|--------|--------|-------------|148| Route Accuracy | Quoted vs. executed within 0.5% | Backtesting against historical |149| Coverage | 90%+ of trade volume covered | DEX market share analysis |150| Response Time | <3 seconds for full analysis | Performance monitoring |151| User Satisfaction | Recommendations followed >70% | Usage analytics |152153## UX Flow154155```1561. User Input157 ├── Token pair (ETH/USDC)158 ├── Trade amount ($5,000)159 ├── Chain (Ethereum mainnet)160 └── Preferences (gas sensitivity, MEV protection)1611622. Data Collection (parallel)163 ├── Query 1inch API164 ├── Query Paraswap API165 ├── Query DEX subgraphs166 └── Fetch gas prices1671683. Route Analysis169 ├── Direct routes ranked170 ├── Multi-hop routes discovered171 ├── Split strategies calculated172 └── MEV risk assessed1731744. Results Presentation175 ├── Best route highlighted176 ├── Alternative options shown177 ├── Cost breakdown (price + gas + slippage)178 └── MEV protection recommendations179```180181## Constraints & Assumptions182183### Constraints184- API rate limits require caching and request optimization185- Gas prices volatile; recommendations valid for ~30 seconds186- Some DEXs have different liquidity on different chains187188### Assumptions189- User has basic understanding of DEX trading190- User can execute recommended trades manually or via preferred interface191- Real-time prices acceptable (not tick-by-tick precision)192193## Risk Assessment194195| Risk | Likelihood | Impact | Mitigation |196|------|------------|--------|------------|197| API rate limiting | Medium | High | Multi-source fallback; caching |198| Stale price data | Medium | Medium | Timestamp warnings; refresh prompts |199| Route becomes suboptimal | High | Low | Clear validity window; refresh before execution |200| MEV exposure on recommended route | Low | High | Conservative recommendations; private TX options |201202## Version History203204| Version | Date | Author | Changes |205|---------|------|--------|---------|206| 1.0.0 | 2025-01-15 | Claude | Initial PRD |