Skip to content

Commit

Permalink
feat: use denom exponent (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno authored Jul 26, 2024
1 parent 6d0d642 commit e34ff9a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ denoms = [
# 1) denom - the base denom (like uatom for Cosmos Hub)
# 2) display - denom - the denom name to display it (like atom for Cosmos Hub)
# 3) coingecko-currency - a Coinecko API codename for a currency
# 4) denom-coefficient - the coefficient you need to multiply base denom to to get 1 token on Coingecko.
# 4) denom-exponent - the power of the coefficient you need to multiply base denom to get 1 token on Coingecko.
# Example: on Cosmos network the base denom is uatom, 1 atom = 1_000_000 uatom
# and 1 atom on Coingecko = $10, and your wallet has 10 atom, or 10_000_000 uatom.
# Then you need to specify the following parameters:
# coingecko-currency = "cosmos-hub"
# base-denom = "uatom"
# denom-coefficient = 1000000
# denom-exponent = 6 # so the coefficient == 10^6 == 1_000_000
# and after that, the /metrics endpoint will return your total balance as $100.
# Defaults to 1000000
{ denom = "ubtsg", display-denom = "btsg", coingecko-currency = "bitsong", denom-coefficient = 1000000 }
# Defaults to 6
{ denom = "ubtsg", display-denom = "btsg", coingecko-currency = "bitsong", denom-exponent = 6 }
]

# Per-wallet config. You can specify multiple wallet configs per each chain.
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/denom_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package config
type DenomInfo struct {
Denom string `toml:"denom"`
DisplayDenom string `toml:"display-denom"`
DenomCoefficient int64 `default:"1000000" toml:"denom-coefficient"`
DenomExponent int `default:"6" toml:"denom-exponent"`
CoingeckoCurrency string `toml:"coingecko-currency"`
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/queriers/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"main/pkg/config"
"main/pkg/tendermint"
"main/pkg/types"
"math"
"sync"

"go.opentelemetry.io/otel/attribute"
Expand Down Expand Up @@ -93,7 +94,7 @@ func (q *BalanceQuerier) GetMetrics(ctx context.Context) ([]prometheus.Collector
denomInfo, found := chain.FindDenomByName(balance.Denom)
if found {
denom = denomInfo.GetName()
amount /= float64(denomInfo.DenomCoefficient)
amount /= math.Pow10(denomInfo.DenomExponent)
}

balancesGauge.With(prometheus.Labels{
Expand Down
2 changes: 1 addition & 1 deletion pkg/queriers/balance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestBalanceQuerierOk(t *testing.T) {
Name: "name",
Group: "group",
}},
Denoms: []configPkg.DenomInfo{{Denom: "uatom", DisplayDenom: "atom", DenomCoefficient: 1000000}},
Denoms: []configPkg.DenomInfo{{Denom: "uatom", DisplayDenom: "atom", DenomExponent: 6}},
}}}

tracer := tracing.InitNoopTracer()
Expand Down

0 comments on commit e34ff9a

Please sign in to comment.