Deep exploration of the inheritance and innovation of the AMM model design in NFT transactions
Original author: @Joseph Xu
Editor: @Heiyu Xiaodou, BuilderDAO
In the past year or two, there have been few updates and iterations on the AMM model algorithms that have been proven effective in the market. The core issue of AMM has gradually shifted from designing an efficient and reasonable algorithm to the essence of the financial market - liquidity. Today, NFT as an asset class also faces the same challenges of liquidity scarcity and other issues. However, there has been no effective DEX in the NFT market that can truly solve the problems of transaction matching and price discovery from the perspective of liquidity aggregation. Today, our topic starts with AMM DEX. We will share with you how we found inspiration and insights from existing AMM solutions in the process of designing the Midaswap Protocol, and how we improved and innovated in these existing solutions to solve the unique pain points and needs in the NFT market.
- Joseph
This article is compiled from an internal sharing by Joseph, an engineer at Midaswap's economic model team.
Since Q3, the NFT market has experienced severe fluctuations, with blue-chip NFTs plunging. Ignoring the impact of various operations by project parties and issuers, liquidity remains the most important issue in the NFT market. Currently, on the EVM chain alone, we can roughly classify NFTs as derivatives of ETH.

In addition, whether you have participated in NFT transactions or not, you should have already paid attention to the rapid success of blur.io. In terms of liquidity solutions, Blur seems to have handed in a high-scoring answer from centralized exchanges/aggregators. It now occupies the largest share of buy-side liquidity in this market, and as a latecomer, especially in the case of Opensea having dominated for so many years, it has risen so rapidly. In fact, we can say that Blur has done a good job in centralized liquidity solutions. However, whether it is for our dApp developers or for the ecosystems on various public chains, we have always believed that centralization may only be part of this trading market, and what we hope to seek is how we can build our own NFT exchange or NFT DEX on the chain. So today, we hope to discuss the following questions in the upcoming discussion:
What kind of liquidity solution should be adopted to build a decentralized NFT exchange?
When thinking and designing a decentralized NFT AMM, what are the aspects that existing DEX AMM solutions can draw inspiration from?
What are the differences in AMM model design between ERC 721 and ERC 20, which represent completely different asset targets?
Today, we will discuss and learn together with these questions, while also attempting to share the thought process our product Midaswap has gone through in its model design.
How to Design a DEX from Scratch
Let's start with a more abstract question: what thoughts and choices do we need to go through when designing a DEX?

