10

I've already spend few hours trying to understand execution price.

I understand the the concept of Mid price as it is the reserve ratio between two pairs.

According to Uniswap sdk documentation, Execution price is the ratio of assets sent/received. I am struggling to understand as how calculation is done. Also it seems that Uniswap swapping of pairs is based on execution price rather than Mid price. Why used Execution price rather than Mid price during trading?

2 Answers2

6

In automated market makers, such as Uniswap, the amount of tokens that you will receive depends on the amount of tokens that you will sent in a non-linear fashion: the more liquidity you remove from the pool, the less tokens you will receive in the final.

If you do not take fees into account, the reserve of pairs X and Y must satisfy the following invariant on each swap:

Xold Yold = Xnew Ynew

Thus, by sending ΔX to the pool, you will receive ΔY according to the formula:

ΔY = (Y ΔX)/(X + ΔX)

The execution price is defined as ΔY/ΔX, that is,

Execution price = Y/(X+ΔX)

Note that the mid-price (defined as Y/X) approximates the execution price as ΔX approximates 0. That is why Uniswap states that the mid-price "represents the price at which you could theoretically trade an infinitesimal amount (ε) of one token for the other". However, in practice, you will pay the execution price since you also pay for removing liquidity from the pool.

shamisen
  • 172
  • 1
  • 4
  • 12
0

Automated Market Makers uses Constant Function Market Makers formula. Based on this formula, multiplication of amounts will always be constant. Let's say initially you had 4000 A and 4000 B tokens. Multiplication of amounts

  // 16.000.000 will always be constant
  4000 X 4000 = 16.000.000

Let's say one user brought 1000 A tokens. Now, the total amount of token A will be 5000. We have to decide how many token B we have to transfer to the user.

The multiplication of tokens has to be 16.000.000 all the time. we had 5000 token A, how many tokens B should remain in the pool

 16.000.000 / 5000 = 3.200

3.200 token B should remain in the pool. so we have to transfer 4000-3200=800 token B to the user.

Yilmaz
  • 35,338
  • 10
  • 157
  • 202