Query editor
/*-- @title: Token Price-- @description: Provides the daily price in USD for a long list of tokens!-- @author: Steakhouse Financial-- @ER model: https://docs.google.com/presentation/d/1JI2b12FBZaV0nInBFB2rbvQiXHBdylDHc1Kq3oJlA8M-- @version:- 1.0 - 2025-02-06 - Initial version- 2.0 - 2025-03-27 - Getting tokens from result_token_info only if they have a price feed- 3.0 - 2025-03-28 - Added price safety check (discard dex price when > 2M USD)- 4.0 - 2025-05-06 - Price history starting from the first price feed per token (instead of global start date for all tokens)- Added calculated_price_usd, default_price_usd & dex_price_usd- Added EUR to USD conversion for eur-stablecoins- 5.0 - 2025-05-13 - Added morpho calcs into <calculated_pricing> cte- 6.0 - 2025-05-14 - Removed 2 price outliers from <default_pricing> cte- 7.0 - 2025-05-22 - Using prices.day instead of prices.usd_daily & dex.prices + backfill backwards missing stablecoin prices- 8.0 - 2026-07-16 - Add Morpho Vault V2 Prices*/-- @todo: remove matview 'dune.steakhouse.result_lending_protocols_asset_info' -- Lending Protocols - Asset infowith-- list of tokens to retrieve prices fortokens as (selectblockchain,symbol,token_address,underlying_address as price_address,date(start_date) as start_date,"type"from dune.steakhouse.result_token_infowhere has_price),-- create a sequence for all tokens since their creation dateseries as (select s.dt, t.*from tokens tcross join unnest(sequence(t.start_date, current_date, interval '1' day)) as s(dt)),-- find the price through alternative calculations for assets when price does not exist in prices.daycalculated_pricing as (selectdt,blockchain,symbol,token_address,price_usdfrom dune.steakhouse.result_token_alternative_pricewhere token_address is not null -- exclude EUR priceunion allselectdt,blockchain,vault_symbol,vault_address,share_price_usdfrom dune.steakhouse.result_morpho_vaults_data_unionWHERE vault_type = 'v1'),-- find the price from dune table prices.day (coinpaprika + dex.trades)dune_pricing as (