Switchboardmonthly_function_routine_request_init_log_messages
    Updated 2023-12-06
    -- next up, work on functionInit, routine/requestInit per authority and leases

    -- functionVerify is called by our sbatt program
    -- which then also calls the ixn in user program in the same txn
    -- so does routineVerify and requestVerify only trigger initial execution call?

    WITH event AS (
    SELECT DISTINCT tx_id AS e_id, instruction
    FROM solana.core.fact_events
    WHERE block_timestamp BETWEEN '2023-05-01' AND '2023-12-01'
    AND program_id = 'sbattyXrzedoNATfc4L31wC9Mhxsi1BmFhTiN8gDshx'
    ),

    tx AS (
    SELECT
    DISTINCT tx_id AS t_id,
    value AS log
    FROM solana.core.fact_transactions
    INNER JOIN lateral flatten (input => log_messages)
    WHERE block_timestamp BETWEEN '2023-05-01' AND '2023-12-01'
    AND succeeded
    ),

    fn AS (
    SELECT
    COUNT(DISTINCT t_id) AS fn_count,
    instruction:accounts[2] AS fn_authority
    FROM
    tx
    JOIN event ON tx.t_id = event.e_id
    WHERE
    log like 'Program log: Instruction: FunctionInit'
    GROUP BY 2
    ),

    rt AS (
    Run a query to Download Data