tomingtop 10 trader with most profit copy
    Updated 2024-07-22
    -- forked from saber-jl / top 10 trader with most profit @ https://flipsidecrypto.xyz/saber-jl/q/Ha01iUHBkDYH/top-10-trader-with-most-profit

    with buyers as (
    select
    ORIGIN_FROM_ADDRESS as buyer,
    AMOUNT_OUT as Buy_Volume,
    AMOUNT_IN as Buy_Cost,
    from ethereum.defi.ez_dex_swaps
    where TOKEN_OUT = '0x38e382f74dfb84608f3c1f10187f6bef5951de93'
    and SYMBOL_IN = 'WETH'
    and EVENT_NAME = 'Swap'
    and BLOCK_NUMBER < 19020778


    ),

    sellers as (
    select
    ORIGIN_FROM_ADDRESS as seller,
    AMOUNT_IN as Sell_Volume,
    AMOUNT_OUT as Sell_Income
    from ethereum.defi.ez_dex_swaps
    where TOKEN_IN = '0x38e382f74dfb84608f3c1f10187f6bef5951de93'
    and SYMBOL_OUT = 'WETH'
    and EVENT_NAME = 'Swap'
    and BLOCK_NUMBER < 19020778
    )

    SELECT
    buyer,
    sum(Sell_Income) - sum(Buy_Cost) as trade_Profit,
    (sum(Sell_Income) - sum(Buy_Cost))/sum(Buy_Cost) as profit_rate,
    sum(Sell_Volume)/sum(Buy_Volume) as selled_rate
    from buyers b left outer join sellers s on buyer = seller
    group by 1
    having trade_Profit > 0
    QueryRunArchived: QueryRun has been archived