cypheroutbound fees of wormhole and terrabridge - with luna price
    Updated 2022-01-11
    with wormhole_fees as (with raw_prices as(
    select
    tx_id,
    date_trunc('day', block_timestamp) as block_day,
    iff(array_size(fee[0]:amount) = 2, array_construct(fee[0]:amount[0]:amount/1e6, fee[0]:amount[1]:amount/1e6), array_construct(fee[0]:amount[0]:amount/1e6)) as total_fee

    from terra.transactions
    where tx_id in (SELECT
    tx_id
    FROM terra.msg_events
    WHERE event_type = 'from_contract'
    AND event_attributes:action = 'complete_transfer_terra_native'
    AND event_attributes:contract_address = 'terra10nmmwe8r3g99a9newtqa7a75xfgs2e8z87r2sf')),

    luna_price as (
    SELECT date_trunc('day', block_timestamp) as block_day, AVG(price_usd) as price
    FROM terra.oracle_prices
    WHERE symbol = 'LUNA'
    AND block_day >= '2021-10-6'
    GROUP BY 1
    )
    select raw_prices.tx_id,
    raw_prices.block_day as block_day,
    raw_prices.total_fee,
    luna_price.price,
    raw_prices.total_fee[0]*luna_price.price as luna_times_price,
    iff(raw_prices.total_fee[1] is null, 0, raw_prices.total_fee[1]) as ust_fee,
    luna_times_price+ust_fee as total_final_fee from raw_prices
    inner join luna_price
    where raw_prices.block_day = luna_price.block_day and luna_times_price < 10
    ),

    terrabridge_fees as (
    select
    date_trunc('day', block_timestamp) as block_day,
    Run a query to Download Data