HessishCopy of Top Terra active wallets by rating
    Updated 2023-01-31
    with actives as (
    select date_trunc ('week',block_timestamp) as date,
    tx_sender as wallet,
    count (distinct block_timestamp::date) as days
    from terra.core.fact_transactions
    WHERE block_timestamp::date >= CURRENT_DATE - 90
    and tx_sender not in (select DISTINCT address from terra.core.dim_address_labels)
    group by 1,2
    having days >= 3),

    nb as (select DISTINCT PURCHASER as w, count(TX_ID) as t
    from terra.core.fact_nft_sales
    where block_timestamp::date >= CURRENT_DATE - 90 and
    PURCHASER in (SELECT DISTINCT wallet from actives)
    group by 1 ),

    ns as (select DISTINCT seller as ws , count(TX_ID) as ts
    from terra.core.fact_nft_sales
    where block_timestamp::date >= CURRENT_DATE - 90 and
    seller in (SELECT DISTINCT wallet from actives)
    group by 1 ),


    base as
    (select DISTINCT TRADER as wallet, count(TX_ID) as txs, 'Swapping' as type
    from terra.core.ez_swaps
    where block_timestamp::date >= CURRENT_DATE - 90 and
    trader in (SELECT DISTINCT wallet from actives)
    group by 1,3

    union

    select DISTINCT DELEGATOR_ADDRESS as wallet, count(TX_ID) as txs, 'Staking actions' as type
    from terra.core.ez_staking
    where block_timestamp::date >= CURRENT_DATE - 90 and