Query editor
with payment_detail as (select e.contract_address,e.evt_block_time,date_trunc('day', e.evt_block_time) as block_date,e.evt_tx_hash,e.evt_index,cast(e.value as double) as amount_original,n."to" as buyer_address,n."from" as seller_address,n.tokenIdfrom erc20_polygon.evt_Transfer e-- here we only calculate the payment buyer pay to seller. Buyer pay to marketplace (e.g. Opensea) part is not included by join belowinner join lens_polygon.LensHub_evt_Transfer n on e.evt_block_number = n.evt_block_numberand e.evt_tx_hash = n.evt_tx_hashand e."from" = n."to" -- buyer_addressand e."to" = n."from" -- seller_addresswhere 1 = 1and e.evt_block_time > date('2022-05-18')and n.evt_block_time > date('2022-05-18')),all_trade_summary as (select count(distinct evt_tx_hash) as transaction_count,count(distinct buyer_address) as buyer_count,count(distinct seller_address) as seller_count,count(distinct tokenId) as token_countfrom payment_detail),latest_token_price as (select contract_address, symbol, decimals, date_trunc('day', minute) as block_date, avg(price) as pricefrom prices.usdwhere blockchain = 'polygon'and contract_addressin (select distinct contract_address from payment_detail)and minute >= date('2022-05-18')group by 1, 2, 3, 4-- union all-- select 0xd838290e877e0188a4a44700463419ed96c16107 as contract_address,-- 'NCT' as symbol,-- 18 as decimals,-- block_date,-- 1.69 as price -- as of date 2023-01-17-- from unnest(sequence(date('2022-05-18'), current_date)) as tbl(block_date)),trade_amount as (select d.*,amount_original / pow(10, decimals) * price as trade_amountfrom payment_detail dinner join latest_token_price p on d.contract_address = p.contract_address and d.block_date = p.block_date),