boomer77beth balance and in usd
    Updated 2022-03-29
    with provide as (select date_trunc('day', block_timestamp) as dt, sum(amount) as prov
    from anchor.collateral
    where event_type = 'provide' and currency = 'terra1dzhzukyezv0etz22ud940z7adyv7xgcjkahuun'
    group by 1),

    wd as (select date_trunc('day', block_timestamp) as dt, sum(amount) as wd
    from anchor.collateral
    where event_type = 'withdraw' and currency = 'terra1dzhzukyezv0etz22ud940z7adyv7xgcjkahuun'
    group by 1),

    price as (select date_trunc('day', block_timestamp) as dt, avg(price_usd) as beth_price
    from terra.oracle_prices
    where symbol = 'bETH'
    group by 1)

    select a.dt, a.prov, b.wd, (a.prov-b.wd) as net, SUM(net) OVER(ORDER BY a.dt asc ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS beth_balance,
    c.beth_price, (beth_balance*c.beth_price) as beth_usd
    from provide a
    left outer join wd b on a.dt = b.dt
    left outer join price c on a.dt = c.dt
    Run a query to Download Data