AMM automatic market maker science

AMM (market maker) runs through the DeFi world, and the AMM model also builds the foundation for the prosperity of the DeFi world. If you want to build a basic understanding of the DeFi world, it is recommended to read the following carefully, Let’s for fun.

What is AMM (Automatic Market Maker)

Before we understand AMM, let us take a look at what is a market maker in the traditional sense? The so-called market maker (AMM) is an entity responsible for providing liquidity for exchanges and conducting price operations at the same time. This is achieved by MM buying and selling assets from their own accounts. Their purpose is to make a profit. Their trading activities create liquidity for other traders, which reduces the slippage of block transactions, before the large-scale popularization of computer trading , Market makers are an indispensable part of the trading market.

The cryptocurrency market also has the need to provide liquidity and pricing, but in the pursuit of decentralization in the cryptocurrency market, this centralized market maker mechanism is not used by people. Therefore, automated market makers (AMM) are produced, which use algorithmic “robots” to simulate these price behaviors in electronic markets such as DeFi. We can think of AMM as a primitive, robotic market maker, who provides quotes between two assets at any time for users to trade according to a self-defined pricing model.

AMM category and its pricing model

Constant Function Market Maker (CFMM) is currently the most popular AMM.

When a trader wants to trade between AB tokens, this AMM will use a constant function as its pricing mechanism. “Constant function” here means that the value of a certain function of the reserve of two or more trading assets must remain unchanged during any transaction.

The current mainstream CFMM has the following types:

A. Constant product (Uniswap)

This kind of AMM requires that the product of the two asset reserves always remain the same, namely:

x * y = k

In this equation, X and Y represent the number of units of the two assets in the liquidity pool. For example, suppose the ETH/DAI pool contains 100ETH(X) and 10000DAI(Y). At this time K=1,000,000. The goal now is to keep the value of k constant regardless of the volume of transactions to the liquidity pool. The only way to do this is to reverse the number of x and y. In other words, when the number of x increases (the trader adds ETH to the pool), the number of y must decrease (the trader takes DAI out of the pool). Ultimately, the price quoted on any given exchange is a function of the constant product formula and the proportion of tokens in the pool. The following figure approximates the exchange relationship between the two types of assets in this model.

AMM automatic market maker science

It can be seen that in this way, the exchange between the two types of assets is not a linear relationship, but a hyperbolic curve. In this mode, liquidity is always available, but the shortcomings are also obvious:

Slippage occurs in transactions, especially when the larger the transaction, the greater the slippage.

The price of assets may get higher and higher, with both ends approaching infinity

Unable to meet the needs of pending orders

B. Constant sum (CSMM)

This type of AMM follows the formula of x + y = k, so that zero slippage can be achieved in the transaction. But his fatal thing is that it cannot provide unlimited liquidity. If the reference price of the reserve token is not equal to 1, all arbitrageurs will continue to buy one of the tokens until its liquidity is exhausted. Therefore, it is not a common AMM mechanism .

AMM automatic market maker science

C. Constant average (Balancer)

The constant average market maker is derived from the concept of a constant product market maker, which can be used for more than two assets, and the weight ratio is not limited to 50/50.

This type is actually a variant of the constant product model. The formula is as follows, where Bt is the number of assets t and Wt is the weight

AMM automatic market maker science

Similar to Uniswap, the goal is to change only the asset balance while keeping the asset weight unchanged, thereby keeping k unchanged. In the case of the Balancer Pool of three assets, transactions can occur between any two of the three assets. Users can exchange ETH for DAI, ETH for BTC, or DAI for ETH. By keeping the value of k unchanged, a value surface can be generated among the three assets. This value is actually not much different from the Uniswap curve, just a few more dimensions.

The difference is that in this model, the pricing model becomes more complicated.

There are 2-8 kinds of assets allowed in the balancer fund pool. Each pair of tokens in the pool has a price, which depends on the balance B and weight W of that particular token. From a formal point of view, the price of transaction execution is calculated according to the ratio of the token balance to the token weight.

