Solving Constant Product for price

The constant product is used in decentralized finance. It is used to calculate how much someone gets for currency $Y$ when giving funds of currency $X$. $X$ and $Y$ indicate the size of funds in the corresponding currencies, $z$ stands for the amount of funds of currency $X$ given into the pool, $a$ stands for the amount of funds received in currency $Y$. $p$ is the price paid for the transaction.

$k = X * Y$
$a = Y - k / (X + z)$
$p = z / a$

Now my question is: How much does someone have to give to exactly receive $p$?

Example:
$X = 100, Y_1 = 50, Y_2 = 50, z = 10$
$k = 100 *(50+50)$
$a = (50+50) - 10000 / (100+10) = 9.09...$
$p = 9.09... / 10 = 1.09...$

  • Mathe Mathe
    0

    When you say, "How much does someone have to give?" you mean "z", right?

Answer

Answers can be viewed only if
  1. The questioner was satisfied and accepted the answer, or
  2. The answer was disputed, but the judge evaluated it as 100% correct.
View the answer
Mathe Mathe
3.2K
The answer is accepted.
Join Matchmaticians Affiliate Marketing Program to earn up to 50% commission on every question your affiliated users ask or answer.