Query editor
-- Decrypt Information Exchange — fee events (recent: last 10 days, refreshed daily)-- Every successful transaction that moved tokens INTO one of our fee token accounts (address book).-- event_type:-- swap fee taken by a swap route (native Money Account swaps or article plugin swaps)-- private_balance_setup plain token transfer to the fees wallet in a transaction signed by a Helius sponsor-- other_charge any other plain token transfer to the fees wallet (e.g. withdrawal account-opening charges)-- Excluded: account-creation rent, and transactions signed by our own operational wallets.WITH book AS (SELECT * FROM query_9176010),fee_accounts AS (SELECT address FROM book WHERE role IN ('fee_token_account', 'referral_fee_token_account')),ref_accounts AS (SELECT address FROM book WHERE role = 'referral_fee_token_account'),ops_wallets AS (SELECT address FROM book WHERE role IN ('fees_wallet', 'phoenix_builder_authority', 'phoenix_sponsor')),fee_tx AS (SELECT DISTINCT aa.block_date, aa.tx_idFROM solana.account_activity aaWHERE aa.address IN (SELECT address FROM fee_accounts)AND aa.block_time >= CAST(current_date - INTERVAL '10' DAY AS timestamp)AND aa.block_time < now()AND aa.tx_successAND (aa.token_balance_change > 0 OR aa.balance_change > 0)),legs AS (SELECTt.block_date, t.block_time, t.tx_id, t.tx_signer, t.outer_executing_account,coalesce(t.from_owner, t.from_token_account) AS from_owner, t.to_owner, t.symbol, t.amount_display, t.amount_usd,t.to_token_account IN (SELECT address FROM fee_accounts) AS is_fee_leg,t.to_token_account IN (SELECT address FROM ref_accounts) AS is_ref_legFROM tokens_solana.transfers tWHERE t.block_date >= current_date - INTERVAL '10' DAYAND t.block_date < current_date + INTERVAL '1' DAYAND t.block_date IN (SELECT block_date FROM fee_tx)AND t.tx_id IN (SELECT tx_id FROM fee_tx)),per_tx AS (SELECTblock_date,tx_id,min(block_time) AS block_time,arbitrary(tx_signer) AS tx_signer,array_agg(CAST(ROW(from_owner, to_owner, amount_usd, amount_display, symbol, outer_executing_account, is_fee_leg, is_ref_leg)AS ROW(f varchar, t varchar, usd double, amt double, sym varchar, prog varchar, fee boolean, ref boolean))) AS lFROM legsGROUP BY block_date, tx_id),shaped AS (SELECTblock_date, block_time, tx_id, tx_signer,filter(l, x -> x.fee AND x.prog <> 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL') AS fee_legs,filter(l, x -> NOT x.fee) AS other_legsFROM per_tx),tx AS (SELECTblock_date, block_time, tx_id, tx_signer, other_legs,fee_legs[1].f AS wallet,fee_legs[1].prog AS fee_program,fee_legs[1].sym AS fee_symbol,reduce(fee_legs, 0e0, (s, x) -> s + coalesce(x.amt, 0e0), s -> s) AS fee_amount,reduce(fee_legs, 0e0, (s, x) -> s + coalesce(x.usd, 0e0), s -> s) AS fee_usd,any_match(fee_legs, x -> x.ref) AS via_referralFROM shaped