You might be wondering what is an Automated Market Maker (AMM). Well AMM allows traders to buy & sell certain coins using an algorithm that decides price based on demand & supply. As someone buys one asset, it gets more & more expensive as there is less of it. Similarly on the flip side, if someone sells an asset, it gets cheaper & cheaper.

All of this is pure supply and demand as I mentioned above but it is done using an algorithm instead of a traditional method that uses a person (Centralised Entity). In this article, we’re going to cover what an Automated Market Maker is & exactly how it works.

## Constant Product AMM

Take a basic example of a Potato farmer. You are a Potato farmer & you’re sick of seeing Potatoes everywhere at farms, homes & dining tables. Even though you can cook Potatoes in some interesting ways you don’t want to eat any more Potatoes. But here’s a kicker though, you live in a village of only Potato farmers so you can’t really trade your Potatoes for anything else. It would be nice if you could trade your Potatoes for something like Apples.

Then you come across a person who has a boat & he says he knows the person on the far end of a river who is sick with so many Apples. That person asks if you’re interested in trading & now that your wish is true, you don’t want to chance to disappear. You agree to the offer & say yes. The person says he has received 50,000 apples from that village for his exchange business & if you can give 50,000 potatoes we can get started. Your village has a meeting & you all agree to accept the trade.

To safeguard the trade, the trader says that he will multiply the total number of apples and potatoes which is 2.5 billion. If there are fewer apples & more potatoes at a later point in time, apples would become more expensive to buy.

Now you may wonder, why did I tell you such a long story but this is actually the formula of an Automated Market Maker protocol called a constant product market maker protocol. It uses the inverse formula x*y=k, where x & y are the quantities of items and k is a constant that remains the same.

So right now there were 50,000 apples and 50,000 potatoes. k for this case must be equal to 2.5 billion when multiplied. Now, assume another person comes with 7,000 extra potatoes and he wants apples desperately, so now we have 57,000 potatoes. The question is how many apples do we give to the person?

We take 2.5 billion and divide it by 57,000. The answer we get is 43,859. This should be the number of apples that must be left after the trade is executed. Right now there are 50,000 apples so we give 6140 apples for 7000 potatoes to the farmer.

I hope now you understand why the farmer got fewer apples for 7000 potatoes. That’s because apples had a higher demand than potatoes & when someone buys potatoes in exchange for apples, it gets balanced out.

## Big Question: How much each cost in USD?

Assume that there was $50,000 worth of apples in the basket at the first hand. Each one of the apples was priced at $1 in the beginning. Now that the apples have been lower in supply after the first trade & we have 57,000 potatoes, each potato would cost $0.87 keeping the value constant. Apples on the flip side would be worth $1.14 each because of the lower supply.

You may again wonder why did the price of potatoes drop from $1? Well, that’s because someone added more potatoes to the basket.

The more of an asset there is in the AMM pool, the lesser it would cost.

## Another Example

Let’s say another Potato farmer brings up another 10,000 potatoes, so now there are 67,000 potatoes in the pool. We need to know how many apples to give out to the farmer. So using the constant of 2.5 billion divided by 67,000 we get 37,313. This means that there should be 37,313 apples in the pool. Right now we have 43,859. So we give 6,546 apples to the new farmer in exchange for 10,000 potatoes.

This time the farmer paid even more for the apples since he kept buying them up. The liquidity pool keeps charging more & more for apples & never runs out of stock. The price would jump exponentially as he buys more.

So now there would be 67,000 potatoes and 37,313 apples in our liquidity pool. Both of these numbers multiply to a total of 2.5 billion so that the liquidity pool stays functional.

Coming to the price of each potato we divide $50,000 by 67,000 potatoes which means each potato now costs $0.74 they dropped even lower. Similarly, the apples are now $1.34 cents each meaning they went up in price.

So again like our previous example, we saw that there are now more potatoes which led to an overall price drop & fewer apples which led to a price hike. Basically, that is how an AMM works. As someone buys more & more of something, the price goes up.

As for pricing, the algorithm always wants the pricing of what it is holding to be 50:50. So if you multiply the price of each asset by the quantity, you’ll get $50,000 worth of potatoes & $50,000 worth of apples.

## Last Example

This time an apple farmer comes along with 2,000 apples and he adds them to the Liquidity Pool and now there are 39,313 apples in the pool. We need to figure out how many potatoes to give him.

We divide 2.5 billion by 39,313 and we get 63,592 which is how many potatoes should be in the pool. Right now there are still 67,000 potatoes so we take the difference of 3,408 potatoes & give them to the apple farmer.

In essence, the farmer gave 2,000 apples & got 3,408 potatoes because at the time his apples were very valuable.

All of these were very vague examples that I used & if you are still kinda confused I would suggest you send me a text on Twitter to help you figure out even more.