Skip to content

Automated Market Makers: Pricing, Swaps and LP Accounting

How AMM curves, fees, reserves and arbitrage determine swap execution, and how liquidity providers should measure fees, range exposure and impermanent loss.

Updated

For educational purposes only; not investment advice. AMM swaps and liquidity positions can incur slippage, MEV, contract loss and underperformance versus holding.

Direct answer

An automated market maker is a family of on-chain exchange mechanisms that quote and settle trades against pooled assets under a rule or curve. Constant-product, weighted, stable-swap, concentrated-liquidity and hook-based designs have different invariants, fees and risks; AMM is not synonymous with x*y=k or with every decentralized exchange.

For a swap, distinguish pre-trade marginal price, average execution price, deterministic price impact and pending-time slippage. For a liquidity position, reconcile deposited inventory, pool shares or range liquidity, fees, incentives, gas and withdrawal proceeds against the same-assets hold benchmark.

Amount out
18,132.22
Price impact including fee
9.34%
Input-side fee
0.03

Outputs are educational approximations. They exclude venue rules, taxes, latency, oracle behavior, and other protocol-specific parameters unless shown.

How it works

  1. Pin the chain, pool and router addresses, implementation version, token ordering and decimals, curve or invariant, fee tier, protocol fee, hooks, administrators and pause controls.
  2. Normalize raw balances and internal reserves; define asset-in, asset-out and price units. Verify whether donations, rebases or transfer fees make balances differ from accounting reserves.
  3. Reproduce the exact-input or exact-output quote for every route hop, including fee, invariant, rounding, reserve update, marginal price, average execution, price impact, minOut and deadline.
  4. Simulate the calldata, approvals, native value and route against a declared block; stress state drift, MEV, gas, reverts and alternative liquidity before signing.
  5. For LPs, reconcile deposits, minted shares or liquidity, active range, fee ownership, incentives, withdrawals, rounding and any lock or pause.
  6. Compare terminal LP wealth with a matched hold benchmark, separating inventory value, fees, sold rewards, gas, tax, impermanent loss, adverse selection and rebalancing.
  7. Verify receipts, balance deltas and allowances; monitor curve, fee, hooks, reserves, concentration, oracle use, upgrades, range status, migrations and exit limits.

Examples

  • A constant-product pool has x=100 ETH, y=200,000 USDC and k=20,000,000. Buying exactly 10 ETH without a fee requires 200000*10/90 = 22,222.222222 USDC; with a 0.30% input fee it requires 200000*10/(90*0.997) = 22,289.089491 USDC, averaging 2,228.908949 USDC/ETH. The post-trade reserve ratio is 222289.089491/90 = 2,469.878772 USDC/ETH.
  • The same pool has 1,000 LP tokens. A proportional deposit of 10 ETH and 20,000 USDC mints 100 LP tokens, giving 100/1100 = 9.0909090909%. If reserves later become 120 ETH and 264,000 USDC, that share withdraws 10.9090909091 ETH and 24,000 USDC, before burn fees and rounding.
  • An LP starts with 10 ETH and 20,000 USDC at 2,000; ETH rises to 3,200, so price ratio is r=1.6. Full-range constant-product value relative to holding is 2*sqrt(1.6)/(1+1.6)=0.9730085108, or -2.6991489179%; a 52,000-USDC hold benchmark corresponds to 50,596.442563 USDC before fees.
  • Concentrated liquidity has L=1,000, range PA=1 to PB=9, and current P=4. It holds 166.6666666667 token0 and 1,000 token1, worth 1,666.6666666667 in token1 units. At P>=9, it holds zero token0 and 2,000 token1 and earns no active-range swap fees while price remains outside.

Risks

  • The curve or AMM model is identified incorrectly.
  • Token order, price direction or decimals invert the quote.
  • Balances, reserves or the simulated block are stale.
  • Fee tier or protocol fee changes the invariant update.
  • Thin liquidity creates large deterministic price impact.
  • Slippage tolerance or minOut permits an unacceptable fill.
  • A sandwich or other MEV strategy extracts value.
  • A multihop router or intermediate pool fails.
  • LP shares are diluted or reserve donations distort accounting.
  • Impermanent loss exceeds fees and rewards.
  • Concentrated liquidity becomes inactive outside its range.
  • Rebalancing, gas and taxes consume range returns.
  • Fees or incentives are double counted in LP performance.
  • Reward tokens fall, unlock or cannot be sold.
  • Fee-on-transfer, rebasing, callbacks or hooks break assumptions.
  • A manipulable AMM spot price is used as an oracle.
  • A contract bug, reentrancy or accounting error loses assets.
  • Admin, upgrade, pause, governance or hook powers change behavior.
  • Bridge, custodian, frontend or RPC compromise redirects execution.
  • Chain congestion, reorg, failed withdrawal or recordkeeping errors block exit.

Common misconceptions

  • Every AMM uses x*y=k. Stable, weighted, concentrated and custom curves differ.
  • The pool spot is the external fair price. Arbitrage only tends to align prices subject to fees, depth, latency and risk.
  • Slippage and price impact are identical. Price impact follows the trade size; slippage also captures movement between quote and execution.
  • Fees guarantee that LPs beat holding. Inventory loss and adverse selection can exceed fee income.
  • Impermanent loss harmlessly disappears if one waits. It is benchmark-relative underperformance and can persist or become realized on exit.

Sources

Navigation

Search the wiki...