mimo protocol
中文
中文
  • 欢迎来到mimo!
  • 公式
  • 跨链交易
  • 分析
  • 常见问题
  • mimo V2
    • mimo V2
    • 使用说明
    • 智能合约
    • SDK
    • 常见问题 (V2)
  • mimo V1
    • Smart Contract
    • Automator
    • API
Powered by GitBook
On this page
  • 自动做市
  • 公式
  • 基于输入值的定价
  • 价格影响因素
  • 交叉交易价格影响因素

Was this helpful?

公式

This page shows the formulas used in mimo protocol.

Previous欢迎来到mimo!Next跨链交易

Last updated 3 years ago

Was this helpful?

自动做市

在每笔交易中,用户可以用一定数量的特定代币对一定数量的另一种代币进行交易兑换,价格由公式进行定义。MIMO没有使用传统的交易委托账本和待执行机制。

mimo 使用的公式是基于自动做市(AMM)的 DEX 广泛采用的著名公式x∗y=kx * y = kx∗y=k,例如 uniswap。

公式 x∗y=kx * y = kx∗y=k

假设XXX这是源代币, YYY是目标代币。在 mimo 中,XXX, YYY可以是 IOTX 或任何 XRC20 令牌。 设xxx,yyy分别为当前流动性池中的 X-token、Y-token。

基于著名的 AMM 方程

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

公式中的kkk 是一个常数。

xxx和 yyy的乘积在交易前后保持不变。详情请参考。

基于输入值的定价

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​,

让我们进一步定义 dxd_xdx​ , dyd_ydy​,分别是您想要支付的X-token的数量,以及您将获得的Y-token的数量。

我们需要知道,价格是基于dxd_xdx​或dyd_ydy​的。如果用getInputPrice表示通过出售给定的dxd_xdx​可以购买的Y-token的数量(即dyd_ydy​ ),则:

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​

在代码中表示为:

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

如果getOutputPrice 表示购买dyd_ydy​ Y-tokens需要的X-token的数量 ,则:

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

在代码中表示为:

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.

上方等式中的 / 表示 divToInteger,意为除以四舍五入到结果。

价格影响因素

在AMM中,兑换汇率会在每次交易后发生变化,也会在 dxd_xdx​ , dyd_ydy​ 和 x,yx, yx,y池中的流动性发生变化后变化。因此,价格影响因素是交易者们在交易前希望知道的。

有两种支持计算价格影响的方法。它可以基于 x,y,dxx, y, d_xx,y,dx​或x,y,dyx, y ,d_yx,y,dy​。一种是基于输入值,一种是基于输出值。

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

或

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

在代码中表示为:

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

请注意,价格影响始终介于 -1 和 0 之间。

交叉交易价格影响因素

如果两个代币之间没有直接交易对,比如在 V1 中我们只支持 IOTX/XRC20交易对,交易者需要使用一个代币,例如 IOTX,作为两个代币之间交易的桥梁。

在这种情况下,价格影响公式将是

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

在代码中表示为:

price impact = PI1 * PI2 + PI1 + PI2

当中,

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的帖子