emirprince95Average bETH-mETH Peg
    Updated 2021-10-15
    select avg(basset_to_asset_ratio) as AVERAGE_bETH_ETH_PEG_LAST_THREE_MONTHS from(
    SELECT me.block_id, me.block_timestamp AS time_of_pricing, me.event_attributes:asset AS address_of_bToken,
    ls.address_name AS base_address_name
    , op.symbol AS target_address_name
    , me.event_attributes:price AS Price_of_base
    ,TO_NUMERIC(op.price_usd, 8) AS price_of_target
    , price_of_base/price_of_target as basset_to_asset_ratio,
    cast('ETH_PEG' as varchar) as peg_type
    FROM terra.msg_events me
    JOIN terra.labels ls ON ls.address = me.event_attributes:asset
    JOIN terra.oracle_prices op on me.block_timestamp = op.block_timestamp
    WHERE me.event_type = 'from_contract' AND
    me.event_attributes:action = 'feed_prices' AND
    me.event_attributes:contract_address = 'terra1cgg6yef7qcdm070qftghfulaxmllgmvk77nc7t' AND
    LOWER(base_address_name) = 'beth token contract' AND
    me.tx_status = 'SUCCEEDED'
    AND LOWER(target_address_name) = 'meth'
    AND (time_of_pricing > dateadd(month,-3,getdate()) AND time_of_pricing <= current_date))
    Run a query to Download Data