Skip to content

Commit

Permalink
feat: add multichain denoms (#50)
Browse files Browse the repository at this point in the history
* feat: add multichain denoms

* chore: add Prometheus metrics config example

* chore: display warnings if chain-id is not set

* feat: add multichain tokens support for IBC MsgTransfer
  • Loading branch information
freak12techno authored Feb 24, 2024
1 parent e7b3d37 commit cb66d8a
Show file tree
Hide file tree
Showing 36 changed files with 553 additions and 131 deletions.
15 changes: 15 additions & 0 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ aliases = "cosmos-transactions-bot-aliases.toml"
# Defaults to "Etc/GMT", so UTC+0
timezone = "Europe/Moscow"

# Prometheus metrics configuration.
[metrics]
# Whether to enable Prometheus metrics. Defaults to true.
enabled = true
# Prometheus metrics listen address.
# If you are running this bot on a same server than your Prometheus instance is,
# you might want to switch it to "127.0.0.1:<port>" so it won't be accessible from outside.
# Defaults to ":9580" (so, port 9580 on all interfaces and accessible from outside).
listen-addr = ":9580"

# Logging configuration
[log]
# Log level. Set to "debug" or "trace" to make it more verbose, or to "warn"/"error"
Expand Down Expand Up @@ -106,6 +116,10 @@ filters = ["message.action = '/cosmos.staking.v1beta1.MsgBeginRedelegate'"]
[[chains]]
# Chain codename, required.
name = "cosmos"
# Chain ID. Optional, if omitted, multichain denoms matching would not work
# (like, if you want to filter transactions that are transferring tokens via IBC
# from one chain to another).
chain-id = "cosmoshub-4"
# Chain pretty name, optional. If provided, would be used in reports, if not,
# codename would be used.
pretty-name = "Cosmos Hub"
Expand Down Expand Up @@ -165,6 +179,7 @@ validator-link-pattern = "https://mintscan.io/cosmos/validators/%s"
# There can be multiple chains.
[[chains]]
name = "sentinel"
chain-id = "sentinelhub-2"
pretty-name = "Sentinel"
tendermint-nodes = ["https://rpc.sentinel.quokkastake.io:443"]
api-nodes = ["https://api.sentinel.quokkastake.io"]
Expand Down
18 changes: 9 additions & 9 deletions pkg/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type App struct {
Chains []*configTypes.Chain
NodesManager *nodesManagerPkg.NodesManager
Reporters reportersPkg.Reporters
DataFetchers map[string]*data_fetcher.DataFetcher
DataFetcher *data_fetcher.DataFetcher
Filterer *filtererPkg.Filterer
MetricsManager *metricsPkg.Manager

Expand Down Expand Up @@ -51,10 +51,12 @@ func NewApp(config *config.AppConfig, version string) *App {
)
}

dataFetchers := make(map[string]*data_fetcher.DataFetcher, len(config.Chains))
for _, chain := range config.Chains {
dataFetchers[chain.Name] = data_fetcher.NewDataFetcher(logger, chain, aliasManager, metricsManager)
}
dataFetcher := data_fetcher.NewDataFetcher(
logger,
config,
aliasManager,
metricsManager,
)

filterer := filtererPkg.NewFilterer(logger, config, metricsManager)

Expand All @@ -63,7 +65,7 @@ func NewApp(config *config.AppConfig, version string) *App {
Chains: config.Chains,
Reporters: reporters,
NodesManager: nodesManager,
DataFetchers: dataFetchers,
DataFetcher: dataFetcher,
Filterer: filterer,
MetricsManager: metricsManager,
Version: version,
Expand Down Expand Up @@ -92,8 +94,6 @@ func (a *App) Start() {
for {
select {
case rawReport := <-a.NodesManager.Channel:
fetcher, _ := a.DataFetchers[rawReport.Chain.Name]

reportablesForReporters := a.Filterer.GetReportableForReporters(rawReport)

if len(reportablesForReporters) == 0 {
Expand All @@ -113,7 +113,7 @@ func (a *App) Start() {
Str("hash", report.Reportable.GetHash()).
Msg("Got report")

rawReport.Reportable.GetAdditionalData(fetcher)
rawReport.Reportable.GetAdditionalData(a.DataFetcher)

reporter := a.Reporters.FindByName(reporterName)

Expand Down
3 changes: 3 additions & 0 deletions pkg/config/toml_config/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
type Chain struct {
Name string `toml:"name"`
PrettyName string `toml:"pretty-name"`
ChainID string `toml:"chain-id"`
TendermintNodes []string `toml:"tendermint-nodes"`
APINodes []string `toml:"api-nodes"`
Queries []string `default:"[\"tx.height > 1\"]" toml:"queries"`
Expand Down Expand Up @@ -76,6 +77,7 @@ func (c *Chain) ToAppConfigChain() *types.Chain {
return &types.Chain{
Name: c.Name,
PrettyName: c.PrettyName,
ChainID: c.ChainID,
TendermintNodes: c.TendermintNodes,
APINodes: c.APINodes,
Queries: queries,
Expand All @@ -89,6 +91,7 @@ func FromAppConfigChain(c *types.Chain) *Chain {
chain := &Chain{
Name: c.Name,
PrettyName: c.PrettyName,
ChainID: c.ChainID,
TendermintNodes: c.TendermintNodes,
APINodes: c.APINodes,
Denoms: TomlConfigDenomsFrom(c.Denoms),
Expand Down
25 changes: 23 additions & 2 deletions pkg/config/types/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,20 @@ func (c Chains) FindByName(name string) *Chain {
return nil
}

func (c Chains) FindByChainID(chainID string) *Chain {
for _, chain := range c {
if chain.ChainID == chainID {
return chain
}
}

return nil
}

type Chain struct {
Name string
PrettyName string
ChainID string
TendermintNodes []string
APINodes []string
Queries []query.Query
Expand Down Expand Up @@ -98,15 +109,25 @@ func (c Chain) GetBlockLink(height int64) Link {

func (c *Chain) DisplayWarnings(logger *zerolog.Logger) {
if len(c.Denoms) == 0 {
logger.Warn().Str("chain", c.Name).Msg("No denoms set, prices in USD won't be displayed.")
logger.Warn().
Str("chain", c.Name).
Msg("No denoms set, prices in USD won't be displayed.")
} else {
for _, denom := range c.Denoms {
denom.DisplayWarnings(c, logger)
}
}

if c.ChainID == "" {
logger.Warn().
Str("chain", c.Name).
Msg("chain-id is not set, multichain denom matching won't work.")
}

if c.Explorer == nil {
logger.Warn().Str("chain", c.Name).Msg("Explorer config not set, links won't be generated.")
logger.Warn().
Str("chain", c.Name).
Msg("Explorer config not set, links won't be generated.")
} else {
c.Explorer.DisplayWarnings(logger, c)
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/converter/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ func (c *Converter) ParseEvent(event jsonRpcTypes.RPCResponse, nodeURL string) t
return nil
}

c.Logger.Trace().
Str("values", fmt.Sprintf("%+v", resultEvent.Events)).
Msg("Event values")

eventDataTx, ok := resultEvent.Data.(tendermintTypes.EventDataTx)
if !ok {
c.Logger.Debug().Msg("Could not convert tx result to EventDataTx.")
Expand Down
Loading

0 comments on commit cb66d8a

Please sign in to comment.