Published in


Market Maker & Automated Market Maker

AESwap, one of aelf’s most important DeFi products. At the moment, any community member can try out this product using ELF test tokens.

Many of you know how popular DeFi is, but you might not be familiar with the actual DeFi projects. For example, we see lots of “swaps” in this field, including Uniswap, JustSwap, SushiSwap, etc. In this article, we will briefly introduce this type of “swap” to give you a basic understanding of what DeFi really is.

Essentially, these “swaps” are called automated market maker(AMM), if you trade stocks, you must be quite familiar with “market maker”. But for those of you who don’t or seldom trade stocks or tokens, a short explanation is in order.

In finance, market maker is a firm or individual who are often brokerage houses, such as exchanges, actively quoting two-sided markets in a security, providing bids and offers (known as asks) along with the market size of each. They buy stocks of some companies, and quote the price for selling and buying the stocks, that is, they have an ask (they will sell), and a bid (they will buy). For example, suppose Company A’s ask is $10 per share and the bid is $9 per share, this is because the exchange needs to profit from the $1 difference, which is also called the bid-ask spread. If a new trader wants to buy Company A’s stocks on this exchange, he has to buy at $10, vise versa, if he wants to sell, he has to sell at $9.

In this example, he buys Company A’s stocks at $10 per share, which is the current price, that is, the latest price they are traded. Moreover, just like the exchange, anyone can set his own bid and ask. Suppose there is Company A’s stocks have a huge trading volume, now there must be a lot of traders who are holding the stocks and are setting the asks. In this case, let’s say Alice thinks the stocks are quite worth the value, she can set the ask at $12 and offer 200 shares, which ($12, 200 shares, ask) makes an order. Now Bob thinks the stock isn’t so valuable, so he sets the ask at $11, and offer 300 shares. Charlie and others can also set the ask this way. On the other hand, there must also be many people who want to buy this stock, and just like the sellers, buyers will also set the bid and the amount they want to buy. That’s why we always see a series of order log as follows:



( $13, 500 )

( $12, 100 )

( $11, 250 )

( $10, 300 )


( $9, 100 )

( $8.5, 300 )

( $8, 350 )

( $7, 400 )


This log is what we call the “order book”. The order book is an important tool for analyzing the short-term fluctuation of stock price, or any other asset price, say, cryptocurrency or tokens! And we always analyze with another tool, the famous candlestick chart. In some centralized token exchanges such as Huobi, we can see the order book is just on the right-hand side of the web page, which is the core part of the market maker.

We can see that in MM the market price is completely determined by traders’ sentiment, i.e. the orders in the order book.

The new automated market maker (AMM) is quite different. In AMM, the prices are no longer determined by human factors, instead, they are completely determined by algorithms. What does it mean?

In AMM, generally two tokens (e.g. ETH and USDT) form a trading pair, those who hold these two tokens can deposit them into this pair, thus making the pair a liquidity pool where people who want to exchange ETH for USDT can swap their tokens in this pool, and vice versa. But if you really want to swap, the token price must be what you care about most. In AMM, the price of one token is relative to its counterpart, and is determined by algorithms.

There are various implementations of this automated algorithm, of which the most popular one is called “constant product formula”, whose equation is:

x*y = k

x and y are the amount of the two tokens, k is the constant, which is also called invariable.

And the token price is the ratio between the two:

P = x/y

This is because this pool is seen as an isolated environment, like the ETH-USDT pool mentioned above. In this pool, the total fiat value of ETH must equal to that of USDT:

P(ETH) * x = P(USDT) * y

Which equals:

P(ETH/USDT) = y/x

For example, suppose there are 100 ETHs and 10,000 USDTs in this pool, then the price of ETH to USDT is 10,000/100 = 100.

You might ask: why this seemingly simple formula is so effective?

First, it gets rid of the limitation on liquidity. If we draw the curve of x*y=k, we will see a half hyperbola.

Now suppose there are 100 ETHs and 10,000 USDTs in the pool, meanwhile, in a typical centralized exchange, say Huobi, the ETH/USDT is 100. If I want to exchange for 60 ETHs from the pool, how many USDTs does it cost?

According to the constant product formula, k=100*10,000=1,000,000, now ETH is 40 (100–60=40), and the amount of USDT should be 1,000,000/40 = 25,000, the price of ETH to USDT becomes 25,000/40 = 625. One couldn’t possibly buy so many ETH at such a high price (625) relative to 100 in Huobi exchange. So, as you can see, people are not incentivized to trade a large amount of tokens in this AMM, instead, they only trade a very small amount relative to the total deposit amount, say, 0.05 ETH, which would’t make the price too different from that on Huobi. But there is no such incentive to prevent people from trading in such a large amount, and they are incentivized to do that, because by doing that they could have a big impact on the market price without being affected themselves. In this case, we say there isn’t enough liquidity in this market, or there isn’t enough market depth, or put it another way:

In an asset market with enough liquidity, there isn’t such an order which could make a big impact on the market price.

Second, AMM automatically stabilizes the price through arbitrage mechanism.

Suppose the price of ETH on Huobi changes to 150, whereas in AMM, ETH’s price is still 100, now smart traders will definitely buy ETH in AMM and then sell them on Huobi to make a profit, by doing so, the amount of ETH in AMM will start to decrease, which means ETH will become more expensive there. People won’t stop arbitrage until ETH’s price reaches 150 in AMM (the transaction fee is not considered here).

One more example, suppose we add 100 ETHs to the pool, now we have 200 ETHs and 10,000 USDTs, which means the value of ETH will go down by half in AMM. If you are smart, you will surely buy ETH in AMM and sell them on Huobi for a profit. As mentioned before, the amount of ETH in AMM will go back to 100, but then the amount of ETH in the pool provided by everyone will decrease by half, thus incurring losses. Therefore, when provide liquidity, every swap dApp will remind you that:

Please provide ETH and an amount of USDT of the same fiat value.

Finally, you must know that k is not always constant, if we don’t add new liquidity into the pool and just do token swap, then k is constant, but when we add or remove liquidity in the pool, k will go up or down.

— Join the Community:

· Get on our Telegram Discord Slack and Kakao channel

· Follow us on Twitter Reddit and Facebook

· Read weekly articles on the aelf blog

· Catch up with the develop progress on Github

· Telegram community in 한국, 日本 語, русский, العربية, Deutsch, Italiano and Tiếng Việt

· Instagram: aelfblockchain

· YouTube Channel: aelf

For more information, visit



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store