LTirrell2022-01-28_luna_anchor-collateral
    Updated 2022-02-01
    --How much of the collateral provided on Anchor is bLUNA vs. bETH? How has this changed over the past 90 days?
    with luna_price as (
    select
    date_trunc('day', block_timestamp) as timestamp,
    avg(price_usd) as avg_price
    from
    terra.oracle_prices
    where
    symbol = 'LUNA'
    group by
    timestamp
    ),
    eth_price as (
    select
    date_trunc('day', hour) as timestamp,
    avg(price) as avg_price
    from
    ethereum.token_prices_hourly
    where
    symbol = 'ETH'
    group by
    timestamp
    ),
    provide as (
    select
    date_trunc('day', block_timestamp) as datetime,
    sum(
    msg_value :execute_msg :lock_collateral :collaterals [0] [1] / pow(10, 6)
    ) as token_amount,
    case
    when msg_value :execute_msg :lock_collateral :collaterals [0] [0] = 'terra1kc87mu460fwkqte29rquh4hc20m54fxwtsx7gp' then 'bLUNA'
    when msg_value :execute_msg :lock_collateral :collaterals [0] [0] = 'terra1dzhzukyezv0etz22ud940z7adyv7xgcjkahuun' then 'bETH'
    end as denom
    from
    terra.msgs
    where
    Run a query to Download Data