mimo protocol
English 1.1
English 1.1
  • Welcome to mimo!
  • The Formulas
  • Cross-Chain Trading
  • Analytics
  • Listing Token on Mimo V2
  • FAQ
  • MIMO V3
    • Smart Contracts
    • SDK
  • mimo V2
    • mimo V2
    • Get Started
    • Smart Contracts
    • SDK
    • Swap For IOTX Gas on Mimo
    • FAQ (V2)
  • mimo V1
    • Smart Contract
    • Automator
    • API
Powered by GitBook
On this page
  • Automated Market Making
  • The formula
  • Pricing based on the inputs
  • Price impact
  • Cross-Trading Price Impact

Was this helpful?

The Formulas

This page shows the formulas used in mimo protocol.

PreviousWelcome to mimo!NextCross-Chain Trading

Last updated 4 years ago

Was this helpful?

Automated Market Making

In each trade, traders trade certain amount of a particular token for certain amount of another token with the price defined by a formula. There is no orderbook and waiting for fulfillment.

The formula that mimo uses is the famous x∗y=kx * y = kx∗y=k that has been widely adopted by AMM based DEX, such as uniswap.

The formula x∗y=kx * y = kx∗y=k

Assume thatXXX is the source token, and YYY is the destination token. In mimo, XXX, YYY could be either IOTX or XRC20 tokens. Let xxx, yyy be X-token, Y-token in current liquidity pool, respectively.

Based on the famous AMM equation

x∗y=kx * y = kx∗y=k

where kkk is a constant.

The product of xxx and yyy remains the same before and after trading. For details, please refer to .

Pricing based on the inputs

Let's further define dxd_xdx​ , dyd_ydy​ are how many X-tokens you want to pay, and how many Y-tokens you will get, respectively.

We'd like to know, the price based on dxd_xdx​ ordyd_ydy​. IfgetInputPrice denotes how many Y-Tokens (i.e. dyd_ydy​ ) can be bought by selling a given dxd_xdx​,

getInputPrice(x,y,dx)=y∗997∗dx1000∗x+997∗dxgetInputPrice(x, y, d_x) = \dfrac{y * 997 * dx}{1000 * x + 997 * d_x}getInputPrice(x,y,dx​)=1000∗x+997∗dx​y∗997∗dx​

or in code,

getInputPrice(x, y, dx) = (y * 997 * dx) / (1000 x + 997 dx)

If getOutputPrice denotes how many X-tokens is needed to buy dyd_ydy​ Y-tokens,

getOutputPrice(x,y,dy)=1000∗x∗dy(y−dy)∗997+1getOutputPrice(x, y, d_y) = \dfrac{1000 * x * d_y}{(y-d_y)*997} + 1getOutputPrice(x,y,dy​)=(y−dy​)∗9971000∗x∗dy​​+1

or in code,

getOutputPrice(x, y, dy) = 1000 x * dy / ((y - dy) * 997) + 1

where / in above equations denotes divToInteger, which means divide with rounding to floor of the results.

Price impact

In AMM, the price would change after each trade, dxd_xdx​ , dyd_ydy​ and x,yx, yx,y the liquidity in the pool. The price impact is what traders want to know before the trade.

There are two ways of calculating price impact. It can be based on x,y,dxx, y, d_xx,y,dx​ , or x,y,dyx, y ,d_yx,y,dy​ . One is based on input , one is based on output.

PriceImpact(x,y,dx)=(1000∗x)2(1000∗x+997∗dx)2−1PriceImpact(x, y, d_x) = \frac{ (1000*x)^2} { (1000*x + 997*d_x)^2} -1PriceImpact(x,y,dx​)=(1000∗x+997∗dx​)2(1000∗x)2​−1

or

PriceImpact(x,y,dy)=(y−dy)2y2−1PriceImpact(x, y, d_y) = \dfrac{(y-d_y)^2}{y^2} -1PriceImpact(x,y,dy​)=y2(y−dy​)2​−1

in code,

price impact(x, y, dx) = (1000*x)^2 / (1000*x + 997*dx)^2 - 1
price impact(x, y, dy) = (y - dy)^2 / y^2 - 1

Note that the price impact is always between -1 and 0.

Cross-Trading Price Impact

If there are no direct trading pairs between two tokens, like in V1 where we only support IOTX/token pairs, traders need to use one token, such as IOTX, as a bridge to trade among two tokens.

In this case, the price impact would be

PriceImpactcross=PI1∗PI2+PI1+PI2PriceImpact_{cross} = PI_1 * PI_2 + PI_1 + PI_2PriceImpactcross​=PI1​∗PI2​+PI1​+PI2​

or in code,

price impact = PI1 * PI2 + PI1 + PI2

where

PI1 is the price impact of first trading pair, such as x to IOTX
PI2 is the price impact of second trading pair, such as IOTX to y

vbuterin's post