Query editor
-- ================================================================================-- P2P.ME — QUERY 2 (v2): ANNUALIZED VOLUME PER WEEK-- Same output columns as v1. Rebuilt for coverage, not hardcoding.---- CHANGES vs v1 (details in chat):-- 1. Added p2pconfigfacet_evt_ordercompleted -> v1 was missing a whole facet era-- 2. Deduped on (chain, tx_hash, evt_index) -> v1 could double-count diamond logs-- 3. Token-aware decimals via tokens.erc20 -> v1 hardcoded /1e6 (USDC only)-- 4. NOT EXISTS instead of NOT IN -> v1 returns ZERO ROWS if any blacklist user is NULL-- 5. Excluded the in-progress week -> v1's last bar is always a fake crash, ×52'd-- 6. leg_multiplier + take_rate as params -> the ×2 was buried; it doubles the headline-- 7. Sanity bounds on decoded amounts -> a bad byte-offset decode = a $10^24 week-- 8. Solana branch stubbed, ready to switch on-- ================================================================================WITH params AS (SELECT2.0 AS leg_multiplier, -- ⚠️ VALIDATE. See note below.0.01 AS take_rate, -- 1% protocol fee1e9 AS max_sane_order -- reject any single order > $1B (bad decode guard)),-- ---------------------------------------------------------------------------------- Blacklist. NOT IN + a single NULL = empty result set. Use NOT EXISTS.-- --------------------------------------------------------------------------------blacklisted AS (SELECT DISTINCT user AS walletFROM p2p_me_base.reputationmanager_evt_userblacklistedWHERE user IS NOT NULL),-- ---------------------------------------------------------------------------------- Every OrderCompleted source, normalized to a common shape.-- src_rank = dedup priority (lower wins): decoded tables beat raw logs, because-- decoded tables can't drift when the event struct changes.-- --------------------------------------------------------------------------------raw_events AS (-- Base: OrderProcessor (decoded)SELECT 'base' AS chain, 1 AS src_rank, 'orderprocessor' AS src,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, -- TODO verify field nameTRY_CAST(JSON_QUERY("_order", 'strict $.amount') AS DOUBLE) AS amount_rawFROM p2p_me_base.OrderProcessor_evt_OrderCompletedUNION ALL-- Base: OrderFlowFacet (decoded)SELECT 'base', 1, 'orderflowfacet',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_QUERY("_order", 'strict $.amount') AS DOUBLE)FROM p2p_me_base.OrderFlowFacet_evt_OrderCompletedUNION ALL-- Base: P2PConfigFacet (decoded) <<< ADDED. Your Query 1 uses this facet for-- `completed`; Query 2 did not. That is an entire facet era of missing volume.SELECT 'base', 1, 'p2pconfigfacet',evt_tx_hash, evt_index, evt_block_time,from_hex(trim('"' FROM TRY_CAST(JSON_EXTRACT_SCALAR("_order", '$.user') AS VARCHAR))),