Uniswap is a set of computer programs that run on the Ethereum blockchain and allow for decentralized token swaps. It works with the help of unicorns (as illustrated by their logo).
Traders can exchange Ethereum tokens on Uniswap without having to trust anyone with their funds. Meanwhile, anyone can lend their crypto to special reserves called liquidity pools. In exchange for providing money to these pools, they earn fees.
How do these magical unicorns convert one token to the other? What do you need to use Uniswap? Let’s read on.
exchanges have been the backbone of the cryptocurrency
market for years. They offer fast settlement times, high trading volume
, and continually improving liquidity
. However, there’s a parallel world being built in the form of trustless
protocols. Decentralized exchanges (DEX)
require no middlemen or custodians to facilitate trading.
Due to the inherent limitations of blockchain
technology, it has been a challenge to build DEXes that meaningfully compete with their centralized counterparts. Most DEXes could improve both in terms of performance and user experience.
Many developers have been thinking about new ways to build a decentralized exchange. One of the pioneers of this is Uniswap. The way Uniswap works may be a bit more difficult to understand than a more traditional DEX. However, we’ll soon see that this model brings some attractive benefits.
As a result of this innovation, Uniswap has become one of the most successful projects that’s part of the Decentralized Finance (DeFi)
Let’s see what Uniswap is, how it works, and how you can swap tokens on it simply with an Ethereum wallet
Uniswap is a decentralized exchange protocol built on Ethereum
. To be more precise, it is an automated liquidity protocol
. There is no order book
or any centralized party required to make trades. Uniswap allows users to trade without intermediaries, with a high degree of decentralization and censorship-resistance
Uniswap is open-source software
. You can check it out yourself on the Uniswap GitHub
Ok, but how do trades happen without an order book? Well, Uniswap works with a model that involves liquidity providers creating liquidity pools. This system provides a decentralized pricing mechanism that essentially smooths out order book depth
. We’ll get into how it works in more detail. For now, just note that users can seamlessly swap between ERC-20 tokens
without the need for an order book.
Since the Uniswap protocol is decentralized, there is no listing process. Essentially any ERC-20 token can be launched as long as there is a liquidity pool available for traders. As a result, Uniswap doesn’t charge any listing fees, either. In a sense, the Uniswap protocol acts as a kind of public good.
The Uniswap protocol was created by Hayden Adams in 2018. But the underlying technology that inspired its implementation was first described by Ethereum co-founder, Vitalik Buterin.
Uniswap leaves behind the traditional architecture of digital exchange in that it has no order book. It works with a design called Constant Product Market Maker, which is a variant of a model called Automated Market Maker (AMM).
Automated market makers are smart contracts
that hold liquidity reserves (or liquidity pools) that traders can trade against. These reserves are funded by liquidity providers. Anyone can be a liquidity provider who deposits an equivalent value of two tokens in the pool. In return, traders pay a fee to the pool that is then distributed to liquidity providers according to their share of the pool. Let’s dive into how this works in more detail.
Liquidity providers create a market by depositing an equivalent value of two tokens. These can either be ETH and an ERC-20 token or two ERC-20 tokens. These pools are commonly made up of stablecoins
such as DAI, USDC, or USDT, but this isn’t a requirement. In return, liquidity providers get “liquidity tokens,” which represent their share of the entire liquidity pool. These liquidity tokens can be redeemed for the share they represent in the pool.
So, let’s consider the ETH/USDT liquidity pool. We’ll call the ETH portion of the pool x and the USDT portion y. Uniswap takes these two quantities and multiplies them to calculate the total liquidity in the pool. Let’s call this k. The core idea behind Uniswap is that k must remain constant, meaning the total liquidity in the pool is constant. So, the formula for total liquidity in the pool is:
x * y = k
So, what happens when someone wants to make a trade?
Let’s say Alice buys 1 ETH for 300 USDT using the ETH/USDT liquidity pool. By doing that, she increases the USDT portion of the pool and decreases the ETH portion of the pool. This effectively means that the price of ETH goes up. Why? There is less ETH in the pool after the transaction, and we know that the total liquidity (k) must remain constant. This mechanism is what determines the pricing. Ultimately, the price paid for this ETH 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 linearly. In effect, the larger the order is, the more it shifts the balance between x
. This means that larger orders become exponentially more expensive compared to smaller orders, leading to larger and larger amounts of slippage
. It also means that the larger a liquidity pool is, the easier it is to process large orders. Why? In that case, the shift between x
The technology behind Uniswap has seen several iterations so far. Chances are, if you’ve used Uniswap, you used Uniswap v2. However, there are always new improvements in the pipeline. Let’s go through the most impactful updates brought forth by Uniswap v3.
One of the most significant changes coming with Uniswap v3 relates to capital efficiency. You see, most AMMs are very capital inefficient – that is, most of the funds sitting in them at any given moment are not being used. This is due to an inherent characteristic of this x*y=k model discussed earlier. In a simplified way, the more liquidity there is in the pool, the bigger orders the system can support in a larger price range.
However, liquidity providers (LPs) in these pools essentially provide liquidity for a price curve (range) between 0 and infinity. All that capital is sitting there reserved for the scenario when one of the assets in the pool 5x-s, 10x-s, 100x-s.
If that happens, those idle assets ensure that there’s still liquidity left on that part of the price curve. This means that only a small portion of the liquidity in the pool is sitting where most of the trading happens.
As an example, Uniswap currently has about 5B dollars of liquidity locked, while it does only about 1B of volume per day. You might think this isn’t a particularly elegant way of doing things, and it appears that the Uniswap team agrees. Uniswap v3 addresses this issue.
Liquidity providers can now set custom price ranges for which they want to provide liquidity for. This should lead to more concentrated liquidity in the price range that most trading activity happens in.
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 the price ranges they set. It’s worth noting that this change favors professional market makers over retail participants. The beauty of AMMs is that anyone can provide liquidity and put their funds to work.
However, with this additional layer of complexity, “lazy” LPs are going to earn much less in trading fees than professional players who can constantly keep optimizing their strategy. At the same time, it’s not hard to imagine aggregators like yearn.finance
offering retail LPs a way to remain somewhat competitive in this environment.
Uniswap LP tokens as NFTs
We now understand that each Uniswap LP position is unique since each depositor can set their own price range. This means that Uniswap LP positions are not fungible anymore. As a result, each LP position is now represented by a non-fungible token (NFT)
One of the advantages of representing a Uniswap LP position with a fungible token was how it could be used in other parts of DeFi. Uniswap v2 LP tokens could be deposited into Aave
as collateral. This is no longer the case with v3 since each position is unique. However, this break of composability may be solved with new types of derivative products.
Uniswap on layer 2
Transaction fees on Ethereum have skyrocketed in the last year. This makes using Uniswap economically nonviable for many of the smaller users.
Uniswap v3 will also be deployed on a layer 2
scaling solution called an Optimistic rollup. It’s a neat way to scale smart contracts while still getting security from the Ethereum network. This deployment should lead to a massive increase in the transaction throughput and much lower fees for users.
As we’ve discussed, liquidity providers earn fees for providing liquidity to traders who can swap between tokens
. Is there anything else liquidity providers should be aware of? Yes. There’s an effect called impermanent loss
Let’s say that Alice deposits 1 ETH and 100 USDT in a Uniswap pool. Since the token pair needs to be of equivalent value, this means that the price of ETH is 100 USDT. At the same time, there’s a total of 10 ETH and 1,000 USDT in the pool – the rest funded by other liquidity providers just like Alice. This means that Alice has a 10% share of the pool. Our total liquidity (k), in this case, is 10,000.
What happens if the price of ETH increases to 400 USDT? Remember, the total liquidity in the pool has to remain constant. If ETH is now 400 USDT, that means that the ratio between how much ETH and how much USDT is in the pool has changed. As a matter of fact, there is 5 ETH and 2,000 USDT in the pool now. Why? Arbitrage traders will add USDT to the pool and remove ETH from it until the ratio reflects the accurate price. This is why it’s crucial to understand that k is constant.
So, Alice decides to withdraw her funds and gets 10% of the pool according to her share. As a result, she gets 0.5 ETH and 200 USDT, totaling 400 USDT. It seems like she made a nice profit. But hang on, what would have happened if she didn’t put her funds in the pool? She’d have 1 ETH and 100 USDT, totaling 500 USDT.
In fact, Alice would have been better off by HODLing
rather than depositing into the Uniswap pool. In this case, the impermanent loss is essentially the opportunity cost of pooling a token that appreciates in price. This just means that by depositing funds into Uniswap in hopes of earning fees, Alice may lose out on other opportunities
Note that this effect works regardless of what direction the price changes from the time of the deposit. What does this mean? If the price of ETH decreases compared to the time of the deposit, the losses may also be amplified. If you’d like to get a more technical explanation for this, check out Pintail’s article
But why is the loss impermanent? If the price of the pooled tokens returns to the price when they were added to the pool, the effect is mitigated. Also, since liquidity providers earn fees, the loss may get balanced out over time. Even so, liquidity providers need to be aware of this before adding funds to a pool.
It doesn’t. Uniswap is a decentralized protocol that doesn’t have a native token
. All fees go to liquidity providers, and none of the founders get a cut from the trades that happen through the protocol.
Currently, the transaction fee paid out to liquidity providers is 0.3% per trade. By default, these are added to the liquidity pool, but liquidity providers can redeem them at any time. The fees are distributed according to each liquidity provider’s share of the pool.
A portion of fees may be dedicated to Uniswap development in the future. The Uniswap team has already deployed an improved version of the protocol called Uniswap v2.
Uniswap is an open-source protocol, meaning that anyone could create their own frontend application for it. However, the most commonly used one is https://app.uniswap.org
- Go to the Uniswap interface.
- Connect your wallet. You can use MetaMask, Trust Wallet, or any other supported Ethereum wallet.
- Select the token you’d like to exchange from.
- Select the token you’d like to exchange to.
- Click on Swap.
- Preview the transaction in the pop-up window.
- Confirm the transaction request in your wallet.
- Wait for the transaction to be confirmed on the Ethereum blockchain. You can monitor its status on https://etherscan.io/.
UNI is the native token of the Uniswap protocol, and it entitles its holders to governance rights. This just means that UNI holders can vote on changes to the protocol. We’ve discussed earlier how the protocol has already been acting as a sort of public good. The UNI token solidifies this idea.
1 billion UNI tokens have been minted at genesis. 60% of those are distributed to existing Uniswap community members, while 40% will be made available to team members, investors and advisors over the course of four years.
Part of the community distribution happens through liquidity mining. This means that UNI will be distributed to those who provide liquidity to the following Uniswap pools:
But who are Uniswap community members? Well, any Ethereum address that has interacted with the Uniswap contracts. Let’s see how you can claim UNI tokens.
If you’ve used Uniswap, you can likely claim 400 UNI tokens per address that you used Uniswap with. To claim your tokens:
Connect the wallet that you previously used Uniswap with.
Click on “Claim your UNI tokens”.
Confirm the transaction in your wallet (you can check the current gas prices at the Ethscan Gas Tracker
Congratulations, you’re now a UNI holder!
Want to trade your UNI tokens? Binance has you covered.
Uniswap is an innovative exchange protocol built on Ethereum
. It allows anyone with an Ethereum wallet to exchange tokens without the involvement of any central party.
While it does have its limitations, this technology may have some exciting implications for the future of trustless
token swapping. Once Ethereum 2.0 scalability solutions
go live on the network, Uniswap could likely benefit from them as well.
Do you still have questions about token swaps and DeFi? Check out our Q&A platform, Ask Academy
, where the Binance community will answer your questions.