29
30
Since the ratio of assets available is still greater than the ratio that can be deposited, that means we need to trade to the next tick, let the liquidity change, and then repeat the first step. We do that over and over again until we find that d_ratioavailabletodeposit at the next tick is less than d_ratiovaliddeposit for it, which will mean that the target price is within the current tick.
31
Once we've reached the right tick, we then want to find the exact right p_target where trading to p_target will allow us to deposit all of our tokens into our desired range.
32
We have a formula below that computes the right value for p_target, but we can peek at the answer here (and its square root):
33
34
35
We can use the same formulas to compute the ratio for valid deposits and the ratio available to deposit for p_target:
36
37
38
To find the right value of p_target, we find the price where these curves meet—where the ratio of assets that the user has available to deposit to be equal to the ratio of assets that the user CAN deposit. (The "+0" is so Desmos doesn't treat this as a definition.)
39
40
Combining all of the above formulas gives us this equation:
41
42
Let's replace sqrt(p_target) with x (so note that we are solving now for the square root of price rather than price), and expand:
43
44
45
46
47
Then rearrange to make it a quadratic equation, and use the quadratic formula to solve for x.
48
49
50
51
52
53
54
Therefore, in order to compute the target price, first compute a, b, and c as per the formulas above, plug it into the quadratic formula, and then square it.
55
56
57
58
59
powered by
powered by
New Blank Graph
Examples