HitmonleeCrypto2024-06-27 03:08 PM
    Updated 2024-06-28
    WITH
    -- Filtered swaps data for relevant address and conditions
    filtered_swaps AS (
    SELECT
    DATE_TRUNC('month', block_timestamp) AS month,
    swap_from_amount_usd,
    swapper,
    swap_program,
    tx_id
    FROM
    solana.defi.ez_dex_swaps
    WHERE
    (swapper = '{{Address}}' AND swap_program LIKE 'jupiter%')
    OR swapper ILIKE 'DCA%'
    OR (swapper ILIKE 'j1%' AND swap_program ILIKE '%jupiter%')
    ),
    -- Monthly trade volume
    monthly_trade_volume AS (
    SELECT
    month,
    SUM(swap_from_amount_usd) AS monthly_trade_total
    FROM
    filtered_swaps
    WHERE
    swapper = '{{Address}}' AND swap_program LIKE 'jupiter%'
    GROUP BY
    month
    ),
    -- Monthly DCA volume
    monthly_dca_volume AS (
    SELECT
    DATE_TRUNC('month', s.block_timestamp) AS month,
    SUM(s.swap_from_amount_usd) AS monthly_dca_total
    FROM
    solana.defi.ez_dex_swaps AS s
    INNER JOIN
    QueryRunArchived: QueryRun has been archived