New Ethereum talks, every Monday. The week's conference uploads by event, in your inbox.

Loading player…

Building on CoW SwapProtocol - ETHGlobal Bangkok 2024

ETHGlobalThu, Oct 9, 2025, 12:00 AM

Join us for a workshop with Anxo Rodriguez from CoW Protocol titled, "Building on CoW SwapProtocol." Dive into CoW Protocol's CoW Hooks and Programmatic Orders and learn to build powerful DeFi tools. Learn how to create custom order types and multi-step DeFi actions, unlocking new possibilities for automated, conditional transactions that any DeFi user can access. Don’t miss this chance to deepen your understanding of CoW Swap/Protocol and explore the cutting edge DeFi automation and interaction! This workshops took place at ETHGlobal Bangkok, a 3-day hackathon held November 15 to 17 2024, that brought together the most skilled 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] my name is ano I'm here to talk about hooks today actually about multistep intents but before we do that uh I want to explain what is an intent and I will do it so with an example I need to paint the wall of my house right so one potential solution is to ask this guy Valentino Morris which for now on we will call him VM Valentino is not very very smart H so what I will will do is give him detail instructions on how to paint the wall so you have to hold the brush up and down apply two layers off paint and then H use the tape to not make a mess so the problem is solved is it when I arrive home I find the VM make this mess what do we do in reality we normally call Professional painters so this is a good option because of course BM the this Valentino is stupid but also I'm not the brightest right so if I had to tell to follow my instructions because I'm not a professional p painter myself it won't take him very very far the painter however will have years of of experience doing the job and they can perform optimizations like get cheaper paint H deals like for example doing bulk um treaties and then get more professional equipment like like uh paint guns and they will be faster and cheaper option especially if we let a collection of painters a collection of workers to complete the job let's call this collection of workers from now on cow the painter can screw us somebody can say like you pay them to paint a wall you give them some money and then they screw you for example they could do half of the work and never finish the rest they can use less layers of paint or low quality paint but this doesn't happen in reality because the painter is a professional and his incentive is to deliver a good service so we can call them again and recommend this this professional to our friends what if the problem is not painting a wall but it's something that is 10 times harder 100 times harder or even 10,000 times harder this is what re in reality happens when we try to settle orders on chain and this is due to fragmentation of the liquidity is harder and harder to find Optimal solution and and this is even harder now that we have over 1,000 side chain like l2s out there so nobody can solve this problem on its own so this is our choice we can send the pained instructions to the VM to Valentino and get terrible results or send the a pain job to this collection of workers that would find the optimal execution um if I didn't Hint it enough this is exactly what we do in cowap or C protocol where we send a order transaction so we don't send a order transaction to the VM with detail instruction of how to get the liquidity or execute this trade but we sell it send it to a um collection of workers ER which we call solvers and these solvers have the incentive to to do this optimal execution and can give all these nice features that users of cow swap can benefit from like mab protection gasless trades Surplus generating orders optimal PR pass and the better of all that we can adapt to price changes gas changes and path changes so we enter into the ER multi- intent um orders H this is the life of a cow order the normal one you like the you need to validate the signature and you transfer the sell tokens from the user uh into the settlement contract execute there the interactions that that Acquire The Spy tokens that that the the the trader needs and then send them by the the by tokens so hooks are just two extra steps that we added into this uh process and you can execute arbitrary call Data before your order and after your order and this is done inside a special contract called the trampoline that would uh protect the like it will execute the hook in the context of this contract instead of the settlement for security uh reasons so basically you can do any defy interaction before any CA trade or after your ca trade and this is how it's get it gets done when you send a normal order there's one field called app data that points to a document a Json document with uh the hooks and the hooks is just an array of this triplet of the Target contract you want to invoke the cold data that encodes the the function and the parameters you want to call and then the gas limit that is how much gas you willing willing to pay and remember we are gasless therefore this gas won't be paid in ether or native tokens you will pay it in sell tokens only if you trade so we are very H happy because we are releasing something really new uh these hooks was not no new but but now we can uh allow third parties to create hook dabs that are small uis that people can inject in cab itself and this is what I'm going to show so if you go today to cow swap you'll find this this setting to enable Hooks and here you can find this button to add a preh hook and this button to add a post hook H this these are the the hook tabs that third parties can make or Hackers from this hacker could be making uh and remember since a hook is a interaction with with any defi protocol we could H you could be adding some execution you want to do with any protocol before or or after here we have an example of withdrawing liquidity from our c m I have the only thing I have in my wallet are LP tokens right um and here the developer of this cow hooked up um made this interface so this is really a night frame running inside cop and there's like a thin library for the communication between the the DAP that lives inside and the cab itself and the responsibility of this DB is to create a call to pass the the hook that at the end of the day is this call data encoding the function we want to call on chain here in the the face we can select how much we want to withdraw from this amm and in this case I'm going to withdraw 50% which will give me 136 cow and 0.2 Geno so what we I'm doing right now is uh well Bas basically the the the hookd has access to the wallet so they can sign transactions so this is what I'm doing I'm signing not a transaction sorry A message this is a a message I'm signing so for right now we haven't done any call to to any blockchain we are just sending messages and cab will like the the dab has passed the the the the hook information to cab so they can we can simulate the the execution on chain of of this and calculate the the the token that will be withdrawn these tokens are right now credited here so so they will be part of your balance so even if you don't have uh any balance because we are gutless you could do the interaction that g gives gives you the balance and then you can do the trade so right now I'm adding a post hook that will create a lama lama pay invting er uh contract um I'm just going to create a a new neonic here and send it to this address that I just generated sorry not this one so what this H post hook allows is to send a stream a stream of money which money the output tokens of the swap so right now I'll put uh three minutes I'm sending this you know again I'm not sending a transaction I'm sending a message that will be also um simulated in tenderly and I'm ready to post this this swap still I haven't placed any any transaction but I I just placed um a a meta transaction that the solver will be trying to solve if we look in the Explorer we can see all these hooks here and this is what you really need to do and there's a lot of tutorials ER at the end of the the presentation you you can uh see the the tutorials and and other resources so because we made this easy for you if you want to well this this order was executed and I'm supposed to have this these um tokens already in in the new wallet so I could actually import this wallet here and I I can and remember this is a fresh account I'm using the fresh account I don't have any tokens and what I could be doing is claiming in a gasless fashion without any native token any ether any XI anything the the the besting amount you can see it um you can see how the the connected wallet that this new wallet has this these tokens this gno has been received and now is besting I could claim it let me get the the contract of this sorry that's a easy way to get the contract and I can put it here this adds the preh hook and look what happened here is that I I I can claim already this G like I can select it here the the G as a cell token um maybe I select the native token now and this is one super cool way let me cancel this one and sign this other one so I just posted another order that will give me native tokens on the vested gno that I received from the other token without having any ether uh so this is the the promise of a gasless experience and what we want to provide in in cop uh one more thing ER these hooks if you want to if you want to list your your application there you you don't need to ask permissions you just add your custom hook here um we have examples on on a tutorial how to add it but just add the URL here and it will be loaded um that's all I wanted to show ER there one one more thing this programmatic orders is the other the other product that that gets you a price in this hackaton and it's basically uh something that allows your smart contract to get kind of superpowers to create offchain orders inside the cop uh the only thing you need to do is to implement two functions really the uh is is valid signature that will um that that needs to to say uh well is the the one that have arbitrary logic to say if your order is valid or not valid so as long as you provide your custom logic there then you can H place your order and then this other function that is get tradeable orders that uh should revert if the if the contract if your contract doesn't want to trade or should return the the order that you want to add it to Cup and this this offchain component called Watchtower that will be created in the order for you so there's no infrastructure you need to deploy join these two things together and you have a loal broker working for you 247 plac in the order when the time is right and this is not just Theory but we have uh two orders working already in cup and a lot of implementation of different smart orders so the takeaways are same as we would delegate hard jobs to professional we should delegate execution to Dex uh this brings power and protection to users and all the features people love about cowo hooks allow us to extend intents allowing you to do defi interactions before and after the trade make your own hooks by simply calculating the cold data and attach it to your order extend CA with small pieces of UI as I showed before and programmatic orders will give you your smart contract the super power to create offchain orders at the right time thank you very much H we prepared some documentation for you if you scan the QR it will be better explained that thank you I don't know if there's any questions yes hello yeah so in the post hooks uh the settlement layer transfers the uh tokens to the hook right and then the hook trampoline calls it correct um the the hook is called by by the solvers so because when you at the contract level so contract level so the settlement layer transfers the funds The Hook and the hook trampoline contract calls the hook right exactly yeah the basically you said it correctly yeah and what uh what about the preh hooks pre hooks so the token transfer gets transferred from the users's address to the pre hook account right yeah I really can't can't hear the w uh what happens how does the fund transfer happens in the pre hooks yeah so the Thee the preh hooks you you have arbitrary logic so technically you can the simplest H case you can think is for example an airdrop if you have a per permissionless airdrop and I can claim for you I only need to encode the call to H claim airdrop and pass your address so because uh this call data will be called in the in the moment of set settling this settlement by the solvers then the transfer from the the airdrop contract will flow to you uh and and then you can decide what to do with with those tokens [Music]

Automatic transcript — names and jargon may be misspelled.