Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(wallet)_: fix single chain operation check #5784

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions services/wallet/router/pathprocessor/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,11 @@ const (
ProcessorENSPublicKeyName = "ENSPublicKey"
ProcessorStickersBuyName = "StickersBuy"
)

func IsProcessorBridge(name string) bool {
alaibe marked this conversation as resolved.
Show resolved Hide resolved
return name == ProcessorBridgeHopName || name == ProcessorBridgeCelerName
}

func IsProcessorSwap(name string) bool {
return name == ProcessorSwapParaswapName
}
18 changes: 2 additions & 16 deletions services/wallet/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dlipicar what I had in mind with this function was to compare DisabledFromChainIDs and DisabledToChainIDs arrays, cause when client sends mainnet chain enabled only it sends for both arrays `[10, 42161], but now since they are converted to "enabled chains" we don't need it I guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm not sure if you were planning to use that function in the future (you can re-introduce it then), it didn't make sense where it was used before since we had this check right before calling this
image

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 {
Expand Down
12 changes: 3 additions & 9 deletions services/wallet/router/router_send_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions services/wallet/router/router_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down