Optimizing Uniswap V3 Liquidity: A Backstend Approach / Pablo Baiocchi

EthereumZuri.ch 2023 · April 2023 · 15:16

Pablo Baiocchi addresses the data needed to assess liquidity provision opportunities in Uniswap V3, which is not commonly available. He analyzes what data is missing, how to find it and how to use it for backtesting, giving liquidity providers on the decentralized exchange a firmer basis for their investment decisions.

Speakers

Topics

From EthereumZuri.ch 2023, hosted by EthereumZuri.ch.

Transcript

foreign [Music] okay good uh well my name is Pablo I work at UH sentiment and today I'm going to talk about uh using on-chain data to be smarter about um liquidity provision in unisol V3 so overview of unisol B3 um and it's liquidity pools so unified Universal office 3 is an automatic an automated Market maker it allows trustless token swaps between

swappers and the pool itself with a new thing about V3 is concentrated liquidity so the concept of concentrated liquidity I think makes more sense if we look at unisol V2 and what unsolv2 did or it still does so in unusual V2 liquidity providers provide liquidity to the whole spectrum of prices um what does that mean so if you provide liquidity to unisol V2 pool what you're doing you'll provide liquidity to in an ethu SCT pool for example you're providing liquidity to the case of 0.01 usdt Youth and 100 million usdts um

which is great in the sense that every single price can be traded but it also has some some issues um which we're going to look at here so the problem is that you assign liquidity to unlikely prices so we can all agree that in the medium term short term ease is not likely to be worth 0.01 usdt or 100 million usdt so there's liquidity there and it's not getting used and then where the price action is happening there could be more liquidity we could be using that that liquidity from the edges and we're not using it and and that's pretty inefficient because that's that's making for more slippage so so big swaps

are moving the price more than they realistically should so incomes concentrated liquidity which fixes that um well concentrated liquidity to us is when a liquidity provider provides liquidity they have to set the price range for the liquidity so going back to exact same example instead of providing liquidity essentially from zero to Infinity you could provide liquidity from 1500 to 2500 so now your liquidity is more concentrated it's a lot more useful because it's a lot closer to the price action and since you only make money when the price is within your range then everybody is sort of wants to provide liquidity where they think the price is going to be they want to provide

liquidity close to price action and that's great because now there's a lot more liquidity uh price action and there's less slippage so everything's fixed right um not so much um because if we look at this entirely from a liquidity provider's point of view um it makes it makes liquidity provision a lot more complicated because previously in V2 you picked the pool you're going to provide liquidity for you provide liquidity and that's it and and now with V3 you have to pick the pool and now you actually have to make the most important decision which is within what price range do I provide liquidity and and that's not that's not all that trivial

um so first we're going to talk about some of the risks of providing liquidity among them platform risk so something could go wrong with the smart contracts and permanent loss maybe you provide tokens that throughout your uh liquidity probation lose value and then opportunity costs of course maybe you could have done something better with your tokens made more money um so so since since there are risks in liquidity provision and we kind of have to look at as an investment right there's got to be some return on these risks for it to be worth doing like nobody's going to do this just to be nice um so normally when you think about an

investment you know what the risks are hopefully and you say okay how much return do I need to realistically want to take those risks so you want to have an expected return to compare to these risks um and in a big parameter whenever you compute expected returns it's generally a historical return like that's a that's a really good starting point and so let's so now we're going to look at how we would compute that for for uniswab um so for v2 it's really simple right because the Returns on these pools are just the fees that you're going to make from the swap so and V2 is simple because since everybody provides

liquidity to the whole range then whenever a swap happens the fees for the swap just get distributed to everyone um so you just yeah take the fees divided by essentially the total amount of liquidity in the pool and well you get the return for that Swap and that's really straightforward um but for for V3 it's a lot more complicated because not everyone provides liquidity for every Swap and the liquidity is also not constant so how do you compute that um so first of all because because not everyone provides liquidity to the whole range the liquidity is not constant and

you have to you have to divide the pool right into into different parts um which luckily you know celebrity does that for us takes our pools are divided into ticks where each tick is 0.01 higher price than the previous tick so so good now we have ticks and if you think about it each tick is sort of its own investment vehicle um where previously in V2 the whole pool was one investment now in V3 each tick is its own investment because each tick could have its own liquidity and swaps happen at specific ticks so it's the tick that gets the fees on its liquidity

so itself it's kind of its own unit um so calculating tick returns we have to what we have to do is find for a swap what ticket took place at how much fees there was we divided by the liquidity and the tick and now we get the returns for that for that swap um which seems pretty straightforward um but thing is that swaps don't always happen at single ticks so you could have a swab that starts it takes zero and it ends at tick four right

