What is an Automated Market Maker? (Liquidity Pool Algorithm)

What is an Automated Market Maker? 

You might be wondering what an automated market maker is? 

An automated market maker allows traders to buy and sell certain coins using an algorithm that dictates how expensive something should be based on how much of it is.

As someone buys one asset, it gets more and more expensive because there’s less of it, and as they give it another asset, it gets cheaper and cheaper because there’s more of it.

Basically, it’s supply and demand, but it’s using an algorithm instead of the traditional method, which uses a person.

Welcome to Shavuna; we explain cryptocurrency topics using analogies, stories, and examples so that you can actually understand them.

In this blog post, we will cover what an automated market maker is and exactly how it works.

Let’s get started.

Let’s say that you’re a mango farmer; you’re sick and tired of going to work and seeing mangos everywhere, then coming home to eat only more mangos. Even though you can cook some mangos in exciting ways, you do not want any more mangos.

But here’s the real kicker though, you live in a village of mangos farmers, so you can’t really trade your mangos for anything else.

“It would be nice to trade my mangos for something else like bananas,” you think.

Along comes a trader who has access to a boat, and he says that he found a village over east that grows bananas, and they are sick of them, and he is there to see if you would like to invest in a trade.

Now that your wish has come true and you don’t want the chance to disappear, you tell the trader “yes.” He says the banana farmers have put up 50,000 bananas to add to my banana mango exchange business, and if you can give him 50,000 mangos, you can get started.

So your village has a meeting, and they decide to join the trader in exchanging bananas and mangos.

The trader goes, here’s the thing though I have a magical genie with me that will store all 50,000 bananas and all 50,000 mangos in his magical lamp to keep safe that way; they don’t go bad.

But he wants to keep a perfect ratio of the value of both of these. The trader goes on since together we put in 50,000 bananas and 50,000 mangos, he wants both of these numbers always to multiply to equal 2.5 billion, which is equal to 50,000 multiplied by 50,000.

This way, if there are fewer bananas in one year, the bananas will cost more to buy.

Now, if you’re currently confused about what the magical genie is. It is actually the formula for a type of automated market maker called a Constant Product Automated Market Maker.

It uses the inverse formula x times y equals k (X*Y=K).

Well, x and y are the quantities or the amounts of the things you have where k is a constant that always stays the same, and it does not change.

In this case, k is 2.5 billion.

Let’s keep going on with the example above so that maybe you can understand it just a bit better.

The trader says there is a perfect 50 to 50 ratio of mangos to bananas right now, but that is because I have priced them each at a dollar.

When you guys start trading, one of these may become more valuable, and thus it should be priced at more than a dollar.

For example,  right now, there are fifty thousand bananas and fifty thousand mangos, and the number of both of those must equal 2.5 billion when multiplied.

So let’s say a mango farmer comes along with 7,000 mangos to trade because they really want some bananas. He gives them to the genie, and he waits while the genie figures out how many bananas to provide him with.

Now, we have 57,000 mangos in the genie’s lamp, but we need to know how many bananas to give the mango farmer. Let’s start with some math.

We take 2.5 billion, and we divide it by 57,000. You might be wondering why? Hopefully, you’ll see it in a minute.

The answer we get to this math question is 43,859. This is the number of bananas that should be leftover in the magical genie’s lamp.

However, there’s 50,000, so we just need to determine the difference and give the difference to the mangos farmer. The difference is six thousand one hundred forty. 

We give the mango farmer six thousand one hundred and forty bananas.

Now you might be wondering how come we gave seven thousand mangos, but we got around six thousand bananas?

Well, as more and more bananas were bought up, they became more expensive. This is why the farmer didn’t get precisely 7,000 bananas back.

And now there are 57,000 mangos and 43 859 bananas in the genie’s lamp.

Let’s make sure that we didn’t upset the genie; 57,000 times 43,859 does equal 2.5 billion, so the magical genie is still happy.

I hope that this is starting to make sense.

Before we continue with another example, let’s run over a quick example of finding out how much each asset costs in dollars.

Assume that there was fifty thousand dollars worth of bananas in the beginning since the magical genie said he priced them at one dollar, and there was 50,000 of them.

We just need to keep $50,000 as a constant when we’re calculating their value. This is how much each asset should equal.

So mangos would be $50,000 over 57,000 because that’s how many mangos we have, which brings their price to 87.7 pennies for each mango.

You might be wondering why did they drop from a dollar?

