Uniswap V3.
Welcome, premium subscribers! Thank you for subscribing. I appreciate you very much.
TLDR below. This is not financial advice.
Catch the episode on YouTube
General Conclusion
Uniswap is an Ethereum-based decentralised exchange (DEX), where people can trade between with ERC-20 tokens entirely onchain using smart contracts. It eliminates order books and is an interesting feature compared to centralised exchanges (CEXs).
The main innovations from the Uniswap protocol are the development of a user-friendly platform on which traders can easily swap tokens, while at the same time enabling anyone to be a provider of liquidity and earn passive income through transaction fees.
How does Uniswap Work?
The Uniswap protocol does things differently to CEX. It allows users to trade ERC-20 tokens without the need for a middleman. As well as helping to reduce fees, this can iron out some thorny issues concerning censorship.
Source: Uniswap.org
Uniswap is a 100% decentralised and permissionless protocol, operating on the following formula: xy=k (called “constant product”)
In which:
-
x is amount token X;
-
y is amount token Y;
-
k is a constant
Uniswap provides an environment for the parties (Liquidity provider, trader, arbitrageurs and developer) to trade and develop.
Liquidity Providers (LPs) provide liquidity by depositing Erc-20 tokens into the pool and they receive LP token back as a certificate of ownership of a portion of this pool. After a while, they will be paid with the pool’s transaction fees.
Traders participating in trading must pay a fee for each transaction. This fee is stored in the pool and paid to the LP.
Arbitrageurs align the price difference between the internal market and external markets.
For example
The pool created is ETH/DAI with 10 $ETH and 1000 $DAI. We have:
x * y = k ⇔ 10 * 1000 = 10,000. And 1 $ETH = 100 $DAI and 1 $DAI = 0.01 $ETH.
Case 1: Swap DAI for ETH.
Trader A enters this pool and swaps 500 $DAI + 0.3% fee to exchange it for $ETH.
⇒ y1 = 500 + 1000 = 1500 $DAI.
k is const ⇒ x1 = k / y1 = 6.66 $ETH.
The trader receives x – x1 = 10 – 6.66 = 3.33 $ETH, which is worth 500 $DAI.
⇒ 1 $ETH = 150.15 $DAI, increase 50.15% from the initial price.
Note: 0.3% fee will be added back to the pool after swapping and changes the value of k.
Case 2: Swap ETH for DAI.
Trader B sells 6 $ETH in exchange for $DAI.
⇒ x1 = 10 + 6 = 16.
⇒ y1 = 10,000 / 16 = 625.
It follows that the trader gets y – y1 = 1000 – 625 = 375 $DAI, which is worth 6 $ETH.
⇒ 1 $ETH = 62.5 $DAI, 37.5% decrease from the initial price.
Note: If the slippage is too large, Uniswap will issue a warning before you swap to display a notification.
New Price Each Token
The price of the token is determined after a change in reserves. This means the current transaction price is the price of the token which is redetermined at the previous transaction.
The token price in re-calculated. Hence,
New Price of $X Token = ∆y/∆x.
In Case 1: New 1 $ETH = |y1-y| / |x1-x| = 500/3.33 = 150.15 $DAI.
K for Constant
Trading in terms of quantity
The constant is defined by the number of LISA tokens and ETH (the two different assets). You multiply their total quantity together and that’s the constant where one goes down the other goes up and that’s how you trade with each other.
Price:
From the price perspective, they’re always priced relative to each other. If my decentralised exchange has the LISA token and the ETH token then the price of LISA is priced in ETH and the price of ETH is priced in LISA tokens**.**
Constant:
The constant is always the same and the constant is a multiplication of the quantity of LISA and quantity of ETH and so to get the quantity of whatever you just move the math around and this is where the problem comes.
But it’s no perfect! What’s The Problem?
Uniswap V3: Decentralised Market Maker + CLOB
CLOB = central limit order book. That’s the NASDAQ style trade.
The problem in V1 and V2 is that you’ve got slippage on large trade and greater chances of impermanent loss. That’s what Uniswap V3 trying to change and improve. Uniswap V3 mixes decentralised market makers with central limit order books. Decentralised market maker is the general thing that you see all the time which is these transactions.
If you go to Uniswap trade, you see the transactions where people are swapping wETH to USDC or USDC to wBTC. This is the trade. Instead of having the buyer side and seller side you’re just trading for each other within the pool so you’re trading with the contract.
In the CLOB method, you can see the red and the green in the order book. The red are people selling at what price and the green is the price that people are selling it. People are just writing in the price like I want to sell it at this price or I want to buy at this price. It lists down and unlike Uniswap where it trades against the pool it’s just listed over there and based on the price users want to buy and sell at the machines will pair them up.
Uniswap’s trying to take these two worlds together and put them in the version three ecosystem defined with code.
7 Changes in Uniswap V3
1. Focused Liquidity
In the CLOB method I can define the price that I want to buy at so let’s say 500 bucks and I can also define to trade only in a specific range of 499 and 501. In stable coins for instance it’s more or less $1 and your risk tolerance is 1%.
You can tell the smart contract and Uniswap V3 to say that this is a DAI and USDC pool and I only want to provide liquidity or the range of $0.99 and $1.01 which makes sense because it’s a stable coin.
If you look at the graph that range is the shaded area under the box. This is how you do the calculation.
Benefits
-
You have capital only in the specific range which is good because you’re only providing capital within the range that you’re confident in and you know prices won’t deviate too much.
-
You’re concentrating your depth within a range. It becomes quite useful because we’re going to make the pool very deep with a lot of tokens available. If the pool is very large, your large trade might not be so significant and there wouldn’t be a large slippage.
2. Capital Efficiency
Back to the pegged stable coin $1 example. If you’re providing liquidity outside of the $1, say $2, that capital is not working for you. Because as a liquidity provider, you only want to provide liquidity where people will be trading at because then you will get shares of the transaction fees and get to earn profits. Allocating your capital where people won’t be trading ($2 range) makes it inefficient.
For LP: Uniswap is providing more capital efficiency. You get to earn more fees by providing liquidity in the range that you’re comfortable with.
For traders: The good thing for the traders is that you get less slippage. Because when you have very deep liquidity for this range then your large trade will have less slippage. The large trade is proportionately smaller when the liquidity pool is huge.
3. Price Discovery
We are combining central limit order books with decentralised exchanges and sophisticated traders to provide liquidity to specific ranges. There are some ranges where you can technically have no liquidity because nobody is going to trade DAI for two USDC since it’s too expensive and that’s what price discovery is about.
When the market aggregates information together, it doesn’t price USDC at two dollars worth when USDC is really only worth one dollar. That’s a way to understand price discovery because not only are you just trading with the contract itself but you’re able to dictate what segments or range you want to trade at.
I might not be a sophisticated investor and might not understand a lot of information that I didn’t research on. But someone else does that and they provide liquidity within a specific range that I didn’t realise. That gives me more information and I can go and read more about the things that I need to research about so that’s a very interesting way for price discovery.
4. Range Orders
You will only be providing liquidity in the specific range that you select. Let’s say I’ve got ETH and LISA tokens in the pool and I’m providing within a particular range. When the price goes out of range, one of my assets will be completely liquidated to turn into the other asset. In this case, if my ETH goes out of range then all of ETH will be liquidated and changed to LISA tokens.
It’s kinda like a stop loss. Or a put option.
5. Non-Fungible Liquidity
The liquidity providers positions are now non-fungible. If I only want to provide liquidity within specific ranges then my LP tokens for the LISA-ETH pool will be different from your LISA-ETH pool LP tokens because we’re providing liquidity at different ranges. Hence we will receive different kinds of token transactions so it’s non-fungible. It is also quite useful because maybe in the future we can use that LP tokens as collateral to be borrowing in other protocols.
6. Flexible Fees
The value adds for Uniswap as a platform is that it always allows people to trade at any price and to do that you can customize your fees. You can do it at 0.05%,0.3%, or 1% so you get to choose the fees. The fees can change depending on the risk taken. For example, when things are super volatile, you want to incentivize the liquidity providers to provide liquidity into the pool. You can compensate them by giving them higher fees.
Example: The USDC vs DAI pool will have a much lower risk because it’s not that volatile as compared to the ETH and DAI pool because ETH could be quite volatile so those two different pools will have different fee structures.
7. Advanced oracle
A lot of different DeFi protocols are using Uniswap as the price oracle for their projects. Uniswap as an oracle is the price input for many protocols, so it’s looking to improve the oracle. Previously it was the total weighted average price on a per-second basis to protocols but today you’re able to compute them up to about nine days and because it’s built on ETH version two it’s a lot cheaper and more accurate to be transacting when you’re using Uniswap as the price oracle.
TLDR:
Uniswap V3 combines the benefits of a standard AMM with those of an asset-stable AMM, plus other functions that make using capital more efficient. This makes V3 a super flexible protocol that can accommodate a wide variety of assets.
Uniswap V3 can change the game on AMM. It also poses many problems for related projects. Of course when the problem is solved, it is the opportunity!
Ps: Order the textbook “Economics and Math of Token Engineering and DeFi” today!