John_GaltExisting Solid
    Updated 2023-05-21
    with borrow_table as (select
    date(block_timestamp) as date,
    sum(message_value:msg:borrow_stable:borrow_amount) / pow(10, 6) as borrow
    from terra.core.ez_messages
    where date(block_timestamp) > '2023-03-01'
    and message_value:contract = 'terra1h4cknjl5k0aysdhv0h4eqcaka620g8h69k8h0pjjccxvf9esfhws3cyqnc'
    and SPLIT_PART(message_value:msg, '"', 2) = 'borrow_stable'
    group by date
    ),

    repay_table as (select
    date(block_timestamp) as date,
    sum(message_value:msg:send:amount) / pow(10, 6) as repay
    from terra.core.ez_messages
    where date(block_timestamp) > '2023-03-01'
    and message_value:msg:send:contract = 'terra1h4cknjl5k0aysdhv0h4eqcaka620g8h69k8h0pjjccxvf9esfhws3cyqnc'
    and message_value:msg:send:msg = 'eyJyZXBheV9zdGFibGUiOnt9fQ=='
    group by date
    ),

    Common as (select
    distinct date(block_timestamp) as date
    from terra.core.ez_swaps
    where date(block_timestamp) > '2023-03-01'
    ),

    final as (select
    common.date, borrow - repay as net_borrow,
    sum(net_borrow) over (order by common.date) as total_solid
    from common
    left outer join borrow_table on common.date = borrow_table.date
    left outer join repay_table on common.date = repay_table.date
    )

    select *
    from final
    Run a query to Download Data