mogarchyTrust Wallet Top Swap Pairs
    Updated 2023-11-07
    with base as (select 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 affiliate_address = 'thor1zw97zhhgwy3u99rxpn7cyelj44y733ntgg30e8' then 'DefiSpot'
    when affiliate_address in ('wr', 'thor1a427q3v96psuj4fnughdw8glt5r7j38lj7rkp8') then 'ThorWallet'
    when affiliate_address in ('T', 't', 't.THOR', 'thor160yye65pf9rzwrgqmtgav69n6zlsyfpgm9a7xk') then 'ThorSwap'
    when affiliate_address in ('te') then 'TrustWallet'
    when affiliate_address in ('ej') then 'EdgeWallet'
    --when affiliate_address = 'ferz' then 'Ferz Wallet'
    else 'Others'
    end as affiliate_name,
    sum(to_amount_usd) as swap_volume_usd
    from thorchain.core.fact_swaps
    where affiliate_name = 'TrustWallet'
    and block_timestamp >= '2022-01-01'
    --where tx_id = 'E3701AEC766A1CCBE22F0857EBEEE36BC2A358684A7577AC9900D3FEA99DD1A3'
    group by tx_id, from_asset, to_asset, affiliate_address),

    base2 as (select tx_id,
    array_agg(distinct assets) within group (order by assets asc) as swap_direction,
    sum(swap_volume_usd) as swap_volume
    from base
    group by 1),

    base3 as (select swap_direction[0] as path1,
    swap_direction[1] as path2,