Query editor
/* ============================================================================QUERY: Infinex - Monthly Active User Churn (Hybrid Model)AUTHOR: Antoine | ContangoACTIVE USER DEFINITION:A user is "Active" in a given month if they meet AT LEAST ONE of:1. Has a cumulative USDC balance >= {{min_balance}} (passive holder)2. Triggered the Gelato gasless relay this month (any swap, perp, action, etc.)3. Emitted any event from their account contract this month (deposit, withdraw, etc.)DESIGN NOTES:- Forward-Shifted (LEAD): Churn is plotted on the last month a user was active.- Zero-Floor Calendar: Forces empty months to render as 0, not NULL.- Calendar starts: 2024-03-01 (AccountFactory deployment).Parameters:- {{min_balance}}: Minimum USDC value to consider a user active (e.g. 10).============================================================================ */WITH inputs AS (SELECT CAST({{min_balance}} AS DOUBLE) AS threshold),-- =====================================================================-- 1. INFINEX USER UNIVERSE (via AccountFactory)-- =====================================================================infinex_users AS (SELECTaccount AS user_address,DATE_TRUNC('month', MIN(evt_block_time)) AS creation_monthFROM infinex_multichain.accountfactory_evt_accountcreatedGROUP BY 1),-- =====================================================================-- 2. USDC BALANCE TRACKING (Base, Arbitrum, Optimism)-- =====================================================================raw_transfers AS (SELECT DATE_TRUNC('month', evt_block_time) AS month_bucket, "to" AS user_address, CAST(value AS DOUBLE)/1e6 AS amountFROM erc20_base.evt_Transfer WHERE contract_address = 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913UNION ALLSELECT DATE_TRUNC('month', evt_block_time) AS month_bucket, "from" AS user_address, -(CAST(value AS DOUBLE)/1e6) AS amountFROM erc20_base.evt_Transfer WHERE contract_address = 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913UNION ALLSELECT DATE_TRUNC('month', evt_block_time) AS month_bucket, "to" AS user_address, CAST(value AS DOUBLE)/1e6 AS amountFROM erc20_arbitrum.evt_Transfer WHERE contract_address = 0xaf88d065e77c8cC2239327C5EDb3A432268e5831UNION ALLSELECT DATE_TRUNC('month', evt_block_time) AS month_bucket, "from" AS user_address, -(CAST(value AS DOUBLE)/1e6) AS amountFROM erc20_arbitrum.evt_Transfer WHERE contract_address = 0xaf88d065e77c8cC2239327C5EDb3A432268e5831UNION ALLSELECT DATE_TRUNC('month', evt_block_time) AS month_bucket, "to" AS user_address, CAST(value AS DOUBLE)/1e6 AS amountFROM erc20_optimism.evt_Transfer WHERE contract_address = 0x0b2c639c533813f4aa9d7837caf992c96bd58442UNION ALLSELECT DATE_TRUNC('month', evt_block_time) AS month_bucket, "from" AS user_address, -(CAST(value AS DOUBLE)/1e6) AS amountFROM erc20_optimism.evt_Transfer WHERE contract_address = 0x0b2c639c533813f4aa9d7837caf992c96bd58442),