Ultimate Guide to Uniswap and How it Works
Table Of Interest
Looking for a perfect guide for Uniswap, then “Ultimate Guide to Uniswap and How it Works ” is for you.
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.
Centralized 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) movement.
What is Uniswap?
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.
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.
How does Uniswap work?
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 and y. 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 and y is smaller.
What is impermanent loss?
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 about it.
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.
How does Uniswap make money?
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.
How to use Uniswap
- 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/.
The Uniswap (UNI) token
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.
How to claim Uniswap (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:
Go to https://app.uniswap.org/.
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.