Fraxswap is a decentralized exchange built by Frax Finance that implements the Time-Weighted Average Market Maker (TWAMM) — enabling permissionless execution of extremely large token orders spread across thousands of blocks to minimize price impact — serving as Frax Finance’s primary on-chain market operations tool for minting/redeeming FRAX, managing FXS buybacks, and rebalancing protocol collateral without relying on third-party market makers.
Overview
Fraxswap launched in April 2022 as the first production implementation of TWAMM, a mechanism described in a 2021 research paper by Paradigm (Dave White and Dan Robinson). The protocol is built by Frax Finance — the team behind the FRAX algorithmic stablecoin and FXS governance token — primarily to serve as internal market operations infrastructure for the Frax protocol itself, though it also functions as a public DEX.
The core design allows very large orders (e.g., $10M buyback of FRAX using USDC collateral) to be executed atomically across 10,000+ future blocks, paying a small price spread each block rather than hitting market depth once. This eliminates the price impact that would occur from a single large swap and reduces MEV extraction from large predicted trades.
TWAMM (Time-Weighted Average Market Maker)
Here’s how the market structure works.
The Problem TWAMM Solves
Large order execution in DeFi:
- Option A: Single swap → $10M swap in one transaction → massive price impact (can be 5-20% on shallow pools) + sandwiching by MEV bots
- Option B: Manual TWAP execution → human manually executes orders over time → requires monitoring, gas, and still susceptible to frontrunning on each tx
- Option C: Off-chain OTC/RFQ (Hashflow/Wintemute) → works but requires trusting counterparty
- TWAMM: Automated, on-chain TWAP execution → submit large order + time duration → TWAMM automatically executes across every block, splitting the order effectively into infinitely small pieces
TWAMM Architecture
Fraxswap is a Uniswap V2 fork with TWAMM as an embedded feature:
- Long-Term Orders (LTOs): Users submit orders specifying: token to sell, token to receive, total amount, deadline (block or timestamp)
- Virtual TWAMM Reservoir: The AMM maintains a separate “long-term order reservoir” that continuously sells tokens from active LTOs into the pool at each block
- Execution Mechanics:
Each block: TWAMM calculates how much of each active LTO should be virtually filled based on elapsed blocks
Uses an analytical formula (not iterative) to compute the exact output without actually executing each block (gas-efficient: only requires settlement at withdrawal)
The formula accounts for the interaction between all active LTOs simultaneously (multiple long-term orders in both directions partially cancel each other)
- Settlement: When the LTO completes (or the user cancels), they call
withdraw()to receive accumulated output tokens
Mathematical Foundation
The TWAMM execution formula (from Paradigm research):
For two LTOs in opposite directions (selling token X at rate xk and selling token Y at rate yk):
- The orders partially net against each other at the midpoint
- The remaining imbalance trades into the AMM pool
- Uses closed-form solution based on geometric mean of trading rates
This allows computing the exact accumulated LTO execution without simulating every block, making settlement gasless for intermediate blocks.
Frax Protocol Integration
Fraxswap’s primary use case is Frax’s internal market operations:
AMO (Algorithmic Market Operations)
- FRAX buybacks: Algorithmically buy FRAX off-market when FRAX trades below peg using collateral — TWAMM spreads buyback over time to avoid price impact
- FXS buybacks and burns: Protocol treasury buys FXS gradually using fees/revenue — TWAMM minimizes market impact and reduces predictability for MEV bots
- Collateral rebalancing: Shift between USDC, FRXETH, and other collateral positions gradually
frxETH Integration
Public DEX Function
Beyond Frax internal operations, Fraxswap also functions as a public DEX:
- Standard V2 swaps available (same x*y=k pools as Uniswap V2 for spot swaps)
- Public users can create Long-Term Orders for their own large trades
- Multi-chain: deployed on Ethereum, Arbitrum, Optimism, Polygon, BNB Chain, Avalanche, Moonbeam
- TVL primarily in Frax-related pairs; general-purpose DEX usage limited (Uniswap/Curve dominate spot swapping)
Sources
- “TWAMM” — Paradigm Research — Dave White and Dan Robinson, Paradigm, June 2021. The foundational academic paper introducing the Time-Weighted Average Market Maker concept — proving the completeness of the closed-form TWAMM execution formula (using continuous-time differential equations for AMM reserve dynamics with constant flow rates, deriving the analytical solution for accumulated swap output over N blocks with simultaneous opposing LTOs), analyzing gas efficiency advantages over block-by-block execution, and characterizing MEV resistance properties of predictable large order flow via TWAMM.
- Fraxswap Documentation — Frax Finance — Frax Finance Team, 2022–2023. Technical documentation for Fraxswap implementation — Uniswap V2 fork modifications (additional TWAMM-specific functions:
longTermSwapFrom0To1(amountIn, numberOfTimeIntervals),longTermSwapFrom1To0(amountIn, numberOfTimeIntervals),cancelLongTermSwap(orderId),withdrawProceedsFromLongTermSwap(orderId)), multi-chain deployment addresses, LP provision mechanics (LPs provide liquidity normally; TWAMM reservoir is virtually separate from spot LP reserves during execution, reconciled at settlement), fee structure (0.3% swap fee on spot swaps; no additional fee on TWAMM LTOs — TWAMM trades do pay spread against the AMM curve per block), and AMO integration points (how Frax protocol contracts call Fraxswap’s LTO functions for scheduled buybacks and rebalancing).
- “Frax’s AMO System: Using Fraxswap for Algorithmic Market Operations” — Frax Finance Research, 2022–2023. Analysis of how Frax’s AMO (Algorithmic Market Operations Controller) uses Fraxswap as its primary on-chain execution venue — the FXS buyback schedule (protocol revenue → Fraxswap TWAMM LTOs for FXS → monthly buyback execution), FRAX peg defense mechanism (collateral → TWAMM buy FRAX when below peg), and the role Fraxswap plays in Frax v2 and v3 stability.
- “TWAMM in Practice: Gas Costs, MEV, and Real-World Performance on Fraxswap” — DeFi Infrastructure Research, 2023. Production analysis of Fraxswap TWAMM usage — actual gas consumption for order creation and settlement (vs theoretical estimates), observed MEV strategies by searchers against TWAMM order flows, LTO usage patterns (who submits long-term orders, typical size and duration), and the slippage achieved vs alternative execution methods for comparable order sizes.
- “TWAMM vs Alternatives: Comparing Large-Order Execution in DeFi” — DeFi Market Microstructure Research, 2022–2023. Comparative analysis of execution strategies for large DeFi orders (>$1M) — TWAMM (Fraxswap), RFQ (Hashflow), OTC (Wintermute/GSR), CLMM aggregated routing (1inch for chunked execution), and off-chain Dutch auctions (CoW Protocol batch settlement) — examining price achieved, counterparty trust, cost, and speed trade-offs.