Query editor
with base_trades as(select *from test_schema.git_dunesql_7dd173e_dex_solana_base_tradeswhere block_month >= timestamp '2025-06-01')SELECT bt.blockchain, bt.project, bt.version, bt.block_month, cast(date_trunc('day', bt.block_time) as date) as block_date, bt.block_time, bt.block_slot, bt.trade_source, token_bought.symbol as token_bought_symbol, token_sold.symbol as token_sold_symbol, case when lower(token_bought.symbol) > lower(token_sold.symbol)then concat(token_bought.symbol, '-', token_sold.symbol)else concat(token_sold.symbol, '-', token_bought.symbol)end as token_pair, bt.token_bought_amount_raw / pow(10, coalesce(bt.token_bought_decimal_project_specific, token_bought.decimals)) as token_bought_amount, bt.token_sold_amount_raw / pow(10, coalesce(bt.token_sold_decimal_project_specific, token_sold.decimals)) as token_sold_amount, bt.token_bought_amount_raw, bt.token_sold_amount_raw, COALESCE(-- if bought token is trusted, prefer that price, else default to sold token then bought token.case when tt_bought.contract_address is not null thenbt.token_bought_amount_raw / pow(10, coalesce(bt.token_bought_decimal_project_specific, token_bought.decimals)) * p_bought.priceelse null end, bt.token_sold_amount_raw / pow(10, coalesce(bt.token_sold_decimal_project_specific, token_sold.decimals)) * p_sold.price, bt.token_bought_amount_raw / pow(10, coalesce(bt.token_bought_decimal_project_specific, token_bought.decimals)) * p_bought.price)as amount_usd, bt.fee_tier, bt.fee_tier * COALESCE(-- if bought token is trusted, prefer that price, else default to sold token then bought token.case when tt_bought.contract_address is not null thenbt.token_bought_amount_raw / pow(10, coalesce(bt.token_bought_decimal_project_specific, token_bought.decimals)) * p_bought.priceelse null end, bt.token_sold_amount_raw / pow(10, coalesce(bt.token_sold_decimal_project_specific, token_sold.decimals)) * p_sold.price, bt.token_bought_amount_raw / pow(10, coalesce(bt.token_bought_decimal_project_specific, token_bought.decimals)) * p_bought.price) as fee_usd, bt.token_bought_mint_address, bt.token_sold_mint_address, bt.token_bought_vault, bt.token_sold_vault, bt.project_program_id, bt.project_main_id, bt.trader_id, bt.tx_id, bt.outer_instruction_index, bt.inner_instruction_index, bt.tx_indexFROMbase_trades btLEFT JOIN"delta_prod"."tokens_solana"."fungible" token_boughtON token_bought.token_mint_address = bt.token_bought_mint_addressLEFT JOIN"delta_prod"."tokens_solana"."fungible" token_sold