Query editor
with sales as (selectdate_trunc('day', cast(block_timestamp as timestamp)) as day,sum(case when currency = 'WETH' then cast(amount_raw as double)/1e18 else 0 end) as total_sales_eth,sum(case when currency = 'WETH' then 1 else 0 end) as num_eth_sales,sum(case when currency = 'CU' then cast(amount_raw as double)/1e18 else 0 end) as total_sales_cu,sum(case when currency = 'CU' then 1 else 0 end) as num_cu_sales,sum(case when currency = 'XAI' then cast(amount_raw as double)/1e18 else 0 end) as total_sales_xai,sum(case when currency = 'XAI' then 1 else 0 end) as num_xai_salesfrom dune.lagunagames12_team.dataset_marketplace_sales_v2group by 1order by 1 desc),prices as (selectdate_trunc('day', hour) as day,avg(case when contract_address = 0x89C49A3fA372920aC23ce757A029e6936c0b8e02 then median_price else NULL end) as cu_price, --cu priceavg(case when contract_address = 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1 then median_price else NULL end) as eth_price, --eth priceavg(case when contract_address = 0x4Cb9a7AE498CEDcBb5EAe9f25736aE7d428C9D66 then median_price else NULL end) as xai_price --xai pricefrom dex.priceswhere blockchain = 'arbitrum'and hour > cast('2024-05-07' as timestamp)group by 1)selects.*,s.num_eth_sales + s.num_cu_sales as total_num_sales,s.total_sales_eth * p.eth_price + s.total_sales_cu * p.cu_price + s.total_sales_xai * p.xai_price as total_daily_volume_usd,(s.total_sales_eth * p.eth_price + s.total_sales_cu * p.cu_price + s.total_sales_xai * p.xai_price ) * 0.04 as fee_to_treasury,p.cu_price as cu_price,p.xai_price as xai_price,p.eth_price as eth_pricefrom sales sleft join prices p on s.day = p.dayorder by 1 desc