fix(wallet)_: fix single chain operation check

This commit is contained in:
Dario Gabriel Lipicar 2024-08-29 12:34:53 -03:00 committed by dlipicar
parent 666f07fe1e
commit dc7ca3ddb4
4 changed files with 15 additions and 27 deletions

View File

@ -32,3 +32,11 @@ const (
ProcessorENSPublicKeyName = "ENSPublicKey" ProcessorENSPublicKeyName = "ENSPublicKey"
ProcessorStickersBuyName = "StickersBuy" ProcessorStickersBuyName = "StickersBuy"
) )
func IsProcessorBridge(name string) bool {
return name == ProcessorBridgeHopName || name == ProcessorBridgeCelerName
}
func IsProcessorSwap(name string) bool {
return name == ProcessorSwapParaswapName
}

View File

@ -317,24 +317,10 @@ func arrayContainsElement[T comparable](el T, arr []T) bool {
return false return false
} }
func arraysWithSameElements[T comparable](ar1 []T, ar2 []T, isEqual func(T, T) bool) bool { func isSingleChainOperation(fromChains []*params.Network, toChains []*params.Network) 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 {
return len(fromChains) == 1 && return len(fromChains) == 1 &&
len(toChains) == 1 && len(toChains) == 1 &&
arraysWithSameElements(fromChains, toChains, func(a, b *params.Network) bool { fromChains[0].ChainID == toChains[0].ChainID
return a.ChainID == b.ChainID
})
} }
type Router struct { type Router struct {

View File

@ -109,13 +109,11 @@ func (s SendType) canUseProcessor(p pathprocessor.PathProcessor) bool {
switch s { switch s {
case Transfer: case Transfer:
return pathProcessorName == pathprocessor.ProcessorTransferName || return pathProcessorName == pathprocessor.ProcessorTransferName ||
pathProcessorName == pathprocessor.ProcessorBridgeHopName || pathprocessor.IsProcessorBridge(pathProcessorName)
pathProcessorName == pathprocessor.ProcessorBridgeCelerName
case Bridge: case Bridge:
return pathProcessorName == pathprocessor.ProcessorBridgeHopName || return pathprocessor.IsProcessorBridge(pathProcessorName)
pathProcessorName == pathprocessor.ProcessorBridgeCelerName
case Swap: case Swap:
return pathProcessorName == pathprocessor.ProcessorSwapParaswapName return pathprocessor.IsProcessorSwap(pathProcessorName)
case ERC721Transfer: case ERC721Transfer:
return pathProcessorName == pathprocessor.ProcessorERC721Name return pathProcessorName == pathprocessor.ProcessorERC721Name
case ERC1155Transfer: 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 { func (s SendType) processZeroAmountInProcessor(amountIn *big.Int, amountOut *big.Int, processorName string) bool {
if amountIn.Cmp(pathprocessor.ZeroBigIntValue) == 0 { if amountIn.Cmp(pathprocessor.ZeroBigIntValue) == 0 {
if s == Transfer { if s == Transfer {

View File

@ -893,8 +893,8 @@ func (r *Router) resolveCandidates(ctx context.Context, input *RouteInputParams,
continue continue
} }
// if just a single from and to chain is selected for transfer, we can skip the bridge as potential path // if we're doing a single chain operation, we can skip bridge processors
if !input.SendType.simpleTransfer(pProcessor) && sameSingleChainTransfer(selectedFromChains, selectedToChains) { if isSingleChainOperation(selectedFromChains, selectedToChains) && pathprocessor.IsProcessorBridge(pProcessor.Name()) {
continue continue
} }