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

Loading player…

AMMs for Dummies - Aleeza Howitt | Cowri Labs

ETH Belgrade CommunitySat, Oct 7, 2023, 12:00 AM

Transcript

foreign I work at Kerry Labs we're the creators of shell protocol and I'm here to talk to you about amm's I myself do not hail from the fine disciplines of Finance or mathematics and I've crafted this talk to hopefully be somewhat accessible for a general audience um so that means no math in chapter one and um yeah I probably made too many slides to cover everything here but I'll do what I can and heads up if you don't make it through the whole talk the big reveal is in chapter three the problem with amm's um basically amms lose money so if you're lping in an amm you're probably you're probably losing money um that's how it is let's begin so what what is an amm um let's start with the problem AMS um Okay so suppose you have some dye you want to buy some eth you could use a centralized exchange like coinbase or binance these exchanges rely on the order book model which means they sit around and collect individual buy and sell orders and then they match these orders together and if you're lucky there's a market maker providing liquidity which means they're always willing to trade with you which sounds okay but there are downsides centralized exchanges first of all have lost like billions of dollars from hacks and Corruption um they're able to lose your money because they're a centralized intermediary they take con they take custody of your crypto that is assuming that you have all the required documents to access the exchange in the first place so what are your options use a decentralized Exchange a public blockchain is a permissionless and censorship resistant platform which means you don't need permission to use it you don't need an intermediary to process your transactions and if it's a good blockchain it's never going to go suddenly offline um using a centralized exchange kind of ruins the point of the blockchain there can exist decentralized order books um but there are still downsides to this um order books will match manual buy and sell orders if you see the graph that's like just a random image of an order book um you can see by by orders on one side bid sell sell orders on the other side um so with order books you always need a counterparty for every trade and for small tokens with low liquidity you're not always guaranteed a counterparty another problem is the logic is expensive to implement on chain for an order book model it costs gas every time you submit or cancel an order and market makers usually do this a lot over and over again to make sure they're getting good prices also it's slow um so yeah and not to mention the regular regulatory headache for example the SEC went after ether Delta for operating an unregistered Exchange these sound like awful problems to deal with but never fear you can use a money robot instead with an amm you don't need a counterparty the robot will always be able to quote your price and instantly take your trade and it's gas efficient in other words MMS and blockchains are match made in heaven like coinbase and amm is always willing to swap tokens with you the big difference is it's automatic nobody owns it controls it it's in a stop an Unstoppable autonomous math machine AKA a smart contract that swaps your tokens according to a pre-programmed algorithm uh I promised you no math so why am I talking about this algorithm um well um unblock chains there's something called The Oracle problem in ancient times the Oracle would Divine the wishes of the Gods everybody relied on these holy vessels for correct information people would basically believe whatever they said um go to war and stuff over it I think that image is the Oracle Delphi I'm not really an expert on that so it's basically the same thing on a blockchain there's no way to know real information about the world without trusting someone to upload that information in the first place um which brings us back to amms so how does an amm get the exchange rate for its tokens we're crypto people we're paranoid we don't trust anyone you don't know who's operating your Oracle could be the NSA it could be North Korea it could even be a dog um thankfully a basic amm doesn't need any oracles at all you can compute the exchange rate purely based on the internal inventory of tokens without any information from the outside world which brings us back to the algorithm um okay I promised you no math but I didn't say anything about hydraulic systems so here you have a diagram of a simple hydraulic system whenever you swap one token for another you're pushing down one side of its inventory and filling up the other side automatically you aren't removing any fluid from the perspective of the system the total volume is conserved um big caveat value is not actually necessarily conserved but we'll talk about that later so imagine the left side is e if the other side is die pushing eth pushes or yeah buying eth pushes the bar down the other side fills up automatically with the dye salt um okay now imagine that dashed line in the middle is the correct exchange rate when eth goes down and diet goes up it gets unbalanced and someone has to push down on the other side AKA make an opposite trade to rebalance it why would someone want to make a swap just to rebalance the amm's tokens here's another analogy because I like analogies imagine the amm like a balance scale and amm uses the ratio of the quantity of its tokens to determine the exchange rate this exchange rate fluctuates as the ratio of its tokens changes you can actually imagine the exchange rate as like the angle here and every time you drop an orange on one side and eat a banana the angle shifts a little and changes the price right now one banana is worth three oranges so I'm going to sell my bananas and buy oranges until they're equal again um I skipped a very important detail which is that amm's um which are unpaid robot servants uh rely on liquidity providers to get their token Reserves so why would you risk putting your tokens in an autonomous robot the traditional argument is that you learn fees from Traders and sometimes protocols have extra incentives on top of that although as we'll see later you're actually more likely to lose money as an LP um all right amms were awesome for defy the first platforms to implement them were bank or and then uniswap people usually forget about bancor but things uh I guess that's because things really took off after univ2 and yeah basically amm's were a big deal in crypto because anyone could permissionlessly deploy one they bootstrapped liquidity for infrequently traded tokens a lot of these tokens weren't listed on centralized exchanges because of the regular turtle regulatory hurdle or because it was too expensive and ultimately it caused a surge in the ability to trade illiquid assets and was a big contributor to defy summer congratulations we made it through part one um all right now we're going to talk about pricing curves AKA bonding curves and concentrated liquidity getting back to that algorithm the um so the problem is the ratio of East to die changes whenever you make a swap um the exchange rate will change on a sliding scale therefore for most amms the bigger the swap the bigger the the change in exchange rate this is also called price impact so how do you compute the change in exchange rate you compute it with a pricing curve AKA bonding curve very similar to an indifference curve in economics and by the way that's what it looks like before I get to the next slide I want you to take 10 seconds and try to guess what the bond means in bonding curve for the past few days I've been asking people where they believe the term bonding curve comes from and also how they might Define it to define it and I've gotten some wildly different answers so here's the real story or at least what I've managed to figure out the original bonding curve was defined as a relationship between price and token Supply so there's actually just one asset the amm holds in reserve you can use that asset to pay the amm the amm will Mint new tokens for you or burn them the price of these tokens changes with supply and demand minting it and burning it moves the price back and forth along the bonding curve if you don't follow that that's okay allegedly the zap oracles team coined the name to describe the concept as it was conceived by Simon De la rouvier who had imagined using bonding Curves in the context of curation markets in his words Bond signifies a bonded together curation community which is not was not my guess actually for the term the bonding curve however is a classic concept of multiple discovery or a convergent evolution if you come from biology because at the same time bancor released its smart tokens which were basically the same thing so it was vented multiple times in our very small field incidentally the first on-chain amms were created by bankore since then um amms have evolved so that multiple tokens can be held in reserves within one contract priced against each other directly and the term bonding curve has evolved as well and taken on a broader meaning at least in popular use and how I'm using it now it's basically an expression or yeah an algebraic expression of a pricing curve in lieu of discrete buy and sell instructions um I am open to other definitions it doesn't seem like we've really as a field aligned on a formal definition there yet but it's just semantics um okay so many curves there are many types of money curves used in amms first we have basic amms you'll hear a lot about constant product but there's also constant mean and constant sum hybrid amms are generally a combination of constant sum constant product um yeah with some variation and virtual Reserve amms are like constant product but imagine if you multiply the reserved balances of each asset by an amplification Factor and actually I think shell protocols Am engine Proteus falls into that category and Matt has a talk on this you should check it out he categorizes everything very thoroughly all right so here's a graph of a constant product curve constant products are classic the classic standby for volatile tokens um they're like price discovery mode if you don't know what the exchange rate is a constant product curve will help you figure that out um the formula is x times y equals K and here X and Y would be the quantity of Ethan Die For example K is the constant also known as the invariant then we have constant sum which is theoretically good for two assets of correlated value um but it is dangerous actually to use this in practice because if you imagine one asset going off its Peg or off the correlated value then you could actually drain the whole mm and break it uh constant Min is used for pooling multiple assets also you can add weights um there are other ways to accomplish this like having a pool with multiple assets you can have a system with like fractal LP tokens which is something also that we do at Shell protocol with proteus and yeah balancer was was the one that implemented this in the first place hmm so to bring it back liquidity providers want Capital efficiency and the problem is that constant product isn't efficient um what do I mean by that so if you take a look at this graph um so I mentioned that hybrid amms so stable stable swap by curve is like the first example of that it's kind of a combination of constant sum and constant product and here the Blue Line represents staple Swap and you can see it kind of flattens around the popular exchange rate so it looks it's yeah it's a little nice to compromise between those two curves um concentrated liquidity uh so we'll get a little more into this later but it works great for stable coins and highly correlated assets and it's good for some active LPS Traders do get better swap rates but passive LPS uh lose money tragically [Music] um this brings us to the most important part of this talk I kind of like this quote from the balancer white paper balancer turns the concept of an index fund on its head instead of paying fees to portfolio managers to rebalance your portfolio you collect fees from traders who rebalance your portfolio by following Arbitrage opportunities uh this sounds great but in reality the arbitragers are yeah taking value from you you're losing money um and yeah amms in general are risk here for elite retail liquidity providers then we'd like to think concentrated liquidity is Con it it increases the fee revenue for LPS but it actually exacerbates impermanent loss and ultimately it's harmful for most most LPS as you can see here um one analysis showed that um there was a negative 30 percent return for most um yeah for LPS in uniswap which means for every dollar That You LP you're losing 30 cents uh in other words number go down Okay so that's the big catch to lping You're Gonna Lose money um why do you lose money in general it's because the amm doesn't know Real World prices um because it lives on a blockchain it's slower than tradfi and basically it's always a step behind and in other words the amm is always taking the worst side on every trade and because it's using LP money um LPS are basically always buying high and selling low how can you measure your losses well there's this concept called impermanent loss it's the opportunity cost of LPN instead of holding and you are affected by impermanent loss whenever the token prices deviate from when you originally lp'd or at least if the ratios of the tokens um end up different from when you originally lp'd so you might still make money from fees but you'll just make less than if you just kept your tokens there's another measure also loss versus rebalancing I won't get into that but very good to look into um okay looks like I have I'm running out of time here so let's rush through this the math part um imagine here you have a LP into a balanced pool there's 40 each of token X and token y because it's balanced their price um is equal to each other right now so to calculate your initial portfolio value V in terms of Y um you can do four plus four times one which is the price of in terms of Y the total value of the pool is 40 plus 40 equals 80 and you own eight so you own 10 of the pool when you withdraw your funds um some time passes imagine that the price of X quadruples and it's now worth 4y as a result the Arbitrage Traders have rebalanced the pool moving the price along the curve and changing the pool reserves so that there's now only 20x and 80y and do you decide to withdraw your money you're entitled to 10 of the pool so you get back 2X and 8y and if you do the math your final portfolio value is 16 which means you doubled your portfolio value which is awesome however um if you compare it to what your portfolio would have been if you had been simply huddling um you can yeah it's basically it's four plus four times the new price of X which is 4 equals 20. and by simply LPN you lost 20 of your profits sad face um basically what this graph is showing is that if there's any price any deviation price you get in permanent loss the blue line is LPN the red line is huddling um and yeah you can see the difference there whenever the price TV hits so I've probably said this a bunch of times already but um LPS are only profitable when fees are greater than impermanent loss and that's not the case right now and it's our responsibility it's D5 protocol is to figure out how to solve this problem uh the first attempt was really to address Capital inefficiency and what I mean by that um so if most trades are happening around this 10 of the Curve um yeah okay so If You LP ulp into the entire curve so you're lping into 100 of the curve but you're only collecting fees on the 10 that the trades are happening in and this is called capital inefficiency uniswap's big innovation was um you can pick the price bands where you put your liquidity however you don't make any money if the price goes out of your range and when prices deviate from your position you suffer so that's like a screenshot from uniswap the blue bands are your where you put your liquidity and the Red Dot is the price if it looks like that you're not making any money on fees hmm okay we'll just skip through this basically if you are not making money someone else is making money off of you that's what that shirt shows and it is a new field but the research basically supports this analysis that you know most retail LPS are losing money participating in concentrated liquidity pools in particular uh this is a good chart it shows that the um yeah basically the fees are the blue lines the Improvement loss is the orange lines and in almost every pool the orange loss uh yeah the Improvement loss outweighs the fees there's a big internet debate about this um that is to say amms have an existential problem and eventually where the LPS are going to start realizing this is a problem they're going to withdraw their liquidity and it's going to break D5 how do we fix amms well there are a bunch of ideas around the space um my team is particularly interested in the idea of charging a premium for exclusive access to a pool um basically you charge a premium for the right to trade with a pool at some future block and that works if you imagine the problem like LPS are selling free options on the right to trade with the pool I'm completely out of time so I'm just gonna very quickly skip through the rest of these slides and I can share them with you if you want to look at it later um that's Proteus is our amm engine NHL protocol and we hope that people will be able to use it to help experiment and solve these problems and yeah amms can be really cool guys thank you [Applause]

Automatic transcript — names and jargon may be misspelled.