AMM automatic market maker science

In the above formula, token A represents the token sold (into the pool) and token B is the token bought (out of the pool). If the holders of the pool do not change the asset reserve, it is easy to see that the price changes are entirely based on transactions, because the asset weight must always remain the same. This mechanism, combined with the constant surface shown in Figure 2, can ensure that the price of buying assets rises while the price of selling assets falls. In the same situation as Uniswap, arbitrage opportunities ensure that the prices offered by Balancer Pools move in sync with the rest of the market.

D. Hybrid CFMM (Curve)

After analyzing the above three models, we can see that they all have their own advantages and disadvantages, so some projects want to obtain ideal properties based on asset characteristics by using hybrid functions. The representative project among them is Curve

Curve is an exchange liquidity pool, and it is expected that assets with stable prices can be efficiently traded in this pool (such as stable coins or wrapped bitcoins). Uniswap and Balancer are mainly for the trading of volatile and unstable tokens. However, when dealing with transactions between assets that want to maintain stability with each other, low price slippage is the most important. The inherent curvature of the various AMMs of the previous iteration is problematic, because the larger the transaction size, the greater the slippage.

From the above we can see that the Heng Sum mechanism can achieve no slippage, but it cannot stimulate liquidity. Therefore, Curve creates a hybrid AMM based on the CSMM combined with a constant product function:

This function creates a relatively flat curve near the equilibrium point of the constant product curve, similar to the constant sum function, to keep the price relatively stable, while making the ends more inclined, similar to the constant product function, so every point on the curve is There is liquidity. In the case of dual assets (x and y), the final result is the following complex function.

AMM automatic market maker science

Where n is the number of assets (n=2 in the case of dual assets), and A is the “magnification factor” parameter, which determines the degree of similarity between the function and the constant product function. The smaller the value of A, the more similar to the constant product function of Uniswap. There is no need to understand the composition of this function, as long as the purpose of the function is to keep the constant K unchanged during the transaction. The function is drawn as follows:

AMM automatic market maker science

It can be seen that it is more similar to a straight line at the function terminal, showing a constant sum function, but as x and y increase, it moves closer to the constant product function. This shape keeps the price in the middle section of the curve stable, and at the same time can Provide liquidity at both ends.

Market-making model and potential risks

Market-making model:

CFMM mainly has the following three types of participants:

Trader: Hope to exchange a certain type of asset for another type of asset in CFMM

Liquidity providers: provide asset portfolios (trading pairs) to meet transaction needs and earn transaction fees

Arbitrage: Maintaining the assets in the trading pair at market prices through arbitrage

Among the three types of participants, the most important role is the liquidity provider (LP), responsible for injecting their own assets into the smart contract of the DEX, as an asset reserve pool, providing liquidity for transactions, and obtaining transaction fees. income. The second is arbitrageurs, who are responsible for correcting the transaction price to ensure that the transaction price is consistent with the market price, but also incurring impermanent losses (Impermanent Loss), which brings the risk of loss to the liquidity provider.

Let’s take the transaction of asset A and asset B in Uniswap as an example. Before the transaction starts, we need to inject x amount of asset A and y amount of asset B into the smart contract of the blockchain as a liquidity reserve, that is, in the formula x*y=k, the initial values ​​of x, y and k The value is determined by the liquidity provider (LP). Because the initial price P = x / y between asset A and asset B, it can be achieved when the first liquidity provider (LP) recharges assets A and asset B that they consider to be equivalent in value to this smart contract The setting of the initial price P. After opening the transaction, combined with the different types of pricing models we talked about in the first part, the price of assets will continue to change according to the number of assets in the liquidity pool.

From the above, we can see that the automatic market maker system breaks the traditional trading system model. It does not require an order book, nor does it require market maker quotations or system matching. Instead, it uses the liquidity in the reserve pool to complete asset transactions. Exchange; most importantly, the transaction price of AMM is not determined by the market maker’s quotation or the trader’s order, but by the ratio of the number of two assets in the asset pool, so it is a liquidity-driven transaction system.

