Simple Automated Market Maker

Simple version of the Uniswap AMM

Constant Product Market

A group of liquidity providers deposits token α \alpha and token β\betawith reserves RαR_{\alpha}and RβR_{\beta}, respectively. The fee for a transaction is (1γ)(1-\gamma) and the conserved quantity is k=RαRβk=R_{\alpha}R_{\beta}. A user wants to trade an amount of token α\alpha, Δα\Delta_{\alpha}, for some amount of token β\beta,Δβ\Delta_{\beta} such that k remains conserved.

Each transaction must satisfy the following equation:

(RαΔα)(Rβ+γΔβ)=k(R_{\alpha} - \Delta_{\alpha})(R_{\beta} +\gamma\Delta_{\beta}) = k

After the transaction the reserves and k are updated as follows:

Rα=RαΔαR_{\alpha} = R_{\alpha} - \Delta_{\alpha}
Rβ=Rβ+ΔβR_{\beta} = R_{\beta} + \Delta_{\beta}
k=(RαΔα)(Rβ+Δβ)k = (R_{\alpha} - \Delta_{\alpha})(R_{\beta} + \Delta_{\beta})

Simple Calculation

Alice wants to sell an amount Δα\Delta_{\alpha} for token β\beta.

What amount, Δβ\Delta_{\beta}, does Bob pay to Alice given RαR_{\alpha}, RβR_{\beta}, and γ\gamma?

Δβ=RβΔαγ(ΔαRα)\Delta_{\beta} = -\frac{R_{\beta} \Delta_{\alpha}}{\gamma(\Delta_{\alpha} - R_{\alpha})}

The ratio of the changes: ν=Δα/Δβ\nu = \Delta_{\alpha} / \Delta_{\beta}.

ν=γΔα(ΔαRα)RβΔα\nu = -\frac{\gamma \Delta_{\alpha}(\Delta_{\alpha} - R_{\alpha})}{R_{\beta}\Delta_{\alpha}}

The market price is mμ=Rα/Rβm_{\mu} = R_{\alpha} / R_{\beta}.

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 wiw_{i}is the reserve weight for the ith token.

k=i=1nRiwik = \prod_{i=1}^{n} R_{i}^{w_{i}}

The conservation equation becomes

c(Rj+γjΔj)wj(RΔ)w=kc(R_{j} + \gamma_{j}\Delta_{j})^{w_{j}}(R_{\ell} -\Delta_{\ell})^{w_{\ell}} = k

where γj\gamma_{j}is the fee for the jth coin and c is given by

c=i=1jnRiwic = \prod_{\substack{i=1 \\ \ell \neq j}}^{n}R_{i}^{w_{i}}

An example can be seen at

Last updated

Was this helpful?