Updated 2023-01-01
    WITH table1 AS (SELECT sender as new_joiners, min(BLOCK_TIMESTAMP) as min_day
    FROM osmosis.core.fact_transfers
    WHERE not SENDER LIKE 'osmo%' and RECEIVER LIKE 'osmo%' and TX_SUCCEEDED=true
    GROUP by 1),
    table2 as (select INITCAP(regexp_substr(sender,'[a-zA-Z]+|\d+')) as top_chain,
    COUNT(DISTINCT tx_id) as count_transactions
    FROM osmosis.core.fact_transfers
    WHERE tx_id in (select tx_id from (select sender, tx_id from osmosis.core.fact_transfers
    join table1
    where sender = new_joiners and block_timestamp = min_day))
    GROUP BY 1 ORDER BY 2 DESC LIMIT {{number_of_chains}})
    select date_trunc('month',block_timestamp) as month, INITCAP (regexp_substr (sender,'[a-zA-Z]+|\d+')) as original_chain,
    COUNT(DISTINCT tx_id) as count_transaction
    FROM osmosis.core.fact_transfers
    WHERE receiver ilike 'osmo%' AND not sender ilike 'osmo%' and original_chain in (select top_chain from table2)
    GROUP BY 1,2
    Run a query to Download Data