Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: bump github.com/umee-network/umee/price-feeder from 0.2.1 to 0.2.4 #322

2 changes: 1 addition & 1 deletion cmd/peggo/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func getOrchestratorCmd() *cobra.Command {
return err
}

if err := o.SubscribeSymbols(oracle.BaseSymbolETH); err != nil {
if err := o.SubscribeSymbols(oracle.SymbolETH); err != nil {
return err
}

Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/umee-network/peggo
go 1.17

require (
github.com/Gravity-Bridge/Gravity-Bridge/module v1.4.2-0.20220317234142-1c674cbc83ff
github.com/Gravity-Bridge/Gravity-Bridge/module v1.4.2-0.20220517191451-8d660b559b07
github.com/avast/retry-go v3.0.0+incompatible
github.com/cosmos/cosmos-sdk v0.45.5
github.com/cosmos/go-bip39 v1.0.0
Expand All @@ -22,7 +22,7 @@ require (
github.com/spf13/viper v1.12.0
github.com/stretchr/testify v1.8.0
github.com/tendermint/tendermint v0.34.19
github.com/umee-network/umee/price-feeder v0.2.1
github.com/umee-network/umee/price-feeder v0.2.4
github.com/umee-network/umee/v2 v2.0.2
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
Expand Down Expand Up @@ -50,7 +50,7 @@ require (
github.com/Workiva/go-datastructures v1.0.53 // indirect
github.com/alexkohler/prealloc v1.0.0 // indirect
github.com/alingse/asasalint v0.0.10 // indirect
github.com/armon/go-metrics v0.3.10 // indirect
github.com/armon/go-metrics v0.3.11 // indirect
github.com/ashanbrown/forbidigo v1.3.0 // indirect
github.com/ashanbrown/makezero v1.1.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
Expand Down Expand Up @@ -108,7 +108,7 @@ require (
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.10.1 // indirect
github.com/go-playground/validator/v10 v10.11.0 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/go-toolsmith/astcast v1.0.0 // indirect
github.com/go-toolsmith/astcopy v1.0.0 // indirect
Expand Down Expand Up @@ -214,9 +214,9 @@ require (
github.com/phayes/checkstyle v0.0.0-20170904204023-bfd46e6a821d // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/polyfloyd/go-errorlint v1.0.0 // indirect
github.com/prometheus/client_golang v1.12.1 // indirect
github.com/prometheus/client_golang v1.12.2 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.33.0 // indirect
github.com/prometheus/common v0.34.0 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/quasilyte/go-ruleguard v0.3.16-0.20220213074421-6aa060fab41a // indirect
github.com/quasilyte/gogrep v0.0.0-20220120141003-628d8b3623b5 // indirect
Expand Down
745 changes: 12 additions & 733 deletions go.sum

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions mocks/gravity_queryclient.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion orchestrator/main_loops.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func (p *gravityOrchestrator) BatchRequesterLoop(ctx context.Context) (err error
return fmt.Errorf("failed to get Ethereum gas estimate: %w", err)
}

usdEthPrice, err := p.oracle.GetPrice(oracle.BaseSymbolETH)
usdEthPrice, err := p.oracle.GetPrice(oracle.SymbolETH)
if err != nil {
return err
}
Expand Down
32 changes: 32 additions & 0 deletions orchestrator/oracle/currency.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package oracle

import (
"strings"

umeedpftypes "github.com/umee-network/umee/price-feeder/oracle/types"
)

const (
symbolUSD = "USD"
symbolUSDT = "USDT"
symbolDAI = "DAI"
)

var (
quoteStablecoins = []string{symbolUSD, symbolUSDT, symbolDAI}
)

// GetStablecoinsCurrencyPair return the currency pair of that symbol quoted by some
// stablecoins.
func GetStablecoinsCurrencyPair(baseSymbol string) []umeedpftypes.CurrencyPair {
currencyPairs := make([]umeedpftypes.CurrencyPair, len(quoteStablecoins))

for i, quote := range quoteStablecoins {
currencyPairs[i] = umeedpftypes.CurrencyPair{
Base: strings.ToUpper(baseSymbol),
Quote: quote,
}
}

return currencyPairs
}
62 changes: 32 additions & 30 deletions orchestrator/oracle/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package oracle
import (
"context"
"fmt"
"strings"
"sync"
"time"

Expand All @@ -17,11 +16,13 @@ import (
ummedpfsync "github.com/umee-network/umee/price-feeder/pkg/sync"
)

// We define tickerTimeout as the minimum timeout between each oracle loop.
const (
tickerTimeout = 1000 * time.Millisecond
// tickerTimeout is the minimum timeout between each oracle loop.
tickerTimeout = 1000 * time.Millisecond
// availablePairsReload is the amount of time to reload the providers available pairs.
availablePairsReload = 24 * time.Hour
BaseSymbolETH = "ETH"
// SymbolETH refers to the ethereum symbol.
SymbolETH = "ETH"
)

// Oracle implements the core component responsible for fetching exchange rates
Expand All @@ -34,6 +35,9 @@ type Oracle struct {
providers map[string]*Provider // providerName => Provider
prices map[string]sdk.Dec // baseSymbol => price ex.: UMEE, ETH => sdk.Dec
subscribedBaseSymbols map[string]struct{} // baseSymbol => nothing
// this field could be calculated each time by looping providers.subscribedPairs
// but the time to process is not worth the amount of memory
providerSubscribedPairs map[string][]umeedpftypes.CurrencyPair // providerName => []CurrencyPair
}

// Provider wraps the umee provider interface.
Expand All @@ -59,16 +63,23 @@ func New(ctx context.Context, logger zerolog.Logger, providersName []string) (*O
}
}

oracle := &Oracle{
logger: logger.With().Str("module", "oracle").Logger(),
closer: ummedpfsync.NewCloser(),
providers: providers,
subscribedBaseSymbols: map[string]struct{}{},
o := &Oracle{
logger: logger.With().Str("module", "oracle").Logger(),
closer: ummedpfsync.NewCloser(),
providers: providers,
subscribedBaseSymbols: map[string]struct{}{},
providerSubscribedPairs: map[string][]umeedpftypes.CurrencyPair{},
}
oracle.loadAvailablePairs()
go oracle.start(ctx)
o.loadAvailablePairs()
if err := o.subscribeProviders([]umeedpftypes.CurrencyPair{
{Base: symbolUSDT, Quote: symbolUSD},
{Base: symbolDAI, Quote: symbolUSD},
}); err != nil {
return nil, err
}
go o.start(ctx)

return oracle, nil
return o, nil
}

// GetPrices returns the price for the provided base symbols.
Expand Down Expand Up @@ -166,6 +177,7 @@ func (o *Oracle) subscribeProviders(currencyPairs []umeedpftypes.CurrencyPair) e

for _, pair := range pairsToSubscribe {
provider.subscribedPairs[pair.String()] = pair
o.providerSubscribedPairs[providerName] = append(o.providerSubscribedPairs[providerName], pair)

o.logger.Debug().Str("provider_name", providerName).
Str("pair_symbol", pair.String()).
Expand Down Expand Up @@ -237,7 +249,7 @@ func (o *Oracle) setPrices() error {
for providerName, provider := range o.providers {
providerName := providerName
provider := provider
subscribedPrices := umeedpftypes.MapPairsToSlice(provider.subscribedPairs)
subscribedPrices := o.providerSubscribedPairs[providerName]

g.Go(func() error {
var (
Expand Down Expand Up @@ -277,7 +289,13 @@ func (o *Oracle) setPrices() error {
o.logger.Debug().Err(err).Msg("failed to get ticker prices from provider")
}

computedPrices, err := ummedpforacle.GetComputedPrices(o.logger, providerCandles, providerPrices)
computedPrices, err := ummedpforacle.GetComputedPrices(
o.logger,
providerCandles,
providerPrices,
o.providerSubscribedPairs,
make(map[string]sdk.Dec, 0), // uses default deviation
)
if err != nil {
return err
}
Expand All @@ -293,19 +311,3 @@ func (o *Oracle) tick() error {

return nil
}

// GetStablecoinsCurrencyPair return the currency pair of that symbol quoted by some
// stablecoins.
func GetStablecoinsCurrencyPair(baseSymbol string) []umeedpftypes.CurrencyPair {
quotes := []string{"USD", "USDT", "DAI"}
currencyPairs := make([]umeedpftypes.CurrencyPair, len(quotes))

for i, quote := range quotes {
currencyPairs[i] = umeedpftypes.CurrencyPair{
Base: strings.ToUpper(baseSymbol),
Quote: quote,
}
}

return currencyPairs
}
2 changes: 1 addition & 1 deletion orchestrator/relayer/batch_relaying.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func (s *gravityRelayer) IsBatchProfitable(
}

// First we get the cost of the transaction in USD
usdEthPrice, err := s.oracle.GetPrice(oracle.BaseSymbolETH)
usdEthPrice, err := s.oracle.GetPrice(oracle.SymbolETH)
if err != nil {
s.logger.Err(err).Msg("failed to get ETH price")
return false
Expand Down