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

Loading player…

Building with Cowswap's SDK Angel Rodriguez

Ethereum DenverSun, Oct 9, 2022, 12:00 AM

Transcript

okay thank you okay so let's start explaining what is cow protocol um so cow protocol is a meta dex aggregator what it means is it's a decentralized exchange but also aggregates liquidity from different sources for example uniswap or sushi shop but additionally it aggregates it other aggregators so that's right it's an aggregator of aggregators additionally it provides to the users maybe protection by default so without thinking the user will get protection from front running or sandwich attacks on the left you see this screenshot of khao sob and khao sub looks like unisop is a it's a shop interface but don't be mistaken because underneath this some cool architecture let's dig a little bit deeper by seeing a simple workshop a workflow so a user place an order what is an order in cow protocol an order is a limit order so you define a limit price that will be executed at that price or better and then you have a deadline so it will execute before that deadline or not at all but one important change with other taxes is that there's no transaction cost for submitting an order so it's totally free this is because it uses meta transactions so you sign it off chain and then submit it to our off chain api does this mean that is free to trading call swap and inco protocol not at all you have to pay some fee in self-talking but the difference is that first you paid in is included in the price so and als also it only you only pay if the trade goes through so this means that you don't pay for reverted transactions or for expired orders there's another big change compared to other dexes and is the existence of these so-called solvers solvers are external parties that will try to bundle trades together in batches so they will try to find the best price and they do so by looking into on-chain liquidity so they can provide the same prices as other exchanges like uni-swap sushi swap and also aggregate other aggregators like one inch but it doesn't stop there this this other concept of matching orders peer to peer so when two users send the order at the same time and they will be matched in the same block and it won't be necessary to match against external liquidity this is what we call coincidence of wands or for short cow and give a name to this protocol one other interesting concept is the objective criteria the objective criteria is just a way we have for ranking these solutions these batches proposals for for from these solvers and decide which one of those is the the one maximizing the benefits for the user so it's an objective criteria and it helps with the competition and and the and creates this symbiotic relationship between the solver and the users note how this symbiotic relationship doesn't exist in other exchanges where the one executing is the miner and the miner have the opposite incentive the miner will try to screw the user by reordering the transaction within a block just to exploit their limit price so after all the solvers provide their solutions the best one is chosen and then all the trades are bundled in a batch it will be executed on chain i know it's a lot of information so bear with me this is documented very well so it's pretty interesting if you didn't understand all of it don't worry just read the documentation it'll be clear enough so what we want to present today is this challenge we create this hackathon boutique to to build a ui or an integration and the price is 7500 dollars so what we want is to increase the order flow so so the challenge is to build a ui or an integration with the potential of highly increasing the volume and trades happening in cow protocol there will be other bounties so please check out the last slide so why would you care why would you want to build on top of this protocol first of all this is a brand new protocol we have been only around six like a few months and we have been seeing this rapid growth and it's because of this setup and architecture we can deliver better prices and we have a special properties that is tailored to the blockchain you can see how we are scaling up in this in this ranking of dex aggregator and since we're having only a few months we believe that this year we will be way on the top also because we we have pretty we are pretty new i think it's interesting to be part of this growing a fast-growing project for us growing community that by the way this project was kick-started by gnosis and um it is it has spin off last week by boat of gnosis dell and now it has its own dao and its own token there's 50 000 address addresses in this dial and it raised 10 million dollars this money will be in the in the dow for incentivizing um things like if order flow so if you decide to to build on top of a copper toggle on top of winning this this challenge this bounty you can also have a um a future earnings by asking the dow to receive some some tokens or some money for bringing overflow so why order flow why is this important one property that this proto protocol has is that the more volume we have the more orders we have the the better price that everybody gets so you you make the protocol better by bringing liquidity to it and our estimations are that without having our own on liquidity just by using external liquidity and and because of our efficiencies we can get 0.5 percent price improvement but how this is due to the coincidence of wants that gives name to our protocol and this is this phenomenon where two users want to trade at the same time since the blockchain is discrete anyways that this blocks every a few seconds then there's gonna be people trading at the same time opposite orders so when this happens and it happens all the time when this happens we can get like gas cost savings because it's cheaper to submit a bundled transaction with a several trades than the cost per trade reduces so the user needs to pay less gas so they get a better price also it's cheaper to settle a trade peer-to-peer gas-wise than doing it in a in a automatic market maker like uniswap additionally if you don't go to unisop to take this liquidity you don't have to pay this liquidity fee that normally you would need to pay so when a trader trades something they will need to pay this 0.3 percent per hop and then the opposite trade will do will pay another zero three percent per hop again and is compounding so because you don't have to pay this fees there there you got another benefit of coincidence of ones and last but not least it protects users from meb extra extraction and how is this possible imagine two users trading at the same time their volumes will be cancelled to each other and be executed in an atomic transaction this volume that is cancelled doesn't matter that you reorder this transaction within a block it won't be exploitable so there's more protection all these take us to better prices and more peace of mind for the user now zooming in a little bit let's see how what do you need to do in order to bring order flow you will need to approve a token for trading this is pretty standard for all the taxes so it's something you have to do only once is sending this transaction to ethereum for this erc20 approval once you do this one-time thing you can send any number of orders for free and and the process is the following you get a price from then an api then you sign an order and then you post a signed order the the solvers will be observing these open orders finding this solution running this algorithms to find the optimal liquidity paths for for the users and then submit this batch that include the execution of these trades so note how the solvers are the ones paying the ether for the transaction and not the users however they get the money back because the users agree on paying a fee but only if they trade not if they don't so continuing life assuming a bit more how do we get a price why one way to do it is just to create this a cow protocol api and it's as simple as submitting your intent to trade you say i want to trade sell i'm going to sell 10 west for usdc and the end point will return the price the fee and the expiration the the price is straight forward the fee is the amount of sell token that you need to pay in order for the protocol to accept your order and what it calculates is how much cost your order to be settled on chain and it's assuming that other people will be sharing your cost in in the in the bundle so you will get a cheaper price then what we need to do is sign in the order how do we do that this is different options for different scenarios the the most common one is the off chain signing i was mentioning before this using eap 712 this allows gasless trading for eoas like metamask this is the approach that cow swap uses however this this other method that is pre-signed and is just a smart contract call and allows protocol integrations so if you decide to instead of doing a ui doing to do a protocol integration you would be using this then this this last method that is smart contract signing is aap 1271 and allows gasless signing for a smart contract it's pretty cool and supported by the protocol however it's not supported currently by the api but will be soon so we have to prepare our raw order in order to sign and the raw order will have all the fields that you you would expect like the cell token by talking but then you need to define the price by the sale amount and by amount by the relationship and what price should you use it's up to you if you set the price too high it's going to be a limit order it will execute in the future because it cannot be executed given the current market price if you so for example what cow swap does is allows the user to select his slippage and then you we apply this slippage to the price return by the api i mentioned before and then you provide a fee amount that was returned in the previous step so once you have the raw order you sign it and you sign it by using ep712 but for convenience we created these npm packages that you can use for signing in a simpler way this part is abstracted this is how it looks cal swap when you sign an order so you'll see this structured data with all the fields of the order this is how we define the order once the user review this information they can sign it so next step once you have a raw order signed is to prepare the sign order that we need to send the raw so so that's trivial because we already have the raw order so we only have to add the signature that we we got in the previous step then with this sign order we post it to the api and the api will return a unique identifier this unique identifier will become very handy in if you want to check the state of your order that's the normal thing to do after so there's two ways you can check the state of an order first the first is just to watch for trade events in the settlement settlement contracts so every time a solver delivers a solution in a batch there's going to be a settlement with a a bunch of trades okay i'm going to wrap it up so the other way is using the api and there's a convenient er endpoint for that wrapping it up cause a capra toco is a meta dex aggregator with some property it's gas less don't you don't pay for reverted transactions it aggregates any on-chain liquidity and it's mav protector and it finds coincidence of one which gives you better prices calzob is its interface and and is powered by cal protocol we are launching this a hackathon boutin of 7500 and the goal is to build a ui or integration that increases the volume and trades i hope this is interesting for you and you decide to to build on top if you don't do so we have a lot of resources you can use and examples with just snippets of code just scan the qr code on the left thank you very much happy hacking [Applause]

Automatic transcript — names and jargon may be misspelled.