AMM automatic market maker science

potential risks:

Impermanence loss

Due to the flaws in the model design, AMM had to introduce an arbitrage mechanism to improve its price mechanism. However, this has also brought another serious consequence-impermanent loss (Impermanent Loss)

The loss of impermanence actually comes from arbitrage. We are ahead of time that the transaction price of AMM is derailed from the fair market price. For this reason, arbitrageurs need to come in to buy undervalued assets or sell overvalued assets until the price provided by AMM matches the external market. Therefore, the profits of arbitrageurs actually come from the liquidity providers, and this part of the losses caused by arbitrage to the liquidity providers is called impermanence loss.

The following figure is an example after the arbitrage occurs at T3, the total asset value in the liquidity pool is missing compared to the actual market value. This part of the value is the value earned by the arbitrageur from the liquidity provider.

AMM automatic market maker science

The liquidity provider (LP) provides liquidity to AMM because it can obtain transaction fees, but the existence of impermanent losses increases the risk of the liquidity provider. If the impermanence loss exceeds the liquidity gain, then the LP will no longer provide liquidity. Therefore, the size of the impermanence loss is the key to determining whether the AMM DEX can operate normally.

Multi-generation. Coin exposure

AMM usually requires a liquidity provider (LP) to deposit two different tokens to provide equal liquidity on both sides of the transaction. Therefore, the liquidity provider (LP) cannot keep its long-term risk exposure on a single token, but must divide its exposure by holding additional ERC20 reserve assets. Teams with a large number of tokens, or individual holders who wish to provide liquidity, are forced to purchase another asset to provide liquidity, thereby reducing their holdings in the underlying tokens of the asset pool and increasing their Exposure to another asset.

Advantages and Disadvantages

advantage analysis:

The advantages of AMM are obvious. Its appearance coincides with people’s pursuit of decentralization, automation, and fast transactions in the defi market. At present, most of the transaction volume in the defi market occurs on DEXs that apply AMM. It fully reflects the trust of users in this transaction model. DEX is also currently the most usable trading type of digital currency in the defi market. However, the current AMM mechanism also has many problems. In some aspects, compared with traditional centralized bidding, the market maker mechanism still has shortcomings. These This aspect is also the direction that the current AMM projects on the market will focus on in the future, which will be summarized here.

Disadvantage analysis:

No independent pricing

As we mentioned earlier, the price of AMM is driven by liquidity, and the transaction price is determined by the asset situation in the reserve pool, not the order price. That is, AMM can only generate transaction prices, but cannot find market prices. For this reason, AMM has to introduce the important role of arbitrageur: once the price on the AMM platform is different from the fair market price, there will be room for arbitrage and bring the price back to the right track.

This means that if there is no centralized exchange on the market, the trading platform using AMM cannot reflect the real asset price, so it cannot completely replace the existing bidding system and market maker system.

Transaction depth (slippage):

Transaction depth is one of the important indicators to measure the pros and cons of market transactions, reflecting the market’s ability to withstand large transactions without substantial price fluctuations. Many people in the industry believe that as long as sufficient liquidity is provided to the market, the problem of transaction depth can be solved. This is true for the bidding system and market maker system based on the order book, but for AMM, the model itself will also affect the depth of the transaction.

Compared with the traditional trading system, under the condition of providing the same liquidity, the AMM user puts more assets A into the transaction contract, the less assets B are exchanged, that is, the higher the transaction price. Therefore, the transaction depth of AMM depends not only on the size of LP (ie k value), but also on the model itself. Therefore, although many DEX’s simple trading models have brought great advantages to them, they also brought high slippage problems. Especially for trading pair assets with a small reserve pool, large transactions cannot be supported, otherwise higher prices will be paid.

Inefficient capital: 

Since AMM distributes funds evenly over the entire price range (0, +∞), only funds allocated near the market price can be effectively used, and a large part of the funds are only available when the pricing curve begins to change exponentially. As a result, AMM needs a lot of liquidity to match the slippage in traditional order book transactions.

