diff --git a/README.md b/README.md index 9f7df38..c147c88 100644 --- a/README.md +++ b/README.md @@ -37,25 +37,26 @@ https://user-images.githubusercontent.com/31609693/200193555-2e5f6bc4-ecf4-4332-
Click to view -- Cosmos(`cosmoshub-4`) -- IRISnet(`irishub-1`) -- Umme (`umee-1`) -- Osmosis (`osmosis-1`) -- Juno (`juno-1`) -- Akash (`akashnet-2`) -- Regen (`regen-1`) -- Microtick (`microtick-1`) -- NYM (`nyx`) -- EVMOS (`evmos_9001-2`) -- Rizon (`mantel-1`) -- Stargaze (`stargaze-1`) -- Chihuahua (`chihuahua-1`) -- Gravity Bridge (`gravity-bridge-3`) -- Lum (`lum-network-1`) -- Provenance (`pio-mainnet-1`) -- Crescent (`crescent-1`) -- Sifchain (`sifchain-1`) -- Any Tendermint chain really +- Cosmos +- IRISnet +- Umme +- Osmosis +- Juno +- Akash +- Regen +- EVMOS +- Rizon +- Stargaze +- Gravity Bridge +- Lum +- Provenance +- Crescent +- Stride +- AssetMantle +- Passage +- Teritori + +Additional chains can be simply added in `chains.json`.
diff --git a/chains.json b/chains.json new file mode 100644 index 0000000..c79189e --- /dev/null +++ b/chains.json @@ -0,0 +1,200 @@ +[ + { + "chain": "cosmos", + "assets": [ + { + "denom": "uatom", + "symbol": "ATOM", + "decimals": "6" + } + ], + "addr_prefix": "cosmos" + }, + { + "chain": "irisnet", + "assets": [ + { + "denom": "uiris", + "symbol": "IRIS", + "decimals": "6" + } + ], + "addr_prefix": "ia" + }, + { + "chain": "osmosis", + "assets": [ + { + "denom": "uosmo", + "symbol": "OSMO", + "decimals": "6" + } + ], + "addr_prefix": "osmo" + }, + { + "chain": "stride", + "assets": [ + { + "denom": "ustrd", + "symbol": "STRD", + "decimals": "6" + } + ], + "addr_prefix": "stride" + }, + { + "chain": "evmos", + "assets": [ + { + "denom": "aevmos", + "symbol": "EVMOS", + "decimals": "18" + } + ], + "addr_prefix": "evmos" + }, + { + "chain": "umee", + "assets": [ + { + "denom": "uumee", + "symbol": "UMEE", + "decimals": "6" + } + ], + "addr_prefix": "umee" + }, + { + "chain": "juno", + "assets": [ + { + "denom": "ujuno", + "symbol": "JUNO", + "decimals": "6" + } + ], + "addr_prefix": "juno" + }, + { + "chain": "akash", + "assets": [ + { + "denom": "uakt", + "symbol": "AKT", + "decimals": "6" + } + ], + "addr_prefix": "akash" + }, + { + "chain": "regen", + "assets": [ + { + "denom": "uregen", + "symbol": "REGEN", + "decimals": "6" + } + ], + "addr_prefix": "regen" + }, + { + "chain": "stargaze", + "assets": [ + { + "denom": "ustars", + "symbol": "STARZ", + "decimals": "6" + } + ], + "addr_prefix": "starz" + }, + { + "chain": "rizon", + "assets": [ + { + "denom": "uatolo", + "symbol": "ATOLO", + "decimals": "6" + } + ], + "addr_prefix": "rizon" + }, + { + "chain": "gravity-bridge", + "assets": [ + { + "denom": "ugraviton", + "symbol": "GRAVITON", + "decimals": "6" + } + ], + "addr_prefix": "gravity" + }, + { + "chain": "lum", + "assets": [ + { + "denom": "ulum", + "symbol": "LUM", + "decimals": "6" + } + ], + "addr_prefix": "lum" + }, + { + "chain": "provenance", + "assets": [ + { + "denom": "nhash", + "symbol": "HASH", + "decimals": "9" + } + ], + "addr_prefix": "pb" + }, + { + "chain": "crescent", + "assets": [ + { + "denom": "ucre", + "symbol": "CRE", + "decimals": "6" + } + ], + "addr_prefix": "cre" + }, + { + "chain": "assetMantle", + "assets": [ + { + "denom": "umntl", + "symbol": "MNTL", + "decimals": "6" + } + ], + "addr_prefix": "mantle" + }, + { + "chain": "passage", + "assets": [ + { + "denom": "upasg", + "symbol": "PASG", + "decimals": "6" + } + ], + "addr_prefix": "pasg" + }, + { + "chain": "teritori", + "assets": [ + { + "denom": "utori", + "symbol": "TORI", + "decimals": "6" + } + ], + "addr_prefix": "tori" + } +] diff --git a/config/main.go b/config/main.go index 55f7895..ebac465 100644 --- a/config/main.go +++ b/config/main.go @@ -1,8 +1,11 @@ package config import ( + "encoding/json" "fmt" + "io/ioutil" "log" + "os" "strings" sdktypes "github.com/cosmos/cosmos-sdk/types" @@ -12,7 +15,8 @@ import ( ) type Config struct { - Chain string + Chain Chain + ChainList map[string][]string SDKVersion string OperatorAddr string RestAddr string @@ -25,9 +29,16 @@ type Config struct { LogLevel string } +type Chain struct { + Chain string `json:"chain"` + Assets []struct { + Denom string `json:"denom"` + } `json:"assets"` +} + func (cfg Config) SetSDKConfig() { // Bech32MainPrefix is the common prefix of all prefixes - Bech32MainPrefix := utils.GetPrefix(cfg.Chain) + Bech32MainPrefix := utils.GetPrefix(cfg.Chain.Chain) // Bech32PrefixAccAddr is the prefix of account addresses Bech32PrefixAccAddr := Bech32MainPrefix // Bech32PrefixAccPub is the prefix of account public keys @@ -48,18 +59,6 @@ func (cfg Config) SetSDKConfig() { } func (config Config) CheckInputs(chainList map[string][]string) { - if config.Chain == "" { - log.Fatal("Chain was not provided.") - } else { - valid := false - if _, found := chainList[config.Chain]; found { - valid = true - } - if !valid { - log.Fatal(fmt.Sprintf("%s is not supported", config.Chain) + fmt.Sprint("\nList of supported chains: ", chainList)) - } - } - // TO-DO add more robust checks if config.OperatorAddr == "" { log.Fatal("Operator address was not provided") @@ -136,28 +135,23 @@ func GetDenomList(chain string, chainList map[string][]string) []string { } func GetChainList() map[string][]string { - var chainList = map[string][]string{} - - chainList["cosmos"] = []string{"uatom"} - chainList["umee"] = []string{"uumee"} - chainList["osmosis"] = []string{"uosmo"} - chainList["juno"] = []string{"ujuno"} - chainList["akash"] = []string{"uakt"} - chainList["regen"] = []string{"uregen"} - chainList["stargaze"] = []string{"ustars"} - chainList["evmos"] = []string{"aevmos"} - chainList["rizon"] = []string{"uatolo"} - chainList["gravity"] = []string{"ugraviton"} - chainList["lum"] = []string{"ulum"} - chainList["provenance"] = []string{"nhash"} - chainList["crescent"] = []string{"ucre"} - chainList["assetMantle"] = []string{"umntl"} - chainList["sifchain"] = []string{"urowan"} - chainList["passage"] = []string{"upasg"} - chainList["stride"] = []string{"ustrd"} - chainList["canto"] = []string{"acanto"} - chainList["teritori"] = []string{"utori"} - chainList["nyx"] = []string{"unyx"} + jsonFile, err := os.Open("chains.json") + if err != nil { + fmt.Println(err) + } + defer jsonFile.Close() + + byteValue, _ := ioutil.ReadAll(jsonFile) + + var chains []Chain + json.Unmarshal(byteValue, &chains) + + chainList := make(map[string][]string) + for _, chain := range chains { + for _, asset := range chain.Assets { + chainList[chain.Chain] = append(chainList[chain.Chain], asset.Denom) + } + } return chainList } @@ -175,7 +169,7 @@ func (config Config) IsLegacySDKVersion() bool { func (config Config) IsGravityBridgeEnabled() bool { var enabled bool = false - if config.Chain == "gravity" || config.Chain == "umee" { + if config.Chain.Chain == "gravity" || config.Chain.Chain == "umee" { enabled = true } diff --git a/exporter/main.go b/exporter/main.go index 919fe0d..8358bb1 100644 --- a/exporter/main.go +++ b/exporter/main.go @@ -27,8 +27,7 @@ func Start(config *config.Config, port string, logger *zap.Logger) { } func Run(cfg *config.Config, log *zap.Logger) { - cl := config.GetChainList() - denomList := config.GetDenomList(cfg.Chain, cl) + denomList := config.GetDenomList(cfg.Chain.Chain, cfg.ChainList) registerGauges(denomList) counterVecs := registerLabels() diff --git a/main.go b/main.go index 6747360..55a9ac9 100644 --- a/main.go +++ b/main.go @@ -16,6 +16,7 @@ limitations under the License. package main import ( + "fmt" "log" "os" @@ -40,8 +41,13 @@ func main() { log.Fatal("Error loading .env file") } + if os.Getenv("CHAIN") == "" { + log.Fatal("Chain was not provided.") + } + + providedChain := os.Getenv("CHAIN") + cfg := config.Config{ - Chain: os.Getenv("CHAIN"), OperatorAddr: os.Getenv("OPERATOR_ADDR"), RestAddr: os.Getenv("REST_ADDR"), RpcAddr: os.Getenv("RPC_ADDR"), @@ -52,10 +58,24 @@ func main() { PollInterval: os.Getenv("POLL_INTERVAL"), LogLevel: os.Getenv("LOG_LEVEL"), } + chainList := config.GetChainList() + cfg.ChainList = chainList + supportedChains := make([]string, 0, len(chainList)) + for key := range chainList { + supportedChains = append(supportedChains, key) + } + var found bool + if _, found = chainList[providedChain]; found { + cfg.Chain = config.Chain{Chain: providedChain} + } + if !found { + log.Fatal(fmt.Sprintf("%s is not supported", providedChain) + fmt.Sprint("\nList of supported chains: ", supportedChains)) + } + cfg.CheckInputs(chainList) - chain = cfg.Chain + chain = cfg.Chain.Chain operAddr = cfg.OperatorAddr restAddr = cfg.RestAddr rpcAddr = cfg.RpcAddr diff --git a/rest/akash.go b/rest/akash.go index e88fa8f..5ba7953 100644 --- a/rest/akash.go +++ b/rest/akash.go @@ -109,7 +109,7 @@ type GroupSpec struct { } func (rd *RESTData) getAkashDeployments(cfg config.Config) { - if cfg.Chain != "akash" { + if cfg.Chain.Chain != "akash" { return } var deployments, activeDeployments akashDeployments diff --git a/rest/inflation.go b/rest/inflation.go index 195e3bd..4ed7203 100644 --- a/rest/inflation.go +++ b/rest/inflation.go @@ -28,8 +28,8 @@ func (rd *RESTData) getInflation(cfg config.Config, denom string) { route := getInflationRoute(cfg) res, err := HttpQuery(RESTAddr + route) - switch cfg.Chain { - case "iris": + switch cfg.Chain.Chain { + case "irisnet": var i inflation_iris if err != nil { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", "Failed to connect to REST-Server")) diff --git a/rest/routes.go b/rest/routes.go index 449663f..ef867a9 100644 --- a/rest/routes.go +++ b/rest/routes.go @@ -40,7 +40,7 @@ func getValidatorDistributionByAddressRoute(cfg config.Config) string { } func getInflationRoute(cfg config.Config) string { - if cfg.Chain == "iris" { + if cfg.Chain.Chain == "irisnet" { return "/irishub/mint/params" } else if cfg.IsLegacySDKVersion() { return "/minting/inflation"