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

Loading player…

CowSwap & Gnosis Protocol V2 - Felix Leupold

ETHGlobalSat, Oct 9, 2021, 12:00 AM

Felix Leupold, the software engineering lead at Gnosis, discusses the protocol's V2 and its built-in MEV protection. ---------------------------------------------------- Follow us: https://twitter.com/ETHGlobal​ Check us out: https://ethglobal.co​ Email us at: hello@ethglobal.co

Transcript

cool yeah thank you very much um i'm very excited to talk about cow swap um to you guys today um cow swap is kind of the first application the first trading interface that we have built on top of um gnosis protocol version two which is the underlying trading mechanism and gnosis protocol is trying to prevent mav by employing batch auctions and uniform clearing prices as a kind of separate trading mechanism compared to what we know from ethereum today so let's let's take a look at you can basically take any random block on ethereum today and you're very likely to going to find a couple of trades on the same token pair potentially even on the same protocol different indices which will have sometimes slightly but sometimes also significantly different prices um and this just comes from the fact how the underlying protocols work that they basically give a price time priority and the ordering at which transactions are executed even within a block matter and this kind of concept makes sense in traditional finance where we have continuous markets and where we can actually execute trades kind of all the time and we want to incentivize traders to act as fast as possible and kind of incorporate new information as fast as possible into the market price so that the market is very efficient and kind of resembles all the real world information that is out there as efficiently as possible and even in the traditional space there's people arguing that kind of this arms race nanoseconds milliseconds to incorporate new information might not be actually that useful uh compared to the externalities that it costs um and are even advertising for for batch auction kind of that sense but then you know that is kind of this continuous market traditional finance if we go back to the ethereum space we really only get new information every 12 seconds when when a new block is mined and then we get a bunch of new information in the form of multiple transactions but if you look at these transactions they're all really just you know mined at the exact same time so kind of this notion of employing a price time priority within a single block to us is not really meaningful um and i mean frankly this is the reason why meb exists in the first place and and why we are here and so hypnosis protocol version two that also known as pro gold version one kind of our vision is that at least within a single block trades that happen on the same token pair should regardless of their index regardless of their ordering all receive the same uniform clearing price there shouldn't be a difference if you're first or second or third everyone every trade that happens in one block or for the matter of batch auctions in one batch receives the same uniform clearing price so how do we get there there's two main main ideas that we need to incorporate the first thing is we need to stop people from giving their trade execution in form of raw ethereum transactions to the miners because we've seen miners are not acting in your best interests if you don't use technologies like maybe guests they're just going to take your transaction and trying to extract as much value from it as they possibly can so they're not acting in our best interest what we should do instead and what moses protocol does is instead of signing a directly executable transaction the user just signs um kind of intent to trade basically saying i'm willing to buy token a for token b at a certain limit price maybe with a certain deadline um and it then hands off this abstract intent to trade to a third party which maybe in the traditional sense would have been called relayer and gnosis protocol v2 this party is called solver and that is a basically it's a professional player which can execute the transaction of the user much better than the average metamask user would be able to the solver can employ kind of professional price estimation for what gas price to to pick it can even use tools like flashboards maybe guests to make sure that it can it can this is in itself um mev resisted it can look unchained for the best path at execution time if this path is no longer available because there's race conditions can reroute the the trade and so overall this kind of professional party can just do trade execution much better than the the average user can now you might ask why would the solver have an interest to um actually actually act on on behalf of the user in their best interest uh the first answer is kind of well there's a longer lasting relationship between the user and kind of this network of solvers but also at least signals protocol v2 each solver is bonded financially inside the protocol and if it extracts value from a user which is always which is most often provable um after the fact the protocol can penalize the solver and could actually refund the user from the penalty that is taken so we have bonded solvers which can do trade execution much better than the user another aspect of kind of this extra layer of indirection is that now not only can we settle each intent to trade individually we can also start aggregating multiple trade intents together and settle them all in a single on-chain transaction and that allows us to actually be even more efficient than than if every user was going to settle their trade individually because if we batch five or six trades into a single ethereum transaction that costs less gas than settling these five or six trades as individual transactions on chain the the other cool thing that comes from this aggregation is that the solver can now apply certain rules to the settlement so for example the solver can make sure that if two trades are happening on the same token pair both of these trades get executed at the exact same clearing price so the solver can employ kind of yeah uniform clearing prices to a settlement for all the orders that it settles in one batch and this brings us to kind of the second core idea of nurses protocol or cow swap also where the name comes from which is coincidences of ones and coincidences of one's well the general idea is that we want to reduce the amount of volume that we trade against external market makers because those uh charge a fee for this service and if we kind of minimize the amount of volume that we have to match against these we can actually get a better price for users and so coincidence of wants is basically the phenomenon where somebody wants to sell a token for another token and another person wants to buy the token that the first party is selling exactly for the token that the first party is buying and so today on ethereum what would happen let's take uni swap as an example if you had one party selling two thousand us dollars for each and another person that would be willing to buy one each for us dollar they would both hit the uni swap pool they would both pay the liquidity provider fee it might be 0.05 percent now but it is kind of a non it's a significant fee and at the end of the block the units of a pool would actually be in exactly the same state it would have not provided kind of provided a real change or value other than kind of just being a sponge to within that block kind of absorb the liquidity temporarily on gnosis protocol because we have these solvers that are batching traits together they can first perform kind of a peer-to-peer matching within all the orders that are in a block or in in one of those noses protocol batches and then they only have to match whatever they cannot settle peer-to-peer with external entry liquidity and so in this specific example where we have a perfect coincidence of ones we actually don't need any external liquidity at all we can match the two traders directly peer-to-peer now of course more often than not one order will be larger than the other in which case we could still match the small order completely via a coincidence of want and only have to take the excess and try to find the best on-chain opportunity to settle that extra part and for every dollar that we don't settle against external market makers we save fee and we can pass that on to the user to get a better price and now you might say well but how often does it really happen that two people really want to trade the exact opposite tokens markets are directional and so either tokens are going up or down but it's not like you know you have a lot of times that people are trying to buy the exact opposites but that's also not really necessary because if you look at a the trades that happen within a block today you really need to dissect kind of what are the individual hops that are happening on the underlying protocols and so for example if you're buying a project token like curve for us dollar today what would happen most often is that you actually do a two-hop trade on uniswap where you first convert your curve into width and then you make a width against usdc trade and kind of similarly if you were to buy g o with us dollar you would first convert your us dollar into into with and then trade that with against geno and you might see that there is now actually a coincidence of wants in this west usdc part and so even though there's not a perfect coincidence of once there's still some aspect of these trades that can be matched peer-to-peer and where we can reduce the amount that we have to trade with external market makers that are charging a fee so to summarize kind of the meb protection that gnosis protocol or cow swap specifically offers is um basically two-fold uh the first part is everything that we can match peer-to-peer via coincidence of once is fully mav protected and it's somewhat similar to this the rfq system that we've seen in the talk before the prices are agreed to off-chain only the gnosis protocol settlement contract is allowed to execute this trade and it doesn't matter in which position within the block the actual settlement transaction is mined because yeah the only the only entity that can actually do this trade is the moses protocol settlement contract itself so the coincidence of ones are fully meb predicted they are maximum gas efficient because they just trade tokens kind of transfer tokens back and forth and they save the lp free from external market makers then we have the part that is kind of the excess that cannot be matched peer-to-peer directly for this part we have to hit kind of the best available on-chain liquidity source and so that part theoretically is prone to med but here kind of the mav protection comes from the fact that we have a professional solver executing transactions for us and so they can set extremely tight slippage bounds basically zero slippage for any external any external liquidity source they tap into they can use mavgeth or flashbots to even bribe the miner to make sure they get the best price available they can watch the mempool to to avoid race conditions and just generally they can protect the user from meb much better than the average metamask user could and so yeah that's the overview thank you very much thank you for a great presentation

Automatic transcript — names and jargon may be misspelled.