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 inton equal parts executing every t seconds, with each part having a validity window defined by the span parameter.
Key Parameters
Validation Requirements
Orders must satisfy:- Different sell and buy tokens
- Non-zero addresses
partSellAmount> 0minPartLimit> 0nbetween 2 andtype(uint32).maxtbetween 1 and 365 daysspanmust be less than or equal tot
Validity Window Calculation
Withspan = 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
Implementation
The contract resides at/src/types/twap/TWAP.sol. Key functions include:
getTradeableOrder()- Retrieves the current executable partorderFor()- Constructs the CoW Protocol order with calculated validity timestamps