Written by: MVP Workshop

Uniswap v3 Explained – All You Need to Know


DeFi summer and decentralized exchanges have disrupted the state of the financial world. No KYC, no boring procedures, no downtime and absolute freedom to do whatever you want. All this brought millions of users to DeFi. Uniswap, one of the world’s most popular DEXs, is one of the leaders in the race to surpass centralized institutions. After getting to one of the highest TVLs among all DeFi projects, the Uniswap team announced they will be launching a new version of this famous DEX – Uniswap v3.

So what’s new in Uniswap v3?

They are introducing a lot of new features, more decentralization, better security but they are also trying to address the urging need for lower gas fees. Their announcement might get a bit overwhelming, so we’ll try to cover everything top-to-bottom in detail as best as possible. Let’s begin!

Uniswap v1 vs v2 – A Brief Introduction and Comparison

Before we take a look at Uniswap v3, we must remind ourselves of its evolutionary path and the difference between v1 and v2. It will help us understand why the new features are the only natural thing that could happen for Uniswap to be one of the leaders in the DeFi space.

Uniswap v1 – Introducing AMMs

Uniswap v1 was first launched on the Ethereum mainnet on November 2, 2018. Even though it wasn’t the first DEX, it certainly was the first one to catch the eye of Crypto lovers. Before Uniswap, EtherDelta was pretty much the only DEX that captured some traction. Still, it was based on the Order Book model, which isn’t considered the best solution for a decentralized exchange because it introduces problems such as costs, poor user experience and a lack of liquidity.

Unlike EtherDelta, Uniswap is based on the Automated Market Maker (AMM) model. This model relies on a mathematical formula to price assets. Rather than placing orders, AMMs rely on Liquidity Providers (LPs) who invest trading pairs in Liquidity Pools

Uniswap is a Constant Function Market Maker, or more specifically, a Constant Product Market Maker. That means that the ratio of trading pairs in every liquidity pool must respect the Constant Product Formula:

x*y=k

where k is a constant, x is the reserve of the first asset, and y is the reserve of the second asset.

This means that all the LPs are to provide additional liquidity in a way that wouldn’t change k. Also, everyone traded had to be aware of the total amount of the funds locked to avoid high slippage.

Uniswap v1 supported only ETH-ERC20 trading pairs, so you could only swap ETH for a single ERC20 token. So, if you wanted to swap USDC for DAI, you had to swap USDC for ETH and then go to the ETH-DAI pool to get DAI.

uniswap v1 DAI/USDC swap

Another feature Uniswap v1 introduced was LP tokens. Every liquidity provider would get the amount of LP token proportional to the percentage of total liquidity they added. These LP tokens represent LP’s contribution to the pool and could be sold/traded or burned to redeem the deposited tokens. Furthermore, every trade on Uniswap incurred a 0.30% trading fee. These fees were automatically sent to the liquidity reserve as a reward for LPs providing liquidity.

Uniswap v2 – Optimization, Decentralization and Security

Uniswap v1 was a proof-of-concept for a new type of decentralized marketplace. Its initial success was a signal for the team to immediately reiterate for an even better solution. Uniswap v2 was launched in May 2020.

In short, Uniswap v2 was a much better and more user-friendly version of Uniswap v1. The main problem of v1 addressed in this new version was the absence of ERC20-ERC20 token pools. This incurred much higher costs and slippage for users who wanted to swap one ERC20 token for another.

ERC20-ERC20 Pools

Uniswap v2 introduced ERC20-ERC20 liquidity pools to solve this so-called “ETH bridging” problem. They even used Wrapped ETH instead of native ETH in the core contracts. However, end-users could still use ETH through helper contracts.

uniswap v1 vs v2 swaps

Oracles

This second version of Uniswap also implements a new functionality that enables highly decentralized and manipulation-resistant on-chain price feeds.

The basic idea was to calculate the average price over a period of blocks (Time Weighted Average Price – TWAP) by dividing the cumulative price (sum of the Uniswap price for every second in the entire history of the contract) by the timestamp duration (the end-of-duration timestamp minus the start-of-duration timestamp).

uniswap v2 TWAP

Flash Swaps

