Query editor
WITHnear_price as (selecttimestamp as dt,price as near_price_usdfromprices.daywhereblockchain = 'ethereum'and contract_address = 0x85f17cf997934a597031b2e18a9ab6ebd4b9f6a4),trading_parsed as (selecttx_hash,tx_from as trader,b.block_time,block_date,casewhen regexp_extract(split(log, ',')[1], 'Swapped +([0-9]+) +([^ ]+) +for +([0-9]+) +([^ ]+)', 2) = 'wrap.near'then cast(regexp_extract(split(log, ',')[1], 'Swapped +([0-9]+) +([^ ]+) +for +([0-9]+) +([^ ]+)', 1) as double) / 1e24when regexp_extract(split(log, ',')[1], 'Swapped +([0-9]+) +([^ ]+) +for +([0-9]+) +([^ ]+)', 4) = 'wrap.near'then cast(regexp_extract(split(log, ',')[1], 'Swapped +([0-9]+) +([^ ]+) +for +([0-9]+) +([^ ]+)', 3) as double) / 1e24end as normalized_amountfromnear.actions ajoinnear.logs b using (receipt_id, block_date)whereblock_date >= current_date - interval '{{Days Interval}}' dayand block_date != current_dateand (b.executor_account_id = 'v2.ref-finance.near' orb.executor_account_id like '%.rhea.near' orb.executor_account_id like '%rhealab%')and b.execution_status like 'SUCCESS%'and log like 'Swapped % for %'),main as (selecttp.*,coalesce(tp.normalized_amount,max(tp.normalized_amount) over (partition by tp.tx_hash)) * np.near_price_usd as trade_volume_usdfromtrading_parsed tpleft joinnear_price np on np.dt = tp.block_date)selectdate_trunc('day', block_date) as dt,count(distinct tx_hash) as daily_swaps,count(distinct trader) as daily_unique_traders,sum(trade_volume_usd) as daily_volume_usd,avg(trade_volume_usd) as avg_trade_size_usd,approx_percentile(trade_volume_usd, 0.5) as median_trade_size_usd,lag(sum(trade_volume_usd), 1) over (order by date_trunc('day', block_date)) as prev_day_volume,casewhen lag(sum(trade_volume_usd), 1) over (order by date_trunc('day', block_date)) > 0