However, uniswap’s V3 has greatly improved capital efficiency by reforming the market-making mechanism on the original basis. And judging from the latest news, uniswap will also improve the efficiency of large transactions by splitting large orders. Can look forward to~

Representative product and its economic system design

At present, there are many DEX products that apply the AMM mechanism on the market, and their trading volume occupies the majority of the Defi market. Here, we will select several representative products in the market for analysis. It mainly includes the pricing model, economic system, and the advantages and characteristics of these products (what are they focusing on)

According to CoinMarketcap’s current DEX trading volume, the top ten are:

AMM automatic market maker science

1.Uniswap (V3)

Uniswap has occupied the leading position of DEX trading since its launch. It is also his appearance that introduced AMM into the defi world. In the process, this project has undergone many updates. Uniswap basically represents the standard of the AMM DEX project, and most of the other projects are Modifications and improvements based on Uniswap. Uniswap itself is also constantly undergoing version iteration. V3 has just been launched not long ago, and the latest version will be used for research here.

Pricing model

Constant product (x * y = k)

Economic system

UNI is the native token of the Uniswap protocol, which gives the holder the right to govern. This means that UNI holders can vote on changes to the agreement. The total initial minting of this token is 1 billion, of which 60% will be shared by existing Uniswap community members, and the remaining 40% will be distributed to team members, investors and advisors within four years.

At the same time, part of the UNI can be obtained by liquidity mining, and these tokens will be issued to suppliers who are liquid capital pools to incentivize them to provide liquidity.

characteristic

The biggest improvement of Uniswap V3 is actually to improve capital efficiency through a centralized liquidity mechanism

Concentrated liquidity

In Uniswap’s liquidity pool, the price curve corresponding to the liquidity provided by the liquidity provider (LP) actually ranges from 0 to infinity. All these funds are stored in it, and one of the assets in the pool should be 5x-s, 10x-s or 100x-s.

If this happens, these idle assets will ensure that the corresponding part of the price curve remains liquid. This means that only a small part of the liquidity in the pool of funds is concentrated in the price range where most transactions are made.

Nowadays, liquidity providers can set their own price ranges for the pool of funds injected into liquidity. Therefore, liquidity will be more concentrated in the price range corresponding to most trading activities. Greatly improved capital efficiency

The principle of Uniswp V3 to achieve liquidity aggregation is also very simple: mainly on the basis of the V2 version, two parameters have been added,

(x+m)*(y+n)= k

m=  L/√(p_b )

n= L √(p_a )

L^2=k

In Uniswap V3, x and y are actual reserve assets, (x+m) and (y+n) are virtual assets, which are equivalent to x^’ in the V2 version (x^’*y^’=k) And y^’. For example, in the V2 version, the numbers of x^’ and y^’ are respectively 300 and 600. In the V3 version, if m is 100 and n is 200, then x and y only need 200 and 400 respectively. From the above, we can find that under the premise of ensuring that the model’s liquidity is consistent with the V2 version, the V3 version reduces the actual quantity requirements of x and y assets, thereby improving capital efficiency.

AMM automatic market maker science

2.PancakeSwap

Pancakeswap runs on BSC, which can be regarded as the DEX version of binance, which is not much different from Uniswap in terms of core.

Similar to other AMM exchanges, Pancake transaction fee is 0.2%, of which 0.17% is used as a liquidity mining reward, and 0.03% is used as system revenue. Pancakeswap is like a decentralized version of Binance, in addition to transaction business, there are many other subsidiary functions. The combination of these functions makes Pancakeswap no longer a pure DEX, but a comprehensive DeFi service platform.

3.MDEX

Similar to Pancake, MDEX is backed by HECO and also has a high transaction volume. MDEX’s transaction fee is 0.3%. What is more special is that MDEX supports transaction mining, users can obtain MDX tokens through transactions

4.Sushiswap

