dƒusion - A Scalable, Fair Exchange
EDCON 2019 · 13 Apr 2019 · 16:55
Fragmented token liquidity and front-running are the problems this proposed exchange mechanism aims to address. It would use three-to-five-minute batch auctions with uniform clearing prices, while ring trades connect orders across token pairs to increase volume. Computationally hard optimization would run off-chain through competing solvers, but the project was still work in progress: encryption was excluded from the first version, and an optional order-collection service might also be omitted.
Speakers
Topics
From EDCON 2019, hosted by EDCON.
Transcript
I'm so next up we have another speaker we have Felix Leopold who is software engineer at canosa and he'll be talking about diffusion a scalable fair exchange welcome perfect thank you very much hi my name is Felix lope old I'm a software engineer at Knossos and today I want to talk about diffusion which is one of the decentralized exchanges that we're working on it aghhhhhh no --ss and I want to focus particularly on the market mechanism of diffusion because it's fundamentally different from the market mechanisms that you might be used from existing existing centralized or
decentralized exchanges and just a quick disclaimer to start with this project went from research phase to execution phase earlier this year and we're currently working hard on getting a like test net demo out and hoping to achieve this by the middle of this year but right now this is not on maintenance work in progress before I start talking about how diffusion works in detail I want to start by introducing some of the motivating thoughts behind the market mechanism when we look at asset trading today what we can see as a picture as as shown here on the Left we can see usually trades happening between dominant trading pairs and in these
pairs on one side there's usually the same token so any theorem that would be either it could be US dollars could be Bitcoin but usually when you want to trade an A or C 20 token you trade it first into ether and then trade it back into some other year C 20 token that you might want to get and that's true on uni swap or most of the exchanges that you can see today however in the future what we predict is going to happen is we're going to have a much more dense much more complete trading graph more like you can see here on the right and you could just think about general year C 20 token explosion and how this will might make this graph more complete but even if you just look at stable coins for example you could envision that the USD
today holds something like a hundred million dollars of liquidity in some exchange but with the rise of die tether and all these other stable coins who are all worth $1 that liquidity might get fragmented and so you might have 10 million dollars and died 10 million dollars in tether and so on so people will want to make trades not just to one dominant trading token but kind of wanna trade tokens directly against one another and if you look at kind of like the liquidity of year see 20 tokens today you can see that there's a lot of tokens which don't have another liquidity to be effectively traded on centralized and some of them not even on decentralized exchanges because these exchanges trim tend to focus just on high-volume tokens
but if we want to for example trade prediction market outcome tokens which is wide gnosis is really interested in the space but also general financial derivatives game assets which tend to be low liquidity tokens we really don't have an effective way of doing that today but if we want to tokenize the world and make it easy for people to trade one asset for another we need a market mechanism that can do that the other thing that we're seeing today is that the prevailing market mechanism are pseudo continuous order books with market makers and market takers order makers in order take us when I say pseudo continues because since decentralized exchanges usually do their
settling on the main chain and since we have a block size of 15 seconds it's not really continuous trades can only really happen every 15 seconds but the real problem of these kind of continues order book auctions is the problem of front-running order takers have an advantage the sooner they see an order that has been submitted to the system which leads to them trying to be very close to either the operator or the mining pools and it creates this arms race for arbitrage which is not a sign of an efficient market as it only profits high-frequency traders but goes on the expense of everyday people who are just trying to exchange the assets and fill day and has given a talk at DEFCON 4 and
has just released a paper this week and that actually analyzes the problem of front-running in d central exchanges Ani theorem today and he kind of shows this is a graph that you can find on front run me which shows that there is an excessive bidding war of gas for transaction and happening already today on decentralized exchanges when people are putting in either a very beefy order or even a mistaken order where they just have an off by one error in their amount and so there's a huge opportunity for whoever picks up this order first and you could see a bidding war in gas price happening on the network to try to take these basically risk-free arbitrage opportunities and in his paper he estimates a lower bound of
the revenue from these risk free arbitrage trades to be 1.6 million dollars on etherium per year even today so what we predict what will happen is that people will want to have a way to trade assets in a front running resistant way and the way that we usually achieve front run resistance see for example in ENS is with a commit revealed scheme so in the case of orders we would have sealed orders that are collected over a period of time that are encrypted and then once the collection period is over people could reveal their orders but there would be no way to squeeze an order in last minute and at the time when the order collection process is open nobody knows
what is actually in the batch and so the market mechanism that we are that we are suggesting does not in its first version entail encryption and decryption of orders but it is a discrete batch auction mechanism which will make it very easy to bolt on this commit revealed scheme in like one of the first iterations of this version so let's talk about the diffusion mechanism I already hinted that it's going to be a batch auction mechanism so let's first look at how a batch auction will work with just two tokens so we are collecting orders over a predefined amount of time and right now we envision this to be something between three and five minutes and when we have done this we can start
printing or we can start collect we can start yeah drawing an order book just like we do here on the slide and this order book might remind you of order books that you can see on classic centralized centralized exchanges today with the difference that the by and the cell line actually overlap and that is because what we collect orders over a batch so you don't really like if in a classic order book if there was an overlap the order would be immediately executed and this is why you're buy and sell line kind of approach each other but they they stop right in front of each other and you have a gap in between there which is your spread but in order in in batch auctions you don't have the spread you have a you might end up with a negative spread and so this all this
gray area under the curve is the amount of trading that can happen so what we can do is we can fix a price that tries to maximize all the trading that can happen within a batch and the metric that we optimize for is not just the volume it's something that we call the trader surplus now trader surplus is very similar to volume it's basically for a given order we take the volume of that order and multiply it with the difference of limit price and the market price that was fixed the red line that is fixed there and the reason we do this is to ensure that the people that bid on the lower edges of the graph so at the very end spectrum of the price range are prioritized over people that have placed
an order at the very very close to the market price so if there's a final order that can only be fulfilled fractionally we make sure that somebody that gave a very low sell order or a very high buy order gets it prioritized over somebody that was very close at the optimal price but the key point here is that we settle all orders at a uniform clearing price at this redline price so you are incentivized to give us your true willingness to pay as a limit you don't have to guess what will be the fair market price and try to be as close to there as possible and it also prevents already people who put in very beefy orders or even off by one error orders because they will not overpay and
everyone will just be set back kind of to this optimal uniform clearing price the second concept that's important to understand diffusion is the concept of ring trades and that kind of caters back to the idea of having a very fragmented token space with with liquidity and now for this example let's assume that B and C are both stable coins let's say die and tether and that we have a somebody who's trying to sell token a for token B but we don't have a reverse order nobody is trying to sell token B for token a but given that B and C are both technically dollars there might be a market maker that is willing to trade one dollar for one dollar or
with a rough with a small margin all the time and then there might be another participant who's willing to sell token C for token A and now by looking at this graph in total and not just at orders between token pairs we can actually fulfill a trade and we can trade token a for B B for C and C for a and increase the volume that we have in our batch so by not only looking at order pairs directly but looking at the whole graph and trying to find loops or rings in this graph we can actually increase volume in a completely fragmented space and now taking these two ideas together the batch auctions and drink trades what we end up getting is a network of tokens where between each token pair we can
draw one of these order books and we can set a price for each token pair and then we can draw these prices in a multi-dimensional space so here we have three tokens so we also have three prices and so we end up with a three dimensional space and so each point in the space kind of signifies a price between a and C C and B a and B and then the color kind of says okay what will be the trader surplus what would be the kind of a fair volume that could be could be achieved if we fix these prices and so now you end up with a classic optimization problem you can just go over the space and try to find the dots that are the most yellow because they will give you that will basically tell you what your price is you have to
choose to get the most trading surplus and now of course this is a very computationally expensive problem in fact it's a mixed integer linear optimization problem and the way that we formulated at the moment it's np-complete or np-hard at least and so it's nothing that we could run on the blockchain directly but we don't have to can run it off chain and we just have to verify that a given solution is valid in that it satisfies a bunch of constraints and another fact about this being computationally hard is we can actually distribute it and make it kind of a challenge and have different people solve this optimization problem have a smart contract pick the best solution and thus have the kind of price finding algorithm decentralized as well so let
me talk about the constraints that we need to verify by briefly summarizing this mechanism so we collect orders between any token pair over a predefined time three or five minutes then we have multiple solvers running to try to find uniform clearing prices all trades are settled at the same price that maximize the trader surplus and respect these three constraints that are on the slide first of all we are not fulfilling any order if the limit price was not respected so if you're willing to sell something for ten we're not going to sell it on your behalf for nine arbitrage FreeNAS means that within a batch there's no arbitrage basically the fact if we did a ring trade for you or if we
had a direct reverse order is abstracted away if two people want to trade a four B and there's one direct reverse order in another order that goes over another token they will end up with the same amount of B tokens at the end of course they can be arbitrage between external exchanges or also between two batches that can be different prices but within a batch there's no arbitrage in the last point is conservation of value just means the numbers of the amount of token going into a batch and coming out of a batch should always be the same we're not burning or minting any tokens so now I want to briefly talk about how we implement this on aetherium but because I have very limited time here unfortunately I will only be able to scratch the surface fortunately there were a lot of talks on roll-up before my
talk so I hope that some of you caught at least one of these talks because the mechanism behind how we scale this on aetherium is basically a roll-up application in a roll-up application we don't store a lot of State on the Ethier and main chain directly we kind of only store the root hash of all our account balances in our state so you can see here on the Left we have state 1 which is the account of all participants before a batch and then on the right we'll have our state after the trade which will be all the account balances of people after the trade Merkel eyes together and stored on the main chain and then we have three phases we have the ordered collection price calculation and trade settlement in the order collection people will be
able to broadcast their limit orders directly on chain now in the spirit of roll-up we're not storing any of the data permanently in the smart contract we're just using it as call data to broadcast to the entire network and to have data availability so that everyone knows what are the orders that are in a batch now this can happen directly a person can put a single order on chain or the orders can be batched together and collected to make this more gas efficient but that's an optional step then we'll have the batch will be closed and we have another three to five minutes of price calculation where we have hopefully a bunch of solvers compete for the best solution so we have a smart contract that decides which of the provided solution maximizes our
trading surplus and whoever provided that solution will then be invited to broadcast that solution on chain collect the fees that are associated with winning this kind of proof of optimization and also submit the trait state-transition which applies all the orders to the previous state so basically if an order was fulfilled we subtract the amount of the sell token and we add the amount of the buy token and at the end we rehash all the states and get our state to and now the state transition is backed by a zero knowledge proof to make it so that people cannot cannot cheat and cannot put invalid state transitions on chain on this light you can see that for example the order
collection cloud there is kind of an optional service which we might not be able to implement in our first version also for the solvers agnosticism --nt a solver but we are kind of relying on people willing to compete there and trying to get some of the fees that will that this network will incur and to incentivize this kind of work even more what we have started is a ecosystem fund which supports teams with up to one hundred thousand US dollars that work on projects in the canosa secrecy so this could be something diffusion related it could also be something related to our prediction markets or to our noses safe multi signature smart contract wallet or to the decentralized exchange that we have already launched a
minute last year the Dutch checks any of these projects are eligible for this for this fund and if you're interested in working with us you could either talk to me after this talk find anyone else who's working for gnosis here or just email Gekko at Knossos p.m. my email is felix diagnosis dot p.m. and the code that is already out there for diffusion can be found at github slash get about consolation gnosis and then all the repositories that start with de x are for the diffusion exchange and i want to leave you with this picture because it kind of summarizes the market mechanism which is really the key feature that i wanted to present here the idea that we have a an exchange where you can submit orders with any kind of token pair and
then we'll find the the best uniform clearing prices in this in this batch of of orders that that basically can come from any token pair what kind of pool the liquidity together and make the future of faire decentralized trading possible thank you very much [Applause]