CORE DEFI PRIMITIVES AND MECHANICS

Illustrating the Blueprint of Automated Market Makers and Generalized Market Makers

5 min read
#DeFi #Smart Contracts #Liquidity Pools #Protocol Design #Yield Farming
Illustrating the Blueprint of Automated Market Makers and Generalized Market Makers

Automated and generalized market makers are the invisible engines that keep decentralized exchanges humming, as detailed in the architecture behind decentralized exchanges.
They let traders swap assets without a central counterparty, while liquidity providers earn fees for keeping the pools alive.
Below we walk through the core mechanics that make these systems work, then break down the design of classic automated market makers (AMMs) in a deep dive into automated market maker design and the more flexible generalized market makers (GMMs) that are shaping the next wave of DeFi in generalized market makers expanding DeFi opportunities.

Core DeFi Primitives

The following elements are the building blocks of these protocols.
Tokens – ERC‑20 and other assets that can be transferred and verified by the blockchain are a key building block of DeFi protocols.
Smart contracts are the logic that enforces the pool rules, a concept explored in depth in the same building block of DeFi protocols.
Reserve – the total number of tokens held in the pool.
Invariant – the fixed mathematical relationship that the pool must satisfy.
Fees – the percentage of each swap that goes to LPs.
TWAP – the time‑weighted average price that can be used by external protocols for reliable price feeds.

Constant‑Product Formula

x · y = k

This invariant drives classic AMMs and sets the groundwork for the rest of the discussion.
When a swap occurs, the pool’s reserves are recalculated to preserve the constant‑product relationship, ensuring the pool always has the correct amounts of each asset.

Advanced AMMs

Beyond the constant‑product formula, several protocols introduce weighted and stable‑curve invariants.
Stablecoin Curves, as used by Curve, provide extremely low slippage across multiple USD‑pegged assets, while cross‑chain bridging pools can automatically adjust to token supply changes on different chains.
These innovations are further elaborated in revealing how AMMs and GMMs shape modern trading.

GMMs – Dynamic Invariants and Programmable Fees

Key concepts of GMMs include dynamic invariants, composable liquidity, programmable fees, and TWAP integration.
GMMs are designed to adapt to market volatility and provide nuanced fee structures that can deter destabilizing trades, a capability explored in depth in how generalized market makers reshape trading strategies.

Liquidity Provision in GMMs – A Step‑by‑Step

  1. Deposit Tokens
    An LP sends a specified amount of each token to the GMM contract.
    The contract records the deposit, updates the reserves, and issues LP shares proportional to the pool’s overall size.

  2. Dynamic Rebalancing
    The GMM continuously rebalances weights based on a predefined strategy or external signals.

  3. Earn Fees
    Every swap that passes through the GMM pays a fee, which is distributed to LPs according to their share ownership at the time of withdrawal.

  4. Withdraw
    The LP calls the withdraw function, which burns LP shares and returns the underlying tokens, adjusted for the pool’s current invariant and any accrued fees.

Practical Use Cases for GMMs

  • Stablecoin Swaps – Low slippage across multiple USD‑pegged assets.
  • Cross‑Chain Bridging – Pools that automatically adjust to token supply changes on different chains.
  • Synthetic Asset Creation – GMMs can underlie protocols that issue tokenized derivatives, using the invariant to maintain collateral ratios.
  • Portfolio Management – Automated rebalancing of token allocations based on market conditions.

Security and Governance

Because GMMs are more complex, they must incorporate robust security measures:

  • Formal Verification – Proving mathematical properties of the invariant ensures no hidden vulnerabilities.
  • Upgradeability – Governance structures that allow the community to patch bugs or optimize formulas without disrupting liquidity.
  • Audit Trails – Transparent logs of all swaps, deposits, and rebalancing events help detect abuse or anomalies.

Comparative Snapshot

Feature Uniswap V2 Curve Balancer GMM
Invariant x·y = k Complex stable‑curve ∏xᵢ^wᵢ = k ∏xᵢ^wᵢ·f(σ,t) = k
Pool Size 2‑Asset 2‑Asset Multi‑Asset Multi‑Asset
Fees Fixed Low Variable Programmable
Slippage High for volatile pairs Low Variable Adaptive
Governance On‑chain On‑chain On‑chain On‑chain

Final Thoughts

Automated market makers are the backbone of liquidity in decentralized finance.
By moving away from order books to algorithmic pricing, they democratize trading and open the door to novel financial primitives.
Generalized market makers push this evolution further, adding the ability to adapt to market conditions, to handle arbitrary token sets, and to offer nuanced fee structures.
While the mathematics becomes richer and the code more intricate, the core idea remains the same: a transparent, composable system that lets anyone provide liquidity and anyone trade, all governed by immutable rules encoded in smart contracts.

As DeFi matures, the distinction between AMMs and GMMs will blur.
The most successful protocols will likely blend the simplicity of constant‑product pools with the flexibility of weighted, volatility‑aware invariants—providing traders with deep, low‑slippage markets while giving liquidity providers a fair share of the upside.


The diagram above illustrates the flow of a typical AMM trade, showing how reserves adjust to maintain the invariant.


This image depicts a weighted liquidity pool, where each token’s weight influences the pool’s price curve and the allocation of fees.

Lucas Tanaka
Written by

Lucas Tanaka

Lucas is a data-driven DeFi analyst focused on algorithmic trading and smart contract automation. His background in quantitative finance helps him bridge complex crypto mechanics with practical insights for builders, investors, and enthusiasts alike.

Contents