Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix_: check if bridge for token exists in ToChainId before returning contract address for FromChainId #6272

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 6 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,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
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
Loading