Takes a twap over a set period for a certain aggregator. Aggregators have an optional history buffer account storing the last N accepted results. The TwapTask will iterate over an aggregators history buffer and calculate the time weighted average of the samples within a given time period.

Input: None

Returns: The time weighted average of an aggregator over a given time period.

Example: The 1hr Twap of the SOL/USD Aggregator, requiring at least 60 samples.

{ "twapTask": { "aggregatorPubkey": "GvDMxPzN1sCj7L26YDK2HnMRXEQmQ2aemov8YBtPS7vR", "period": 3600, "minSamples": 60, "weightByPropagationTime": true  } }

Implements

Constructors

  • Constructs a new TwapTask.

    Parameters

    • Optional properties: ITwapTask

      Properties to set

    Returns TwapTask

Properties

aggregatorPubkey: string

The target aggregator for the TWAP.

endingUnixTimestamp: number

Ending unix timestamp to collect values up to

endingUnixTimestampTask?: ICronParseTask

Execute the task to get the ending unix timestamp

minSamples: number

Minimum number of samples in the history to calculate a valid result

period: number

Period, in seconds, the twap should account for

weightByPropagationTime: boolean

Weight samples by their propagation time

Methods

  • Converts this TwapTask to JSON.

    Returns {
        [k: string]: any;
    }

    JSON object

    • [k: string]: any
  • Creates a new TwapTask instance using the specified properties.

    Parameters

    • Optional properties: ITwapTask

      Properties to set

    Returns TwapTask

    TwapTask instance

  • Decodes a TwapTask message from the specified reader or buffer.

    Parameters

    • reader: Uint8Array | Reader

      Reader or buffer to decode from

    • Optional length: number

      Message length if known beforehand

    Returns TwapTask

    TwapTask

    Throws

    If the payload is not a reader or valid buffer

    Throws

    If required fields are missing

  • Decodes a TwapTask message from the specified reader or buffer, length delimited.

    Parameters

    • reader: Uint8Array | Reader

      Reader or buffer to decode from

    Returns TwapTask

    TwapTask

    Throws

    If the payload is not a reader or valid buffer

    Throws

    If required fields are missing

  • Encodes the specified TwapTask message. Does not implicitly verify messages.

    Parameters

    • message: ITwapTask

      TwapTask message or plain object to encode

    • Optional writer: Writer

      Writer to encode to

    Returns Writer

    Writer

  • Encodes the specified TwapTask message, length delimited. Does not implicitly verify messages.

    Parameters

    • message: ITwapTask

      TwapTask message or plain object to encode

    • Optional writer: Writer

      Writer to encode to

    Returns Writer

    Writer

  • Creates a TwapTask message from a plain object. Also converts values to their respective internal types.

    Parameters

    • object: {
          [k: string]: any;
      }

      Plain object

      • [k: string]: any

    Returns TwapTask

    TwapTask

  • Gets the default type url for TwapTask

    Parameters

    • Optional typeUrlPrefix: string

      your custom typeUrlPrefix(default "type.googleapis.com")

    Returns string

    The default type url

  • Creates a plain object from a TwapTask message. Also converts values to other types if specified.

    Parameters

    • message: TwapTask

      TwapTask

    • Optional options: IConversionOptions

      Conversion options

    Returns {
        [k: string]: any;
    }

    Plain object

    • [k: string]: any
  • Verifies a TwapTask message.

    Parameters

    • message: {
          [k: string]: any;
      }

      Plain object to verify

      • [k: string]: any

    Returns string

    null if valid, otherwise the reason why it is not