WhitePaper(EN)
MiaoO by ht.mdis.finance
Abstract
This paper, presents Mooniswap – an AMM1 that uses the constant- product invariant, with the extension of virtual balances. Unlike other AMM designs, MiaoO virtual balances allows to blunt the price impact of the short-term trading volume slippage. This allows profits that would otherwise be captured by arbitrageurs to instead be captured by liquidity providers. This makes MiaoO significantly more profitable for liquidity providers than most other AMM designs.
MiaoO translation fee = basis DEX fex + 0.1%
Introduction
This document will first describe the current state of AMMs on the market today. It will then provide a detailed description of MiaoO and highlight its key differences from other AMMs.
Prior Work
The constant-product invariant x · y = const and its generalized version xω1 · 1
xω2 · . . . · xωn = const were initially proposed by Alan Lu from Gnosis[1] to 2n
create AMMs on Ethereum. Vitalik Buterin also called on[2] developers to run on-chain DEXes2 using the same formula. Several products were launched using this fundamental design, some with the proposed formulas, others with own custom formulas.
MDEX Protocol
MDEX’s AMM was launched in November 2020. MDEX allowed the creation of pools consisting of HT and any HECO-compatible token using the constant- product invariant:
x · y = const where x − balance of HT
y − balance HECO token By using a simple constant-product invariant and using HT as the central
asset, MDEX was able to create lightweight and gas-efficient contracts.
Depth Protocol
Depth Protocol was launched in January 2021. Depth found its initial success as an AMM for mean-reverting assets (such as stable tokens) by introducing its 2 own formula suitable for mean-reverting assets. depth combines the constant- sum invariant x + y = const with the constant-product invariant x · y = const, based on the pool imbalance ratio χ:
n χDn−1 bi +
Dn bi = χDn + n
i=0 where bi − balance of i-th asset
D − sum of all asset balances before the swap χ − imbalance coefficient
How it Works
All existing AMMs use swap fees to earn profits for their liquidity providers. (The swap fees are configurable in MDEX for each pool, whereas MDEX charges 0.3% and Depth currently charges 0.04% per swap.) Liquidity providers are ultimately compensated via these fees. But if the pricing function signifi- cantly misprices the assets in the pool, as might happen after a sudden exoge- nous price crash, liquidity providers lose potential profit to arbitrageurs who purchase the mispriced assets.
An AMM can thus maximize its profit in one of two ways: maximizing trading fees, or minimizing arbitrageur profits. MiaoO seeks specifically to pursue the latter strategy: by introducing virtual balances, arbitrageurs are less able to profit on temporarily mispriced pools, leaving more profit for liquidity providers.
All AMMs with constant product pricing functions offer worse slippage as the trade size increases. Other AMMs instantly provide an arbitrage opportunity in the opposite direction after a sufficiently large swap (specifically, if the slippage was larger than the protocol trading fee). Arbitrageurs then compete for these arbitrage opportunities by participating in priority gas auctions[3], paying a significant portion of potential arbitrageur profits to miners. In this model, liquidity providers are not able to capture any of the subsequent profits—aside from the trading fee, all of the revenue from a temporary mispricing is captured by miners and arbitrageurs.
MiaoO fixes this issue by creating an asymmetry between the two trad- ing directions. Rather than moving both the buy-sell prices simultaneously and offering an immediate arbitrage opportunity, MiaoO gradually increases the price of the opposite trade. Consequently, the size of the arbitrage opportunity in the opposite direction also increases gradually. This allows the pool to capture some portion of the slippage via further organic trading, rather than giving it all away to the fastest arbitrageur. To achieve that behavior, we have introduced virtual balances that emulate different prices for different swap directions. With virtual balances, purchase of asset A leads the curves for purchasing asset A and asset B to temporarily diverge. The Depth eventually converge again over some predetermined time decay. The idea of using virtual balances in AMMs was initially proposed[4] by Vitalik Buterin, to mitigate front-running issues.
Mathematical Model
In Miao, when a swap takes place, the pool does not immediately offer a profitable trade in the opposite direction. Instead, it slowly improves the price over some period of time. The following chart shows how several trades would significantly increase the constant-product invariant from point X to point Q.
where A − Initial balances,
X − Balances after a swap with significant slippage,
B − Virtual balances for the opposite swap after some period of time, −→ −→
0A, 0Q − Line representing the true exogenous price, −→ −→ −→
BC, DE, ZQ − Arbitrage trades based on virtual balances, −→ −→ −→
XY , Y Z, ZQ − Parallel translation of arbitrage trades to real balances,
Chart 1. Swap with a huge slippage and 3 subsequent arbitrage trades (source)
After the above swap takes place, the virtual balance for the opposite swap will linearly move from point A to point X. At some point before this full transition takes place, arbitrageurs will attempt to exploit the smaller temporary arbitrage opportunities along the way. For example, when the virtual balance reaches point B, an arbitrageur may choose to arbitrage the price back to the true price at point C. Note that points A and C (and the origin) are located
on the same line, which means they have the same price. The chart depicts
three sequential arbitrage trades (BC, DE, ZQ) until the real balance reaches an equilibrium price at point Q.
Deposits and withdrawals scale virtual balances in the same proportion as real balances do. The effect of a +100% deposit is shown in the following chart.

where A − Initial real balances, B − Real balances after deposit,
X, M − Initial virtual balances, Y, N − Virtual balances after deposit.
Note that the following equality describes the proportionality between real and virtual balances immediately after deposit or withdrawal:
−→ −→ −→
0A = 0X = 0M −→ −→ −→
0B 0Y 0N
Fees
MiaoO initially utilizes 0.3% swap fee which can be lowered all the way down to 0% in the future as a way to provide more competitive prices to the market.
MiaoO introduces referral fee to incentivize integrations with wallets, dapps and other services that increase trading volume and provide additional income for liquidity providers. Referral fee does not introduce additional pres- sure on the exchange rate and rewards external actors who contribute to the protocol by providing external trading volume. Referral fee is only charged when referral wallet is specified in transaction arguments.
Referral fee is fixed and is equal to 5% of income earned by liquidity providers on the trade. So initial 0.3% swap fee will be split into 0.015% going to referral and 0.285% going to liquidity providers. Additional profits acquired due to using virtual balances are also split in the same ratio with 5% going to referral.
Apart from swap fee and referral fee, MiaoO does not charge any other protocol fees.
References
[1] Building a decentralized exchange in Ethereum, March 2017. https://blog.gnosis.pm/ building-a-decentralized-exchange-in-ethereum-eea4e7452d6e.
[2] Let’s run on-chain decentralized exchanges the way we run prediction markets, October 2016. https://www.reddit.com/r/ethereum/comments/ 55m04x/lets_run_onchain_decentralized_exchanges_the_way/.
[3] Flash boys 2.0: Frontrunning, transaction reordering, and consensus insta- bility in decentralized exchanges, April 2019. https://arxiv.org/abs/ 1904.05234.
[4] Improving front running resistance of x*y=k mar-
ket makers, October 2016. https://ethresear.ch/t/ improving-front-running-resistance-of-x-y-k-market-makers/ 1281.
Last updated
Was this helpful?