Query editor
-- ================================================================================-- P2P.ME — TOP 100 POWER USERS (v2). SINGLE STATEMENT.---- STANDARD FIXES: + P2PConfigFacet | dedup (MANDATORY — SUM(volume) and COUNT(*)-- of txs are both corrupted by a double-counted log; this is the query that decides-- WHICH WALLETS ARE THE WHALES, so a double-counted era can put the wrong wallets-- at the top) | NOT EXISTS | token decimals | zero-address + bad-decode guards.---- BUGS FIXED THAT ARE SPECIFIC TO THIS QUERY:-- 1. activity_rate could exceed 1.0. months_tenure was a calendar DIFFERENCE, but-- months_active is an inclusive COUNT. A user whose first tx was last month and-- who was active last month + this month got 2 / 1 = 2.0. Tenure is now-- months_since_first + 1, so activity_rate is bounded at 1.0 by construction.-- 2. months_since_last_tx was calendar-month arithmetic. Last active Jan 31, run it-- Feb 1, and you get "1 month since last tx" for a user who traded yesterday.-- Added days_since_last_tx, which is the honest churn signal.---- COLUMNS ADDED (they are the point of this query — see notes at the bottom):-- pct_of_all_volume, cum_pct_of_all_volume -> concentration, the actual question-- pay_in_volume / pay_out_volume / round_trip_score -> is this a CUSTOMER or a-- MARKET MAKER? These are not the same thing and this table currently calls both-- of them "power users."---- ⚠️ The ×2 does NOT cancel here. total_volume and total_revenue are LEVELS.-- ================================================================================WITH params AS (SELECT 2.0 AS leg_multiplier, 0.01 AS take_rate, 1e9 AS max_sane_order),blacklisted AS (SELECT DISTINCT user AS walletFROM p2p_me_base.reputationmanager_evt_userblacklistedWHERE user IS NOT NULL),raw_events AS (SELECT 'base' AS chain, 1 AS src_rank, evt_tx_hash AS tx_hash, evt_index, evt_block_time AS block_time,from_hex(trim('"' FROM TRY_CAST(JSON_EXTRACT_SCALAR("_order",'$.user') AS VARCHAR))) AS user_wallet,from_hex(trim('"' FROM TRY_CAST(JSON_EXTRACT_SCALAR("_order",'$.token') AS VARCHAR))) AS token,TRY_CAST(JSON_EXTRACT_SCALAR("_order",'$.orderType') AS VARCHAR) AS order_type,TRY_CAST(JSON_QUERY("_order",'strict $.amount') AS DOUBLE) AS amount_rawFROM p2p_me_base.OrderProcessor_evt_OrderCompletedUNION ALLSELECT 'base', 1, evt_tx_hash, evt_index, evt_block_time,from_hex(trim('"' FROM TRY_CAST(JSON_EXTRACT_SCALAR("_order",'$.user') AS VARCHAR))),from_hex(trim('"' FROM TRY_CAST(JSON_EXTRACT_SCALAR("_order",'$.token') AS VARCHAR))),TRY_CAST(JSON_EXTRACT_SCALAR("_order",'$.orderType') AS VARCHAR),TRY_CAST(JSON_QUERY("_order",'strict $.amount') AS DOUBLE)FROM p2p_me_base.OrderFlowFacet_evt_OrderCompletedUNION ALL -- ADDED: absent from every query on the dashboardSELECT 'base', 1, evt_tx_hash, evt_index, evt_block_time,from_hex(trim('"' FROM TRY_CAST(JSON_EXTRACT_SCALAR("_order",'$.user') AS VARCHAR))),from_hex(trim('"' FROM TRY_CAST(JSON_EXTRACT_SCALAR("_order",'$.token') AS VARCHAR))),TRY_CAST(JSON_EXTRACT_SCALAR("_order",'$.orderType') AS VARCHAR),TRY_CAST(JSON_QUERY("_order",'strict $.amount') AS DOUBLE)FROM p2p_me_base.P2PConfigFacet_evt_OrderCompletedUNION ALL -- diamond raw logs; src_rank 2 => loses dedup to any decoded row