Make money long after you're dead
ETHCC 5 · July 2022 · 27:53
Vincent Danos examines using DeFi protocols as backend infrastructure for trading and liquidity.
Speakers
Topics
From ETHCC 5, hosted by Ethereum France.
Transcript
let's start so liquidity is an important resource to markets and markets whoever already existing or markets we'd like to build and actually defy has set up very innovative and interesting solutions to bringing liquidity to markets and if you think of it icos amms down to balancers lbps our new instruments to create exactly that so who brings liquidity to markets these are special market participants liquidity providers and what they say essentially whatever the syntax is and whatever the vehicle is they say i'm willing to trade that many x's against
that many wise and of course they do it for profit and it's important because it's the aggregate amount of liquidity that's on offer from the liquidity providers that's going to build the depth of a market and that is roughly the ability of a market to absorb orders of substantial size so the the larger the depth the more the price stays stable under large orders and of course if the price is stable it means it's a good signal so i can use it as a way to evaluate my wealth and that brings me more confidence into when i enter and when i exit the market so good overall good
and what i want to talk about today is a new mechanism to bring even better liquidity to markets and that mechanism we're going to call for the duration of this presentation a reactive market engine and we've built one obviously which is called mangrove so this is what we're going to talk about so more appealing more efficient easier to use and eventually more profitable so before we describe this in any detail let me give you just an impression of what it is so here i'm connecting via the dap to the mangrove exchange on a pair this is the this is the if die market and i'm trying to buy 10 if with a bunch of dice
so there are two things that we have to before i launch this really short five seconds clip uh there are two things we need to uh look for so one is that the order i'm gonna shoot at the market is quite substantial so if you look at the the right side of the panel you'll see that it's going to eat up a substantial amount of wet liquidity is provided on that side of the book so the red part of the book is the aggregate offer to sell if on that market the asks as they're called and so that's the result of the action which is me shooting a market order to to the exchange and now what's going to
happen next at the end of the five seconds is that you'll see that this void that i created by shooting my market order is going to be filled instantaneously by a bunch of bits that are going to jump in the void so i shoot this is my action and the market will react a reaction by jumping in the void that i create with my market order so let's look at the clip it's not very long a few seconds success up have you seen it i think i repeat it for another five seconds so you see that the liquidity jumps to the right
and of course the price increases a lot because there's a lot of slippage so what's happening here behind the scene what's happening is the offers that look like offers actually are code so to each offer is attach a piece of code hence the action or the reaction of that piece of code that we just looked at in that video so let's go into the sequence of things that happen so the first event is issued a market order this is received by mangrove minecraft will split my market order into tiny little slices that each match an offer that's on the book and then it will call the code that's attached to the offer now that code is in charge and it turns
out that right now with that example there's just one big piece of code that has all the offers on the red part of the book under management and it's called mango that's a smart contract and what the smart contract will do is well it will deliver the liquidity from some source of liquidity more about that later but it will also take control of the book a second time and replenish the set of offers it's actually placing on the book so that's the reaction part of the the piece of code that manages the offers and like i said that code can be any piece of code so in particular in that case mango in the
implementation is actually sourcing the liquidity from ave in that particular case which means actually there is nowhere at no time any liquidity which is captured by the book itself it's just always somewhere in the remote source that the code can access all right so this action is the right part of the video and this is the green part of the video the reaction so let's now open up mango and look at how it reacts you know what's the code behind so it applies a very simple strategy which is to lay down a price grid with a bunch of price points actually you think i think here we're using something like one
point every ten dollar of if and when an ask is matched then what will do it will take in the cash deposit it to ave and rebuild on the beat side a new offer to buy back what it just sold just one price point lower so sell high buy low it's one of the basic market making strategy and of course conversely it does the opposite when it sells it tries to buy it back it tries to buy back one price point lower there are many variants but this is the simplest and just to give you an idea this is 900 line of codes in solidity so it's about the same order of complexity as you need to have v2 and it's fully completely
unchanged so in that respect it's an amm mango is the name a mangrove is not an amm right so how does it uh perform well we back tested against unisof v3 so mango is in green unisof v3 is in red so we consistently beat the performance the the back testing period is from beginning of may 2021 to end of march uh and the other thing to notice about that diagram is that the number so the ranges of the two strategies for the sake of comparison are the same 1500 to 5000 so the mean price of operation and the max price of operation and the other thing to notice is that mango here the way it was configured in
the simulation was using only 10 price points so a much faster price grade quoting or every 300 worth of eve since it's interesting super simple market making strategy so here i need to prevent a bunch of misconceptions so when we say bring your own logic it really means bring or build or borrow so uh your logic so we mangrove is not specific about which kind of logic you should use to manage your the your intentions to trade so mango is one particular way to do it and this is an example that we've built
and with which we actually make our markets on on the test net like you've seen but you know it's not a stipulation that you should use the same so please build your own so mangrove is the platform the market engine is just one strategy that runs above it and you can clone it tweak it and run your own copy on the side of it if you make a copy and you tweak it and you deploy it it will run on the same join platform so in a way you can think of mangrove as aggregating the joint behavior of many little automated market making strategies so this is very different from balances custom pools for instance they let you specify your own maps but as soon as you
create one it's alone in the world and it has to bring it its own liquidity if you create another one with another piece of math it's going to be fragmented it's going to be next to it not together also similarly the way sources of its liquidity by ave is just one example you could use morpho you could use compound you could even use lp tokens to another amm whatever fits the way you managing your liquidity as long as you know how where to find the code to connect or or even better if you know how to write it yourself then it's eligible so it's super flexible all right so talking about flexibility
let's examine maybe a bit more sophisticated ways to provide liquidity so here i describe a family of liquidity providing strategies that have roughly ballpark the same mathematical guarantees as a mango but allow you to express more of what you think is going to be the price action within the duration of interest so they're all based on the concept of cash ratio what's the cash ratio it's a function that's defined between a mean price and a max price of your choice and for every price in the middle of that range it will specify how much of your portfolio in value you want to hold as a percentage for instance you want to hold
in cash so if you say 50 50 over the entire in interval you have a kind of a uni-swap v2 type of a way to manage your cash ratio but there are other ways to do it for example the blue line is maybe the most natural it's a lena interpolation so an old by the way all the free curves that i'm presenting here define cash ratios and they all share the same common behavior which is that you hold actually zero cash at the bottom of the interval so you're holding the the low asset and you hold no none of the asset at the top of the the range so you're selling on the rise and you're buying back on the low which is you know typically where the market
making strategy does uh so the banana shaped green one just in case you wonder is actually uni swap v3 which can be captured very neatly in this type of syntax and the sigmoidal one so what exactly do you express with that sigmoidal uh cash ratio function well you express the belief this is going to trade harder uh near the middle price right so you'll the rebalancing will swing harder uh when it's at the place where the sigmoidal is uh has a higher differential so uh what you're expressing if you pick up that particular way to provide liquidity is that you think that the price action will mostly happen uh in this middle
price so it's good to have diversity in the way you you set up your you express your liquidity providing strategy and this is an example of how to give it simply uh so um i should say importantly uh and i haven't said it yet that they all satisfied the no permanent last property so you can prove mathematically that if the price loops on itself you're not losing and actually you're winning and if you use a discrete form of those strategies which we do on mangrove you actually increase geometrically or returns each time the price loops on itself so the worst that can that you know things go wrong then the price can escape at the
top of the interval or at the bottom of the interval and then you don't make any profit anymore but that's impermanent losses people say so this has nothing to do with unicef in particular it's a very generic mechanism and i last word about that on on the pure mathematical standpoint there is absolutely no reason to pick up the maps of unison v3 against another one they all have the same properties so you can extend that logic this is a rather you know extensive but still very simple class you can inject new signals variance volatility you can make it time dependent you can you you can make it depend on momentum measurement devices
uh you you can use signals that are available on chain and of course you can generalize that to multiple assets that's all in our drawers so you can have an index based strategies of the same type so that's about what i want to say for the flexibility of the way you provide liquidity now let's say just a word about the way you manage the liquidity so the fact that the liquidity is not in the book but somewhere else so here we we work out a little model uh which we call fractional reserves so the the game you want to play you want to trade off between the cost of moving your liquidity back to where it's needed just in time and the returns that you're making if your liquidity is in your savings account if you want
so the you pick up two parameters one r which is the interest rate which is served by whichever source you're using so maybe it's the supply rate on mor4 for example and c for the cost of transfer and for the sake of the argument here i suppose transfer is as a symmetric cost whether i deposit or withdraw so clearly if the rate is dominating and the cost is very small compared to the right then you should always push everything to your savings account right because what you get there by far exceeds the cost of moving things back and forth so that's one extreme regime another one is when the returns are very small and the cost is huge
and in that case you should not even consider managing liquidity in a remote place so but what we've what we've seen by back testing on actual data on three different markets the the main liquid markets on uh on ethereum is that uh with very simple stochastic control based on when you have an excess of liquidity on the uh on the local money side uh then deposit it to your lender and when you're below a certain amount of liquidity luckily then withdraw and replenish to a certain mid [Music] fraction of your reserves then with this
very simple minded control that we actually uh managed to get exceedingly good performance contrary to what one might think so the way we measure this we draw a line at 100 this is the maximum amount of returns that you can expect to get this is the one you would get if the cost of transfer was zero so then you would put everything remotely all the time and you know and get hundred percent of the ideal profit and what we see is when the fraction are divided by c so how do how did this increases with how easy it is to make money remotely or how non-expensive it is to move things around and we see that on one of these markets you get 80 even in very degraded
condition of this ratio so that's good news all right so let's summarize uh into my two last slides the benefits of working with a reactive market engine if you're a liquidity provider so first of all you can bring your own logic we have a very flexible class of super simple strats just like mango but you know expressing your desire to balance your portfolio as a liquidity provider in a flexible way and of course you could run this manually from off chain but it would be a nightmare of infrastructure robustness asynchrony so you can also bring your own liquidity
source so this means that the decks the platform mangrove doesn't lock your liquidity and you're at completely what's here of using it in the way you want of course again you could try to shoot from off-chain tiny updates and transfer orders but that would be again very cumbersome and very actually demanding in terms of infrastructures so uh one clear simple benefit is that to run your liquidity provision strategies in this fashion you don't need any infrastructure of chain uh actually the only infrastructure that you use is the blockchain itself which is particularly elegant so you can set it
and and forget it and long after you died as the title suggests it will keep self-financing moving around money and make profit every time the price loops and the fact that you have no asynchrony and i conclude with the next slide about that is a bit so no asynchrony means that when your code runs it actually runs on chain so it knows everything about the context in which it's evaluating its own options uh if you're off chain you may be able to deploy a lot more intelligence you know computationally be much stronger but then you have to shoot your order it will be in flight and while your order to the market is in
flight things will move so the evidence on which you base your decision may no longer be the case by the time it's executed and this is a reducible asynchrony except that so here in this model you always execute last when the market engine calls you you're fully synchronous you can do crazy things so what crazy things can you do so let's dream a little bit this is the last slide as i said further than what we've already demonstrated and these are just ideas they've not been implemented yet one thing you can do is you can define your price so the market engine passes you a match and you can actually pass on that match you can say well i'm no longer interested i'm measuring x y z on
chain and i see that maybe i was under selling so at a certain cost which is a bounty that you have to pay to do the engine and the tekken you'll say okay no i just want to update my positions so i'll take the reaction part but thank you i'm not going to deliver what i promised to deliver you can the opposite can happen of course during the flight maybe you're over selling so the taker was actually uh misguided in taking your offer but there was no way you could tell so there can be positive slippage and you can pick this kind of for me arbitrage opportunities on the fly so this is the advantage of being on chain right another interesting thing you can do is you can self-leverage so the engine
has a peculiarity that i didn't mention yet which is that when it triggers the execution of the code that manages a given offer that is currently matching the engine actually will give the money of the taker to the code so now the code has the cash of the taker one thing you can do which is very natural to do is to deposit it that will increase its borrow capacity and on the back of that borrow capacity it can actually borrow what it promised to the ticker so not quite everything but you know three quarters of what was promised which means that you do a times full uh leverage on the amount of capital you actually have to have control of compared to the one you're publishing
so this is like margin trading but there is no margin trader there is no mechanism you're just leaning on the uh lending uh uh the liquidation infrastructure of the lender so you don't have to ask permission uh there's another type of leverage which is we don't know mangrovian which is that you can actually publish the liquidity that you have access to uh at on two different markets at the same time so let's say you have a bunch of a's 10 let's say you can sell them on the av market and on the ac market at the same time now whichever of these two offers will be the first is going to trigger the same code and
what the code will do is uh if your 1080s have been wiped out by the consumed by the ticker then what it does it will erase the other competing offer on the other book and then now let's say it has 10 b's so again the code will can republish those 10 b's on both markets baby and bc so each time and same thing if you're taken on seed and you republish on both markets so what you're doing here is is a completely uh one-of-a-kind time of leverage which is leveraged using the temporal structure of the evaluation at the execution environment so you do times two times three times n minus one or n is the number of markets on which you
place simultaneously and because the execution environment of the evm is sequential there is no no there is no mathematical risk that you'll have another feel or you'll be finding solvent because you promised too much much more than you could actually fulfill so if you think of it in terms of cpu time you actually have a semaphore you're the only one executing and you have you you can manipulate everything which is within the access of the execution environment all right so that concludes this presentation and i'm happy to take questions if you have some [Applause] thank you
questions out there here we go so with regards to liquidity since you don't have a locked value how do you like there are some conditions where the market can be like very volatile and where a lot of uh your actually orders could be like ghost liquidity like you just described and so how do you handle that that case where uh where it's just like a lot of orders actually don't have the liquidity anymore because it was just used like a few milliseconds ago so the engine is fail proof so if one if your offer doesn't work for
whatever reason maybe because you don't want it to work or your code doesn't want it to work only because there's an accident maybe the lender you're drawing liquidity from is insolvent it happens maybe the pool is dry then the market engine will just continue switch on to the next offer and carry on the execution of the the market order so there is no discontinuity of service so to speak if there is a failure that's the first thing the second thing is obviously we like the book to hold credible offers right so we want it to be plagued with just failing offers so what we do is very simple we make it a free lunch for specific actors to actually shoot
offers that fail so now a liquidity provider has to uh give on top of the intentions to trade and the code to call a bounty which will be given to the taker in the case the offer fails and so that's essentially a free lunch to keep us people who know how to connect to you know use the entry point uh the program entry point to to shoot an offer and so we've written keepers ourselves but we expect people who actually take the take the free lunch thank you great other questions out there great another question but we're not fully relying on keepers
either for asynchrony problems so if they fail then the market engine just continues fine since this is a pretty unique system which kind of lps do you expect to be using your protocol do you think there is going to be one day integrations which allow retail actors to be lp and margot so we're still in the process of discovering you know potential customers and market fits and things like this so it's a bit it's a bit too early days for me to give you a definite answer but we've certainly looked into what you're suggesting uh put one of those strategies that's really easy to program into a little box
connected to a good source of lending let's say morpho and we do a little morphobox and then we'll uh knock at the door of large liquidity providers on ave for example on mofo and we'll tell them you know why don't you also liquidity provide to that market you don't have to touch your liquidity it's just gonna happen by code uh you know maybe you don't want to disrupt the structure of your portfolio too much but maybe a little sliver of what you have in the fridge will be animating our markets that's one road of inquiry but there are many more for example token essence uh is a super application with an active market engine you can go way further
than the lbps of balancer so liquidity bootstrapping tools are actually quite used by default projects for obvious reasons because you have to bring less capital to the table when you want to do a public sale of your token but with an engine like this we can actually bring the amount of cash that you have to add to zero which seems just very intuitive we can guarantee to the token issue that the project cannot lose money it can fail to sell its tokens obviously but it cannot lose money uh it can only win if there is some price action and uh from the point of view of the investor we can also guarantee that the underpinning logic will re-buy
everything at a floor price for example so that's another avenue to market that we're exploring and then we also would like to use this kind of market engine for semi-foundable tokens for example so there are many assumptions on the table uh in three months we'll probably have done our homework we will know a lot more about what are the good ones we want to focus on great thank you do we have any other questions otherwise you're of course welcome to meet with vessel after and let's uh thank him again thank you [Applause] you