Uniswap v3, or How I Learned To Stop Worrying And Love Concentrated Liquidity

ETHCC 5 · July 2022 · 20:04

Daniel Robinson explains Uniswap v3's concentrated-liquidity design and mathematical foundations. The speaker examines pitfalls including just-in-time liquidity, oracle manipulation and subtleties in liquidity mining.

Speakers

Topics

From ETHCC 5, hosted by Ethereum France.

Transcript

hi everyone i'm dan robinson i am the head of research at paradigm and i'm here to talk for the first time i think publicly is talking about uniswap v3 um and this specifically is going to be talking about how i learned to stop worrying and love concentrated liquidity so a few things this isn't going to be um this is not an introduction to v3 i'm going to talk a little about kind of the concept behind it but if you're not familiar with it this probably isn't for you there's a lot of things online i've actually done an online course about unisoft v3 that you can check out um but i'm going to assume that people people interested in this uh particular area uh uh know sort of how it works um and it's because this is not a neutral talk i'm very biased here um not only am

i uh close to the use of team paradigm is invested in um uniswap uh we have a lot of other investments that touch on various areas of mev including ones that are that are related to this talk so i would say um if it matters to you that that you know you're i'd be speaking from authority and a completely unbiased place you should also probably stop watching now um but what you get instead of uh neutrality and lack of bias is you get passion and i come by that passion honestly i think i i this is going to be a rant that i have been giving for a couple years now and i think i've been arguing about this as a brag but longer than longer than almost anyone else because this was actually an internal discussion at uniswap when we were working on uniswopd3 and we sort of like sorted out

some of the issues but i think seeing them in public has really helped figure out like okay what were we right about what we're wrong about and here is something that i continue to uh to think we're right about um and i'll be that's gonna be talking about um just in time liquidity so um let's first talk a little about just conceptually what uniswap v3 is here's a picture of moses concentrating the liquidity in the red sea um what we the reason we came up with concentrated liquidity was we were trying to figure out how to take what was working on ethereum which for largely gas efficiency related reasons was automated market makers and make it more capital efficient and so this actually the origin story of of unesco v3 was thinking like okay how do we

actually take what's in unison v1 and v2 and avoid this problem of capital efficiency so the solution to that is to start with this uh famous reserve curve x x y equals k and translate it down and to the left um for each individual liquidity provider so they're only providing across a certain range of it um and then here you can see that they can just provide that and then you combine that aggregated efficiently with all the other liquidity providers and so this is how we construct this from basically slicing up an amm into its constituent parts and then letting people provide only one piece of it but there's actually another way that this could have happened and another way you can approach this

and so imagine we had actually started with a normal central limit order book this is just how most exchanges historically uh have worked and it's a design that evolved over over centuries um toward what again i think is actually a fairly efficient mechanism for this we'll take it we're going to make a couple small improvements so first we're just going to smear out every tick um so that it covers instead of just being like a single price it covers all the prices around it um and what this allows us to do is actually have slightly wider ticks than we might otherwise have so it's a gas efficiency optimization the other thing it allows you to do is have like infinitely small precision although of course the fees sort of compromise on that a little bit

then we're going to say we're going to add a new kind of order type to this central limit order book we have like a flip order and whenever this order is crossed whenever it's a buy order we're going to turn it into a sell order and if it's crosstalk and it's a seller we're going to turn it into a buy order and then we're going to say just oh like for convenience because it would be you know maybe slow for you to add all these orders we're just going to have a function for you just drag across a whole range of liquidity and you're going to add a bunch of orders and this is basically at this point we've now actually created um something that looks quite a lot like uniswap v3 looks like the capital of vision amm i think that's you know that they're these they're the

same picture i think this is not a coincidence i think everything that rises must converge and ultimately if you're optimizing there's like how nature keeps trying to evolve a crab it's if there's only one really good design i think for how uh this kind of like uh liquidity uh market making should work and i think it looks something like this hybrid uh autobook amm and so what's interesting is i think you know in 2019 if you were arguing with me about uh dexes i would probably be taking a very like anti-central limit order book stance and very pro amms are really uh are sort of the future and i think you know again like i don't think i was necessarily wrong then um but certainly the world has changed a lot such that actually i think a lot of the

arguments that people were making at the time and then maybe i might have actually dismissed you quickly we're just ahead of their time people people were right when they were saying that amms were too capital and efficient they were just too early um and so when we when we optimized uh the amm for capital efficiency we actually ended up with something that could have looked like if we started with this uh central limit data book and just optimize it for gas okay um so when we had uh when now that we have central limit order books we actually get something that's a lot uh we see these phenomena arise that exist in traditional uh finance more often and one of them is this concept of just-in-time liquidity this is a ninja shooting water from his hands um representing just in time liquidity from mortal kombat

