Query editor
WITH multisig_list AS (-- Get the list of distinct multisigsSELECT DISTINCT multisigFROM autonolas_gnosis.StakingProxy_Quickstart_Beta_Expert_evt_ServiceStakedWHEREcontract_address = 0xeF44Fb0842DDeF59D37f85D61A1eF492bbA6135dOR contract_address = 0x1c2F82413666d2a3fD8bC337b0268e62dDF67434OR contract_address = 0xDaF34eC46298b53a3d24CBCb431E84eBd23927dA),first_activity AS (-- Get the first transaction date for each multisig and assign them to a cohort weekSELECTtxs."to" AS multisig,MIN(txs.block_time) AS first_activity_date,DATE_TRUNC('week', MIN(txs.block_time)) AS cohort_week -- Assign to cohort based on the first week of activityFROMgnosis.transactions AS txsWHEREtxs."to" IN (SELECT multisig FROM multisig_list)GROUP BYtxs."to"),multisig_transactions AS (-- Get the activity for each multisig within their first 7 daysSELECTtxs."to" AS multisig,DATE_TRUNC('day', txs.block_time) AS active_day,fa.cohort_weekFROMgnosis.transactions AS txsINNER JOINfirst_activity fa ON txs."to" = fa.multisigWHEREtxs.block_time BETWEEN fa.first_activity_dateAND fa.first_activity_date + INTERVAL '7' day -- First 7 days of activity)-- Calculate the percentage of addresses active for at least 5 days in their first 7 days per cohortSELECTcohort_week, -- Cohort week based on first activityCOUNT(DISTINCT multisig) AS total_multisigs_in_cohort, -- Total multisigs in cohortCOUNT(DISTINCT CASE WHEN active_days >= 5 THEN multisig END) AS active_multisigs, -- Multisigs active for 5 or more days in the first 7 days(COUNT(DISTINCT CASE WHEN active_days >= 5 THEN multisig END) * 100.0 / COUNT(DISTINCT multisig)) AS percentage_active, -- Percentage of multisigs active for 5+ days-- Trailing 4-week average of the percentage activeAVG(COUNT(DISTINCT CASE WHEN active_days >= 5 THEN multisig END) * 100.0 / COUNT(DISTINCT multisig))OVER (ORDER BY cohort_week ROWS BETWEEN 3 PRECEDING AND CURRENT ROW) AS trailing_avg_4_weeks -- Trailing average over last 4 weeks-- Latest retention percentage across all cohortsFROM (-- Subquery to count the number of distinct active days for each multisig in their first 7 daysSELECTmultisig,cohort_week,COUNT(DISTINCT active_day) AS active_days -- Count of distinct active days in the first 7 daysFROMmultisig_transactionsGROUP BYmultisig, cohort_week) AS cohort_activityWHERE