near-toll-audit / pipeline/sql/04_cohort_matrix.sql · raw
-- Monthly signer cohorts over the full chain history. A signer's cohort is the first month it signed a transaction.-- `kind` separates app-managed account namespaces from self-custody style accounts.WITH m AS ( SELECT DISTINCT DATE_TRUNC(block_date, MONTH) AS mth, signer_account_id AS s FROM `bigquery-public-data.crypto_near_mainnet_us.transactions` WHERE block_date >= '2020-07-01'), f AS ( SELECT s, MIN(mth) AS first_m FROM m GROUP BY s)SELECT f.first_m, m.mth, CASE WHEN m.s LIKE '%.tg' THEN 'tg' WHEN m.s LIKE '%.sweat' OR m.s LIKE '%.u.sweat' THEN 'sweat' WHEN m.s LIKE '%kaiching' THEN 'kaiching' WHEN REGEXP_CONTAINS(m.s, r'^[0-9a-f]{64}$') THEN 'implicit' WHEN REGEXP_CONTAINS(m.s, r'^0x[0-9a-f]{40}$') THEN 'evm_implicit' WHEN m.s LIKE '%.near' THEN 'named_near' ELSE 'other' END AS kind, COUNT(*) AS signersFROM m JOIN f USING (s)GROUP BY 1, 2, 3ORDER BY 1, 2, 3