A Quick Summary of Changes to Uniswap from V1 to V4
Here are the major features that were added on Uniswap between versions v1 and v4
Uniswap is a decentralized cryptocurrency exchange that launched in November 2018. It allows you to swap between ERC-20 token pairs, and anyone can create a liquidity pool for their token. I decided to compile a summary of the changes from Uniswap’s four versions.
Disclaimer: this is not financial advice, nor is this list exhaustive of all the changes in the protocol. Please read and understand the risks of Uniswap on their website before participating. One such risk not explained in this article is impermanent loss.
V1
There is a separate smart contract for each ETH to ERC-20 token pair, called “exchanges.”
Uniswap uses a constant Automated Market Maker (AMM) pool using the equation
x*y=k
, wherex
is the liquidity of ETH andy
is the liquidity of the ERC-20 token in the pool.When people provide liquidity, they are given pool tokens. These tokens are minted when liquidity is deposited and burned at the time of withdrawal.
The pools charge a 30 basis point fee on any swap, so every swap increases the liquidity of the pool and the value of a liquidity pool token. This is how liquidity provides (LPs) make their money—they deposit tokens and the more swaps that happen, the more overall money in the pool they can withdraw based on their shares in the pool.
In order to go from one ERC-20 to another, you have to go through two contracts, ERC-20 token 1 to ETH then from ETH to ERC-20 token 2.
Since everything is on-chain, the price of the token may shift by the time the transaction of your swap is included in a block. So Uniswap allows you to provide limits and deadlines for swaps.
V2
Exchanges now allow liquidity pools for arbitrary pairs of ERC-20s (before it was only ETH and ERC-20).
Uniswap introduces a price oracle that allows people to estimate the time-weighted average price of the swaps over a given time interval. This helps prevent market manipulation, an example of this being when someone changes the liquidity in the pool right before a derivatives contract reads the current price of the pool.
Flash swaps allow traders to receive assets and use them elsewhere before paying them back in a single transaction.
Uniswap added the option to turn on a 0.05% protocol fee for themselves. This could have cost more gas for each swap, but they avoided this by minting liquidity tokens to themselves anytime an LP deposits or withdraws money.
We now have meta transactions. People can transfer their pool shares off-chain without paying gas fees. They can do this by signing a message off-chain that says the transfer happened. Then, someone can bring this transaction on-chain by calling the
permit
function with their signed message.This version moved from Vyper to Solidity as the main programming language.
V3
LPs have the option to use concentrated liquidity. This provides them granular control over the price ranges to which their capital is allocated. There are “positions” that represent the price ranges in which the LPs liquidity is available.
Because of concentrated liquidity, fees are no longer added uniformly to everyone. LPs receive a fee for a swap depending on if their liquidity was active when the swap happened. Therefore, fees are no longer added to the overall liquidity of the pool and instead sit in a separate pool.
There are now multiple fee tiers. Each pool can charge 0.05%, 0.30%, or 1%.
There were improvements to the historical price oracle. People can query recent price changes, whereas before, it was the responsibility of the user to store historical price changes. They also use the geometric mean now to store the price changes, which allows them to save space on how much information they need to store (I might dedicate an article to this in the future). Finally, there is an oracle for volume too.
V4
Uniswap added Hooks. You can write custom code for your liquidity pool that is executed before or after predetermined pool actions.
Uniswap is now a singleton contract. Before, Uniswap used a factory contract to create new exchanges. Now, there is a single contract that holds all the pools.
Uniswap introduced flash accounting. In complicated multi-hop swaps, we want to accumulate changes to pools and apply them once at the end of the transaction. Before, Uniswap applied each intermediate transaction independently, potentially costing more gas.
There’s support for native ETH.
Thanks for reading! Hope this helps.