AMM Pricing
5 algorithms in Digital Assets and On-Chain Finance.
In this family#
-
Constant-Product AMM contract
The
x · y = kcurve behind Uniswap v2. Price is set by the reserve ratio, so every trade moves it — and the slippage a trade suffers is a deterministic function of its size relative to the pool.constantProductQuote(reserve0, reserve1, amount0In, feeRate) -
Constant-Sum AMM contract
The
x + y = kcurve: zero slippage, and the pool can be fully drained of one asset. Never used alone for that reason — it is the component that makes stableswap flat near the peg.constantSumQuote(reserve0, reserve1, amount0In, feeRate) -
StableSwap Invariant contract
Curve's invariant: nearly constant-sum near the peg, constant-product away from it. The amplification coefficient sets where that transition happens, and it is what lets a stablecoin pool quote size with almost no slippage until it suddenly cannot.
stableSwapQuote(balances, amountIn, amplification, feeRate, inputIndex, outputIndex) -
Weighted-Product AMM contract
Balancer's generalisation of constant product to arbitrary weights, so a pool can hold 80/20 rather than 50/50. The weights set both the target allocation and the slippage profile.
weightedProductQuote(balanceIn, balanceOut, weightIn, weightOut, amountIn, feeRate) -
Concentrated-Liquidity Position contract
Uniswap v3 positions: liquidity supplied only within a price range. Far more capital-efficient inside the range, and entirely one-sided outside it — a position whose price has left its range is holding only the losing asset.
concentratedLiquidityPosition(liquidity, priceLower, priceUpper, currentPrice)
What they share#
Every topic here is a record-transform, so once you have
called one the rest follow the same shape. Import paths differ only in the final segment:
import { constantProductQuote } from "fintech-algorithms/digital-assets-and-on-chain-finance/amm-pricing/constant-product-amm";
import { constantSumQuote } from "fintech-algorithms/digital-assets-and-on-chain-finance/amm-pricing/constant-sum-amm";Read them in the order above — the sequence is pedagogical, not alphabetical.
Where this sits#
Digital Assets and On-Chain Finance collects 10 algorithms across 2 families. For the concept behind this family rather than the call signatures, see the concept guides.