ShapeShiftTrust Wallet Trader CRM
    Updated 2025-02-03
    -- forked from Rayyyk / Trader CRM @ https://flipsidecrypto.xyz/Rayyyk/q/r1aFqxHKLmn9/trader-crm
    with table_1 as (
    select
    date_trunc('day', block_timestamp) as day,
    from_address,
    affiliate_address,
    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 assets 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
    where
    affiliate_address is not null
    and block_timestamp >= '{{Start_Date}}'
    and block_timestamp <= '{{End_Date}}'
    group by
    1,
    2,
    3,
    4,
    QueryRunArchived: QueryRun has been archived