John_GaltNEB LBP Total NEB Sold from Pool
    Updated 2022-05-06
    with table1 as (select
    case
    when event_attributes:ask_asset = 'terra1mpq5zkkm39nmjrjg9raknpfrfmcfwv0nh0whvn' then event_attributes:to
    when event_attributes:ask_asset = 'uusd' then event_attributes:from
    else 0
    end as address,
    case
    when event_attributes:ask_asset = 'terra1mpq5zkkm39nmjrjg9raknpfrfmcfwv0nh0whvn' then event_attributes:return_amount / pow(10, 6)
    else 0
    end as neb_bought,
    case
    when event_attributes:ask_asset = 'uusd' then event_attributes:offer_amount / pow(10, 6)
    else 0
    end as neb_sold
    from terra.msg_events
    where date(block_timestamp) > '2022-04-24'
    and (event_attributes:ask_asset = 'terra1mpq5zkkm39nmjrjg9raknpfrfmcfwv0nh0whvn' or event_attributes:ask_asset = 'uusd')
    and (event_attributes:"0_contract_address" = 'terra152wlyd53nfcltuwcje9ale8qv3hpyna4sv9mvg'
    or event_attributes:"1_contract_address" = 'terra152wlyd53nfcltuwcje9ale8qv3hpyna4sv9mvg')
    and event_index = 3
    ),

    table2 as (select address, sum(neb_bought) as total_bought, sum(neb_sold) as total_sold,
    total_bought - total_sold as net_bought
    from table1
    group by address
    order by net_bought desc
    )

    select sum(net_bought) as total_sold from table2
    Run a query to Download Data