RayyykTC Affiliates Trader CRM 2
    Updated 14 hours ago
    with table_1 as (select date_trunc('day', block_timestamp) as day,
    from_address,
    a1.value::string as affiliate_address,
    a2.value::number as affiliate_fee_basis_points,
    tx_id,
    split(from_asset, '-')[0] as from_assets,
    case
    when from_assets ilike '%/%' then split(from_assets, '/')[1]
    else split(from_assets, '.')[1]
    end as from_asset_names,
    split(to_asset, '-')[0] as to_assets,
    case
    when to_assets ilike '%/%' then split(to_assets, '/')[1]
    else split(to_assets, '.')[1]
    end as to_asset_names,
    concat(from_asset_names, ' -> ', to_asset_names) as assets,
    case when concat(from_asset_names, ' -> ', to_asset_names) ilike '%rune' then 2 else 1 end as numbering,
    sum(from_amount_usd / rune_usd) as rune_volume,
    sum(from_amount_usd) as usd_volume
    from thorchain.defi.fact_swaps as t,
    lateral flatten(input => t.affiliate_addresses_array) a1,
    lateral flatten(input => t.affiliate_fee_basis_points_array) a2
    where affiliate_address is not null
    and a1.path = a2.path
    and block_timestamp >= '{{Start_Date}}'
    and block_timestamp <= '{{End_Date}}'
    group by 1,2,3,4,5,6,7,8),

    table_2 as (select day,
    from_address,
    tx_id,
    affiliate_address,
    affiliate_fee_basis_points,
    array_agg(distinct assets) within group (order by assets asc) as swap_direction,
    sum(rune_volume) as swap_volume_rune,
    sum(usd_volume) as swap_volume_usd
    Last run: about 14 hours agoAuto-refreshes every 24 hours
    TOTAL_ADDRESS
    TX_ON_SS
    VOL_ON_SS
    FEES_ON_SS
    AVG_BPS_ON_SS
    1
    52493033008968.3676741.2921.911870229
    1
    45B
    107s