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,
derive
Step3 - Output Total XT
Step4 - Update Pool State
SP2 - Buy FT with Underlying
Step1 - Mint FT and XT by UT
where
Step2 - Sell XT to FT
derive
Step3 - Output Total FT
Step4 - Update Pool State
SP3 - Sell XT for Underlying
derive
where
Step4 - Update Pool State
SP4 - Sell FT for Underlying
derive
where
Step4 - Update Pool State
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
Step1 - Mint FT and XT by UT
where
Step2 - Sell FT to XT
derive
Step3 - Output Total XT
Step4 - Update Pool State
SP6 - Buy Negative FT with Negative Underlying
Step1 - Mint FT and XT by UT
where
Step2 - Sell XT to FT
derive
Step3 - Output Total XT
Step4 - Update Pool State
SP7 - Sell Negative XT for Negative Underlying
derive
where
Step4 - Update Pool State
SP8 - Sell Negative FT for Negative Underlying
derive
where
Step4 - Update Pool State
xˆori⋅yˆori=(xˆori+σx)⋅(yˆori−δy) δy=yˆori−xˆori+σxxˆori⋅yˆori (Eq.S-3) λy (total ouput XT)=σy+δy=σu+(yˆori−xˆori+εσuxˆori⋅yˆori) (Eq.S-4) Update new APR ( r ) according Eq.D-5
rnew=θRˆy,newRˆx,new+ε−1 Buy λx FT with σu UT
According to Eq.C-2, mint σx FT and σy XT by σu (input amount) UT
σx=εσu (Eq.S-5) σy=σu (Eq.S-6) According to Eq.C-5,
xˆori⋅yˆori=(xˆori−δx)⋅(yˆori+σy) δx=xˆori−yˆori+σyxˆori⋅yˆori (Eq.S-7) λx (total ouput FT)=σx+δx=εσu+(xˆori−yˆori+δuxˆori⋅yˆori) (Eq.S-8) Update new APR ( r ) according Eq.D-5
rnew=θRˆy,newRˆx,new+ε−1 To sell σy XT for λu UT, we need to swap some XT to FT first and combine the remain XT and the bought 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 δ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) ⎩⎨⎧a=εb=xˆori+ε(yˆori−σy) (Eq.S-12)c=−εσyyˆori Update new APR ( r ) according Eq.D-5
rnew=θRˆy,newRˆx,new+ε−1 To sell σx FT for λu UT, we need to swap some FT to XT first and combine the remain FT and the bought 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 δ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) ⎩⎨⎧a=εb=−(xˆori+σx+εyˆori) (Eq.S-16)c=σxyˆori Update new APR ( r ) according Eq.D-5
rnew=θRˆy,newRˆx,new+ε−1 Buy −λy XT with −σu UT
According to Eq.C-2, mint −σx FT and −σy XT by −σu (input amount) UT
σx=εσu (Eq.S-17) σy=σu (Eq.S-18) According to Eq.C-5,
xˆori⋅yˆori=(xˆori+(−σx))⋅(yˆori−(−δy))=(xˆori−σx)⋅(yˆori+δy) δy=xˆori−σxxˆori⋅yˆori−yˆori (Eq.S-19) −λy (total ouput XT)=−σy−δy=−σu−(xˆori−εσuxˆori⋅yˆori−yˆori) (Eq.S-20) Update new APR ( r ) according Eq.D-5
rnew=θRˆy,newRˆx,new+ε−1 Buy −λx FT with −σu UT
According to Eq.C-2, mint −σx FT and −σy XT by −σu (input amount) UT
σx=εσu (Eq.S-21) σy=σu (Eq.S-22) According to Eq.C-5,
xˆori⋅yˆori=(xˆori−(−δx))⋅(yˆori+(−σy))=(xˆori+δx)⋅(yˆori−σy) δx=yˆori−σyxˆori⋅yˆori−xˆori (Eq.S-23) −λx (total ouput XT)=−σx−δx=−εσu−(yˆori−σyxˆori⋅yˆori−xˆori) (Eq.S-24) Update new APR ( r ) according Eq.D-5
rnew=θRˆy,newRˆx,new+ε−1 To sell −σy XT for −λu UT, we need to swap some XT to FT first and combine the remain XT and the bought 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 δ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−δy) (Eq.S-26) −λu=−σy+δy (Eq.S-27) ⎩⎨⎧a=εb=−(xˆori+ε(yˆori+σy)) (Eq.S-28)c=εσyyˆori Update new APR ( r ) according Eq.D-5
rnew=θRˆy,newRˆx,new+ε−1 To sell −σx FT for −λu UT, we need to swap some FT to XT first and combine the remain FT and the bought 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 δy=2a−b+b2−4ac (Eq.S-29) δy=2a−b−b2−4ac (invalid, since yˆnew should be greater than 0) δx=σx−εδy (Eq.S-30) −λu=−δy (Eq.S-31) ⎩⎨⎧a=εb=xˆori−σx+εyˆori (Eq.S-32)c=−σxyˆori Update new APR ( r ) according Eq.D-5
rnew=θRˆy,newRˆx,new+ε−1