FanchicTotal value bridge / blockchain V2
    Updated 2023-09-04
    WITH

    t1 as (
    SELECT
    DATE(block_timestamp) as date,
    case to_address
    when LOWER('0x49048044D57e1C92A77f79988d21Fa8fAF74E97e') then 'base'
    when LOWER('0x32400084C286CF3E17e7B677ea9583e60a000324') then 'zkSync'
    when LOWER('0xae0Ee0A63A2cE6BaeEFFE56e7714FB4EFE48D419') then 'Starknet'
    else 'other'
    end as blockchain,
    SUM(eth_value) as eth_bridge
    FROM ethereum.core.fact_transactions
    --WHERE to_address = LOWER('0x49048044D57e1C92A77f79988d21Fa8fAF74E97e') -- base
    --AND to_address = LOWER('0x32400084C286CF3E17e7B677ea9583e60a000324') -- zkSync
    --AND to_address = LOWER('0xae0Ee0A63A2cE6BaeEFFE56e7714FB4EFE48D419') -- Starknet
    GROUP BY 1,2
    ORDER BY 1 DESC),


    eth_price AS(
    select
    DATE(HOUR)as date1,
    AVG(price) as eth_price
    from ethereum.price.fact_hourly_token_prices
    where TOKEN_ADDRESS = LOWER('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2')
    GROUP BY 1
    ORDER BY 1 DESC),

    final_t as(
    SELECT
    date,
    blockchain,
    eth_bridge,
    SUM(eth_bridge) OVER (ORDER BY date ASC) as total_eth_bridge
    from t1
    Run a query to Download Data