First, it is well known that choosing an AMM curve is a direction that all AMM designers need to establish from the beginning. Indeed, x+y=k or x·y=k, or the more customized multi-coin pool model of Balancer, which can all be called CFMM, a constant function market maker. Here, x and y, including b in the balancer formula, actually represent the corresponding market or the asset balances or supply involved in this liquidity pool. Based on the proportional relationship between supplies or various created quantity relationships, they re-match and price within this market. Therefore, the choice of what kind of curve to select is often related to the target assets that the liquidity protocol believes it can attract. For stablecoin transactions, such as Curve V2, it will choose a hybrid constant function for the market maker. Near the equilibrium point, its model is closer to a constant sum curve, while at points further away from the equilibrium, it is more similar to the constant product method of Uniswap v3. So, there is no perfect AMM curve, but rather how to find an AMM curve that is suitable for your own market.
Then, in fact, everyone will face a second issue, which is how we want to distribute liquidity. This involves two aspects: whether liquidity needs to be distributed across the entire range, or within a fixed price range, or within a price range provided by LP. This is actually the difference between Uni V2 and Uni V3. Uni V2 has designed a very simple model in which two tokens are distributed across the entire range, strictly following the AMM curve of xy=k. However, Uni V2 also brings another issue, which is a significant decrease in capital utilization efficiency at both ends of the curve. Uni V3 has made innovations in this regard by providing a new feature for LPs, where LPs can provide liquidity within the range they desire, which is defined as the range order feature in Uni V3. Its AMM curve is not a simple xy=k, but the result of multiple overlapping xy=k curves. The distribution of liquidity within this range also raises another question: do you want your liquidity to be positioned horizontally or vertically? There may not be a more intuitive method to explain the difference between these two at the moment, but we will further elaborate on this later.
The third and most important issue is how you incentivize your LPs. LPs are actually the most important participants in DEXes or games. Without LPs, there would be no depth of liquidity, and therefore, no good trading experience. So, all DEXes actually face the question of how to attract LPs. Of course, we know that all DEXes use transaction fee revenue to attract their LPs. Some emerging liquidity protocols create more composability benefits for LPs, such as liquidity staking or various combinations of liquidity tokens. For example, Paraspace enables Uniswap LPs to achieve more leveraged composability through borrowing and lending. All these aspects are aimed at increasing the attractiveness of liquidity pools to LPs. As we just mentioned, LPs are the most crucial factor in making this liquidity protocol game work. If we don't have a good mechanism to attract LPs, then this flywheel cannot operate in a positive manner.
Then we come to the fourth issue: how should you charge your traders? On this point, existing DEXes are quite consistent. The fee charged to traders is almost determined by the creator of the liquidity pool. For example, Uniswap, Joe may have a multi-tier fee structure. It's worth mentioning that in Joe V2, it has a dynamic fee. We also see Uni V4 following suit in this regard, introducing dynamic fees through hooks. Dynamic fee rates represent a more advanced product design because dynamic fees can not only form a negative feedback system to balance the market but also hedge against the LPs' gratuitous losses to some extent. Here we won't delve into this part of the content too much, but this link is definitely something that must be considered as an AMM designer.
Then it's about choosing the token standard for LP. There are many different approaches to this. Uni V2 chose ERC 20, Uni V3 chose ERC 721, and Joe V2 chose ERC 1155. In fact, the LP Token is determined by the combined choices of these four. The distribution method of liquidity and the way liquidity is quantified in the liquidity protocol will ultimately determine the form of the LP Token. Taking the difference between Uni V2 and Uni V3 as an example, Uni V2 distributes liquidity across the entire range. So, at each price point, as long as the proportion of liquidity assets provided by the two LPs to the total assets is the same, we consider these two parts of liquidity to be equivalent. Therefore, LP Tokens in the same liquidity pool of Uniswap v2 are fungible. Because at each price point, we fairly consider them to contribute capital to the market. On the other hand, Uni V3 introduces range orders (limit liquidity), so the validity of liquidity itself has a new definition. Not all liquidity will participate in market trading at all times, only the liquidity within the price range will truly contribute capital to this market. Therefore, it needs to non-fungibly package the positions of each LP by wrapping them with an ERC 721 Token. This may be the best solution currently. Of course, we don't know what Uni V4 will be like next, but I think that if the liquidity solution of Uni V4 does not differ significantly from Uni V3, ERC 721 may still be the best choice for its LP Token.
After going through these 5 important steps of decision-making and struggle, we have established a rough direction for an AMM protocol. So, the process we just went through was actually a brainstorming session to help everyone have a clear understanding. Only when all 5 of these steps are without issues can we truly enter the gateway of AMM model design and start discussing more detailed issues.
The NFT AMM Triangle of Difficulties

