Query editor
withstatic as (selecttimestamp '{{displayed period from for exported volumes charts}}' as ts_from, '{{timebox for exported volumes charts}}' as timebox), oneinch as (selectblockchain, block_time, tx_hash, sum(amount_usd) as amount_usd_1inchfrom oneinch.swapswhereprotocol = 'AR'and block_time > (select ts_from from static)and if('{{blockchain}}' = '= all =', true, blockchain = '{{blockchain}}')group by 1, 2, 3)-- dex.trades is read only for the 1inch AR txs, and the join is done before the group by, dexes as (selectblockchain, oneinch.block_time, tx_hash, oneinch.amount_usd_1inch, if(position('uniswap' in trades.project) > 0, trades.project || ' v' || trades.version, replace(trades.project, '_', ' ')) as project, sum(trades.amount_usd) as amount_usdfrom oneinchjoin dex.trades as trades using(blockchain, tx_hash)wheretrades.block_month >= cast(date_trunc('month', timestamp '{{displayed period from for exported volumes charts}}') as date)and trades.block_time > (select ts_from from static)and if('{{blockchain}}' = '= all =', true, blockchain = '{{blockchain}}')group by 1, 2, 3, 4, 5), joined as (selectdate_trunc((select timebox from static), block_time) as time, project, count(*) as txs, sum(least(coalesce(amount_usd, 0), coalesce(amount_usd_1inch, 0))) as volume, approx_percentile(least(coalesce(amount_usd, 0), coalesce(amount_usd_1inch, 0)), 0.5) as median_amount, max(amount_usd) as max_amount_usd, max_by(get_href(get_chain_explorer_tx_hash(blockchain, cast(tx_hash as varchar)), cast(tx_hash as varchar)), amount_usd) as tx_hash_example, max_by(get_href(get_chain_explorer_tx_hash(blockchain, cast(tx_hash as varchar)), cast(tx_hash as varchar)), amount_usd) filter(where blockchain = 'ethereum') as tx_hash_ethereum_example, max_by(get_href(get_chain_explorer_tx_hash(blockchain, cast(tx_hash as varchar)), cast(tx_hash as varchar)), block_time) as tx_hash_last, max_by(get_href(get_chain_explorer_tx_hash(blockchain, cast(tx_hash as varchar)), cast(tx_hash as varchar)), block_time) filter(where blockchain = 'ethereum') as tx_hash_ethereum_lastfrom dexesgroup by 1, 2)-- output --selecttime