mariyaAmount of Collateral
    Updated 2022-03-30
    with bETH_coll as (
    SELECT date_trunc('day',block_timestamp) as t1,
    sum(amount) AS coll1
    from anchor.collateral
    WHERE currency='terra1dzhzukyezv0etz22ud940z7adyv7xgcjkahuun' and event_type= 'provide' and block_timestamp>=CURRENT_DATE-90
    group by 1),
    bETH_with AS (
    SELECT date_trunc('day',block_timestamp) as t2,sum(amount) AS coll2
    from anchor.collateral WHERE currency='terra1dzhzukyezv0etz22ud940z7adyv7xgcjkahuun' and event_type= 'withdraw'
    and block_timestamp>=CURRENT_DATE-90 group by 1),
    bETH_liq as (
    SELECT date_trunc('day',block_timestamp) as t3,
    sum(liquidated_amount) AS coll3
    from anchor.liquidations
    WHERE LIQUIDATED_CURRENCY='terra1dzhzukyezv0etz22ud940z7adyv7xgcjkahuun' and block_timestamp>=CURRENT_DATE-90 group by 1)
    select
    bETH_coll.t1 as day,
    coll1 as collateral,
    coll2 as withdraw,
    coll3 as liquia,
    coll1-coll2-coll3 as net_collateral_anchor
    from bETH_coll
    full outer join bETH_with on bETH_coll.t1=bETH_with.t2
    full outer join bETH_liq on bETH_coll.t1=bETH_liq.t3
    Run a query to Download Data