2024-08-28 08:59:19 +00:00
|
|
|
package router
|
|
|
|
|
|
|
|
import (
|
2024-08-28 11:17:59 +00:00
|
|
|
"github.com/status-im/status-go/services/wallet/common"
|
2024-08-28 12:06:50 +00:00
|
|
|
"github.com/status-im/status-go/services/wallet/router/routes"
|
2024-08-28 08:59:19 +00:00
|
|
|
)
|
|
|
|
|
2024-08-28 12:06:50 +00:00
|
|
|
func removeBestRouteFromAllRouters(allRoutes []routes.Route, best routes.Route) []routes.Route {
|
2024-08-28 11:17:59 +00:00
|
|
|
for i := len(allRoutes) - 1; i >= 0; i-- {
|
|
|
|
route := allRoutes[i]
|
|
|
|
routeFound := true
|
|
|
|
for _, p := range route {
|
|
|
|
found := false
|
|
|
|
for _, b := range best {
|
|
|
|
if p.ProcessorName == b.ProcessorName &&
|
|
|
|
(p.FromChain == nil && b.FromChain == nil || p.FromChain.ChainID == b.FromChain.ChainID) &&
|
|
|
|
(p.ToChain == nil && b.ToChain == nil || p.ToChain.ChainID == b.ToChain.ChainID) &&
|
|
|
|
(p.FromToken == nil && b.FromToken == nil || p.FromToken.Symbol == b.FromToken.Symbol) {
|
|
|
|
found = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !found {
|
|
|
|
routeFound = false
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if routeFound {
|
|
|
|
return append(allRoutes[:i], allRoutes[i+1:]...)
|
2024-08-28 08:59:19 +00:00
|
|
|
}
|
|
|
|
}
|
2024-08-28 11:17:59 +00:00
|
|
|
|
|
|
|
return nil
|
2024-08-28 08:59:19 +00:00
|
|
|
}
|
|
|
|
|
2024-08-28 11:17:59 +00:00
|
|
|
func getChainPriority(chainID uint64) int {
|
|
|
|
switch chainID {
|
|
|
|
case common.EthereumMainnet, common.EthereumSepolia:
|
|
|
|
return 1
|
|
|
|
case common.OptimismMainnet, common.OptimismSepolia:
|
|
|
|
return 2
|
|
|
|
case common.ArbitrumMainnet, common.ArbitrumSepolia:
|
|
|
|
return 3
|
|
|
|
default:
|
|
|
|
return 0
|
2024-08-28 08:59:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-28 12:06:50 +00:00
|
|
|
func getRoutePriority(route routes.Route) int {
|
2024-08-28 11:17:59 +00:00
|
|
|
priority := 0
|
|
|
|
for _, path := range route {
|
|
|
|
priority += getChainPriority(path.FromChain.ChainID)
|
|
|
|
}
|
|
|
|
return priority
|
2024-08-28 08:59:19 +00:00
|
|
|
}
|