# Solving Constant Product for ratio

The constant product is used in decentralized finance. It is used to calculate how much someone gets of currency $Y$ when giving funds of currency $X$ into a trading pool. $X$ and $Y$ indicate the size of funds in the corresponding trading pool, $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$. $R$ represents the ratio of the two currencies, $R = Y/X$, $R'$ represents the ratio of the two currencies after the trade

$k = XY$
$a = Y − k/(X+z)$
$X' = X+z$
$Y' = Y-a$
$R' = Y'/X'$

Now my question is: How to solve for $z$ given the variables $X$, $Y$ and $R'$?

Example:
$X=20, Y=10, R=0, z=1$
$k=20∗10 = 200$
$a=10 − 200/(20+1)=0.47619...$
$X'=X+z=21$
$Y'=Y-a=9.5238...$
$R'=9.5238... / 21 = 0.4535...$

• Erdos
+1

The offered bounty is low.

• I increased the bounty

• Martin
+1

The bounty is too low

• I increased the bounty

## 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
Kav10
1.9K
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.
• answered
• 217 views
• \$20.00