Skip to main content

TWAP Orders

TWAP (Time-Weighted Average Price) orders enable splitting large trades into multiple smaller executions at fixed intervals, helping reduce price impact and achieve better average prices.

Core Structure

The TWAP mechanism divides a total trade into n equal parts executing every t seconds, with each part having a validity window defined by the span parameter.

Key Parameters

ParameterTypePurpose
sellTokenIERC20Token being sold
buyTokenIERC20Token being purchased
receiveraddressRecipient of bought tokens
partSellAmountuint256Amount per execution part
minPartLimituint256Minimum buy amount per part
t0uint256Start timestamp (0 for dynamic)
nuint256Number of parts (>1)
tuint256Seconds between parts
spanuint256Validity window (must be less than or equal to t)
appDatabytes32IPFS metadata hash

Validation Requirements

Orders must satisfy:
  • Different sell and buy tokens
  • Non-zero addresses
  • partSellAmount > 0
  • minPartLimit > 0
  • n between 2 and type(uint32).max
  • t between 1 and 365 days
  • span must be less than or equal to t

Validity Window Calculation

With span = 0, each part remains valid until the next part begins. When span > 0, validity is restricted to that duration. This ensures unique order identifiers preventing duplicate executions.

Error Conditions

ErrorDescription
BEFORE_TWAP_STARTCurrent time precedes order start
AFTER_TWAP_FINISHAll parts completed
NOT_WITHIN_SPANCurrent time outside part’s validity window

Implementation

The contract resides at /src/types/twap/TWAP.sol. Key functions include:
  • getTradeableOrder() - Retrieves the current executable part
  • orderFor() - Constructs the CoW Protocol order with calculated validity timestamps
Last modified on March 4, 2026