4IRE
Guide to building a DEX like Uniswap: how the AMM works, what each version's licence allows, v4 hooks, build steps, liquidity and cost
28 Sept 2026DeFiDEX

How to Build a DEX Like Uniswap: A Practical Guide

9 min

Olena PetrashchukCEO

How to build a DEX like Uniswap: how the protocol works, what v2, v3 and v4 licenses allow, hooks, build steps, security, liquidity and cost.

DeFiDEX

Share:

inX

Uniswap is the reference design for decentralized exchanges. It replaced the order book with an automated market maker (AMM), made token listing permissionless and published its contracts for anyone to read and, eventually, reuse. A large share of the DEXs launched since 2020 are Uniswap forks or borrow its architecture.

It is still the largest single DEX. According to DefiLlama, Uniswap's v2, v3 and v4 deployments processed about $90 billion of trades in the 30 days to 28 September 2026, roughly 29% of all DEX volume the site tracks, with about $3.9 billion in total value locked. Building a decentralized exchange that competes with it is less about copying code, which is easy, and more about licensing, security and liquidity, which are not. This guide covers all three.

Uniswap at a glance as of September 2026: about $90 billion traded in 30 days, 29% of DEX volume, $3.9 billion TVL, v4 live since January 2025 and the fee switch approved in December 2025

How Uniswap Works

Uniswap is a set of smart contracts that hold pools of two tokens. Traders swap against a pool rather than against another trader, and a formula sets the price.

  • Constant product. In v2, each pool keeps the product of its two reserves constant (x · y = k). Buying token A takes A out of the pool and adds B, so every unit bought makes the next one more expensive. Quotes are always available, at the cost of slippage on large trades.
  • Liquidity providers (LPs). Anyone can deposit both tokens and receive a share of the pool. LPs earn the swap fee (0.3% on v2 pools, of which LPs keep 0.25% where the protocol fee is switched on) and carry impermanent loss when prices move.
  • Permissionless listing. Any ERC-20 pair can have a pool. There is no listing committee.
  • Self-custody. Users trade from their own wallets. The contracts hold pooled liquidity, not user accounts.

Uniswap v3, launched in 2021, added concentrated liquidity: LPs choose a price range, which makes capital far more efficient but turns liquidity provision into active position management. Its pools use fee tiers of 0.01%, 0.05%, 0.3% and 1%. For the math behind AMM curves, and why stablecoin pools use a different invariant, see our guide on how to build an AMM.

Uniswap v4: Hooks and the Singleton

Uniswap v4 went live on 31 January 2025 on Ethereum and nine other networks (Uniswap). It changes the architecture in ways that matter to anyone building on it or copying it:

  • Singleton PoolManager. All pools live in one contract instead of one contract per pair. Uniswap says this cuts pool creation cost by up to 99.99% and makes multi-hop swaps cheaper.
  • Flash accounting. Balances are netted across a transaction and settled once at the end.
  • Hooks. A pool can call an external contract before or after swaps and liquidity changes, which enables dynamic fees, on-chain limit orders, custom oracles or access-controlled pools.
  • Native ETH. Pairs can hold ETH directly, without wrapping it first.

Hooks change the build-or-fork question. Instead of forking the whole protocol to add one feature, a team can often deploy a hook on Uniswap's own v4 contracts and reuse their audited core, routing and user base. The trade-off is that a hook is new code that touches user funds, and it needs the same audit discipline as a whole DEX.

Architecture of a Uniswap-style DEX: factory deploys pools, router routes user swaps, pools hold reserves and price trades by the constant product formula, LPs earn fees, and in v4 a singleton PoolManager with hooks holds all pools

What a Uniswap-Style DEX Is Made Of

Uniswap v2 split its code into a minimal core and a periphery, a pattern most forks keep:

  • Factory. Deploys a pool for each new token pair and keeps the registry.
  • Pair (pool). Holds the reserves, executes swaps, mints and burns LP tokens and exposes a price oracle.
  • Router. The periphery contract users actually call. It finds paths through several pools and enforces slippage limits and deadlines.

Around the contracts you need an indexer or subgraph for pool data, a web front end with wallet connection, token lists, analytics, and monitoring with alerts. Plan for them from the start: together they take as much effort as the Solidity.

Licensing: Which Uniswap Version You Can Fork

The license decides which version you can legally launch:

VersionLicenseCommercial fork
v2GPL-3.0Yes, under GPL terms
v3Business Source License until 1 April 2023, now GPL-2.0-or-laterYes, under GPL terms
v4 coreBusiness Source License until 15 June 2027 at the latest, then MITOnly with an Additional Use Grant until then

