Query editor
withbalances as (select*from"query_3881155(blockchain='ethereum',tokens_query_id='4952175',start_date='2024-12-01')"union allselect*from"query_3881155(blockchain='sonic',tokens_query_id='4952175',start_date='2024-12-01')"),pools_enriched as (selectpe.*,sp.price_blockchain,sp.price_token_addressfrom (selectcasewhen chain_id = 1 then 'ethereum'when chain_id = 146 then 'sonic'end as blockchain,chain_id,from_hex(pool_address) as pool_address,from_hex(underlying_token_address) as underlying_token_address,underlying_token_indexfromquery_4953084) peinner joinquery_4952175 spon pe.pool_address = sp.token_addressand pe.blockchain = sp.blockchain),get_prices as (selectdate_trunc('day', p.minute) as day,pe.blockchain,pe.chain_id,pe.pool_address,pe.underlying_token_address,pe.underlying_token_index,max_by(p.price, minute) as pricefrompools_enriched peleft joinprices.usd pon pe.blockchain = p.blockchainand pe.underlying_token_address = p.contract_addressand p.minute >= date '2024-12-01'group by 1, 2, 3, 4, 5, 6),get_prices_two as (select