with data_ as(
select *
from ethereum.core.ez_nft_sales
where PROJECT_NAME = 'cryptopunks' AND EVENT_TYPE ='sale' and ORIGIN_FUNCTION_SIGNATURE ='0x8264fe98' and NFT_ADDRESS='0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb'
),
input_ as (
select SELLER_ADDRESS,TOKENID,PRICE as sell
from data_
),
output_ as (
select BUYER_ADDRESS,TOKENID,PRICE as buy
from data_
),
profits as (
select SELLER_ADDRESS ,(sell-buy) as profit
from input_ join output_ on input_.TOKENID= output_.TOKENID and input_.SELLER_ADDRESS= output_.BUYER_ADDRESS
)
select sum (profit) as total_profit___ETH___,SELLER_ADDRESS as user_wallet
from profits
group by 2
order by 1 desc
limit 10