SalehOvertime Markets - Profitable Traders-Game
    Updated 2022-08-25
    with contracts as (
    select
    tx_hash
    ,data
    ,concat('0x', substring(data,27,40)) as contract
    ,substring(data, 3+13*64, 64)
    ,regexp_replace(hex_decode_string(substring(data, 3+13*64, 64)), '[^a-z A-Z]') as Home
    ,regexp_replace(hex_decode_string(substring(data, 3+15*64, 64)), '[^a-z A-Z]') as Away
    ,ethereum.public.udf_hex_to_int(concat('0x',SUBSTR(regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}')[17], 25, 40))) AS sport_code
    ,case
    when sport_code = 9001 then 'NCAA - American Footbal '
    when sport_code = 9002 then 'NFL - American Footbal '
    when sport_code = 9003 then 'MLB - Baseball '
    when sport_code = 9004 then 'NBA - Basketball'
    when sport_code = 9005 then 'NCAA - Basketball'
    when sport_code = 9006 then 'NHL - Hockey '
    when sport_code = 9007 then 'MMA'
    when sport_code = 9008 then 'WNBA'
    when sport_code = 9010 then 'MLS - Soccer'
    when sport_code = 9011 then 'EPL - Soccer'
    when sport_code = 9012 then 'Ligue 1 - Soccer'
    when sport_code = 9013 then 'Bundesliga - Soccer'
    when sport_code = 9014 then 'La Liga - Soccer'
    when sport_code = 9015 then 'Serie A - Soccer'
    when sport_code = 9016 then 'UEFA Champions League - Soccer'
    else null
    end as sport_name
    from optimism.core.fact_event_logs
    where topics[0]::string = '0x889e2060e46779287c2fcbf489c195ef20f5b44a74e3dcb58d491ae073c1370f'
    and contract_address = '0x2b91c14ce9aa828ed124d12541452a017d8a2148'
    and block_timestamp::date>=CURRENT_DATE-14
    and TX_STATUS='SUCCESS'
    and EVENT_REMOVED=false
    )
    ,lst_bets as (
    select
    Run a query to Download Data