mariyaNet borrow Luna from Mars protocol
    Updated 2022-04-09
    with dep as(
    SELECT --*
    date_trunc('day', block_timestamp) AS dt1,
    sum(EVENT_ATTRIBUTES:"0_amount")/1e6 as daily_borrow
    FROM terra.msg_events
    where EVENT_ATTRIBUTES:"0_action"='borrow'
    and EVENT_ATTRIBUTES:asset='uluna'
    and EVENT_ATTRIBUTES:"0_contract_address"='terra19dtgj9j5j7kyf3pmejqv8vzfpxtejaypgzkz5u'
    and tx_status = 'SUCCEEDED'
    group by 1),

    witd as(
    SELECT
    date_trunc('day', block_timestamp) AS dt2,
    sum(EVENT_ATTRIBUTES:"0_amount")/1e6 as daily_repay
    FROM terra.msg_events
    where EVENT_ATTRIBUTES:"0_action"='repay'
    and EVENT_ATTRIBUTES:asset='uluna'
    and EVENT_ATTRIBUTES:"0_contract_address"='terra19dtgj9j5j7kyf3pmejqv8vzfpxtejaypgzkz5u'
    and tx_status = 'SUCCEEDED'
    group by 1)

    select dep.dt1 as dt,
    daily_borrow,
    daily_repay,
    (daily_borrow-daily_repay) as net_borrow
    from dep
    inner join witd on dep.dt1=witd.dt2
    Run a query to Download Data