Set nested map value
Set nested map value

Database · Acts onchain

Writes a value into a two-level keyed map in the socket's persistent storage. The outer and inner keys are both bytes32, so any values can serve, such as user then token. Scope chooses socket storage, shared across every plug the socket runs, or plug storage, private to this plug bundle. Writing zero deletes the entry. Reach for it to record two-dimensional state across executions, like how much of each token has been sent to each recipient, so later runs read it back and enforce limits.

Get Simple Moving Average

plug
time
chainlink
17actions
  1. 1·Take

    The caller supplies a token as a named parameter, declared here so later steps can reference it.

  2. 2·Take

    A window parameter is declared next, its value provided by the caller at execution time.

  3. 3·Get current timestamp

    The current block timestamp is read as Unix seconds.

  4. 4·Get interval start

    This computes the start of the 1 day interval containing the window value from slot 2.0, snapping that timestamp to a day boundary.

  5. 5·Get price

    A Chainlink read fetches the latest price of the token in USD, normalized to 18 decimals.

  6. 6·Set nested map value

    The fetched price from slot 4.7 is written into the sma nested map in socket storage, keyed by the token and the day start from slot 3.0.

  7. 7·Set

    A variable named day_index is initialized to 0 to serve as a loop counter.

  8. 8·Set

    Another variable, total, is set to 0 to accumulate a running sum.

  9. 9·Predicate

    A loop predicate runs while day_index is less than the window value, controlling how many iterations execute.

  10. 10·Use

    Inside the loop, the Get Price Running Total plug is composed to produce a value.

  11. 11·Set

    The total variable is assigned the result returned by that composed plug from slot 9.0.

  12. 12·Calculate

    Arithmetic adds 1 to day_index.

  13. 13·Set

    The incremented result is written back into day_index, advancing the loop.

  14. 14·End block

    The loop block is closed here.

  15. 15·Calculate

    Once the loop ends, total is divided by the window value to compute the average.

  16. 16·Bubble

    The averaged result from slot 14.0 is surfaced as an output.

  17. 17·Bubble

    The stored price from slot 4.7 is also surfaced as an 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
  • Get Simple Moving Average

    plug
    time
    chainlink