


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.
Plug lets you combine onchain actions like this one into a single transaction, without writing a smart contract. Use in App opens a new plug with this action already in it.
Takes nothing — it reads the caller's own position.
Get Simple Moving Average



1·Take
The caller supplies a token at slot 0.0, naming the asset whose moving average this plug computes.
2·Take
A window parameter is declared next, the count of intervals the average will span.
3·Get current timestamp
Block time is read as Unix seconds to anchor the day being recorded.
4·Get interval start
Taking the window value, this returns the start timestamp of the 1 day interval containing it.
5·Get price
Chainlink returns the token's latest price in USD, normalized to 18 decimals.
6·Set nested map value
That price is written into the sma nested map in socket storage, keyed by the token and the day start.
7·Set
A day_index variable is initialized to 0 to drive the loop counter.
8·Set
A running total variable is set to 0 before accumulation begins.
9·Predicate
Looping while day_index is less than the window value, the block repeats once per day in the span.
10·Use
Inside the loop, the Get Price Running Total plug is composed to accumulate stored prices.
11·Set
Total is assigned the value that composed plug returned.
12·Calculate
Adding 1 to day_index advances the loop counter.
13·Set
The incremented counter is written back to day_index.
14·End block
This closes the loop block once day_index reaches the window value.
15·Calculate
Dividing the accumulated total by the window yields the simple moving average.
16·Bubble
The computed average is surfaced as an output.
17·Bubble
The latest Chainlink price recorded this run is also surfaced as an output.
Dollar-cost average on Base · 4 plugs
Posts · 4
More on Time · 7