Query editor
-- Query 1: TW Fee Inflows — Optimized-- Purpose:-- Efficiently tracks incoming balance changes to the Trustless Work fee address.-- Strategy:-- 1. Restrict by date partition.-- 2. Keep only operations whose asset_balance_changes include the TW address.-- 3. Unnest only the filtered balance changes, not the whole table.WITH candidate_operations AS (SELECTo.closed_at,o.closed_at_date,o.ledger_sequence,o.transaction_id,o.id AS operation_id,o.type_string,o.source_account,o.asset_balance_changesFROM stellar.history_operations oWHERE o.closed_at_date >= CURRENT_DATE - INTERVAL '90' DAYAND cardinality(o.asset_balance_changes) > 0AND any_match(o.asset_balance_changes,x -> x."to" = 'GBWWSOATPLIC72ZBOIM7WJCT7VCAHNWW4QUBZ2H4FORMCCIUM5ZVKSZN')),fee_inflows AS (SELECTo.closed_at AS block_time,o.closed_at_date AS block_date,o.ledger_sequence,o.transaction_id,to_hex(t.transaction_hash) AS transaction_hash,o.operation_id,o.type_string,o.source_account,u.bc_from AS sender_address,u.bc_to AS receiver_address,COALESCE(u.bc_asset_code, 'XLM') AS token_symbol,u.bc_asset_issuer AS asset_issuer,u.bc_asset_type AS asset_type,u.bc_type AS balance_change_type,u.bc_amount AS fee_amount,u.bc_amount / 0.003 AS estimated_released_volumeFROM candidate_operations oLEFT JOIN stellar.history_transactions tON o.transaction_id = t.idCROSS JOIN UNNEST(filter(o.asset_balance_changes,x -> x."to" = 'GBWWSOATPLIC72ZBOIM7WJCT7VCAHNWW4QUBZ2H4FORMCCIUM5ZVKSZN'AND x.amount > 0AND x.type = 'transfer')) AS u(