Skip to content

Commit

Permalink
fix_: check if bridge for token exists in ToChainId before returning …
Browse files Browse the repository at this point in the history
…contract address for FromChainId

Signed-off-by: Brian Sztamfater <brian@status.im>
  • Loading branch information
briansztamfater committed Jan 22, 2025
1 parent 27ad41b commit e69172c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
1 change: 1 addition & 0 deletions services/wallet/common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
SttSymbol = "STT"
UsdcSymbol = "USDC"
HopSymbol = "HOP"
DaiSymbol = "DAI"
)

type ChainID uint64
Expand Down
5 changes: 4 additions & 1 deletion services/wallet/router/pathprocessor/processor_bridge_hop.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ 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
if _, _, err := hop.GetContractAddress(params.ToChain.ChainID, params.FromToken.Symbol); err != nil {
return false, ErrToChainNotSupported
}

_, err := h.GetContractAddress(params)
// toToken is not nil only if the send type is Swap
return err == nil, err
Expand Down
42 changes: 42 additions & 0 deletions services/wallet/router/pathprocessor/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)},
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit e69172c

Please sign in to comment.