# twap

> This module exports helpers for validating and deriving TWAP order timing.

# twap

This module exports helpers for validating and deriving TWAP order timing.

## Exports

Import these helpers, constants, and types from `@gmx-io/sdk/utils/twap`:

- `getIsValidTwapParams`
- `getTwapDurationInSeconds`
- `getTwapPartDelaySeconds` (added in 2.3.1)
- `getTwapValidFromTime`
- `getTwapPartDelaysSeconds` (added in 2.3.1)
- `changeTwapNumberOfPartsValue`
- `getTwapOrderKey`
- `makeTwapValidFromTimeGetter`
- Re-exported constants: `UI_FEE_SOURCE_UI`, `UI_FEE_SOURCE_API`
- Re-exported types: `TwapDuration`, `TwapOrderParams`, `TwapPartParams`

From version 2.3.1, the `@gmx-io/sdk/utils/twap/uiFeeReceiver` subpath exports the helpers that encode and decode TWAP grouping metadata in an order's `dataList`:

- `decodeOrderTwapParams`
- `encodeOrderDataListMetadata`
- `decodeOrderDataListMetadata`
- `findOrderDataListMetadata`
- `setOrderDataListMetadataSource`
- `setOrderDataListMetadataIsJit`
- `setOrderDataListMetadataIsExpress`
- `decodeTwapUiFeeReceiver`
- `isValidTwapUiFeeReceiver`
- `generateTwapId`
- Constants: `UI_FEE_SOURCE_UI`, `UI_FEE_SOURCE_API`, `DATA_LIST_METADATA_PREFIX`, `DATA_LIST_METADATA_VERSION`
- Type: `OrderDataListMetadata`

`decodeOrderTwapParams` returns the decoded metadata from the first valid `dataList` entry that carries a TWAP ID. If no entry does, it falls back to the legacy synthetic `uiFeeReceiver` address format that older TWAP orders use, and it returns `undefined` when neither identifies a TWAP order.

```typescript

// order is an Order from @gmx-io/sdk/types/orders; order.data holds the order's dataList
const twapParams = decodeOrderTwapParams(order.data, order.uiFeeReceiver);
```
