Exchange Mechanics
The exchange is performed by adding funds to the balance of the incoming currency pool and removing them from the balance of the outgoing currency pool so that after the exchange operation the invariant k does not change.
You can find all the mentionedformulas in this article: Pricing Mathematics.
We will schematically show an example on the BTC - USDt pool. This pool consists of 10 BTC and 190,000 USDt. Therefore 1 BTC costs 19,000 USDT. A trader wants to exchange 300 USDt for BTC:
Let's calculate k at the initial moment of time:
10 × 190000=1900000
Let's calculate according to the formula (6) how much BTC the trader should return from the pool:
BTCgained=10-1900000190000+300=0.01576458
Let's calculate the transaction price for a trader using the formula (5):
Price=3000.01576458=19030 USDt
Let's calculate the new pool balances and calculate k:
USDtpool=190000+300=190300
BTCpool=10-0.01576458=9.98423542
k=190300 × 9.984235423=1900000 , k not changed
Consider how, with this mathematics, the volume of the transaction affects the price of the transaction:
The table clearly shows that the larger the volume of a exchange transaction, the worse the transaction rate. If the volume of an exchange transaction exceeds 2% of the pool’s balance, the rate will be completely unfavorable. However, keep in mind that these additional fees are calculated based on the current size of the pool. In this example, If the pool’s liquidity was 10 times higher (1,900,000 USDt and 100 BTC), then the exchange of 10,000 USDt for BTC would take place at a favorable rate. Consequently, the more liquid the pool, the easier and more profitable larger orders become.