near-toll-audit / pipeline/sql/05_signer_tiers_monthly.sql · raw
-- Monthly activity by signer, with concentration and three adjusted activity tiers (definitions in METHODS.md).WITH c AS (  SELECT DATE_TRUNC(block_date, MONTH) AS m, signer_account_id AS s,         COUNT(*) AS n, COUNT(DISTINCT block_date) AS days, COUNT(DISTINCT receiver_account_id) AS rcv,         COUNTIF(receiver_account_id = 'intents.near') AS n_intents  FROM `bigquery-public-data.crypto_near_mainnet_us.transactions`  WHERE block_date >= '2025-07-01'  GROUP BY 1, 2), r AS (  SELECT *, ROW_NUMBER() OVER (PARTITION BY m ORDER BY n DESC) AS rk,         CASE           WHEN s LIKE '%.tg' THEN 'tg'           WHEN s LIKE '%.sweat' OR s LIKE '%.u.sweat' OR s LIKE 'sweat%' THEN 'sweat'           WHEN s LIKE '%kaiching' THEN 'kaiching'           WHEN REGEXP_CONTAINS(s, r'^[0-9a-f]{64}$') THEN 'implicit'           WHEN REGEXP_CONTAINS(s, r'^0x[0-9a-f]{40}$') THEN 'evm_implicit'           WHEN s LIKE '%.near' THEN 'named_near'           ELSE 'other'         END AS kind  FROM c)SELECT m, kind,       COUNT(*) AS signers,       SUM(n) AS txs,       SUM(IF(rk = 1, n, 0)) AS tx_top1,       SUM(IF(rk <= 10, n, 0)) AS tx_top10,       SUM(IF(rk <= 100, n, 0)) AS tx_top100,       COUNTIF(days >= 2) AS signers_2d,       COUNTIF(days >= 3 AND rcv >= 2) AS signers_engaged,       COUNTIF(days >= 3 AND rcv >= 2 AND n <= 3000) AS signers_engaged_nobot,       SUM(n_intents) AS tx_intents,       COUNTIF(n_intents > 0) AS signers_intents,       COUNTIF(n_intents > 0 AND days >= 2) AS signers_intents_2dFROM r GROUP BY 1, 2 ORDER BY 1, 2