Data Structure
No direction of trade is specified, as for TWAP it is assumed to be a sell order
sellToken= DAIbuytoken= WETHreceiver=address(0)partSellAmount= 12000000 / 30 = 400000 DAIminPartLimit= 7500 / 30 = 250 WETHt0= Nominated start time (unix epoch seconds)n= 30 (number of parts)t= 86400 (duration of each part, in seconds)span= 0 (duration ofspan, in seconds, or0for entire interval)
span to a non-zero duration. For example, if Alice wanted to execute the TWAP, each day for 30 days, however only wanted to trade for the first 12 hours of each day, she would set span to 43200 (ie. 60 * 60 * 12).
Using span allows for use cases such as weekend or week-day only trading.
Methodology
To create a TWAP order:-
ABI-Encode the
IConditionalOrder.ConditionalOrderParamsstruct with:handler: set to theTWAPsmart contract deployment.salt: set to a unique value.staticInput: the ABI-encodedTWAP.Datastruct.
-
Use the
structfrom (1) as either a Merkle leaf, or withComposableCoW.createto create a single conditional order. -
Approve
GPv2VaultRelayerto traden x partSellAmountof the safe’ssellTokentokens (in the example above,GPv2VaultRelayerwould receive approval for spending 12,000,000 DAI tokens).
When calling
ComposableCoW.create, setting dispatch = true will cause ComposableCoW to emit event logs that are indexed by the watch tower automatically. If you wish to maintain a private order (and will submit to the CoW Protocol API through your own infrastructure, you may set dispatch to false).For cancelling a TWAP order, follow the instructions at Conditional order cancellation.