ramishoow(Overmarket top users by profit)
    Updated 2022-08-25
    --and t.BLOCK_TIMESTAMP::date>=CURRENT_DATE-14 and b.topics [0] = '0x889e2060e46779287c2fcbf489c195ef20f5b44a74e3dcb58d491ae073c1370f' and b.contract_address = '0x2b91c14ce9aa828ed124d12541452a017d8a2148'
    with tx as (select t.ORIGIN_FROM_ADDRESS user ,concat('0x', substr(b.DATA, 27, 40)) game, ethereum.public.udf_hex_to_int(concat('0x', SUBSTR(regexp_substr_all(SUBSTR(b.DATA, 3, len(b.DATA)), '.{64}') [17], 25, 40))) tags,
    concat(ltrim(rtrim(HEX_DECODE_STRING(substr(b.DATA, 3 + 13 * 64, 64)))) ,ltrim(rtrim(HEX_DECODE_STRING(substr(b.DATA, 3 + 15 * 64, 64))))) title, sum(raw_amount/pow(10,18)) amount from optimism.core.fact_token_transfers t
    right join optimism.core.fact_event_logs b on t.to_address = concat('0x', substr(b.DATA, 27, 40)) where t.ORIGIN_TO_ADDRESS='0x170a5714112daeff20e798b6e92e25b86ea603c1'
    and t.BLOCK_TIMESTAMP::date>=CURRENT_DATE-14 and b.topics [0] = '0x889e2060e46779287c2fcbf489c195ef20f5b44a74e3dcb58d491ae073c1370f' and b.contract_address = '0x2b91c14ce9aa828ed124d12541452a017d8a2148'
    and len(ethereum.public.udf_hex_to_int(concat('0x', SUBSTR(regexp_substr_all(SUBSTR(b.DATA, 3, len(b.DATA)), '.{64}') [17], 25, 40)))) = 4
    group by 1, 2, 3, 4), tx1 as (select EVENT_INPUTS:account user,ORIGIN_TO_ADDRESS game,sum(EVENT_INPUTS:value/pow(10,18)) amount
    from optimism.core.fact_event_logs where BLOCK_TIMESTAMP::date>=CURRENT_DATE-14 and EVENT_NAME='Burned' and ORIGIN_FUNCTION_SIGNATURE = '0x85149258' group by 1,2),tx2 as( select a.user,b.title,b.tags,sum(a.amount-b.amount) amount
    from tx1 a join tx b on a.user = b.user and a.game = b.game where a.amount- b.amount>0 group by 1,2,3 order by 4 desc limit 5)
    select cast(user as varchar(100)) user,title,case tags
    when 9001 then 'NCAA - American Footbal ' when 9002 then 'NFL - American Footbal ' when 9003 then 'MLB - Baseball ' when 9004 then 'NBA - Basketball' when 9005 then 'NCAA - Basketball'
    when 9006 then 'NHL - Hockey ' when 9007 then 'UFC MMA' when 9008 then 'WNBA' when 9010 then 'MLS - Soccer' when 9011 then 'EPL - Soccer' when 9012 then 'Ligue 1 - Soccer'
    when 9013 then 'Bundesliga - Soccer' when 9014 then 'La Liga - Soccer' when 9015 then 'Serie A - Soccer' when 9016 then 'UEFA Champions League - Soccer' end sport,amount
    from tx2 order by 2 desc
    --(Overmarket top users by profit)

    Run a query to Download Data