From d10d492515b5c4567ef52c62738704345582c656 Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Wed, 28 Aug 2024 11:23:32 +0200 Subject: [PATCH] chore!: removed v2 mark from api endpoints, structs and files marked as router v2 Breaking change! Since the old router logic is removed, there is no need to have files and structs marked as v2. Renamed endpoints: - `GetSuggestedRoutesV2` to `GetSuggestedRoutes` - `GetSuggestedRoutesV2Async` to `GetSuggestedRoutesAsync` - `StopSuggestedRoutesV2AsyncCalcualtion` to `StopSuggestedRoutesAsyncCalcualtion` --- services/wallet/api.go | 18 +- services/wallet/router/filter.go | 40 +-- services/wallet/router/filter_test.go | 284 +++++++++--------- .../wallet/router/{router_v2.go => router.go} | 106 +++---- .../{router_v2_test.go => router_test.go} | 26 +- ...er_v2_test_data.go => router_test_data.go} | 104 +++---- 6 files changed, 289 insertions(+), 289 deletions(-) rename services/wallet/router/{router_v2.go => router.go} (93%) rename services/wallet/router/{router_v2_test.go => router_test.go} (90%) rename services/wallet/router/{router_v2_test_data.go => router_test_data.go} (98%) diff --git a/services/wallet/api.go b/services/wallet/api.go index 76339b114..966ba9073 100644 --- a/services/wallet/api.go +++ b/services/wallet/api.go @@ -488,22 +488,22 @@ func gweiToWei(val *big.Float) *big.Int { return res } -func (api *API) GetSuggestedRoutesV2(ctx context.Context, input *router.RouteInputParams) (*router.SuggestedRoutesV2, error) { - log.Debug("call to GetSuggestedRoutesV2") +func (api *API) GetSuggestedRoutes(ctx context.Context, input *router.RouteInputParams) (*router.SuggestedRoutes, error) { + log.Debug("call to GetSuggestedRoutes") - return api.router.SuggestedRoutesV2(ctx, input) + return api.router.SuggestedRoutes(ctx, input) } -func (api *API) GetSuggestedRoutesV2Async(ctx context.Context, input *router.RouteInputParams) { - log.Debug("call to GetSuggestedRoutesV2Async") +func (api *API) GetSuggestedRoutesAsync(ctx context.Context, input *router.RouteInputParams) { + log.Debug("call to GetSuggestedRoutesAsync") - api.router.SuggestedRoutesV2Async(input) + api.router.SuggestedRoutesAsync(input) } -func (api *API) StopSuggestedRoutesV2AsyncCalcualtion(ctx context.Context) { - log.Debug("call to StopSuggestedRoutesV2AsyncCalcualtion") +func (api *API) StopSuggestedRoutesAsyncCalculation(ctx context.Context) { + log.Debug("call to StopSuggestedRoutesAsyncCalculation") - api.router.StopSuggestedRoutesV2AsyncCalcualtion() + api.router.StopSuggestedRoutesAsyncCalculation() } // Generates addresses for the provided paths, response doesn't include `HasActivity` value (if you need it check `GetAddressDetails` function) diff --git a/services/wallet/router/filter.go b/services/wallet/router/filter.go index be696725f..c872f0469 100644 --- a/services/wallet/router/filter.go +++ b/services/wallet/router/filter.go @@ -20,7 +20,7 @@ func init() { } } -func filterRoutesV2(routes [][]*PathV2, amountIn *big.Int, fromLockedAmount map[uint64]*hexutil.Big) [][]*PathV2 { +func filterRoutes(routes [][]*Path, amountIn *big.Int, fromLockedAmount map[uint64]*hexutil.Big) [][]*Path { for i := len(routes) - 1; i >= 0; i-- { routeAmount := big.NewInt(0) for _, p := range routes[i] { @@ -38,18 +38,18 @@ func filterRoutesV2(routes [][]*PathV2, amountIn *big.Int, fromLockedAmount map[ return routes } - routesAfterNetworkCompliance := filterNetworkComplianceV2(routes, fromLockedAmount) - return filterCapacityValidationV2(routesAfterNetworkCompliance, amountIn, fromLockedAmount) + routesAfterNetworkCompliance := filterNetworkCompliance(routes, fromLockedAmount) + return filterCapacityValidation(routesAfterNetworkCompliance, amountIn, fromLockedAmount) } -// filterNetworkComplianceV2 performs the first level of filtering based on network inclusion/exclusion criteria. -func filterNetworkComplianceV2(routes [][]*PathV2, fromLockedAmount map[uint64]*hexutil.Big) [][]*PathV2 { - filteredRoutes := make([][]*PathV2, 0) +// filterNetworkCompliance performs the first level of filtering based on network inclusion/exclusion criteria. +func filterNetworkCompliance(routes [][]*Path, fromLockedAmount map[uint64]*hexutil.Big) [][]*Path { + filteredRoutes := make([][]*Path, 0) if routes == nil || fromLockedAmount == nil { return filteredRoutes } - fromIncluded, fromExcluded := setupRouteValidationMapsV2(fromLockedAmount) + fromIncluded, fromExcluded := setupRouteValidationMaps(fromLockedAmount) for _, route := range routes { if route == nil { @@ -57,15 +57,15 @@ func filterNetworkComplianceV2(routes [][]*PathV2, fromLockedAmount map[uint64]* } // Create fresh copies of the maps for each route check, because they are manipulated - if isValidForNetworkComplianceV2(route, copyMapGeneric(fromIncluded, nil).(map[uint64]bool), copyMapGeneric(fromExcluded, nil).(map[uint64]bool)) { + if isValidForNetworkCompliance(route, copyMapGeneric(fromIncluded, nil).(map[uint64]bool), copyMapGeneric(fromExcluded, nil).(map[uint64]bool)) { filteredRoutes = append(filteredRoutes, route) } } return filteredRoutes } -// isValidForNetworkComplianceV2 checks if a route complies with network inclusion/exclusion criteria. -func isValidForNetworkComplianceV2(route []*PathV2, fromIncluded, fromExcluded map[uint64]bool) bool { +// isValidForNetworkCompliance checks if a route complies with network inclusion/exclusion criteria. +func isValidForNetworkCompliance(route []*Path, fromIncluded, fromExcluded map[uint64]bool) bool { logger.Debug("Initial inclusion/exclusion maps", zap.Any("fromIncluded", fromIncluded), zap.Any("fromExcluded", fromExcluded), @@ -101,8 +101,8 @@ func isValidForNetworkComplianceV2(route []*PathV2, fromIncluded, fromExcluded m return true } -// setupRouteValidationMapsV2 initializes maps for network inclusion and exclusion based on locked amounts. -func setupRouteValidationMapsV2(fromLockedAmount map[uint64]*hexutil.Big) (map[uint64]bool, map[uint64]bool) { +// setupRouteValidationMaps initializes maps for network inclusion and exclusion based on locked amounts. +func setupRouteValidationMaps(fromLockedAmount map[uint64]*hexutil.Big) (map[uint64]bool, map[uint64]bool) { fromIncluded := make(map[uint64]bool) fromExcluded := make(map[uint64]bool) @@ -116,20 +116,20 @@ func setupRouteValidationMapsV2(fromLockedAmount map[uint64]*hexutil.Big) (map[u return fromIncluded, fromExcluded } -// filterCapacityValidationV2 performs the second level of filtering based on amount and capacity validation. -func filterCapacityValidationV2(routes [][]*PathV2, amountIn *big.Int, fromLockedAmount map[uint64]*hexutil.Big) [][]*PathV2 { - filteredRoutes := make([][]*PathV2, 0) +// filterCapacityValidation performs the second level of filtering based on amount and capacity validation. +func filterCapacityValidation(routes [][]*Path, amountIn *big.Int, fromLockedAmount map[uint64]*hexutil.Big) [][]*Path { + filteredRoutes := make([][]*Path, 0) for _, route := range routes { - if hasSufficientCapacityV2(route, amountIn, fromLockedAmount) { + if hasSufficientCapacity(route, amountIn, fromLockedAmount) { filteredRoutes = append(filteredRoutes, route) } } return filteredRoutes } -// hasSufficientCapacityV2 checks if a route has sufficient capacity to handle the required amount. -func hasSufficientCapacityV2(route []*PathV2, amountIn *big.Int, fromLockedAmount map[uint64]*hexutil.Big) bool { +// hasSufficientCapacity checks if a route has sufficient capacity to handle the required amount. +func hasSufficientCapacity(route []*Path, amountIn *big.Int, fromLockedAmount map[uint64]*hexutil.Big) bool { for _, path := range route { if amount, ok := fromLockedAmount[path.FromChain.ChainID]; ok { if path.AmountIn.ToInt().Cmp(amount.ToInt()) != 0 { @@ -137,7 +137,7 @@ func hasSufficientCapacityV2(route []*PathV2, amountIn *big.Int, fromLockedAmoun return false } requiredAmountIn := new(big.Int).Sub(amountIn, amount.ToInt()) - restAmountIn := calculateRestAmountInV2(route, path) + restAmountIn := calculateRestAmountIn(route, path) logger.Debug("Checking path", zap.Any("path", path)) logger.Debug("Required amount in", zap.String("requiredAmountIn", requiredAmountIn.String())) @@ -153,7 +153,7 @@ func hasSufficientCapacityV2(route []*PathV2, amountIn *big.Int, fromLockedAmoun } // calculateRestAmountIn calculates the remaining amount in for the route excluding the specified path -func calculateRestAmountInV2(route []*PathV2, excludePath *PathV2) *big.Int { +func calculateRestAmountIn(route []*Path, excludePath *Path) *big.Int { restAmountIn := big.NewInt(0) for _, path := range route { if path != excludePath { diff --git a/services/wallet/router/filter_test.go b/services/wallet/router/filter_test.go index b513fad56..74c8e4b94 100644 --- a/services/wallet/router/filter_test.go +++ b/services/wallet/router/filter_test.go @@ -26,24 +26,24 @@ var ( amount4 = hexutil.Big(*big.NewInt(400)) amount5 = hexutil.Big(*big.NewInt(500)) - path0 = &PathV2{FromChain: network4, AmountIn: &amount0} + path0 = &Path{FromChain: network4, AmountIn: &amount0} - pathC1A1 = &PathV2{FromChain: network1, AmountIn: &amount1} + pathC1A1 = &Path{FromChain: network1, AmountIn: &amount1} - pathC2A1 = &PathV2{FromChain: network2, AmountIn: &amount1} - pathC2A2 = &PathV2{FromChain: network2, AmountIn: &amount2} + pathC2A1 = &Path{FromChain: network2, AmountIn: &amount1} + pathC2A2 = &Path{FromChain: network2, AmountIn: &amount2} - pathC3A1 = &PathV2{FromChain: network3, AmountIn: &amount1} - pathC3A2 = &PathV2{FromChain: network3, AmountIn: &amount2} - pathC3A3 = &PathV2{FromChain: network3, AmountIn: &amount3} + pathC3A1 = &Path{FromChain: network3, AmountIn: &amount1} + pathC3A2 = &Path{FromChain: network3, AmountIn: &amount2} + pathC3A3 = &Path{FromChain: network3, AmountIn: &amount3} - pathC4A1 = &PathV2{FromChain: network4, AmountIn: &amount1} - pathC4A4 = &PathV2{FromChain: network4, AmountIn: &amount4} + pathC4A1 = &Path{FromChain: network4, AmountIn: &amount1} + pathC4A4 = &Path{FromChain: network4, AmountIn: &amount4} - pathC5A5 = &PathV2{FromChain: network5, AmountIn: &amount5} + pathC5A5 = &Path{FromChain: network5, AmountIn: &amount5} ) -func routesEqual(t *testing.T, expected, actual [][]*PathV2) bool { +func routesEqual(t *testing.T, expected, actual [][]*Path) bool { if len(expected) != len(actual) { return false } @@ -55,7 +55,7 @@ func routesEqual(t *testing.T, expected, actual [][]*PathV2) bool { return true } -func pathsEqual(t *testing.T, expected, actual []*PathV2) bool { +func pathsEqual(t *testing.T, expected, actual []*Path) bool { if len(expected) != len(actual) { return false } @@ -67,7 +67,7 @@ func pathsEqual(t *testing.T, expected, actual []*PathV2) bool { return true } -func pathEqual(t *testing.T, expected, actual *PathV2) bool { +func pathEqual(t *testing.T, expected, actual *Path) bool { if expected.FromChain.ChainID != actual.FromChain.ChainID { t.Logf("expected chain ID '%d' , actual chain ID '%d'", expected.FromChain.ChainID, actual.FromChain.ChainID) return false @@ -83,7 +83,7 @@ func pathEqual(t *testing.T, expected, actual *PathV2) bool { return true } -func TestSetupRouteValidationMapsV2(t *testing.T) { +func TestSetupRouteValidationMaps(t *testing.T) { tests := []struct { name string fromLockedAmount map[uint64]*hexutil.Big @@ -161,53 +161,53 @@ func TestSetupRouteValidationMapsV2(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - included, excluded := setupRouteValidationMapsV2(tt.fromLockedAmount) + included, excluded := setupRouteValidationMaps(tt.fromLockedAmount) assert.Equal(t, tt.expectedIncluded, included) assert.Equal(t, tt.expectedExcluded, excluded) }) } } -func TestCalculateRestAmountInV2(t *testing.T) { +func TestCalculateRestAmountIn(t *testing.T) { tests := []struct { name string - route []*PathV2 - excludePath *PathV2 + route []*Path + excludePath *Path expected *big.Int }{ { name: "Exclude pathC1A1", - route: []*PathV2{pathC1A1, pathC2A2, pathC3A3}, + route: []*Path{pathC1A1, pathC2A2, pathC3A3}, excludePath: pathC1A1, expected: big.NewInt(500), // 200 + 300 }, { name: "Exclude pathC2A2", - route: []*PathV2{pathC1A1, pathC2A2, pathC3A3}, + route: []*Path{pathC1A1, pathC2A2, pathC3A3}, excludePath: pathC2A2, expected: big.NewInt(400), // 100 + 300 }, { name: "Exclude pathC3A3", - route: []*PathV2{pathC1A1, pathC2A2, pathC3A3}, + route: []*Path{pathC1A1, pathC2A2, pathC3A3}, excludePath: pathC3A3, expected: big.NewInt(300), // 100 + 200 }, { name: "Single path, exclude that path", - route: []*PathV2{pathC1A1}, + route: []*Path{pathC1A1}, excludePath: pathC1A1, expected: big.NewInt(0), // No other paths }, { name: "Empty route", - route: []*PathV2{}, + route: []*Path{}, excludePath: pathC1A1, expected: big.NewInt(0), // No paths }, { name: "Empty route, with nil exclude", - route: []*PathV2{}, + route: []*Path{}, excludePath: nil, expected: big.NewInt(0), // No paths }, @@ -215,65 +215,65 @@ func TestCalculateRestAmountInV2(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - result := calculateRestAmountInV2(tt.route, tt.excludePath) + result := calculateRestAmountIn(tt.route, tt.excludePath) assert.Equal(t, tt.expected, result) }) } } -func TestIsValidForNetworkComplianceV2(t *testing.T) { +func TestIsValidForNetworkCompliance(t *testing.T) { tests := []struct { name string - route []*PathV2 + route []*Path fromIncluded map[uint64]bool fromExcluded map[uint64]bool expectedResult bool }{ { name: "Route with all included chain IDs", - route: []*PathV2{pathC1A1, pathC2A2}, + route: []*Path{pathC1A1, pathC2A2}, fromIncluded: map[uint64]bool{1: true, 2: true}, fromExcluded: map[uint64]bool{}, expectedResult: true, }, { name: "Route with fromExcluded only", - route: []*PathV2{pathC1A1, pathC2A2}, + route: []*Path{pathC1A1, pathC2A2}, fromIncluded: map[uint64]bool{}, fromExcluded: map[uint64]bool{3: false, 4: false}, expectedResult: true, }, { name: "Route without excluded chain IDs", - route: []*PathV2{pathC1A1, pathC2A2}, + route: []*Path{pathC1A1, pathC2A2}, fromIncluded: map[uint64]bool{1: false, 2: false}, fromExcluded: map[uint64]bool{3: false, 4: false}, expectedResult: true, }, { name: "Route with an excluded chain ID", - route: []*PathV2{pathC1A1, pathC3A3}, + route: []*Path{pathC1A1, pathC3A3}, fromIncluded: map[uint64]bool{1: false, 2: false}, fromExcluded: map[uint64]bool{3: false, 4: false}, expectedResult: false, }, { name: "Route missing one included chain ID", - route: []*PathV2{pathC1A1}, + route: []*Path{pathC1A1}, fromIncluded: map[uint64]bool{1: false, 2: false}, fromExcluded: map[uint64]bool{}, expectedResult: false, }, { name: "Route with no fromIncluded or fromExcluded", - route: []*PathV2{pathC1A1, pathC2A2}, + route: []*Path{pathC1A1, pathC2A2}, fromIncluded: map[uint64]bool{}, fromExcluded: map[uint64]bool{}, expectedResult: true, }, { name: "Empty route", - route: []*PathV2{}, + route: []*Path{}, fromIncluded: map[uint64]bool{1: false, 2: false}, fromExcluded: map[uint64]bool{3: false, 4: false}, expectedResult: false, @@ -282,23 +282,23 @@ func TestIsValidForNetworkComplianceV2(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - result := isValidForNetworkComplianceV2(tt.route, tt.fromIncluded, tt.fromExcluded) + result := isValidForNetworkCompliance(tt.route, tt.fromIncluded, tt.fromExcluded) assert.Equal(t, tt.expectedResult, result) }) } } -func TestHasSufficientCapacityV2(t *testing.T) { +func TestHasSufficientCapacity(t *testing.T) { tests := []struct { name string - route []*PathV2 + route []*Path amountIn *big.Int fromLockedAmount map[uint64]*hexutil.Big expected bool }{ { name: "All paths meet required amount", - route: []*PathV2{pathC1A1, pathC2A2, pathC3A3}, + route: []*Path{pathC1A1, pathC2A2, pathC3A3}, amountIn: big.NewInt(600), fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1, 2: &amount2, 3: &amount3}, expected: true, @@ -308,7 +308,7 @@ func TestHasSufficientCapacityV2(t *testing.T) { /* { name: "A path does not meet required amount", - route: []*PathV2{pathC1A1, pathC2A2, pathC3A3}, + route: []*Path{pathC1A1, pathC2A2, pathC3A3}, amountIn: big.NewInt(600), fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1, 2: &amount2, 4: &amount4}, expected: false, @@ -316,42 +316,42 @@ func TestHasSufficientCapacityV2(t *testing.T) { */ { name: "No fromLockedAmount", - route: []*PathV2{pathC1A1, pathC2A2, pathC3A3}, + route: []*Path{pathC1A1, pathC2A2, pathC3A3}, amountIn: big.NewInt(600), fromLockedAmount: map[uint64]*hexutil.Big{}, expected: true, }, { name: "Single path meets required amount", - route: []*PathV2{pathC1A1}, + route: []*Path{pathC1A1}, amountIn: big.NewInt(100), fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1}, expected: true, }, { name: "Single path does not meet required amount", - route: []*PathV2{pathC1A1}, + route: []*Path{pathC1A1}, amountIn: big.NewInt(200), fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1}, expected: false, }, { name: "Path meets required amount with excess", - route: []*PathV2{pathC1A1, pathC2A2}, + route: []*Path{pathC1A1, pathC2A2}, amountIn: big.NewInt(250), fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1, 2: &amount2}, expected: true, }, { name: "Path does not meet required amount due to insufficient rest", - route: []*PathV2{pathC1A1, pathC2A2, pathC4A4}, + route: []*Path{pathC1A1, pathC2A2, pathC4A4}, amountIn: big.NewInt(800), fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1, 4: &amount4}, expected: false, }, { name: "Empty route", - route: []*PathV2{}, + route: []*Path{}, amountIn: big.NewInt(500), fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1, 2: &amount2}, expected: true, @@ -360,22 +360,22 @@ func TestHasSufficientCapacityV2(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - result := hasSufficientCapacityV2(tt.route, tt.amountIn, tt.fromLockedAmount) + result := hasSufficientCapacity(tt.route, tt.amountIn, tt.fromLockedAmount) assert.Equal(t, tt.expected, result) }) } } -func TestFilterNetworkComplianceV2(t *testing.T) { +func TestFilterNetworkCompliance(t *testing.T) { tests := []struct { name string - routes [][]*PathV2 + routes [][]*Path fromLockedAmount map[uint64]*hexutil.Big - expected [][]*PathV2 + expected [][]*Path }{ { name: "Mixed routes with valid and invalid paths", - routes: [][]*PathV2{ + routes: [][]*Path{ { {FromChain: network1}, {FromChain: network3}, @@ -394,7 +394,7 @@ func TestFilterNetworkComplianceV2(t *testing.T) { 1: (*hexutil.Big)(big.NewInt(100)), 2: (*hexutil.Big)(big.NewInt(0)), }, - expected: [][]*PathV2{ + expected: [][]*Path{ { {FromChain: network1}, {FromChain: network3}, @@ -403,7 +403,7 @@ func TestFilterNetworkComplianceV2(t *testing.T) { }, { name: "All valid routes", - routes: [][]*PathV2{ + routes: [][]*Path{ { {FromChain: network1}, {FromChain: network3}, @@ -416,7 +416,7 @@ func TestFilterNetworkComplianceV2(t *testing.T) { fromLockedAmount: map[uint64]*hexutil.Big{ 1: (*hexutil.Big)(big.NewInt(100)), }, - expected: [][]*PathV2{ + expected: [][]*Path{ { {FromChain: network1}, {FromChain: network3}, @@ -429,7 +429,7 @@ func TestFilterNetworkComplianceV2(t *testing.T) { }, { name: "All invalid routes", - routes: [][]*PathV2{ + routes: [][]*Path{ { {FromChain: network2}, {FromChain: network3}, @@ -443,19 +443,19 @@ func TestFilterNetworkComplianceV2(t *testing.T) { 1: (*hexutil.Big)(big.NewInt(100)), 2: (*hexutil.Big)(big.NewInt(0)), }, - expected: [][]*PathV2{}, + expected: [][]*Path{}, }, { name: "Empty routes", - routes: [][]*PathV2{}, + routes: [][]*Path{}, fromLockedAmount: map[uint64]*hexutil.Big{ 1: (*hexutil.Big)(big.NewInt(100)), }, - expected: [][]*PathV2{}, + expected: [][]*Path{}, }, { name: "No locked amounts", - routes: [][]*PathV2{ + routes: [][]*Path{ { {FromChain: network1}, {FromChain: network2}, @@ -466,7 +466,7 @@ func TestFilterNetworkComplianceV2(t *testing.T) { }, }, fromLockedAmount: map[uint64]*hexutil.Big{}, - expected: [][]*PathV2{ + expected: [][]*Path{ { {FromChain: network1}, {FromChain: network2}, @@ -479,7 +479,7 @@ func TestFilterNetworkComplianceV2(t *testing.T) { }, { name: "Single route with mixed valid and invalid paths", - routes: [][]*PathV2{ + routes: [][]*Path{ { {FromChain: network1}, {FromChain: network2}, @@ -490,11 +490,11 @@ func TestFilterNetworkComplianceV2(t *testing.T) { 1: (*hexutil.Big)(big.NewInt(100)), 2: (*hexutil.Big)(big.NewInt(0)), }, - expected: [][]*PathV2{}, + expected: [][]*Path{}, }, { name: "Routes with duplicate chain IDs", - routes: [][]*PathV2{ + routes: [][]*Path{ { {FromChain: network1}, {FromChain: network1}, @@ -504,7 +504,7 @@ func TestFilterNetworkComplianceV2(t *testing.T) { fromLockedAmount: map[uint64]*hexutil.Big{ 1: (*hexutil.Big)(big.NewInt(100)), }, - expected: [][]*PathV2{ + expected: [][]*Path{ { {FromChain: network1}, {FromChain: network1}, @@ -514,7 +514,7 @@ func TestFilterNetworkComplianceV2(t *testing.T) { }, { name: "Minimum and maximum chain IDs", - routes: [][]*PathV2{ + routes: [][]*Path{ { {FromChain: ¶ms.Network{ChainID: 0}}, {FromChain: ¶ms.Network{ChainID: ^uint64(0)}}, @@ -524,7 +524,7 @@ func TestFilterNetworkComplianceV2(t *testing.T) { 0: (*hexutil.Big)(big.NewInt(100)), ^uint64(0): (*hexutil.Big)(big.NewInt(100)), }, - expected: [][]*PathV2{ + expected: [][]*Path{ { {FromChain: ¶ms.Network{ChainID: 0}}, {FromChain: ¶ms.Network{ChainID: ^uint64(0)}}, @@ -533,10 +533,10 @@ func TestFilterNetworkComplianceV2(t *testing.T) { }, { name: "Large number of routes", - routes: func() [][]*PathV2 { - var routes [][]*PathV2 + routes: func() [][]*Path { + var routes [][]*Path for i := 0; i < 1000; i++ { - routes = append(routes, []*PathV2{ + routes = append(routes, []*Path{ {FromChain: ¶ms.Network{ChainID: uint64(i + 1)}}, {FromChain: ¶ms.Network{ChainID: uint64(i + 1001)}}, }) @@ -547,10 +547,10 @@ func TestFilterNetworkComplianceV2(t *testing.T) { 1: (*hexutil.Big)(big.NewInt(100)), 1001: (*hexutil.Big)(big.NewInt(100)), }, - expected: func() [][]*PathV2 { - var routes [][]*PathV2 + expected: func() [][]*Path { + var routes [][]*Path for i := 0; i < 1; i++ { - routes = append(routes, []*PathV2{ + routes = append(routes, []*Path{ {FromChain: ¶ms.Network{ChainID: uint64(i + 1)}}, {FromChain: ¶ms.Network{ChainID: uint64(i + 1001)}}, }) @@ -560,7 +560,7 @@ func TestFilterNetworkComplianceV2(t *testing.T) { }, { name: "Routes with missing data", - routes: [][]*PathV2{ + routes: [][]*Path{ { {FromChain: nil}, {FromChain: network2}, @@ -574,11 +574,11 @@ func TestFilterNetworkComplianceV2(t *testing.T) { 1: (*hexutil.Big)(big.NewInt(100)), 2: (*hexutil.Big)(big.NewInt(0)), }, - expected: [][]*PathV2{}, + expected: [][]*Path{}, }, { name: "Consistency check", - routes: [][]*PathV2{ + routes: [][]*Path{ { {FromChain: network1}, {FromChain: network2}, @@ -591,7 +591,7 @@ func TestFilterNetworkComplianceV2(t *testing.T) { fromLockedAmount: map[uint64]*hexutil.Big{ 1: (*hexutil.Big)(big.NewInt(100)), }, - expected: [][]*PathV2{ + expected: [][]*Path{ { {FromChain: network1}, {FromChain: network2}, @@ -604,101 +604,101 @@ func TestFilterNetworkComplianceV2(t *testing.T) { }, { name: "Routes without excluded chain IDs, missing included path", - routes: [][]*PathV2{ + routes: [][]*Path{ {pathC1A1, pathC2A2}, {pathC2A2, pathC3A3}, }, fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1, 2: &amount2}, - expected: [][]*PathV2{ + expected: [][]*Path{ {pathC1A1, pathC2A2}, }, }, { name: "Routes with an excluded chain ID", - routes: [][]*PathV2{ + routes: [][]*Path{ {pathC1A1, pathC2A2}, {pathC2A2, pathC3A3, path0}, }, fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1, 2: &amount2, 4: &amount0}, - expected: [][]*PathV2{ + expected: [][]*Path{ {pathC1A1, pathC2A2}, }, }, { name: "Routes with all included chain IDs", - routes: [][]*PathV2{ + routes: [][]*Path{ {pathC1A1, pathC2A2, pathC3A3}, }, fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1, 2: &amount2, 3: &amount3}, - expected: [][]*PathV2{ + expected: [][]*Path{ {pathC1A1, pathC2A2, pathC3A3}, }, }, { name: "Routes missing one included chain ID", - routes: [][]*PathV2{ + routes: [][]*Path{ {pathC1A1, pathC2A2}, {pathC1A1}, }, fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1, 2: &amount2, 3: &amount3}, - expected: [][]*PathV2{}, + expected: [][]*Path{}, }, { name: "Routes with no fromLockedAmount", - routes: [][]*PathV2{ + routes: [][]*Path{ {pathC1A1, pathC2A2}, {pathC2A2, pathC3A3}, }, fromLockedAmount: map[uint64]*hexutil.Big{}, - expected: [][]*PathV2{ + expected: [][]*Path{ {pathC1A1, pathC2A2}, {pathC2A2, pathC3A3}, }, }, { name: "Routes with fromExcluded only", - routes: [][]*PathV2{ + routes: [][]*Path{ {pathC1A1, pathC2A2}, {pathC2A2, pathC3A3}, }, fromLockedAmount: map[uint64]*hexutil.Big{4: &amount0}, - expected: [][]*PathV2{ + expected: [][]*Path{ {pathC1A1, pathC2A2}, {pathC2A2, pathC3A3}, }, }, { name: "Routes with all excluded chain IDs", - routes: [][]*PathV2{ + routes: [][]*Path{ {path0, pathC1A1}, {path0, pathC2A2}, }, fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1, 2: &amount2, 3: &amount3, 4: &amount0}, - expected: [][]*PathV2{}, + expected: [][]*Path{}, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { t.Logf("Original Routes: %+v\n", tt.routes) - filteredRoutes := filterNetworkComplianceV2(tt.routes, tt.fromLockedAmount) + filteredRoutes := filterNetworkCompliance(tt.routes, tt.fromLockedAmount) t.Logf("Filtered Routes: %+v\n", filteredRoutes) assert.Equal(t, tt.expected, filteredRoutes) }) } } -func TestFilterCapacityValidationV2(t *testing.T) { +func TestFilterCapacityValidation(t *testing.T) { tests := []struct { name string - routes [][]*PathV2 + routes [][]*Path amountIn *big.Int fromLockedAmount map[uint64]*hexutil.Big - expectedRoutes [][]*PathV2 + expectedRoutes [][]*Path }{ { name: "Sufficient capacity with multiple paths", - routes: [][]*PathV2{ + routes: [][]*Path{ { {FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(50))}, {FromChain: network2, AmountIn: (*hexutil.Big)(big.NewInt(100))}, @@ -717,7 +717,7 @@ func TestFilterCapacityValidationV2(t *testing.T) { fromLockedAmount: map[uint64]*hexutil.Big{ 1: (*hexutil.Big)(big.NewInt(50)), }, - expectedRoutes: [][]*PathV2{ + expectedRoutes: [][]*Path{ { {FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(50))}, {FromChain: network2, AmountIn: (*hexutil.Big)(big.NewInt(100))}, @@ -731,7 +731,7 @@ func TestFilterCapacityValidationV2(t *testing.T) { }, { name: "Insufficient capacity", - routes: [][]*PathV2{ + routes: [][]*Path{ { {FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(100))}, {FromChain: network2, AmountIn: (*hexutil.Big)(big.NewInt(50))}, @@ -742,11 +742,11 @@ func TestFilterCapacityValidationV2(t *testing.T) { 1: (*hexutil.Big)(big.NewInt(50)), 2: (*hexutil.Big)(big.NewInt(50)), }, - expectedRoutes: [][]*PathV2{}, + expectedRoutes: [][]*Path{}, }, { name: "Exact capacity match", - routes: [][]*PathV2{ + routes: [][]*Path{ { {FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(100))}, {FromChain: network2, AmountIn: (*hexutil.Big)(big.NewInt(50))}, @@ -757,7 +757,7 @@ func TestFilterCapacityValidationV2(t *testing.T) { 1: (*hexutil.Big)(big.NewInt(100)), 2: (*hexutil.Big)(big.NewInt(50)), }, - expectedRoutes: [][]*PathV2{ + expectedRoutes: [][]*Path{ { {FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(100))}, {FromChain: network2, AmountIn: (*hexutil.Big)(big.NewInt(50))}, @@ -766,7 +766,7 @@ func TestFilterCapacityValidationV2(t *testing.T) { }, { name: "No locked amounts", - routes: [][]*PathV2{ + routes: [][]*Path{ { {FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(100))}, {FromChain: network2, AmountIn: (*hexutil.Big)(big.NewInt(50))}, @@ -774,7 +774,7 @@ func TestFilterCapacityValidationV2(t *testing.T) { }, amountIn: big.NewInt(150), fromLockedAmount: map[uint64]*hexutil.Big{}, - expectedRoutes: [][]*PathV2{ + expectedRoutes: [][]*Path{ { {FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(100))}, {FromChain: network2, AmountIn: (*hexutil.Big)(big.NewInt(50))}, @@ -783,7 +783,7 @@ func TestFilterCapacityValidationV2(t *testing.T) { }, { name: "Single route with sufficient capacity", - routes: [][]*PathV2{ + routes: [][]*Path{ { {FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(50))}, {FromChain: network2, AmountIn: (*hexutil.Big)(big.NewInt(100))}, @@ -793,7 +793,7 @@ func TestFilterCapacityValidationV2(t *testing.T) { fromLockedAmount: map[uint64]*hexutil.Big{ 1: (*hexutil.Big)(big.NewInt(50)), }, - expectedRoutes: [][]*PathV2{ + expectedRoutes: [][]*Path{ { {FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(50))}, {FromChain: network2, AmountIn: (*hexutil.Big)(big.NewInt(100))}, @@ -802,7 +802,7 @@ func TestFilterCapacityValidationV2(t *testing.T) { }, { name: "Single route with inappropriately locked amount", - routes: [][]*PathV2{ + routes: [][]*Path{ { {FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(100))}, }, @@ -811,11 +811,11 @@ func TestFilterCapacityValidationV2(t *testing.T) { fromLockedAmount: map[uint64]*hexutil.Big{ 1: (*hexutil.Big)(big.NewInt(50)), }, - expectedRoutes: [][]*PathV2{}, + expectedRoutes: [][]*Path{}, }, { name: "Single route with insufficient capacity", - routes: [][]*PathV2{ + routes: [][]*Path{ { {FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(50))}, }, @@ -824,20 +824,20 @@ func TestFilterCapacityValidationV2(t *testing.T) { fromLockedAmount: map[uint64]*hexutil.Big{ 1: (*hexutil.Big)(big.NewInt(50)), }, - expectedRoutes: [][]*PathV2{}, + expectedRoutes: [][]*Path{}, }, { name: "Empty routes", - routes: [][]*PathV2{}, + routes: [][]*Path{}, amountIn: big.NewInt(150), fromLockedAmount: map[uint64]*hexutil.Big{ 1: (*hexutil.Big)(big.NewInt(50)), }, - expectedRoutes: [][]*PathV2{}, + expectedRoutes: [][]*Path{}, }, { name: "Partial locked amounts", - routes: [][]*PathV2{ + routes: [][]*Path{ { {FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(50))}, {FromChain: network3, AmountIn: (*hexutil.Big)(big.NewInt(100))}, @@ -850,7 +850,7 @@ func TestFilterCapacityValidationV2(t *testing.T) { 2: (*hexutil.Big)(big.NewInt(0)), // Excluded path 3: (*hexutil.Big)(big.NewInt(100)), }, - expectedRoutes: [][]*PathV2{ + expectedRoutes: [][]*Path{ { {FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(50))}, {FromChain: network3, AmountIn: (*hexutil.Big)(big.NewInt(100))}, @@ -860,7 +860,7 @@ func TestFilterCapacityValidationV2(t *testing.T) { }, { name: "Mixed networks with sufficient capacity", - routes: [][]*PathV2{ + routes: [][]*Path{ { {FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(100))}, {FromChain: network3, AmountIn: (*hexutil.Big)(big.NewInt(200))}, @@ -871,7 +871,7 @@ func TestFilterCapacityValidationV2(t *testing.T) { 1: (*hexutil.Big)(big.NewInt(100)), 3: (*hexutil.Big)(big.NewInt(200)), }, - expectedRoutes: [][]*PathV2{ + expectedRoutes: [][]*Path{ { {FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(100))}, {FromChain: network3, AmountIn: (*hexutil.Big)(big.NewInt(200))}, @@ -880,7 +880,7 @@ func TestFilterCapacityValidationV2(t *testing.T) { }, { name: "Mixed networks with insufficient capacity", - routes: [][]*PathV2{ + routes: [][]*Path{ { {FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(100))}, {FromChain: network3, AmountIn: (*hexutil.Big)(big.NewInt(100))}, @@ -891,13 +891,13 @@ func TestFilterCapacityValidationV2(t *testing.T) { 1: (*hexutil.Big)(big.NewInt(50)), 3: (*hexutil.Big)(big.NewInt(100)), }, - expectedRoutes: [][]*PathV2{}, + expectedRoutes: [][]*Path{}, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - filteredRoutes := filterCapacityValidationV2(tt.routes, tt.amountIn, tt.fromLockedAmount) + filteredRoutes := filterCapacityValidation(tt.routes, tt.amountIn, tt.fromLockedAmount) if !routesEqual(t, tt.expectedRoutes, filteredRoutes) { t.Errorf("Expected: %+v, Actual: %+v", tt.expectedRoutes, filteredRoutes) } @@ -905,53 +905,53 @@ func TestFilterCapacityValidationV2(t *testing.T) { } } -func TestFilterRoutesV2(t *testing.T) { +func TestFilterRoutes(t *testing.T) { tests := []struct { name string - routes [][]*PathV2 + routes [][]*Path amountIn *big.Int fromLockedAmount map[uint64]*hexutil.Big - expectedRoutes [][]*PathV2 + expectedRoutes [][]*Path }{ { name: "Empty fromLockedAmount and routes don't match amountIn", - routes: [][]*PathV2{ + routes: [][]*Path{ {pathC1A1, pathC2A2}, {pathC3A3, pathC4A4}, }, amountIn: big.NewInt(150), fromLockedAmount: map[uint64]*hexutil.Big{}, - expectedRoutes: [][]*PathV2{}, + expectedRoutes: [][]*Path{}, }, { name: "Empty fromLockedAmount and sigle route match amountIn", - routes: [][]*PathV2{ + routes: [][]*Path{ {pathC1A1, pathC2A2}, {pathC3A3, pathC4A4}, }, amountIn: big.NewInt(300), fromLockedAmount: map[uint64]*hexutil.Big{}, - expectedRoutes: [][]*PathV2{ + expectedRoutes: [][]*Path{ {pathC1A1, pathC2A2}, }, }, { name: "Empty fromLockedAmount and more routes match amountIn", - routes: [][]*PathV2{ + routes: [][]*Path{ {pathC1A1, pathC2A2}, {pathC3A3, pathC4A4}, {pathC1A1, pathC2A1, pathC3A1}, }, amountIn: big.NewInt(300), fromLockedAmount: map[uint64]*hexutil.Big{}, - expectedRoutes: [][]*PathV2{ + expectedRoutes: [][]*Path{ {pathC1A1, pathC2A2}, {pathC1A1, pathC2A1, pathC3A1}, }, }, { name: "All paths appear in fromLockedAmount but not within a single route", - routes: [][]*PathV2{ + routes: [][]*Path{ {pathC1A1, pathC3A3}, {pathC2A2, pathC4A4}, }, @@ -962,11 +962,11 @@ func TestFilterRoutesV2(t *testing.T) { 3: &amount3, 4: &amount4, }, - expectedRoutes: [][]*PathV2{}, + expectedRoutes: [][]*Path{}, }, { name: "Mixed valid and invalid routes I", - routes: [][]*PathV2{ + routes: [][]*Path{ {pathC1A1, pathC2A2}, {pathC2A2, pathC3A3}, {pathC1A1, pathC4A4}, @@ -977,13 +977,13 @@ func TestFilterRoutesV2(t *testing.T) { 1: &amount1, 2: &amount2, }, - expectedRoutes: [][]*PathV2{ + expectedRoutes: [][]*Path{ {pathC1A1, pathC2A2}, }, }, { name: "Mixed valid and invalid routes II", - routes: [][]*PathV2{ + routes: [][]*Path{ {pathC1A1, pathC2A2}, {pathC2A2, pathC3A3}, {pathC1A1, pathC4A4}, @@ -993,14 +993,14 @@ func TestFilterRoutesV2(t *testing.T) { fromLockedAmount: map[uint64]*hexutil.Big{ 1: &amount1, }, - expectedRoutes: [][]*PathV2{ + expectedRoutes: [][]*Path{ {pathC1A1, pathC2A2}, {pathC1A1, pathC2A1, pathC3A1}, }, }, { name: "All invalid routes", - routes: [][]*PathV2{ + routes: [][]*Path{ {pathC2A2, pathC3A3}, {pathC4A4, pathC5A5}, }, @@ -1008,11 +1008,11 @@ func TestFilterRoutesV2(t *testing.T) { fromLockedAmount: map[uint64]*hexutil.Big{ 1: &amount1, }, - expectedRoutes: [][]*PathV2{}, + expectedRoutes: [][]*Path{}, }, { name: "Single valid route", - routes: [][]*PathV2{ + routes: [][]*Path{ {pathC1A1, pathC3A3}, {pathC2A2, pathC3A3}, }, @@ -1021,13 +1021,13 @@ func TestFilterRoutesV2(t *testing.T) { 1: &amount1, 3: &amount3, }, - expectedRoutes: [][]*PathV2{ + expectedRoutes: [][]*Path{ {pathC1A1, pathC3A3}, }, }, { name: "Route with mixed valid and invalid paths I", - routes: [][]*PathV2{ + routes: [][]*Path{ {pathC1A1, pathC2A2, pathC3A3}, }, amountIn: big.NewInt(300), @@ -1035,11 +1035,11 @@ func TestFilterRoutesV2(t *testing.T) { 1: &amount1, 2: &amount0, // This path should be filtered out due to being excluded via a zero amount }, - expectedRoutes: [][]*PathV2{}, + expectedRoutes: [][]*Path{}, }, { name: "Route with mixed valid and invalid paths II", - routes: [][]*PathV2{ + routes: [][]*Path{ {pathC1A1, pathC3A3}, }, amountIn: big.NewInt(400), @@ -1047,13 +1047,13 @@ func TestFilterRoutesV2(t *testing.T) { 1: &amount1, 2: &amount0, // This path should be filtered out due to being excluded via a zero amount, 0 value locked means this chain is disabled }, - expectedRoutes: [][]*PathV2{ + expectedRoutes: [][]*Path{ {pathC1A1, pathC3A3}, }, }, { name: "Route with mixed valid and invalid paths III", - routes: [][]*PathV2{ + routes: [][]*Path{ {pathC1A1, pathC3A3}, {pathC1A1, pathC3A2, pathC4A1}, }, @@ -1062,7 +1062,7 @@ func TestFilterRoutesV2(t *testing.T) { 1: &amount1, 2: &amount0, // This path should be filtered out due to being excluded via a zero amount, 0 value locked means this chain is disabled }, - expectedRoutes: [][]*PathV2{ + expectedRoutes: [][]*Path{ {pathC1A1, pathC3A3}, {pathC1A1, pathC3A2, pathC4A1}, }, @@ -1072,7 +1072,7 @@ func TestFilterRoutesV2(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { t.Logf("Original Routes: %+v\n", tt.routes) - filteredRoutes := filterRoutesV2(tt.routes, tt.amountIn, tt.fromLockedAmount) + filteredRoutes := filterRoutes(tt.routes, tt.amountIn, tt.fromLockedAmount) t.Logf("Filtered Routes: %+v\n", filteredRoutes) assert.Equal(t, tt.expectedRoutes, filteredRoutes) }) diff --git a/services/wallet/router/router_v2.go b/services/wallet/router/router.go similarity index 93% rename from services/wallet/router/router_v2.go rename to services/wallet/router/router.go index b0775258b..71b646650 100644 --- a/services/wallet/router/router_v2.go +++ b/services/wallet/router/router.go @@ -101,7 +101,7 @@ func makeBalanceKey(chainID uint64, symbol string) string { return fmt.Sprintf("%d-%s", chainID, symbol) } -type PathV2 struct { +type Path struct { ProcessorName string FromChain *params.Network // Source chain ToChain *params.Network // Destination chain @@ -147,32 +147,32 @@ type ProcessorError struct { Error error } -func (p *PathV2) Equal(o *PathV2) bool { +func (p *Path) Equal(o *Path) bool { return p.FromChain.ChainID == o.FromChain.ChainID && p.ToChain.ChainID == o.ToChain.ChainID } -type SuggestedRoutesV2 struct { +type SuggestedRoutes struct { Uuid string - Best []*PathV2 - Candidates []*PathV2 + Best []*Path + Candidates []*Path TokenPrice float64 NativeChainTokenPrice float64 } -type SuggestedRoutesV2Response struct { +type SuggestedRoutesResponse struct { Uuid string `json:"Uuid"` - Best []*PathV2 `json:"Best,omitempty"` - Candidates []*PathV2 `json:"Candidates,omitempty"` + Best []*Path `json:"Best,omitempty"` + Candidates []*Path `json:"Candidates,omitempty"` TokenPrice *float64 `json:"TokenPrice,omitempty"` NativeChainTokenPrice *float64 `json:"NativeChainTokenPrice,omitempty"` ErrorResponse *errors.ErrorResponse `json:"ErrorResponse,omitempty"` } -type GraphV2 []*NodeV2 +type Graph []*Node -type NodeV2 struct { - Path *PathV2 - Children GraphV2 +type Node struct { + Path *Path + Children Graph } type Router struct { @@ -222,15 +222,15 @@ func (r *Router) GetPathProcessors() map[string]pathprocessor.PathProcessor { return r.pathProcessors } -func newSuggestedRoutesV2( +func newSuggestedRoutes( uuid string, amountIn *big.Int, - candidates []*PathV2, + candidates []*Path, fromLockedAmount map[uint64]*hexutil.Big, tokenPrice float64, nativeChainTokenPrice float64, -) (*SuggestedRoutesV2, [][]*PathV2) { - suggestedRoutes := &SuggestedRoutesV2{ +) (*SuggestedRoutes, [][]*Path) { + suggestedRoutes := &SuggestedRoutes{ Uuid: uuid, Candidates: candidates, TokenPrice: tokenPrice, @@ -240,12 +240,12 @@ func newSuggestedRoutesV2( return suggestedRoutes, nil } - node := &NodeV2{ + node := &Node{ Path: nil, - Children: buildGraphV2(amountIn, candidates, 0, []uint64{}), + Children: buildGraph(amountIn, candidates, 0, []uint64{}), } - allRoutes := node.buildAllRoutesV2() - allRoutes = filterRoutesV2(allRoutes, amountIn, fromLockedAmount) + allRoutes := node.buildAllRoutes() + allRoutes = filterRoutes(allRoutes, amountIn, fromLockedAmount) if len(allRoutes) > 0 { sort.Slice(allRoutes, func(i, j int) bool { @@ -258,12 +258,12 @@ func newSuggestedRoutesV2( return suggestedRoutes, allRoutes } -func newNodeV2(path *PathV2) *NodeV2 { - return &NodeV2{Path: path, Children: make(GraphV2, 0)} +func newNode(path *Path) *Node { + return &Node{Path: path, Children: make(Graph, 0)} } -func buildGraphV2(AmountIn *big.Int, routes []*PathV2, level int, sourceChainIDs []uint64) GraphV2 { - graph := make(GraphV2, 0) +func buildGraph(AmountIn *big.Int, routes []*Path, level int, sourceChainIDs []uint64) Graph { + graph := make(Graph, 0) for _, route := range routes { found := false for _, chainID := range sourceChainIDs { @@ -275,9 +275,9 @@ func buildGraphV2(AmountIn *big.Int, routes []*PathV2, level int, sourceChainIDs if found { continue } - node := newNodeV2(route) + node := newNode(route) - newRoutes := make([]*PathV2, 0) + newRoutes := make([]*Path, 0) for _, r := range routes { if route.Equal(r) { continue @@ -290,7 +290,7 @@ func buildGraphV2(AmountIn *big.Int, routes []*PathV2, level int, sourceChainIDs newSourceChainIDs := make([]uint64, len(sourceChainIDs)) copy(newSourceChainIDs, sourceChainIDs) newSourceChainIDs = append(newSourceChainIDs, route.FromChain.ChainID) - node.Children = buildGraphV2(newAmountIn, newRoutes, level+1, newSourceChainIDs) + node.Children = buildGraph(newAmountIn, newRoutes, level+1, newSourceChainIDs) if len(node.Children) == 0 { continue @@ -303,18 +303,18 @@ func buildGraphV2(AmountIn *big.Int, routes []*PathV2, level int, sourceChainIDs return graph } -func (n NodeV2) buildAllRoutesV2() [][]*PathV2 { - res := make([][]*PathV2, 0) +func (n Node) buildAllRoutes() [][]*Path { + res := make([][]*Path, 0) if len(n.Children) == 0 && n.Path != nil { - res = append(res, []*PathV2{n.Path}) + res = append(res, []*Path{n.Path}) } for _, node := range n.Children { - for _, route := range node.buildAllRoutesV2() { + for _, route := range node.buildAllRoutes() { extendedRoute := route if n.Path != nil { - extendedRoute = append([]*PathV2{n.Path}, route...) + extendedRoute = append([]*Path{n.Path}, route...) } res = append(res, extendedRoute) } @@ -323,8 +323,8 @@ func (n NodeV2) buildAllRoutesV2() [][]*PathV2 { return res } -func findBestV2(routes [][]*PathV2, tokenPrice float64, nativeTokenPrice float64) []*PathV2 { - var best []*PathV2 +func findBest(routes [][]*Path, tokenPrice float64, nativeTokenPrice float64) []*Path { + var best []*Path bestCost := big.NewFloat(math.Inf(1)) for _, route := range routes { currentCost := big.NewFloat(0) @@ -503,11 +503,11 @@ func validateFromLockedAmount(input *RouteInputParams) error { return nil } -func (r *Router) SuggestedRoutesV2Async(input *RouteInputParams) { +func (r *Router) SuggestedRoutesAsync(input *RouteInputParams) { r.scheduler.Enqueue(routerTask, func(ctx context.Context) (interface{}, error) { - return r.SuggestedRoutesV2(ctx, input) + return r.SuggestedRoutes(ctx, input) }, func(result interface{}, taskType async.TaskType, err error) { - routesResponse := SuggestedRoutesV2Response{ + routesResponse := SuggestedRoutesResponse{ Uuid: input.Uuid, } @@ -516,7 +516,7 @@ func (r *Router) SuggestedRoutesV2Async(input *RouteInputParams) { routesResponse.ErrorResponse = errorResponse.(*errors.ErrorResponse) } - if suggestedRoutes, ok := result.(*SuggestedRoutesV2); ok && suggestedRoutes != nil { + if suggestedRoutes, ok := result.(*SuggestedRoutes); ok && suggestedRoutes != nil { routesResponse.Best = suggestedRoutes.Best routesResponse.Candidates = suggestedRoutes.Candidates routesResponse.TokenPrice = &suggestedRoutes.TokenPrice @@ -527,11 +527,11 @@ func (r *Router) SuggestedRoutesV2Async(input *RouteInputParams) { }) } -func (r *Router) StopSuggestedRoutesV2AsyncCalcualtion() { +func (r *Router) StopSuggestedRoutesAsyncCalculation() { r.scheduler.Stop() } -func (r *Router) SuggestedRoutesV2(ctx context.Context, input *RouteInputParams) (*SuggestedRoutesV2, error) { +func (r *Router) SuggestedRoutes(ctx context.Context, input *RouteInputParams) (*SuggestedRoutes, error) { testnetMode, err := r.rpcClient.NetworkManager.GetTestNetworksEnabled() if err != nil { return nil, errors.CreateErrorResponseFromError(err) @@ -860,7 +860,7 @@ func (r *Router) getSelectedChains(input *RouteInputParams) (selectedFromChains } func (r *Router) resolveCandidates(ctx context.Context, input *RouteInputParams, selectedFromChains []*params.Network, - selectedToChains []*params.Network, balanceMap map[string]*big.Int) (candidates []*PathV2, processorErrors []*ProcessorError, err error) { + selectedToChains []*params.Network, balanceMap map[string]*big.Int) (candidates []*Path, processorErrors []*ProcessorError, err error) { var ( testsMode = input.testsMode && input.testParams != nil group = async.NewAtomicGroup(ctx) @@ -873,7 +873,7 @@ func (r *Router) resolveCandidates(ctx context.Context, input *RouteInputParams, } appendProcessorErrorFn := func(processorName string, sendType SendType, fromChainID uint64, toChainID uint64, amount *big.Int, err error) { - log.Error("routerv2.resolveCandidates error", "processor", processorName, "sendType", sendType, "fromChainId: ", fromChainID, "toChainId", toChainID, "amount", amount, "err", err) + log.Error("router.resolveCandidates error", "processor", processorName, "sendType", sendType, "fromChainId: ", fromChainID, "toChainId", toChainID, "amount", amount, "err", err) mu.Lock() defer mu.Unlock() processorErrors = append(processorErrors, &ProcessorError{ @@ -882,7 +882,7 @@ func (r *Router) resolveCandidates(ctx context.Context, input *RouteInputParams, }) } - appendPathFn := func(path *PathV2) { + appendPathFn := func(path *Path) { mu.Lock() defer mu.Unlock() candidates = append(candidates, path) @@ -1080,7 +1080,7 @@ func (r *Router) resolveCandidates(ctx context.Context, input *RouteInputParams, requiredNativeBalance.Add(requiredNativeBalance, ethTotalFees) } - appendPathFn(&PathV2{ + appendPathFn(&Path{ ProcessorName: pProcessor.Name(), FromChain: network, ToChain: dest, @@ -1137,7 +1137,7 @@ func (r *Router) resolveCandidates(ctx context.Context, input *RouteInputParams, return candidates, processorErrors, nil } -func (r *Router) checkBalancesForTheBestRoute(ctx context.Context, bestRoute []*PathV2, balanceMap map[string]*big.Int) (hasPositiveBalance bool, err error) { +func (r *Router) checkBalancesForTheBestRoute(ctx context.Context, bestRoute []*Path, balanceMap map[string]*big.Int) (hasPositiveBalance bool, err error) { balanceMapCopy := copyMapGeneric(balanceMap, func(v interface{}) interface{} { return new(big.Int).Set(v.(*big.Int)) }).(map[string]*big.Int) @@ -1193,7 +1193,7 @@ func (r *Router) checkBalancesForTheBestRoute(ctx context.Context, bestRoute []* return hasPositiveBalance, nil } -func removeBestRouteFromAllRouters(allRoutes [][]*PathV2, best []*PathV2) [][]*PathV2 { +func removeBestRouteFromAllRouters(allRoutes [][]*Path, best []*Path) [][]*Path { for i := len(allRoutes) - 1; i >= 0; i-- { route := allRoutes[i] routeFound := true @@ -1234,7 +1234,7 @@ func getChainPriority(chainID uint64) int { } } -func getRoutePriority(route []*PathV2) int { +func getRoutePriority(route []*Path) int { priority := 0 for _, path := range route { priority += getChainPriority(path.FromChain.ChainID) @@ -1242,7 +1242,7 @@ func getRoutePriority(route []*PathV2) int { return priority } -func (r *Router) resolveRoutes(ctx context.Context, input *RouteInputParams, candidates []*PathV2, balanceMap map[string]*big.Int) (suggestedRoutes *SuggestedRoutesV2, err error) { +func (r *Router) resolveRoutes(ctx context.Context, input *RouteInputParams, candidates []*Path, balanceMap map[string]*big.Int) (suggestedRoutes *SuggestedRoutes, err error) { var prices map[string]float64 if input.testsMode { prices = input.testParams.tokenPrices @@ -1256,8 +1256,8 @@ func (r *Router) resolveRoutes(ctx context.Context, input *RouteInputParams, can tokenPrice := prices[input.TokenID] nativeTokenPrice := prices[pathprocessor.EthSymbol] - var allRoutes [][]*PathV2 - suggestedRoutes, allRoutes = newSuggestedRoutesV2(input.Uuid, input.AmountIn.ToInt(), candidates, input.FromLockedAmount, tokenPrice, nativeTokenPrice) + var allRoutes [][]*Path + suggestedRoutes, allRoutes = newSuggestedRoutes(input.Uuid, input.AmountIn.ToInt(), candidates, input.FromLockedAmount, tokenPrice, nativeTokenPrice) defer func() { if suggestedRoutes.Best != nil && len(suggestedRoutes.Best) > 0 { @@ -1270,13 +1270,13 @@ func (r *Router) resolveRoutes(ctx context.Context, input *RouteInputParams, can }() var ( - bestRoute []*PathV2 - lastBestRouteWithPositiveBalance []*PathV2 + bestRoute []*Path + lastBestRouteWithPositiveBalance []*Path lastBestRouteErr error ) for len(allRoutes) > 0 { - bestRoute = findBestV2(allRoutes, tokenPrice, nativeTokenPrice) + bestRoute = findBest(allRoutes, tokenPrice, nativeTokenPrice) var hasPositiveBalance bool hasPositiveBalance, err = r.checkBalancesForTheBestRoute(ctx, bestRoute, balanceMap) diff --git a/services/wallet/router/router_v2_test.go b/services/wallet/router/router_test.go similarity index 90% rename from services/wallet/router/router_v2_test.go rename to services/wallet/router/router_test.go index ae1e76a5d..a3fdb2ef2 100644 --- a/services/wallet/router/router_v2_test.go +++ b/services/wallet/router/router_test.go @@ -58,7 +58,7 @@ func amountOptionsMapsEqual(map1, map2 map[uint64][]amountOption) bool { return true } -func assertPathsEqual(t *testing.T, expected, actual []*PathV2) { +func assertPathsEqual(t *testing.T, expected, actual []*Path) { assert.Equal(t, len(expected), len(actual)) if len(expected) == 0 { return @@ -124,19 +124,19 @@ func setupRouter(t *testing.T) (*Router, func()) { return router, cleanTmpDb } -type suggestedRoutesV2ResponseEnvelope struct { - Type string `json:"type"` - Routes SuggestedRoutesV2Response `json:"event"` +type suggestedRoutesResponseEnvelope struct { + Type string `json:"type"` + Routes SuggestedRoutesResponse `json:"event"` } -func setupSignalHandler(t *testing.T) (chan SuggestedRoutesV2Response, func()) { - suggestedRoutesCh := make(chan SuggestedRoutesV2Response) +func setupSignalHandler(t *testing.T) (chan SuggestedRoutesResponse, func()) { + suggestedRoutesCh := make(chan SuggestedRoutesResponse) signalHandler := signal.MobileSignalHandler(func(data []byte) { var envelope signal.Envelope err := json.Unmarshal(data, &envelope) assert.NoError(t, err) if envelope.Type == string(signal.SuggestedRoutes) { - var response suggestedRoutesV2ResponseEnvelope + var response suggestedRoutesResponseEnvelope err := json.Unmarshal(data, &response) assert.NoError(t, err) @@ -153,7 +153,7 @@ func setupSignalHandler(t *testing.T) (chan SuggestedRoutesV2Response, func()) { return suggestedRoutesCh, closeFn } -func TestRouterV2(t *testing.T) { +func TestRouter(t *testing.T) { router, cleanTmpDb := setupRouter(t) defer cleanTmpDb() @@ -165,7 +165,7 @@ func TestRouterV2(t *testing.T) { // Test blocking endpoints for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - routes, err := router.SuggestedRoutesV2(context.Background(), tt.input) + routes, err := router.SuggestedRoutes(context.Background(), tt.input) if tt.expectedError != nil { assert.Error(t, err) @@ -184,7 +184,7 @@ func TestRouterV2(t *testing.T) { // Test async endpoints for _, tt := range tests { - router.SuggestedRoutesV2Async(tt.input) + router.SuggestedRoutesAsync(tt.input) select { case asyncRoutes := <-suggestedRoutesCh: @@ -198,7 +198,7 @@ func TestRouterV2(t *testing.T) { } } -func TestNoBalanceForTheBestRouteRouterV2(t *testing.T) { +func TestNoBalanceForTheBestRouteRouter(t *testing.T) { router, cleanTmpDb := setupRouter(t) defer cleanTmpDb() @@ -211,7 +211,7 @@ func TestNoBalanceForTheBestRouteRouterV2(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - routes, err := router.SuggestedRoutesV2(context.Background(), tt.input) + routes, err := router.SuggestedRoutes(context.Background(), tt.input) if tt.expectedError != nil { assert.Error(t, err) @@ -236,7 +236,7 @@ func TestNoBalanceForTheBestRouteRouterV2(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - router.SuggestedRoutesV2Async(tt.input) + router.SuggestedRoutesAsync(tt.input) select { case asyncRoutes := <-suggestedRoutesCh: diff --git a/services/wallet/router/router_v2_test_data.go b/services/wallet/router/router_test_data.go similarity index 98% rename from services/wallet/router/router_v2_test_data.go rename to services/wallet/router/router_test_data.go index b177c6d48..7fbed8675 100644 --- a/services/wallet/router/router_v2_test_data.go +++ b/services/wallet/router/router_test_data.go @@ -202,7 +202,7 @@ var defaultNetworks = []params.Network{ type normalTestParams struct { name string input *RouteInputParams - expectedCandidates []*PathV2 + expectedCandidates []*Path expectedError *errors.ErrorResponse } @@ -246,7 +246,7 @@ func getNormalTestParamsList() []normalTestParams { Code: errors.GenericErrorCode, Details: fmt.Sprintf("failed with 50000000 gas: insufficient funds for gas * price + value: address %s", common.HexToAddress("0x1")), }, - expectedCandidates: []*PathV2{}, + expectedCandidates: []*Path{}, }, { name: "ETH transfer - No Specific FromChain - No Specific ToChain - 0 AmountIn", @@ -275,7 +275,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorTransferName, FromChain: &mainnet, @@ -323,7 +323,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorTransferName, FromChain: &mainnet, @@ -409,7 +409,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorTransferName, FromChain: &mainnet, @@ -459,7 +459,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorTransferName, FromChain: &optimism, @@ -528,7 +528,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorTransferName, FromChain: &arbitrum, @@ -578,7 +578,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorTransferName, FromChain: &optimism, @@ -647,7 +647,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorTransferName, FromChain: &arbitrum, @@ -686,7 +686,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorBridgeHopName, FromChain: &arbitrum, @@ -725,7 +725,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorTransferName, FromChain: &arbitrum, @@ -764,7 +764,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorTransferName, FromChain: &mainnet, @@ -821,7 +821,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorBridgeHopName, FromChain: &arbitrum, @@ -862,7 +862,7 @@ func getNormalTestParamsList() []normalTestParams { }, }, expectedError: ErrNoBestRouteFound, - expectedCandidates: []*PathV2{}, + expectedCandidates: []*Path{}, }, { name: "ETH transfer - No Specific FromChain - No Specific ToChain - Single Chain LockedAmount", @@ -895,7 +895,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorTransferName, FromChain: &mainnet, @@ -994,7 +994,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorTransferName, FromChain: &optimism, @@ -1050,7 +1050,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorTransferName, FromChain: &mainnet, @@ -1149,7 +1149,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorTransferName, FromChain: &mainnet, @@ -1249,7 +1249,7 @@ func getNormalTestParamsList() []normalTestParams { }, }, expectedError: ErrLockedAmountLessThanSendAmountAllNetworks, - expectedCandidates: []*PathV2{}, + expectedCandidates: []*Path{}, }, { name: "ETH transfer - No Specific FromChain - No Specific ToChain - LockedAmount exceeds sending amount", @@ -1284,7 +1284,7 @@ func getNormalTestParamsList() []normalTestParams { }, }, expectedError: ErrLockedAmountExceedsTotalSendAmount, - expectedCandidates: []*PathV2{}, + expectedCandidates: []*Path{}, }, { name: "ERC20 transfer - No Specific FromChain - No Specific ToChain", @@ -1314,7 +1314,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorTransferName, FromChain: &mainnet, @@ -1400,7 +1400,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorTransferName, FromChain: &mainnet, @@ -1450,7 +1450,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorTransferName, FromChain: &optimism, @@ -1518,7 +1518,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorTransferName, FromChain: &arbitrum, @@ -1568,7 +1568,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorTransferName, FromChain: &optimism, @@ -1637,7 +1637,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorTransferName, FromChain: &arbitrum, @@ -1676,7 +1676,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorBridgeHopName, FromChain: &arbitrum, @@ -1715,7 +1715,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorTransferName, FromChain: &arbitrum, @@ -1754,7 +1754,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorTransferName, FromChain: &mainnet, @@ -1811,7 +1811,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorBridgeHopName, FromChain: &arbitrum, @@ -1851,7 +1851,7 @@ func getNormalTestParamsList() []normalTestParams { }, }, expectedError: ErrNoBestRouteFound, - expectedCandidates: []*PathV2{}, + expectedCandidates: []*Path{}, }, { name: "ERC20 transfer - All FromChains - No Locked Amount - Enough Token Balance Across All Chains", @@ -1881,7 +1881,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorTransferName, FromChain: &mainnet, @@ -2080,7 +2080,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorBridgeHopName, FromChain: &mainnet, @@ -2148,7 +2148,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorBridgeHopName, FromChain: &optimism, @@ -2192,7 +2192,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorBridgeHopName, FromChain: &mainnet, @@ -2248,7 +2248,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorBridgeHopName, FromChain: &arbitrum, @@ -2292,7 +2292,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorBridgeHopName, FromChain: &optimism, @@ -2350,7 +2350,7 @@ func getNormalTestParamsList() []normalTestParams { }, }, expectedError: ErrNoBestRouteFound, - expectedCandidates: []*PathV2{}, + expectedCandidates: []*Path{}, }, { name: "Bridge - Specific Single FromChain - Specific Single ToChain - Different Chains", @@ -2382,7 +2382,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorBridgeHopName, FromChain: &arbitrum, @@ -2422,7 +2422,7 @@ func getNormalTestParamsList() []normalTestParams { }, }, expectedError: ErrNoBestRouteFound, - expectedCandidates: []*PathV2{}, + expectedCandidates: []*Path{}, }, { name: "Bridge - Specific Multiple FromChain - Specific Multiple ToChain - Multiple Common Chains", @@ -2454,7 +2454,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorBridgeHopName, FromChain: &mainnet, @@ -2499,7 +2499,7 @@ func getNormalTestParamsList() []normalTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorBridgeHopName, FromChain: &arbitrum, @@ -2539,7 +2539,7 @@ func getNormalTestParamsList() []normalTestParams { }, }, expectedError: ErrNoBestRouteFound, - expectedCandidates: []*PathV2{}, + expectedCandidates: []*Path{}, }, { name: "ETH transfer - Not Enough Native Balance", @@ -2574,7 +2574,7 @@ func getNormalTestParamsList() []normalTestParams { Code: ErrNotEnoughNativeBalance.Code, Details: fmt.Sprintf(ErrNotEnoughNativeBalance.Details, pathprocessor.EthSymbol, walletCommon.EthereumMainnet), }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorBridgeHopName, FromChain: &mainnet, @@ -2616,7 +2616,7 @@ func getNormalTestParamsList() []normalTestParams { Code: ErrNotEnoughTokenBalance.Code, Details: fmt.Sprintf(ErrNotEnoughTokenBalance.Details, pathprocessor.UsdcSymbol, walletCommon.EthereumMainnet), }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorBridgeHopName, FromChain: &mainnet, @@ -2656,7 +2656,7 @@ func getNormalTestParamsList() []normalTestParams { }, }, expectedError: ErrLowAmountInForHopBridge, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorBridgeHopName, FromChain: &arbitrum, @@ -2671,8 +2671,8 @@ func getNormalTestParamsList() []normalTestParams { type noBalanceTestParams struct { name string input *RouteInputParams - expectedCandidates []*PathV2 - expectedBest []*PathV2 + expectedCandidates []*Path + expectedBest []*Path expectedError *errors.ErrorResponse } @@ -2747,7 +2747,7 @@ func getNoBalanceTestParamsList() []noBalanceTestParams { Code: ErrNotEnoughNativeBalance.Code, Details: fmt.Sprintf(ErrNotEnoughNativeBalance.Details, pathprocessor.EthSymbol, walletCommon.OptimismMainnet), }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorTransferName, FromChain: &optimism, @@ -2834,7 +2834,7 @@ func getNoBalanceTestParamsList() []noBalanceTestParams { Code: ErrNotEnoughNativeBalance.Code, Details: fmt.Sprintf(ErrNotEnoughNativeBalance.Details, pathprocessor.EthSymbol, walletCommon.ArbitrumMainnet), }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorBridgeHopName, FromChain: &mainnet, @@ -2888,7 +2888,7 @@ func getNoBalanceTestParamsList() []noBalanceTestParams { approvalL1Fee: testApprovalL1Fee, }, }, - expectedCandidates: []*PathV2{ + expectedCandidates: []*Path{ { ProcessorName: pathprocessor.ProcessorBridgeHopName, FromChain: &mainnet, @@ -2910,7 +2910,7 @@ func getNoBalanceTestParamsList() []noBalanceTestParams { ApprovalRequired: true, }, }, - expectedBest: []*PathV2{ + expectedBest: []*Path{ { ProcessorName: pathprocessor.ProcessorBridgeHopName, FromChain: &arbitrum,