Automated Market Makers (AMMs) are decentralized trading systems that use a mathematical formula (x × y = k) to automatically calculate prices between two tokens, eliminating the need for traditional order books that require constant negotiation between buyers and sellers. In an AMM, buyers and sellers trade directly with a smart contract pool containing both tokens, and the price adjusts based on the ratio of tokens in the pool. When prices deviate from market equilibrium, arbitrageurs restore balance by trading back to the pool, while liquidity providers earn fees (typically 0.1-0.3%) for supplying tokens to the pool. This system solves the problem of slow and expensive smart contract transactions that make traditional order books impractical on blockchains.
Automated Market Makers Explained: Function and Purpose in DeFi
Added:is about automated market makers now this is easily one of the most talked-about primitives or concepts in defy these days but it's actually one of the least understood and most scariest ones to actually understand and to be honest it's taken me a while to really wrap my head around these crazy twisted machines and I hope that this video unravels some of the mystery for you so in this video first we're kind of before we even talk about what in automated market maker is I won't actually talk about how a traditional order book works because then that gives us context is to what problem in order book has on the blockchain with smart contracts and why automated automated market makers actually solve this problem so we know why we need automated market makers and why they're so good we can then talk about how they work and some of the mats around it so that when you come across this in the wild you have a much better intuition so let's get started cool so number one traditional order books this is basically how any existing exchange works in the real world right now so we have Bob who says I want to sell something say ten dollars of a coin alright and this is claims over here and then you have Alice over here who says I want to buy nine dollars worth of some coin over here and the role of the exchange which is in the middle over here is to match both of these two together and helping them essentially what we call fill each other's orders so in this case Bob would sell essentially 90% of his order because it's his $9 his $10 9 of it is being filled over here and Alice her $9 is entirely filled now this is very very simplified but the point which I want to illustrate here is this exchange is kind of like much making service where it says ok you have a buyer you have a seller let's connect them and do what we need to fill this order now if we go in a bit more depth the way in order actually looks is we might have say sell 10 8 at $100 over here so we have the quantity and the price and then we might have on the other side things so I'm saying by 5/8 $90 all right and what you have kind of hair is kind of the war right because this person wants to sell 10 at $100 and this president wants to buy 5 at 90 and essentially what we then see in the order book is these two entries next to each other in the way the price is calculated is when these two when these two kind of agree to come in the middle so Alice might say hmmm it's been ten minutes nobody's taking my order let me offer let me offer instead of $90 $95 and see if anyone takes Bob Waits wall and he says no one's taking a hundred let me maybe offer 97 and eventually there's a point at which they meet and let's suppose that's actually eventually $95 because Bob decides to come down so the price of say eath in this case is now gonna be set at $95 and what we're essentially seeing here is that there's kind of like a tug of war between cells and bison if you've ever seen in exchange you kind of have these graphs that look a little something like this where this is your middle right where you've got like this green versus red war going on and what this really is saying is the kind of depth of the order book at different prices so these are all the orders that say $10 at a hundred dollars and a thousand dollars and what you can kind of see is it like how much buying and selling pressure is there at different price points and for what quantities so of course with this I you can kind of see that order books in their traditional sense they're quite complex cuz you have to essentially find a price which the other side wants to buy it without losing too much value in the process so this kind of has worked great for many years because in traditional finance because we have fast computers that can keep changing these things now the issue with smart contracts when we kind of simplify it down is that they are slow they are expensive and they are yeah there are so many expensive basically and what this means is that when we want to run a traditional order book like the above it's not really that straightforward because the smart contract has to keep on being called and each call incurs a cost it takes time so essentially a traditional order book on a smaller contract is terrible because if one transaction takes anywhere between say like 1 to 5 minutes and maybe like 20 cents to $1 we can't really be paying this much of a fee to just even update a trade not even for it to settle so what the whole beauty around automated mark makers is that they solve this order of a problem for smart contracts and how do they do that let's kind of dig in so let's use a nice hair so a mess the real magic is essentially that there is no order book what yeah it's really cool the way it works is that the smart contract basically calculates a price continuously and buyers and seller can determine whether they want to buy or sell at a predetermined price there is no order book so rather than in our previous example where we had Bob and Alice coming together in meeting on an exchange we now have a different model where Bob simply goes to a smart contract and it will give him back a price and we have Alice on the other side who also will go to the same smart contract and will get a price neither of these two actually are ever trading against each other they simply trade with the smart contract and the whole thing around this is that the price is calculated on essentially a rake gyeo between the two tokens so we'll go deeper into this next bitter on the mat and how this kind of works but just want to reiterate the fact that there is no order book it's simply you get quoted a price and you take it or you leave it now how is this price determined I kind of touched on this is a ratio but let's dig into it a bit more so this is what I call Amen math 101 or the conceptual understanding okay so the way aim and math works is as we said before between a ratio of two tokens now the way this ratio is calculated is through an equation called x times y which gives us a constant as in this never changes so let's suppose that the price of eath is at $100 and dye is $1 the way name and works to begin with is that we supply an equal amount of quantities of each token so if we want to supply an equal not of Ethan died let's say and at $1000 Evie each quantity we would supply 10 etherium and 1,000 die which gives us 10,000 is our constant now this is X and this is y this is K the price of eat is equal to Y divided by X which is a thousand divided by 10 which is a hundred that checks out and the price of dye is equal to X divided by Y which is 10 divided by 1000 which is equal to 0.01 cool now essentially the way this kind of works is when someone makes a trade is that they give a quantity of one token and get back another from the pool so now let's say somebody wants to buy eath from the pool and let's just say they want to buy 1/8 so what that essentially means is they're going to be giving 8th to the pool and taking die in return so we had 10 richly they're taking away one and we had 1,000 died the pool and we're going to be getting a certain amount but at the end of the day this has to equal back to 10,000 and once we fear our X we can figure out the prices so let's just go ahead and carry on so we've got nine times 1,000 plus X is equal to 10,000 so 1,000 plus X is equal to 10,000 divided by nine one thousand plus X is equal to let's do this 10,000 divided by nine 1111 1111 which means X is equal to 1111 minus 1,000 this is a 1 1 1 you know it's simplify the decimals so what we're seeing over here is that in order for this person to buy 1/8 from the pool they are going to be paying a hundred and eleven dollars for that eath or sorry know the price of eath in the pool has now changed to one hundred and eleven dollars and why does that happen simply because the ratio of eat to die change and that's conceptually like how the math around an automated market make it works and now kind of getting a bit deeper is the fact that this is not actually the real price means that somebody else is going to take advantage and bring the price back to what it should be so let's say the price is actually still a hundred dollars on coin base but the price to buy eath over here is a hundred and eleven dollars so what someone will do is they'll get eat from coin base and try and sell it back to the automated market maker so in this case let's go back to our simple equation where we have nine eath in the pool and we have 1111 died in the pool with our constant being 10,000 so somebody's saying that I'm actually get this hundred dollars worth of eat or this eath for a hundred dollars and I can now make an eleven dollar profit by giving it back to this pool itself so what they'll do is they'll say here you go pool I'm going to give you one extra eighth and you will give me a certain amount of die back and this is gonna be ten thousand now in case this kind of looks familiar this is exactly what we kind of had when we started off with and you can just run through the math we can go through this minus X equals 10,000 1 1 1 minus x equals 1,000 X is equal to 1 1 1 yep which means that our equation is now at and that's exactly where we started off with so in essence someone bought eath which subtracted 1/8 from the pool and bought a bunch of dye which changed the ratios to this new price over here then someone else realizes is the incorrect price so they've got the eath from somewhere else sold it back to the pool made an $11 profit and in return they bought the price back to what it should be so the way you know an AMM works is essentially relying on arbitrage Azur ARBs as we call them to bring back the price by finding these profit opportunities and intuitively if we draw out this equation x times y equals k it kind of looks a little something like this and you basically keep moving so say this is your token X and this is your token Y basically you keep moving up and down this curve based on the ratio of tokens and the more tokens that you have in both quantities or the bigger that your K is the smaller the price change if you buy or a sell a certain quantity of tokens and like just to get a really clear understanding if we had say ten times a thousand which gives us 10,000 a week as we used in our example one by buying one eight you're changing the pool by the price by almost 10% but if this number was actually say 1,000 a hundred thousand then this K is much larger and as a result if you bought or sold 1/8 it would probably have a less than 1% change in the price and that's what we call order book depth so the deeper the order book is the less the price change as you buy a larger quantity of tokens and that's what makes a mem so powerful because all I have to do is give two quantities of tokens to the smart contract and it will in turn set the correct price and make sure that I can consistently make money for providing this liquidity and the way I do it is that each tray that occurs on an AM M incurs a fee usually to the tune of about 0.3% to maybe 0.1% so every time I buy and take tokens from this curve I pay a little fee and that's why I'm incentivized to give a bit of a tin a bit of dye to essentially what we call the market maker and hopefully that ladies and gentleman gives you an overview of how a man works so just to kind of resize we have traditional order books which are kind of constant negotiation between buyers and sellers but as we learned that the problem with order books is that there's this kind of consistent kind of updating or editing that needs to happen and because smart contracts are slow and expensive this isn't really feasible so instead we have automated market makers which rely on no order books and the smart contract calculates surprise and the way calculates surprise is by determining the ratio of two to determining the price by determining the ratio of two Hogan's and we determined that through this equation called x times y equals K where we will always get one side of the equation which we want to say update we work out the difference and that difference can then tell us the new price and any shift in the price from the real price means that arbitrage is can restore the price by selling back to the pool or kind of reversing the trade and because of this entire system and elegance of the smart contract calculating the price we don't actually need order books we simply have a contract which tells us the price of the quantity of tokens so we're buying and the deeper the order book is the less change in price we experience so yeah and if I provide liquidity as an I provide both x and y to this equation i will earn a fee for doing so because I'm providing service to other users and that is literally just how an automated market maker works at a very conceptual level I'll if I'll make other videos which goes into this in more detail but hopefully this gives you all a very good understanding of how these things work and why they're so useful Thanks see ya
Up Next

Liquidity Pools in Crypto: Uniswap & PancakeSwap Explained
@CryptoAnimations
412 views•2021-12-05

Torrent File Format & Bencoding: A Technical Deep Dive
@AsliEngineering
12.5K views•2022-08-08

Operational Security Essentials: A Guide for Hacktivists (OPSEC)
@hitbsecconf
157.4K views•2012-11-26

Understanding Ethereum: A Comprehensive Beginner's Overview
@99Bitcoins
3.1M views•2018-06-26
Related Study Plans & Knowledge Roadmaps
Structured learning paths in Blockchain & Crypto



![[r3s] Blockchain 102 (Henryk Plötz)](https://i.ytimg.com/vi/MiLnDe_bX6Y/maxresdefault.jpg)



































