Glossary

TWAMM (Time-Weighted Average Market Maker)

TWAMM breaks large trades into infinitely small orders executed over time to minimize price impact on decentralized exchanges.

Key Takeaways

  • TWAMM is a special type of automated market maker that splits large orders into infinitely many infinitely small virtual sub-orders, executing them continuously over a set period to minimize price impact.
  • Virtual orders are embedded directly into the AMM's constant-product formula, solved with a closed-form equation rather than discrete transactions, and computed lazily only when someone interacts with the pool.
  • Primary use cases include DAO treasury diversification, large token sales, and dollar-cost averaging: bringing institutional-grade execution to permissionless, non-custodial on-chain trading.

What Is TWAMM?

TWAMM (Time-Weighted Average Market Maker) is a decentralized exchange mechanism designed for executing large orders on-chain without moving the market. Introduced in a July 2021 research paper by Dave White and Dan Robinson of Paradigm alongside Uniswap creator Hayden Adams, TWAMM embeds long-running virtual orders directly into an AMM's pricing formula, breaking a single massive trade into a continuous stream of infinitesimally small sub-orders executed over blocks or days.

The problem TWAMM solves is straightforward: a market order selling $10 million of ETH into a DEX liquidity pool can push the price by half a percent or more, costing tens of thousands of dollars in slippage. Traditional finance solves this with TWAP algorithms, iceberg orders, and dark pools. TWAMM brings equivalent functionality to DeFi in a fully trustless, permissionless design.

How It Works

TWAMM consists of two layers: an embedded constant-product AMM (identical to a standard Uniswap V2 pool) and a virtual order system layered on top. Anyone can trade against the embedded AMM normally as a regular swap. The novel part is what happens with long-term orders.

  1. A trader submits a long-term order specifying the token to sell, the total amount, and the duration (measured in blocks or time intervals)
  2. The TWAMM conceptually splits this order into infinitely many infinitely small sub-orders, distributed evenly across the duration
  3. These virtual sub-orders trade against the embedded AMM continuously, adjusting reserves and price as they execute
  4. Arbitrageurs monitor the embedded AMM's price and trade against it to keep it aligned with external markets, ensuring the long-term order gets fair execution
  5. When the duration expires, the trader withdraws their purchased tokens

The Closed-Form Solution

Executing infinite sub-orders one-by-one would require infinite computation. TWAMM avoids this through a closed-form mathematical solution. For a pool with reserves x and y (where x × y = k), receiving orders at rate x_in for one token and y_in for the other, the final reserves can be computed directly using exponential functions:

// Closed-form solution for TWAMM pool reserves after virtual order execution
// Given: x_start, y_start (initial reserves), x_in, y_in (order rates), k = x * y

x_end = sqrt(k * x_in / y_in) * (exp(2 * sqrt(x_in * y_in / k)) + c)
                                / (exp(2 * sqrt(x_in * y_in / k)) - c)

y_end = sqrt(k * y_in / x_in) * (exp(2 * sqrt(x_in * y_in / k)) - c)
                                / (exp(2 * sqrt(x_in * y_in / k)) + c)

// where c = (sqrt(x_start * y_in) - sqrt(y_start * x_in))
//         / (sqrt(x_start * y_in) + sqrt(y_start * x_in))

// Output tokens received by each side:
x_out = x_start + x_in - x_end
y_out = y_start + y_in - y_end

This formula collapses what would be infinite sequential calculations into a single deterministic computation. It preserves the constant-product invariant throughout and produces the exact same result as if every infinitesimal sub-order had been executed individually.

Lazy Evaluation

Even with a closed-form solution, computing virtual order effects every block would waste gas. TWAMM uses lazy evaluation: the contract only recalculates cumulative virtual order effects when a user actually interacts with the pool (swapping, placing a new long-term order, or withdrawing). Between interactions, the pool state is stale but deterministic. If 10,000 blocks pass with no interaction, the next trade triggers a single closed-form calculation covering all 10,000 blocks of accumulated virtual orders.

Order Pooling

Multiple long-term orders in the same direction are pooled together and tracked as a single aggregate order. If three traders are each selling ETH for USDC at different rates, TWAMM combines them into one total sell rate. Proceeds are distributed proportionally using a share-based accounting system similar to how liquidity pool LP shares work.