so what is just in time liquidity so there's you know and since unit swap launched there has been this type of uh attack i'll say um maybe losing using the word attack non-judgmentally um where it's called a sandwich attack and so the way this works is that when someone places a market order on unit swap they have some limit of the price that they're willing to to uh pay and they'd like to not pay that price they'd like to pay a lower price but what an attacker can do if the price current price is lower is come in force them to get that price under certain conditions an attacker can do this force them to get the worst price of basically the limit price that they're willing to pay and then um after they've paid it they get to lock in some profit um and so

this has been an issue in um in uniswap for a while i think there are uh it's not what the main thing i'm going to talk about but i but i will get back to it in a in a second what i'm going to talk about is this other kind of attack which is just in time liquidity attack and so the way the liquidity tech works is instead of an attacker causing the user to get a worse price by trading in front of them the users the attacker's actually going to add liquidity they're going to provide liquidity that the user is then going to trade against well this does it gives the user a better price um so and then like afterward the attacker doesn't just can't just lock in a particular profit they actually have done a trade with the user they had to

provide this this better price for the user and then the attacker has to go hedge it or or it takes there's a little risk added on the attacker side potentially or they have to find somewhere else to hedge that that trade that they've done and so this is a this is a phenomenon this could have happened in theory in uniswap v2 um but it would have taken unimaginably more liquidity uh to make this act to actually do this um reasonably in v2 and so v3 by adding a lot of capital efficiency to liquidity provision also makes this a much more practical thing to do so as i've explained it here again i maybe maybe i'm a little biased on how i'm presenting this but i should say that people go nuts about this people hate it people just like you know just-in-time

liquidity if if you would if you're in my like twitter mentions is just like it's like the worst thing that's that's ever been happened to the death of ethereum and uniswap um and i think there's there is a reason for this and i'm going to i'm going to talk a little about the the uh logic behind this critique and the the issue is when somebody comes in with um it was just in time liquidity they get some of the fees that would have gone otherwise to passive liquidity providers and these are uh these these trades basically these trades that would have happened these bad trades that a user would have had um you would the liquidity fighters might have wanted to get those trades because then they would have gotten the fees from it but instead uh these go to

uh so these go to the uh to the just-in-time liquidity provider so um this hap you know this is absolutely right and it does actually cause some drag on um on lp fees relative to what would happen if those if those exact trades were happening without the just-in-time liquidity but again that's in some sense like largely a transfer from um the liquidity providers to the traders right and the traders again being another user of uniswap um so here we talk again i think just in time liquidity is good i don't think we should be apologizing for it i think we should be encouraging that there should be way more just-in-time liquidity doesn't liquidity is just order improvement it only is going to happen if you're

actually going to get a bad price and in fact it's a really janky kind of order improvement it's a really janky kind of what's called a request for quote systems because basically someone submits this into the mempool someone has to see it and then put in an expensive ad liquidity operation before it put an expensive liquidity operation after it submit this as a flashbots bundle and you know and take some take some risk and basically figure out how to exactly like hedge this like this is it would only really happen if actually it's gonna be a really bad trade for the user and so this is like a really janky way or you could think of it as a janky aggregator because if there's good liquidity available somewhere now somewhere else someone might actually jitted and route you to them um but you could think of it as kind of

like a safety net for the user where if they're trading on unused v3 um they're not going to get it so this is this is you know my this is how i see um jet uh i another important thing though is i think it's also people are way too confident about how much of this is actually happening and so if you saw peck on my angry tweet slide a lot of people talking about oh it's like drained all the fees from v3 and if you go there you're just gonna get wrecked all the time because of of uh jet um i put this poll up last night um and i did the analysis it's actually about less than less than half a percent of volume actually happens against jet that's not nothing and this is really out there it's really happening in the world there is just in time liquidity

going on in unison v3 but at least right now it is not a very significant percentage of volume that's actually going through this um and the you know the the what's particularly perverse i think about this is that there actually is a problem and this has been a problem um you know on all on-chain indexes really since uh since it started which is slippage um which is getting a the user getting a worse price than they than the price at the beginning of the block when they're submitting their trade and you know this is not uh i think it's about 21 of prices actually have a worse price this is not all i would say like front running some of it could just be the right the price has moved it's not all sandwiching um but this is a much more significant

thing and i think it's perverse for people to be saying oh you know like users are getting too good a deal on uniswap v3 it's just it's just too easy out there for the user they're getting jitted and they're getting better like better uh trades that it's good for passive i think sandwiching which you know technically i think is positive for passive liquidity providers because it's adding a bunch of fees that they're that they're getting is a much more significant phenomenon and in some ways these things are opposed these things are opposites we're actually i don't want people to think about jet not as another kind of sandwich attack but almost the inverse is it's really a way to say like the user's going to get a particular trade and saying i think i can give you a better trade and that is i think what we actually need to have

going on i think that's ultimately where the market is going to go where the industry is going to go and the uh the deck space i think look if we could you can just you could just turn off jit liquid you can prevent people from withdrawing liquidity in the same block in which it was deposited there are some complexities to how it's implemented but i think even if we even if we really we could i don't think we'd want to because uh what you what you're doing there is you're just saying like you can't actually provide this liquidity for a user on unit swap v3 but you could provide it at a router layer you could actually build a router that provides exactly the same thing but more gas efficiently and then users can just use that you could do this people could go to an aggregator and ultimately you