The previous discussions were about the design of ERC 20 AMM DEX, including mainstream AMM DEXs like Uni, Curve, Balancer, etc. Today, our topic is NFT AMM. In NFT AMM, one side of the trading pair is an ERC 721 NFT, and the other side is an ERC 20 or a fungible token like ETH. When these two types of assets are placed in an AMM liquidity pool, we encounter some inherent contradictions.
First and foremost, the most important thing in the traditional NFT trading market is that they rely on a bid-ask trading model, more like an order book market. In situations where there is a lack of liquidity on one side of the order book market, the liquidity rate is very poor. Therefore, the NFT market lacks good market-making tools and sufficient buyer liquidity. It has always been criticized that NFT lacks intrinsic value and its buyer liquidity is extremely scarce regardless of which public chain it is on, so the lack of turnover severely depletes liquidity. So we are thinking, if we directly introduce NFT AMM into the existing AMM DEX market without any modifications, it is likely to face serious liquidity shortages on the ETH side or ERC 20 side. This is a problem that everyone needs to face from the beginning.
The second important issue, which is also a practical issue, is that NFTs are traded as whole assets. Because of the non-fungible nature of NFTs, without any other additional design, no NFT holder is willing to sell 10% of an NFT to another person. This is not feasible based on the characteristics of the asset itself. This actually introduces a problem: our original AMM DEX is infinitely divisible within the token's precision range. If some mainstream ERC 20 tokens have 18 decimal places of precision, they can be subdivided within 18 decimal places, which means that the price curve can approach a continuous curve infinitely. On the other hand, NFTs have a discontinuous liquidity, which often means that there is a large liquidity gap. We need to determine what kind of curve can connect points together, and this is also an important issue.
At the same time, from another perspective, because the Token ID itself is traded in integer units, the threshold for NFT transactions has always been relatively high. When retail investors buy ETH, if their USDT is not enough to buy one Ether, they can choose to buy Ether worth 100 USDT. But when an NFT is worth 1 ETH, it is impossible for a user to spend 100 USDT to buy a certain percentage of the NFT. Previously, liquidity protocols in the market have proposed introducing fractionalization design for NFTs. Fractionalization is certainly a simple and direct solution, but it also introduces the third issue of the difficult triangle: do fractionated NFTs still possess the trading attributes of NFTs themselves?
When any NFT collection is issued, it determines the rarity of a certain NFT ID or a group of NFT IDs based on the attributes in the metadata. Different rarities often determine that these NFT holders have different expectations for the prices of their NFTs. And fractionalization means that all NFTs invested in this fractionalized liquidity pool are treated equally, because we cannot distinguish certain fragments in a fragmented liquidity pool that come from NFTs of different rarities.
This is actually the three core pain points that decentralized NFT protocols must face. If there is no compromise among these three issues, NFT AMM designs may encounter significant difficulties.
Existing Solutions for NFT AMM Markets

