maymoth55safe-purple
    Updated 2025-04-11
    with wbtc_price_hourly as (
    select
    hour,
    price
    from ethereum.price.ez_prices_hourly
    where SYMBOL = 'WBTC' and hour::date >= '2025-03-01'
    ),

    trove_openings as (
    select
    BLOCK_TIMESTAMP,
    tx_hash,
    FROM_ADDRESS as borrower_address,
    value as collateral_wbtc,
    value * price as collateral_usd,
    regexp_substr_all(SUBSTR(INPUT, 11, len(INPUT)), '.{64}') as segmented_input,
    ethereum.public.udf_hex_to_int(segmented_input[1])::int / 1e18 as borrowed_musd
    from mezo.testnet.fact_traces
    join wbtc_price_hourly on trunc(BLOCK_TIMESTAMP, 'hour') = hour
    where
    TO_ADDRESS = '0x20faea18b6a1d0fcdbccfffe3d164314744baf30'
    and left(input, 10) ilike '0x8f09162b'
    and tx_succeeded = 'True'
    ),

    trove_adjustments as (
    select
    BLOCK_TIMESTAMP,
    tx_hash,
    FROM_ADDRESS as borrower_address,
    value as collateral_wbtc,
    value * price as collateral_usd,
    regexp_substr_all(SUBSTR(INPUT, 11, len(INPUT)), '.{64}') as segmented_input,
    ethereum.public.udf_hex_to_int(segmented_input[1])::int / 1e18 as total_debt_after,
    ethereum.public.udf_hex_to_int(segmented_input[2])::int / 1e18 as collateral_change,
    ethereum.public.udf_hex_to_int(segmented_input[3])::int / 1e18 as musd_debt_increase