Sushiswap is Uniswap’s fork. There is no difference from the DEX itself. The difference lies in the operation and governance strategy outside the DEX. Uniswap focuses on the improvement of swap itself and its liquidity mechanism, while Sushi is more inclined to expand other functions and businesses that help increase its liquidity.

5.Curve(V2)

As we mentioned before, Curve uses a hybrid CFMM mechanism to create a curve that has a constant and non-slip point stable characteristic within its core range, and it also guarantees flow at both ends of the curve. The existence of sex, such a mechanism is that it can provide extremely low slippage for stablecoin transactions on DEX while ensuring liquidity.

V2 curve

At the same time, in the latest V2 version, the project has made improvements to the curve:

AMM automatic market maker science

The core part of this latest mathematical model is that it creates a new shape of curve. Intuitively from the above figure, the two dashed lines are constant product curves, the blue line is the famous Curve V1 stable currency exchange curve, and the yellow curve constructed by Curve V2 has two basic characteristics-

1. Between the constant product curve and the Curve V1 curve;

2. Its curve tail features have obvious constant product curve fitting.

So what problems can it solve:

a. Inherit the advantages of Curve V1 in the area near the “equilibrium point” of ultra-low slippage and concentrated liquidity;

b. By fitting between the constant product curve and the Curve V1 curve, and fitting to the constant product curve in the middle and tail region of the curve, the advantage of the constant product curve in responding quickly to changes in fluidity is obtained, avoiding the exhaustion of the liquidity of the pool, and flexibly responding quickly. Market changes.

In addition to this there is a very important innovation:

The internal oracle repegging mechanism.

This mechanism is very beneficial for implementing better centralized liquidity and mitigating impermanent losses.

Simply put, this mechanism allows the originally fixed Curve V1 curve to continuously change its equilibrium point along with the large deviation of the exchange rate on the market, so that it will always have the maximum liquidity near the current exchange rate, fight arbitrageurs in time, and reduce impermanent losses.

It can be seen that Curve uses a very complex mathematical model to create a curve that can dynamically balance between a constant product curve and a constant sum curve, so that stablecoin transactions on Curve can have both curves, low slippage and high liquidity. Characteristics.

At the same time, the new introduction mechanism solves the problems of impermanence loss and capital efficiency to a certain extent. The mathematical ability of the team is their core competitiveness.

Curve’s incentive mechanism

In addition to the low slippage and low impermanent loss we mentioned above due to Curve’s unique curve design, Curve was founded with low transaction fees as a selling point, but this resulted in a corresponding decrease in LP’s revenue. This Curve has a liquidity incentive mechanism different from most DEX.

AMM is one of the transaction models driven by liquidity. Although it is not the original blockchain ecology, it has developed and grown in the blockchain ecology. Investigating the reasons, we believe that there are the following points:

1. Concise pricing and market-making models lower the threshold for liquidity convergence

2. Uniswap and other products have no censorship, unlimited and highly productized currency listing mechanisms that promote their barbaric growth

3. The concise UI and product logic lower the threshold for users to use

4. The spirit of open source promotes the evolution of combined innovation

5. The liquidity mining mechanism promotes the demand for AMM

The composability of DeFi gives AMM a new meaning, that is, “infrastructure”. In the overall ecology of DeFI Lego, AMM and products such as lending, insurance, and synthetic assets play the role of infrastructure. There are many types of products. The combination also inspired more innovation. While innovation is also facing the pressure of financial risks and compliance risks, especially the recent event that Uniswap’s front-end delisting of stock certificates has also caused many practitioners to worry about supervision. Fortunately, this concern is more aimed at the project side. The nature of the DeFi ecosystem is not affected, and the future is still promising.

 

Posted by:CoinYuppie,Reprinted with attribution to:https://coinyuppie.com/amm-automatic-market-maker-science/
Coinyuppie is an open information publishing platform, all information provided is not related to the views and positions of coinyuppie, and does not constitute any investment and financial advice. Users are expected to carefully screen and prevent risks.

Leave a Reply