Hands-on with Uniswap v4 - ETHGlobal San Francisco 2024
ETHGlobal·Thu, Oct 9, 2025, 12:00 AM
Join us for a workshop with saucepoint. from UniSwap titled, "Hands-on with Uniswap v4." This workshop is a walkthrough of Uniswap v4 & hook development for beginners. This workshop took place at ETHGlobal San Francisco, a 3-day hackathon held from October 18 to 20, 2024, which brought together web3 developers, designers and product builders from all around the globe for a weekend-long adventure to advance the Ethereum ecosystem! ----------------- Follow us: https://x.com/ethglobal Check us out: https://ethglobal.com/ Email us at: hello@ethglobal.com
Transcript
[Music] hey guys um I go by SAU I'm the protocol engineer at the unisoft foundation and today's talk I was just going to do a simple just intro to unisoft V4 um I describe it as this rapbit hole because you'll see see shortly about about like all the intricacies of uh V4 and like what's possible on unisoft V4 um so in case you don't know this is me on Twitter um I'm also known to be like the troll on GitHub as well um so those are some of the funny moments on Unis swap V4 um so quickly on like what Unis swap V4 is and like all the features of Unis swap V4 we have first is like the Singleton design so what that means is every or every pool is managed by a single contract this is different than V2 and V3 where every pool or every trading pair existed as as its own uh smart contract and so if you wanted to trade across multiple pools you're transferring tokens between every single pool um and with this sort of Singleton design you get what's called like flash accounting I think Oiler calls it deferred balance accounting where essentially you can string together a bunch of uh complex operations like Swap and add liquidity swap across multiple pools swap where you create like two or three different like token outputs right like one token input but like three different token outputs and at the very end you only have to do token transfers for the input and output tokens and so that's kind of what flash accounting is um there's something called ERC 699 where essentially instead of trading with ERC 20s you could wrap them as699 which are a little bit more gas efficient uh for like high frequency Traders or like me Bots um there's support for Native eth as well uh so in V2 and V3 you had to wrap your ether um but in V4 you can just trade using native ether so that's a really nice ux benefit uh one new feature on V4 is donations um what donations are are ways to send tokens to the contract which then acre to liquidity providers and so this is just like an entirely new feature in V2 and V3 um which allows you to do really interesting like value distribution mechanisms uh in V4 we also have no fee tiers um in V2 it's at a fixed uh 0.3% in Unis swap V3 there's like four or five different fixed values in V4 it's like fully continuous and then we also have Dynamic fees which is also very uh program aable where you can like adjust fees up or down um the core protocol doesn't make any sort of like hardcoded decision on how the fees should be changing and so that's kind of something for developers to look into and then lastly hooks which is kind of like the bulk of where v4s flexibility comes into play and that's where I'll be spending a lot of time so all these together kind of summarized V4 as being extension of V3 uh with way more flexibility and gas efficiency um oh uni chain um as you guys saw last week we announced a def Centric evm equivalent L2 built on the super chain so I figured I'd just like quickly chime in um it has 250 millisecond flash blocks or like transactions confirm super quickly uh we have this validator network associated with it and then also priority fee ordering slash uh less sandwich attacks happening on on uni chain um but back to V4 and hooks we have so what are hooks uh hooks are arbitrary solidity in the swap life cycle um so what is the swap life cycle it's really the full end to-end experience that you would see on Unis swap so like creating a pool um adding liquidity to it or removing liquidity swapping and then in V4 we also have donate and so what Hooks are are you know separate contracts where you can make an external call and run just custom logic before a swap happens or after a swap happens um so that's a quick little summary on hooks this is what it kind of looks like where you implement a contract to a certain interface standard and then inside this function you can really do whatever you want as long as it's valid solidity and it runs um you can run any sort of logic you want before a swap happens or after a swap um I'll probably do a little Deep dive a deeper dive soon but just wanted to show the code here uh before we get into it though it's kind of good to have some context on the difference between like a hook and a pool um they're kind of synonymous with each other um and so uh you can think of pools as independent unique sets of liquidity positions right uh pools have at most one hook contract and then the hook contract implements these hook functions like before swap after Swap and then you can mix and match right you're not forced to use every single hook you're not forced to if you use before swap you can use after swap it's kind of up to you um so that's a little bit more context and to really highlight this point we so here's the code snippet or the interface for creating a pool um critically you can see that whenever you create a pool you define like the pool key and that's the pool it's a unique set of liquidity positions and what the pool key is is it's the trading pair associated with it um the fees this parameter called tick spacing and then lastly you can see Hooks and so every pool has one hook contract um the cool thing is one hook contract could service multiple pools right you can design a hook contract that Services eth usdc eth tether eth BTC you're not restricted that you know this Hook is assoc tightly ass associated with this trading pair um and so back to like before Swap and after swap um things that I wanted to call out with the interface is so in before swap you will always know which trading pair you're operating on uh you know it's possible that your hook is specifically tailored for stable pair so like usdc and tether or your hook supports like you know eth and stake eth and so you can like discern different logic dependent on the pool um in after swap you actually get the results of the swap so you get both how many tokens were sent in and how many tokens were going to be sent out and so you could run Logic on that where you know if you wanted to do like bonus Rewards or collect fees on your hook proportional to the swap result you could do that as well uh um I also won't really go into the liquidity side but we do have hook functions here they're separated out based on adding and removing liquidity this was like a security implementation um but so there's the liquidity hooks um now on to like hook ideas so this is kind of where the rabbit hole really really opens up uh so one thing you can do like I said is like Dynamic fees and fee optimization you can create like incentive structures where you know if You observe gas to be really low let's decrease the fee to like incentivize some volume You could argue that it should be the other way around where like if gas is really high the markets are fluctuating a lot and therefore like LPS might want to capture more fees um so there's fun things you can do around fees um Dan Robinson a couple months ago put out this really cool work called uh sandwich resistant amm where for given Direction uh let's say you're trading eth into usdc so over the course of a block normally in V2 and V3 as people are trading eth into usdc the price goes up up and up right or I guess down um but with sandwich resistance you kind of pin the price at the start of the block and every single trade within that block uh fills at the same price you can do things like automated liquidity management so after swap you could compound some somebody's fees like Auto compound their fees you could expand their positions you could decre uh you know concentrate their positions there's a lot of like fun little like liquidity management things you can do inside of a hook uh we could do like rebasing tokens or support for rebasing tokens so things like the a tokens uh Lio Stak ether you could support through a hook either by sort of wrapping it as wrap steak ether or you can create like this custom pool that lets you essentially manage uh Lio stake ether um so yeah automated wrapping and there's a feature in in V4 it's quite Advanced but it's called custom curves and it lets you sort of eject or circumvent the V3 swap math and sort of implement your entirely own custom curve uh another aspect related to custom curves and this is kind of like a a Hot Topic these days is like application controlled execution and the idea is like you could write logic inside your hook that controls actually the order the sequencing of Trades that are happening against this pool so like what if you introduced like a bidding mechanism and transactions are ordered based on a bid or you could somehow like prove the time stamp of a trade and you know order based on time stamp and so there are some things you can do inside the hooks uh as for more General V4 ideas like you know our bounties and our prizes aren't really just uh hooks themselves we have uh liquidity mining with subscribers subscribers are like a new feature in V4 that lets you do liquidity mining so in V3 if somebody was saying like oh I'll pay you x amount of money to provide liquidity what you would have to do is you would have to transfer your LP position to them and that opens up a lot of like security risk and so subscribers essentially let you do that without having to forit or like sacrifice your liquidity position uh one thing that I haven't seen really is liquidity position oracles um so if you wanted to collateralize a liquidity position on like a lending lending protocol you need a way to like price the value of the liquidity position and so that's one project that you guys could work on um like I said about ERC 699 it's like this sort of token wrapper and so if you could build like some sort of staking system for this uh token standard that'd be pretty cool as well uh lastly we also have like developer tooling so things like maybe like back testing LP performance because like one of the things that we're super optimistic about at the foundation is like LP profitability right um You can design hooks that in increase LP profitability but it's always good to like back that right instead of just going out on Twitter and saying like oh this Hook is amazing um so building tooling that can like verify and like back test a pool's performance I think is pretty sweet uh testing kits of course are super useful and then lastly like indexing as well uh is also like a really great topic within V4 cool uh as for the prizes we have three categories the first one is hooks um some ideas like I mentioned are like Dynamic fees Uh custom curves for like stable pairs rwas are very like nuanced and specific tokens like I guess the the two categories of hooks that the foundation is super excited about are like one anything related to LP profitability and then two are like pools that are like specially tailored for certain types of asset classes um and so this like Sable pairs rwas you could say meme coins as well um and there's an idea called like penalty hooks where you know with the custom accounting mechanism you can kind of charge fees or charge penalties that if people are like misbehaving in your hook like they're doing just in time liquidity um you can sort of penalize those uh our second category is this like catchall categories that if you're you know building on un swap V4 but not directly building a hook um you could be eligible for a prize so that's like liquidity management developer tooling me lvr research um token issuance products are also really cool and then our last category is like just deploying a dii app on uni chain it doesn't have to be Unis swoft specific any sort of dii app would be eligible for the last category um and so I go by SAU Point that's me on Twitter Telegram and GitHub you can find docs on docs. uniswap and then the uniswap foundation has this like starter template called V4 template that lets you get started on hook development super easily um and then with that I can open up the floor to questions I know we do have a mic for the recording so if you do have a question feel free to go up to the mic if you're uncomfortable with going up to the mic you can just ask it and I'll repeat it for the crowd so [Music]
Automatic transcript — names and jargon may be misspelled.