Uniswap is the one of the world’s largest permissionless Distributed Exchange (DEX) on Ethereum by volume. After weeks of breathless anticipation, Uniswap has launched its new sophisticated product, Uniswap v3. In this article we’ll explore the exciting changes that were introduced, introduce some new terms, and help users understand the protocol to make good decisions.
While Uniswap v2 prioritized low risk and accessibility, v3 puts capital efficiency front and center, and the UI offers these options when making the trades. However, the additional features increase the complexity as we will explore.
Let’s understand this together as friends, from the viewpoint of “Alice” and “Bob”. Alice is a Uniswap v2 user and Bob is a Uniswap v3 user and both have $100,000 in their pockets for investment. They have decided to invest in the ETH/DAI pool. Let’s dive into the questions that come to mind: how they perceive the pool dynamics and some of the basis of their decisions to highlight the differences.
There are some parameters to consider for ETH/DAI pool at first glance to gain some insights about the current situation.
How can Alice and Bob provide liquidity to these pools?
What would be some things they need to be aware of while providing liquidity?
The first half of this article dives into the mathematical equations that govern the platform and the second half provides insight into how this exposes the user to more risk.
Alice wants to provide $100,000 worth of liquidity to the ETH/DAI pool. For that Alice needs to have a certain amount of ETH and DAI. In v2, when providing liquidity you must add the tokens in such a ratio that they have equal dollar amounts.
Alice doesn’t need to calculate the ratio herself, the v2 interface manages it for her: 1 ETH = 3784 DAI. If she deposits 1 ETH, she will also have to deposit 3784 DAI for the equal ratio in this pool.
There are two transactions, and thus two gas costs to consider when adding liquidity to a pool: approving your wallet to be accessed by the ETH/DAI Uniswap v2 smart contract and moving the liquidity from your wallet to the smart contract itself.
When Alice adds liquidity, she gets a relative position in the pool, in this case about 0.0625% of the pool ($100,000 out of the pool’s total 159.806m). She’ll earn that percentage of all swap fees, which in Uniswap v2 is 0.3% of all swaps.
Whenever someone makes a ETH-DAI or DAI-ETH swap, her liquidity represents 0.0625% of the total liquidity, and thus she earns that percentage of the swap fee, which in Uniswap v2 is 0.3% of the swap. She earns fees on a simple volume based ratio, irrespective of the price of the tokens. When Alice earns liquidity fees, it is added back to the pool via liquidity tokens, compounding Alice’s liquidity position. When Alice is satisfied with her earnings she can remove them when she sees it fit.
Alice has had fun on v2, so she calls Bob, to see how his V3 experience is going.
Bob also has $100,000 to invest in his v3 pool. He likes Alice’s liquidity strategy, and wants to invest equal parts ETH and DAI and earn 0.3% liquidity fee. Well, life has changed for Bob in v3 and this is no longer a set-it-and-forget-it platform. Buckle up, Bob!
In order to increase capital efficiency abilities, v3 introduces concentrated liquidity. This allows for greater returns - but at the cost of complexity. Not only does Bob have to select the tokens (ETH & DAI) he wants to provide liquidity for, but also the range of prices for those tokens.
Before Bob starts understanding V3, he has to understand the concept of concentrated liquidity. Since V3 allows the user to set their own price range, we have to understand how these price ranges are represented. Uniswap V3 introduces the concept of Ticks to accomplish this. Ticks are a way to express a range of prices that the tokens can be between. Ticks are integers so some math needs to be done to calculate the tick range he wants to provide liquidity for.
Bob needs to identify where the current price is represented on this number line. Each number on this number line represents a tick, that is just a representation of the value of sqrt(P). Bob needs to invest his assets as a range of ticks around the current tick. How does he calculate the tick based on current price and vice versa? Uniswap has given a formula to do that.
Calculating current tick based on sqrt(price)
Calculating price based on current tick
We need to calculate the liquidity range and square root of P, in order to do so, we need to consider our variables. Amount of DAI (y), Amount of ETH (x), and Liquidity (L) and Price (P).
Liquidity is calculated by taking the square root of x * y. In this case 187816.08
Price of the Position is calculated by taking the square root of y / x. In our case 54.1
The current tick value for this price is: 2932, It’s an integer because of the floor function.
It is very important to visualize your liquidity in a range interval as a combination of parts of liquidity within consecutive ticks, e.g. If you are providing liquidity from tick 7 to tick 10 of the pool this should be visualized as:
(tick7 > tick8) + (tick8 > tick9) + (tick9 > tick10) + (tick10 > tick11)
This visualization of position as combinations of small positions help understand some key points usually missed.
As long as the price is within two ticks, the lower tick is used as a representation of price. If the actual price either goes below lower tick or above upper tick after a swap, the reported price changes; otherwise although liquidity may change some amount, price remains pegged to the lower tick.
This tick is like a marker for Bob. Based on current pool prices, the price is at 91506 tick, so Bob will have to carefully think about creating liquidity around this tick.
Since the number line covers all integers, Uniswap v3 uses the concept of discrete tick spacing so that now all ticks are tracked. For example, a tick spacing of 2 will allow only integers such as -4, -2, 0, 2, 4.
Before Bob can make his position, he must understand
Bob’s liquidity is no longer in a range of [0, inf). He also realizes that non-symmetrical positions make for different token ratios. He can set his own range in which he wants to invest. This creates a virtual interval of liquidity.
As an example, if ETH is trading at $4,300, Bob decides to set the interval of his investment from $3,500 to $5,900.
Bob buys the ETH and DAI tokens to amount to a total $50,000 in equal amounts. In this case $3,500 would represent lower bound of interval and $5,900 would represent upper bound of interval.
As price moves in this interval, the provided tokens get converted from ETH => DAI or DAI => ETH depending on the price curve. When the current price approaches either lower or upper bound of this order, he ends up with either only ETH or only DAI. In this case, he can either withdraw his position or wait for the price to come back in range. This is explored later in this article.
This is going to help Bob understand the effect of a swap order on the price. As, now the whole swap is executed as multiple small swaps, i.e. if swap is going to move the price from tick 7 to tick 9 which actually means moving the price from $P1 to $P2, the whole volume of swap is done as:
Total Volume of SWAP (Tick 7 -> Tick 9) = Volume of SWAP (Tick 7-> Tick 8) + Volume of SWAP (Tick 8 -> Tick 9)
Bob earns the percent of capital provided by Bob between ticks 7 and 8, plus the percent of capital provided by Bob between ticks 8 and 9, times the fees collected from the trade in those ranges.
This makes Bob’s position more capital efficient than Alice’s. Now his liquidity is not calculated against total liquidity, but rather calculated as accumulation of volume ratio within his price ranges. Hence, as long as the price stays in his chosen range, he ends up making more money than he would have in v2 from the same initial investment amount.
This is very important to understand because now the fees that you are going to make by providing liquidity is going to be calculated based on these ticks.
Bob is an adventurous trader and he wants to create multiple intervals with his investment divided partially into each one of them. Basically, Bob wants his $100,000 to be divided in multiple custom ranges of liquidity, e.g. $10,000 into $4,000 to $4,500 price of ETH, $50,000 into $3,500 to $4,400 and the rest of $40,000 into $5,000 to $6,000. These ranges may/may not overlap. The V3 whitepaper has presented such representation in their work.
If the current price or current tick is within your price/tick range, then your liquidity is considered active, and you are collecting fees If it’s not within your range, it's inactive.
You may either wait for the current price to be within your interval or change your liquidity range so that the current price falls within the range provided, but rebalancing your position frequently may lead to huge losses.
You can read more about it in this article. (https://reuptake.medium.com/liquidity-providing-in-uniswap-v3-2-5e24af7c346c)
This brings up the concept of impermanent loss. In V2, as the price of an asset went up, an LP would miss out on profit as the ratio of asset 1 to asset 2 shifts in favor of the less valuable asset.
An example would be DAI/ETH. If ETH = 100 DAI and I add liquidity to DAI/ETH in v2 with $10000 DAI and 100 ETH for a total value of 20,000 DAI. I would be losing profits in the case where ETH rises. Since i own a percentage of the pool and not the assets themselves, if ETH doubles and hits 200 DAI, my position in the pool goes from 100 ETH to 71 ETH and 10000 DAI to 14142 DAI for a total of 28284 DAI. If i had simply held my ETH and DAI in a wallet, my total value would be 30000 DAI. Thus, I suffered an impermanent loss of 1716 DAI. My only hope is that enough volume occurred that I made up for the loss via fees.
How does V3 solve this? Well...it doesn’t really.
With V3, if the price of ETH falls outside of my configured price range, all my ETH is converted to DAI. If ETH hits a new all time high, how does that help me? As we’ve explored, I have the ability to distribute my 20000 DAI/ETH across several price ranges, earning fees as the price goes into each range and protecting myself against IL by distributing the volatile asset (ETH in this case) to multiple tranches. There is also a feature called a range order which is best explained by Yitaek Hwang:
“[An] LP can deposit a single asset in a custom range outside the current price. Once the market price enters this range, the original asset is sold for the other pair while earning swap fees in the process. This strategy can complement market orders for profit taking or buying the dip.”
Since we know that Bob can provide less total liquidity than Alice to earn the same amount of fees, he can then take his remaining capital to set up a range order in which he converts ETH to DAI at a higher price to realize at least some of the gains he missed out on due to impermanent loss.
What have we learned?
Now after going through the Credmark Uniswap V3 class, Bob is ready to invest his liquidity. But one question remains: “How do I choose the intervals to make the most money and minimize my downside?”Well that’s a matter for another post.
Bob has the tools to answer that himself. He understands Ticks, Active Liquidity, Capital Efficiency on Swaps, Impermanent Loss and Range Orders. He now has the ability to build a risk diversified portfolio within one asset pool. Meaning, if Bob has a particularly strong understanding of the ETH/DAI volatility as well as the dynamics of V3’s new features, he can build a fully risk adjusted portfolio simply by having those 2 assets, saving himself time and the resources needed to convert to additional assets. Easy enough!
After looking at the thoughts and learnings of Alice and Bob, we hope you now have a deeper understanding of Uniswap v3. If you have any feedback or comments, please provide them in the comments section. Happy Learning!
1. Uniswap V3 whitepaper (https://uniswap.org/whitepaper-v3.pdf)
2. Uniswap V3 architecture - Finematics (https://www.youtube.com/watch?v=Ehm-OYBmlPM)
3. Uniswap V3 docs - (https://docs.uniswap.org/)
Sign up for our newsletter for the latest product updates, partnerships, and more.
Sign up for our newsletter for the latest product updates, partnerships, and more.