From 661a31b36ee607c1d317f14fe1beb394bf029523 Mon Sep 17 00:00:00 2001 From: Brian Sztamfater Date: Tue, 21 Jan 2025 12:29:37 -0300 Subject: [PATCH] fix_: check if bridge for token exists in ToChainId before returning contract address for FromChainId Signed-off-by: Brian Sztamfater --- services/wallet/common/const.go | 1 + .../pathprocessor/processor_bridge_hop.go | 7 +++- .../router/pathprocessor/processor_test.go | 42 +++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/services/wallet/common/const.go b/services/wallet/common/const.go index 6ffbf59d5d1..47eaac178cb 100644 --- a/services/wallet/common/const.go +++ b/services/wallet/common/const.go @@ -22,6 +22,7 @@ const ( SttSymbol = "STT" UsdcSymbol = "USDC" HopSymbol = "HOP" + DaiSymbol = "DAI" ) type ChainID uint64 diff --git a/services/wallet/router/pathprocessor/processor_bridge_hop.go b/services/wallet/router/pathprocessor/processor_bridge_hop.go index e1eb1b6aff5..b60b6f63adb 100644 --- a/services/wallet/router/pathprocessor/processor_bridge_hop.go +++ b/services/wallet/router/pathprocessor/processor_bridge_hop.go @@ -154,7 +154,12 @@ func (h *HopBridgeProcessor) AvailableFor(params ProcessorInputParams) (bool, er if params.FromChain.ChainID == params.ToChain.ChainID { return false, ErrFromAndToChainsMustBeDifferent } - // We chcek if the contract is available on the network for the token + // We check if the contract is available on the receiver network for the token + if _, _, err := hop.GetContractAddress(params.ToChain.ChainID, params.FromToken.Symbol); err != nil { + return false, ErrToChainNotSupported + } + + // We check if the contract is available on the sender network for the token _, err := h.GetContractAddress(params) // toToken is not nil only if the send type is Swap return err == nil, err diff --git a/services/wallet/router/pathprocessor/processor_test.go b/services/wallet/router/pathprocessor/processor_test.go index 049da12105c..9f43fd55b85 100644 --- a/services/wallet/router/pathprocessor/processor_test.go +++ b/services/wallet/router/pathprocessor/processor_test.go @@ -45,6 +45,22 @@ var optimism = params.Network{ RelatedChainID: walletCommon.OptimismMainnet, } +var base = params.Network{ + ChainID: walletCommon.BaseMainnet, + ChainName: "Base", + BlockExplorerURL: "https://basescan.org", + IconURL: "network/Network=Base", + ChainColor: "#0052FF", + ShortName: "base", + NativeCurrencyName: "Ether", + NativeCurrencySymbol: "ETH", + NativeCurrencyDecimals: 18, + IsTest: false, + Layer: 2, + Enabled: true, + RelatedChainID: walletCommon.BaseMainnet, +} + var testEstimationMap = map[string]requests.Estimation{ pathProcessorCommon.ProcessorTransferName: {Value: uint64(1000)}, pathProcessorCommon.ProcessorBridgeHopName: {Value: uint64(5000)}, @@ -268,6 +284,32 @@ func TestPathProcessors(t *testing.T) { }, }, }, + { + name: "Different Chains Set - FormToken Set - No ToToken - Token Not Supported On ToChain", + input: ProcessorInputParams{ + TestsMode: true, + FromChain: &optimism, + ToChain: &base, + FromToken: &token.Token{ + Symbol: walletCommon.DaiSymbol, + }, + TestEstimationMap: testEstimationMap, + }, + expected: map[string]expectedResult{ + pathProcessorCommon.ProcessorTransferName: { + expected: false, + expectedError: nil, + }, + pathProcessorCommon.ProcessorBridgeHopName: { + expected: false, + expectedError: ErrToChainNotSupported, + }, + pathProcessorCommon.ProcessorSwapParaswapName: { + expected: false, + expectedError: ErrToAndFromTokensMustBeSet, + }, + }, + }, { name: "Different Chains Set - FormToken Set - ToToken Set - Different Tokens", input: ProcessorInputParams{