Another groundbreaking feature that v2 introduced was Flash Swaps. These Flash Swaps allowed users to withdraw as much as they wanted of any ERC20 token on Uniswap at no upfront cost and do anything they wanted with them (execute arbitrary code), provided that by the end of the transaction execution, they either:

  • pay for all ERC20 tokens withdrawn
  • pay for a percentage of ERC20 tokens and return the rest
  • return all ERC20 tokens withdrawn
uniswap v2 flash swaps

Uniswap also introduced a protocol fee (that could be turned on/off via a decentralized community vote that sends 0.05% of every 0.30% trading fee to a Uniswap fund to finance future development.

Even though Uniswap v1 still existed after v2 was launched, it didn’t take too long for LPs to transfer most of the liquidity from one version to another. Uniswap v2 experienced huge success, passing even some of the most famous centralized exchanges in daily trading volume. This success made Uniswap v2 one of the most forked projects – SushiSwap being its biggest competitor that was created as a fork. This vampire attack from SushiSwap drained a big portion of liquidity from Uniswap, which led to the famous UNI token airdrop in September 2020.

Uniswap v3 Launch

Uniswap v3 launch date on the Ethereum mainnet is targeted for May 5, 2021. The team also announced they will be launching an L2 deployment on Optimism shortly after to solve Ethereum’s high fees.

Uniswap v3 vs v2 – Efficiency, Security and NFTs

Uniswap v3 will introduce a plethora of new features which will address current problems and provide a more flexible and efficient AMM. Those features are:

  • Concentrated Liquidity
  • Active Liquidity
  • Range Orders
  • Non-Fungible Liquidity
  • Flexible Fees
  • Advanced Oracles
  • License

We could argue that concentrated liquidity is the only new flagship feature the team was aiming for, and the rest are byproducts or prerequisites to achieve concentrated liquidity. You’ll see what I mean by that when we go through each of these new features.

Concentrated Liquidity in Uniswap v3

Let’s take a look at the Uniswap v2 DAI/USDC pool. Since we are talking about dollar-pegged stablecoins, most of the swaps occur in the $0.99-$1.01 price range. This means LPs can expect to see most of the volume and most of the fees to come from that price range. This happens because nobody is willing to trade outside of that range since they can get a better deal on some other exchange. Also, margin traders would almost instantly use the opportunity to reap the profits from the price discrepancy, automatically moving the price into the appropriate price range.

However, liquidity is distributed evenly along an x*y=k price curve, with assets reserved for all prices between 0 and infinity. This means that most of the liquidity is sitting unused instead of rewarding LPs for taking the risk of impermanent loss. Furthermore, trades often involve high slippage as liquidity is spread thin across all price ranges.

uniswap constant product curve

In the case of Uniswap v3, LPs don’t just put their assets in liquidity pools and spread them evenly along the price curve. Instead, they get to choose the price range they want to allocate their assets to and earn from fees when the price is within the selected price range.

Let’s explain this concentrated liquidity a little bit better through an example. Imagine that you put 1 ETH and 2,000 DAI in the ETH/DAI liquidity pool, and you choose to put it in the $1,950-$2,050 price range. What you are saying is the following: 

“Take these assets and put them in the pool. Whenever someone buys ETH for any amount of DAI between 1,950-2,050 DAI, I get the fees from that swap. If ETH price is outside that range, I don’t get the fees.”

Higher Capital Efficiency for Uniswap v3 LPs

Now, why would you say that you don’t want to earn from fees? Well, for the stablecoin pools such as DAI/USDC, there is a minimal chance that the price would go out of the $0.99-$1.01 price range, even though your assets would be evenly distributed along the price curve in v2. That means only a tiny percentage of the total amount of funds is earning fees for you. In Uniswap v3, you deposit 100% of your assets in that $0.99-$1.01 range. This way, it’s not only a fraction of the assets you deposited that is making returns for you but the whole amount. 

When it comes to non-stablecoin pools, such as the already mentioned ETH/DAI pool, you can’t predict the price range as accurately as you can for the DAI/USDC pool. However, you can select a wider price range to account for ETH price fluctuations – such as $1,950-$2,050. You wouldn’t constantly be earning fees, but when you do, you would gain much, much more than in v2 because you are using 100% of your assets, not just a small portion. That’s how concentrated liquidity makes higher capital efficiency possible.

uniswap v3 capital efficiency

What is the logic behind higher capital efficiency? Well, let’s say that you had 50,000 DAI and 24.61 ETH you wanted to deposit into the ETH/DAI pools. You choose to put it inside the $1,808-$2,215 price range. At the same time, your friend deposited 1,010,282 DAI and 497.35 ETH across the entire price curve. What happens is – even though your friend deposited 20.21x as much capital as you, both of you get the same amount of fees as long as the ETH/DAI price stays within the $1,808-$2,215 range

In this case, you had to provide a total of $100,000 while your friend had to provide $2,020,564. This means that your capital is 20.21x more efficient.

You can also make your own example at the official blog post announcement of Uniswap v3.

capital efficiency example

To make things even crazier, Uniswap claims that the maximum capital efficiency could reach 4,000x in a 0.10% price range. Also, when deployed on L2, those gains will go up to mind-blowing 20,000x. At least that’s what they claim. We’ll have to wait and see after it’s launched.

This new feature of concentrating liquidity in a custom price will significantly increase market depth and therefore reduce the slippage for Uniswap v3 users.

increased market depth

Users will be able to divide their assets and put them in multiple different price ranges. This will help them account for price fluctuations and allow users to trade against the combined liquidity of all individual curves with no gas cost increase per liquidity provider. Trading fees collected at a given price range are split pro-rata by LPs proportional to the amount of liquidity they contributed to that range.

Active Liquidity

As I already mentioned in the previous example, you and your friend would get the same amount of fees as long as the price of ETH stays within the $1,808-$2,215 range. So what happens if it goes beyond that?

In this case, your liquidity becomes inactive i.e. effectively removed from the pool and is no longer earning fees. Your liquidity will be composed entirely of the asset with less value as long as the ETH price stays outside the range you specified or until you decide to update your range to account for the price change.

active liquidity

To cut a long story short, you have three main options. The first one is that you choose multiple price ranges. The second one is to choose one wide price range, settle for lower capital efficiency but reduce the risk of price fluctuations. And the third one is to pick one narrow range, get super-high capital efficiency but also expose yourself to a much higher risk.

Range Orders

This one is somewhat opposite of the active liquidity feature. Better said, this is a brilliant way of using the active liquidity feature.

You will be able to deposit a single token in a price range of your choice above or below the current price. So, if the market price enters into your specified range, you will be selling that token for another along a smooth curve while earning swap fees in the process. Quite nifty, isn’t it? Let’s examine how you can do that.

Let’s say that the price of DAI is below 1.001 USDC. In this case, you could provide $1M worth of DAI to the pool in the 1.001-1.002 price range. As soon as DAI goes back above 1.001 USDC, you start earning fees. Once it trades above 1.002, all of the liquidity you provided converts into USDC. At this point, you can withdraw your funds and get 1M USDC plus all the fees you earned.

range order

This was just an example of the DAI/USDC pool. You can use this same method to get ETH from the ETH/DAI pool when ETH goes below a specific price. And you will be earning fees on the way.

Just a few days ago, our Web3 Tech incubator 3327 organized a hackathon dedicated to tools and products built on top of Uniswap v3. Make sure to check out the recording to see the ideas the teams came up with.

Non-Fungible Liquidity

Since LPs can provide liquidity in custom price ranges, their liquidity positions in Uniswap v3 aren’t fungible anymore. ETH/DAI positions at $1,950-$2,050 and $1,900-$2,100 aren’t the same. The first one comes with higher capital efficiency but also more risk and possibility of inactive liquidity.

That’s why LP positions in Uniswap v3 can’t be represented as ERC20 tokens in the core protocol. Instead, LP positions will be represented by non-fungible ERC721 tokens (NFTs). This may be the first actually good use-case of NFTs…

Flexible Fees

As I already mentioned, Uniswap v1 had only flat 0.30% fees, of which 100% goes to the LPs. Uniswap v2 introduced a 0.05% protocol fee which could be turned on/off.

Uniswap v3 brings community governed flexibility through multiple fee tiers:

  • 0.05% – expected for stablecoin pools like DAI/USDC
  • 0.30% – for standard non-correlated pools like ETH/DAI
  • 1.00% – for exotic non-correlated pairs

The Uniswap team added even more flexibility by allowing the governance to add additional fee tiers. Protocol fees are also there, but they are turned off by default. However, the governance will be able to turn on the protocol fees on a per-pool basis and set them between 10%-25% of LP fees.

Advanced Oracles

Uniswap v3 introduced significant improvements to the TWAP oracles. It’s storing an array of cumulative sums instead of just one like Uniswap v2 did, thus making it possible to calculate any recent TWAP within the past nine days in a single on-chain call.

uniswap v3 improved oracles

This improvement makes it easier to create more advanced oracles easier and cheaper. The team claims this will reduce the gas costs for keeping oracles up to date by 50%.

License – Preventing Uniswap v3 Copycats

This could be seen as contrasting to the open-source philosophy of Blockchain. The team announced the time-delayed license for Uniswap v3. This means that Uniswap v3 Core will launch under the Business Source Licence 1.1. This will limit the use of the Uniswap v3 source code in commercial or production use for up to two years.

They decided to do this to prevent potential future copycats, such as SushiSwap. However, all code needed for external integrations isn’t affected by this license. Also, Uniswap v3 governance will be able to make this 2-year timeframe shorter or grant exemptions.

Uniswap v3 on Optimism

The Uniswap team has announced it’s about to launch Uniswap v3 on Optimism, aside from the Ethereum mainnet. This was absolutely necessary, considering how high gas fees presented one of the main problems for Uniswap v2 and Ethereum in general. 

However, Optimism was to launch by the end of March, but they announced that it would be delayed due to a lack of “community preparation”. Guess we will have to wait for a few more weeks, but let’s hope it will be worth it.

Gas Costs

Even though they introduced some significant improvements in the Uniswap v3, the team claims the gas fees on the Ethereum mainnet will be slightly lower than in v2. Considering that gas prices aren’t going away with the controversial EIP-1559, we have to look for another solution. While we are waiting for the Ethereum 2.0 launch, Uniswap v3 is also launching on Optimism. However, Optimism has its own issues, so let’s keep our fingers crossed and hope for the best.

Conclusion

Since its inception, Uniswap has been the leading DEX and one of the world’s most popular DeFi platforms. They brought innovation with every new iteration. This time, with Ethereum’s scalability issues, Uniswap v3 depends on the underlying infrastructure more than previous versions. That’s why we shouldn’t be surprised with potential delays or initial lack of performance they promised.

Uniswap v3 is not only enabling higher return on capital for its users, but it also brings new possibilities to the developer community to build an ecosystem around it

What do I mean by that?

The features Uniswap v3 introduced are fairly complex and might prevent user-base growth due to a lack of understanding by ordinary crypto holders. That’s why we can expect to see developers working on their solutions to make Uniswap v3 more user-friendly and make products that help experienced users create sophisticated trading and investment strategies. You can see some of the ideas that could be implemented in the recording of our hackathon.

If you are thinking about making such products but not sure how to do it or need someone to collaborate with, our 3327 tech incubator is a great place to look for advice. We have a great community of developers, designers and other brilliant minds willing to help you with your idea. So, make sure you join our Discord server and join the conversation.

Also, in case you would like to work in the industry of the future, make sure to visit our Careers page. We have partnered with some of the best players in Blockchain, but also experimenting with new use-cases and new technologies.

For more details about Uniswap v3, you can check out their official Whitepaper.


Guides, articles, and news
Uncategorized

RWA Marketplace Validation Use Case – Tokenized RWAs are yet to take off

As the bull market kicks off, we are seeing exciting new trends taking over the market from DePINs, tokenized RWA,

Uncategorized

ZKSIM – Revolutionizing ZK Circuit Testing

The development of zero-knowledge (ZK) circuits is an intricate process, with testing posing a considerable challenge that often extends timelines

Uncategorized

FHE Project comparison

As the adoption of this transformative technology continues to grow, so does the emergence of innovative projects harnessing its capabilities.

get in touch