elsinaDistribution of utilization ratio
    Updated 2025-05-14
    WITH raw_tx AS (
    SELECT
    CASE
    WHEN origin_function_signature = '0x617ba037' THEN 'Supply'
    WHEN origin_function_signature = '0xa415bcad' THEN 'Borrow'
    WHEN origin_function_signature = '0x573ade81' THEN 'Repay'
    WHEN origin_function_signature = '0x69328dec' THEN 'Withdraw'
    END AS states,
    tx_hash,
    from_address,
    block_timestamp,
    regexp_substr_all(SUBSTR(input_data, 11), '.{64}') AS segmented_data
    FROM mezo.testnet.fact_transactions
    WHERE
    to_address = '0x9c55214751472788a06797d88f38af1e79eee018'
    AND tx_succeeded = 'True'
    AND origin_function_signature IN (
    '0x617ba037', -- Supply
    '0xa415bcad', -- Borrow
    '0x573ade81', -- Repay
    '0x69328dec' -- Withdraw
    )
    ),

    extracted AS (
    SELECT
    states,
    tx_hash,
    from_address,
    block_timestamp,
    '0x' || LOWER(RIGHT(segmented_data[0], 40)) AS token_address,
    segmented_data[1] AS raw_amount
    FROM raw_tx
    ),

    decoded AS (
    QueryRunArchived: QueryRun has been archived