# An Overview of AMM Mechanisms by Matt Deible | Devcon Bogotá

- Channel: [Devcon](https://streameth.org/devcon)
- Date: 2023-10-07
- Duration: 26:47
- Watch: https://streameth.org/watch/yt-KxuyHfmLHP0
- YouTube: https://www.youtube.com/watch?v=KxuyHfmLHP0

## Description

Visit the https://archive.devcon.org/ to gain access to the entire library of Devcon talks with the ease of filtering, playlists, personalized suggestions, decentralized access on Swarm, IPFS and more.
https://archive.devcon.org/archive/watch/6/an-overview-of-amm-mechanisms/

The talk will give an exhaustive overview of the different AMM algorithms currently deployed on major distributed ledgers, as well as the underlying intuition behind their design. Building up from the basic principles of AMM design, the talk will then cover the algorithmic mechanisms used in the various different algorithms including Constant Sum, Constant Product (Uniswap V2), Uniswap V3, KyberSwap, StableSwap (Curve), CryptoSwap (Curve V2), Solidly Stable pairs, Clipper, Dodo, and RFQ systems.

Speaker(s): Matt Deible
Skill level: Intermediate
Track: Cryptoeconomics
Keywords: AMM,DeFi,DEX

Follow us: https://twitter.com/efdevcon, https://twitter.com/ethereum
Learn more about devcon: https://www.devcon.org/
Learn more about ethereum: https://ethereum.org/ 

Devcon is the Ethereum conference for developers, researchers, thinkers, and makers. 
Devcon 6 was held in Bogotá, Colombia on Oct 11 - 14, 2022.
Devcon is organized and presented by the Ethereum Foundation, with the support of our sponsors. To find out more, please visit https://ethereum.foundation/

## Transcript

foreign [Music] everybody my name is Joseph I'll be your MC this morning uh how are you enjoying Defcon so far I guess I guess this is the this is the group of people that didn't party or did party hard and just didn't go to sleep and just continued uh with the drill so um I appreciate you for being here in the morning I know it's tough uh um but um without further Ado because we are getting to our time uh we are going to start with some heavy topics uh right in the morning uh Matt's dibel the research and product lead at Otis is going to present his talk about an overview of automated Market making mechanisms so please put your hands together for Matt [Applause] all right hey everyone um so otos is a DEX aggregator um and so while building it I've had the unique opportunity to really um do a deep dive into the different automated Market maker mechanisms that control billions in D5 tvl every day so the aim of this talk is going to be to try to cover as many of these as possible uh primarily the ones that currently control a large amount of tvl so it's not going to be completely exhaustive but hopefully it's uh close as close as possible in 25 minutes um and then we're going to tie that back into Dex aggregation why it's needed and what it's for so to start off I want to briefly cover um some of the basic principles that we can think about well we're going over these many different mechanisms so first I think it's useful to clearly Define what we're actually trying to do with these Market making mechanisms so we can start off by clearly defining what a market maker is so a market maker has a portfolio of assets and they're trying to earn yield on that portfolio um and they do that by allowing people to trade through it and so essentially what happens is uh they offer to sell an asset at a slightly higher value then they will buy it back and that creates this spread um that serves as Revenue that they earn on um the volume that goes through their platform now the catch is that this revenue is not risk-free right uh people are when trading is happening we're actually changing the composition of the portfolio um and this also leads to a change in value in the portfolio and so what can happen is if the change in value in the portfolio as a result of the trading uh outweighs the revenue then you're now losing money and you're not actually earning any yield and so uh we really need to do a good job designing the uh the strategy and how we're actually pricing and allowing people to trade so with that objective in mind we can now think about what tools we can use to actually um decide on the pricing right so there's many different types and strategies of course but we can sort of simplify it down to two basic paradigms so the first of which is uh price Discovery so this is essentially reacting to um what's happening in the market so if we think of a simple example if at the current price lots of people are buying that means the price is probably a bit too low and you should raise it up and so by reacting to how people are interacting with the prices you set you can sort of follow around the market price and discover what the market thinks the price is which is a very powerful mechanism but of course if you're following around what the actual market price is um you're not actually really providing the best price at any given time because you're always trailing behind and so ideally what we'd like to do is just be providing the price that people actually want to buy and sell at right we want the real market price and so we can try to approximate that by leveraging Price oracles so trying to leverage some external knowledge um to decide on the price without actually having to discover it ourselves and so this can be extremely powerful because you can really then concentrate your liquidity and uh general pricing strategy around what people actually value an asset at but it can also be very detrimental because if you're setting if your price Oracle is wrong well then you have the same problem with price Discovery except quite a bit worse potentially right so real quick to give some concrete examples uh one thing we can Leverage is the pegged value of uh the asset so if you have two stable coins usdc and usdt they're both worth a dollar and they should be exchanged one to one right and we can leverage that knowledge as sort of an Oracle and use that to inform our pricing and Market making decisions some other examples are chain link oracles and uh the pricing of other dexes as well so last thing before we get into the actual amms um I do want to concretely cover um what where how I'm actually going to be showing these amms right I'm going to avoid the math it's very interesting but it's not uh it's not fit for a 25 minute talk on nine different uh amms so instead I'm going to show this trading function which is hopefully a bit more intuitive and basically what this trading function shows is it shows uh the space of possible trades that this uh Market maker will actually allow right so on the x-axis we have um on the x-axis we have the input amount and on the y-axis we have the um output amount and this curve is the space of uh trades that you can make so this point for instance is one trade you can make if you have 100 of the input asset this Market maker will give you out 200 of the output asset and at any given point the slope uh sort of shows you the marginal price that you're getting if you keep on putting input into this Market maker so with all of that in mind we can we can Now cover our very first amm and this one is the constant product Market maker uh so this one's huge it's very important it's been uh it's probably well it is the most popular one uh it was introduced by bancor originally then uniswot V1 and unit swap V2 both used it and popularized it a lot um it's also important for the context of this talk because it essentially embodies uh full-on price Discovery right unit swap V2 has no notion of uh what a value or what an asset should be valued at it simply discovers that price and how it does that is it sets the price as the ratio of how much of each asset it owns and that allows um the price to essentially respond to uh demand so you can see in the trading curve as you put more and more in the slope of the curve continues to decrease and that's showing the price responding to uh the trading so it's discovering the price now on the other hand as we said if you can leverage an oracle that can lead to much better pricing and so a constant sum Market maker is uh sort of the full-on embodiment of this right so a constant sum Market maker will provide a fixed rate of exchange at whatever the Oracle is so you can see on the trading function on the right there is now a completely constant slope so a constant price all the way up until the market maker runs out of assets um at which point uh you can't trade anymore right because uh the market maker no longer owns any of this output asset and this turns out to be a very precarious position for the market maker to be in um for one they're not earning revenue from Trading anymore because they're a liquid and for two they now don't have a portfolio right they own all of one asset and there's a lot higher risk of portfolio value change there which generally they want to avoid um so there are some examples of this uh technically any wrapper contract is a constant some Market maker like Ave um maker has a peg stability module uh that allows one-to-one exchange of uh other stable coins for die which sort of keeps the stability of that Peg and synthetics has um a fixed rate of exchange using uh other external oracles for their synthetic assets which is also quite powerful um so those serve as uh both models that are used in practice but for the purposes of this talk they sort of serve more as boundaries right they both have some big weaknesses the constant sum is um if your Oracle is even slightly off you're gonna just lose all of one asset and you're not actually going to be Market making anymore while the constant product while extremely powerful is not very efficient with its money because it knows nothing about what the asset should be worth and so uh essentially what the rest of this talk is going to cover is different types of mechanisms they can cover that middle ground and these are these can be known as hybrid amms the first of which will be stable swap uh so stable swap was introduced by curve and essentially what stable swap is trying to do is it is moving from a constant sum uh Market maker so from a really a fixed rate of exchange to a constant product as the reserves get more and more out of balance because as the reserves get more and more out of balance you can imagine that your price is probably a bit off right and so you want to start adjusting that price while still taking advantage of that one-to-one exchange rate and so this equation also has this amplification parameter and that's what you're seeing in the animation on the right and you're seeing that as that amplification parameter increases uh the stable swap curve in purple moves from the constant product in blue to the constant sum very quickly closely approximating constant sum because again we want to leverage this one-to-one exchange rate as much as possible um so other than stable swap there are some other stable Solutions stable swaps generally the industry standard more recently though there's been uh solidly introduced an alternative equation for stable swap which is generally a bit more uh slightly simpler simpler to use as well because it doesn't have that amplification parameter um for the purposes of this talk we can compare it to stable Swap and that's what you're seeing on the in the trading functions on the right you're seeing solidly stable in purple compared to stable swap with an amplification of two and they're still different but they're about the same at that parameterization um now an amplification of 2 is actually quite low typically it's much higher than this so solidly stable essentially represents a uh a low risk sort of stable swap that's still a big improvement over the constant product when there is that one-to-one exchange rate to Leverage next up we have dodo's proactive Market maker so um dodo has a mechanism again leveraging some external Oracle this can be chain link this can be this one-to-one exchange rate um and they introduced this parameter K that allows you to continuously adjust from the constant sum to the constant product as K is increased um and it does this in a bit of a smoother way than stable swap with which makes uh more Dynamic oracles possible to use in general uh you can sort of think of K as representing your confidence in the oracle right so if you have if you're extremely confident that the Oracle is correct you can set K to zero and you get a constant sum you just get that fixed exchange rate whereas uh if your Oracle is less reliable let's say it's a chain link Oracle that can't update super often you may set K somewhere in between these two and the Curve will leverage that Oracle to inform its pricing but it will also discover the price if that Oracle turns out to be incorrect or there's large trade volume uh Clipper is another one that actually has a k parameter that serves a very similar purpose the math behind it is is very different and very interesting but um the end result is again you get this curve um and this parameter K that allows you to adjust the curve between the constant sum and the constant product Market maker now the interpretation of K as confidence in the Oracle sort of has some extra meaning here in that Clipper originally deployed their amm fully on chain leveraging and on chain chain link Oracle um now as I mentioned the limitation with a chain link Oracle is that it can't possibly update faster than the block time and so you can't have full confidence in the Oracle uh when its update time is limited so more recently what they've done is they've actually built a another version that can leverage a fully off chain Oracle and we're gonna come back to how that's possible later in the talk um but for now the the context of that is that this allowed them to set K much lower and so this is sort of a concrete example of K being the confidence you have in this Oracle price so last uh hybrid amm we're going to cover today is crypto swap um we covered stable swap as the first one and stable swaps fantastic for stable assets uh unfortunately it's not very good for more volatile pegs um because it's so closely matches that constant sum curve so what curve did is they took that stable swap curve and they essentially added another degree of freedom to it called the gamma parameter and this parameter allows the curve to more quickly adjust from the constant sum to the constant product as the reserves get more and more out of balance and so on the right in the trading curves what you're seeing is the stable swap curve for reference in green next to the crypto swap curve in purple and you can see for very small inputs the crypto swap curve is actually closer to the constant sum uh whereas for very large inputs it's much quicker to adjust away from the constant sum towards the constant product as it switches over to price discovery right so this allows it to be used for more volatile oracles non-one-to-one pegs which makes it um very powerful and allows curve to essentially expand to uh other options now there are quite a few other interesting things about crypto swap that sort of break the mold that we unfortunately don't have time to get into so I encourage anyone who's interested to look more into that um for now we're going to move into another sort of type of amm these amms still live in between the constant sum and constant product but uh the thinking and Concepts behind them are a bit different and so I think it's worth approaching them from another Direction and that is through virtual reserves so kyber DMM is one example of a mechanism that utilizes virtual reserves and what virtual reserves are are essentially just pretending to have more of the assets than you actually have right so we're still using the constant product equation but we are saying we have five times more of each asset than we actually have and so you plug these virtual reserves into the constant product equation and you get what we see on the right where we have that constant product curve that moves closer and closer to the constant sum as this amplification increases um with the trade-off obviously being that you are introducing this zone of illiquidity because you don't actually have as much money as you're pretending to have and so you have to be careful of course uh how much and where you're concentrating this liquidity and you really need to use uh pairs of assets that are going to trade within some price range because once you exit this price range you become illiquid and you can no longer Market make which as we discussed is is very bad um so what we really need is to be able to leverage this powerful virtual Reserve mechanism but to also uh have some freedom to move it around right and so that's exactly what uniswap V3 provides so uniswot V3 utilizes these virtual reserves but it basically says each individual liquidity provider can choose their own price range and implicitly amplification and concentration as well um and so this is super interesting to me because it's essentially Outsourcing this hard problem of deciding where to provide liquidity to the liquidity providers themselves so the mechanism no longer has to solve this problem specifically but instead it's simply General enough to let liquidity providers decide what risk and reward payoffs they want to take by deciding where to concentrate the liquidity um now the there is not a trading function for this one as you probably noticed uh it's hard to appreciate the complexity that uniswot V3 can provide with a trading function instead what you're seeing is a liquidity graph so um on the x-axis is essentially the price and on the y-axis is the liquidity at any given point which is essentially how flat the trading function is there and you can see for reference just for fun we have uniswot V2 which is just flat because it's uniform whereas uniswot V3 has this very complex shape because this is sort of the combination of all these different ranges uh that all these uniswap V3 liquidity providers are providing liquidity in and so um as everyone's probably aware this has become extremely popular and uh is responsible for a huge proportion of the D5 trading volume because of how powerful this this mechanism is so that concludes all the uh specific amm types I'm going to cover today um to close things out I'd like to briefly cover how we can build on top of these great on-chain mechanisms and leverage off-chain computation as well to improve upon them even more so the first thing I want to cover are requests for quote systems so I alluded to this earlier and essentially what this is um is it allows the market maker to do completely off-chain pricing right so you can either leverage a real-time Oracle or you can leverage actual traditional professional market makers that are constantly manipulating the order book um and you can then provide an API that anyone can hit and they can get a quote and a signature with that quote and you can then take that quote and signature on chain and you can then execute it and compose it with all these other amms as well um and so this becomes a powerful mechanism where we can leverage uh this these off-chain resources which often allow for more efficient pricing um while still maintaining a lot of these on-chain benefits that we get from amms and so we have a few examples there one is Clipper RFQ which I mentioned which leverages that off chain Oracle hash flow is another one that leverages these traditional essentially Market making tactics and provides that as a RFQ API that can then be leveraged on chain so with all of that in mind uh I'd like to close things out by asking the question now from the Trader's Point of View um how do we actually navigate this complex landscape and figure out where and how much to trade right and just to summarize um what we've covered here are many different types of amms which all have different purposes um each type of amm is actually implemented many many times on chain sometimes thousands of times in the case of uniswot V2 so you have many choices there as well uh it turns out since these trading functions are always adjusting their prices as you trade through them uh for any direct pair of assets the best place to trade is actually usually a combination of different uh liquidity pools instead of just picking one so your problem is not just picking uh one place it's actually picking some arbitrary combination right and if all that wasn't enough uh the best trading price is often actually routing through other tokens as well um and so the answer to all this uh as you may guess is of course Dex aggregators right we have a very hard optimization problem and we can essentially uh leverage off-chain computation um to solve this problem and provide again uh a transaction that still maintains a lot of the great qualities of on-chain amms by still allowing for Atomic execution self-custody uh still you still have protection from slippage um and so this is an incredibly powerful mechanism uh and I have an example of uh a particular trade you can execute with Odo specifically now with otos we visualize these uh aggregation paths with what's called a Sankey diagram and it's essentially showing the flow from the left hand side to the right hand side through all these other assets and all these other dexes this one in particular actually has about 40 different swaps so 40 different decks integration interactions that you can execute all atomically um this one is also showing multiple assets being traded at once so this is another benefit that we can get from uh sort of combining these amms like building blocks into a bigger transaction to execute a given trade um and so yeah that's aggregators very powerful and sort of an example again of leveraging this off-chain execution um for uh even better experience over these amazing amm mechanisms and so that concludes things um a few final notes uh the parent company of odos semiotic Labs is actually giving a couple other talks today so uh I encourage you to check those out they're related to artificial intelligence and cryptography work related to our work as core devs for the graph um and we are also hiring so you can feel free to reach out if any of that sounds interesting um so yeah that's time [Applause]
