Mity net borrow dai
    Updated 2023-04-13
    with tab1 as (
    select BLOCK_TIMESTAMP::date as date,sum(EVENT_INPUTS:value)/1e18 as borrow_amount
    from optimism.core.fact_event_logs
    where ORIGIN_TO_ADDRESS='0x794a61358d6845594f94dc1db02a252b5b4814ad'
    and ORIGIN_FUNCTION_SIGNATURE='0xd5eed868'
    and EVENT_NAME='Transfer'
    and EVENT_INPUTS:from<>'0x0000000000000000000000000000000000000000'
    and CONTRACT_ADDRESS='0xda10009cbd5d07dd0cecc66161fc93d7c9000da1'
    and TX_STATUS='SUCCESS'
    and date >='2022-08-01'
    group by 1),
    tab2 as (
    select BLOCK_TIMESTAMP::date as date,-sum(EVENT_INPUTS:value)/1e18 as repay_amount
    from optimism.core.fact_event_logs
    where ORIGIN_TO_ADDRESS='0x794a61358d6845594f94dc1db02a252b5b4814ad'
    and ORIGIN_FUNCTION_SIGNATURE='0x563dd613'
    and EVENT_NAME='Transfer'
    and EVENT_INPUTS:to<>'0x0000000000000000000000000000000000000000'
    and CONTRACT_ADDRESS='0xda10009cbd5d07dd0cecc66161fc93d7c9000da1'
    and TX_STATUS='SUCCESS'
    and date >='2022-08-01'
    group by 1)
    select tab2.date,borrow_amount,repay_amount,borrow_amount+repay_amount as daily_net
    ,sum (daily_net)over(order by tab2.date asc)as net_borrow
    from tab1
    full outer join tab2
    on tab1.date=tab2.date
    where tab2.date is not null


    Run a query to Download Data