From 52181932b9e18957b9bd09b574ce49947ccf69fc Mon Sep 17 00:00:00 2001 From: Joe Huang Date: Tue, 12 Nov 2024 16:34:08 -0600 Subject: [PATCH 1/2] add helper function for fetching chainID from chain selector and test coverage (#74) * add helper function and test coverage * default handler --- aptos_test.go | 8 ++++++++ evm_test.go | 9 +++++++++ selectors.go | 33 +++++++++++++++++++++++++++++++++ solana_test.go | 9 +++++++++ 4 files changed, 59 insertions(+) diff --git a/aptos_test.go b/aptos_test.go index 9df5d80..23b25bb 100644 --- a/aptos_test.go +++ b/aptos_test.go @@ -69,3 +69,11 @@ func Test_AptosGetChainDetailsByChainIDAndFamily(t *testing.T) { assert.Equal(t, v, details) } } + +func Test_AptosGetChainIDByChainSelector(t *testing.T) { + for k, v := range aptosSelectorsMap { + chainID, err := GetChainIDFromSelector(v.ChainSelector) + assert.NoError(t, err) + assert.Equal(t, chainID, fmt.Sprintf("%v", k)) + } +} diff --git a/evm_test.go b/evm_test.go index 6691f74..69ed399 100644 --- a/evm_test.go +++ b/evm_test.go @@ -1,6 +1,7 @@ package chain_selectors import ( + "fmt" "math/rand" "strconv" "testing" @@ -235,3 +236,11 @@ func Test_EVMGetChainDetailsByChainIDAndFamily(t *testing.T) { assert.Equal(t, v, details) } } + +func Test_EVMGetChainIDByChainSelector(t *testing.T) { + for k, v := range evmSelectorsMap { + chainID, err := GetChainIDFromSelector(v.ChainSelector) + assert.NoError(t, err) + assert.Equal(t, chainID, fmt.Sprintf("%v", k)) + } +} diff --git a/selectors.go b/selectors.go index a163742..2c01945 100644 --- a/selectors.go +++ b/selectors.go @@ -35,6 +35,39 @@ func GetSelectorFamily(selector uint64) (string, error) { return "", fmt.Errorf("unknown chain selector %d", selector) } +func GetChainIDFromSelector(selector uint64) (string, error) { + destChainFamily, err := GetSelectorFamily(selector) + if err != nil { + return "", err + } + + var id uint64 + var destChainID string + switch destChainFamily { + case FamilyEVM: + id, err = ChainIdFromSelector(selector) + if err != nil { + return "", fmt.Errorf("failed to get %v chain ID from selector %d: %w", destChainFamily, selector, err) + } + destChainID = fmt.Sprintf("%d", id) + case FamilySolana: + destChainID, err = SolanaChainIdFromSelector(selector) + if err != nil { + return "", fmt.Errorf("failed to get %v chain ID from selector %d: %w", destChainFamily, selector, err) + } + case FamilyAptos: + id, err = AptosChainIdFromSelector(selector) + if err != nil { + return "", fmt.Errorf("failed to get %v chain ID from selector %d: %w", destChainFamily, selector, err) + } + destChainID = fmt.Sprintf("%d", id) + default: + return "", fmt.Errorf("selector %d is not supported", selector) + } + + return destChainID, nil +} + func GetChainDetailsByChainIDAndFamily(chainID string, family string) (ChainDetails, error) { switch family { case FamilyEVM: diff --git a/solana_test.go b/solana_test.go index 2efc164..6fda055 100644 --- a/solana_test.go +++ b/solana_test.go @@ -1,6 +1,7 @@ package chain_selectors import ( + "fmt" "math/rand" "testing" @@ -75,3 +76,11 @@ func Test_SolanaGetChainDetailsByChainIDAndFamily(t *testing.T) { assert.Equal(t, v, details) } } + +func Test_SolanaGetChainIDByChainSelector(t *testing.T) { + for k, v := range solanaSelectorsMap { + chainID, err := GetChainIDFromSelector(v.ChainSelector) + assert.NoError(t, err) + assert.Equal(t, chainID, fmt.Sprintf("%v", k)) + } +} From a7cb43605ba3b116539215a4f415e93c7624029a Mon Sep 17 00:00:00 2001 From: Kashif Date: Fri, 15 Nov 2024 01:19:08 +0900 Subject: [PATCH 2/2] Add Shibarium (#73) * Add Shibarium * Add generated --- generated_chains_evm.go | 4 ++++ selectors.yml | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/generated_chains_evm.go b/generated_chains_evm.go index 738027e..95f683d 100644 --- a/generated_chains_evm.go +++ b/generated_chains_evm.go @@ -139,6 +139,8 @@ var ( RONIN_TESTNET_SAIGON = Chain{EvmChainID: 2021, Selector: 13116810400804392105, Name: "ronin-testnet-saigon"} SEI_MAINNET = Chain{EvmChainID: 1329, Selector: 9027416829622342829, Name: "sei-mainnet"} SEI_TESTNET_ATLANTIC = Chain{EvmChainID: 1328, Selector: 1216300075444106652, Name: "sei-testnet-atlantic"} + SHIBARIUM_MAINNET = Chain{EvmChainID: 109, Selector: 3993510008929295315, Name: "shibarium-mainnet"} + SHIBARIUM_TESTNET_PUPPYNET = Chain{EvmChainID: 157, Selector: 17833296867764334567, Name: "shibarium-testnet-puppynet"} SONIC_TESTNET = Chain{EvmChainID: 64165, Selector: 3676871237479449268, Name: "sonic-testnet"} STORY_TESTNET = Chain{EvmChainID: 1513, Selector: 4237030917318060427, Name: "story-testnet"} TELOS_EVM_MAINNET = Chain{EvmChainID: 40, Selector: 1477345371608778000, Name: "telos-evm-mainnet"} @@ -385,6 +387,8 @@ var ALL = []Chain{ RONIN_TESTNET_SAIGON, SEI_MAINNET, SEI_TESTNET_ATLANTIC, + SHIBARIUM_MAINNET, + SHIBARIUM_TESTNET_PUPPYNET, SONIC_TESTNET, STORY_TESTNET, TELOS_EVM_MAINNET, diff --git a/selectors.yml b/selectors.yml index 455c2f8..d45ee81 100644 --- a/selectors.yml +++ b/selectors.yml @@ -21,6 +21,9 @@ selectors: 97: selector: 13264668187771770619 name: "binance_smart_chain-testnet" + 157: + selector: 17833296867764334567 + name: "shibarium-testnet-puppynet" 111: selector: 572210378683744374 name: "velas-testnet" @@ -281,6 +284,9 @@ selectors: 106: selector: 374210358663784372 name: "velas-mainnet" + 109: + selector: 3993510008929295315 + name: "shibarium-mainnet" 137: selector: 4051577828743386545 name: "polygon-mainnet"