Query editor
with cached_list as (selectblock_time,bytearray_to_uint256(bytearray_substring(data, 5, 32)) as pid,cast(bytearray_to_uint256(bytearray_substring(data, 37, 32)) as decimal) as amt,hashfrom ethereum.transactionswhere bytearray_substring(data, 1, 4) =0xe1df480fand "to"=0xECa9D81a4dC7119A40481CFF4e7E24DD0aaF56bDorder by 1),pid_token_array as(select pid,ids from(selectcl.block_time,cl.pid,tb.ids,ROW_NUMBER() OVER (PARTITION BY cl.pid ORDER BY cl.block_time DESC) AS rnkfrom cached_list cl left join erc1155_ethereum.evt_TransferBatch tb on cl.hash=tb.evt_tx_hash)where rnk=1order by pid),pid_token_list as(select pid,id from pid_token_array cross join unnest(ids) as tbl(id)),transact_currency as (select distinct currency_symbol, currency_contractfrom nft.trades where nft_contract_address=0x76BE3b62873462d2142405439777e971754E8E77and currency_symbol is not null),price_info as(select date_trunc('day',hour) as block_date,contract_address,approx_percentile(median_price,0.5) as median_pricefrom dex.prices where contract_address in (select currency_contract from transact_currency where currency_symbol != 'PRIME') -- dex prices has missing prime datagroup by 1,2union all--union prime price(SELECTblock_date,contract_address,approx_percentile(price,0.5) as median_priceFROM (SELECTblock_date,0xb23d80f5fefcddaa212212f028021b41ded428cf "contract_address",(CASE WHEN token_bought_address = 0xb23d80f5fefcddaa212212f028021b41ded428cf THEN amount_usd/token_bought_amount ELSE amount_usd/token_sold_amount END) as priceFROM (SELECT * FROM dex.trades WHERE token_bought_address = 0xb23d80f5fefcddaa212212f028021b41ded428cfUNION ALLSELECT * FROM dex.trades WHERE token_sold_address = 0xb23d80f5fefcddaa212212f028021b41ded428cf))GROUP BY 1,2ORDER BY 1)),time_series AS (SELECT block_date