Back to projects
DeFi · DEX

Uniswap V2 Mainnet Forking

DEX swap integration tested against live liquidity

Fork block
19,000,000
Swap modes
3
Tooling
Hardhat
Network
ETH Mainnet fork

Overview

This project demonstrates real DEX integration: a wrapper around the Uniswap V2 router that executes token and ETH swaps with proper slippage bounds.

Rather than mocking the DEX, tests run against a fork of Ethereum mainnet at block 19,000,000 — exercising the contract against real Uniswap V2 liquidity for deterministic, production-realistic results.

Key highlights

  • Supports multiple swap patterns: exact-input, exact-output, and ETH-to-token.
  • Slippage protection via amountOutMin / amountInMax bounds on every swap.
  • Mainnet forking at a pinned block for deterministic tests against real liquidity.
  • Environment-driven RPC configuration — production-ready practice, no hard-coded secrets.

What it does

  • IUniswapV2Router interface integration for external DEX calls
  • ERC-20 approval flow before swap execution
  • On-chain usage counters (swapCount, liquidityCount) for analytics
  • Custom Hardhat gas config for reliable forked testing

Tech stack

Solidity ^0.8.24Hardhat + TypeScriptMainnet ForkingOpenZeppelinUniswap V2 Router