Updated 2 days ago
    with pools_count as (
    select
    tx_id,
    count(DISTINCT pool_name) as n_pools
    from thorchain.defi.fact_swaps
    where tx_id not in (select tx_id from thorchain.defi.fact_refund_events)
    group by 1
    )
    ,
    all_time_affiliate_fee as (
    select
    zeroifnull(sum((from_amount_usd / n_pools) * AFFILIATE_FEE_BASIS_POINTS) / 10000) as all_time_affiliate_fee
    from thorchain.defi.fact_swaps
    join pools_count using(tx_id)
    where AFFILIATE_ADDRESS is not null
    ),
    one_month_affiliate_fee as (
    select
    zeroifnull(sum((from_amount_usd / n_pools) * AFFILIATE_FEE_BASIS_POINTS) / 10000) as one_month_affiliate_fee
    from thorchain.defi.fact_swaps
    join pools_count using(tx_id)
    where block_timestamp::date > current_date - interval '1 month'
    and AFFILIATE_ADDRESS is not null
    )
    ,
    one_week_affiliate_fee as (
    select
    zeroifnull(sum((from_amount_usd / n_pools) * AFFILIATE_FEE_BASIS_POINTS) / 10000) as one_week_affiliate_fee
    from thorchain.defi.fact_swaps
    join pools_count using(tx_id)
    where block_timestamp::date > current_date - interval '1 week'
    and AFFILIATE_ADDRESS is not null
    )
    ,
    one_day_affiliate_fee as (
    select
    Last run: 1 day ago
    All Time Affiliate Earning $
    30 Days Affiliate Earning $
    7 Days Affiliate Earning $
    24 Hours Affiliate Earning $
    YTD Affiliate Earning $
    1
    32973478.231389902.69354272.472301522696396.84
    1
    54B
    23s