Order durations are also batched to expire at fixed intervals (every 250 blocks in the original design, hourly in Fraxswap's implementation). This prevents the gas cost degradation that would occur if orders expired at arbitrary blocks, forcing per-block recalculations.

TWAMM vs. TWAP Bots and Iceberg Orders

Traditional finance offers several tools for executing large orders with minimal impact. TWAP bots on centralized exchanges slice an order into equal chunks executed at regular intervals. Iceberg orders hide the true order size, displaying only a small visible portion on the order book. TWAMM achieves a similar outcome on-chain but with fundamentally different properties:

PropertyTWAMMTWAP Bot (CEX)Iceberg Order
CustodyNon-custodial smart contractCustodial exchange accountCustodial exchange account
AutomationFully on-chain, no infrastructureRequires bot and API accessExchange-managed
VisibilityOrder parameters public on-chainPrivatePartially hidden
MEV resistanceInter-block execution deters single-block sandwichesVulnerable to exchange front-runningDesigned to hide intent
AccessPermissionless, any walletOften institutional-only APIOften institutional-only
Gas costsOn-chain gas (optimized via lazy evaluation)Exchange trading feesExchange trading fees

The key tradeoff: TWAMM replaces custodial trust with on-chain transparency, but that transparency means order details are publicly visible, creating information leakage that CEX-based alternatives avoid.

Implementations

Several protocols have implemented TWAMM since the original paper:

Fraxswap

Launched in June 2022 by Frax Finance, Fraxswap was the first live TWAMM implementation. Built on a Uniswap V2 fork, it uses an approximation of the closed-form formula for gas efficiency and aligns order expiries hourly. It deployed across ten chains including Ethereum, Arbitrum, Optimism, and Polygon.

Cron Finance

Cron Finance built a TWAMM on top of Balancer V2's custom pool architecture, launching on Ethereum mainnet via governance proposal BIP-255. It extended the original design with dynamic fee structures, MEV re-investment mechanisms, and virtual order oracles.

Uniswap v4 TWAMM Hook

When Uniswap v4 launched in January 2025, TWAMM shipped as a flagship reference hook implementation. The hook uses the beforeSwap callback to execute virtual orders as the first action in each block, preventing frontrunning. Aggregators like CoW Swap and 1inch route large orders through TWAMM-enabled v4 pools when the execution math is favorable.

Use Cases

DAO Treasury Diversification

The most prominent use case for TWAMM. When a DAO needs to convert millions of dollars in governance tokens to stablecoins for operating expenses, a single large swap would crater the token's price. TWAMM allows the DAO to spread execution over days or weeks, letting arbitrageurs continuously realign the pool with external markets and achieving a fair time-weighted price. The ENS DAO, for example, explored TWAMM for a $16.5 million ETH-to-USDC diversification.

Dollar-Cost Averaging

Individual traders can use TWAMM for automated, on-chain DCA: deposit USDC and buy ETH steadily over 30 days without managing a bot, trusting a centralized exchange, or executing manual transactions. The smart contract handles execution continuously.

Protocol-Owned Liquidity Rebalancing

Protocols managing liquidity pools, conducting token buybacks, or converting treasury assets can use TWAMM to avoid signaling large directional trades to the market. The gradual execution makes it difficult for MEV extractors to profit from the predictable flow.

Risks and Considerations

Information Leakage

The most significant tradeoff: long-term orders are publicly visible on-chain, including order size, direction, and duration. Sophisticated traders can observe a large incoming TWAMM order and front-run it by buying the target asset on external venues, then selling back as the TWAMM order pushes the price. Users can cancel orders at any time, which provides some defense, but the information asymmetry remains a structural weakness compared to dark pool execution.

Multi-Block MEV

TWAMM's virtual orders execute "between" blocks (computed lazily as if they occurred continuously), making single-block sandwich attacks infeasible. However, as proposer-builder separation matures and multi-block MEV extraction becomes more practical, attackers who control consecutive blocks could exploit TWAMM's predictable order flow. The original Paradigm paper acknowledged this as a forward-looking risk.

Oracle Manipulation

TWAMM pools can serve as on-chain price oracles. Research from ETH Zurich demonstrated that multi-block TWAP oracle attacks are "orders of magnitude cheaper than previously known attacks" when an attacker can control two consecutive blocks. TWAMM's predictable order flow could amplify this risk for protocols relying on the embedded AMM's price feed.

Liquidity and Adoption

TWAMM pools require active arbitrageur participation to keep prices aligned with external markets. Without sufficient liquidity and arbitrage activity, long-term orders may execute at prices that diverge significantly from fair value. Early implementations like Fraxswap saw modest adoption, though aggregator integration with Uniswap v4 hooks has broadened the reach of TWAMM execution.

Why It Matters

TWAMM represents a fundamental shift in how large trades can be executed in DeFi. Before TWAMM, traders choosing between self-custody and execution quality faced a binary choice: accept massive price impact on a DEX, or hand assets to a centralized exchange for algorithmic execution. TWAMM eliminates that tradeoff by embedding time-weighted execution directly into the AMM layer, keeping assets in a smart contract throughout.

For the broader crypto payments ecosystem, TWAMM illustrates how on-chain primitives can replicate and improve upon traditional market microstructure. As TradFi and DeFi converge, mechanisms like TWAMM help bridge the execution quality gap that has historically kept institutional capital on centralized venues. For protocols building on Bitcoin Layer 2s and stablecoin infrastructure, these same principles of minimizing price impact apply to large stablecoin conversions, treasury management, and on-chain forex operations.

This glossary entry is for informational purposes only and does not constitute financial or investment advice. Always do your own research before using any protocol or technology.