Updated 2023-02-05
    WITH chain_data AS (
    SELECT
    'Optimism' AS chain,
    trunc(block_timestamp, 'week') AS date,
    count(distinct from_address) AS total_unique_users,
    count(distinct tx_hash) AS total_transactions,
    (count(distinct tx_hash) / 86400) AS tps,
    sum(ETH_VALUE) AS amount_eth_volume,
    sum(tx_fee) AS total_volume_fees,
    count(CASE WHEN status = 'FAIL' THEN 1 END) /
    (count(CASE WHEN status = 'FAIL' THEN 1 END) +
    count(CASE WHEN status = 'SUCCESS' THEN 1 END)) AS tx_fail_rate
    FROM optimism.core.fact_transactions
    WHERE block_timestamp >= '2022-01-01'
    GROUP BY 1, 2
    UNION ALL
    SELECT
    'Arbitrum' AS chain,
    trunc(block_timestamp, 'week') AS date,
    count(distinct from_address) AS total_unique_users,
    count(distinct tx_hash) AS total_transactions,
    (count(distinct tx_hash) / 86400) AS tps,
    sum(ETH_VALUE) AS amount_eth_volume,
    sum(tx_fee) AS total_volume_fees,
    count(CASE WHEN status = 'FAIL' THEN 1 END) /
    (count(CASE WHEN status = 'FAIL' THEN 1 END) +
    count(CASE WHEN status = 'SUCCESS' THEN 1 END)) AS tx_fail_rate
    FROM arbitrum.core.fact_transactions
    WHERE block_timestamp >= '2022-01-01'
    GROUP BY 1, 2
    UNION ALL
    SELECT
    'Polygon' AS chain,
    trunc(block_timestamp, 'week') AS date,
    count(distinct from_address) AS total_unique_users,
    count(distinct tx_hash) AS total_transactions,
    Run a query to Download Data