WITH daws AS (
SELECT
date_trunc('day', block_timestamp) as date,
count(distinct msg_value:sender) as unique_wallets
FROM terra.msgs
WHERE msg_value:sender IS NOT NULL
GROUP BY 1
)
SELECT
date,
unique_wallets,
avg(unique_wallets) OVER (ORDER BY date ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) as weekly_ma
FROM daws
ORDER BY 1 DESC