What Is Uniswap & How Does It Work?

A Beginner’s Guide:

Uniswap is an Ethereum-based decentralized exchange (DEX) that facilitates the swapping of ERC-20 tokens between traders. As the decentralized finance (DeFi) continues to bloom, the hype for Uniswap’s protocol also continues to grow, but not without reason. When comparing Uniswap to any other DEXs, never before has it been so easy for anyone to add or list tokens to earn rewards. Plus, the convenience of peer-to-peer (P2P) transactions means any trades can be executed without intermediaries.

As the pioneer in DeFi, Uniswap strives to revolutionize the traditional DEX with its automated liquidity protocol. That means Uniswap can facilitate the exchange of tokens without relying on the conventional architecture of an order book method and to curb liquidity issues simultaneously. In this guide, you’ll understand what Uniswap is, how it works, and the pros and cons it possesses.

What Is Uniswap?

Uniswap refers to an open-source protocol built on top of the Ethereum blockchain. It represents an exquisite solution to simplify the process of ERC-20 token swaps without any centralized third-parties. That means users have the autonomy to manage their funds without depending on any centralized resources.

However, the lack of liquidity, such as insufficient funds passing through the platforms, prevented these decentralized exchanges from getting popular among liquidity providers.

That said, what sets Uniswap apart from the rest is it does not use an order book to determine prices. Instead, the protocol works by following an equation, where the total liquidity remains constant within the pool. And for the model to work, it involves liquidity providers to create a liquidity pool that sustains the decentralized trading and lending. That includes listing and swapping ERC-20 tokens without an order book.

How Does Uniswap Work?

The Uniswap protocol was inspired by the concept of the on-chain automated market maker (AMM) by Vitalik Buterin. Uniswap primarily uses the pricing mechanism Constant Product Market Maker Model, a variant of the Automated Market Making (AMM) system that holds liquidity pools for traders to trade against.

Subsequently, in May 2020, Uniswap introduced the updated version — Uniswap V2, along with liquidity pools. Unlike its predecessor (V1), users can swap between ETH and a single ERC-20 token, whereas V2 uses Wrapped Ether (wETH) in core contracts where users can pool ERC-20 tokens directly with any other ERC-20 tokens. Plus, prices became more reliable and more difficult for price manipulation.

This was followed by the introduction of Uniswap V3 in 2021, where liquidity providers were given access to concentrated liquidity and multiple fee tiers to better allocate their capital while capturing more fees in the process. V3 also allows cheaper and easier oracle integration with TWAP on demand that could be calculated for up to 9 days. This gave more control to individual liquidity providers, allowing them to be paid for taking on varying risks.

But how does it work exactly?

How Does Liquidity Pool Work?

The liquidity pools are liquidity reserves locked in a smart contract, typically funded by liquidity providers. And stablecoins like USDT, DAI are the main constituent of the pool. Since Uniswap exists in a permissionless environment, and liquidity pools are the backbone of Uniswap, it is vital to comprehend its fundamentals.

Basically, anyone can be a liquidity provider (LP), and to be an LP, you need to deposit an equivalent value of ETH and ERC-20 tokens into the pool. One of these AMM features is you can provide liquidity regardless of the liquidity pool’s size. In exchange, you’ll earn a reward in the form of liquidity tokens according to your contribution to the pool. That also means the number of unique tokens you receive is proportional to the pool’s liquidity. These liquidity tokens are used to track your contribution to the pool, distribute your share of the transaction fees, and for a multitude of usage across DeFi apps (dApps).

In these liquidity pools, the total liquidity derived from the product of the two types of tokens always remains constant, following this simple equation X × Y = K, in which the total liquidity remains constant.

Let’s understand how this equation works using the ETH/USDT liquidity pool as an example. If a user buys ETH (x) from the ETH/USDT pool, the supply of USDT (y) will be more than the ETH after a transaction is made. When the ETH supply is lesser, naturally, there will be a price surge and vice versa. That is where the total liquidity (k) remains constant to determine the pricing. Generally, the larger the liquidity pool, the easier it is to process large orders. However, slippage does happen as the x and y’s ratios are not on a linear scale.

When comparing Uniswap to centralized exchanges, there are no listing fees for verifications on Uniswap. Hence, Uniswap quickly became one of the most popular protocols for swapping tokens. Interestingly, Uniswap took-off even when Ethereum was still struggling with scalability issues during the Proof of Work consensus.

What is Concentrated Liquidity?

As mentioned above, Uniswap v2 liquidity is distributed evenly along the X × Y = K price curve. This causes the majority of liquidity to be kept unused and LPs only earn fees on a small portion of their capital. This does not make up for the impermanent loss risk taken by holding both tokens. Traders are also subjected to high slippage due to thin liquidity.

Uniswap V3 allows LPs to concentrate their capital within custom price ranges, providing greater amounts of liquidity at desired prices. LPs can choose between specific price curves and provide the same liquidity depth as v2 while putting far less capital at risk.

If you previously had $100 and decided to deploy capital in V2, you would have to do so across the entire price range which gives you a lesser yield. With concentrated liquidity, you can create a position by depositing only within a certain price range to earn the same amount of fees, as long as the price of the asset stays within the deposited range.

However, if market prices move out of your specified price range, liquidity is removed from the pool and will stop earning fees. Your position will also be converted entirely into the "less valuable" of the two assets, until the market price moves back into the specified range or you decide to manually update the price range.

What is a TWAP Oracle?

Uniswap v2 introduced time weighted average price (TWAP) oracles to store cumulative sums of Uniswap prices on a per-second basis. However, price sums were only checked once at the beginning and once at the end of a period to calculate an accurate TWAP.

The v3 oracle offers significant improvements, making it possible to calculate any recent TWAP within the past 9 days on-chain. This new version of historical price accumulators makes it easier and cheaper to create more advanced oracles that include simple-moving averages (SMA), exponential moving averages (EMA), etc.

This new update has reduced gas costs for keeping oracles up to date by almost 50% compared to v2. The costs for calculating TWAPs in external smart contracts are much cheaper too.

The Retrospective Of Uniswap

In 2016, Ethereum’s creator Vitalik Buterin proposed to create a decentralized exchange combined with an “on-chain automated market maker.” In his post on Reddit, he also shared some technical details of how this could be achieved.

Hayden Adams, a former mechanical engineer at Siemens, picked up that idea and started developing a fully-functional platform — Uniswap. Soon after he pitched the idea, the project received some grants and $100,000 from the Ethereum Foundation. Shortly after, the first version was officially launched in Nov 2018. Subsequently, in April 2019, Paradigm (a digital asset investment company) contributed $1 million for the further development of Uniswap.

In 2019, Uniswap was crowned as the ‘King of DEXs’ leading all DEX by a large volume. After Uniswap V2 was launched in May 2020 together with the boost of DeFi, the number of transactions in the Ethereum network quickly rose to the level of the previous peak in 2017. By May 2021, Uniswap V3 was introduced to allow liquidity providers to earn more fees through concentrated liquidity and multiple fee tiers. This caused a momentarily spike in Ethereum transactions, reaching an all-time high of 1.75 million daily transactions.

Uniswap acquired Genie in June 2022, expanding its products to include NFTs. The NFT marketplace aggregator lets anyone discover and trade NFTs across most platforms. The team plans to integrate NFTs into the Uniswap web app, where users will be able to buy and sell NFTs across all major marketplaces like OpenSea. The announcement came with a USDC airdrop for all Genie users that interacted with the platform previously.

Last updated