ThatGuyOAB: MakerDAO (Sep 1) - Health - 7. vault
    Updated 2022-09-06
    WITH
    prices as (
    SELECT
    hour::date as date,
    symbol,
    token_address,
    decimals,
    avg(price) as price
    FROM ethereum.core.fact_hourly_token_prices
    GROUP BY 1, 2, 3, 4
    )
    SELECT
    *
    ,
    avg(vault_count) over (order by date rows between 5 preceding and current row) as "MA Vault Count",
    avg(vault_count) over (order by date rows between 100 preceding and current row) as "MA100 Vault Count",
    sum(vault_count) over (order by date) as "Cumulative Vault Count"
    FROM (
    SELECT
    date_trunc('week', block_timestamp) as date,
    count(DISTINCT TX_HASH) as vault_count
    FROM
    ethereum.maker.ez_vault_creation
    WHERE block_timestamp::date >= '{{StartDate}}' AND TX_STATUS = 'SUCCESS'
    GROUP BY 1
    )
    ORDER BY date DESC
    Run a query to Download Data