The Evolution of On-chain Trading
ETHCC 6 · July 2023 · 20:03
Austin Adams reviews onchain trading through Uniswap's product development and research since 2018. The speaker examines earlier innovations, the state at EthCC[6] and possible future directions.
Speakers
Topics
From ETHCC 6, hosted by Ethereum France.
Transcript
[Music] foreign [Music] they got me before I was ready I apologize I so I don't have apparently my my slides and my notes are no longer here so I'm just gonna have to send it uh no slides no notes but I I appreciate you all coming uh this is Hook Line and Sinker a guide to uniswa V4 hux so my original title was the evolution of on-chain trading also spelled wrong with The Hyphen um and I it was like the most boring title I've ever come up with it was what we uh I submitted this talk pre-v4 so I could not you know leak that Alpha uh so
this is the new title which is hopefully a little bit more fun so uh this is an introduction so I'm Austin I'm a researcher at uniswap Labs uh I mainly focus on like protocol design and economic incentives on the uniswap protocol and this is a very fun photo of me as Captain Hook uh because this is all about hooks uh shout out to Sarah for making this wonderful meme of me and this is my website AJ adams.com and you can also find me on Twitter at austinadams10 or something um okay perfect so this uh this is hopefully you after this talk so this is a wonderful little a little meme that JT Riley on Twitter made about hooks uh and this is how I feel this is me I do not
trade very often on the protocol but when I do I um we'll be using hook pools so and I'll get into the fun talk I wanted to give all the memes before I did it um so yeah it's just a hook 101 oh they're right there cool so what are hooks bottom text uh hooks are the new one of the new Innovations of uniswot V4 they are uh hooks that hooks to fine code that run at predetermined points in the amm's life cycle so this was a definition actually made uh by Dan Robinson at Paradigm somewhat similar to this and then I butchered it because I was like we need to make it a little bit more simple for everybody uh so what does hooks what is what does Define code mean
so this is an example of one of the hooks that runs after initialization of a uniswap pool and what it does is it creates the oracles this is actually the uni swap V4 tiwap Oracle which calculates uh like on-chain prices and after initial this this sort of function is called after initialization of that pool and what you can see is it sort of creates the Oracle and what calls this you may be asking so this is actually the code in the pool manager that calls this hook so you can sort of see the pool manager calls after initialize and if the what it's calling Returns what it expects it allows that
code to go through and if it does not it sort of airs out um so this is the four or the eight different type of hook callbacks we have and we'll go into them but it's a little snippet from the white paper uh so I actually stole the slide again from Sarah and Alice this is uh the eight different type of uh Hooks and what they sort of relate to so on pool creation you call this initialize hook uh you have swapping at one token for another is a swap and you have ADD remove liquidity or collect it's modified position and then you also have giving money to in-range LPS is donating uh and what this is this goes to the before and after initialize before and after swap
before and after modify position before and after donate hooks so this is currently the eight hooks that are on uniswap V4 so what can we do or sorry what this is uh the example of like I cut down in the protocol in the pool manager which manages all the pools on unit swap before in the Singleton this is a really cut down version of how hooks work so you can see before this swap is called there's a before swap call we sort of check should we do it and then the actual swap happens and then afterwards an after swap call is called and so that's sort of a very cut down version of how V4 hooks work and this is sort of similar to how they work in all the other uh versions so this is a wonderful little diagram I'm very
proud of it I made this the night before the V4 white paper launched uh this is a very cute little technical diagram that helps you run through exactly when and how hooks are called and you can sort of see that these are the exact same thing so these this code and this diagram were the same thing and so usually one of these helps people understand how hooks work maybe one of them does for you as well uh so what do hooks enable this is sort of the meat of the talk is what do what do we think hooks are good for so this is the use cases from the white paper they're T wam on chain limit orders Dynamic fees Mev internalization and custom oracles however we've talked
about this like a million times so let's talk about some new Hooks and talk about things that we haven't actually talked about before so the first one is this very fun hook that we actually came up with like last week so this is this uni swap V2 hook and this is enabled by um Emma so Emma is one of our protocol interns she came up with this wonderful PR which allows the hooks to actually edit uh and put sort of Trades inside the uniswap protocol so this is sort of the the new code for before Swap and you can see right here that you can actually the hook can return things to add to the Singleton so sort of like adding a trade inside the Singleton and what does this
enable this is a enables hooks to have non-xy equals K or non-concentrated liquidity so one of the cool things is you can actually have a hook that is actually just a V2 pool so instead of actually doing the swap inside the V4 pool you actually do it in this Hook and the hook returns all of the Deltas it returns everything and so you can have things like pre-filling swaps you can have things like uh non-xy equals K liquidity you could have like a curve pool you could have like a balancer pool inside these hooks so they can sort of manage and get all the swap parameters and then a change inside the hook and then it can have all the composability
that comes with the unit swap V4 in the single 10. uh the other one is dynamic fees via auctions this is the one that I'm most excited about uh this is calculates optimal fees so uh Dynamic fees are really hard I feel like people think they're really easy they're like actually extremely hard Dynamic fees uh are one of the hardest things that and that's one of the reasons why they really like in the Mev problem and like lever problem hasn't really been solved uh and it's because optimal fees versus Arbitrage are really easy to calculate so if a given volatility measure or like a given price path you can pretty much calculate like what the good like what a good uh fee rate would be for this unit swap V4 pool however the problem is that
the optimal fee rate needs to take into account this non-arbitrage non-toxic flow and one of the problems that we found is that there really isn't a model that exists currently that uh will work for non-toxic flow so and if there was it probably requires way too much data to work in the evm so it's functionally uh impossible for us currently to create these Dynamic fee models that run on chain uh so how can we sort of have but one of the things that we can do with this auction measure is we can CR this auction is we can create something that both helps mitigate the top of the block auctions which was a lot of these things that people on Twitter talk about they talk about like a centralized decentralized exchange Arbitrage and
that's Arbitrage that happens the top of the block and also we can also mitigate loss versus rebalancing which is sort of things that uh losses that LPS take when they get arbitraged against centralized exchange prices so this is sort of I was I was like there's two things here so I was like inside you there are two wolves uh so here's one possible solution that I think is very cool um we can actually auction off all of the lp fees in the next five minutes and the right to set the fee rate for that like five minute period as well and that's really good because uh the winner of this right is both incentivized to win is incentivized to set an optimal
fee rate which is like the fee rate that Returns the modes for the LPS of the pool and they are always going to win the top of the block auctions they're always going to win the centralizing centralized exchange Arbitrage because they get all the fees so they actually are trading at a zero fee rate and that uh is really helpful because then you can have two things that are really like two of the big losses for LPS are fees that don't update very efficiently and then top of the block auctions and this sort of does both of them there are issues there's never a sort of Golden Goose solution uh two of the issues that I really really have is Builder centralization uh sandwiches and censorship resistance so Builder ships
and centralization censorship resistance are two things that Max Resnick the special mechanisms group talks about a lot uh which are sort of like the person who wins all of the centralized centralized exchange arbitrages is going to be like the person who wins all of the blocks in the Mev auctions and then if they win all the Mev auction they're going to have pretty much control of the chain for a little while and then it's also really easy to censor people who are submitting bids to this auction so we have to be really careful with how we set up these auctions and then there's also sandwiching so if you trade with no fees as a sort of the person who owns this right to this pool you can sandwich people for free and that's pretty
problem automatic because those are two really bad things but there are some benefit there's some ways around them but uh setting up this auction is really hard and we've got to figure out how to do that uh and so these are like two of the things I want to talk about and then another interesting Hook is your hook so one of the things we're really excited about in unusual before is how we're working in part with the public we're working in public and that means that we're taking Community feedback we're taking uh things that the community wants and that's really helpful because there's a lot of things we didn't really think about that people really wanted um and so this is a quote I don't really care about uh and then this is what I was saying and then here is the current and possible future unusual V4 PR so
these are four things that the community actually came up with that we've sort of trying to implement inside the V4 core and we hope that some combination of these will support new use cases and new things that the community the team wouldn't have thought about but can making this one before sort of the best place to trade and sort of the best decks and so that's Singleton Delta from hooks so you can use the unit swap V4 accounting methodology in your hook and then returning early with sort of a desired one from a Community member that we think is pretty good and then arbitrary data passing into Hooks and then locking by address instead of locking by routers uh so with these four things we hope
that a lot more use cases will come out and then we're also looking for your ideas so we want to hear what you have to say about V4 you may think that like we don't care about what you have to say but we've had a lot of really great PR's we had a lot of really great people bring up things that we never thought about and how they're this sort of small change means their use case can happen now and we really want that we want all of the use cases we want to support as many things as we can with safety on uniswap V4 so uh this is sort of why I love hooks sort of just a shill about hooks I won't read these but I'll read the last one which is my favorite one as a research person is that there's more
research we can do so instead of having to do all your research every like two years and launch a new protocol you can launch a protocol like every day as a new hook that's sort of one of the things I'm very excited about and it's very good for job security uh so here's a little q a I will also do so I want to take some questions uh if there are any about hooks yeah you the black shirt oh do you need a mic sorry I threw that q a on you I was like love I love q a I can hear you but I don't think the
audience hello hello okay perfect only from the security perspective how do you plan to filter uh the pulse with malicious Hawks yeah it's a great question it's one of the things that we're thinking about as a team um I think that there's been things thrown around like a white list there's been things thrown around uh like looking at certain hooks that only have certain permissions so one of the things that's really great about V4 is that your Hook's address determines what things you can do on the protocol and so if you have like a certain subset of things you can do and none of them are malicious then I think we should route to all those hooks but one of the really great things is actually routers don't
have to worry as much about your router like is one of the biggest things that supports you uh and supports like community members essentially so like your router has a certain amount in that it gives and has a certain amount out and that's an invariant you really can't change change so it's not routing isn't as big of a deal as it is for LPS so LPS are where we think a lot of the uh worry comes around hooks but we don't want people to LP in malicious pools and so I think routing is less of a concern because your you know the unit swap Universal router protects you from a malicious pool but uh for El ping that is actually pretty nerve-wracking I
think like what we'll have to do especially for our community members is I think a lot about how we can Surface only safe hooks about the router with accounting the gas cost also and not just the token out talking in yeah I think like I I must I guess I'm less concerned about the gas costs from uh security standpoint um I mean creating like a malicious Hook is I I think like you know spending an extra five or two dollars on gas is significantly less impactful than like
losing all your tokens uh so I think like but like I know obvious will be simulations and things like that that will be done to make sure that gas costs are accounted for in routing uh but this is sort of like routing from like on-chain routing like the thing that sent or swap to different pools uh is more of what I was talking about less of like actually determining where uh the swap goes um but yeah gas costs will obviously be taking into account is that is that your question yeah perfect question down here oh this is how everyone else's talk by the way so I'm going to be talking tomorrow at four oh it's Haroon uh who's gonna a very large Brain and I'm a little nervous about it but should be a wonderful talk about oracles versus not
oracles on D5 protocols sorry I can just repeat yours as well if you want what's your question depending on the fees of the pool it's facing is different right yeah um there's going to be will this be will this have an impact on like liquidity providers yeah so I think your question was on you know Tech spacings or dynamic there's Dynamic fees now will take spacings be
uh changeable as well okay um so yeah so Dynamic fee are the fees can be set they can be dynamic but the tick spacing is also it can't be dynamic and that's for um how we search for the pool is you can't have Dynamic tick spacing but you can have when you initialize the pool you can say any text spacing you want um but you can't have Dynamic tick spacing so it can't adjust after it's been set in the initialization and that's just more of an optimization for um how you search for the next pool uh so if like the tick spacing doubled we and then we would miss people's pools we searched for the next tick that'd be slightly dangerous probably maybe it would work I don't know if it's it could be possible I'd have to think
about it more though thank you any other questions about anything sorry so just curious can hooks interact with other versions of uniswap and other forks and other Forks hooks or like hooks of forks of hooks of forks yeah so you can right so one of the cool things now is this balanced Deltas that we return pretty much means that like the hook could check V3 to see if V3 has a better Swap and if it does it actually executes the swap there and Returns the money or Returns the tokens to you in
the V4 swap uh so that's like one of the cool things that could happen uh hooks can do a lot of things um I think with with balance Deltas you could do that though you could interact with the fork you could interact with V3 V2 and a lot of different things like that are we are we good we're we're happy another question okay I can't answer your question I answer your questions a lot you know on Twitter it's more it's not as fun yeah how do you point to why traced what a hook can do and what's the process of
getting white noise yeah I don't think I I guess I'm not the one planning it uh how the they will be set up um I don't even know if there will be a white list I think that will I think that's just like one possible way that they could be done I think there's a lot of other ways that we could go without them I just think that like we launched this like we we sort of open sourced the code like a month ago and we have like six more months until I uh Cancun comes out and so I think that uh why oh I don't think we even like might not even go with the white list I'm just like that was just sort of one of the ideas I sort of threw out um it could be that it could be a lot of
different things so I don't know how we would plan to do it um because I don't know it could be not that it could be something completely different okay was we want to call it a day okay if there is no question then the perfect perfect [Applause] oh wait I'm supposed to shout out one more time