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,regexp_extract(split(log, ',')[1], 'Swapped +([0-9]+) +([^ ]+) +for +([0-9]+) +([^ ]+)', 1) as amount_in_raw,replace(regexp_extract(split(log, ',')[1], 'Swapped +([0-9]+) +([^ ]+) +for +([0-9]+) +([^ ]+)', 2), ',', '') as token_in,regexp_extract(split(log, ',')[1], 'Swapped +([0-9]+) +([^ ]+) +for +([0-9]+) +([^ ]+)', 3) as amount_out_raw,replace(regexp_extract(split(log, ',')[1], 'Swapped +([0-9]+) +([^ ]+) +for +([0-9]+) +([^ ]+)', 4), ',', '') as token_out,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 (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)selectcount(distinct tx_hash) as total_swaps,count(distinct trader) as unique_traders,sum(trade_volume_usd) as total_volume_usd,avg(trade_volume_usd) as avg_trade_size_usd,APPROX_percentile(trade_volume_usd, 0.5) as median_trade_size_usd,max(trade_volume_usd) as largest_trade_usd,