Updated 2025-03-24
    WITH transfers AS (
    SELECT
    TRUNC(e.block_timestamp,'day') as date,
    CASE WHEN e.origin_function_signature in ('0x6e553f65','0x06bf0dd3') THEN 'Deposit' ELSE 'Withdraw' END as type,
    COUNT(DISTINCT e.tx_hash) as actions,
    COUNT(DISTINCT CASE WHEN e.origin_function_signature='0x6e553f65' THEN decoded_log:to ELSE decoded_log:from END) as active_users,
    SUM(decoded_log:value/1e6) as amount
    FROM avalanche.core.ez_decoded_event_logs e
    WHERE e.contract_address = lower('0xBFdEf5e389bB403426337081eCD1D05bC5193203')
    AND e.origin_function_signature IN ('0x6e553f65','0xde0c7fdf','0x06bf0dd3')
    AND e.event_name = 'Transfer'
    GROUP BY 1, 2
    ),
    daily_prices AS (
    SELECT
    TRUNC(hour, 'day') as date,
    AVG(price) as avg_daily_price
    FROM avalanche.price.ez_prices_hourly
    WHERE token_address = lower('0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E')
    GROUP BY 1
    ),
    daily_net AS (
    SELECT
    t.date,
    SUM(CASE WHEN type = 'Deposit' THEN amount ELSE -amount END) as net_amount_usdc,
    SUM(CASE WHEN type = 'Deposit' THEN amount * p.avg_daily_price ELSE -amount * p.avg_daily_price END) as net_amount_usd
    FROM transfers t
    LEFT JOIN daily_prices p ON t.date = p.date
    GROUP BY 1
    )
    SELECT
    t.date,
    t.type,
    t.actions,
    SUM(t.actions) OVER (PARTITION BY t.type ORDER BY t.date) as total_actions,
    t.active_users,
    Last run: 23 days ago
    DATE
    TYPE
    ACTIONS
    TOTAL_ACTIONS
    ACTIVE_USERS
    AMOUNT_USDC
    TOTAL_AMOUNT_USDC
    AMOUNT_USD
    TOTAL_AMOUNT_USD
    DAILY_NET_AMOUNT_USDC
    RUNNING_BALANCE_USDC
    DAILY_NET_AMOUNT_USD
    RUNNING_BALANCE_USD
    1
    2025-03-07 00:00:00.000Deposit21221048856.7908092360030.073331048721.969009012359818.680700061048856.7908092371094.1751921048721.969009012370881.32578864
    2
    2025-03-06 00:00:00.000Withdraw3422.553.552.549664253.54963037511066.6519961322237.38438311065.1948868211322159.35677962
    3
    2025-03-06 00:00:00.000Deposit410211069.2019961311173.28252111067.7445510711311096.7116910511066.6519961322237.38438311065.1948868211322159.35677962
    4
    2025-03-04 00:00:00.000Deposit16194831.263711300104.08052594816.5253510981300028.9671399894831.263711300104.08039194816.5253510981300028.96700598
    5
    2025-02-24 00:00:00.000Deposit15177966.3528561205272.81681577960.1220449681205212.4417888877966.3528561205272.81668177960.1220449681205212.44165488
    6
    2025-02-17 00:00:00.000Deposit141259775.971461127306.463959259762.0950935241127252.31974391259775.971461127306.463825259762.0950935241127252.31960992
    7
    2025-02-10 00:00:00.000Deposit131867528.492633867530.492499867488.224852134867490.224650388867528.492633867530.492365867488.224852134867490.224516393
    8
    2025-02-05 00:00:00.000Withdraw111110.9999661250.9999661250.9998661.9997320.99983212951.999664259
    9
    2025-02-05 00:00:00.000Deposit2211.9998661.9998661.9997982551.9997982550.9998661.9997320.99983212951.999664259
    9
    1KB
    3s