Query editor
with_config as (select(timestamp '2025-02-01') as start_date-- null as start_date),ton_prices as ( -- get price of TON for each day to estimate USD valueselectdate_trunc('day', minute) as block_date, avg(price) as pricefrom prices.usdwhere trueand ((select start_date from _config) is null or minute > (select start_date from _config))and symbol = 'TON'and blockchain is nullgroup by 1),filters as (select '%Reward from Telegram bot%Ref#%' as f, 'TG Stars Reward from bot' as payment_type, 'out' as payment_directionunion allselect '%Telegram Stars%Ref#%' as f, 'TG Stars' as payment_type, 'in' as payment_directionunion allselect '%Telegram Premium%Ref#%' as f, 'TG Premium' as payment_type, 'in' as payment_directionunion allselect '%Prepaid Subscription%Ref#%'as f, 'TG Premium' as payment_type, 'in' as payment_directionunion allselect '%Reward from Telegram channel%Ref#%' as f, 'TG Ads Rewards' as payment_type, 'out' as payment_direction-- union all-- select 'Telegram Gateway account top up%Ref#%'as f, 'TG Gateway' as payment_type, 'in' as payment_direction-- union all-- select 'Fee to upgrade % for bots%Ref#%'as f, 'TG Bots Upgrade' as payment_type, 'in' as payment_direction-- union all-- select 'Ref#%'as f, 'Others(unlabelled)' as payment_type, 'in' as payment_directionunion allselect '%Telegram Ad account top up%Ref#%' as f, 'TG Ads Top Up' as payment_type, 'in' as payment_direction-- union all-- select 'Royalty' as f, 'Royalty' as payment_type, 'in' as payment_direction),output as (selectm.block_date,payment_type,payment_direction,case when payment_direction = 'in' then m.source else m.destination end as address,arbitrary(trace_id) as example,sum(value * price) / 1e9 as amount,sum(value) / 1e9 as amount_tonfrom ton.messages mjoin filters on m.comment like fjoin ton_prices tp on tp.block_date = m.block_datewherem.block_date >= CAST('2025-02-01' AS TIMESTAMP)