adriaparcerisasOsmosis swap fees
    Updated 2022-06-28
    WITH
    froms as (
    SELECT
    from_currency,
    tx_id
    from osmosis.core.fact_swaps
    ) ,
    tos as (
    SELECT
    to_currency,
    tx_id
    from osmosis.core.fact_swaps
    ),
    froms_fees as (
    SELECT
    case when REGEXP_SUBSTR(fee,'i.*') is not null then REGEXP_SUBSTR(fee,'i.*')
    else REGEXP_SUBSTR(fee,'u.*') end as fee_name,
    REPLACE(fee, fee_name, '')::decimal/pow(10,6) as fee_paid,
    tx_id
    from osmosis.core.fact_transactions
    where tx_id in (select tx_id from froms)
    ),
    tos_fees as (
    SELECT
    case when REGEXP_SUBSTR(fee,'i.*') is not null then REGEXP_SUBSTR(fee,'i.*')
    else REGEXP_SUBSTR(fee,'u.*') end as fee_name,
    REPLACE(fee, fee_name, '')::decimal/pow(10,6) as fee_paid,
    tx_id
    from osmosis.core.fact_transactions
    where tx_id in (select tx_id from tos)
    ),
    final_froms as (
    SELECT
    project_name,
    avg(fee_paid) as avg_tx_fee
    from froms_fees x
    Run a query to Download Data