BlockTrackeractive vs new contracts
    Updated 2025-04-06
    -- forked from active vs new contracts @ https://flipsidecrypto.xyz/studio/queries/6394b0dc-84a9-428a-ba2d-bd0a38c06a8f

    with contract_list as (
    select
    distinct to_address as address
    from swell.core.fact_traces
    where type ilike '%CREATE%'
    and TX_SUCCEEDED
    and input <> '0x'
    and to_address is not null
    and ORIGIN_FUNCTION_SIGNATURE <> '0x'
    )
    ,
    total_new_contract as (
    select
    date_trunc('{{granularity}}', first_tx) as date,
    count(distinct address) as new_contract
    from (
    select
    to_address as address,
    min(block_timestamp) as first_tx
    from swell.core.fact_transactions
    where 1 = 1
    and to_address IN (select address from contract_list)
    group by 1
    )
    group by 1
    )
    , total_active_contract as (
    select
    date_trunc('{{granularity}}', block_timestamp) as date,
    count(distinct to_address) as active_contract
    from swell.core.fact_transactions
    where 1=1
    and to_address IN (select address from contract_list)
    group by 1