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, $a$ stands for the amount of funds of currency $X$ given into the pool, $b$ stands for the amount of funds taken out in currency $Y$. $p$ is the price paid for the transaction.

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

Now my question is: How much does someone have to take out to exactly receive $p$? I.e., for given $X$, $Y$ and $p$, which value for $b$ results in $p$?

  • Kav10 Kav10
    0

    If you solve for b, you will get a nonlinear equation and to solve it you need to use numerical methods. If that's what you are looking for, I can explain it more.

  • Maxbry Maxbry
    0

    I know that's possible to solve for $a$: $a = pY - X$. So I was actually hoping to get a solution for $b$ of similar type.

    • Kav10 Kav10
      0

      b does not simplify into a similar closed-form expression because of this nonlinearity. if p, X, Y, and k are known, b can be solved numerically.

Answer

Answers can only be viewed under the following conditions:
  1. The questioner was satisfied with and accepted the answer, or
  2. The answer was evaluated as being 100% correct by the judge.
View the answer
The answer is accepted.
Join Matchmaticians Affiliate Marketing Program to earn up to a 50% commission on every question that your affiliated users ask or answer.