Get current timestamp
Get current timestamp

Time · Reads onchain state

Returns the current block timestamp as Unix seconds. This is the time the plug executes at, as the chain sees it. Reach for it to stamp a stored record of when a step ran, to compute intervals against earlier timestamps, or to set a deadline offset for a later step.

Takes nothing — it reads the caller's own position.

Get Simple Moving Average

plug
time
chainlink
17actions
  1. 1·Take

    Declares a token parameter the caller supplies at execution, feeding the asset whose moving average is being computed.

  2. 2·Take

    Declares a window parameter the caller supplies, setting how many days the average spans.

  3. 3·Get current timestamp

    Fetches the current block timestamp as Unix seconds, giving a reference point for today's price sample.

  4. 4·Get interval start

    Rounds that current timestamp down to the start of the day containing it, producing a day-aligned key for storage.

  5. 5·Get price

    Reads the latest Chainlink price of the supplied token quoted in USD, normalized to 18 decimals.

  6. 6·Set nested map value

    Writes that price into the sma nested map in socket storage, keyed by the token and today's day start, recording today's sample.

  7. 7·Set

    Initializes day_index to 0, the loop counter that will walk backward over the window.

  8. 8·Set

    Sets total to 0, the running accumulator for summed prices.

  9. 9·Predicate

    Opens a loop that runs while day_index is less than the window, iterating once per day in the requested span.

  10. 10·Use

    Composes the Get Price Running Total plug to accumulate the price for the current day of the loop.

  11. 11·Set

    Assigns total to the value returned by the running total plug, carrying the accumulated sum forward.

  12. 12·Calculate

    Adds 1 to day_index, advancing the loop counter by one day.

  13. 13·Set

    Stores the incremented value back into day_index so the next iteration compares against the window.

  14. 14·End block

    Closes the loop block, ending the per-day accumulation.

  15. 15·Calculate

    Divides the accumulated total by the window to produce the arithmetic mean price across the span.

  16. 16·Bubble

    Surfaces that mean as an output, the simple moving average.

  17. 17·Bubble

    Surfaces the current Chainlink price stored earlier as a second output.

Take
Take
Get current timestamp
Get start of containing
Get price of in
Set nested map value of in in to
Set to
Set to
Use where
tokenis
todayis
days_backis
price_running_totalis
Set to
Calculate
Set to
End block
Calculate
Bubble
Bubble
  • Pendle Leveraged PT Auto Rollover

    plug
    pendle
    time
  • Get Simple Moving Average

    plug
    time
    chainlink