Sandeshaverage days held
    Updated 2025-01-27
    -- Step 1: Identify wolves SBT holders
    WITH wolves_sbt_holders AS (
    SELECT
    DATE_TRUNC('week', block_timestamp) AS member_since,
    nft_to_address AS member,
    tokenId
    FROM polygon.nft.ez_nft_transfers
    WHERE block_number >= '44071817' -- Consider only transactions from this block onwards (SBT airdrop block)
    AND nft_address = LOWER('0x0433882c60ada1077a9f652ca2d1d36422c62c6c') -- wolvesDAO sbt token
    AND member != '0x0000000000000000000000000000000000000000' -- Ignore burn/mint address
    QUALIFY ROW_NUMBER() OVER (PARTITION BY tokenId ORDER BY block_number DESC) = 1 -- Keep only latest transfer per tokenId
    ),

    -- Step 2: Build the balance table
    balance_table AS (
    -- Incoming transactions
    WITH inn AS (
    SELECT
    block_timestamp,
    event_index,
    tx_hash,
    from_address AS counterparty,
    to_address AS user,
    amount
    FROM base.core.ez_token_transfers
    WHERE block_timestamp >= '2024-12-11 00:00:00.000'
    AND to_address IN (SELECT member FROM wolves_sbt_holders) -- Only include wolvesdao members
    AND contract_address = LOWER('0x919E43a2CcE006710090E64BDE9E01b38Fd7f32f') -- AIYP token
    ),

    -- Outgoing transactions (negative amount for debits)
    outt AS (
    SELECT
    block_timestamp,
    event_index,
    tx_hash,
    Last run: 3 months ago
    AVERAGE_DAYS_TOTAL
    AVERAGE_DAYS_SOLD
    1
    26.6685089.828283
    1
    22B
    17s