The story of Uniswap told through its versions: The road of the DeFi Giant
Uniswap stands as a pillar of DeFi and exemplifies continuous innovation. In this post, we’ll explore how the protocol evolved through its versions, examining what each release set out to solve, what it accomplished, and how it enhanced the DeFi ecosystem.
Uniswap V1
The first version of Uniswap, which was launched in November 2018 and created by Hayden Adams, was inspired by a model proposed by Vitalik Buterin. Hayden felt that a decentralized exchange aimed to be:
- Censorship resistant: No one can stop it
- Decentralized: No one can control it
- Permissionless: Anyone can use it
- Secure: Anyone can verify transactions
The core idea was revolutionary: allow users to swap tokens automatically, without relying on traditional order books or centralized intermediaries.
The constant product formula made it possible:
x * y = k
Where “x” represents the number of tokens in the pool and “y” represents the amount of the other token. At last, “k” is the constant that must remain unaltered.
Each token pair has a dedicated smart contract that holds reserves of both tokens, allowing users to deposit into these pools as Liquidity Providers (LPs). This innovation introduced the first functional Automated Market Maker (AMM), enabling decentralized swaps between ERC-20 tokens and ETH, and letting anyone provide liquidity to earn fees. The protocol charges a 0.3% fee on every trade distributed among the LPs.
How does the formula work? When a user swaps Token A for ETH, the protocol adjusts the token reserves while ensuring that the k constant remains unchanged. This makes larger trades have a bigger price impact, making it more expensive to execute large swaps in only one operation. After the swap, the new reserves will be updated, and the price will change based on the new token ratio.
How are LP shares calculated? When a new LP adds liquidity, they deposit x amount of “A” token and y amount of ETH proportionally to the current reserves. They receive LP tokens that represent their percentage ownership of the pool.
As the total liquidity in the pool is calculated as
each LP receives liquidity tokens proportional to its contribution, equal to the difference between L(new) and L(old)
Could LPs lose money by providing liquidity? Yes, it’s called impermanent loss, and it is the temporary loss in terms of value that LPs experience compared to holding their assets. It happens when the price of tokens in a liquidity pool changes relative to when they were deposited. The IL percentage formula is:
where P is the relation between the new price and the initial one. Uniswap V1 was written in Vyper, a smart contract language focused on simplicity and security. It laid the foundation for the protocol’s core mechanics before later versions moved to another language.
However, the first version had clear limitations:
- Trades are limited to ERC-20/ETH pairs: In the case you need to trade ERC20 to ERC20, it would require two separate transactions, resulting in a higher gas fee and a potential price slippage (difference between the expected price of a trade and the actual price after execution).
- Vulnerability to MEV attacks (e.g., front-running or sandwich attacks): These kinds of strategies made by miners or validators directly affect the final cost that users have to pay for every transaction, worsen the user experience in general, and reduce their usage.
- Capital usage is inefficient: liquidity was distributed uniformly on every point of the curve of prices, so only a fraction of the assets is available at a given price.
Still, it worked. v1 processed over 400M USD in volume in its first year, proving that decentralized, automated trading was viable. In its peak, the TVL of Uni v1 was around 65M USD (Apr 2020), and the fees generated were around 780k USD (May 2020). Nowadays, it is still active, but its usage has significantly dropped, with a TVL of $4.3M and a trading volume of just $ 70 K.
The “x” axis represents time since launch, and the “y” in two scales, million dollars on the left and billion dollars on the right. The red line is TVL, and the Yellow line is the cumulative Trading Volume. From: Defillama
Uniswap v1 was the initial experiment that took shape and laid the foundation for something much more advanced. Over time, it helped pave the way for other protocols and DeFi as a whole.
Uniswap V2
In May 2020, Uniswap released its second version — a milestone in the evolution of decentralized exchanges. This version wasn’t just an upgrade but a direct response to v1’s limitations, aiming to improve and extend core functionality while maintaining simplicity and decentralization.
While v1 was built using Vyper, v2 switched to Solidity. This change was strategic — Solidity provided capabilities that Vyper lacked, enabling more sophisticated features.
A key improvement came in token trading mechanics. In v1, swaps were limited to ERC-20/ETH pairs, forcing all trades to route through ETH. Though this design unified liquidity, it led to higher transaction costs and increased impermanent loss exposure for liquidity providers (LPs).
Uniswap v2 eliminated this constraint by enabling direct trading between any two ERC-20 tokens, using the same x*y=k formula. This created a more flexible and efficient trading experience.
Another major limitation of v1 was its vulnerability as a price oracle. Prices were easily manipulated, making it unreliable for other on-chain applications. Uniswap v2 solved this by introducing Time-Weighted Average Price (TWAP) oracles. The protocol began recording cumulative prices at the start of each block, allowing external contracts to calculate average prices over any arbitrary time window:
This meant that longer averaging periods made price manipulation exponentially more expensive, boosting the security and utility of Uniswap as a data source for the rest of DeFi.
One of the most powerful features in this version is the support of flashloans through flash swaps, which enabled users to borrow any amount of tokens from a pool with no upfront cost, as long as they were returned (or paid for) by the end of the transaction. Through flash swaps, anyone can temporarily borrow assets from a Uniswap pool. The contract runs a callback function before applying the constant product formula. The transaction automatically reverts if the user fails to meet the repayment condition (owed amount plus fees).
Uniswap v2 made important architectural changes to enhance security and modularity. By moving all non-core logic to a separate router contract, the main contract could focus solely on swaps and liquidity storage. This design minimized potential attack vectors and better protected user funds.
The protocol required traders to send tokens before calling swap(), allowing the contract to determine swap amounts from balance changes. This approach made the system more robust and compatible with various transfer methods.
A crucial economic update introduced a 0.05% fee switch that, when activated, would decrease LP earnings from 0.30% to 0.25% per trade. The remaining 0.05% is redirected to the Uniswap protocol’s treasury, providing a potential revenue for governance or development initiatives.
To reduce liquidity fragmentation and simplify contract logic, Uniswap v2 replaced native ETH with Wrapped ETH (WETH).
The protocol also improved its LP token minting mechanism. In v1, the number of LP tokens minted simply matched the amount of ETH deposited. Though functional, this arbitrary approach tied the LP token supply to the initial price of the paired token, creating vulnerability to manipulation and inconsistencies.
How did V2 solve this issue? It implemented a more reliable and mathematically accurate formula. Rather than using a single asset, v2 now determines LP token minting amounts using the geometric mean of the deposited token amounts:
This ensures a balanced and fair representation of both assets in the pool, regardless of their relative prices.
To prevent manipulation during pool creation, the protocol burns the first 10–15 LP tokens. This safeguard stops users from exploiting the system by adding tiny, imbalanced token amounts to gain disproportionate control of the pool’s value.
How did MEV affect this protocol? Between 2020 and 2022, according to data from Flashbots, MEV activity on Uniswap v2 alone generated over $700 million in extracted value. More than $350 million in 2021 came from sandwich attacks and arbitrage strategies.
While profitable for searchers, these strategies imposed high implicit costs on everyday users. Transactions with low slippage tolerance were especially vulnerable. During volatile periods, sandwich attacks could inflate prices by 5–10% in certain token pairs, directly draining value from traders.
An analysis of Ethereum blocks from 2021 revealed that over 60% of blocks contained MEV-related transactions, many stemming from Uniswap v2 swaps. This highlighted Uniswap v2’s central role in MEV extraction on Ethereum. To mitigate these risks, traders increasingly adopted private transaction architectures like Flashbots Protect, enabling direct trade submission to block producers instead of through the public mempool.
Since its launch, Uniswap V2 has played a crucial role in the DeFi ecosystem by enabling decentralized token swaps and providing liquidity providers with steady fee earnings. Its significant improvements over the original version attracted more users and increased platform liquidity.
In 2021, DeFi surged in popularity, and Uniswap V2’s liquidity grew substantially. Its TVL went over $10 billion, establishing it as one of the largest DEXs at the time. Trading fees reached record highs.
In May 2021, Uniswap V3 launched with many new features, but V2 maintained its popularity due to its simpler design and lower gas costs. Many LPs, particularly those seeking a straightforward setup, continued using V2.
Uniswap v3
In May 2021, Uniswap launched v3, its most significant protocol upgrade to date. While v2 emphasized simplicity and accessibility, v3 introduced powerful tools aimed at boosting capital efficiency and giving liquidity providers (LPs) more control over their liquidity.
Earlier versions (v1 and v2) distributed liquidity evenly across all price levels on the curve, regardless of where trading activity occurred. This approach left substantial amounts of liquidity sitting inactive and unutilized.
Uniswap v3 revolutionizes this with its concentrated liquidity concept. LPs can now specify custom price ranges for their active liquidity. Within these bounds, the familiar constant product formula x * y = k still applies, but trades in the selected range benefit from much deeper liquidity. This innovation dramatically improves capital efficiency, sometimes achieving gains of up to 4000x compared to the previous version. But compared with v2, who is winning or losing? By allowing LPs to focus their capital, v3 gives higher rewards to those who accurately predict the trading price range. If the market stays within their defined zone, they earn more fees, all with less capital at risk.
However, it’s a double-edged sword:
- Active LPs who manage their ranges well earn more.
- Passive LPs might earn less, or even nothing, if the price moves outside their range (their liquidity becomes inactive).
Trades executed within these concentrated ranges experience much less slippage, meaning better prices and lower transaction costs for traders. This benefits the entire DeFi ecosystem, not just LPs.
The real reserves of a position in the range (Pa; Pb) with the real price at Pc are given by:
Where L represents the available liquidity
What happens if a price exits the position defined range? That liquidity stops earning fees and becomes inactive. At that point, the position holds only the asset with the lower price. But if the market price returns to the specified range, the liquidity becomes active again, resuming fee generation. This mechanism makes active management crucial for LPs who aim to maximize returns.
When LPs choose very small price ranges, the position works similarly to a CEX limit order:
- When the price enters the range, the LP is actively trading between the two assets.
- If the price fully crosses the range, the position flips from being entirely in one asset to being entirely in the other.
However, there are important considerations:
- Ranges can’t be infinitely narrow.
- The swap is not irreversible — if the price re-enters the range, the position becomes active again and can be traded back.
To achieve these capital efficiency improvements and improve the protocol’s performance, some Architectural changes were necessary; the most important of these are detailed below:
- Contrasting v2’s flat 0.3% fee (could only change to 0.25%), v3 introduced multiple fee tiers:
- 0.05% for low-volatility pairs (e.g., stablecoin-stablecoin)
- 0.3% is the standard for most pairs
- 1.0% for high-volatility or exotic tokens
- LPs can choose the tier that goes with the risk they’re willing to take, giving them even more flexibility and control.
- Unlike previous versions, where trading fees were automatically reinvested into the pool, V3 requires LPs to claim and reinvest their fees manually. Additionally, LP positions are now represented as NFTs rather than standard ERC-20 tokens. This change was necessary because each position in V3 is unique due to customizable price ranges. While this makes liquidity positions more customizable, it also makes them less flexible for staking or lending.
What about the Oracle system? Uniswap v3 made a big upgrade to its price oracle, making it more secure and gas-efficient. In v2, it used a time-weighted average price (TWAP) by recording price data per block. V3 keeps this idea but makes it more flexible and easier to use.
Now, users don’t need to store price history themselves. V3 includes that in the core, so outside contracts can get TWAPs without saving extra data.
A major improvement is the shift from arithmetic mean TWAP to geometric mean TWAP. V3 tracks the sum of log prices, which lets users compute the geometric mean TWAP. This calculation method multiplies all prices (P1, P2, P3, …, Pn) and takes the nth root, where “n” represents the total number of values.
It has some advantages, such as:
- Reduce the impact of the outliers (Extreme or atypical values)
- A better reflection of the proportional price variations (useful in volatile markets)
- It’s more representative in markets with exponential growth or logarithmic variations.
Rather than tracking the cumulative sum of price P, it accumulates the cumulative sum of the current tick index (log1.0001(Pi)). This accumulator represents the sum of the price logarithm (base 1.0001) calculated for each second since the contract’s inception.
To find the geometric mean TWAP over any period from t1 to t2:
To compute this, check the value at the two points t1(start) and t2(end), subtract the first one from the second to find the accumulated change, and divide by the number of seconds expended. Last Raise 1.0001 to the power of this result to compute the final price. Operating, we arrive at:
Where at is the price accumulator.
Additionally, the protocol tracks a metric called Seconds Per Liquidity Cumulative (SPL), which measures the duration of active liquidity at any given time. A practical application of SPL occurs when external contracts distribute rewards fairly to LPs, ensuring that only active liquidity receives rewards. This prevents positions from earning rewards when prices move outside their predicted ranges, thus strengthening the protocol’s security and reliability.
With v3’s improved oracle system:
- External protocols can rely on price data with greater security
- TWAP calculations require less gas
- Applications like lending protocols and perpetuals benefit from more precise, cost-effective price reads
- While maintaining compatibility with v2’s TWAP logic, the system offers flexible lookback periods, reduced on-chain storage, and simplified data access
- The result is a faster, safer, and more scalable oracle mechanism than v2
After examining these upgrades and features, a key question emerges: how did Uniswap v3 impact DeFi in practice? How successful was its adoption, and where does it stand in today’s market?
As of April 2025, Uniswap v3 remains a dominant force in DeFi, holding the number one position with 13% of the market share (as of 13/04/2025, according to CoinGecko). While this position is impressive, several key trends and challenges are shaping its trajectory:
- TVL Trends: Uniswap v3’s Total Value Locked (TVL) has fallen from its $4.2 billion peak in mid-December 2024 to $2.5 billion currently. Though the platform remains strong, this decline suggests some market pressure and potential loss of momentum.
- Fee Generation: Despite lower TVL, Uniswap v3’s revenue remains robust. The platform generates approximately $500 million yearly in trading fees, with about $1.27 million collected in the past 24 hours. These figures demonstrate sustained trading activity and profitability for liquidity providers.
- Competitive Landscape: Though Uniswap v3 maintains its market leadership, new competitors are gaining ground. Platforms like Orca (11.1% market share by volume) and Meteora (7.5% market share by volume) are capturing significant trading volume, potentially through distinctive features and fee structures that could challenge Uniswap v3’s dominance.
Uniswap v4
Finally, we’ve arrived at the most up-to-date version of the protocol. Released in January 2025, the latest version of Uniswap was almost ready in 2024 but underwent an extensive audit phase for approximately a year before its production release. This meticulous process was crucial in ensuring the security and reliability of its powerful new features.
The core objective of Uniswap V4 is to offer a flexible and highly efficient framework that encourages developers to build customized solutions on top of liquidity pools. V4 is not just a technical evolution, but an adaptable platform that allows for the integration of new features, reduces gas costs, and improves the experience for both liquidity providers and traders, all through an innovative and modular design.
It brings customizability, introducing code hooks that allow developers to modify the way liquidity pools work, enabling more flexibility in operations in the protocol.
Hooks are external contracts that implement logic defined by developers at specific points of the pool cycle, and they make it possible to integrate new functions without needing custom implementations of Uniswap.
Some use cases could be:
- Executing large orders gradually through Time Weighted Average Market Maker (splitting larger orders into multiple shorter orders distributed over a defined time to reduce slippage)
- On-chain limit orders at specific prices
- Applying dynamic fees depending on price movements and volatility
- Custom oracles
- Mechanism to prevent MEV for LPs
To fully understand how hooks work, it’s essential to first define the Pool lifecycle. Uniswap V4 introduces 10 hook callbacks, each corresponding to a specific stage in the pool’s operation. Below is a description of each callback along with an example use case to illustrate how it can be applied in practice.
beforeInitialize/afterInitialize
A protocol might use beforeInitialize to check if initialization is allowed for a given token pair, e.g., verifying if both tokens are whitelisted. afterInitialize could be used to emit custom analytics or register the pool in an external registry.
beforeAddLiquidity/afterAddLiquidity
beforeAddLiquidity could impose custom limits on who can add liquidity or how much can be added. afterAddLiquidity could be used to record metadata for reward distribution systems.
beforeRemoveLiquidity/afterRemoveLiquidity
Both are triggered by liquidity withdrawal. In beforeRemoveLiquidity, a project could lock liquidity under certain conditions, preventing its removal. Then, when removal is successful, afterRemoveLiquidity could update user records in a staking or farming contract.
beforeSwap/afterSwap
beforeSwap could implement slippage or volatility protection, rejecting swaps at specific margins, and afterSwap could charge fees, record swap metrics, or trigger token rebalancing operations.
beforeDonate/afterDonate
They are executed when someone donates tokens to the pool. beforeDonate can be used to check if the donation is allowed or to set limits. afterDonate can notify other contracts, update donation stats, or trigger rewards.
Uniswap v4 introduces an architecture based on a singleton contract, where all pools are managed by a single contract. This concept offers some key advantages:
- Cost efficiency: It avoids deploying individual contracts for each token pair, making contract deployment significantly cheaper.
- Optimized swap routing: By centralizing the state of all pools, multi-hop swaps (swapping from one token to another, passing through multiple tokens in a single transaction) become more efficient, reducing gas costs and minimizing liquidity fragmentation.
Other significant improvements could be:
- Flash accounting: it allows multiple operations to be executed without transferring tokens after each step. Instead, transfers occur only once at the end, improving efficiency. Combined with the singleton contract, this enables more efficient routing across v4 pools and reduces the cost of liquidity fragmentation.
- Native ETH support: pool pairs support native tokens, so ETH swappers and liquidity providers benefit from gas cost reductions from cheaper transfers and the removal of additional wrapping costs.
All these ambitious changes proposed by Uniswap v4 resulted in a powerful and flexible framework for building custom liquidity solutions. However, despite the protocol’s technical advancements, user adoption has been slower than expected.
Many users and developers recognized the potential of V4, but migration from V3 has been limited. One of the main reasons is that V3 remains highly functional and familiar, with tested tools, deep liquidity, and stable user interfaces. In contrast, V4’s added flexibility comes with greater complexity, requiring more technical knowledge and custom development to take full advantage of its features.
As devs can now add their custom features to how pools work, it means that users are not just trusting Uniswap anymore, but also the code written by others. This makes audits and transparency even more important when interacting with v4-based applications.
Also, the lack of user-friendly frontends has made it harder for less technical users to adopt V4. It makes sense for LPs and traders to prefer the plug-and-play simplicity of V2 and V3.
As of early 2025, Uniswap V4 holds a relatively small portion of overall DeFi activity (At 13/4/2025, the Average Daily Volume is about 75M USD, and the TVL is around 120M USD from Dune), especially when compared to V3. While these numbers confirm that V4 is being used, they also highlight that a full migration hasn’t occurred, and it may take further ecosystem development before its usage grows significantly.
Uniswap has aimed to build an open financial system where anyone can trade assets and provide liquidity without intermediaries. This mission has guided its evolution from V1 to V4.
Each version brought key improvements: V1 proved decentralized trading was possible, V2 enhanced usability and security, V3 added precision and capital efficiency, and V4 transformed Uniswap into a platform where developers can customize how liquidity works.
Has Uniswap fulfilled its mission? In many ways, yes. It has become one of the most vital pillars of DeFi, facilitating billions in trades and reshaping how people interact with financial markets. But challenges remain. V4’s adoption has been slower, and the learning curve steeper. Many users still rely on the simplicity of previous versions, and the ecosystem around V4 is still growing.
The horizon, however, is wide open. With V4’s flexibility and infrastructure in place, the next wave of innovation is just beginning. Uniswap’s mission is far from complete.
We’ll be following this journey closely. Stay tuned, we’ll keep posting updates as Uniswap continues to evolve.