The v4 terms are set out in the license file in the v4-core repository. Hooks built on Uniswap's own v4 deployment do not need a copy of the core, and the v4 periphery code is licensed under GPL-2.0. The Uniswap name and logo are not covered by any of these code licenses.

Fork, Hook or Build: Choosing the Approach

  • Fork v2 or v3. The fastest route to a working DEX on a new chain or for a niche audience. The code is battle-tested, but every change you make invalidates part of the original audits, and you compete with the original on the same design. Our overview of forking options compares the main candidates.
  • Build on v4 hooks. The best fit when your difference is a pool feature, such as dynamic fees, gated access or a custom order type, rather than a new exchange. Only the hook needs building and auditing.
  • Build a custom AMM. Needed when the asset class calls for a different curve, as with stablecoins or tokenized assets, or when you need control of the whole stack. It is the longest route and carries the heaviest audit burden.
Fork, hook or build: three routes to a Uniswap-style DEX

Step-by-Step: Launching a Uniswap-Style DEX

  1. Scope the market. Pick the chain, the asset pairs and the users you will serve, and decide why they would trade with you rather than on Uniswap.
  2. Choose the approach and check the license of the code you will reuse.
  3. Design the economics. Fee tiers, any protocol fee, LP incentives, and whether you need a token at all.
  4. Develop the contracts. Fork and modify, or write the hook or the new pool logic, keeping changes to audited code to a minimum. This is where experienced Solidity developers matter most.
  5. Build the off-chain stack. Indexer, API, front end, analytics, monitoring and alerting.
  6. Test and audit. Unit, fuzz and invariant tests, a testnet deployment, then an independent smart contract audit of every changed line and a bug bounty.
  7. Seed liquidity and integrate. Bootstrap the first pools and get listed by DEX aggregators, which route a large share of today's volume. Our guide to developing a DeFi aggregator explains how they choose routes.
  8. Launch in stages, with deposit caps, a timelocked admin and an incident runbook.

How Uniswap Makes Money

For most of its history the protocol itself earned nothing: swap fees went to LPs. In December 2025, UNI holders approved the UNIfication proposal, which switches on a protocol fee and uses it to burn UNI. On v2 pools, LPs keep 0.25% and 0.05% goes to the protocol; on v3, the protocol takes a quarter or a sixth of the LP fee, depending on the tier. The proposal also included a one-off burn of 100 million UNI from the treasury (Uniswap). The rollout started with v2 and a set of v3 pools on Ethereum.

UNI itself launched in 2020 with a genesis supply of 1 billion tokens: 60% for the community, 21.266% for the team, 18.044% for investors and 0.69% for advisors.

For a new DEX the levers are the same: an LP fee, an optional protocol fee, fees on premium pools or hooks, and interface fees. None of them works without volume, so the revenue model is really a liquidity plan.

Challenges to Plan For

  • Security. AMM contracts hold pooled funds. Rounding errors, reentrancy, oracle manipulation and compromised admin keys are recurring attack vectors.
  • Liquidity. Thin pools give bad prices and attract no aggregator flow. Budget for incentives from day one.
  • MEV. Sandwich attacks in public mempools cost users money. Sensible slippage defaults, private order flow and intent-based routing reduce the damage.
  • Regulation. Protocol code may be out of scope, but the company that runs the front end, issues a token or holds an admin key may not be. In the EU, MiCA excludes only services provided in a fully decentralized manner without any intermediary. Take legal advice for each market.
  • Multi-chain. Every chain needs its own deployment and its own liquidity, and linking them needs cross-chain infrastructure.

How Much It Costs and How Long It Takes

By 4IRE's estimates, forking an audited AMM and adding custom features typically costs $120,000 to $250,000 before audits, over 3 to 5 months, and a standard AMM built from scratch $80,000 to $250,000; a novel pricing curve costs more, as our AMM development guide explains. A full production exchange can take up to ten months. Our article on DEX development cost breaks the budget down by stage.

How 4IRE Can Help

4IRE designs, builds and audits decentralized exchanges, from Uniswap forks and v4 hooks to custom AMMs, including the liquidity and launch plan that decides whether a DEX survives its first year.

Build Your DEX with 4IRE

From Uniswap forks and v4 hooks to custom AMMs, our team designs, builds and audits the contracts, the front end and the liquidity plan. Schedule a free consultation.

FAQ on Building a DEX Like Uniswap