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"
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
}
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 {

View File

@ -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 {

View File

@ -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
}