Mami Protocol

Abstract

Mami Protocol is an open-source protocol designed to enable efficient and secure liquidity for NFT trading pairs. It allows users to create ERC20 and ERC721 trading pairs, and to earn liquidity tokens by staking ERC20 and ERC721. Users can also increase or destroy the liquidity of trading pairs, and can swap ERC721 and ERC20 tokens, but a fee will be charged.

Unlike other liquidity protocols, users need to purchase ERC20 and ERC721 tokens separately on the blockchain and track their balances, Mami Protocol solves this problem by using smart contracts, allowing users to trade ERC20 and ERC721 tokens on a single blockchain .

This design has the following advantages:

  1. Reduce user difficulty. Users only need to make transactions on the blockchain, buying individually.

  2. Improve transaction efficiency. Transactions are faster because they do not need to operate across platforms.

  3. Improved security. The use of smart contracts to implement transactions can effectively prevent third-party manipulation of transactions.

MAMM algorithm

The MAMM algorithm is an algorithm that supports the coexistence of two different types of tokens, ERC20 and ERC721, in the same blockchain network. It solves the compatibility problem between different types of tokens by maintaining a fixed ratio between the number of ERC20 tokens and the number of ERC721 tokens.

The core theory of the MAMM algorithm is that when a user enters the number of ERC20 tokens, the number of ERC721 tokens will change according to a certain ratio, so as to keep the ratio between the number of ERC20 tokens and the number of ERC721 tokens unchanged. Specifically, if the number of ERC20 tokens is erc20Amount, and the number of ERC721 tokens is erc721Amount.

This is the core algorithm structure:

Performance in add liquidity

When adding liquidity, erc20Amount and erc721Amount will be deposited. If there is no trading pair at this time, a trading pair will be created. Increasing liquidity will increase the k value

Curve performance:

Liquidity expression:

Therefore it is deduced:

Performance in remove liquidity

When you remove liquidity, it will reduce the k value

Liquidity expression:

Therefore it is deduced:

When you remove liquidity, erc721Amount and erc20Amount will also be corrected. If the remainder 1e18 of erc721Amount obtained after removing liquidity is not 0, it will also correct erc721Amount, but removing liquidity will reduce the k value , so when the erc721Amount is corrected, the erc20Amount will also be corrected.

E.g:

You own 10 liquidity tokens of a trading pair, and the trading pair has 10*1e18 erc721Amount and 10*1e18 erc20Amount , when you remove 6.5 liquidity tokens, you will get 6*1e18 erc721 and 6*1e18 erc20Amount+0.5*1e18 the corresponding erc20Amount value calculated according to the k value

Algorithm expression:

K(after remove liquidity):

Factorization:

Substitute K (after remove liquidity):

Substitute erc721Amount(down revision):

Factorization:

This is the curve for the number of tokens received by removing liquidity:

Performance in swap

When the user enters the number of ERC20 tokens, the MAMM algorithm will calculate the change in the number of ERC721 tokens according to the following formula:

By factoring it can be obtained:

The formula indicates that when the number of ERC721 tokens changes, the number of ERC20 tokens will also change according to a certain ratio, so as to keep the ratio of the number of ERC20 tokens to the number of ERC721 tokens unchanged. In addition, the MAMM algorithm also stipulates that the input or output of the number of ERC721 tokens must meet a certain format. Specifically, if the number of ERC721 tokens entered by the user is erc721Amount, the value needs to be divided by 1e18, and then multiplied by 1e18 to get the final amount of ERC721 tokens.

The corrected value will be brought back into k=erc20Amount*erc721Amount to keep the k value unchanged, and calculate the value of another token

E.g :

If change erc721Amount:

Actually the value of erc721Amount will be:

However, the k value of the curve will be slightly larger, because there will be 0.3%*erc20Amount remaining in the agreement as a handling fee

Fee expression:

K actual expression:

After factorization:

