MLDZMNffuser3
    Updated 2023-06-10
    with t1 as (select
    distinct signers[0] as users

    from solana.core.fact_transactions s
    left join solana.core.fact_transfers a on s.tx_id=a.tx_id

    where array_contains('Program log: Instruction: CompleteSwap'::variant, log_messages)
    and INSTRUCTIONS[0]:programId= '8guzmt92HbM7yQ69UJg564hRRX6N4nCdxWE5L6ENrA8P'
    and MINT in ('So11111111111111111111111111111111111111112')
    and (INNER_INSTRUCTIONS[1]:instructions[0]:parsed:info:destination = tx_to or
    tx_from = INNER_INSTRUCTIONS[1]:instructions[0]:parsed:info:destination )
    and s.BLOCK_TIMESTAMP>=current_date-{{Days_back}}
    and SUCCEEDED='TRUE'
    ),

    t2 as(
    select
    SIGNERS[0] as users,
    Count(distinct tx_id) as no_txn,
    count (Distinct block_timestamp::Date) as active_days,
    min (block_timestamp) as first_transaction,
    datediff(day,first_transaction,CURRENT_DATE) as wallet_age
    from solana.core.fact_events
    where SUCCEEDED='TRUE'
    and SIGNERS[0] in (select users from t1)
    and BLOCK_TIMESTAMP>=current_date-180
    group by 1
    )

    select
    case
    when wallet_age<=20 then 'under 20 Days'
    when wallet_age > 20 and wallet_age <= 50 then '20- 50 Days'
    when wallet_age > 50 and wallet_age <= 100 then '50- 100 Days'
    when wallet_age > 100 then 'over 100 Days'
    end as gp,
    Run a query to Download Data