datavortexenchanting-coffee
    Updated 2025-02-08
    WITH Deposits AS (
    SELECT
    contract_name,
    contract_address,
    CASE
    WHEN decoded_log:wad IS NOT NULL
    THEN (decoded_log:wad::int)
    WHEN decoded_log:assets IS NOT NULL
    THEN CAST(PARSE_JSON(decoded_log:assets)[0] AS BIGINT)
    END AS deposit_amount
    FROM swell.core.ez_decoded_event_logs
    WHERE event_name IN ('Deposit', 'Deposits')
    ),

    Withdrawals AS (
    SELECT
    contract_name,
    contract_address,
    CASE
    WHEN decoded_log:wad IS NOT NULL
    THEN (decoded_log:wad::int)
    WHEN decoded_log:assets IS NOT NULL
    THEN CAST(PARSE_JSON(decoded_log:assets)[0] AS BIGINT)
    END AS withdrawal_amount
    FROM swell.core.ez_decoded_event_logs
    WHERE event_name IN ('Withdraw', 'Withdrawal')
    ),

    prices AS (
    SELECT
    LOWER(name) AS name,
    LOWER(symbol) AS symbol,
    price,
    decimals,
    ROW_NUMBER() OVER (PARTITION BY LOWER(symbol) ORDER BY hour DESC) AS rn
    FROM ethereum.price.ez_prices_hourly
    QueryRunArchived: QueryRun has been archived