We know that since we are swapping in an amount, the next reserve of that asset is just the previous reserve plus the amount in __with fees__
29
Expression 30: "w" Subscript, 2 , Baseline equals "x" Subscript, 1 , Baseline plus "a" Subscript, 1 , Baseline times left parenthesis, 1 minus "f" , right parenthesisw2=x1+a1·1−f
equals=
0.4 0 8 3 8 7 5 3 8 7 2 60.408387538726
30
Use the x2 risky reserve to calculate the next stable reserve, y2. This uses the `getStableGivenRisky` function.
31
Expression 32: "y" Subscript, 2 , Baseline equals "K" times normal distribution left parenthesis, 0 , 1 , right parenthesis .cdf left parenthesis, normaldist left parenthesis, 0 , 1 , right parenthesis .inversecdf left parenthesis, 1 minus "w" Subscript, 2 , Baseline , right parenthesis minus "v" times StartRoot, "t" , EndRoot , right parenthesisy2=K·normaldist0,1.cdfnormaldist0,1.inversecdf1−w2−v·t
equals=
2.2 1 1 5 2 9 4 0 3 6 72.21152940367
32
Calculate the amountOut, o1, of stable tokens, by finding the difference between next stable and previous stable
Expression 40: "m" Subscript, 2 , Baseline equals normal distribution left parenthesis, 0 , 1 , right parenthesis .pdf left parenthesis, normaldist left parenthesis, 0 , 1 , right parenthesis .inversecdf left parenthesis, 1 minus "x" Subscript, 2 , Baseline , right parenthesis , right parenthesis to the negative 1st powerm2=normaldist0,1.pdfnormaldist0,1.inversecdf1−x2−1
equals=
2.5 7 4 5 9 0 1 6 9 62.5745901696
40
Marginal price after swap risky in: left parenthesis, 0 , "m" Subscript, 2 , Baseline , right parenthesis0,m2
Label:
equals=
left parenthesis, 0 , 2.5 7 4 5 9 0 1 7 , right parenthesis0,2.57459017
41
Since we swapped the risky asset in, which is selling it, the marginal price should decrease between points, which does happen here.
42
Next, lets do a stable swap in: riskyForStable = false, a2 = 1
43
Expression 44: "a" Subscript, 2 , Baseline equals 1a2=1
00
1010
44
Calculate the next stable reserves, since we know how much stable is being swapped in, include fees in
45
Expression 46: "w" Subscript, 3 , Baseline equals "y" Subscript, 2 , Baseline plus "a" Subscript, 2 , Baseline times left parenthesis, 1 minus "f" , right parenthesisw3=y2+a2·1−f
equals=
3.2 1 0 0 2 9 4 0 3 6 73.21002940367
46
Calculate the next risky reserves using the stable reserves, using the function `getRiskyGivenStable`
47
Expression 48: "x" Subscript, 3 , Baseline equals 1 minus normal distribution left parenthesis, 0 , 1 , right parenthesis .cdf left parenthesis, normaldist left parenthesis, 0 , 1 , right parenthesis .inversecdf left parenthesis, StartFraction, "w" Subscript, 3 , Baseline Over "K" , EndFraction , right parenthesis plus "v" times StartRoot, "t" , EndRoot , right parenthesisx3=1−normaldist0,1.cdfnormaldist0,1.inversecdfw3K+v·t
equals=
0.2 9 6 2 8 8 9 9 8 3 3 30.296288998333
48
The next stable reserve will not include the fee amount
49
Expression 50: "y" Subscript, 3 , Baseline equals "y" Subscript, 2 , Baseline plus "a" Subscript, 2 , Baseliney3=y2+a2
equals=
3.2 1 1 5 2 9 4 0 3 6 73.21152940367
50
Plot the reserves after the stable swap in
51
Swap 1 stable in: left parenthesis, "x" Subscript, 3 , Baseline , "y" Subscript, 3 , Baseline , right parenthesisx3,y3
Label:
equals=
left parenthesis, 0.2 9 6 2 8 9 , 3.2 1 1 5 2 9 4 , right parenthesis0.296289,3.2115294
52
Plot the marginal price after the swap stable in
53
Expression 54: "m" Subscript, 3 , Baseline equals normal distribution left parenthesis, 0 , 1 , right parenthesis .pdf left parenthesis, normaldist left parenthesis, 0 , 1 , right parenthesis .inversecdf left parenthesis, 1 minus "x" Subscript, 3 , Baseline , right parenthesis , right parenthesis to the negative 1st powerm3=normaldist0,1.pdfnormaldist0,1.inversecdf1−x3−1
equals=
2.8 9 2 4 5 7 9 3 7 1 92.89245793719
54
Marginal price after swap stable in: left parenthesis, 0 , "m" Subscript, 3 , Baseline , right parenthesis0,m3
Label:
equals=
left parenthesis, 0 , 2.8 9 2 4 5 7 9 4 , right parenthesis0,2.89245794