What is Uniswap?
Learn what Uniswap is, how its AMM pools work, how swaps and liquidity provision function, and why v2, v3, and v4 changed DeFi.

Introduction
Uniswap is a decentralized exchange protocol for swapping tokens with smart contracts instead of a traditional order book. That sounds like a small interface change, but it solves a deeper problem: on a blockchain, continuously matching buyers and sellers the way a centralized exchange does is expensive, operationally complex, and hard to make fully onchain. Uniswap’s answer is to replace the matching engine with a pool of assets and a pricing rule.
That design made token trading available in a form that is open, programmable, and always on. It also changed who can participate. On Uniswap, a trader does not need an account with an exchange operator, and a market maker does not need special infrastructure to quote bids and asks all day. Instead, the protocol is a set of smart contracts, and anyone who meets the contract’s rules can interact with it.
A useful starting distinction is that the Uniswap Protocol is not the same thing as the Uniswap app. The protocol is the onchain smart-contract system. The app at app.uniswap.org is one interface for using it, but it is only one of several possible ways to interact with the protocol. That matters because Uniswap is best understood as infrastructure: traders, wallets, aggregators, and other DeFi apps can all route through it.
How does Uniswap replace an order book with liquidity pools?
| Model | Counterparty | Price source | Liquidity supply | Slippage behavior | Onchain cost |
|---|---|---|---|---|---|
| Order book | Matched counterparties | Posted quotes by makers | Centralized/professional LPs | Discrete steps; hidden depth | Higher offchain matching cost |
| Pool AMM | The pool contract | Pool state invariant | Anyone can deposit reserves | Continuous price impact (slippage) | Lower per-swap onchain cost |
A normal exchange works by finding someone on the other side of your trade. If you want to swap token A for token B, the exchange matches you against resting orders or professional market makers. Uniswap changes the mechanism. Instead of asking, “Who will take the other side?” it asks, “What price makes this pool remain internally consistent after your trade?”
In early Uniswap designs, that internal consistency came from the constant-product rule. A pool holds reserves of two tokens, and the product of those reserves is constrained so it cannot decrease through a swap. In simple terms, if you remove some of token B from the pool, you must add enough token A so the pool’s pricing rule still holds after fees. The practical consequence is intuitive: the more you push the pool away from its current balance, the worse your price gets. That is what creates slippage.
This is the compression point for understanding Uniswap: price is not posted by a human market maker; price emerges from the pool’s state. Once you see that, several other facts line up. Liquidity providers matter because they supply the reserves the pool prices against. Large trades move the price because they materially change the reserve balance. Arbitrage matters because when the pool price drifts away from the broader market, traders can profit by bringing it back in line.
Uniswap v2 extended this model in an important way by allowing pools for arbitrary ERC-20 pairs rather than forcing trades through ETH as an intermediate asset. That reduced unnecessary routing in many cases. It also introduced features such as flash swaps and a stronger onchain time-weighted average price oracle, which made Uniswap more useful not just for trading but as a composable building block for other applications.
How does a Uniswap swap execute on-chain?
From a user’s point of view, a swap on Uniswap feels simple. You connect a wallet, choose the token you want to sell, choose the token you want to receive, review the quoted output, and sign a transaction. Underneath that, the protocol is doing something quite strict: it is checking whether the pool can release the output tokens while preserving its accounting rules and collecting fees.
Imagine a pool holding USDC and ETH. A trader sends USDC into the pool and asks for ETH out. The pool recalculates what ETH amount is consistent with its current reserves, the fee, and the invariant that governs the pool. If the requested output is too generous, the trade fails. If it is valid, the pool updates its internal state and transfers the ETH. No order book was matched. No dealer promised a quote. The pool itself was the counterparty.
This simplicity is why Uniswap is attractive to ordinary token traders, wallet apps, and aggregators. The protocol provides a predictable onchain venue for ERC-20 swaps, and other software can build around it. The trade-off is that a pool-based market behaves differently from a centralized one. Execution depends heavily on pool depth, route quality, and onchain conditions. A thin pool can move a lot from even a modest trade, and a transaction broadcast publicly can be exposed to frontrunning or sandwich attacks by MEV searchers.
That is not a side issue; it is part of the mechanism. Because the pool state is public and transactions are ordered by the chain, profitable trades create observable opportunities. For users, this means slippage settings, route selection, and execution environment can materially affect outcomes.
Why do liquidity providers matter on Uniswap and how do they earn fees?
| Model | Capital efficiency | Management effort | Position fungibility | Fees handling | Best for |
|---|---|---|---|---|---|
| Uniswap v2 (uniform) | Low per-dollar efficiency | Low; set and forget | Fungible ERC-20 LP tokens | Fees auto-added to pool | Passive LPs, simple markets |
| Uniswap v3 (concentrated) | High when in-range | High; active range management | Non-fungible positions (NFTs) | Fees tracked per position, not auto-compounded | Active LPs and power users |
| v3 with managers/tools | High (via ranges) | Low if delegated | Wrapped/fungible via periphery | Fees can be auto-compounded by tool | Passive investors using managers |
Uniswap works only because someone deposits the tokens that traders swap against. Those depositors are liquidity providers, or LPs. In return for supplying assets to a pool, they earn a share of the swap fees generated by trades through that pool.
This arrangement turns market making into something more open. In a centralized venue, market making usually requires specialized systems for inventory management, quoting, and risk control. In Uniswap, the protocol automates much of the quoting logic. But it does not remove risk; it changes the form of the risk. LPs are exposed to price movement between the assets they deposit, and their returns depend on how much fee income they earn relative to those movements.
That is why Uniswap evolved. In v1 and v2, LP capital was spread across the entire possible price range. Most of that capital was idle most of the time, because a token pair usually trades within a much narrower band. Uniswap v3 addressed this by introducing concentrated liquidity. Instead of providing liquidity everywhere, an LP can choose a price range where their capital will be active.
The effect is straightforward: if an LP places capital near the current market price, that capital can support more trading volume per dollar deposited. In other words, capital becomes more efficient. But the gain comes with a cost. v3 positions are not simple fungible LP tokens anymore; they are range-specific positions with their own accounting, and fees are tracked separately rather than automatically reinvested. So v3 is better suited to LPs who are willing to manage positions actively or use tools that manage them on their behalf.
What are the key changes in Uniswap v4 and why do they matter?
| Aspect | Extensibility | Pool creation cost | Accounting model | Native ETH support | Best for |
|---|---|---|---|---|---|
| Uniswap v3 | Limited to built-in AMM features | Higher per-pool deployment cost | Per-pool ERC-20 transfers and state | WETH wrapper required | Concentrated-liquidity LPs and traders |
| Uniswap v4 | Hooks allow custom pool logic | Much lower via singleton design | Flash accounting; net balance settlement | Native ETH supported natively | Developers building custom pools and experiments |
Uniswap v4 keeps the broad AMM idea but changes the architecture in ways aimed at developers as much as traders. The most important new feature is hooks. A hook is an external contract that can run custom logic at specific points in a pool’s lifecycle, such as before or after a swap or liquidity change.
The practical consequence is that Uniswap v4 is not just a fixed exchange design. It is closer to a platform for building exchange behavior. A developer can create a pool with logic for dynamic fees, custom oracle behavior, automated liquidity management, or even alternative accounting models. The v4 whitepaper explicitly describes hooks as a way to augment concentrated liquidity and, in some cases, even bypass the native concentrated-liquidity math through custom accounting.
That flexibility is paired with a new core architecture. Instead of deploying a separate contract per pool, v4 uses a singleton design where pools are managed in one contract. It also uses flash accounting, which means a caller can perform a sequence of actions while the system tracks only the net balances owed by the end of the call. The reason this matters is gas efficiency: fewer external token transfers and less duplicated contract infrastructure can make pool creation and multi-step interactions much cheaper.
Uniswap’s own materials describe pool deployment in v4 as dramatically cheaper than before, and they also note savings for multi-hop swaps. v4 also restores native ETH support in pools, which can reduce the need to wrap and unwrap ETH into WETH for some flows.
For developers, this makes Uniswap more useful as a settlement layer and experimentation surface. The official docs position it that way directly, with integration guides, smart-contract quickstarts for swaps and liquidity management, hook examples, SDKs, repositories, and deployment references. For end users, much of this complexity may stay in the background: they may simply get routed through v2, v3, v4, or UniswapX liquidity automatically by an interface.
Who should use Uniswap and how is it used in real workflows?
The people best served by Uniswap are the ones who benefit from an exchange that is open, onchain, and programmable. A trader uses it to swap one token for another from a self-custodied wallet. A liquidity provider uses it to earn fees by depositing assets into pools and, in newer versions, deciding how actively to manage price ranges. A wallet or DeFi app uses it as backend liquidity. A developer uses it as a protocol surface for building higher-level products.
This helps explain why Uniswap’s documentation gives so much attention to integrations, smart-contract examples, and deployment addresses. The product is not only a destination website. It is infrastructure other products embed.
At the same time, that openness creates responsibilities. Using Uniswap well means understanding that the protocol is generally non-upgradeable at the core-contract level, but surrounding interfaces, routers, and hooks can introduce new trust and security assumptions. It also means recognizing that “Uniswap” now refers to a family of versions with meaningfully different mechanics: v2’s broad constant-product pools, v3’s concentrated liquidity positions, and v4’s customizable hook-based architecture.
Security deserves especially careful treatment in v4. Hooks are powerful precisely because they let developers inject logic into pool behavior. That power can create new attack surfaces if the hook code is poorly designed. The protocol and periphery have undergone extensive audits and bug-bounty review, but users and integrators still need to evaluate the specific contracts and hooks they interact with, not just the Uniswap brand as a whole.
Conclusion
Uniswap is a decentralized exchange protocol that lets people swap tokens and provide liquidity through smart contracts rather than an order book. Its key insight is simple but far-reaching: a market can be made from pooled assets plus transparent rules.
Everything else follows from that. v2 made the basic AMM model broadly useful, v3 made liquidity far more capital efficient, and v4 turns Uniswap into a more customizable developer platform. If you remember one thing tomorrow, remember this: Uniswap is not just a place to trade tokens; it is a way of turning liquidity itself into programmable onchain infrastructure.
How do you trade through a DEX or DeFi market more effectively?
Trading through a DEX effectively means controlling slippage, checking liquidity, and choosing the right execution path. On Cube Exchange, fund your account, open the market for the assets you want to move, and use order-entry controls to limit price impact while you confirm external pool conditions and route quality.
- Fund your Cube Exchange account with fiat or a supported crypto transfer.
- Check on-chain liquidity and recent 24h volume for the token pair using a block explorer or DeFi analytics tool to confirm pool depth and spread.
- Open the market on Cube and pick an order type: use a limit order to lock a price or a market order for immediate execution.
- Set a slippage tolerance or specific limit price and a transaction deadline, review estimated fees, and submit the order.
- For large trades, slice the trade into several smaller orders over time and re-check pool depth between executions.
Frequently Asked Questions
- How does Uniswap set the price for a trade if there’s no order book? +
- Uniswap prices trades by enforcing a pool invariant (historically the constant-product rule) on on‑chain reserves: a swap must leave the pool’s reserves in a state that satisfies the invariant after fees, so price “emerges” from the pool balance rather than being posted by an order book maker.
- Why do liquidity providers still face risk on Uniswap, and how did v3 change that trade-off? +
- Liquidity providers earn fees but remain exposed to relative price movement between the pair (sometimes called impermanent loss); v3’s concentrated liquidity makes capital much more efficient by letting LPs place liquidity inside specific price ranges, but positions become non‑fungible, require more active management, and fees are tracked rather than automatically compounded.
- What are v4 hooks and why do they raise security concerns? +
- Hooks are user-supplied contracts that can run custom logic at points like before/after swaps or liquidity changes, enabling dynamic fees, custom oracles, or automated management, but they expand the attack surface and require careful auditing and permissioning because buggy or malicious hooks can affect pool behavior.
- How does Uniswap v4 reduce gas costs, and what protocol or chain dependencies does that rely on? +
- Uniswap v4’s singleton pool manager and flash accounting reduce repeated per‑pool contract overhead and transient token transfers to lower gas for pool creation and multi-step interactions, but the design relies on transient storage assumptions (e.g., EIP‑1153) and `flash accounting` behavior that developers should confirm against target chain capabilities.
- Are Uniswap’s core contracts upgradeable, and can governance still change fees or other settings? +
- Core Uniswap contracts are generally deployed as persistent, non‑upgradeable code, though governance retains limited controls over parameters (fee tiers, protocol fee fraction, factory owner) and a private key (feeToSetter) can enable protocol fees, so some operational knobs exist even with immutable core logic.
- How does frontrunning or MEV affect Uniswap trades and what can users do about it? +
- Because pool state and transactions are public and ordered on‑chain, profitable ordering strategies like frontrunning and sandwich attacks (forms of MEV) occur; users can mitigate risk with slippage controls, careful route selection or private/priority‑ordering services, but some MEV exposure is intrinsic to public CFMMs.
- Can a pool’s hooks or callbacks be changed after the pool is created? +
- Hooks and callback choices are constrained at pool creation—which callbacks run is fixed at initialization—so you cannot freely swap in new hook callbacks later without deploying a new pool, a design that trades runtime flexibility for predictable permissions and gas characteristics.
- Is Uniswap v4 production‑ready and fully audited, or should developers be cautious? +
- v4 was released with draft code, multiple audits, a $2.35M security competition, and an active bug‑bounty, but repositories and periphery contracts are described as early‑stage in places and some audit reports are draft or flagged issues remain, so integrators should treat parts as still maturing and verify audit/status before production use.
Related reading