In Simple Terms, What Is Uniswap?
A guide to Uniswap that tells you what it is and how it works. The Uniswap protocol lets buyers and sellers trade ERC20 tokens without using an exchange or order book.
You may have heard of Uniswap, which is a topic that has been talked about a lot in the DeFi space. Hayden Adams first made the Uniswap protocol after reading Vitalik Buterin’s post about the market maker equation X*Y=K, which sparked his interest.
Hayden took a practical approach to the equation and made Uniswap, which is a protocol for providing automated liquidity.
This guide will help you get a grasp on the following ideas:
What does Uniswap mean?
- How does the X * Y = K equation work to make automated liquidity provisioning work?
- How is Uniswap V1 different from Uniswap V2?
- How can you make money by providing liquidity on Uniswap?
- What are the problems with flash swaps (also called “flash loans”)?
Let’s get right into how Uniswap works!
What is Uniswap?
Let’s start with an easy-to-understand explanation of what Uniswap is.
Uniswap is a protocol that lets buyers and sellers swap ERC20 tokens without using an exchange or order book. Uniswap uses an algorithm that figures out the swap rate based on the balances of both tokens and how much demand there is for this swapping pair.
You might wonder why Uniswap is such a big deal. Traditional markets need buyers and sellers to provide liquidity, which is not always easy to do. Even decentralised exchanges (DEX) have this problem because their success depends heavily on liquidity.
Read More: The FBI advises DeFi investors to do this.
Uniswap takes on this problem in a different way by automating the process of providing liquidity. Uniswap makes it possible for a DEX to swap ERC20 tokens without relying on buyers and sellers to create liquidity.
But how does liquidity provisioning that is done automatically work?
How does Automated Liquidity Provisioning work at Uniswap?
How to Understand the “X * Y = K” Equation
In the equation “X * Y = K,” X and Y stand for the number of ETH and ERC20 tokens that are available. While K is a constant that the person who makes the exchange contract on Uniswap can set. K may look like a random constant, but it is the most important. When you multiply X by Y, the number you get must always be the same as K.
Now, let’s look at the graph above. The constant K, which is a function, is shown on the graph. The Y-axis shows the value of token B (ETH), and the X-axis shows the value of token A (ERC20).
Based on the current balance of ETH tokens and ERC20 tokens, the first red dot (old position) shows the current price for swapping this ETH-ERC20 pair.
Alice, on the other hand, decides to trade her ERC20 tokens for ETH.
So, the amount of ETH tokens goes down and the amount of ERC20 tokens goes up. This means that the red dot moves to the new spot because there are more ERC20 tokens in the liquidity pool than ETH tokens. In other words, it’s a very simple pricing algorithm in which the price rate moves along a graph.
Next, it’s important to know that Uniswap V2 has been around since March 23, 2020.
V2 has a lot of new features and updates to features that were already there. Let’s find out what’s different.
Understanding How Uniswap V1 and V2 Are Different
With Uniswap V2, many new features like price oracles, flash swaps, and a swapping router have been added. This last part is the most important for understanding how Uniswap moves tokens from one liquidity pool to another.
Uniswap V1 Swaps
In the blog post about Uniswap V2, we can read about how Uniswap V1 works:
“All liquidity pools in Uniswap V1 are between ETH and a single ERC20 token. A nice user experience (UX) benefit of having a constant numeraire is that users can swap any ERC20 for any other ERC20 by routing through ETH.”
ETH was the best choice for Uniswap V1 because it is the most liquid Ethereum-based asset and doesn’t add any new platform risk.
This means that Uniswap V1 makes two trades every time. First, you trade your ERC20 token for ETH. Then, you trade your ETH back into the ERC20 token you want. In other words, the person who uses the service pays twice.
This posed a couple of limitations on the use of Uniswap:
- Higher fees
- Uniswap strongly tied to the use of ETH
- Not possible to swap ERC20 tokens directly with other ERC20 tokens.
For the above reasons, Uniswap V2 has been created.
Uniswap V2 Swaps
With the “Router Contract,” Uniswap V2 gives end users three different ways to swap their tokens.
Read More:Is Bitcoin Safe To Use?
The Router Contract is just a contract with logic for sending your tokens to the right swapping contract. In other words, every swapping contract that uses the Uniswap V2 protocol is known to the router contract.
Here are the three ways they could switch:
- A straight swap between two pairs of ERC20. For example, traders may find that two stablecoins like DAI/USDC are very useful.
- In a traditional swap using ETH, you pay fees twice.
- Custom path swaps, where you can build a more complex swapping path, such as DAI/ETH, ETH/BAT, BAT/USDT, and USDT/USDC, to change your DAI to USDC. Traders can often find interesting arbitrage opportunities because of this.
How to Make Money by Providing Liquidity on Uniswap?
How does liquidity provisioning on Uniswap help users? The answer is easy: fees for trading. You can join these liquidity pools by giving a Uniswap exchange contract the same number of ETH and ERC20 tokens.
In exchange, people who want to swap have to pay a 0.3% fee per swap. After that, this fee is added to the pool of cash. Then, liquidity providers get a portion of the transaction fee based on how much weight they have in the liquidity pool.
How helpful or dangerous are Uniswap Flash Swaps?
Last but not least, let’s talk about Uniswap V2’s new Flash Swaps feature. In the same blog post, Uniswap says the following about Flash Swaps:
“Uniswap V2 flash swaps let you withdraw as much of any ERC20 token as you want from Uniswap for free, and you can do whatever you want with them (execute arbitrary code) as long as, by the end of the transaction, you:
Pay for all withdrawn ERC20 tokens, pay for some withdrawn ERC20 tokens and return the rest, or return all withdrawn ERC20 tokens.”
All of this sounds very exciting because it makes a lot of new things possible. Max Wolff of Marble Protocol came up with the term “flash swaps” in 2018. It is also called “flash loans.” Back then, he called his idea a “smart contract bank” because it lets people get loans with no risk.
But recently, there have been a lot of flash loan attacks on different protocols like bZx. In these attacks, an attacker gets thousands of tokens for free through flash loans and then runs away with them.
A flash loan attacker takes advantage of differences in prices on different markets, pays back the initial loan, and keeps the extra money they made by trading on those differences.
Some industry leaders say this is a big risk for the DeFi space, but others say flash loan attacks happen because the bZx protocol doesn’t have very good security.
Any way you look at it, Uniswap has decided to use its “flash swaps.” This lets anyone take out as many ERC20 tokens as possible from a liquidity pool. But the user has to give back the tokens within the same block. Or, give the equivalent amount of ETH back to the ETH liquidity pool.
In Conclusion
Automated liquidity provisioning has given the DeFi space a big boost and opened up a lot of new trading opportunities that are more complex. But only time will tell if swaps were good for the cryptocurrency space. Here’s a quick list of the good and bad things about using Uniswap.
Uniswap – The Pros
- Decentralized
- Any new token can directly access liquidity through adding their token for an exchange
- to the Uniswap V2 router contract.
- Low-cost trades compared to a DEX or centralized exchange.
- Liquidity providers can benefit from contributing liquidity to liquidity pools.
Uniswap: The Bad Things
Flash swap attacks could happen
It still uses arbitrage trading to even out the market. But arbitrage trading happens in every natural market to get rid of imbalances as quickly as possible.
Fake token listings.
Because there are so many trades, gas prices are high, which makes trading on Uniswap still more expensive.