Simple Automated Market Maker
Simple version of the Uniswap AMM
Constant Product Market
A group of liquidity providers deposits token αand token βwith reserves Rαand Rβ, respectively. The fee for a transaction is (1−γ) and the conserved quantity is k=RαRβ. A user wants to trade an amount of token α, Δα, for some amount of token β,Δβ such that k remains conserved.
Each transaction must satisfy the following equation:
(Rα−Δα)(Rβ+γΔβ)=k After the transaction the reserves and k are updated as follows:
Rα=Rα−Δα Rβ=Rβ+Δβ k=(Rα−Δα)(Rβ+Δβ) Simple Calculation
Alice wants to sell an amount Δα for token β.
What amount, Δβ, does Bob pay to Alice given Rα, Rβ, and γ?
Δβ=−γ(Δα−Rα)RβΔα The ratio of the changes: ν=Δα/Δβ.
ν=−RβΔαγΔα(Δα−Rα) The market price is mμ=Rα/Rβ.
Constant Mean Market
A constant mean market is a generalization of a constant product market. The conserved constant becomes a product over all the reserves for n tokens where wiis the reserve weight for the ith token.
k=i=1∏nRiwi The conservation equation becomes
c(Rj+γjΔj)wj(Rℓ−Δℓ)wℓ=k where γjis the fee for the jth coin and c is given by
c=i=1ℓ=j∏nRiwi An example can be seen at