Uniswap 🛠Introduction to Uniswap V4
ETHGlobal·Mon, Oct 9, 2023, 12:00 AM
Join us for a Uniswap workshop titled, "Introduction to Uniswap V4". Some of the most skilled web3 developers, designers and product builders from all around the globe came together for a weekend-long hackathon at ETHGlobal New York 2023. ----------------- Follow us: https://twitter.com/ETHGlobal​ Check us out: https://ethglobal.co​m Email us at: hello@ethglobal.com
Transcript
foreign [Music] I'm with the uniswap foundation and today we're going to be talking and introducing you to uniswap V4 so before we start uh I want to say welcome to where it all started for us here in New York when all you could do on uniswap was basically swap uni for eth and safe to say we've come a long way since then uh and while we've done quite a bit we're nowhere near being done this summer we announced the launch of uniswap V4 or I should say we announced that unisa V4 will be launching um and with it came a very new and exciting Paradigm for us which we've introduced called hooks hooks allow you to now create pools that are customizable they're modular and they open up the design space for developers in a way that we haven't previously ever seen before at uniswap and in D5 and I think it's a great great time to be a developer on uniswap so hooks aren't the only new thing here we've added so many new things to uniswap V4 where you probably won't recognize you know you you it's not the same things we saw at V3 now we've moved to a Singleton pool manager design we've reintroduced native eth we have flash accounting all of this is meant to make uniswap faster more gas efficient and easier and more fun to build with for Developers well how about we dive into what makes V4 different as we mentioned the first thing we talked about was we have a different way for pools managing that we didn't that we from uniswot V3 in uniswot V3 the way you would create pools is in a factory type style you would end up going to the pool Factory contract the factory contract would then spin up a new totally separate pool address for you and the pools would all live separately in different addresses and then you would have to call each of those addresses so the way that works here is you set up your factory and pool manager contracts you end up creating the contract Factory and using that to interact with the pull creation then you would use that contract Factory to deploy your uh unisot V3 contracts when you deployed them this is another thing you only had three parameters that you really had to worry about you worry about what pool pair you're doing eat the usdc and then you worry about what feed tier you have in V3 you could choose from four feet tiers and with that you know came the automatic uh creation of what your tick spacing was so your tick spacing is predetermined you have your three parameters cool and then you deploy your contract you create the pool and it's nice and done here but it's in a different uh contract which is not very easy if you're a developer to just keep on finding all these new contracts interacting with them it's kind of a pain so what we did in V4 is we introduced a Singleton style design which is all of the pools now live in one contract and they each have their own ID and this ID is what you would use to reference the pool in the contract so right off the bat we're making it simpler we're making it more gas efficient to also spin up pools now you don't have to deploy new contracts every time you spin up a pool it all exists in the V4 pool manager and the other thing that's different now is as we saw in V3 there were only three parameters when it came to developing a pool now you have a bit more parameters uh you still have your feed tiers uh and your currencies but now fee tiers are basically customizable by you as a developer to any feed tier you want no longer is it just four feet tiers you can put anything you want and you can set your feet here to 99 and see how many uh LPS will rush to that pool um the other thing is the tick spacing is now there and determined by you and also new to the party hooks hooks are their own separate contracts now that live in pools and they're able to be customized developed by you and you could put whatever parameters you want around that and that it'll dictate how the pool performs we'll dive into hooks a little bit later but I think this is uh this is where you would be initializing the pool you'd add your pool key here it's all of the different parameters we just mentioned previously and then you'd initialize this and you would have your pool then you would have your will then saved into the contract this is another interesting thing this is where before when you were initializing pools you would not have the ability to actually have hooks on V3 now in hooks you can see when you're creating a pool it checks to see if there's a hook that needs to be called before this pool is created so that's already built into the initialize function and then it's as we mentioned it's stored in the pool contract the other item no more wrapping of each needed you can interact with Native e it's a lot easier and I think developers it's probably a lot easier for you for testing and for everything so it's simplifying trading it's reducing the costs and welcome back native the other item is Flash accounting flash accounting's very uh important for us because now we're able to actually test out transactions and have them all happen in one batch while they're going through so it's not you know you're not wasting a lot of gas going through multiple different swaps multiple different things the lock and call function in our flash accounting allows you to basically lock together a transaction test out the different swaps that are occurring and it returns what's it looks at the Delta of if everything adds up and makes sense and for the V4 this is super nice because as we mentioned like gas efficiency is a big thing that we've kind of cut down on and this is what enables us to do this um yeah so here you have your account Delta you're checking to see if everything adds up and it tracks all the balances to make sure that they're all accounted for and proper and then you are able to uh get get better results on your transactions and save more gas now that we've gotten all that let's go to like the actual fun of everything here and why I think you as developers should be most excited it's V4 hooks so for the first time you're now able to use uniswap as a protocol and then build onto it new customizable features that could expand it from what it was as a decks as just uniswap to now your own customized decks with your own customized pools your own interface so what it looks like is hooks can basically be called at four different action points within the uniswap protocol before or after you create a pool as we saw when we were initializing the pool there was a hook to check hey do we call this hook here before or after a position is modified for an LP so you're able to do cool things with that you're able to call a hook before or after a swap occurs and before or after donate donate is also a new feature in V4 where basically you can give fees to LPS Who in a pool basically donating to them incentivizing them if they're probably staying within a certain range of liquidity you can give them fees to maintain in that range so it's it's very there are lots of cool liquidity mining incentives that could be created from this so let's take a look at what you can probably build as an example to make you understand how hooks perform we're going to look at a simple New York Stock Exchange hook right what if I want to change uniswap and make it only open during the hours of the New York Stock Exchange so you know we're going to look at this and we're going to say okay before a swap happens I want to enable this hook and I want to check that this you know I want to run my hook for this so I called it before swap I set that to true and then I have my function in my separate hook contract that I add on to the uh do the uh uniswap pool that I've created so I have this ethos DC pool it can only operate during the trading hours of the New York Stock Exchange and before the swap occurs I as the uh as a swapper Now call this separate contract all right the contract now calls a separate contract then it says okay is this between the hours of 8 o'clock and 5 PM is it a holiday is this Etc and it checks to make sure that all of this is true and if it is true then the swap can occur if it's not true then the swap doesn't occur and here the developer actually emitted a ding ding ding whenever a swap happens so you know that your swap has happened and the New York Stock Exchange exchange Val has ring now that's not the only type of hook you can build like let's get instead of the code like let's see other examples that might be more conceptual what if now I have an nft and for whatever reason I only want users of a certain nft to be able to interact with my ethusdc pool I as the developers say okay I have a board ape nft and only people with the board ape nft can interact with this pool and then we've got the ether Rock we don't want The Ether Rock people interacting with this pool so this hook would create the same scenario where it checks before swap happens if this condition is met and it says the swap is successful but if it's not met then you block you can't swap on this pool so you know there are lots of interesting social nft type apps that can be built from this and you know another I think more interesting app for people uh or hook for people that are interested in the liquidity provision space is what if now I have all of this liquidity in a usdc pool and I'm a provider of liquidity and I am not doing a great job of managing my positions so I could create a hook that basically says if this person is in range they're obviously going to be doing well and they're going to be getting fees gathered but what if my position is out of range well you could create a hook that basically says we're going to send any out of range liquidity to someone like Ave where we could still have yield being generated for us so it's a way where hooks don't just have to be on the swap side it's a very interesting way for you as developers to start thinking how do I bring in more people into uniswap into this liquidity pool where we're able to do a lot more with their money and generate them uh generate them fees in ways that hasn't been possible before on unisawat so that's uniswap V4 as what we're doing with hooks we have twenty thousand dollars in bounties that we're giving out for people that are looking to build on top of hooks we call it our hook-a-thon here so we'll be giving 12 000 to people that we're giving twelve thousand dollars as a pool prize to people that are building Innovative unique hooks that you know we haven't really seen before and we haven't seen a lot of things because this has really been out for two months so I think the world is y'all's oyster and how you build out these hooks um and because we're still uh building on top of the protocol we are looking uh because we're still building unisot V4 out we're looking for any help with developer tooling any types that any any things that help make the developer experience a lot better for us and for you guys and we're giving out 3 000 in a pool prizes for that for each of the pool prizes we're probably looking to give out two to three prizes so you guys can deduce how much uh you can make from that and then uh we have an open Innovation prize at the end as well um this is five thousand dollars and it will be for anyone that builds on top of uniswap V3 or V4 uh eligibility to win these bounties is basically uh use the uniswot V4 code use the uniswap V3 code uh you know don't just integrate like a swapping app I think you know we we'd like to see things that are a little bit more sophisticated than that uh and if you are at all interested in continuing the discussion of V4 after this don't come to me after this talk and join our hook Dojo we've got over 200 members in there that are active developers building out hooks sharing their ideas answering questions um and I'm happy to give you guys the invite link and then we also have our V4 docs so you just this week we spun up a test net uh uh a roll up on top of optimism where you're able to develop now much easier than deploying just on a local test net uh all of our information on how to do that is on there and we are um we also have information on you know hook resources and how to start building with some example hook templates with that I am happy to answer any questions anybody has about the protocol I wanted to leave more time for that yes selection selection on the pool I have all pools and uh unsuspected user tries to swap some do I have any guarantee that I always will be used is there a fair this built into new people good question so his question was basically I've now created a pool with a hook and me as a developer how do I ensure that when someone is swapping my pool gets routed to you so that I can collect fees for my LPS on that pool so that is a routing problem which is you know dependent on you know yeah dependent on the interface depended on like where you deploy your pools it's a you I think it brings up like both a unique Advantage where you can kind of have either you know we could go on to uniswap X on how uniswap X kind of addresses routing but basically the short answer is like it does get a little tougher for pools to get picked up because we have to make sure that safety of pools for these protocols it isn't stealing users funds or doing something malicious so there's still discussion on how we solve that right now but for the most part I think we might see some blend of some kind of hookless Standards some kind of protocols like taking the taking the push on how do you actually like implement this into routing so will Labs like route to it automatically I think that's still you know we're still trying to figure that out it'll be the four users that's still yeah that's still being figured out yeah yeah cool great question any other questions awesome well thank you guys for your time and yeah
Automatic transcript — names and jargon may be misspelled.