Query editor
selectd.blockchain,d.contract_address,case-- manually set USDC.e or USDC symbols on arbitrum cuz some rows have them missingwhen d.contract_address = 0xff970a61a04b1ca14834a43f5de4533ebddb5cc8 then 'USDC.e'when d.contract_address = 0xaf88d065e77c8cC2239327C5EDb3A432268e5831 then 'USDC'else symbolend as symbol,case-- manually set USDC.e or USDC decimals on arbitrum cuz some rows have them missingwhen d.contract_address = 0xff970a61a04b1ca14834a43f5de4533ebddb5cc8 then 6when d.contract_address = 0xaf88d065e77c8cC2239327C5EDb3A432268e5831 then 6else decimalsend as decimals,date_trunc('day', hour) as day,approx_percentile(median_price, 0.5) as pricefrom dex.prices dleft join tokens.erc20 ton t.contract_address = d.contract_address and t.blockchain = d.blockchainwhere symbol is not null and decimals is not nulland hour > current_date - interval '30' day -- crucial, only take last 30-day data, else timeout errorgroup by 1,2,3,4,5order by day-- Old code before Oct 20, 2023 ---- -- calc daily median prices for all tokens on all chains-- with oracle_daily_median_prices as (-- -- arbitrum native USDC prices don't show up in prices.usd as of July 16, 2023-- select-- blockchain, contract_address,-- case-- when contract_address = 0xff970a61a04b1ca14834a43f5de4533ebddb5cc8 then 'USDC.e' -- cuz still mislabeled as 'USDC'-- else symbol-- end as symbol,-- decimals, date_trunc('day', minute) as day,-- approx_percentile(price, 0.5) as price-- from prices.usd-- -- where blockchain not in ('solana', 'arbitrum')-- group by 1, 2, 3, 4, 5-- ),-- -- may not be enough so we also pull tokens and prices from the dex.prices table-- dex_daily_median_prices as (-- select-- d.blockchain,-- d.contract_address,-- case-- when d.contract_address = 0xff970a61a04b1ca14834a43f5de4533ebddb5cc8 then 'USDC.e' -- cuz still mislabeled as 'USDC'-- -- native USDC on arbitrum have symbol missing, manually fill in-- when d.contract_address = 0xaf88d065e77c8cC2239327C5EDb3A432268e5831 then 'USDC'-- else symbol-- end as symbol,-- case-- -- native USDC on arbitrum have decimals missing, manually fill in-- when d.contract_address = 0xaf88d065e77c8cC2239327C5EDb3A432268e5831 then 6-- else decimals-- end as decimals,