um and first of all when we when we look at on-chain data and we look at how we know what tick swaps take place at we look at Swap events and the swap event only tells you which tick the swap finishes at um which is already a problem but let's say that we can look at previous swaps and we can infer that well if the previous swap finish had to take zero and this one's finished at tick four then we know it started zero finish at four and that's good but the problem is that when a swap happens across multiple ticks what's realistically happening is that there are several swaps taking place so a swap comes in

um and the pool kind of looks at how much needs to be swapped and how much liquidity there is left going in that direction at this tick and if the swap volume is bigger than the liquidity that's left of that tick then it swaps as much liquidity as is left at that tick and then moves on to the next one and so on and so forth and because ticks as we covered earlier kind of varying liquidity then we don't know from the swap event how much of that swap happened at each of those ticks so we don't know we don't know how to assign the fees of the swab to each tick like how much goes to each tick um so that's where this concept of data is

covering through back testing comes about um so the concept is we essentially take a new pool and we look at the on-chain transactions that have happened with that pool and we essentially recreate its history transaction by transaction and what we're trying to do essentially is take snapshots of its state at every point in time that way we always know how much liquidity is at every tick and then when swaps take place if it's a multi-tick swap then we know how much liquidity is being used in its tick we know

what fees are going to each tick and we can actually compute the tick returns for each swap for each tick um so that has quite a few applications first of all we can do time series to turn on ticks so we can split this pool into ticks and we now know what the returns are on every swap we know when these swaps happen so we can essentially for any window have a Time series return on these ticks um which is which is great for getting a sense for what ticks are making money and how much money are they making um and then we

by reconstructing a state in that way we essentially know how like what the liquidity is at every moment so we know how the liquidity changes we can kind of look at a time variance of the liquidity we can compare it to swap volumes and uh that can also give us a lot of intelligence as to how these pools behave how the market behaves um and of course it is a back testing approach so another nice part about it is that we can use this exact same infrastructure to actually back test signal-based investment ideas so let's say that we use the first part of

the pool history to analyze the data we came up with some idea on how we can trade these pools well now we have the rest of the history of the pool that we can actually you know mental liquidity in the way that we think was a good idea and we can run these real transactions over that time period and see how did we do you know we thought our expected return was going to be X how far off was it um and was that good so thank you here's some information and reach me if you want to talk [Applause] so we have some time for a question

thanks for the interesting talk are there any questions from the audience one is up there thanks hey Pablo hi um question on I guess the tick so are you rewarding I guess the liquidity providers who invest in the ticks that are more further out from the price like greater than the ones who kind of to show I'm trying to get to like how are you creating an incentive system to reward the yeah the guys who take on the more risk okay so so what happens is uh

whenever whenever um whenever someone provides liquidity within a range they're normally providing liquidity to several ticks and they cut spread out pretty evenly and when when a swap happens at that tick then the fees for that swap get distributed to everyone that provided liquidity to that tick proportional to the amount of liquidity that they provided what if I provide liquidity though in like a tick that's like way outside the range of the price right and like I'm like on the edges there you see that like that's that's why that's why this data is useful because you can kind of

look at so obviously you want to provide liquidity to take that get action and like that's why the status useful because use this data and you kind of see that you know this is where you should be provide liquidity if you're providing liquidity like way out way out here then your return is going to be zero you're just you know permanent loss so there's gonna be no action I guess outside the the yeah the heavy action ticks yeah yeah I mean okay cool absolutely I think there's another question there yes I was wondering if you actually do this back testing what kind of insight did you gain because I guess there's a certain trade-off between rebalancing often and like choosing smaller ranges

which costs more gas fees for all the rebalance actions and like choosing uh broader ranges but rebalancing less often so I was wondering what what was like the the insights that you gained there when doing these back tests um I guess it it depends on your strategy right um basically that that's that's a whole that's the whole point of of the back test um that you kind of you kind of see that if you were rebalancing a lot like basically like if you think about it the when if you rebalance like you better have made enough money before the rebalance because otherwise it wasn't worth doing and um that's that's where

the back testing comes in because maybe you you've come up with a strategy that on paper looks great and like you think you crack the code and then when you when you actually try just like the gas fee set you up like yeah you were in range all the time so technically you were getting returns for absolutely every swap but you know the gas fees for actually burning the liquidity and then re-menting it just killed all your returns maybe you even lost money okay thanks is there any other question if not then let's thank Pablo for the great speech Let's thank you again [Applause]