What does it take to become a solver in CoW Protocol - CowSwap - Felix Leupold
Ethereum Denver·Sun, Oct 9, 2022, 12:00 AM
Speaker
Transcript
almost there yes cool thank you all for coming my name is felix i work with cow protocol and i'm here to speak to you today of about what it takes to become a solver inside the car protocol and so this talk is maybe a little bit more on the advanced side it's not an insurance to car protocol or cow swap but i'll still take two minutes in the beginning to get everyone on the same page and explain what cow protocol is to begin with so very fundamentally you might have heard about car protocol by another name cow swap and to differentiate the two cow protocol is really the trading mechanism that underpins the ui the exchange that we've launched that is called cow swap and now if you look at the at our our exchange you can see it looks very much familiar to uniswap in fact it's a ui fork of uni swap with a small but fundamental difference the fundamental difference is that we add a very thin batching layer on top of existing amms which allows us to aggregate multiple trades together and execute them in a single ethereum transaction and what this allows us to do is if for example i am selling ether for usdc and somebody else is buying ether with usdc roughly around the same time we can just trade peer-to-peer we don't have to hit an external market maker we don't have to hit an amm we can save on transaction costs we can save on price impact on lp fees and so we can in the presence of these coincidence of wants you wanting the opposite good of me in in the presence of these cows cow we can offer structurally better prices than existing deck segregators and existing amm protocols the batching comes with another uh nice side effect is and we'll talk a little bit about more how this works because it's really crucial to this solver infrastructure um it comes with a nice benefit that cow swap in and off itself acts as a meta dex aggregator so no matter uh which platform offers you the best prices for your trades currently on chain cowswap will make sure that we query prices from one inch from powerswap from matcha from the different protocols directly and make sure that you're always guest the best execution across all these dex aggregators at the same time it takes care of preventing your trade from being value extracted by miners searchers frontrunners arbitragers in the system so what cowswoop does it guarantees you as a user it guarantees you a price which is decided based on a competition that i'll talk more about in the next slides and then the risk of that price not being fulfilled because of maximally extractable value because a front running or sandwiching is taken care of by that third party that executes the trade for you and then last but not least because you're not actually executing trades yourself but instead giving us an off-chain signature of your limit order um well basically yeah it's an off-chain message you are not paying any gas for the trades that you're doing you're still paying a fee the fee is being captured in the sell token so the token that you're already trying to get rid of but there's no eth that you have to leak that you have to sell every once in a while when you're making swaps and another nice side effect of that is because you're not sending any transactions nothing that you're sending can fail so you don't have failed transaction costs so this is just a little like you know com summary slide of what cow swap does let's dive a little bit more into the protocol and see how it's fundamentally different from today's dexes index aggregators so if you trade on ethereum or any blockchain really today what you're doing is you're sending a layer one transaction where you're telling the miner what exactly you want to do you want to trade a certain coin for a certain other coin on this specific protocol and you're passing that signed transaction to the mempool for the miner to fulfill but in reality to usually try to screw you over as much as they can on cow protocol instead you're assigning an off-chain message which looks very much like a limit order similar to the transaction which also is a limit order on for example uniswap but instead of handing it over to the miner you head it over to this third party which in other protocols might be referred to as relayers but on car protocol it's called a solver and then that solver can batch together multiple transactions multiple intents to trade into a single layer one transaction and execute those trades in bulk and so that can save on execution cost it can have these nice coincidence of ones where we are trading peer-to-peer and reduce the amount of fees that we're paying to amms but it also allows the solver to take care of mev protection and make sure that the miner cannot value extract you now the kind of intuitive question that people ask is like well okay if the miner doesn't value extract me how can i be sure that the solver doesn't value extract me and so this slide is actually wrong it's not a single solver that is processing your orders for you instead it's a network of solvers in fact what solvers are doing is they are competing for your order flow and they are proposing settlements to the protocol and the protocol picks whatever solver has proposed the best has proposed as the best settlement in terms of global welfare and we'll talk about what that means it's basically price improvement for each individual order we'll talk about this on a on another slide but really the the key point to take away here is it is a network of solver solvers that are competing for your order flow on price so the best price execution gets the right to execute your order flow and chain so speaking of solvers and speaking of the current status quo what kind of solvers are there on car protocol today the very basic ones are what we refer to as single order solvers so those solvers don't really make any use of the aspect that they can cross retail users with retail users directly peer-to-peer they just take every single order that's in the system and ask one inch 0x power swap unit swap directly we balance it directly how would you settle this order if it was the only one in the batch and by virtue of having this type of solver we are already a meta dex aggregator because whatever solver from these four sources reports the best price is ahead in the race of getting the right to execute your order flow on your behalf now of course we're called cow protocols so we really want to make use of these coincidence of wants and look at these batches holistically and try to find overlaps peer-to-peer trading opportunities so a second type of solver that we run is a batched dex aggregator solver where we still use the apis of the underlying dex aggregator protocols but we look at each of the individual legs that are being taken one by one let me give you an example if i were to sell gno for usdc and somebody else were willing to buy a balancer token with usdc then on first sight there's no coincidence of once because we're not trading the same token however if you ask xerox how would you execute that trade they might say well you take gno to eth and then east to usdc and for the other trade you take uscc to eth and then east to bell so if we look at these hops individually we can actually find a coincidence of wants and that is what the batchdex aggregator solver is doing this third type of solver then goes a little bit more into math heavy optimization because one aspect of these batches that we solve in cloud protocol is that they are not just based on a single token pair if you look at a batch it can have many token pairs many sell and buy tokens in the same auction and so what you really want to do is you want to lift these two-dimensional order books that you are used to from your centralized exchange into a multi-dimensional space and try to even find more liquidity by the virtue of ring trades so for example if i were to sell eath for dye somebody were to sell die for cow and somebody were to sell cow for eth on a just normal order book exchange we wouldn't see that there's actually an opportunity for trades but on car protocol we can trade those three orders in a ring and therefore re-aggregate fragmented liquidity and so our mixed integer solver our mips solver really just lifts all the limit orders we have into a multi-dimensional space sweeps in some am liquidity and tries to find the global maximum optimum the global optimum for surplus distribution in these in these limit order functions um the mip solver is a little bit uh restricted in the type of amms that it can work with so it doesn't work well with uni swap b3 or curve so we have an even more sophisticated math heavy solver that is running a quasi-linear optimization problem and that is able to also model um basically arbitrary demand curves um you know arbitrarily complex amms and off-chain protocols this is just like an overview of the solver landscape today and what i want to get at is that you don't have to be a math heavy expert or you don't have to be you know these might sound a little bit intimidating but if we look at the distribution of which solver actually wins the race today we see that the pie is relatively evenly distributed and that there's a lot of opportunity to grab a slice and grab a piece of cake in that pie so about 40 percent of the trades currently are solved by 0x just because we also still have a lot of batches which only have one order in them however one inch is catching up quickly we've we've recently released a fix that makes them on par with with 0x but we can also see that our mip and quasimodo solver also take account for about 30 of the cake so there's a lot of opportunity that can be um done by virtue of looking at trades you know holistically and trying to find cows but even the other solvers they're hovering somewhere between five and ten percent meaning that you have if you have some idea of improvement some idea of how we can just make something we have today a little bit better chances are you can actually grab a significant chunk of the spy and so the question really is why should you run a solver what is it in what is it for you if you decide to take a step and run a solver for the protocol well the first reason is that you will contribute to users getting better prices so you might be a user maybe you're a protocol that where you want to enable that the protocol can trade on cow swap effectively so you want to achieve better prices for your protocol users but also you know if you're not maybe yeah if you're not altruistic enough for that we are also working on a incentive program which will hopefully come out next week or the week after where we're going to start to reward cow tokens so our project native governance token to the winning solutions of each batch so a solver can really be a business model if you um have an idea of how to achieve better prices for your users you can really make it a business model and uh yeah and and gain gain money from that and for us white is really important for cow protocol well of course we care about our users a lot but it also makes the underlying game theory and the underlying protocol much more robust against failure and abuse currently most of the solvers are still run by gnosis the company that our protocol has spun out of and so if there's a failure in the gnosis data center if um all solvers that knows is running goes down users are not as well protected as they should be and so we really want a heterogeneous landscape infrastructure of parties running solvers for us so let's say i've convinced you that it's a good idea to run a solver what would you have to do what are what is what is you want to compete in this competition what are the rules of the game um these rules can change slightly we're still you know trying to get the incentives completely right but i think by and large they're they're already you know they already give a good idea of what the solver competition actually does so as an input you're getting buy sell and limit orders across different token pairs from our customers from our users and those orders can be fill or kill or partially fillable they have an expiry date and they have a limit price and then you're supposed to find a matching for these limit orders where demand equals supply of course you're allowed to sweep in any external liquidity that you'd like but basically there are a few constraints that your matching needs to satisfy the first one is that we enforce uniform clearing prices across different tokens that are traded in the same batch the idea is that if i sell usdc for eth and you sell uscc for eth we're if we're mined in the same block in the same batch there should be no time priority um for one of us because really this this batch this block happens at one atomic point in time and the reason why mev exists is because miners can arbitrarily decide okay you go first i go second this guy goes third but we think that this price this time priority pricing within a block really doesn't make any sense for time discrete blockchains which why on our protocol you really just have one price per token per batch the second constraint is something that we call envy freeness and it goes a little bit along the idea of not being able to censor orders that you might not want to match because you're trying to extract some value from from from another trader just as an example if i were willing to buy ether at a price of let's say five thousand dollars and somebody else was willing to sell me to ether at four thousand dollars a solver would not be able to take my order and match it at let's say four thousand five hundred dollars because that would leave the person that was willing to sell it jealous and basically envious at the end of this of this batch uh because they say well if the price is 4500 i'm willing to sell and so we cannot announce prices that will leave any of the trader jealous for not having been uh matched but even if you fulfill all these constraints there might still be multiple settlements that um yeah that basically fulfill all the constraints then we need a judging criteria or basically an objective criterion that allows us to maximize some value to decide what is the best solution and here i've hinted at this before but here what we do is we look at the difference between the limit price that the user has announced in their order and the price the execution price you are offering that user so if i was willing to buy ether at five thousand dollar you got it for me at three thousand 3 500 i make a surplus of 1 500 and so if we sum up that surplus over all different user orders that is the thing we want to maximize now for completeness we do discount the execution cost especially on ethereum mainnet it's very expensive to execute routes and transactions so if you just can get a one cent price improvement it's probably not worth while to touch two or three more pools so you know we offset that surplus by the gas fees and by the fees that the user is paying us for their order but by and large the thing we want to maximize is the overall surplus across all user orders so to summarize if you're running a solver what is the input that you're getting and what can you do we already talked about the type of orders you're getting basically these sell and buy limit orders um we are also going to give you some idea of baseline liquidity that there is on ethereum like uni swap v2 pools sushi swap pools balancer pools just in case you have no idea about defy and about the protocols that are out there you still have some base liquidity to work with we then give you a price estimate for all the tokens that are traded inside the batch and that is needed because we measure the surplus across all orders but if i'm getting surplus and die and somebody else is getting surplus in geno we need to kind of well normalize that surplus into a common numerator and for that we use price estimates and we can basically get make sure that the surplus is measured across solvers in in the same unit in ether for example we then also pass down a gas price because as i showed in the slide before if gas prices are really low it might make sense to have a more complex execution touch more external liquidity than if gas prices are really high and so the solvers need to know what is the current gas price in order to optimize properly and then we also give the solver a deadline which is i think at the moment roughly 15 seconds it might go down a little bit but because we want to run these batches quite frequently and eventually once per block we need to make sure that solvers cannot take arbitrarily long time to to solve these batches so then let's take a look at the solver side and what kind of solver do where really lies the the competitive advantage that a solver can take first thing is you can add your own liquidity and that is really where one inch matcha and power swap currently gain points is because they have a really good understanding of the overall defile system they know all the new protocols they can integrate them and index them so they really know a lot about liquidity but even if you're a protocol that is new to the space or you know you might be a deegan that knows a lot about the ethereum ecosystem you could for example integrate uni swap e3 or curve or some other liquidity and buy this try to you know have more to work with and then um you know do a better job at step two step two is all about the math basically matching orders between one another looking what is the access that i cannot trade peer-to-peer that i need to go on chain for and then yeah basically using the liquidity we've added in step one to optimally settle that part and then the third step which is not really relevant today but we are planning to enable it in the near future is that if you were to win this competition and if the protocol tells you okay go you have the best solution then you also need to be capable of actually executing that transaction on chain and so for this it's really important that you know what other trades are in the what other trades are in the mempool what um you know maybe mev protection mechanism exists out there using flashbots using the eta network so it's really like these three pillars that where a solver can compete and even if you're just you think you're of an advantage or you're good at one of them it's probably worthwhile to kick-start a solver and and and take part in this competition now let me talk i have two minutes left so let me talk about the cow protocol architecture which shows you where you can integrate a solver today so we have the centralized component at the moment which is collecting orders for users and then we have another at the moment still centralized component which we call the driver you could think of it like the auctioneer or the judge that basically orchestrates the competition so periodically this driver will try to get all the orders from the order book and will ask the fleet of solvers that has just registered with him what is the solution you would give me for that input file that i showed on the previous slide and so you're getting the input serialized as json and you're expected to give us a result which shows us which trades you want to settle at what prices and what are the on-chain interactions that are needed for it and then the driver will rank all the solutions internally look which ones will fill the constraints look at the objective criterion and settle the best one on chain and so really if you want to be a solver today all you have to do is spin up an http instance that takes the instance.json file runs your code and returns the result um you know to our driver in the future we want to get rid of the driver component so we want to have a batch that gets you know initiated every 30 seconds or so so the the solvers themselves will get the auction data from our order book they might even figure out themselves who is uh submitting who announced the best solution and they will then be themselves responsible for settling the transaction on chain and so i'm unfortunately out of time but we have a bounty at east denver that would really like you to get involved in for 7 500 we have some more tutorials here from our community member on how to write your own solver we have a more math heavy uh tutorial on that goes really into the weeds of the optimization problem and we have some basic ideas of what you could try out to have a good chance at um you know winning the winning the prize in any case we have a booth right next here in one of the corners next to the between the one-inch team and the super fluid team uh please reach out to us also on twitter we are at meth protection and if you see me around i'm also more than happy to talk about solver stuff thank you very much for your attention thanks
Automatic transcript — names and jargon may be misspelled.