Kruys-Collinsearly-blush
    Updated 2025-01-22
    WITH NET_AMOUNT AS (
    SELECT
    sender_id,
    SUM(CASE WHEN actions in ('deposit_to_reserve', 'deposit') THEN amount_usd ELSE 0 END) AS total_supplied_usd,
    SUM(CASE WHEN actions in ('withdraw_succeeded') THEN amount_usd ELSE 0 END) AS total_withdrawn_usd
    FROM
    near.defi.ez_lending
    GROUP BY
    1
    ),
    SUPPLIERS AS (
    SELECT
    sender_id,
    actions,
    COUNT(DISTINCT tx_hash) AS n_transactions,
    SUM(CASE WHEN actions in ('deposit_to_reserve', 'deposit') THEN amount_usd ELSE 0 END) AS total_supplied_usd
    FROM
    near.defi.ez_lending
    WHERE
    actions in ('deposit_to_reserve', 'deposit')
    GROUP BY
    1,2
    ),
    WITHDRAWERS AS (
    SELECT
    sender_id,
    actions,
    COUNT(DISTINCT tx_hash) AS n_transactions,
    SUM(CASE WHEN actions in ('withdraw_succeeded') THEN amount_usd ELSE 0 END) AS total_withdrawn_usd
    FROM
    near.defi.ez_lending
    WHERE
    actions in ('withdraw_succeeded')
    GROUP BY
    1,2
    )
    QueryRunArchived: QueryRun has been archived