winnie-fsNFT Leaderboard copy
    Updated 2023-03-16
    -- forked from 8a0744ba-ea48-4d79-95d4-1a47b59a6ea2

    -- forked from f44e4688-69a3-42e8-96f1-f051875ad3c4

    -- forked from 50a73190-8f3f-47ff-9f7b-e296c728362f

    ------------------------------------------------------------------
    -- Gather all wallets that have transacted in this collection
    ------------------------------------------------------------------
    with wallets as
    (
    select
    nft_to_address as wallet,
    max(block_timestamp) as last_trade
    from
    ethereum.core.ez_nft_transfers
    where nft_address = lower('{{Address}}')
    group by wallet
    ),
    ------------------------------------------------------------------
    -- Gather all wallets that currently hold an item in collection
    ------------------------------------------------------------------
    current_owners as
    (
    select
    nft_to_address as owner,
    tokenid
    from
    ethereum.core.ez_nft_transfers
    where nft_address = lower('{{Address}}')
    QUALIFY RANK() OVER (PARTITION BY tokenid ORDER BY block_number DESC, event_index DESC) = 1
    ),
    ------------------------------------------------------------------
    -- Calculate holdings per current holder
    ------------------------------------------------------------------
    holder_data as
    Run a query to Download Data