Let's take a look at the existing mature solutions in the NFT AMM market. For example, NFTX fragmented NFTs uniformly into ERC 20 tokens and built trading pairs through Sushi Swap pools. It straightforwardly avoids the issue of Token Decimal Conflict but ignores the differentiation in judgment on scarcity and price expectations by traders and holders. High scarcity NFTs cannot achieve good value discovery in this AMM model.
Another project, Sudoswap, is the first DEX-like platform for native NFT assets. Why do we say it is "like" an AMM? Because it has some differences in role setting compared to the commonly understood AMM. Let's briefly introduce Sudoswap. It turns each liquidity provider into a counterparty for traders. Liquidity providers design their own liquidity provision schemes based on the bonding curve they set. Each liquidity provider owns a liquidity pool and determines whether it is a bidirectional pool or a unidirectional pool. A bidirectional pool means you can both buy and sell NFTs, and liquidity is available on both sides. Bidirectional means you can swap assets on both sides. It can also provide unidirectional pools. For example, if you only provide ETH, it is like an LP hanging a buy order for an NFT, and traders can sell the NFT into this pure ETH pool. Conversely, you can provide liquidity for pure NFTs, making it more like hanging a sell order for an NFT.
So in this process, the role of LP is diminished, and LP is more like another form of trader, just with some customized trading functions to some extent. However, this brings two problems. The first problem is that if an LP has a liquidity pool, it means that the liquidity between each liquidity pool cannot be aggregated. As we just mentioned, the most important problem in the NFT market is the lack of liquidity for buyers. In such a premise, if all liquidity is still fragmented into individual LP pools, it is actually still isolating liquidity islands to some extent. The inability to aggregate liquidity violates the original intention of AMM: AMM hopes to aggregate liquidity within a market to provide better liquidity depth and then match a price that truly reflects the sentiment of the market. In this regard, it actually cannot be achieved. Each liquidity pool is fragmented and does not affect each other. From another perspective, in a single liquidity pool, the scarcity of NFTs is assumed to be the same. That is to say, an LP provides 3 NFTs in his own liquidity pool, and he will not price these 2 NFTs individually. If an LP has three NFTs of different rarities and different expectations, he may need to create three liquidity pools to meet such requirements.
So these two projects are actually relatively mature projects in the NFT AMM market. These two projects solve part of the three problems we just mentioned, but they may have trade-offs and selectively ignore or compromise some of the problems. So what we are thinking about is whether there is an NFT model that can solve these problems well, or whether we can solve these three problems to a level that everyone can accept through an NFT model.
Bonding Curves
We will now give you a detailed explanation of the Bonding Curve as a prelude to discussing the detailed solution. The Bonding Curve is essentially a series of mathematical functions used to achieve price discovery. It maps the supply of assets to the asset price. From the two curve diagrams above, it is clear that the left one is a linear Bonding Curve, while the right one is an exponential Bonding Curve. In the diagram, the green dot represents the position of ERC 20 in the pool, while the red dot represents ERC 721. Taking the left diagram as an example, how is the liquidity distributed in such a liquidity pool? The lowest price point and the second point after that are occupied by the liquidity of FT, which is ERC 20. The liquidity of ERC 721 is placed on the three points above. When a trader buys an NFT from this liquidity pool, the middle red dot is replaced by a green dot. This means that for every NFT bought in this market, the price will linearly increase by a constant value. And for every NFT sold, the inDEX price provided by the pool will decrease by a constant value. The same applies to the exponential function, but it changes the constant difference to a constant ratio.
Sudoswap's notable feature is that it introduces the Bonding Curve into NFT trading, providing liquidity providers with a great degree of freedom in market-making. However, as mentioned earlier, in its design, the liquidity pools between LPs are fragmented, which means that its Bonding Curve loses the ability to fully describe the market. We cannot see the extent to which the market is trading from a single liquidity pool. The inDEX Price it trades in the market also cannot reflect the characteristics of the entire NFT Collection market, falling into a "incomplete view" dilemma.
Inspiration from existing DEX
Considering the pain points mentioned above and the design of existing mature products, we are thinking about what kind of NFT AMM can solve these problems. First, we will go back to some mainstream ERC 20 DEX in the market to find elements that can inspire or guide us.
First, we conducted a careful study of Uniswap V3, which provided us with good inspiration. Firstly, LPs can provide liquidity within a price range, similar to the LPs in Sudoswap that restrict their liquidity to a specific bonding curve and provide liquidity within that range. So, we had an idea: can LPs freely provide their liquidity in our liquidity pool according to a certain bonding curve? Based on this, we may need to accompany it with a Non Fungible LP Token, which is an ERC 721 LP certificate, in order to determine the position of each LP. In fact, they are non-homogeneous.
Then, we conducted in-depth research on Joe V2's protocol design, which made some upgrades based on Uni V3. Firstly, the Curve of LP can be customized, allowing LPs to choose the sparsity of liquidity and whether liquidity is globally spread within their range order price interval. It can also provide liquidity in a point-like manner. It also utilizes the design of the Liquidity Book, making on-chain transactions achieve a trading mode similar to an Order Book in a micro-dimension. This is a more innovative solution for liquidity distribution.

