freemartianInteractive Daily PNL
    Updated 2023-05-16


    with source AS
    (SELECT
    block_timestamp,
    tx_hash,
    data,
    regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
    ethereum.public.udf_hex_to_int(segmented_data [4] :: STRING)/pow(10,8) AS fee,
    CONCAT('0x', substr(topics[2] :: STRING, 27, 42)) AS user_address,
    ethereum.public.udf_hex_to_int(segmented_data [5] :: STRING)/pow(10,8) AS PNL,
    CASE
    when substr(segmented_data [5] :: STRING, 1, 1) IN ('8' , '9' , 'a' , 'b', 'c', 'd', 'e', 'f')
    then (ethereum.public.udf_hex_to_int(
    translate(segmented_data [5] :: STRING,'fedcba9876543210','0123456789abcdef')
    ) / pow(10,8)) * -1
    else ethereum.public.udf_hex_to_int(segmented_data [5] :: STRING)/pow(10,8)
    end AS adjusted_PNL
    FROM optimism.core.fact_event_logs
    WHERE topics[0] = '0x980658f6b65b51ce7d353bc2f9110e33617a69ab8dd85ed76e70546542ebea25')

    SELECT
    date_trunc('day', block_timestamp::date) AS time,
    sum(adjusted_PNL) AS Traders_NET_PNL,
    sum(Traders_NET_PNL) over (ORDER BY time) AS cumulative_PNL
    FROM source
    WHERE user_address = '{{User_Address}}'
    GROUP BY time




    Run a query to Download Data