boomer771. top 10 depositor basset deposited
    Updated 2022-01-08
    with top as (select sender, sum(deposit_amount) as UST_deposited, count(distinct tx_id) as deposit_tx_count
    from anchor.deposits
    where date(block_timestamp) >= CURRENT_DATE - 30
    group by 1
    order by 2 desc
    limit 10),

    p_bluna as (select sender, sum(amount) as bAssets, currency, event_type
    from anchor.collateral
    where sender in (select sender from top) and event_type = 'provide' and currency = 'terra1kc87mu460fwkqte29rquh4hc20m54fxwtsx7gp' --bluna
    group by 1,3,4),

    w_bluna as (select sender, sum(amount) as bAssets, currency, event_type
    from anchor.collateral
    where sender in (select sender from top) and event_type = 'withdraw' and currency = 'terra1kc87mu460fwkqte29rquh4hc20m54fxwtsx7gp' --bluna
    group by 1,3,4),

    p_beth as (select sender, sum(amount) as bAssets, currency, event_type
    from anchor.collateral
    where sender in (select sender from top) and event_type = 'provide' and currency = 'terra1dzhzukyezv0etz22ud940z7adyv7xgcjkahuun' --beth
    group by 1,3,4),

    w_beth as (select sender, sum(amount) as bAssets, currency, event_type
    from anchor.collateral
    where sender in (select sender from top) and event_type = 'provide' and currency = 'terra1dzhzukyezv0etz22ud940z7adyv7xgcjkahuun' --beth
    group by 1,3,4)

    select a.sender, a.ust_deposited, a.deposit_tx_count, (b.bassets - c.bassets) as net_bluna, (d.bassets - e.bassets) as net_beth
    from top a
    left outer join p_bluna b on a.sender = b.sender
    left outer join w_bluna c on a.sender = c.sender
    left outer join p_beth d on a.sender = d.sender
    left outer join p_beth e on a.sender = e.sender
    order by 2 desc
    Run a query to Download Data