Query editor
with fx as (select*from query_5519263), market_rate as (select*from query_5519376),dex_tx as (selectblockchain,block_month,block_date,block_time,tx_hash,token_pair,project,project_contract_address,token_bought_symbol,token_sold_symbol,t.token_bought_amount,t.token_sold_amount,amount_usd,casewhen token_bought_symbol != 'usd' then 'buy ccy'when token_sold_symbol = 'usd' then 'sold ccy'end as trade_type,casewhen token_bought_symbol != 'usd' then token_sold_amount / token_bought_amountwhen token_sold_symbol = 'usd' then token_bought_amount/token_sold_amountend as dex_ratefrom dex.trades tjoin fx fb on lower(t.token_bought_symbol) = fb.tokenjoin fx fs on lower(t.token_sold_symbol) = fs.tokenwhereblockchain = 'base' andblock_date >= NOW() - INTERVAL '12' month andfb.type != fs.type -- fx pair),dex_rate as (selectblock_date,project,project_contract_address,avg(dex_rate) as dex_rate_meanfrom dex_txwhere token_pair = 'CADC-USDC' and dex_rate < 10 -- exclude outliers (potnetial sandwich attack)group by 1,2,3)select * from dex_rate --where block_date = timestamp '2025-03-15' and token_pair = 'CADC-USDC'