Uniswap V3 Pt.1
A protocol overview and its math with some commentary on potential applications
A Technical Overview
Uniswap V3 has now been out for months and has quickly dominated the DEX market, but I believe we are still in early stages for the potential that this DeFi protocol, primitive, and paradigm. Uniswap has innovated with every iteration and brought forth technology and applications that have not been replicated anywhere else before. This means the features of the protocol don't have a history in TradFi or elsewhere to give us examples of uses and applications to build off of. This makes UniV3 represent a new primitive that is only possible in Web3 and is teeming with potential.
In this series I will focus on how users can make the most of this protocol with this first post being a broader introduction to its mechanics.
Efficiency is key
Concentrated liquidity is the big innovation of V3 and has greatly increased the efficiency on both sides of the DEX market: the traders swapping assets and liquidity providers earning fees on those swaps by providing their capital as liquidity. Formerly one would deposit liquidity to a pool for a pair of assets and that liquidity would be spread from 0 to ∞ on the constant product graph I'm sure you've seen before here.

Swapping from one asset to another was simple, but depending on the depth of the pool your swap could move the price quite significantly. This is fine when smaller users are swapping assets (but beware of gas fees) but is not acceptable for whales to swap large amounts in a short period of time. This led to centralized exchanges and OTC (Over The Counter) desks to retain significant market share as doing large swaps on chain was just not feasible. For that matter neither were small swaps once gas fees were factored in, but Uniswap going L2 has mediated that issue significantly.
The innovation in V3 is the ability to deposit liquidity only in a specific range, greatly increasing the capital efficiency of the Uniswap TVL. LPs now provide their capital only within a specific range which usually follows a normal distribution around the current price. Here is a visualization from metacrypt.org.

This capital efficiency obviously helps anyone looking to swap tokens as these liquidity ranges mean swaps with have significantly less price impact and can be done at much larger sizes. What it also helps are liquidity providers receive much higher returns for providing liquidity to this pool. Since your liquidity is now specified within a range, you inherently are providing much more liquidity to receive the swap fees when the price is within your set range. Additionally, the lack of price impact for traders has made volume on each pool has explode, and now you now have more transactions to pay swap fees.
Liquidity Providers only earn those fees when the price is within their given range, but when the price is in those ranges it is pretty friggin' sweet. Since fees are distributed based on the proportion of liquidity that you are providing a position of WETH/DAI with bounds at $1500 and $1800 would garner much more fees than the same position between $1000 and $2300. But how would we figure out the fees we could get? Or know what ranges to input as a Liquidity Provider? Let's dig in deeper.
Math is a really cool thing
Ok, that was the overview, now get off your ath let's do some math. In Uniswap V3 a liquidity position has a variable to represent how much liquidity they are providing. There is an and an , one for each asset in the pool, but when the price is in range, we can consider these to be equal (technically it is the minimum of the two). The following are the equations for and .
The values and represent the upper and lower bounds of the range you set, is the current price and the values are for the amounts of the two different assets in the pool.
Now that we know how to calculate the liquidity we’re providing let’s find the fees!
For every swap fees are taken according to the fee tier and then distributed among the active liquidity providers in proportion to the amount of liquidity they provide over the total. To get daily fees you could use this equation:
Where is the fee percentage, daily volume, user’s liquidity, and total liquidity.
Let's use some real values now for the USDC/WETH pool, the most liquid on Uniswap.
As of this writing on September 10th ETH is $1733 and we will look at volumes and liquidity for the 5 basis point fee pool (0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640) on September 9th for a full day of volume along with the current liquidity.
In our example let's say we deposit $1000 in value in the form of 500 USDC and 0.286 WETH. We'll set our upper bound to equate to a 25% move at 2165 USDC per WETH and our lower bound at 1388.6 USDC per WETH. These bounds allow us to deposit equal values of USDC and WETH; your ratios of each asset move within your range according to the liquidity of each but covering that would be some math overload and you don't have time for that.
Now hang on, we're going to do some funny conversions based on the way Uniswap does its ordering, its “tick” creation, and its preservation of integers to avoid Float math. We have to do this in order to compare the provided liquidity to the contract quoted liquidity number. If we were doing only hypothetical scenarios we wouldn't have to do this.
Firstly, the order of assets in this pool are USDC in the 0 index and WETH as the 1 index so the price is the USDC/WETH which is just the inverse of the current price and then with the scientific notation of the amount of decimals to make it an integer, so the price is now as follows:
The upper and lower bounds change to tick integers which are described in the whitepaper but are just prices represented as an integer of tick size like this and with a reversed direction, so the ticks are now as follows:
Using the above equations gives:
Accounting for some imprecision we get very slightly different answers which is to be expected given we didn't use real tick prices as inputs, but now taking the minimum we can find the daily fees. Our pool has a total liquidity of given from the contract here, a USDC volume of and a WETH volume of (wowza). The volume for trades is half of the total volume of each side (since you only pay on one side of the trade) so we will take the $482,559,497 as our volume
That gives us the following for daily fees:
So $0.53 a day on $1000, annualized that's a 21.3% APY. Not too shabby.
What if we narrowed the liquidity we were providing to bounds of 1600 and 1880? Following the same math we now have an of 302103972567312 and with our DailyFees equation we would get $1.41 per day for an annualized return of 67%! Note too that this is not autocompounding, Uniswap fees are collected manually where you could then choose to redeposit, so this could be even higher.
Too good to be true?
Does this sound too good to be true? Well yeah, it kind of is. That's because your fees are only collected when in the range you set. And your ratio of your deposit changes depending on how close the current price is to your bounds and as the price moves away from the middle you acquire more of the less valuable asset.
Ok that's a significant damper on what was appearing to be a super lucrative concept. But therein lays the opportunity. While Uniswap V2 was great for passive investors depositing their assets and then not having to think about or manage their position, even for reinvesting returns, Uniswap V3 introduces a lot of complexity (if you didn't get that from the math) but improves efficiency and opens more features for opportunity while requiring more active management.
But the potential!
There are opportunities for active rebalancing based on price movements, or for users to make price predictions in their LP positions. Allowing single sided liquidity for bounds outside the current price allows users to essentially do limit orders by using narrow outside of the money bounds with benefit of collecting fees while the order is filled rather than paying them. The price dynamics of providing liquidity also closely resemble selling at the money puts which is something Guillaume Lambert has spoken about.
Interoperability
And here is the best part. As a web3 permissionless protocol, anyone can call these function. That means someone could set up their own protocol that pools funds and actively moves liquidity to always be in range with reinvesting fees. Or a protocol when you input some of Guillaume's flowchart and it makes a position for you. The potential is limitless for others to buidl and create financial products that you want to see. No approvals to trade options from a bank where you pay them for the privilege of providing liquidity. Or there could be a system for complex directional bets with hedging where you don't need a personal connection at Goldman Sachs and $100M in assets to get access to. This is a new financial paradigm and we're in early days of what is possible with Uniswap V3. Before we even think about what V4 could have in store for us.
Next time on Dragon Ball Z this blog
Instead of daydreaming about what others could build I put together a python function to simulate Uniswap V3 LP positions so we can backtest and get a more visual perspective on how to position our assets and see where and how LPing would be a good decision. Until next time!