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:
getIsValidTwapParamsgetTwapDurationInSecondsgetTwapPartDelaySeconds(added in 2.3.1)getTwapValidFromTimegetTwapPartDelaysSeconds(added in 2.3.1)changeTwapNumberOfPartsValuegetTwapOrderKeymakeTwapValidFromTimeGetter- 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:
decodeOrderTwapParamsencodeOrderDataListMetadatadecodeOrderDataListMetadatafindOrderDataListMetadatasetOrderDataListMetadataSourcesetOrderDataListMetadataIsJitsetOrderDataListMetadataIsExpressdecodeTwapUiFeeReceiverisValidTwapUiFeeReceivergenerateTwapId- 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.
import { getIsValidTwapParams, getTwapOrderKey } from "@gmx-io/sdk/utils/twap";
import { decodeOrderTwapParams } from "@gmx-io/sdk/utils/twap/uiFeeReceiver";
// order is an Order from @gmx-io/sdk/types/orders; order.data holds the order's dataList
const twapParams = decodeOrderTwapParams(order.data, order.uiFeeReceiver);