What is a virtual order in a TWAMM? A 100 ETH case
A virtual order in a TWAMM splits a long-term trade into tiny trades over time, then settles their combined effect on-chain at the pool’s next interaction.
By Web3 Hub Newsroom3 min read
A virtual order in a TWAMM is a long-term trade split into tiny trades over time; this explains why the pool applies them only at its next interaction. Take a trader selling 100 ETH over 10 hours: the order streams out at roughly 10 ETH per hour.
A TWAMM is a time-weighted market maker built into an automated market maker. In Fraxswap, that lets a trader spread a large sale over time without sending a separate swap for every small part.
What happens to 100 ETH over 10 hours?
At a constant rate, the order represents roughly 10 ETH of virtual trades after the first hour. No transaction executes each tiny slice as that hour passes; the pair records the order’s rate and elapsed time.
When someone next swaps or changes liquidity, the Fraxswap pair contracts settle the elapsed trades first. The function executeVirtualOrders computes their combined effect, so reserves then reflect about 10 ETH sold. The pool follows a constant product curve, and arbitrageurs can trade against price differences between pool interactions.
This is lazy settlement: the first transaction that touches the pair after time has passed triggers the computation, and its caller pays the gas. Calculating every slice in a separate on-chain transaction would mean recurring gas costs; calculating the cumulative result at interaction makes long-term orders practical.
Why do opposing virtual orders reduce price impact?
When virtual orders to buy and sell the same token run during the same interval, they trade against each other first. Only the net imbalance pushes the pool along its constant product curve, so both sides cause less price impact than if their full amounts moved the reserves separately.
For instance, a buy stream can absorb part of a sell stream within that interval. The pool then processes only what remains unmatched, reducing how far its price moves for both traders. Paradigm proposed the TWAMM design in July 2021; Dave White, Dan Robinson and Hayden Adams are named on the proposal.
More about long-term orders
How long can a long-term order run?
There is no single run time set by the TWAMM concept. The pair groups order expiries into fixed time intervals; an order ends at its selected expiry.
Does a virtual order earn LP fees for the pool?
Virtual trades execute against the pool like swaps, and the applicable swap fee accrues to liquidity providers under the pair’s fee settings.
What happens if pool liquidity is removed?
The pair settles pending virtual orders before processing a liquidity change. So elapsed trades are computed against the reserves before the removal takes effect.