Query editor
WITH marketplaces AS (SELECTname AS marketplace_name,address AS marketplace_address,subcategoryFROM dune.ton_foundation.dataset_labelsWHERE tags LIKE '%telegram-gifts%'),TON_WALLETS AS (SELECT addressFROM ton.accounts AWHERE 1=1-- only smart-contracts with wallet interface aka real usersAND cardinality(FILTER(A.interfaces, i->regexp_like(i, 'wallet_.*') )) > 0 -- wallets & highload),raw_users AS (SELECT DISTINCT prev_owner AS user_address FROM ton.nft_eventsWHERE type = 'sale'AND collection_address IN (SELECT col_address FROM dune.rdmcd.result_gifts_collection_addresses)UNION ALLSELECT DISTINCT owner_address AS user_address FROM ton.nft_eventsWHERE type = 'sale'AND collection_address IN (SELECT col_address FROM dune.rdmcd.result_gifts_collection_addresses)UNION ALLSELECT DISTINCT source AS user_address FROM ton.messagesWHERE destination IN (SELECT marketplace_address FROM marketplaces WHERE subcategory = 'offchain_marketplace') and block_date > CAST('2025-01-01' AS TIMESTAMP)UNION ALLSELECT DISTINCT destination AS user_address FROM ton.messagesWHERE source IN (SELECT marketplace_address FROM marketplaces WHERE subcategory = 'offchain_marketplace') and block_date > CAST('2025-01-01' AS TIMESTAMP)UNION ALLSELECT DISTINCT source AS user_address FROM ton.jetton_eventsWHERE destination IN (SELECT marketplace_address FROM marketplaces WHERE subcategory = 'offchain_marketplace') and block_date > CAST('2025-01-01' AS TIMESTAMP)UNION ALLSELECT DISTINCT destination AS user_address FROM ton.jetton_eventsWHERE source IN (SELECT marketplace_address FROM marketplaces WHERE subcategory = 'offchain_marketplace') and block_date > CAST('2025-01-01' AS TIMESTAMP)UNION ALLSELECT DISTINCT source AS user_address FROM ton.messagesWHERE destination = upper('0:ee59aff2efcd2ba6211ead3bf9259b41abcb24a2f5a9d0d3cb1ed2558b7441e3') and block_date > CAST('2025-01-01' AS TIMESTAMP)UNION ALLSELECT DISTINCT destination AS user_address FROM ton.messagesWHERE source = upper('0:ee59aff2efcd2ba6211ead3bf9259b41abcb24a2f5a9d0d3cb1ed2558b7441e3') and block_date > CAST('2025-01-01' AS TIMESTAMP) -- tonnel withdraw addressUNION ALLSELECT DISTINCT source AS user_address FROM ton.messagesWHERE destination IN (SELECT address FROM dune.ton_foundation.dataset_labels WHERE label = 'mrkt' AND comment = 'top up address')),all_users AS (SELECT DISTINCT ru.user_addressFROM raw_users ruJOIN TON_WALLETS tw ON tw.address = ru.user_address),total_volume AS (SELECT SUM(total_volume_ton) AS total_volume_ton,