Query editor
withpricet as (selecttimestamp as dt,price as token_price_usdfromprices.daywhereblockchain = 'ethereum'and contract_address = 0x85f17cf997934a597031b2e18a9ab6ebd4b9f6a4),parsed as (selecttx_hash,tx_from as swapper,b.block_time,block_date,regexp_extract(split(log, ',')[1], 'Swapped +([0-9]+) +([^ ]+) +for +([0-9]+) +([^ ]+)', 1) as amount_in_unadj,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_unadj,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 amountfromnear.actions ajoinnear.logs b using (receipt_id, block_date)whereblock_date >= current_date - interval '30' dayand block_date != current_dateand b.executor_account_id = 'v2.ref-finance.near'and b.execution_status like 'SUCCESS%'and log like 'Swapped % for %'),main as (selectparsed.*,coalesce(amount,max(amount) over (partition by tx_hash)) * token_price_usd as amount_usdfromparsedleft joinpricet on dt = block_date)selectdate_trunc('day', block_date) as dt,count(distinct tx_hash) as swaps,count(distinct swapper) as swappers,sum(amount_usd) as volume_usd,avg(amount_usd) as average_amount_usdfrommain