diff --git a/common/chain.go b/common/chain.go index 2ef7116ede..284fa5bf7b 100644 --- a/common/chain.go +++ b/common/chain.go @@ -9,12 +9,7 @@ import ( ethcommon "github.com/ethereum/go-ethereum/common" ) -var ( - SigningAlgoSecp256k1 = SigninAlgo("secp256k1") - SigningAlgoEd25519 = SigninAlgo("ed25519") -) - -// return the ChainName from a string +// ParseChainName returns the ChainName from a string // if no such name exists, returns the empty chain name: ChainName_empty func ParseChainName(chain string) ChainName { c := ChainName_value[chain] @@ -29,7 +24,7 @@ type SigninAlgo string // Chains represent a slice of Chain type Chains []Chain -// Equals compare two chain to see whether they represent the same chain +// IsEqual compare two chain to see whether they represent the same chain func (chain Chain) IsEqual(c Chain) bool { if chain.ChainName == c.ChainName && chain.ChainId == c.ChainId { return true @@ -44,7 +39,7 @@ func (chain Chain) IsExternalChain() bool { return !chain.IsEqual(ZetaChain()) } -// bytes representations of address +// EncodeAddress bytes representations of address // on EVM chain, it is 20Bytes // on Bitcoin chain, it is P2WPKH address, []byte(bech32 encoded string) func (chain Chain) EncodeAddress(b []byte) (string, error) { @@ -168,16 +163,6 @@ func (chains Chains) Strings() []string { return strings } -func GetChainFromChainName(chainName ChainName) *Chain { - chains := DefaultChainsList() - for _, chain := range chains { - if chainName == chain.ChainName { - return chain - } - } - return nil -} - func GetChainFromChainID(chainID int64) *Chain { chains := DefaultChainsList() for _, chain := range chains { diff --git a/common/chain_network.go b/common/chain_network.go deleted file mode 100644 index cb4f386fad..0000000000 --- a/common/chain_network.go +++ /dev/null @@ -1,40 +0,0 @@ -package common - -import ( - "os" - "strings" -) - -// ChainNetwork is to indicate which chain environment THORNode are working with -type ChainNetwork uint8 - -const ( - // TestNet network for test - TestNet ChainNetwork = iota - // MainNet network for main net - MainNet - // MockNet network for main net - MockNet -) - -// GetCurrentChainNetwork determinate what kind of network currently it is working with -func GetCurrentChainNetwork() ChainNetwork { - if strings.EqualFold(os.Getenv("NET"), "mocknet") { - return MockNet - } - if strings.EqualFold(os.Getenv("NET"), "testnet") { - return TestNet - } - return MainNet -} - -// Soft Equals check is mainnet == mainet, or (testnet/mocknet == testnet/mocknet) -func (net ChainNetwork) SoftEquals(net2 ChainNetwork) bool { - if net == MainNet && net2 == MainNet { - return true - } - if net != MainNet && net2 != MainNet { - return true - } - return false -} diff --git a/common/chain_network_test.go b/common/chain_network_test.go deleted file mode 100644 index 9aa804e76e..0000000000 --- a/common/chain_network_test.go +++ /dev/null @@ -1,18 +0,0 @@ -package common - -import ( - . "gopkg.in/check.v1" -) - -type ChainNetworkSuite struct{} - -var _ = Suite(&ChainNetworkSuite{}) - -func (s *ChainNetworkSuite) TestSoftEquals(c *C) { - c.Assert(MainNet.SoftEquals(MainNet), Equals, true) - c.Assert(TestNet.SoftEquals(TestNet), Equals, true) - c.Assert(MockNet.SoftEquals(MockNet), Equals, true) - c.Assert(TestNet.SoftEquals(MockNet), Equals, true) - c.Assert(MainNet.SoftEquals(MockNet), Equals, false) - c.Assert(MainNet.SoftEquals(TestNet), Equals, false) -} diff --git a/common/default_chains_mainnet.go b/common/chains.go similarity index 63% rename from common/default_chains_mainnet.go rename to common/chains.go index 170aaf245d..5ffd628750 100644 --- a/common/default_chains_mainnet.go +++ b/common/chains.go @@ -1,18 +1,6 @@ package common -func EthChain() Chain { - return Chain{ - ChainName: ChainName_eth_mainnet, - ChainId: 1, - } -} - -func BscMainnetChain() Chain { - return Chain{ - ChainName: ChainName_bsc_mainnet, - ChainId: 56, - } -} +// Zeta chains func ZetaChain() Chain { return Chain{ @@ -42,19 +30,27 @@ func ZetaPrivnetChain() Chain { } } -func BtcMainnetChain() Chain { +// Mainnet chains + +func EthChain() Chain { return Chain{ - ChainName: ChainName_btc_mainnet, - ChainId: 8332, + ChainName: ChainName_eth_mainnet, + ChainId: 1, } } -func BtcChainID() int64 { - return BtcMainnetChain().ChainId +func BscMainnetChain() Chain { + return Chain{ + ChainName: ChainName_bsc_mainnet, + ChainId: 56, + } } -func BtcDustOffset() int64 { - return 2000 +func BtcMainnetChain() Chain { + return Chain{ + ChainName: ChainName_btc_mainnet, + ChainId: 8332, + } } func PolygonChain() Chain { @@ -64,6 +60,38 @@ func PolygonChain() Chain { } } +// Testnet chains + +func GoerliChain() Chain { + return Chain{ + ChainName: ChainName_goerli_testnet, + ChainId: 5, + } +} + +func BscTestnetChain() Chain { + return Chain{ + ChainName: ChainName_bsc_testnet, + ChainId: 97, + } +} + +func BtcTestNetChain() Chain { + return Chain{ + ChainName: ChainName_btc_testnet, + ChainId: 18332, + } +} + +func MumbaiChain() Chain { + return Chain{ + ChainName: ChainName_mumbai_testnet, + ChainId: 80001, + } +} + +// Privnet chains + func BtcRegtestChain() Chain { return Chain{ ChainName: ChainName_btc_regtest, @@ -71,18 +99,33 @@ func BtcRegtestChain() Chain { } } -func GoerliChain() Chain { +func GoerliLocalnetChain() Chain { return Chain{ ChainName: ChainName_goerli_localnet, ChainId: 1337, } } +func BtcChainID() int64 { + return BtcRegtestChain().ChainId +} + +func BtcDustOffset() int64 { + return 2000 +} + +// DefaultChainsList returns a list of default chains func DefaultChainsList() []*Chain { chains := []Chain{ BtcMainnetChain(), BscMainnetChain(), EthChain(), + BtcTestNetChain(), + MumbaiChain(), + BscTestnetChain(), + GoerliChain(), + BtcRegtestChain(), + GoerliLocalnetChain(), ZetaChain(), } var c []*Chain @@ -92,11 +135,18 @@ func DefaultChainsList() []*Chain { return c } +// ExternalChainList returns a list chains that are not Zeta func ExternalChainList() []*Chain { chains := []Chain{ BtcMainnetChain(), BscMainnetChain(), EthChain(), + BtcTestNetChain(), + MumbaiChain(), + BscTestnetChain(), + GoerliChain(), + BtcRegtestChain(), + GoerliLocalnetChain(), } var c []*Chain for i := 0; i < len(chains); i++ { diff --git a/x/observer/types/core_params_testnet.go b/x/observer/types/core_params.go similarity index 59% rename from x/observer/types/core_params_testnet.go rename to x/observer/types/core_params.go index a2be9be7fc..0ee73f3bf9 100644 --- a/x/observer/types/core_params_testnet.go +++ b/x/observer/types/core_params.go @@ -1,6 +1,3 @@ -//go:build TESTNET -// +build TESTNET - package types import ( @@ -13,6 +10,45 @@ import ( func GetCoreParams() CoreParamsList { params := CoreParamsList{ CoreParams: []*CoreParams{ + { + ChainId: common.EthChain().ChainId, + ConfirmationCount: 14, + ZetaTokenContractAddress: "", + ConnectorContractAddress: "", + Erc20CustodyContractAddress: "", + InTxTicker: 12, + OutTxTicker: 15, + WatchUtxoTicker: 0, + GasPriceTicker: 30, + OutboundTxScheduleInterval: 30, + OutboundTxScheduleLookahead: 60, + }, + { + ChainId: common.BscMainnetChain().ChainId, + ConfirmationCount: 14, + ZetaTokenContractAddress: "", + ConnectorContractAddress: "", + Erc20CustodyContractAddress: "", + InTxTicker: 5, + OutTxTicker: 15, + WatchUtxoTicker: 0, + GasPriceTicker: 30, + OutboundTxScheduleInterval: 30, + OutboundTxScheduleLookahead: 60, + }, + { + ChainId: common.BtcMainnetChain().ChainId, + ConfirmationCount: 2, + ZetaTokenContractAddress: "", + ConnectorContractAddress: "", + Erc20CustodyContractAddress: "", + WatchUtxoTicker: 30, + InTxTicker: 120, + OutTxTicker: 60, + GasPriceTicker: 30, + OutboundTxScheduleInterval: 30, + OutboundTxScheduleLookahead: 60, + }, { ChainId: common.GoerliChain().ChainId, ConfirmationCount: 6, @@ -66,6 +102,19 @@ func GetCoreParams() CoreParamsList { OutboundTxScheduleInterval: 30, OutboundTxScheduleLookahead: 100, }, + { + ChainId: common.BtcRegtestChain().ChainId, + ConfirmationCount: 2, + ZetaTokenContractAddress: "", + ConnectorContractAddress: "", + Erc20CustodyContractAddress: "", + GasPriceTicker: 5, + WatchUtxoTicker: 1, + InTxTicker: 1, + OutTxTicker: 2, + OutboundTxScheduleInterval: 2, + OutboundTxScheduleLookahead: 5, + }, }, } chainList := common.ExternalChainList() diff --git a/x/observer/types/core_params_mainnet.go b/x/observer/types/core_params_mainnet.go deleted file mode 100644 index 1f2af59ad4..0000000000 --- a/x/observer/types/core_params_mainnet.go +++ /dev/null @@ -1,69 +0,0 @@ -package types - -import ( - "fmt" - - "github.com/coinbase/rosetta-sdk-go/types" - "github.com/zeta-chain/zetacore/common" -) - -func GetCoreParams() CoreParamsList { - params := CoreParamsList{ - CoreParams: []*CoreParams{ - { - ChainId: common.EthChain().ChainId, - ConfirmationCount: 14, - ZetaTokenContractAddress: "", - ConnectorContractAddress: "", - Erc20CustodyContractAddress: "", - InTxTicker: 12, - OutTxTicker: 15, - WatchUtxoTicker: 0, - GasPriceTicker: 30, - OutboundTxScheduleInterval: 30, - OutboundTxScheduleLookahead: 60, - }, - { - ChainId: common.BscMainnetChain().ChainId, - ConfirmationCount: 14, - ZetaTokenContractAddress: "", - ConnectorContractAddress: "", - Erc20CustodyContractAddress: "", - InTxTicker: 5, - OutTxTicker: 15, - WatchUtxoTicker: 0, - GasPriceTicker: 30, - OutboundTxScheduleInterval: 30, - OutboundTxScheduleLookahead: 60, - }, - { - ChainId: common.BtcMainnetChain().ChainId, - ConfirmationCount: 2, - ZetaTokenContractAddress: "", - ConnectorContractAddress: "", - Erc20CustodyContractAddress: "", - WatchUtxoTicker: 30, - InTxTicker: 120, - OutTxTicker: 60, - GasPriceTicker: 30, - OutboundTxScheduleInterval: 30, - OutboundTxScheduleLookahead: 60, - }, - }, - } - chainList := common.ExternalChainList() - requiredParams := len(chainList) - availableParams := 0 - for _, chain := range chainList { - for _, param := range params.CoreParams { - if chain.ChainId == param.ChainId { - availableParams++ - } - } - } - if availableParams != requiredParams { - panic(fmt.Sprintf("Core params are not available for all chains , DefaultChains : %s , CoreParams : %s", - types.PrettyPrintStruct(chainList), params.String())) - } - return params -} diff --git a/x/observer/types/core_params_mock_mainnet.go b/x/observer/types/core_params_mock_mainnet.go deleted file mode 100644 index 549edc5bf7..0000000000 --- a/x/observer/types/core_params_mock_mainnet.go +++ /dev/null @@ -1,72 +0,0 @@ -//go:build MOCK_MAINNET -// +build MOCK_MAINNET - -package types - -import ( - "fmt" - - "github.com/coinbase/rosetta-sdk-go/types" - "github.com/zeta-chain/zetacore/common" -) - -func GetCoreParams() CoreParamsList { - params := CoreParamsList{ - CoreParams: []*CoreParams{ - { - ChainId: common.EthChain().ChainId, - ConfirmationCount: 6, - ZetaTokenContractAddress: "", - ConnectorContractAddress: "", - Erc20CustodyContractAddress: "", - InTxTicker: 12, - OutTxTicker: 15, - WatchUtxoTicker: 0, - GasPriceTicker: 30, - OutboundTxScheduleInterval: 30, - OutboundTxScheduleLookahead: 60, - }, - { - ChainId: common.BscMainnetChain().ChainId, - ConfirmationCount: 6, - ZetaTokenContractAddress: "", - ConnectorContractAddress: "", - Erc20CustodyContractAddress: "", - InTxTicker: 5, - OutTxTicker: 15, - WatchUtxoTicker: 0, - GasPriceTicker: 30, - OutboundTxScheduleInterval: 30, - OutboundTxScheduleLookahead: 60, - }, - { - ChainId: common.BtcMainnetChain().ChainId, - ConfirmationCount: 2, - ZetaTokenContractAddress: "", - ConnectorContractAddress: "", - Erc20CustodyContractAddress: "", - WatchUtxoTicker: 30, - InTxTicker: 120, - OutTxTicker: 60, - GasPriceTicker: 30, - OutboundTxScheduleInterval: 30, - OutboundTxScheduleLookahead: 60, - }, - }, - } - chainList := common.ExternalChainList() - requiredParams := len(chainList) - availableParams := 0 - for _, chain := range chainList { - for _, param := range params.CoreParams { - if chain.ChainId == param.ChainId { - availableParams++ - } - } - } - if availableParams != requiredParams { - panic(fmt.Sprintf("Core params are not available for all chains , DefaultChains : %s , CoreParams : %s", - types.PrettyPrintStruct(chainList), params.String())) - } - return params -} diff --git a/x/observer/types/core_params_privnet.go b/x/observer/types/core_params_privnet.go deleted file mode 100644 index 27b5a1d6fa..0000000000 --- a/x/observer/types/core_params_privnet.go +++ /dev/null @@ -1,59 +0,0 @@ -//go:build PRIVNET -// +build PRIVNET - -package types - -import ( - "fmt" - - "github.com/coinbase/rosetta-sdk-go/types" - "github.com/zeta-chain/zetacore/common" -) - -func GetCoreParams() CoreParamsList { - params := CoreParamsList{ - CoreParams: []*CoreParams{ - { - ChainId: common.GoerliChain().ChainId, - ConfirmationCount: 2, - ZetaTokenContractAddress: "0xA8D5060feb6B456e886F023709A2795373691E63", - ConnectorContractAddress: "0x733aB8b06DDDEf27Eaa72294B0d7c9cEF7f12db9", - Erc20CustodyContractAddress: "0xD28D6A0b8189305551a0A8bd247a6ECa9CE781Ca", - InTxTicker: 2, - OutTxTicker: 2, - WatchUtxoTicker: 0, - GasPriceTicker: 5, - OutboundTxScheduleInterval: 2, - OutboundTxScheduleLookahead: 5, - }, - { - ChainId: common.BtcRegtestChain().ChainId, - ConfirmationCount: 2, - ZetaTokenContractAddress: "", - ConnectorContractAddress: "", - Erc20CustodyContractAddress: "", - GasPriceTicker: 5, - WatchUtxoTicker: 1, - InTxTicker: 1, - OutTxTicker: 2, - OutboundTxScheduleInterval: 2, - OutboundTxScheduleLookahead: 5, - }, - }, - } - chainList := common.ExternalChainList() - requiredParams := len(chainList) - availableParams := 0 - for _, chain := range chainList { - for _, param := range params.CoreParams { - if chain.ChainId == param.ChainId { - availableParams++ - } - } - } - if availableParams != requiredParams { - panic(fmt.Sprintf("Core params are not available for all chains , DefaultChains : %s , CoreParams : %s", - types.PrettyPrintStruct(chainList), params.String())) - } - return params -} diff --git a/zetaclient/supported_chains.go b/zetaclient/supported_chains.go deleted file mode 100644 index 022029667a..0000000000 --- a/zetaclient/supported_chains.go +++ /dev/null @@ -1,10 +0,0 @@ -package zetaclient - -import ( - "github.com/zeta-chain/zetacore/common" -) - -// Modify to update this from the core later -func GetSupportedChains() []*common.Chain { - return common.DefaultChainsList() -}