@@ -1605,7 +1605,29 @@ export class SwapAndBridgeController extends EventEmitter implements ISwapAndBri
16051605 return - 1
16061606 }
16071607
1608- const sortByAmountAndTime = ( ) => {
1608+ const sortByPerformance = ( ) => {
1609+ // if it's a bridge, prioritize across and relay as we find
1610+ // across and relay the best bridges out where with a close
1611+ // to 100% success rate and an approximate bridge time of 30s
1612+ if ( isBridge ) {
1613+ const aHasAcross = r1 . usedBridgeNames ?. includes ( 'across' )
1614+ const bHasAcross = r2 . usedBridgeNames ?. includes ( 'across' )
1615+ if ( aHasAcross && ! bHasAcross ) return - 1
1616+ if ( bHasAcross && ! aHasAcross ) return 1
1617+
1618+ const aHasRelay = r1 . usedBridgeNames ?. includes ( 'relaydepository' )
1619+ const bHasRelay = r2 . usedBridgeNames ?. includes ( 'relaydepository' )
1620+ if ( aHasRelay && ! bHasRelay ) return - 1
1621+ if ( bHasRelay && ! aHasRelay ) return 1
1622+ } else {
1623+ // if it's a swap, deprioritize the bungee auto route as it's an intent
1624+ // engine. And intent engines are bad UX
1625+ const aHasBungeeAutoRoute = r1 . usedBridgeNames ?. includes ( 'bungeeAutoRoute' )
1626+ const bHasBungeeAutoRoute = r2 . usedBridgeNames ?. includes ( 'bungeeAutoRoute' )
1627+ if ( aHasBungeeAutoRoute && ! bHasBungeeAutoRoute ) return 1
1628+ if ( bHasBungeeAutoRoute && ! aHasBungeeAutoRoute ) return - 1
1629+ }
1630+
16091631 const a = BigInt ( r1 . toAmount )
16101632 const b = BigInt ( r2 . toAmount )
16111633
@@ -1646,7 +1668,8 @@ export class SwapAndBridgeController extends EventEmitter implements ISwapAndBri
16461668 const r2ServiceFee = r2 . serviceFee && Number ( r2 . serviceFee . amountUSD ) > 0
16471669 if ( r1ServiceFee && ! r2ServiceFee ) return 1
16481670 if ( r2ServiceFee && ! r1ServiceFee ) return - 1
1649- return sortByAmountAndTime ( )
1671+
1672+ return sortByPerformance ( )
16501673 } )
16511674 . sort ( ( a , b ) => Number ( a . disabled === true ) - Number ( b . disabled === true ) )
16521675 // select the first enabled route
0 commit comments