MetaLightZeta Traders P&L
    Updated 2025-01-23
    WITH token_metadata AS (
    -- Get token decimals for normalization with fallback
    SELECT
    TOKEN_ADDRESS,
    COALESCE(DECIMALS, 6) AS DECIMALS
    FROM solana.price.ez_asset_metadata
    WHERE BLOCKCHAIN = 'solana'
    ),
    decoded_data AS (
    -- Extract relevant data from decoded events
    SELECT
    DATE_TRUNC('month', e.BLOCK_TIMESTAMP) AS month,
    JSON_EXTRACT_PATH_TEXT(e.DECODED_ARGS, 'asset') AS mint_address,
    JSON_EXTRACT_PATH_TEXT(e.DECODED_ARGS, 'side') AS side,
    TRY_CAST(JSON_EXTRACT_PATH_TEXT(e.DECODED_ARGS, 'price') AS FLOAT) AS price,
    TRY_CAST(JSON_EXTRACT_PATH_TEXT(e.DECODED_ARGS, 'size') AS FLOAT) AS size
    FROM solana.core.ez_events_decoded e
    WHERE e.PROGRAM_ID = 'ZETAxsqBRek56DhiGXrn75yj2NHU3aYUnxvHXpkf3aD'
    AND e.BLOCK_TIMESTAMP BETWEEN '2024-01-01' AND '2024-07-31'
    AND e.EVENT_TYPE = 'placePerpOrderV4'
    AND JSON_EXTRACT_PATH_TEXT(e.DECODED_ARGS, 'asset') IS NOT NULL
    AND JSON_EXTRACT_PATH_TEXT(e.DECODED_ARGS, 'price') IS NOT NULL
    AND JSON_EXTRACT_PATH_TEXT(e.DECODED_ARGS, 'size') IS NOT NULL
    ),
    monthly_pnl AS (
    -- Calculate P&L normalized by token decimals
    SELECT
    d.month,
    SUM(
    CASE
    WHEN d.side LIKE '%bid%' THEN
    -(COALESCE(d.price, 0) / POW(10, COALESCE(tm.DECIMALS, 6))) *
    (COALESCE(d.size, 0) / POW(10, COALESCE(tm.DECIMALS, 6)))
    WHEN d.side LIKE '%ask%' THEN
    (COALESCE(d.price, 0) / POW(10, COALESCE(tm.DECIMALS, 6))) *
    (COALESCE(d.size, 0) / POW(10, COALESCE(tm.DECIMALS, 6)))
    Last run: 2 months ago
    MONTH
    TOTAL_PNL
    1
    2024-01-01 00:00:00.000-100086381.074241
    2
    2024-02-01 00:00:00.000-179465674.028419
    3
    2024-03-01 00:00:00.000-260417448.157801
    4
    2024-04-01 00:00:00.000-10791198.2384696
    5
    2024-05-01 00:00:00.000-45414927.125916
    6
    2024-06-01 00:00:00.000-21570506.8394605
    7
    2024-07-01 00:00:00.0002988572.60699621
    7
    321B
    585s