near-toll-audit / pipeline/sql/14_destination_retention.sql · raw
-- Do Intents withdrawal destinations come back? Sampled to the first seven days of each month.-- For each month: destinations seen, and how many were seen in the same window one, three and six months later.WITH w AS ( SELECT DISTINCT DATE_TRUNC(block_date, MONTH) AS m, event_memo AS dest FROM `bigquery-public-data.crypto_near_mainnet_us.ft_events` WHERE (block_date BETWEEN '2025-10-01' AND '2025-10-07' OR block_date BETWEEN '2025-11-01' AND '2025-11-07' OR block_date BETWEEN '2025-12-01' AND '2025-12-07' OR block_date BETWEEN '2026-01-01' AND '2026-01-07' OR block_date BETWEEN '2026-02-01' AND '2026-02-07' OR block_date BETWEEN '2026-03-01' AND '2026-03-07' OR block_date BETWEEN '2026-04-01' AND '2026-04-07' OR block_date BETWEEN '2026-05-01' AND '2026-05-07' OR block_date BETWEEN '2026-06-01' AND '2026-06-07' OR block_date BETWEEN '2026-07-01' AND '2026-07-07' OR block_date BETWEEN '2026-08-01' AND '2026-08-07' OR block_date BETWEEN '2026-09-01' AND '2026-09-07' OR block_date BETWEEN '2026-10-01' AND '2026-10-07') AND contract_account_id IN ({{INTENTS_TOKENS}}) AND affected_account_id = 'intents.near' AND cause = 'ft_burn' AND event_memo LIKE 'WITHDRAW_TO:%'), f AS (SELECT dest, MIN(m) AS first_m FROM w GROUP BY dest)SELECT w.m, f.first_m, COUNT(*) AS destinationsFROM w JOIN f USING (dest)GROUP BY 1, 2ORDER BY 1, 2