mlhUntitled Query
    Updated 2022-08-25
    with outflow as (SELECT CONTRACT_ADDRESS,
    event_inputs:account as user,
    event_inputs:value /pow(10,18) as outflow
    FROM optimism.core.fact_event_logs
    WHERE ORIGIN_FUNCTION_SIGNATURE = '0x85149258'
    AND EVENT_NAME = 'OptionsExercised'
    )
    SELECT from_address as users,
    loss
    FROM (SELECT from_address,
    bet_count,
    case WHEN outflow is NULL THEN -1 * inflow ELSE outflow - inflow END as loss
    FROM (SELECT tx_hash,
    ORIGIN_FROM_ADDRESS as address,
    case when CONTRACT_ADDRESS = '0x8c6f28f2f1a3c87f0f938b96d27520d9751ec8d9' then event_inputs:value /pow(10,18) --susd
    when CONTRACT_ADDRESS = lower('0x7F5c764cBc14f9669B88837ca1490cCa17c31607') then event_inputs:value /pow(10,6) --usdc
    when CONTRACT_ADDRESS = lower('0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1') then event_inputs:value /pow(10,18) --dai
    when CONTRACT_ADDRESS = lower('0x94b008aA00579c1307B0EF2c499aD98a8ce58e58') then event_inputs:value /pow(10,6) --usdt
    else event_inputs:value /pow(10,18) end as inflow
    FROM optimism.core.fact_event_logs
    WHERE ORIGIN_FUNCTION_SIGNATURE in ('0x8875eb84','0x6cc5a6ff','0x9f916c9f')
    and event_inputs:to = '0x170a5714112daeff20e798b6e92e25b86ea603c1'
    and event_inputs:from = ORIGIN_FROM_ADDRESS
    and event_name = 'Transfer'
    and event_index in ('0','1')
    and BLOCK_TIMESTAMP::date >= CURRENT_DATE - 14
    )
    LEFT OUTER join outflow on to_address = from_address
    HAVING NOT loss is NULL
    AND NOT from_address IS NULL
    )
    group by 1, 2
    order by 2 desc
    limit 5
    Run a query to Download Data