Normal Swap
SP1 - Buy XT with Underlying
Buy λy XT with σu UT
Step1 - Mint FT and XT by UT
According to Eq.C-2, mint σx FT and σy XT by σu (input amount) UT
where
σx=εσu (Eq.S-1) σy=σu (Eq.S-2) Step2 - Sell FT to XT
According to Eq.C-5,
xˆori⋅yˆori=(xˆori+σx)⋅(yˆori−δy) derive
δy=yˆori−xˆori+σxxˆori⋅yˆori (Eq.S-3) Step3 - Output Total XT
λy (total ouput XT)=σy+δy=σu+(yˆori−xˆori+εσuxˆori⋅yˆori) (Eq.S-4) Step4 - Update Pool State
Update new APR ( r ) according to Eq.D-5
rnew=θRˆy,newRˆx,new+ε−1 SP2 - Buy FT with Underlying
Buy λx FT with σu UT
Step1 - Mint FT and XT by UT
According to Eq.C-2, mint σx FT and σy XT by σu (input amount) UT
where
σx=εσu (Eq.S-5) σy=σu (Eq.S-6) Step2 - Sell XT to FT
According to Eq.C-5,
xˆori⋅yˆori=(xˆori−δx)⋅(yˆori+σy) derive
δx=xˆori−yˆori+σyxˆori⋅yˆori (Eq.S-7) Step3 - Output Total FT
λx (total ouput FT)=σx+δx=εσu+(xˆori−yˆori+δuxˆori⋅yˆori) (Eq.S-8) Step4 - Update Pool State
Update new APR ( r ) according to Eq.D-5
rnew=θRˆy,newRˆx,new+ε−1 SP3 - Sell XT for Underlying
To sell σy XT for λu UT, we need to swap some XT to FT first and combine the remaining XT and purchased FT into UT.
Step1 - Sell
δy XT for
δx FT
According to Eq.C-5,
xˆori⋅yˆori=(xˆori−δx)⋅(yˆori+δy) (eq.1) Step2 - Combine
δx FT and
(σy−δy) XT into
λu UT
According to Eq.C-2,
δx=ε(σy−δy) (eq.2) Step3 - Calculate output
λu UT
According to eq.1 and eq.2 with elimination by substitution,
ϵδy2+(xˆori+εyˆori−εσy)⋅δy−εσyyˆori=0 derive
δy=2a−b+b2−4ac (Eq.S-9) δy=2a−b−b2−4ac is invalid, since yˆnew should be greater than 0 δx=ε(σy−δy) (Eq.S-10) λu=σy−δy (Eq.S-11) where
⎩⎨⎧a=εb=xˆori+ε(yˆori−σy) (Eq.S-12)c=−εσyyˆori Step4 - Update Pool State
Update new APR ( r ) according to Eq.D-5
rnew=θRˆy,newRˆx,new+ε−1 SP4 - Sell FT for Underlying
To sell σx FT for λu UT, we need to swap some FT to XT first and combine the remaining FT and purchased XT into UT.
Step1 - Sell
δx FT for
δy XT
According to Eq.5,
xˆori⋅yˆori=(xˆori+δx)⋅(yˆori−δy) (eq.1) Step2 - Combine (σx−δx) FT and δy XT into λu UT
According to Eq.2,
σx−δx=εδy (eq.2) Step3 - Calculate output
λu UT
According to eq.1 and eq.2 with elimination by substitution,
ϵδy2−(xˆori+σx+εyˆori)⋅δy+σxyˆori=0 derive
δy=2a−b−b2−4ac (Eq.S-13) δy=2a−b+b2−4ac (invalid, since ynew′ should be greater than 0) δx=σx−εδy (Eq.S-14) λu=δy (Eq.S-15) where
⎩⎨⎧a=εb=−(xˆori+σx+εyˆori) (Eq.S-16)c=σxyˆori Step4 - Update Pool State
Update new APR ( r ) according to Eq.D-5
rnew=θRˆy,newRˆx,new+ε−1 Negative Swap
We define Negative Swap operations for applying the same rules of our AMM while withdrawing liquidity and charging tx fees.
SP5 - Buy Negative XT with Negative Underlying
Buy −λy XT with −σu UT
Step1 - Mint FT and XT by UT
According to Eq.C-2, mint −σx FT and −σy XT by −σu (input amount) UT
where
σx=εσu (Eq.S-17) σy=σu (Eq.S-18) Step2 - Sell FT to XT
According to Eq.C-5,
xˆori⋅yˆori=(xˆori+(−σx))⋅(yˆori−(−δy))=(xˆori−σx)⋅(yˆori+δy) derive
δy=xˆori−σxxˆori⋅yˆori−yˆori (Eq.S-19) Step3 - Output Total XT
−λy (total ouput XT)=−σy−δy=−σu−(xˆori−εσuxˆori⋅yˆori−yˆori) (Eq.S-20) Step4 - Update Pool State
Update new APR ( r ) according to Eq.D-5
rnew=θRˆy,newRˆx,new+ε−1 SP6 - Buy Negative FT with Negative Underlying
Buy −λx FT with −σu UT
Step1 - Mint FT and XT by UT
According to Eq.C-2, mint −σx FT and −σy XT by −σu (input amount) UT
where
σx=εσu (Eq.S-21) σy=σu (Eq.S-22) Step2 - Sell XT to FT
According to Eq.C-5,
xˆori⋅yˆori=(xˆori−(−δx))⋅(yˆori+(−σy))=(xˆori+δx)⋅(yˆori−σy) derive
δx=yˆori−σyxˆori⋅yˆori−xˆori (Eq.S-23) Step3 - Output Total XT
−λx (total ouput XT)=−σx−δx=−εσu−(yˆori−σyxˆori⋅yˆori−xˆori) (Eq.S-24) Step4 - Update Pool State
Update new APR ( r ) according to Eq.D-5
rnew=θRˆy,newRˆx,new+ε−1 SP7 - Sell Negative XT for Negative Underlying
To sell −σy XT for −λu UT, we need to swap some XT to FT first and combine the remaining XT and purchased FT into UT.
Step1 - Sell
−δy XT for
−δx FT
According to Eq.C-5,
xˆori⋅yˆori=(xˆori−(−δx))⋅(yˆori+(−δy))=(xˆori+δx)⋅(yˆori−δy) (eq.1) Step2 - Combine
−δx FT and
(−σy−(−δy))=(−σy+δy) XT into
−λu UT
According to Eq.C-2,
−δx=ε(−σy+δy) (eq.2) Step3 - Calculate output
−λu UT
According to eq.1 and eq.2 with elimination by substitution,
ϵδy2−(xˆori+εyˆori+εσy)⋅δy+εσyyˆori=0 derive
δy=2a−b−b2−4ac (Eq.S-25) δy=2a−b+b2−4ac is invalid, since yˆnew should be greater than 0 δx=yˆori−δyxˆori⋅yˆori−xˆori (Eq.S-26) −λu=−σy+δy (Eq.S-27) where
⎩⎨⎧a=εb=−(xˆori+ε(yˆori+σy)) (Eq.S-28)c=εσyyˆori Step4 - Update Pool State
Update new APR ( r ) according to Eq.D-5
rnew=θRˆy,newRˆx,new+ε−1 SP8 - Sell Negative FT for Negative Underlying
To sell −σx FT for −λu UT, we need to swap some FT to XT first and combine the remaining FT and purchased XT into UT.
Step1 - Sell
−δx FT for
−δy XT
According to Eq.5,
xˆori⋅yˆori=(xˆori+(−δx))⋅(yˆori−(−δy))=(xˆori−δx)⋅(yˆori+δy) (eq.1) Step2 - Combine
(−σx−(−δx))=(−σx+δx) FT and
−δy XT into
−λu UT
According to Eq.2,
−σx+δx=−εδy (eq.2) Step3 - Calculate output
−λu UT
According to eq.1 and eq.2 with elimination by substitution,
ϵδy2+(xˆori−σx+εyˆori)⋅δy−σxyˆori=0 derive
δy=2a−b+b2−4ac (Eq.S-29) δy=2a−b−b2−4ac (invalid, since yˆnew should be greater than 0) δx=xˆori−yˆori+δyxˆori⋅yˆori (Eq.S-30) −λu=−δy (Eq.S-31) where
⎩⎨⎧a=εb=xˆori−σx+εyˆori (Eq.S-32)c=−σxyˆori Step4 - Update Pool State
Update new APR ( r ) according to Eq.D-5
rnew=θRˆy,newRˆx,new+ε−1