Query editor
WITHmarketplaces AS (SELECT name AS marketplace_name,address AS marketplace_address,subcategory,tagsFROM dune.ton_foundation.dataset_labelsWHERE category = 'merchant'),prices AS (SELECT DATE_TRUNC('day', timestamp) AS day,token_address,AVG(price_ton) AS price_ton,AVG(price_usd) AS price_usdFROM ton.prices_dailyWHERE timestamp >= DATE '2025-01-01'GROUP BY 1, 2),onchain_data AS (SELECT DATE_TRUNC('day', ne.block_date) AS block_date,'onchain' AS marketplace_type,COALESCE(mp.marketplace_name, 'other on-chain marketplaces') AS marketplace_name,'0:0000000000000000000000000000000000000000000000000000000000000000' AS token_address,COUNT(*) AS total_transactions,SUM(ne.sale_price) AS total_volume_raw,NULL AS net_volume_raw -- used for offchain marketplaces with internal balanceFROM ton.nft_events neLEFT JOIN marketplaces mpON mp.marketplace_address = ne.marketplace_addressAND mp.subcategory = 'onchain_marketplace'WHERE ne.block_date >= DATE '2025-01-01'AND ne.type = 'sale'AND ne.collection_address IN (SELECT col_addressFROM dune.rdmcd.result_gifts_collection_addresses)GROUP BY 1,2,3,4),offchain_marketplaces AS (SELECT marketplace_name,marketplace_addressFROM marketplacesWHERE subcategory = 'offchain_marketplace'),deposits_ton AS (SELECT DATE_TRUNC('day', m.block_date) AS block_date,mp_dst.marketplace_name,m.value AS amount_raw,1 AS sign,'0:0000000000000000000000000000000000000000000000000000000000000000' AS token_addressFROM ton.messages mJOIN offchain_marketplaces mp_dstON mp_dst.marketplace_address = m.destination