diff --git a/cmd/index.go b/cmd/index.go index febb84c..3eb3062 100644 --- a/cmd/index.go +++ b/cmd/index.go @@ -117,7 +117,7 @@ func setupIndexer() *Indexer { } // Some chains do not have the denom metadata URL available on chain, so we do chain specific downloads instead. - tasks.DoChainSpecificUpsertDenoms(indexer.db, indexer.cfg.Lens.ChainID, indexer.cfg.Base.RequestRetryAttempts, indexer.cfg.Base.RequestRetryMaxWait) + tasks.DoChainSpecificUpsertDenoms(indexer.db, indexer.cfg.Lens.ChainID, indexer.cfg.Base.RequestRetryAttempts, indexer.cfg.Base.RequestRetryMaxWait, indexer.cfg.AssetList) indexer.cl = config.GetLensClient(indexer.cfg.Lens) core.ChainSpecificMessageTypeHandlerBootstrap(indexer.cfg.Lens.ChainID, indexer.cl) diff --git a/cmd/update_denoms.go b/cmd/update_denoms.go index 69c9a71..c59e377 100644 --- a/cmd/update_denoms.go +++ b/cmd/update_denoms.go @@ -69,13 +69,13 @@ func updateDenoms(cmd *cobra.Command, args []string) { config.Log.Infof("Running denom update task for all supported chains") for chainID, function := range tasks.ChainSpecificDenomUpsertFunctions { config.Log.Infof("Running denom update task for chain %s", chainID) - function(db, cfg.Base.RequestRetryAttempts, cfg.Base.RequestRetryMaxWait) + function(db, cfg.Base.RequestRetryAttempts, cfg.Base.RequestRetryMaxWait, cfg.AssetList) } case cfg.Lens.ChainID != "": function, ok := tasks.ChainSpecificDenomUpsertFunctions[cfg.Lens.ChainID] if ok { config.Log.Infof("Running denom update task for chain %s found in config", cfg.Lens.ChainID) - function(db, cfg.Base.RequestRetryAttempts, cfg.Base.RequestRetryMaxWait) + function(db, cfg.Base.RequestRetryAttempts, cfg.Base.RequestRetryMaxWait, cfg.AssetList) config.Log.Info("Done") } else { config.Log.Fatalf("No denom update functionality for chain-id %s", cfg.Lens.ChainID) diff --git a/config/assetlist_config.go b/config/assetlist_config.go new file mode 100644 index 0000000..62fca66 --- /dev/null +++ b/config/assetlist_config.go @@ -0,0 +1,5 @@ +package config + +type AssetList struct { + OsmosisAssetListURL string +} diff --git a/config/index_config.go b/config/index_config.go index ef2f560..d54c6e0 100644 --- a/config/index_config.go +++ b/config/index_config.go @@ -16,6 +16,7 @@ type IndexConfig struct { Log log Lens lens Client client + AssetList AssetList } type indexBase struct { @@ -72,6 +73,9 @@ func SetupIndexSpecificFlags(conf *IndexConfig, cmd *cobra.Command) { cmd.PersistentFlags().BoolVar(&conf.Base.ExitWhenCaughtUp, "base.exit-when-caught-up", false, "mainly used for Osmosis rewards indexing") cmd.PersistentFlags().Int64Var(&conf.Base.RequestRetryAttempts, "base.request-retry-attempts", 0, "number of RPC query retries to make") cmd.PersistentFlags().Uint64Var(&conf.Base.RequestRetryMaxWait, "base.request-retry-max-wait", 30, "max retry incremental backoff wait time in seconds") + + // mainnet chain configs + cmd.PersistentFlags().StringVar(&conf.AssetList.OsmosisAssetListURL, "asset-list.osmosis-asset-list-url", "https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/assetlist.json", "osmosis asset list url, must fit the asset list schema") } func (conf *IndexConfig) Validate() error { diff --git a/config/update_denoms_config.go b/config/update_denoms_config.go index b6ac041..b21908e 100644 --- a/config/update_denoms_config.go +++ b/config/update_denoms_config.go @@ -3,10 +3,11 @@ package config import "github.com/spf13/cobra" type UpdateDenomsConfig struct { - Database Database - Lens lens - Log log - Base updateDenomsBase + Database Database + Lens lens + Log log + Base updateDenomsBase + AssetList AssetList } type updateDenomsBase struct { @@ -18,6 +19,9 @@ func SetupUpdateDenomsSpecificFlags(conf *UpdateDenomsConfig, cmd *cobra.Command cmd.Flags().BoolVar(&conf.Base.UpdateAll, "base.update-all", false, "If provided, the update script will ignore the config chain-id and update all denoms by reaching out to all assetlists supported.") cmd.PersistentFlags().Int64Var(&conf.Base.RequestRetryAttempts, "base.request-retry-attempts", 0, "number of RPC query retries to make") cmd.PersistentFlags().Uint64Var(&conf.Base.RequestRetryMaxWait, "base.request-retry-max-wait", 30, "max retry incremental backoff wait time in seconds") + + // mainnet chain configs + cmd.PersistentFlags().StringVar(&conf.AssetList.OsmosisAssetListURL, "asset-list.osmosis-asset-list-url", "https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/assetlist.json", "osmosis asset list url, must fit the asset list schema") } func (conf *UpdateDenomsConfig) Validate() error { diff --git a/tasks/denoms.go b/tasks/denoms.go index a85fb2d..453ddc1 100644 --- a/tasks/denoms.go +++ b/tasks/denoms.go @@ -33,18 +33,18 @@ type DenomUnit struct { Aliases []string } -var ChainSpecificDenomUpsertFunctions = map[string]func(db *gorm.DB, retryMaxAttempts int64, retryMaxWaitSeconds uint64){ +var ChainSpecificDenomUpsertFunctions = map[string]func(db *gorm.DB, retryMaxAttempts int64, retryMaxWaitSeconds uint64, conf config.AssetList){ osmosis.ChainID: UpsertOsmosisDenoms, juno.ChainID: UpsertJunoDenoms, } -func DoChainSpecificUpsertDenoms(db *gorm.DB, chain string, retryMaxAttempts int64, retryMaxWaitSeconds uint64) { +func DoChainSpecificUpsertDenoms(db *gorm.DB, chain string, retryMaxAttempts int64, retryMaxWaitSeconds uint64, conf config.AssetList) { if chain == osmosis.ChainID { - UpsertOsmosisDenoms(db, retryMaxAttempts, retryMaxWaitSeconds) + UpsertOsmosisDenoms(db, retryMaxAttempts, retryMaxWaitSeconds, conf) } if chain == juno.ChainID { - UpsertJunoDenoms(db, retryMaxAttempts, retryMaxWaitSeconds) + UpsertJunoDenoms(db, retryMaxAttempts, retryMaxWaitSeconds, conf) } // may want to move this elsewhere, or eliminate entirely // I would prefer we just grab the denoms when needed always @@ -53,9 +53,13 @@ func DoChainSpecificUpsertDenoms(db *gorm.DB, chain string, retryMaxAttempts int dbTypes.CacheIBCDenoms(db) } -func UpsertOsmosisDenoms(db *gorm.DB, retryMaxAttempts int64, retryMaxWaitSeconds uint64) { +func UpsertOsmosisDenoms(db *gorm.DB, retryMaxAttempts int64, retryMaxWaitSeconds uint64, conf config.AssetList) { config.Log.Info("Updating Omsosis specific denoms") - url := "https://raw.githubusercontent.com/osmosis-labs/assetlists/main/osmosis-1/osmosis-1.assetlist.json" + url := conf.OsmosisAssetListURL + + if url == "" { + config.Log.Fatal("No assetlist URL provided for Osmosis Denom Metadata") + } denomAssets, err := getAssetsListWithRetry(url, retryMaxAttempts, retryMaxWaitSeconds) if err != nil { @@ -67,9 +71,10 @@ func UpsertOsmosisDenoms(db *gorm.DB, retryMaxAttempts int64, retryMaxWaitSecond config.Log.Fatal("Upsert Osmosis Denom Metadata", err) } } + config.Log.Info("Finished updating Omsosis specific denoms") } -func UpsertJunoDenoms(db *gorm.DB, retryMaxAttempts int64, retryMaxWaitSeconds uint64) { +func UpsertJunoDenoms(db *gorm.DB, retryMaxAttempts int64, retryMaxWaitSeconds uint64, conf config.AssetList) { config.Log.Info("Updating Juno specific denoms") url := "https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/assetlist.json"