What Is Uniswap and How Does It Work?
Home
Mga Artikulo
What Is Uniswap and How Does It Work?

What Is Uniswap and How Does It Work?

Intermediate
Na-publish Aug 24, 2020Na-update Dec 11, 2023
12m

TL;DR

  • Uniswap is a decentralized crypto exchange powered by Ethereum and governed by its native token, UNI.

  • Traders can exchange any Ethereum ERC-20 tokens on Uniswap without having to rely on intermediaries or centralized entities. 

  • Anyone can earn fees by lending their crypto to Uniswap’s liquidity pools.

Introduction

Centralized exchanges (CEXs) have been the backbone of the cryptocurrency market for years due to their deep liquidity, faster transactions, fiat on-ramps and customer support. However, decentralized exchanges (DEXs) are gaining popularity as users are attracted by the lower trading fees, security, privacy and accessibility.

DEXs offer unique benefits that can make them a compelling alternative to CEX. One example is Uniswap. Created by Hayden Adams in 2018, its implementation was inspired by the underlying technology first described by Ethereum co-founder Vitalik Buterin. Uniswap pioneered the Automated Market Maker (AMM) model and played a crucial role in the invention and development of DEXs. Today, Uniswap continues to be one of the most user-friendly DEXs available, with substantial liquidity and an extensive selection of token listings.

What Is Uniswap?

Uniswap is a DEX that lets users trade cryptocurrencies without depending on a central authority or intermediary, while maintaining censorship resistance. Operating on the Ethereum blockchain, Uniswap leverages smart contracts — self-executing programs on the blockchain with predetermined conditions directly written into code. 

Uniswap employs an innovative AMM model, which uses liquidity pools instead of traditional order books to enable seamless trading. Users can provide liquidity to these pools by depositing an equal value of both tokens in the pair. In return, they receive Liquidity Provider (LP) tokens. Other users can swap tokens by interacting with the liquidity pools. A Constant Product Market Maker (CPMM) model is used to determine the price of assets in a liquidity pool.  

Uniswap uses open-source software, which you can check out on Uniswap GitHub.

How Does Uniswap Work?

At the core of Uniswap is its CPMM model. Let’s see how it works. 

Let’s say you deposit a trading pair to Uniswap’s liquidity pool as a liquidity provider (LP). You can commit any pair of tokens of equal value, either ETH and one ERC-20 token, or two ERC-20 tokens. One of the tokens is usually a stablecoin such as DAI, USDC, or USDT. In return, you’ll receive "liquidity tokens" as an LP, representing your share of the liquidity pool and the corresponding portion of the trading fees generated by the pool. .

Let's look at the ETH/USDT liquidity pool. We'll call the ETH portion of the pool x and the USDT portion y. Uniswap multiplies x by y to calculate the total liquidity in the pool, which we'll call k. The core idea behind Uniswap is that k must remain constant. Therefore, the formula for the total liquidity of the pool is: x * y = k.

So let's say Alice buys 1 ETH for 300 USDT using the ETH/USDT liquidity pool. In doing so, she increases the USDT portion and decreases the ETH portion of the pool. This will increase the price of ETH.

This occurs as there is now less ETH in the pool after the transaction and we know that the total liquidity of the pool (k) must remain constant; this mechanism determines that the price of ETH will be k/x. Ultimately, the price paid for the ETH in the pool is based on how much a given trade shifts the ratio between x and y.

It's worth noting that this model does not scale in a linear fashion. The larger the order, the greater the shift in the balance between x and y. Larger orders are therefore much more expensive than smaller orders and will lead to progressively greater slippage. It also means that the larger the liquidity pool, the smaller the shift between x and y, and therefore, the easier it is to fill large orders.

The Evolution of Uniswap

Uniswap has evolved over time, with different protocol versions offering new features and improvements. Here's a brief overview of Uniswap v1, v2, and v3:

Uniswap v1

Launched in 2018, Uniswap v1 was the first version of the Uniswap protocol. It was designed with simplicity in mind but still allowed users to trade any ERC-20 token on the Ethereum blockchain. The protocol gained popularity among the Ethereum community and worked as a proof of concept for AMM based decentralized exchanges.

Uniswap v2

Uniswap v2 was launched in 2020 and brought several improvements to the first version. One of the most significant changes was the introduction of ERC-20 to ERC-20 pairs, which meant liquidity providers could create pair contracts for any two ERC-20 tokens.

