We all know how Automated Market Makers (AMMs) like those on Uniswap v2 work. Let’s have a look at how DEXnow.io combines AMM and traditional Order Books.Imagine a trading pool for the SOL/USDC pair with 10000 SOL and 200000 USDC. The current price is calculated as follows:
Now, let's say you want to buy 100 SOL. The amount of USDC, denoted as S, that you'd need to pay with can be found using the equation:
Solve it, and you get:
This tells us that the cost per SOL would be 2020.20202, and the new market price becomes:
How does this play out on DEXnow.io?
Assume we're working with the same initial pool – 10000 SOL and 200000 USDC – and the following Order Book:
Ask:
Price | Amount |
20.20 | 1 |
20.05 | 10 |
Bid:
Price | Amount |
19.95 | 1 |
19.90 | 20 |
19.85 | 1 |
You decide to place a Limit Order for 100 SOL at 20.14. Without an AMM, you'd buy 10 SOL at 20.05, and the remaining 90 SOL would be placed in the Order Book at 20.14.
However, if an AMM is in play, you'd first try to execute trades through the AMM up to the first sell quote, which is 20.05.
Let K be the product of the SOL and USDC amounts in the pool.
In this case, the SOL amount you'd trade up to a price of 20.05 would be:
And the USDC you'd spend would be:
So, you're left with 87.5233887 SOL and have already spent 249.843946 USDC. Since the remaining order size exceeds 10, you can hit an ask at 20.05 from the Order Book.
Summary:
· Bought SOL: 12.4766113 + 10 = 22.4766113
· Spent USDC: 249.843946 + 10 * 20.05 = 450.343946
You can then trade against the AMM up to your limit price of 20.14. The SOL you'd trade up to this price would be:
And the USDC you'd spend would be:
Finally:
· From 20.00 to 20.05 via AMM: received 12.4766113 SOL, spent 249.843946 USDC
· Accepted order at 20.05: received 10 SOL, spent 200.5 USDC
· From 20.05 to 20.14 via AMM: received 22.34070405 SOL, spent 448.9353158 USDC
Overall:
· Bought — 44.81731535 SOL
· Spent — 899.2792618 USDC
· Average purchase price — 20.06544245
· Remaining order — 55.18268465 SOL
Final Order Book:
Ask:
Price | Amount |
20.20 | 1 |
Bid:
Price | Amount |
20.14 | 55.18268465 |
19.95 | 1 |
19.90 | 20 |
19.85 | 1 |
SOL left in pool — 9965.182685
USDC left in pool — 200698.7793
TL;DR
The blend of AMM and traditional Order Book on DEXnow.io offers the best of both worlds. This hybrid approach makes trading more flexible and efficient.
Comments