know the if people are getting bad prices on uniswap v3 then they're going maybe they're going to go to aggregators they're going to go to rfqs and that's going to be worse for passive liquidity it's going to be worse for the unisop ecosystem um so it's kind of a safety net it's like it's a safety valve it really says look we're going to actually fix some of some of the bad trades that might happen if someone is just naively sending liquidity to uniswap and that's good ultimately for people having confidence so they can actually just send their their volume to uniswap so i i look i don't think we can fix this by just disabling features we're not going to fix this by going backward you can't stop this progression of what's of what's happening in the industry um but but you can change it

and so again i think i care a lot about passive liquidity i care a lot about amms there's you know like we said there's like point five percent of volume um that's going through this but uh that's not the volume you should be worried about missing the volume you're worried about missing is volume that's going through aggregators that's 15 of dex volume is going through through an aggregator then there's this 85 of crypto volume which you will not believe this it happens on a centralized exchange what people do is they go give their crypto to somebody and they they they give it up they give it to somebody and then they have to go trade it on a website like it's you know 2014 or something um we i care about dexes and so we just can't be worse at this stuff and look ultimately you know i i think

in 2019 we were in the garden of eden where something like uniswap v1 could really thrive um and was it was a major improvement we're getting to a point i think where where it's not that simple anymore we're actually entering a real world where liquidity is competitive where trading volume is competitive where you have a lot of sophisticated players and you're not going to be able to return to the garden of eden just by basically disabling your own features by making your exchange intentionally worse ultimately it's going to be a war out there for liquidity and so i think you do need something that can if you want to actually protect passive liquidity providers you need to change the structure of how it works and i don't have time to talk about it now but

uh that's one of the major things that i've been thinking about is how do we actually really protect passive liquidity providers um how do we do it in a way that isn't just shutting our eyes and saying and hoping that we get this liquidity i'm sorry it's i think if you're if you're working on dexes you sort of have to have to want the best for the swapper you have to want when the user sends you a trade they are just they're trusting you you have to just care that you're giving them the best possible execution it has to be right that you are and so if you're if you're again just uh i think you don't deserve to actually survive as a as a decentralized exchange if you're not really able to to cope with that kind of um competitive pressure because it's what the user

deserves um cool that's all i've got um any questions yes hello so we have been working on v3 and products on top since the beginning and i find it very interesting how it evolved because i feel like right now it's way more looking like a centralized or order book based exchange than an amm and with the release of the new product that we are doing basically what you

said it's it's very important because what we want is the best execution for the user rather than the liquidity provider not taking fees and we are basically creating a new pool in which is trying to source liquidity across everywhere and just in time execute for the trade and what do you think this can change aggregators because i feel like aggregator are obsolete at this point because they can't see the real execution at at the time because it's on the mempool it's just flashback and how do you see the future of aggregators with just in time liquidity yeah so i think i think you are seeing aggregators

actually get into the just-in-time liquidity game themselves where they are trying to like find centralized market makers or something to provide to provide price improvement for the user i think that's probably a trend that's going to continue um and i think yeah like i said jit liquidity on chain is incredibly janky like you'd never choose this you never design your system so that like you had somebody had to place and it's much more expensive to place an order on a new swap and then uh remove it then it is like settle this thing uh just peer to peer between you and the and the jet between the trader and the jet so i think ultimately yeah they probably can't see that uh jet i think it would be nice actually that would be wonderful if actually this was a this was a

competitive mode that prevented it from being aggregated i don't i don't think it is i think ultimately like they can provide order improvement off chain like potentially even better um or certainly better than the jet that's going on on chain other questions um so how do you see now it's up one percent you said the jit and uh do you think you will have to um protect the lps in the future because it gets very big or uh do you have a oracle about the future i don't know um i think it's it's been fairly steady since this started happening i think i did some of the numbers on it i don't

think it's necessarily rising um i i don't think this particular thing of jet liquidity on unit swap v3 i think again like i said it's a hacky solution it's not it means that there's something actually going wrong somewhere else in the process um that they're not getting a better price there that they're they're the trade is being routed the wrong way so i don't see this particular thing becoming like a huge percentage of unescopia three trades i i could be wrong but if it is i don't think that would mean oh we really should have stopped it i think that'll mean oh something's really going wrong like people are getting much worse prices than they should be any other questions uh you said it's a one percent about

this mainly problem for the providers as i see and is there like any like did you track any backing from the provider's side after the jet is like more public you show the twitter backfire but is it in reality did you like see any like backing from the pools yeah i mean i mean someone some people have done this analysis related to the analysis i did um and i think it's it's something yeah it's it's like under one percent of fees and it just happens mostly on a couple pools um like under one percent of fuse or so um go to uh jet liquidity providers so it like maybe said maybe i think upper bound my guess would be i haven't done this analysis in a while my upper bound would be that it hurts uh liquidity provider returns by like one percent on average

all right thanks everyone [Applause] you