5
votes

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?

1

1 Answers

2
votes

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.