Users could also trade between the tokens without the need for intermediate conversion to ETH. In short, Uniswap v2 permitted liquidity pools consisting of any two ERC-20 tokens instead of needing to have ETH alongside one ERC-20 token.

Uniswap v2 also improved the efficiency of the protocol, lowered gas fees, and ushered in new features such as flash swaps, which meant tokens could be released to recipients before verifying that sufficient input tokens were received. The new features and optimizations set the stage for exponential growth in AMM adoption and made Uniswap one of the largest cryptocurrency spot exchanges.

Uniswap v3

One of the most significant changes Uniswap v3 introduced was related to capital efficiency. Many AMMs are largely capital-inefficient — most of the funds they contain are usually not in use due to an inherent characteristic of the aforementioned x * y = k model. Simply put, the more liquidity the pool has, the larger the orders and price range the system can support.

LPs in these pools provide liquidity for a price curve between 0 and infinity, which means the capital provided by LPs in an AMM is evenly distributed across all price ranges. This means only a portion of the liquidity in the pool sits where most of the trading is taking place. However, it doesn't make much sense to provide liquidity in a price range that is far from the current price or will never be reached.

Uniswap v3 seeks to address this issue — LPs can now set custom price ranges within which they want to provide liquidity, which should result in more concentrated liquidity in the price range with the most trading activity. For example, if an LP sets a price range of $1,000 to $2,000, the liquidity provided can only enable trading between these two prices, instead of within infinite price ranges.

In some sense, Uniswap v3 is a rudimentary way of creating an on-chain order book on Ethereum, where market makers can decide to provide liquidity in price ranges of their choice. It’s worth noting that this change favors more experienced market makers over beginner participants. With this additional layer of complexity, less active LPs may earn less in trading fees than professional players who optimize their strategy consistently.

Uniswap LP positions as NFTs

Since each LP can set their own price range, each Uniswap LP’s position is unique and as such, no longer fungible. In Uniswap v3, LP positions are now represented by a non-fungible token (NFT). However, the shared positions can still be made fungible (ERC-20).

Uniswap v3 LPs now see all fees generated directly in the NFTs themselves. These NFTs can be traded between wallets and holders can always collect position fees. It's basically a digital image that displays essential information, such as the token pair and a curve representing the position's "steepness". Each Uniswap v3 position also has a unique color scheme, and different pools are represented by different color variations.

Different fee tiers

Uniswap v3 offers LPs three fee levels, 0.05%, 0.30% and 1.00%, to allow LPs to adjust their profit margins based on the expected volatility of the token pair. For example, LPs are exposed to higher risks in non-correlated pairs such as ETH/USDT and lower risks in correlated pairs such as stablecoin pairs.

Uniswap on Layer 2

Historically, Ethereum transaction fees have been on the rise as network usage has increased. This makes using Uniswap economically unfeasible at times, especially for smaller users. To solve this problem, Uniswap v3 allows Layer 2 scaling solutions to scale smart contracts while still enjoying the security of the Ethereum network. This implementation also helps to increase transaction throughput and ensure lower fees for users.

Uniswap live on BNB Chain

Uniswap went live on the BNB chain after receiving 66% support from governance voters. This move can potentially provide users with more efficient and cost-effective trading options. It also means Uniswap users will be able to take advantage of BNB Chain's high speed and low transaction fees. Additionally, the integration allows Uniswap to tap into a new pool of liquidity and increase awareness and adoption among both retail and institutional investors.

What Is Impermanent Loss?

Aside from earning fees for providing liquidity to traders who can swap tokens, LPs should also be aware of an effect called impermanent loss. Let’s assume Alice is an LP who has deposited 1 ETH and 100 USDT into a Uniswap pool with a total liquidity of 10,000 (10 ETH x 1,000 USDT); the rest was funded by other LPs like her. Alice's share in the pool is 10%, meaning her initial deposit comprises 10% of the pool’s total liquidity.

At the time of Alice's deposit, the price of 1 ETH was 100 USDT, which means her deposit was $200 (1 ETH x $100 + 100 USDT). Now suppose that the price of ETH increases to 400 USDT. As a result, arbitrage traders add USDT to and remove ETH from the pool until the ratio between the two accurately reflects the new price. This causes the amount of ETH and USDT in the pool to decrease to 5 ETH and 2,000 USDT.