After conversion, here is the curve comparing the K value of reserved and non-reserved fees:

How to create ERC20 and ERC721 trading pairs

Mami Protocol allows users to create ERC20 and ERC721 trading pairs. First, users need to provide the contract addresses of ERC20 and ERC721, as well as the amounts they are willing to stake. Then, the protocol will generate the corresponding liquidity tokens according to the staked amounts and send them to the user.

The specific process is as follows:

  1. The user provides the contract addresses of ERC20 and ERC721, as well as the amounts they are willing to stake.

  2. The protocol verifies the contract addresses of ERC20 and ERC721, and calculates the corresponding liquidity token amounts.

  3. The user confirms the submitted information and signs the transaction to confirm.

  4. The protocol calls the contracts of ERC20 and ERC721, transferring the staked amounts to the protocol's smart contract.

  5. The protocol generates the corresponding liquidity tokens and sends them to the user.

How to increase or destroy liquidity

Mami Protocol allows users to increase or destroy liquidity of trading pairs. The process of increasing liquidity is similar to creating trading pairs, and users only need to stake ERC20 and ERC721 again, and the protocol will generate liquidity tokens again.

The process of destroying liquidity is also simple, and users only need to provide the number of liquidity tokens they want to destroy, and the protocol will unlock ERC20 and ERC721 in proportion according to the number of tokens destroyed by the user and send them to the user.

The specific process is as follows:

  1. The user provides the number of liquidity tokens they want to destroy.

  2. The protocol calculates the corresponding unlocking amount and displays it to the user.

  3. The user confirms the submitted information and signs the transaction to confirm.

  4. The protocol calls the contracts of ERC20 and ERC721, unlocks the destroyed liquidity tokens in proportion as ERC20 and ERC721, and sends them to the user.

How to implement the swap of ERC721 and ERC20

Mami Protocol allows users to implement the swap of ERC721 and ERC20, so that users can obtain ERC20 tokens by exchanging ERC721 tokens, or obtain ERC721 tokens by exchanging ERC20 tokens.

The specific process is as follows:

  1. The user provides the number of ERC721 or ERC20 tokens they want to swap.

  2. The protocol calculates the corresponding exchange amount and displays it to the user.

  3. The user confirms the submitted information and signs the transaction to confirm.

  4. The protocol calls the contracts of ERC20 and ERC721, implements the token swap, and sends the swapped tokens to the user.

The fee charged by the protocol

Mami Protocol charges a fee of 0.3%, and this part of the fee will be deposited into the liquidity pool. The fee will not affect the user's transaction, and the user can view the fee calculation formula through the transaction signature confirmation.

For example, if the user obtains ERC20 tokens by exchanging ERC721 tokens, and the number of ERC20 tokens exchanged is 100, then the fee is 100 * 0.003 = 0.3. The user will receive 99.7 ERC20 tokens, and the remaining 0.3 ERC20 tokens will be deposited into the liquidity pool.

Users can also view the balance of the liquidity pool at any time and can obtain tokens from the liquidity pool by staking ERC20 and ERC721 to the protocol.

About security

Mami Protocol uses smart contracts to implement transactions, and all transactions require the user's signature to confirm. This design can effectively prevent third-party manipulation of transactions and ensure the security of transactions.

The protocol also conducts regular audits to ensure the security of the smart contracts. Users can also view the source code of the protocol to understand the working principle and security measures of the protocol.

Conclusion

Mami Protocol is an open-source protocol designed to enable efficient and secure liquidity for NFT trading pairs. It allows users to create ERC20 and ERC721 trading pairs, and to earn liquidity tokens by staking ERC20 and ERC721. Users can also increase or destroy the liquidity of trading pairs, and can swap ERC721 and ERC20 tokens, but a fee will be charged. The protocol uses smart contracts to implement transactions and all transactions require user signatures to confirm, ensuring the security of transactions. Regular audits are also conducted to ensure the security of the smart contracts.

Last updated