# Ramble On-Chain Pricing Mechanism and ERC7527

## Overview

On-chain asset pricing is a fascinating task, commonly implemented using function-based quotations. Specifically, there are three main categories:

1. Various **Automated Market Maker (AMM)** curves are utilized for token swaps, with the constant product formula x \* y = k gaining the most consensus, which is employed by Uniswap.&#x20;
2. **Bonding Curve** mechanism that directly quote based on factors like supply, with recent examples including FriendTech and pump.fun.
3. **Auction-based** mechanism, where on-chain auctions often use Dutch auctions to enhance efficiency. English auctions are less common, and blind auctions based on sealed bids are also rare due to technical challenges. Notable examples include [GDA](https://www.paradigm.xyz/2022/04/gda) and [VRGDA](https://www.paradigm.xyz/2022/08/vrgda) referring to Paradigm's work , as well as the Dutch auction mechanism within UniswapX.

Each of these function-based pricing mechanism has certain advantages and drawbacks. This article will first introduce these widely used on-chain asset pricing mechanisms, then it will present a new generation of on-chain asset pricing mechanisms based on **ERC7527** and **continuous quotations** based on functions.

## AMM Curves

Currently, the most widely used pricing mechanism in pure on-chain pricing is Automated Market Maker(AMM) pricing. The AMM  pricing mechanism that gaining the the most consensus is the $$x * y = k$$ constant product pricing curve, which was first introduced by Uniswap.

In this formula:&#x20;

* $$x$$ refers to the balance of asset x in the pool,
* $$y$$ represents the balance of asset y in the pool
* $$k$$ is a constant

The corresponding code is as follows:

```
uint balance0Adjusted = balance0.mul(1000).sub(amount0In.mul(3));
uint balance1Adjusted = balance1.mul(1000).sub(amount1In.mul(3));
require(balance0Adjusted.mul(balance1Adjusted) >= uint(_reserve0).mul(_reserve1).mul(1000**2), 'UniswapV2: K');
```

The code above includes four key variables, which are explained as follows:

* `balance0Adjusted`: The amount of asset x in the pool after the user sends asset x to the pool, minus a 0.3% fee charged on the sent amount of asset x.
* `balance1Adjusted`: The amount of asset y in the pool after the user sends asset y to the pool, minus a 0.3% fee charged on the sent amount of asset y.
* `_reserve0`: The reserve of asset x within the pool.
* `_reserve1`: The reserve of asset y within the pool.

Let's explain the code in an example. Suppose the pool currently holds reserves of 20000 DAI and 10 WETH, and we want to swap 1 WETH for 1500 DAI. The calculation process is as follows:

```
_reserve0 = 20000 DAI
_reserve1 = 10 WETH
k = 20000 * 10 = 200000
```

The above represents the reserves before swapping 1 WETH for 1500 DAI. Now, let's proceed with the following swap:

```
balance0 = 20000 - 1500 = 18500
balance1 = 10 + 1 = 11

amount0In = 0
amount1In = 1

balance0Adjusted = 18500
balance1Adjusted = 11 - (1 * 0.003) = 10.997

newK = balance0Adjusted * balance1Adjusted = 203444.5
```

At this point, the condition where `newK` is greater than `k` holds, so the swap can proceed. Certainly, many users might feel they haven't encountered this type of swap, as they are usually given a direct quote on the Uniswap front-end showing the maximum amount of DAI that 1 WETH can be swapped for. This is calculated based on the newK = k condition and the reserves in the pool. If a user wants to swap x units of one asset for y units of another, the formula to calculate the maximum amount that can be swapped is derived as follows:

$$
(x + dx)(y - dy) = xy \\
y - dy = \frac{xy}{x + dx}\\
dy = y - \frac{xy}{x + dx}
$$

Here, $$𝑑𝑥$$ represents the amount of assets provided by the user, and $$𝑑𝑦$$ represents the amount of asset y received in exchange for asset x. $$𝑥$$ and $$𝑦$$ are the reserves in the pool at the time of the swap. The following diagram illustrates a token swap based on the $$𝑥⋅𝑦=𝑘$$ formula:

<figure><img src="https://388396105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F08YvsFJc2cbFLRwby1Re%2Fuploads%2FkJbjElCFSsaUpFSPZaIq%2Fimage.png?alt=media&#x26;token=4b23b684-70dd-4c1d-b05c-3c07f093d153" alt=""><figcaption><p>Token swap priced with the constant product formula 𝑥⋅𝑦=𝑘 </p></figcaption></figure>

For the AMM curve pricing solution, the **advantages** include:

* As the most widely used token swap solution, the AMM curve has the strongest consensus.
* For ERC20 exchanges, the AMM curve solution is currently the best solution.

However, the AMM curve also has significant **drawbacks**, with the largest one being related to liquidity providers (LP). For LPs of the AMM curve, they face the following issues:

*   **Source of Liquidity Providers**&#x20;

    For newly issued tokens, the token issuer must provide <mark style="color:red;">initial liquidity</mark> to ensure users can make exchanges. Ensuring the source of subsequent liquidity is challenging, and third-party liquidity providers or even token issuers might withdraw LPs, leading to a <mark style="color:red;">rapid loss of liquidity</mark> in the AMM pool.
*   **Management of Liquidity**

    As research into AMM curves deepens, several factors that may lead to LP losses have been identified, such as the infamous <mark style="color:red;">Impermanent Loss</mark>. This makes LP management a complex task.
*   **Malicious MEV Attacks**

    For Ethereum, <mark style="color:red;">Miner Extractable Value(MEV)</mark> for AMM curves is extremely developed, and most MEV operations result in losses for various participants. The most malicious MEV attack on AMM curves is the <mark style="color:red;">sandwich attack</mark>. Any transaction without slippage settings is vulnerable to sandwich attacks, resulting in significant asset losses for users.

In practice, the biggest problem with using AMM curves for asset pricing is still the provision of initial liquidity. For early project teams, issuing assets requires a substantial amount of assets for initial liquidity provision. For Meme coin project teams, it is challenging to have sufficient liquidity outside of FOMO (Fear of Missing Out) periods.

Additionally, another characteristic of AMM curves is that they can only price ERC20 assets. Using AMM curves to price NFTs and other assets requires special solutions. These AMM curve pricing solutions for NFTs essentially use the concept of NFT fragmentation. For example, ERC404 assets make it difficult to truly consider these AMM curve-priced NFTs as real NFTs.

## Bonding Curve

The Bonding Curve is widely discussed earlier in the cryptocurrency space. Its full name is Token Bonding Curve, and it generally includes the following parameters:

* **Supply Token:** The underlying token of the Bonding Curve pool. Generally, users are allowed to use the supply token to purchase issued tokens from the pool. In some cases, it can work in reverse, allowing users to sell issued tokens back to the pool in exchange for the supply token. The supply token is typically a fungible token.
* **Issued Token:** The other type of token that users can purchase by using the supply token, calculated according to the curve. The issued token might be a fungible token but can also be a non-fungible token, though cases involving non-fungible tokens are less common.
* **Curve:** This determines the price. Some applications use a single curve to set both the buy and sell prices, while others use more complex mechanisms where the buy and sell prices follow different curves. The spread between these prices effectively acts as a transaction tax.

In the Bonding Curve field, the most crucial element is the curve itself, as it determines the prices at which users buy and sell. The simplest form of a curve is as follows:

$$
y=mx^n
$$

The following graph demonstrates an example of $$𝑦=\frac{1}{400}x^2$$

<figure><img src="https://388396105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F08YvsFJc2cbFLRwby1Re%2Fuploads%2FQgJ1XDlGwH2JodoyXqMl%2Fimage.png?alt=media&#x26;token=1cd480c1-4ac8-4cf6-918e-adc5adece3be" alt=""><figcaption><p>Bonding Curve Pricing</p></figcaption></figure>

When a user decides to enter the market, and if the user needs to purchase $$k$$ units of issued tokens, we will use the integral under the curve to calculate the number of supply tokens required by the user. We will use some methods to simplify the integral calculation. This process involves a series of mathematical derivations. If interested, please read the "**Computing Buy and Sell Prices**" section in the article [_Bonding Curves In Depth: Intuition & Parametrization_](https://medium.com/relevant-community/bonding-curves-in-depth-intuition-parametrization-d3905a681e0a).

The diagram below shows some common curves used for Bonding Curves. &#x20;

* The top left is the Sigmoid curve, with the function expression  $$y = \frac{1}{1 + e^{-x}}$$.
* The top right is the power function curve, with the function expression   $$y =m \cdot x^n$$.&#x20;
* The bottom left is a special function curve, with the mathematical expression  $$y = m(1+25\%)^{\log_2 x} + b$$ . Its economic meaning is that when the token supply doubles, the token price increases by 25%. If interested, you can learn more from the article [On Single Bonding Curves for Continuous Token Models](https://medium.com/thoughtchains/on-single-bonding-curves-for-continuous-token-models-a167f5ffef89).&#x20;
* The bottom right is the constant function.

<figure><img src="https://388396105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F08YvsFJc2cbFLRwby1Re%2Fuploads%2FBR9d8Vh27LVxZcmOl6e2%2Fimage.png?alt=media&#x26;token=aa37e192-79d7-451f-8f1b-d10712bab2c6" alt=""><figcaption><p>Common Bonding Curves</p></figcaption></figure>

These curves can be categorized into sublinear, linear, and superlinear.

Compared to AMM curve pricing mechanism, the biggest advantage of the Bonding Curve is that it does not rely on initial liquidity. The token issuer does not need to prepare a large amount of liquidity but can directly issue tokens, relying on user-injected liquidity to maintain the price. This is extremely beneficial for so-called Curation Markets. Curation Markets were one of the early discussion topics on Ethereum, aimed at allowing groups to coordinate more effectively and profit from the value they co-create toward common goals. The simplest case is currently pump.fun. Curators issue MEME tokens, and other participants buy the issued Meme tokens according to the Bonding Curve. Friend tech is also an example of a Curation Market.

For more detailed information, please refer to the article [Introducing Curation Markets: Trade Popularity of Memes & Information (with code)!](https://medium.com/@simondlr/introducing-curation-markets-trade-popularity-of-memes-information-with-code-70bf6fed9881) . Note that this article is written as early as 2017.

For Bonding Curves, the largest problem is that tokens are unable to operate for long periods due to overly mechanical rules. For applications like FriendTech, using curves can cause some issues, such as, since it is transparent that early participants can have significant gains later on, many bots participates early and then exits later, causing asset losses for mid-term participants. For pump.fun, this problem also exists, but pump.fun creatively uses the Bonding Curve only as an early LP fundraising tool, switching to the AMM model for trading later. This approach reduces the impact of mechanical curves to some extent.

## Auction

Auctions are also a common pricing mechanism suitable for any asset. Due to technical issues, we generally do not conduct sealed auctions on-chain. Typically, we use the following two auction schemes:

1. **Dutch Auction:** This is the most commonly used auction approach on blockchain. The asset is auctioned starting from a pre-set highest price, and the price gradually decreases over time until a deal is made.
2. **English Auction:** During a fixed period, the price of the asset is gradually increased, and the highest price at the end of the auction wins.

Since auctions can provide a relatively fair pricing for any asset, there are currently many specialized ecosystems within Ethereum using auctions. A common form of non-continuous English auction is often used within flashbots, mainly for Maximal Extractable Value(MEV) bots competing for transaction positions.

<figure><img src="https://388396105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F08YvsFJc2cbFLRwby1Re%2Fuploads%2F06U54RdNzwFkmPYto8Yq%2Fimage.png?alt=media&#x26;token=17f4ced4-5da3-4aa8-a633-a79875c96924" alt=""><figcaption><p>An Example of an English Auction from payload.de</p></figcaption></figure>

The above diagram shows the auction of different builders competing for block MEV opportunities. Readers can view the real-time MEV auction status for any block on payload.de, from which the above diagram is taken. This auction uses an English auction system, where different participants gradually bid higher prices to obtain MEV opportunities. For Ethereum, the existence of FlashBot prevents MEV bots from initiating gas wars, reducing Ethereum's gas fees. For block proposers, it allows them to further capture MEV revenue from the blocks, making it more profitable. Due to efficiency issues, English auctions are rarely used for actual Ethereum asset issuance. Some _Intent_ systems use English auctions to maximize the benefit for the _Intent_ initiator. For example, CowSwap uses English auctions during token swaps. If the _Intent_ initiator offers 100 tokens A in exchange for at least 80 tokens B, other participants can bid more than 80 tokens B. The highest bidder can obtain 100 tokens A and give the _Intent_ initiator the bid amount of tokens B.

Dutch auctions are another commonly used auction method, with Gradual Dutch Auctions (GDA) being used for actual asset issuance. First, we introduce non-continuous Dutch auctions, which are generally less used for asset issuance but sometimes used for asset swaps. UniswapX allows users to submit Dutch orders. If a user wants to exchange 100 tokens A for 50-80 tokens B, they can submit a Dutch order to UniswapX, which includes 100 tokens A, and the number of tokens B required decreases over time from 80. If the current decrease reaches 75 tokens B, and a user (referred to as a filler in UniswapX) accepts this order, they need to pay 75 tokens B to obtain 100 tokens A.

For actual asset issuance scenarios, we typically use [Gradual Dutch Auctions (GDA)](https://www.paradigm.xyz/2022/04/gda) and [Variable Rate Gradual Dutch Auctions (VRGDA)](https://www.paradigm.xyz/2022/08/vrgda) introduced by Paradigm. GDA can be used for both fungible and non-fungible token issuance, characterized by completing all token issuance with a single launch without needing the issuer to manually start each token auction. The principle is to initiate auctions for all issued tokens at different starting prices upon issuance. For more details, refer to the article [In-Depth Exploration of GDA and VRGDA](https://blog.wssh.trade/posts/gda-with-vrgda/).&#x20;

Compared to GDA, VRGDA incorporates a time factor, allowing the token issuer to set a token release curve. If the token issuance exceeds the expected release curve, VRGDA will increase the price to curb demand; conversely, it will lower the price to increase demand.

Both GDA and VRGDA, primarily used for asset issuance, have a significant issue. During auctions, users tend to wait for lower prices as time progresses. When all users choose to wait, the asset price continuously declines. In fact, GDA and VRGDA can be seen as variants of the Bonding Curve mechanism, which does not solve the problem of Bonding Curves while losing the secondary market functionality.

Moreover, GDA and VRGDA only solve primary market issues without addressing secondary market problems. After the auction ends, the token issuer can choose to place the auctioned assets into an AMM market. However, more likely, the issuer may conduct a soft rug, ceasing to promote the project. For auction participants, the acquired assets lack liquidity, and the asset pricing is relatively unrealistic.

## ERC7527

ERC7527 is an asset issuance mechanism highly suitable for pricing, addressing many of the drawbacks of the Bonding Curve mechanism while ensuring asset liquidity. The specific operational process of ERC7527 is as follows:&#x20;

<figure><img src="https://388396105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F08YvsFJc2cbFLRwby1Re%2Fuploads%2FWnzuXlK8tZ7xaoLMCtps%2Fimage.png?alt=media&#x26;token=6dc380e3-ffae-4b8b-8fce-068516fe32d3" alt=""><figcaption><p>ERC7527 Operation</p></figcaption></figure>

The ERC7527 system consists of the following three parts:

1. **Agency** is a pool for reserving assets. The pool continually provides buy(wrap) and sell(unwrap) quotes based on its internal functions. When a user accepts a buy(wrap) quote, they can deposit the pre-specified asset into the Agency. At this point, the Agency will call the `mint` function of the App to mint an NFT for the user, an operation we refer to as "wrap." When a user accepts the Agency's sell quote, the Agency will send the asset to the user and call the `burn` function of the App to destroy the NFT, an operation we refer to as "unwrap."
2. **App** is an asset type that inherits from NFTs. Due to the guarantees provided by the Agency, this kind of asset can always maintain its liquidity.
3. **Factory** facilitates the deployment of Agency and App. Users can deploy Agency and App by inputting a few parameters.

Here lies the core issue: **how does the Agency provide wrap and unwrap quotes?** The simplest solution is to use a mechanism similar to Bonding Curve within the Agency, directly calculating quotes based on the total supply of NFTs. However, this solution does not solve the problems inherent in Bonding Curves. Here, we employ more interesting functions aimed at incorporating user wrap actions into the final quote results. The specific functions used for quoting depend on the following parameters:

* &#x20;$$Δ_m$$: The time difference between the current and previous transaction.
* &#x20;$$p_{n-1}$$: The price of the last transaction.
* &#x20;$$p_n$$: The price of the current transaction.

Based on the above parameters, we can derive the following pricing function:

$$
p_n =  \begin{cases}  \frac{2}{1 + e^{\lambda_{\text{up}} \Delta_m}} \cdot p_{n-1} + c & \Delta_m \leq \Delta_{\text{target}} \\ p_{\text{max}} e^{-\lambda_{\text{down}} \Delta_m} & \Delta_m > \Delta_{\text{target}} \end{cases}
$$

This function includes several constants:

* $$c$$ is a constant that intend to bridge the gap between the transaction price and the next quoted price.
* $$λ_{up}$$determines the price increase speed, this value must be greater than 0, and the larger the absolute value, the faster the increase.
* $$λ_{down}$$determines the price decrease speed, this value must be greater than 0, and the larger the absolute value, the faster the decrease.
* $$p_{max}$$ refers to the value of $$p_{n}$$under the condition when $$Δ_m = Δ_{target}$$. This value represents the maximum value within this interval.
* $$Δ_{target}$$: Determines the longest time interval for the rising phase, which, together with $$λ_{up}$$ and $$p_{max}$$, determines the final rise amplitude.

Note that  $$p_{n}$$ should always be greater than or equal to $$p_{n-1}$$, meaning that the current transaction price cannot be lower than the last transaction price.

The following diagram illustrates the quoted prices of the Agency within a specific interval. The quoted prices provided in the diagram are relative values, with the vertical axis representing $$\frac{P_n}{P_{n-1}}$$ and horizontal axis representing time blocks.&#x20;

<figure><img src="https://388396105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F08YvsFJc2cbFLRwby1Re%2Fuploads%2FqNVXhP5eRL7xJwWiY7Th%2Fimage.png?alt=media&#x26;token=e8686b2e-1d5b-44e9-817f-92804b15402d" alt=""><figcaption><p>Relative Wrap Price Quotes within an Interval</p></figcaption></figure>

We have already introduced how ERC7527 quote a wrap, but how to quote an unwrap? The unwrap quote is actually the last transaction price. In the smart contract, it maintains a price stack, and each time a transaction is completed, the transaction price is appended to the stack.&#x20;

When a user unwraps, the last appended price in the stack is popped as the unwrap price. In terms of price discovery, there is a certain symmetry between the wrap and unwrap behaviors.

<figure><img src="https://388396105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F08YvsFJc2cbFLRwby1Re%2Fuploads%2Fef8H4t8sdiE4WCN59THT%2Fimage.png?alt=media&#x26;token=49e178eb-caa0-42d9-89ce-14d56b52da08" alt=""><figcaption><p>Stack Mechanism for Unwrap</p></figcaption></figure>

After introducing the Agency’s quoting mechanism, the security risk caused by  the over-transparency of Bonding Curves can be avoided. All price determinations are led by users' wrap and unwrap behaviors, fostering a more dynamic price discovery system. Users are now more focused on game strategies, both in collaboration with and against other players, rather than solely on quoting functions like Bonding Curves.&#x20;

For example, users will not simply choose to wait, as transactions may occur during the price increase phase. Ultimately, dynamic competition will lead to more complex scenarios than those with the Bonding Curve. The following chart shows the transaction prices of App NFTs under random simulation:

<figure><img src="https://388396105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F08YvsFJc2cbFLRwby1Re%2Fuploads%2FYiOScl5jZcr87HDU8jMg%2Fimage.png?alt=media&#x26;token=e79d24c0-7e68-4ca9-8aa5-f3dc00f678d3" alt=""><figcaption><p>Price Dynamics with Wraps and Unwraps</p></figcaption></figure>

Compared to the Bonding Curve, we can see the above pricing process as a combination of the Bonding Curve and the auction mechanism. The game theory in the auction process compensates for the over-transparency of the Bonding Curve. On the other hand, it retains other advantages of the Bonding Curve. After users obtain App NFTs through wrapping, the concept or entity represented by the Agency is closely related to users' economic interests. Driven by the economic interests, users may contribute to the concept or entity corresponding to the Agency. The Total Value Locked(TVL) of the Agency reflects the corresponding value. For instance, users can choose to issue Meme NFTs through the Agency. If users recognize this Meme, they will wrap with, let's say, ETH and actively encourage other users to participate. They share the same monetary interest with the spread of the Meme. The TVL of the Agency thus reflects the market value of the current Meme.

Compared to the auction mechanism, another major advantage of the ERC7527 scheme is that assets have full liquidity. Users can choose to trade directly in the secondary market. If the liquidity in the secondary market is insufficient, users can choose to destroy the NFT through the Agency’s unwrapping mechanism to obtain the underlying assets. Moreover, the assets within the Agency cannot be extracted by the token issuer, which to some extent avoids Rug Pull behavior by the token issuer.

Compared to the AMM mechanism, ERC7527 also maintains token liquidity. However, unlike AMMs, the liquidity of ERC7527 is self-provided. The funds injected by the wrap behavior of users make the market for the entire Agency. This self-provided liquidity avoids many issues associated with external liquidity providers, such as the token issuer not needing to provide initial liquidity, but simply waiting for users to participate in wrapping. Additionally, participants do not need to engage in complex LP management. Since the price is determined by the above price discovery mechanism, in most cases, liquidity providers are not affected by MEV attacks.

## Summary

This article introduces several commonly used on-chain pricing models:&#x20;

1. **AMM Curve**: Currently the most widely accepted on-chain pricing paradigm. However, it only provides pricing for ERC20 tokens and has several issues in liquidity provision, such as the difficulty of sourcing initial liquidity, potential losses for liquidity providers, and MEV issues.
2. **Bonding Curve**: An early and widely discussed pricing paradigm that can theoretically price any asset and does not have liquidity provision issues. However, its game theory relies solely on transparent mathematical functions, which cannot operate for long periods and often lead to failure in the later stages.
3. **Auction**: A common pricing solution. However, neither English nor Dutch auctions can solve liquidity problems in the later stages. Tokens issued through auctions often see all auction proceeds withdrawn in one go.

Compared to the above solutions, **ERC7527** combines the advantages of different schemes. Firstly, it introduces an auction mechanism within the original Bonding Curve, making the game more dynamic and avoiding problems caused by overly transparent mechanisms. Secondly, ERC7527 uses all assets injected by users for market-making of the issued assets, avoiding the liquidity problems of the issued assets and circumventing a series of issues in liquidity provision seen with AMM curves, especially the problem of initial liquidity. Lastly, ERC7527 retains the so-called curation market capabilities, where users involved in wrapping are essentially a community of interests, actively promoting the development of relevant Agencies driven by economic interests.



May 2024 | Written by: [@randomzly](https://x.com/randomzly), [ @wong\_ssh](https://x.com/wong_ssh)
