How a DEX Is Built: Contracts, Oracles and Liquidity

Insights
2026-11-23
Author:Jyotvir
0 views
How a DEX Is Built: Contracts, Oracles and Liquidity

How a DEX is built: in 17 Uniswap v3 pools, LPs lost $260.1M to impermanent loss vs $199.3M in fees. Audit contracts, oracles and liquidity before launch.

Frequently Asked Questions

In Uniswap v2 every position spreads liquidity across all prices from zero to infinity, so most of it sits idle. In v3 each position picks a price range bounded by ticks, earns fees only while the price is inside that range, and holds a single asset once the price leaves it, which raises both fee income and impermanent loss per unit of capital.
Not the spot price. A flash loan can move a pool's spot price and restore it inside one transaction, so a contract reading that price can be fooled for little more than swap fees, any flash-loan premium and gas. A time-weighted average over enough blocks raises the cost, and Uniswap's own analysis notes that validators proposing consecutive blocks make multi-block manipulation more feasible under proof of stake for a validator with a large share of stake.
The minimum output amount caps how far the execution price can move before the swap reverts, which also caps what a sandwich attacker can extract, because the attacker pushes the price up to that limit and no further. The deadline stops a delayed transaction from executing later at a price the trader never agreed to.
Hooks let a pool call external contract logic before and after events such as initialization, liquidity changes, swaps and donations, so builders can add dynamic fees, custom pricing or access rules without forking the core. The trade-off is trust: a pool is only as safe as its hook, so each hook needs its own review.

Don't Miss What's Next

Subscribe to newsletter

Tags:

how a DEX is built

AMM architecture

Uniswap v4 hooks

DEX oracle security

ICP-3

Get in Touch

Our team will get back to you within 24 hours.

A clear proven process, that delivers

End of Scroll. Start of Discovery.

You've seen our ideas - now go deeper.
Discover more insights, guides, and engineering practice.