Updated 2025-05-12
    WITH SwapFees AS (
    SELECT
    SUM((t.gas_used * t.gas_unit_price) / 1e8) AS fee_in_apt,
    COUNT(s.tx_hash) AS number_of_swaps
    FROM
    aptos.core.fact_transactions t
    JOIN
    aptos.defi.ez_dex_swaps s ON t.tx_hash = s.tx_hash
    WHERE
    t.success = True
    AND t.block_timestamp >= DATE_TRUNC('month', CURRENT_DATE)
    AND t.block_timestamp < DATE_TRUNC('month', CURRENT_DATE) + INTERVAL '1 MONTH'
    GROUP BY t.tx_hash
    ),
    APTPrice AS (
    SELECT
    MEDIAN(price) AS apt_price
    FROM
    aptos.price.ez_prices_hourly
    WHERE
    symbol = 'APT'
    AND hour >= DATE_TRUNC('month', CURRENT_DATE)
    AND hour < DATE_TRUNC('month', CURRENT_DATE) + INTERVAL '1 MONTH'
    )
    SELECT
    SUM(sf.fee_in_apt) AS total_swap_fees_in_apt,
    SUM(sf.fee_in_apt) * (SELECT ap.apt_price FROM APTPrice ap) AS total_swap_fees_in_usd,
    SUM(sf.number_of_swaps) AS total_number_of_swaps,
    ROUND(SUM(sf.fee_in_apt) / SUM(sf.number_of_swaps), 8) AS avg_fee_per_swap_in_apt,
    ROUND((SUM(sf.fee_in_apt) / SUM(sf.number_of_swaps)) * (SELECT ap.apt_price FROM APTPrice ap), 4) AS avg_fee_per_swap_in_usd
    FROM
    SwapFees sf;

    Last run: 16 days ago
    TOTAL_SWAP_FEES_IN_APT
    TOTAL_SWAP_FEES_IN_USD
    TOTAL_NUMBER_OF_SWAPS
    AVG_FEE_PER_SWAP_IN_APT
    AVG_FEE_PER_SWAP_IN_USD
    1
    1410.4125287588.0194006463556060.000221920.0012
    1
    55B
    19s