emirprince95bAssets Prices
    Updated 2021-10-15
    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 > '2021-04-01T15:35:31Z' AND time_of_pricing <='2021-07-15T00:00:00Z')
    UNION

    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
    , swp.ask_currency AS target_address_name
    , me.event_attributes:price AS Price_of_base
    , swp.price_of_target
    , price_of_base/price_of_target as basset_to_asset_ratio,
    cast('LUNA_PEG' as varchar) as peg_type --
    FROM terra.msg_events me
    JOIN terra.labels ls ON ls.address = me.event_attributes:asset
    JOIN (select block_id, block_timestamp, ask_currency, avg(price1_USD) as price_of_target from terra.swaps
    where ask_currency = 'LUNA' and offer_currency = 'UST'
    group by block_id, block_timestamp, ask_currency) swp on me.block_timestamp = swp.block_timestamp and swp.block_id = me.block_id
    WHERE me.event_type = 'from_contract' AND
    me.event_attributes:action = 'feed_prices' AND
    me.event_attributes:contract_address = 'terra1cgg6yef7qcdm070qftghfulaxmllgmvk77nc7t' AND
    base_address_name = 'bLUNA' AND
    Run a query to Download Data