Uniswap V3 Voodoo Magic Fuckery

Mellow Protocol
6 min readMar 22, 2022

--

Heyhey, everyone, we’re back in town! Hope you had a great time with your yields in DeFi while we kept quietly building.

We worked hard on the smart contracts code and audits, as well as the new math models and strategies. As we’re getting closer to the launch (news on the release plans are also coming soon 👀), we’re making it up with new research materials for the community.

Today, we want to go down into the deepest deeps of Uniswap V3 and see if we can use some magic to extract some hidden value from it.

50% APY on WETH/USDC pool? Is it possible?

We want to invite you to our theoretical journey that starts 200 days back and spans over several acts. We’ll go back in time and see what we can learn from the past and how we can change the future. Are you ready? Then let’s start our 20-minute adventure from the beginning of the Uniswap V3 era (in and out, real quick).

Act 1 — The Riddle (long, long time ago…)

In early 2021, Uniswap V3 introduced the concept of concentrated liquidity to AMMs. Instead of providing liquidity on the entire price range of (0, ∞) (as any Uni V2 LP provider did), liquidity providers could now put their tokens into any price range they wanted. And since any price range is shorter than (0, ∞) they could earn more fees from that. Sounds cool, huh? Well, one thing seemed clear — not everyone was happy with it:

Uniswap Labs was the first AMM to provide their LPs with powerful tools for liquidity optimization (they’re real innovators and big brains!). But all of a sudden, capital management on Uniswap V3 became challenging. Any liquidity provider would need to choose the best price range for liquidity provision. Impermanent loss, price risks, mempools… All these creepy details started to matter.

Professional market makers could seemingly deal with it and even extract more value using techniques like JIT. But what about the ones who only want to ape in and forget about it?

One way of doing it would be to put the liquidity onto the (0, ∞) range and forget about it. Wow, that’s a relief! But won’t that steal some precious APY %? Can we do a little bit better?

Wait… Wasn’t Sir Hayden talking exactly about this???

The answer to The Riddle is simple:

Here’s how it works in detail:

  1. Break a UniV2 price curve into equal virtual price ranges
  2. Put a portion of liquidity into the range which currently covers the current price
  3. Put all other tokens into the yield protocols like Convex, Ribbon, and Yearn and earn additional yields
  4. When the price goes from one range to another, pull liquidity from the former and put it into the latter

Now that we have understood the guts of Hayden’s strategy, let’s see how it works.

Lights, camera, action!

Sooooo… With just a handful of capital, we can exactly duplicate the UniV2 position but earn an additional yield on all other capital in your position. It seems like a huge win, but can we do even better?

Act 2 — The VooDoo Magic Fuckery (present days)

Ok, so we could beat UniV2 in the previous act. But can we beat UniV3 itself with UniV3? The answer is YES!

Unsurprisingly, for any UniV3 price range, we can:

  1. Break a UniV3 price range into equal virtual price ranges
  2. Put a portion of liquidity into the range which currently covers the current price
  3. Put all other tokens into the yield protocols like Compound, Aave, and Yearn and earn additional yields
  4. When the price goes from one range to another, pull liquidity from the former and put it into the latter

And here we go again with the almighty VMF strategy:

Here’s the actual magic spell with the correct ingredients:

Assume we provide liquidity on Uni V3 at interval [a0, b0] using 1 unit of wealth. Then concentrated UniV3 strategy will be

where u_1 — is part of liquidity provided to UniV3, u_2, u_3 — is part of liquidity provided to yield generated one-token strategies, [a,b] — subset of [a0,b0] such as a0<a<c0<b<b0, c0 — current price.

UniV3 beats UniV3, sounds pretty cool, right?

But before we conclude this act with a standing ovation, we need to address one more small detail here. If you read carefully, there’s one thing that might be lurking in your mind and make you feel uncomfortable — step 4 of the strategy.

“When the price goes from one range to another, pull liquidity from the former and put into the latter.” Well, we cannot trigger that on UniV3 price change on-chain, right? This has to be done with an external caller, keeper perhaps, that could miss the rebalance event, and the price can move far away from the price range with liquidity. And in that case, the strategy doesn’t work exactly like UniV3. Assume we had a 40% price crash on May 21 when ETH fell from x to y. We can imagine a Twitter thread coming:

To sum up, we have a VMF strategy that:

  1. Earns the same fees as UniV3 position
  2. Has additional yield by adding free liquidity into yield protocols like Compound, Aave, Yearn, etc.
  3. IL protected when prices go mad

Act 3 — The Money (not too far distant future)

Ok, nuff said on math and formulas! Let’s address the elephant in the room, a small question that rules this world, a small question that drives all success — what’s in it for me?

It turns out that the APY for this strategy could reach a staggering 58% on USDC-WETH pair and 18% on WBTC-WETH pair:

Here APY for two-token strategy is calculated by 0xAlexEuler’s approach, which looks more valid for crypto investors (measuring APY in one of two tokens gets higher APY but easy for manipulations — read more in Twitter thread).

Now imagine what we can do next with that? A VMF strategy that beats plain UniV3 LPing. Build a vault that implements this strategy automatically, so it’s just set-and-forget for liquidity providers? Sure thing. But there’s more to it…

In fact, any active management strategy on top of UniV3 can be built on top of the VMF strategy and have… higher yield and… lower IL!

We want to leave this play open-ended. I know, I know, everyone hates open endings. But! They’re leaving more space for imagination, so rare these days!

--

--

Mellow Protocol
Mellow Protocol

Written by Mellow Protocol

Exploring the depths of math on LPing, AMMs and trading strategies.