Automated market makers (CFMMs)
A constant-function market maker holds reserves and accepts any trade that leaves a trading function unchanged. The constant-product rule (Uniswap) $x\cdot y=k$ is the canonical case; Balancer generalises to a weighted geometric mean $\prod_i R_i^{w_i}=k$. Liquidity providers earn fees but bear impermanent loss against a price move of factor $r$:
$\mathrm{IL}(r)=\dfrac{2\sqrt r}{1+r}-1\le 0$
A CFMM is the convex conjugate of a cost-function market maker — the same object as LMSR seen from the reserves side.
Code: mechanisms/amm.py ·
Demo: examples/sim_amm.py