Skip to content

Commit

Permalink
chore: move chain list to json
Browse files Browse the repository at this point in the history
  • Loading branch information
jim380 committed Sep 18, 2023
1 parent 0887bac commit fdca517
Show file tree
Hide file tree
Showing 8 changed files with 278 additions and 64 deletions.
39 changes: 20 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,26 @@ https://user-images.githubusercontent.com/31609693/200193555-2e5f6bc4-ecf4-4332-

<details><summary>Click to view</summary>

- 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`.

</details>

Expand Down
200 changes: 200 additions & 0 deletions chains.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
68 changes: 31 additions & 37 deletions config/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package config

import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"strings"

sdktypes "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -12,7 +15,8 @@ import (
)

type Config struct {
Chain string
Chain Chain
ChainList map[string][]string
SDKVersion string
OperatorAddr string
RestAddr string
Expand All @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}

Expand Down
3 changes: 1 addition & 2 deletions exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading

0 comments on commit fdca517

Please sign in to comment.