
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



1·Take
The caller names a token at slot 0.0, declaring at execution time which asset this average is computed for.
2·Take
A window parameter is declared at slot 1.0, the count of periods the caller supplies to control the loop and the divisor.
3·Get current timestamp
Block time is read as Unix seconds to anchor the current point in time.
4·Get interval start
Taking that timestamp, this returns the start of the day interval containing it, snapping to a day boundary.
5·Get price
Chainlink returns the latest price of the named token in USD, quoted against 0x0000000000000000000000000000000000000348 and normalized to 18 decimals.
6·Set nested map value
Writing into the nested map sma in socket storage, the current price is stored under the token and day-start keys.
7·Set
The variable day_index is initialized to 0 to begin counting loop iterations.
8·Set
Setting total to 0 prepares the running accumulator for summed prices.
9·Predicate
A loop opens that continues while day_index is less than the window, iterating once per period.
10·Use
Inside the loop, the Get Price Running Total plug runs to accumulate prices across periods.
11·Set
The total variable is reassigned to that running total returned by the composed plug.
12·Calculate
Arithmetic advances the counter, adding 1 to day_index.
13·Set
The day_index variable is updated to the incremented value.
14·End block
This closes the loop block once day_index reaches the window.
15·Calculate
Dividing the accumulated total by the window computes the simple moving average.
16·Bubble
The computed average is surfaced as an output of this plug.
17·Bubble
Surfacing the stored current price completes the outputs.