with terraswap_withdraw as (
select
date_trunc('day', block_timestamp) as block_day,
sum((event_attributes:"1_amount"/1e6)*2) as total_luna_amount
from terra.msg_events
where event_attributes:"0_contract_address" = 'terra1nuy34nwnsh53ygpc4xprlj263cztw7vc99leh2'
and event_attributes:"1_action" = 'withdraw_liquidity'
and block_timestamp >= '2021-12-28'
and event_index = 6
and tx_status = 'SUCCEEDED'
group by block_day
),
luna_price as (
select
date_trunc('day', block_timestamp) as block_day,
avg(price_usd) as luna_price
from terra.oracle_prices
where symbol = 'LUNA'
group by 1
)
select terraswap_withdraw.block_day as block_day, terraswap_withdraw.total_luna_amount as luna_withdrawn, luna_price.luna_price, luna_withdrawn*luna_price.luna_price as withdrawn_usd
from terraswap_withdraw, luna_price
where terraswap_withdraw.block_day = luna_price.block_day
order by block_day