Skip to content

Commit

Permalink
feat: price-feeder: force a minimum of three providers (#536)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamewozniak authored Feb 10, 2022
1 parent 20a2f25 commit af8765f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions price-feeder/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Features

- [#536](https://github.com/umee-network/umee/pull/536) Force a minimum of three providers per asset.
- [#502](https://github.com/umee-network/umee/pull/502) Faulty provider detection: discard prices that are not within 2𝜎 of others.

## [v0.1.0](https://github.com/umee-network/umee/releases/tag/price-feeder%2Fv0.1.0) - 2022-02-07
Expand Down
11 changes: 11 additions & 0 deletions price-feeder/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,26 @@ func ParseConfig(configPath string) (Config, error) {
cfg.Server.ReadTimeout = defaultSrvReadTimeout.String()
}

pairs := make(map[string]map[string]struct{})
for _, cp := range cfg.CurrencyPairs {
if !strings.Contains(strings.ToUpper(cp.Quote), denomUSD) {
return cfg, fmt.Errorf("unsupported pair quote: %s", cp.Quote)
}
if _, ok := pairs[cp.Base]; !ok {
pairs[cp.Base] = make(map[string]struct{})
}

for _, provider := range cp.Providers {
if _, ok := SupportedProviders[provider]; !ok {
return cfg, fmt.Errorf("unsupported provider: %s", provider)
}
pairs[cp.Base][provider] = struct{}{}
}
}

for base, providers := range pairs {
if _, ok := pairs[base]["mock"]; !ok && len(providers) < 3 {
return cfg, fmt.Errorf("must have at least three providers for %s", base)
}
}

Expand Down
8 changes: 5 additions & 3 deletions price-feeder/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,17 @@ base = "ATOM"
quote = "USDT"
providers = [
"kraken",
"binance"
"binance",
"huobi"
]
[[currency_pairs]]
base = "UMEE"
quote = "USDT"
providers = [
"kraken",
"binance"
"binance",
"huobi"
]
[account]
Expand Down Expand Up @@ -184,7 +186,7 @@ global_labels = [["chain-id", "umee-local-beta-testnet"]]
require.Len(t, cfg.CurrencyPairs, 2)
require.Equal(t, "ATOM", cfg.CurrencyPairs[0].Base)
require.Equal(t, "USDT", cfg.CurrencyPairs[0].Quote)
require.Len(t, cfg.CurrencyPairs[0].Providers, 2)
require.Len(t, cfg.CurrencyPairs[0].Providers, 3)
require.Equal(t, "kraken", cfg.CurrencyPairs[0].Providers[0])
require.Equal(t, "binance", cfg.CurrencyPairs[0].Providers[1])
}
Expand Down

0 comments on commit af8765f

Please sign in to comment.