0xHaM-dBorrow & Repay
    Updated 2023-07-14
    with tx as (
    select
    BLOCK_TIMESTAMP::date as date,
    'Borrow' as status,
    tx_hash,
    ETH_TO_ADDRESS,
    amount,
    amount_usd
    from ethereum.core.ez_eth_transfers
    where ETH_FROM_ADDRESS = lower('0x3b968d2d299b895a5fcf3bba7a64ad0f566e6f88') -- 0x35611f7e batchBorrowETH
    AND ORIGIN_FUNCTION_SIGNATURE in ('0x35611f7e', '0x9c748eff', '0xd0554fc6', '0xf8a3310b')

    UNION ALL

    select
    BLOCK_TIMESTAMP::date as date,
    'Repay' as status,
    tx_hash,
    ETH_FROM_ADDRESS,
    amount,
    amount_usd
    from ethereum.core.ez_eth_transfers
    where ETH_TO_ADDRESS = lower('0x3b968d2d299b895a5fcf3bba7a64ad0f566e6f88')
    AND ORIGIN_FUNCTION_SIGNATURE in ('0x89cbe656', '0x7f185c1e', '0x5a953999', '0x30727869')
    )
    SELECT
    date,
    status,
    count(DISTINCT tx_hash) as tx_cnt,
    count(DISTINCT ETH_TO_ADDRESS) as users,
    sum(amount) as eth_amt,
    sum(amount_usd) as usd_amt,
    avg(amount) as avg_eth_amt,
    median(amount) as med_eth_amt,
    sum(tx_cnt) over (partition by status order by date) as cum_tx_cnt,
    sum(users) over (partition by status order by date) as cum_users,
    Run a query to Download Data