-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add note. solidity103 56. Author: JakeDu
- Loading branch information
Ling ye
authored and
Ling ye
committed
Oct 16, 2024
1 parent
a024eec
commit b8f1c61
Showing
2 changed files
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
### 五十六课 DEX 自动做市商 | ||
> 自动做市商是一种算法,或者说是一种在区块链上运行的智能合约,它允许数字资产之间的去中心化交易。AMM 的引入开创了一种全新的交易方式,无需传统的买家和卖家进行订单匹配,而是通过一种预设的数学公式(比如,常数乘积公式)创建一个流动性池,使得用户可以随时进行交易。 | ||
#### 恒定总和做市商 | ||
特点:k = x + y。其中的常数k,就是我们说的恒定总和。也就是说,在交易前后, k的值不会发生改变。 | ||
eg: 可乐价值1u,然后现在有个池子,我们放进去10u和10瓶可乐,k为20,为了保证恒定总和k不变,如果我们使用2u买了可乐,(10 + 2) + ? = 20。 ? 等于8。且购买后可乐的价格仍然为1u。然后保证了池子的总价值为20u。 | ||
缺点就是流动性很容易耗尽。因为在这个池子中,如果你有10u,就可以获得所有的可乐,然后其他人就没有了,并不会随着购买力的提高而提高价格。 | ||
|
||
#### 恒定乘积做市商 | ||
特点:k = x * y。 其中的常数k,就是我们说的恒定乘积。在交易前后, k的值不会发生改变。 | ||
eg: 可乐价值1u,然后有个池子,我们放进去10u和10瓶可乐,k为100,为了保证k值不变,如果我们使用了10u购买了可乐,(10 + 10 ) * ? = 100。 ?等于5, 10 - 5 = 5, 于是用10u兑换了五瓶可乐。 | ||
会发现我们购买五瓶可乐的平均价格是2u,说明会随着购买力的改变,价格发生改变,不会耗尽流动性。 | ||
比如有人有1000u,那么(10 + 1000) * ? = 100; ? = 1/11。 说明池子里面还剩1/11瓶可乐,永远有人能喝到一点点。且价格越来越贵。 | ||
|
||
#### 去中心化交易所 | ||
在去中心化交易所中,使用的自动做市商的算法是恒定乘积,保证了价格的动态变化。 | ||
k = x * y。 |