freemartianOvertime Profit Finder
    Updated 2022-08-24
    with markets as (
    select
    regexp_substr_all(SUBSTR(data, 11, len(data)), '.{64}') AS segmented_data,
    concat('0x', substr(segmented_data[0], 17, 40)) as game,
    ethereum.public.udf_hex_to_int(substr(segmented_data[17], 1, 56) :: STRING) :: FLOAT as sport_tag
    from optimism.core.fact_event_logs
    where origin_function_signature = '0xac2c957c'
    and origin_to_address = '0x2b91c14ce9aa828ed124d12541452a017d8a2148'
    and topics[0] = '0x889e2060e46779287c2fcbf489c195ef20f5b44a74e3dcb58d491ae073c1370f'
    ),
    bet_action as (
    select
    distinct tx_hash as tx,
    from_address as bettor,
    regexp_substr_all(SUBSTR(input_data, 11, len(input_data)), '.{64}') AS segmented_data,
    concat('0x', substr(segmented_data[0], 25, 40)) as game,
    ethereum.public.udf_hex_to_int(segmented_data[3] :: STRING) :: FLOAT as paid_bet
    from optimism.core.fact_transactions
    where tx_hash in (
    select tx_hash
    from optimism.core.fact_token_transfers
    where to_address = '0x170a5714112daeff20e798b6e92e25b86ea603c1'
    and from_address != '0x0000000000000000000000000000000000000000'
    and from_address != '0x061b87122ed14b9526a813209c8a59a633257bab'
    and origin_function_signature in ('0x6cc5a6ff', '0x8875eb84')
    and block_timestamp >= CURRENT_DATE - 14)
    group by 1, 2, 3, 4, 5
    ),
    currency as (
    select tx_hash, contract_address, decimals
    from optimism.core.fact_token_transfers t
    inner join optimism.core.dim_contracts c on c.address = t.contract_address
    where tx_hash in (select tx from bet_action)
    ),
    Run a query to Download Data