Fraxswap’s TWAMM turns a deposited token amount into a steady sell rate over a chosen number of intervals, calculates the resulting trades when the pair contract is touched, and lets the order owner withdraw the other token’s proceeds after expiry or cancel to recover proceeds and unsold input.
- Placement fixes the sell rate and an interval-aligned expiry.
- Virtual execution accounts for both selling directions and updates the pool’s reserves.
- Withdrawal collects proceeds; cancellation also returns unsold input.
These are stages of one order. Its tokens can be selling over time even when the contract has not yet recorded each virtual trade on-chain.
How Fraxswap TWAMM Sets the Sell Rate
The pair contract sets a long-term order’s sell rate from its input deposit and number of time intervals. For a treasury spreading a large conversion, Fraxswap makes that rate the starting point for estimating how much input sells during each interval.
The pair contract source exposes longTermSwapFrom0To1 and longTermSwapFrom1To0 for the two directions. Placement assigns an order ID and an expiry on an interval boundary. Orders selling the same token contribute to a shared directional sell rate, while each owner retains a separate claim to their order’s proceeds.
The interval count determines the trading window; the deposited amount determines how much flows through it. A longer window spreads the same input more thinly, leaving the order exposed to the pool’s price path for longer.
How Virtual Execution Moves the Pool
The TWAMM advances virtual sales when an interaction requires current pool state. Its executeVirtualOrders function settles elapsed time through interval boundaries, accounts for orders that expire there, and updates the reserves before the interaction continues.
The 2021 Paradigm TWAMM paper, by Dave White, Dan Robinson and Hayden Adams, defines a virtual order as an infinitesimal piece of a long-term sale against an embedded constant-product AMM. That meaning explains the smooth sell flow: the contract calculates the cumulative result when needed, rather than submitting every piece as a transaction. Where both directions are selling, the calculation handles their combined effect with a closed-form solution; the exchange’s implementation uses an approximation of the paper’s formula.
Lazy settlement does not give an idle order a new price when someone finally touches the pool. It reconstructs the trades across elapsed time, using the reserve path implied by those trades and intervening pool interactions. On Ethereum, arbitrage trades can move the pool back toward prices elsewhere during the order window. Execution quality therefore depends on reserve depth and on whether that arbitrage occurs, not just on the chosen duration.
How Opposing Orders Affect the Fill
Opposing long-term sell flows offset each other before the remaining imbalance moves the AMM’s reserves. At the prevailing pool price, token0 sellers can supply token0 wanted by token1 sellers, and token1 sellers can supply the reverse side. The matched portions exchange value without pushing the reserves in one direction; any unmatched flow trades against them.
Illustratively, a treasury order sells token0 while another owner sells an equivalent value of token1 over the same interval. Before those sales, the treasury has deposited token0 and has no token1 proceeds. After the interval’s virtual calculation, some of its token0 has become claimable token1, yet the matched flow alone has not shifted the reserve ratio. The treasury remains the order owner, and its order ID and expiry remain the same.
If the opposing seller stops earlier, the treasury’s remaining flow reaches the reserves without that offset. Its later fills can therefore differ from its earlier fills even though its own sell rate stays constant. Netting helps explain the path; it does not lock a final average price.
How Cancellation and Withdrawal End the Order
The order owner closes the position by collecting proceeds after expiry or by cancelling while input remains unsold. withdrawProceedsFromLongTermSwap settles the order and transfers claimable output; proceeds can also be withdrawn while the order is active. cancelLongTermSwap settles through cancellation, then returns both purchased output and unsold input.
For the illustrative treasury order, expiry means its scheduled sale has finished: deposited input has become output proceeds, subject to the pool path, and the owner still must withdraw them. Cancellation changes the outcome earlier: sales already executed stay executed, while the unsold balance returns to the same owner. Neither action rewrites earlier fills.
- Choose the input amount and intervals, then record the order ID and expiry.
- Monitor reserves, opposing sell flow and arbitrage during the window.
- At expiry, withdraw proceeds; if the sale should stop sooner, cancel and collect both balances.