A decentralized swap aggregator that finds the best token prices across multiple DEXs and executes optimized trades with gas estimation and slippage protection.
- 🔁 Multi-DEX token swapping
- 📊 Real-time price comparison (best route selection)
- ⚡ Gas estimation before transaction
- 🧠 Smart trade routing engine
- 🔐 Wallet connection (MetaMask/Web3)
- 🔄 Dynamic token list system
- 📉 Slippage protection mechanism
- ⚙️ Fully on-chain execution logic
- User selects tokens
- App queries multiple DEX contracts
- Fetches swap quotes using
getAmountsOut - Selects best output trade
- Estimates gas cost
- Approves ERC20 spending
- Executes swap transaction
Frontend (Next.js + React)
↓
Ethers.js (Blockchain Layer)
↓
Multiple DEX Contracts
↓
On-chain Swap Execution
- Next.js 14
- React
- Ethers.js v6
- Tailwind CSS
- Solidity (DEX interaction)
- Web3 Wallets (MetaMask)
/app
/components
Trade.tsx
ConnectButton.tsx
blockchain.json
tokenList.json
/components
AeroDexLanding.tsx
CogIcon.tsx
Navbar.tsx
SwapIcon.tsx
SwapWidget.tsx
- Always verify ABI before swap execution
- Token approval required before trading
- Gas estimation may vary based on network congestion
- Slippage is applied automatically during trade execution
- 🔀 Multi-hop routing (A → B → C swaps)
- 📊 Price impact visualization
- 🌐 Add more DEX integrations
- 📜 Transaction history tracking
- 📱 Mobile-first UI optimization
- 📡 Live price streaming (WebSockets)
- Clone the repository :
git clone https://github.com/samarkun23/dex_aggregator.git - Install dependencies:
npm install - Run the project locally:
npm run dev
DexFlow acts as a mini Uniswap aggregator engine:
- Finds liquidity across DEXs
- Optimizes trade output
- Reduces slippage loss
- Gives better execution price automatically
Based on the current state of AeroDex, you've built a solid foundation for a DEX aggregator. It currently handles multi-DEX price discovery and execution for direct pairs.
To take this from a "mini-aggregator" to a professional-grade DeFi tool, here are several high-impact features and improvements you can add:
- 🔀 Multi-Hop Smart Routing (Backend Logic) The Problem: Currently, you only check direct paths (e.g., Token A -> Token B). If there's no direct liquidity pool for that pair, your app will fail to find a quote. The Improvement: Implement a search for intermediate tokens.
- Check paths like [Token A, WETH, Token B] or [Token A, USDC, Token B].
- Most professional aggregators check 2-3 "hops" to find the best price, especially for smaller altcoins.
- 📊 Dynamic & Accurate Charting The Problem: Your api/charts/route.ts is currently hardcoded to a single WETH/USDC pool. The Improvement:
- Update the API to take tokenIn and tokenOut as parameters.
- Use the GeckoTerminal API or DexScreener API to fetch the OHLCV data for the specific pair the user has selected in the Swap Widget.
- Add a "Price Impact" indicator: Show the user how much their specific trade size will move the market price (e.g., "Price Impact: 0.05%").
- ⚙️ Advanced Trade Settings (Slippage & Gas) The Problem: Slippage is fixed at 1% in Trade.tsx, and gas isn't estimated for the user beforehand. The Improvement:
- User-Defined Slippage: Add a settings gear icon to let users set their own slippage (0.1%, 0.5%, 1%, or Custom).
- Gas Estimation: Use ethers' estimateGas function before the trade. Show the user the estimated fee in USD: "Estimated Gas Fee: $4.20".
- Infinite Approval Toggle: Allow users to approve a "max" amount once so they don't have to pay for an approve() transaction every single time they swap that token.
- 💼 Portfolio & Wallet Insights The Problem: The user can't see what they already own. The Improvement:
- Add a "Balance" display next to the token selection.
- Create a "Your Assets" sidebar that lists the user's balances for all tokens in your tokenList.json.
- Add a "Max" button to the input field that automatically fills in the user's entire balance.
- 📜 Transaction History (Local) The Problem: Once a trade is done, the record disappears. The Improvement:
- Store successful transactions in localStorage.
- Show a "Recent Transactions" list in the UI with links to Etherscan so users can track their trading history.
- 🌐 Multi-Chain Support The Problem: DeFi is moving toward Layer 2s (Arbitrum, Base, Polygon). The Improvement:
- Add a Network Selector (Ethereum, Base, Arbitrum).
- Update your blockchain.json to include router addresses for these networks (e.g., Aerodrome on Base, Uniswap V3 on Arbitrum).
- 🎨 UI/UX Polish
- Token Search: Add a search bar inside the token selector modal.
- Auto-Refresh: Refresh the price quotes every 15 seconds automatically so the "Best Price" is always current.
- Loading States: Add "Skeleton" loaders while the app is fetching quotes from multiple DEXs to make the app feel faster.
This project is built for educational & experimental DeFi development purposes only.