Alice decides to withdraw her funds from the pool. According to her share, she receives 10%, i.e., 0.5 ETH and 200 USDT, totaling $400 (0.5 ETH x $400 + 200 USDT). On the surface, it seems like Alice has made a profit.

However, if she had held onto her initial deposit of 1 ETH and 100 USDT, she would have ended up with a total value of $500 (1 ETH x $400 + 100 USDT). Therefore, by depositing her funds into the Uniswap pool, Alice has lost out on the ETH price appreciation.

This loss is referred to as “impermanent” because it can be mitigated if the prices of the pooled tokens revert to the same prices as when they were added to the pool. Additionally, since LPs earn fees, the loss may be balanced out over time. Nonetheless, LPs should be aware of the concept of impermanent loss before adding funds to a Uniswap pool.

Do note that the above scenario applies whether the price rises or falls from the time of the deposit. This means that if the price of ETH decreases from the time of the deposit, the losses incurred by the LP may also be amplified. 

How Does Uniswap Make Money?

Uniswap generates revenue through a small fee charged on each trade made on the protocol. This "liquidity provider fee" is set at a certain amount of the trade value and is automatically distributed to LPs. Unlike traditional exchanges, Uniswap as a protocol does not generate revenue for itself but for LPs. By concentrating their liquidity, LPs can increase their exposure within the specified price range to earn even more trading fees on Uniswap v3.

Also, due to Uniswap’s open-source and decentralized nature, there is no central entity controlling or profiting from the protocol. Instead, it’s maintained and improved by a community of developers and its governance, both of whom contribute to its progress.

The Uniswap (UNI) Token 

Uniswap's native token, UNI, was launched in September 2020 and has since been attracting users and LPs to the platform. UNI is an ERC-20 token, which means it was built on Ethereum and can be stored in any cryptocurrency wallet that supports ERC-20 tokens.

The UNI token entitles its holders to governance rights, meaning they can vote on changes and improvements to the protocol. The extent of voting power a user has is proportional to the number of governance tokens they hold. The governance process is decentralized, which means anyone can submit a proposal and anyone can vote.

UNI tokens can be bought and sold on various cryptocurrency exchanges, so traders can use UNI tokens to trade for other cryptocurrencies or to participate in decentralized finance (DeFi) applications. Do note that new use cases may emerge through community requests and governance votes.

How to Use Uniswap

To use Uniswap, you need to have a cryptocurrency wallet that contains some Ether or ERC-20 tokens. Here’s how to start using a simple swap option on Uniswap:

  1. Connect to your Ethereum wallet on the Uniswap website.

  2. Select the token you wish to trade. Uniswap supports several ERC-20 tokens; make sure you select the correct one.

  3. Enter the amount you wish to trade. The interface will then show you the estimated amount of the other token you will receive, based on the current exchange rate.

  4. If the amount is satisfactory, you can click "Swap". Your wallet will then prompt you to confirm the transaction.

  5. After confirming the transaction, the trade will be executed on Ethereum. Finally, the tokens will be displayed in your wallet.

Closing Thoughts

Uniswap is an evolving DEX protocol built on Ethereum. It allows anyone with a crypto wallet to exchange tokens without the involvement of intermediaries or third parties. The platform has enabled a new class of LPs to earn fees on their idle assets while allowing traders to easily swap between cryptocurrencies.

The launch of the UNI governance token has further established Uniswap's position as a community-driven platform. As the DeFi ecosystem continues to grow, it will be interesting to see how DEXs evolve to meet user demands while maintaining their core values of decentralization and trustlessness.

Further Reading

Disclaimer and Risk Warning: This content is presented to you on an “as is” basis for general information and educational purposes only, without representation or warranty of any kind. It should not be construed as financial, legal or other professional advice, nor is it intended to recommend the purchase of any specific product or service. You should seek your own advice from appropriate professional advisors. Where the article is contributed by a third party contributor, please note that those views expressed belong to the third party contributor, and do not necessarily reflect those of Binance Academy. Please read our full disclaimer here for further details. Digital asset prices can be volatile. The value of your investment may go down or up and you may not get back the amount invested. You are solely responsible for your investment decisions and Binance Academy is not liable for any losses you may incur. This material should not be construed as financial, legal or other professional advice. For more information, see our Terms of Use and Risk Warning.