Well, it’s because someone brought a lot more of them to the genie. It’s basic supply and demand.

For example, if you could grow gold on trees in your backyard, gold would suddenly be a lot cheaper because there’s a lot more of it.

The more there is in the genie’s lamp, the less they will cost.

From now on, instead of saying genie’s lamp, I’m going to call it what it really is a liquidity pool.

Now let’s calculate the price of the bananas.

This calculation would be fifty thousand dollars over forty three thousand eight hundred and fifty nine. This means the bananas are worth a dollar and fourteen cents.

They rose in price because there’s less of them in the liquidity pool. Since this mango trader gave a bunch of mangos to the liquidity pool and took out a bunch of bananas, the price of bananas went up, and the cost of mangos went down basically due to supply and demand, which is shown in the formula; x times y equals k.

Let’s go over another example; let’s say a mango farmer brings up another 10,000 mangos. Now there are 67,000 mangos in the pool. We need to know how many bananas to give that mango farmer.

We use our constant of 2.5 billion divided by 67,000, and we get 37,313. This means that there should be 37,313 bananas in the pool, but right now, we have 43,859. So we just calculate the difference and give it to the mango farmer, which is 6,546.

The mango farmer paid even more for his bananas this time since he kept buying them up.

The liquidity pool charges more and more for them; that way, it never runs out of stock. The price will exponentially keep going up as he buys more.

There are sixty-seven thousand mangos and thirty-seven thousand three hundred thirteen bananas in our liquidity pool. Both of these numbers multiply to give 2,5 billion.

The genie, which is actually the algorithm, is happy.

Now let’s calculate the price. Fifty thousand dollars divided by sixty seven thousand mangos means the mangos are worth 74.6 pennies; they dropped even lower.

Next, fifty thousand dollars divided by thirty seven thousand three hundred thirteen bananas means the bananas are now worth a dollar and 34 cents; they rose in price.

Again, we saw that there were more mangos than before, so the price dropped, and there were fewer bananas than before, and the price rose.

Hopefully, you understand how an automated market maker works. As someone buys more and more of something, the price goes up. 

The bananas are costing more because there’s less of them, and when it comes to pricing, the algorithm always wants the value of what it holds to be 50 50. 

If you multiply the price of each asset by how many assets were total in the liquidity pool, the total would still be fifty thousand dollars worth of bananas and fifty thousand dollars worth of mangos.

Let’s do one more example really quick just to drive it home.

This time a banana farmer comes along with two thousand bananas. He adds them to the liquidity pool, and now there are 39,313 bananas, but we need to figure out how many mangos to give him.

If you want to, you try to come up with a number on your own.

Finishing the math, 2.5 billion divided by 39, 313 gives us 63, 592 which is how many mangos there should be in the pool, and right now there’s still 67,000 mangos, and the pool only wants sixty three thousand five hundred ninety two.

So we take the difference and give it to the banana farmer, which is three thousand four hundred eight mangos.

In essence, the farmer gave two thousand bananas and got three thousand four hundred eight mangos because, at the time, his bananas were precious.

Now, we went over those examples really quick, and feel free to go back to the beginning of this article and read it again; and if you’re still kind of confused, I highly recommend reading our article on liquidity pools and how they work.

But one thing I want you to know is that an actual liquidity pool can sometimes have up to millions of dollars worth of assets in it, and you should know the more money that is in a liquidity pool, the stabler the price is.

If there were half a million bananas and half a million mangos and you still only wanted to trade around 2,000 bananas, the price difference wouldn’t change as much as we saw in our example because the number of bananas you were trading in proportion to the number of bananas in the pool was a minimal amount.

Also, you should know that liquidity pools reward investors and the investors are the people who put up the money into the liquidity pool in the first place.

They give those investors a small fraction of each trade that happens on their platform, even if this is less than one percent of each trade.

If someone is trading multiple times a day, those numbers add up, which can be profitable for the investor.

Another thing to know about liquidity pools is that they can get complicated really fast because what if another trader came along and wanted to add another 50,000 bananas and 50,000 mangos from the villages that he found.

How do we ensure that the investors can take out their original investment as the price changes?

What about if we find an banana farmer and we want to add him to the trading pool?

Well, there are answers to these questions, but they’re for a different post as this one has come to its end.

We try to keep these blog posts short and effortless to understand.

Thank you guys very much for reading. I hope that you learned something, and we hope to see you in the next blog post.

Shavuna
Logo