mohammadh5) Cryptopunk Sales and Traders
    Updated 2022-08-31
    with A as (select
    SELLER_ADDRESS as seller,
    sum(PRICE_USD) as sell_usd_volume ,
    sum(PRICE) as sell_eth_volume
    from ethereum.core.ez_nft_sales
    where (PROJECT_NAME = 'cryptopunks' and NFT_ADDRESS = '0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb' or NFT_ADDRESS='0xb7f7f6c52f2e2fdb1963eab30438024864c313f6' and PROJECT_NAME='wrapped cryptopunks')
    and EVENT_TYPE = 'sale'
    and PRICE_USD > 0
    and BUYER_ADDRESS !='0x0000000000000000000000000000000000000000'
    and (CURRENCY_ADDRESS ='ETH' or CURRENCY_ADDRESS ='WETH')
    group by seller),

    B as (select
    BUYER_ADDRESS as buyer,
    sum(PRICE_USD) as buy_usd_volume,
    sum(PRICE) as buy_eth_volume
    from ethereum.core.ez_nft_sales
    where (PROJECT_NAME = 'cryptopunks' and NFT_ADDRESS = '0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb' or NFT_ADDRESS='0xb7f7f6c52f2e2fdb1963eab30438024864c313f6' and PROJECT_NAME='wrapped cryptopunks')
    and EVENT_TYPE = 'sale'
    and PRICE_USD > 0
    and BUYER_ADDRESS !='0x0000000000000000000000000000000000000000'
    and (CURRENCY_ADDRESS ='ETH' or CURRENCY_ADDRESS ='WETH')
    group by buyer),

    C as (select
    buyer as wallets,
    sum(sell_usd_volume - buy_usd_volume) as usd_profit
    from A join B on A.seller=B.buyer
    group by wallets
    order by usd_profit desc
    limit 10),

    D as (select
    date_trunc('week' , block_timestamp) as block_week,
    count(distinct TX_HASH) as buy_tx_count,
    BUYER_ADDRESS,
    Run a query to Download Data