Get Simple Moving Average
0x484428507A212cA56D71baa27Ca6089a6dB63a88

What this does

This plug computes a simple moving average of a token's Chainlink USD price over a caller-set window of days and stores each day's price in socket storage. It asks the caller for a token address and a window count of periods. It runs on execution, reading the current timestamp, snapping to the day start, and looping once per day up to the window. Computing the average by hand or from a stale stored price risks a divisor mismatch or an out-of-date result.

Actions · 15

  • Get current timestamp
    Get current timestamp
    Returns the current block timestamp as Unix seconds.
  • Get interval start
    Get start of containing
    Returns the start timestamp of the hour, day, week, or larger interval containing a timestamp.
  • Get price
    Get price of in
    Reads the latest Chainlink price of a base asset in a quote asset, normalized to 18 decimals.
  • Set nested map value
    Set nested map value of in in to
    Writes a value into a two-level keyed map in the socket's persistent storage.
  • Set
    Set to
    Assigns a value to a named variable that later steps reference.
  • Set
    Set to
    Assigns a value to a named variable that later steps reference.
  • Predicate
    Steers control flow by comparing two values: branch, loop, or require the condition holds.
  • Use
    Use where
    tokenis
    todayis
    days_backis
    price_running_totalis
    Composes another plug inside this one.
  • Set
    Set to
    Assigns a value to a named variable that later steps reference.
  • Calculate
    Calculate
    Applies a binary arithmetic operation to two values and returns the result.
  • Set
    Set to
    Assigns a value to a named variable that later steps reference.
  • End block
    End block
    Closes the innermost open block, whether a conditional branch or a loop.
  • Calculate
    Calculate
    Applies a binary arithmetic operation to two values and returns the result.
  • Bubble
    Bubble
    Surfaces a value as an output of this plug.
  • Bubble
    Bubble
    Surfaces a value as an output of this plug.

Related plugs · 8