diff --git a/services/wallet/router/pathprocessor/constants.go b/services/wallet/router/pathprocessor/constants.go index 80aaa7917..984ac6ac4 100644 --- a/services/wallet/router/pathprocessor/constants.go +++ b/services/wallet/router/pathprocessor/constants.go @@ -32,3 +32,11 @@ const ( ProcessorENSPublicKeyName = "ENSPublicKey" ProcessorStickersBuyName = "StickersBuy" ) + +func IsProcessorBridge(name string) bool { + return name == ProcessorBridgeHopName || name == ProcessorBridgeCelerName +} + +func IsProcessorSwap(name string) bool { + return name == ProcessorSwapParaswapName +} diff --git a/services/wallet/router/router.go b/services/wallet/router/router.go index b46cd33bf..28ecd7cf1 100644 --- a/services/wallet/router/router.go +++ b/services/wallet/router/router.go @@ -317,24 +317,10 @@ func arrayContainsElement[T comparable](el T, arr []T) bool { return false } -func arraysWithSameElements[T comparable](ar1 []T, ar2 []T, isEqual func(T, T) bool) bool { - if len(ar1) != len(ar2) { - return false - } - for _, el := range ar1 { - if !arrayContainsElement(el, ar2) { - return false - } - } - return true -} - -func sameSingleChainTransfer(fromChains []*params.Network, toChains []*params.Network) bool { +func isSingleChainOperation(fromChains []*params.Network, toChains []*params.Network) bool { return len(fromChains) == 1 && len(toChains) == 1 && - arraysWithSameElements(fromChains, toChains, func(a, b *params.Network) bool { - return a.ChainID == b.ChainID - }) + fromChains[0].ChainID == toChains[0].ChainID } type Router struct { diff --git a/services/wallet/router/router_send_type.go b/services/wallet/router/router_send_type.go index 14f6fef99..50ddbd7ac 100644 --- a/services/wallet/router/router_send_type.go +++ b/services/wallet/router/router_send_type.go @@ -109,13 +109,11 @@ func (s SendType) canUseProcessor(p pathprocessor.PathProcessor) bool { switch s { case Transfer: return pathProcessorName == pathprocessor.ProcessorTransferName || - pathProcessorName == pathprocessor.ProcessorBridgeHopName || - pathProcessorName == pathprocessor.ProcessorBridgeCelerName + pathprocessor.IsProcessorBridge(pathProcessorName) case Bridge: - return pathProcessorName == pathprocessor.ProcessorBridgeHopName || - pathProcessorName == pathprocessor.ProcessorBridgeCelerName + return pathprocessor.IsProcessorBridge(pathProcessorName) case Swap: - return pathProcessorName == pathprocessor.ProcessorSwapParaswapName + return pathprocessor.IsProcessorSwap(pathProcessorName) case ERC721Transfer: return pathProcessorName == pathprocessor.ProcessorERC721Name case ERC1155Transfer: @@ -133,10 +131,6 @@ func (s SendType) canUseProcessor(p pathprocessor.PathProcessor) bool { } } -func (s SendType) simpleTransfer(p pathprocessor.PathProcessor) bool { - return s == Transfer && p.Name() == pathprocessor.ProcessorTransferName -} - func (s SendType) processZeroAmountInProcessor(amountIn *big.Int, amountOut *big.Int, processorName string) bool { if amountIn.Cmp(pathprocessor.ZeroBigIntValue) == 0 { if s == Transfer { diff --git a/services/wallet/router/router_v2.go b/services/wallet/router/router_v2.go index de99965bd..38cee49cb 100644 --- a/services/wallet/router/router_v2.go +++ b/services/wallet/router/router_v2.go @@ -893,8 +893,8 @@ func (r *Router) resolveCandidates(ctx context.Context, input *RouteInputParams, continue } - // if just a single from and to chain is selected for transfer, we can skip the bridge as potential path - if !input.SendType.simpleTransfer(pProcessor) && sameSingleChainTransfer(selectedFromChains, selectedToChains) { + // if we're doing a single chain operation, we can skip bridge processors + if isSingleChainOperation(selectedFromChains, selectedToChains) && pathprocessor.IsProcessorBridge(pProcessor.Name()) { continue }