The most important inspirations we gained from these two ERC 20 DEX are the four points mentioned on the chart. If ERC 20 DEX has provided us with important insights for designing NFT AMM, the most crucial point is that we should not ignore the differences between NFTs' Token IDs and should allow LPs to have different expectations for their liquidity. At the same time, we should not divide LPs' liquidity into individual private liquidity pools, but aggregate their buy-side liquidity. Only aggregated liquidity can provide traders with a better trading experience, lower slippage, and more timely transaction experience. In situations where liquidity is lacking and cannot be aggregated, the experience of traders trying to sell an NFT is poor.
Design Ideas for Midaswap AMM
Speaking of this, we can now discuss how to design our own NFT AMM. Before that, let's first discuss a slightly unrelated issue. If you have read about Uniswap V3, you know that Uniswap V3 has its own system for measuring prices, called Tick. Tick is actually an exponential function with a base of 1.0001. Each time Tick increases, it multiplies the corresponding price by 1.0001. In other words, Tick and price are mapped to each other one-to-one. Why is it designed this way? In fact, all DEXs have their own price scales, which are used to extract the most effective price scale for our AMM from almost infinite prices. The liquidity between these price scales is actually ignored, and we only provide liquidity within these predetermined Ticks.
On the other hand, a more mainstream design is Liquidity Bin. Bin, as the name suggests, is like a box. We can think of the liquidity on each price scale as the height of a box stacking liquidity depth for each LP. To put it simply, as an LP, if I provide liquidity at the ETH equals 1000 USDC position, I provide 1000, then I will stack the liquidity depth for the Bin at the price of 1000 to a height of 1000. If the second person comes and provides 2000, they will raise the liquidity depth to a height of 3000.
Why am I mentioning this? Actually, Tick is relatively more in line with the incentive scheme for liquidity in Uni V3. On the other hand, we believe that Bin, as a vertically stacking liquidity solution, is more suitable for discrete NFT liquidity. We can think of NFT liquidity as a small box that can be stacked on the price of the Bin. Each time an NFT holder or an LP provides NFT liquidity at a certain price, we can understand it as placing a box on that price.
Why do we say that simply learning about a certain ERC 20 DEX cannot solve the three problems mentioned above? First of all, there are differences in rarity between different NFT token IDs, and these differences in expected value are inherent to NFT as an asset class. This is actually quite different from most ERC 20 DEXs. In ERC 20 DEXs, it is impossible for two traders to trade at different prices at a fixed moment. So, if we want to build a comprehensive NFT market, we need to learn both the matching mechanism of centralized exchange order books and the liquidity aggregation method in DEX AMM models.
So here's the design: introducing the concepts of Best Offer and Floor Price, which are unique to the centralized NFT market, into the decentralized market. Best Offer refers to the highest offer for an NFT in the current market, which is the buyer's highest ideal price for the NFT in this Collection. Floor Price, on the other hand, is the lowest asking price for NFT sell orders in the market. With these two prices, a watershed is formed in the liquidity market:

-
Above the Floor Price, we can use a liquidity provision solution called Bonding Curve to provide NFT traders with a trading experience similar to an Order Book. For example, when an LP chooses to provide liquidity for NFTs in the range of 3 ETH to 5 ETH, these NFTs will be scattered at price points within that range according to the LP's designed Bonding Curve. When a trader enters the market to trade at any given time, they can choose the desired NFT. In a sense, the LP has limited the price range for that NFT. With each transaction, the price of the NFT can increase based on the LP's Bonding Curve.
-
The AMM model is applied to Best Offer and prices below Best Offer. In this case, LPs providing liquidity for FTs are more like providing buy-side liquidity in the Blur market and can be considered homogenized. They place their FT liquidity within the desired price range, and the liquidity at the same price point is considered fungible and aggregated. By aggregating this liquidity, both the capital utilization efficiency and transaction efficiency in the market are greatly improved, enhancing the user experience when selling an NFT.
This design of an NFT marketplace can to some extent address the three pain points mentioned earlier. We have chosen a more balanced approach that provides good liquidity depth and lower NFT transaction slippage without neglecting the NFT Token ID. From the perspective of meeting the native trading needs of NFTs, I believe this may be the best solution we can think of at present.
At the same time, it is worth mentioning that Best Offer and Floor Price are two important price indicators in the NFT market. Our trading marketplace can provide an on-chain Oracle, or in other words, we can offer a good price discovery mechanism for a particular NFT market instead of relying on an external NFT marketplace to assist with NFT pricing.
In addition, a pure on-chain NFT marketplace opens up many possibilities for composability in DeFi. For example, our LP tokens can continue to be used for lending and leverage stacking, and our Oracle can assist with on-chain oracle pricing. These are the reasons why we urgently need an efficient NFT AMM that can meet the needs of traders and LP providers.


