diff --git a/cmd/priceFeeder/config/config.toml b/cmd/priceFeeder/config/config.toml index 1dacbc1d..5d2b8648 100644 --- a/cmd/priceFeeder/config/config.toml +++ b/cmd/priceFeeder/config/config.toml @@ -12,8 +12,8 @@ # valid options for ProxyRestAPIEntityType are `observer` and `proxy`. Any other value will trigger an error. # `observer` is useful when querying an observer, directly and `proxy` is useful when querying a squad's proxy - ProxyRestAPIEntityType = "observer" - ProxyFinalityCheck = true + ProxyRestAPIEntityType = "proxy" + ProxyFinalityCheck = false ProxyMaxNoncesDelta = 7 # the number of maximum blocks allowed to be "in front" of what the metachain has notarized [[Pairs]] @@ -22,3 +22,26 @@ PercentDifferenceToNotify = 1 # percent difference to notify price change. 0 notifies for each change TrimPrecision = 0.01 # trim precision for prices DenominationFactor = 100 # denomination factor + +# Maiar Exchange token ids mappings +# This should be a mapping between the above generic symbols pairs and their maiar token ids equivalents +# The key in map must be uppercase and tokens should be separated by "-" +# All available pairs can be found at https://api.elrond.com/mex-pairs +# egs. +# "ETH-USD" +# Base = "ETH-tbd000" -> placeholder, not added yet +# Quote = "USDC-c76f1f" +# "EGLD-USD" +# Base = "WEGLD-bd4d79" +# Quote = "USDC-c76f1f" +[MexTokenIDsMappings] + +[MexTokenIDsMappings.EGLD-USD] + Base = "WEGLD-bd4d79" + Quote = "USDC-c76f1f" +[MexTokenIDsMappings.MEX-EGLD] + Base = "MEX-455c57" + Quote = "WEGLD-bd4d79" +[MexTokenIDsMappings.RIDE-EGLD] + Base = "RIDE-7d18e9" + Quote = "WEGLD-bd4d79" diff --git a/cmd/priceFeeder/main.go b/cmd/priceFeeder/main.go index a107b0b6..e25acb3c 100644 --- a/cmd/priceFeeder/main.go +++ b/cmd/priceFeeder/main.go @@ -17,6 +17,7 @@ import ( "github.com/ElrondNetwork/elrond-sdk-erdgo/aggregator/notifees" "github.com/ElrondNetwork/elrond-sdk-erdgo/blockchain" "github.com/ElrondNetwork/elrond-sdk-erdgo/builders" + erdgoCore "github.com/ElrondNetwork/elrond-sdk-erdgo/core" "github.com/ElrondNetwork/elrond-sdk-erdgo/core/polling" "github.com/ElrondNetwork/elrond-sdk-erdgo/data" "github.com/ElrondNetwork/elrond-sdk-erdgo/interactors" @@ -47,6 +48,10 @@ func runApp() error { return err } + for key, val := range cfg.MexTokenIDsMappings { + log.Info("read mex token IDs mapping", "key", key, "quote", val.Quote, "base", val.Base) + } + if len(cfg.GeneralConfig.NetworkAddress) == 0 { return fmt.Errorf("empty NetworkAddress in config file") } @@ -58,13 +63,14 @@ func runApp() error { FinalityCheck: cfg.GeneralConfig.ProxyFinalityCheck, AllowedDeltaToFinal: cfg.GeneralConfig.ProxyMaxNoncesDelta, CacheExpirationTime: time.Second * time.Duration(cfg.GeneralConfig.ProxyCacherExpirationSeconds), + EntityType: erdgoCore.RestAPIEntityType(cfg.GeneralConfig.ProxyRestAPIEntityType), } proxy, err := blockchain.NewElrondProxy(args) if err != nil { return err } - priceFetchers, err := createPriceFetchers() + priceFetchers, err := createPriceFetchers(cfg.MexTokenIDsMappings) if err != nil { return err } @@ -181,11 +187,11 @@ func loadConfig(filepath string) (config.PriceNotifierConfig, error) { return cfg, nil } -func createPriceFetchers() ([]aggregator.PriceFetcher, error) { +func createPriceFetchers(tokenIdsMappings map[string]fetchers.MaiarTokensPair) ([]aggregator.PriceFetcher, error) { exchanges := fetchers.ImplementedFetchers priceFetchers := make([]aggregator.PriceFetcher, 0, len(exchanges)) for _, exchangeName := range exchanges { - priceFetcher, err := fetchers.NewPriceFetcher(exchangeName, &aggregator.HttpResponseGetter{}) + priceFetcher, err := fetchers.NewPriceFetcher(exchangeName, &aggregator.HttpResponseGetter{}, tokenIdsMappings) if err != nil { return nil, err } diff --git a/config/config.go b/config/config.go index a0936e21..0b61f772 100644 --- a/config/config.go +++ b/config/config.go @@ -2,6 +2,7 @@ package config import ( "github.com/ElrondNetwork/elrond-go/config" + "github.com/ElrondNetwork/elrond-sdk-erdgo/aggregator/fetchers" ) // Configs is a holder for the relayer configuration parameters @@ -163,8 +164,9 @@ type ElrondGasMapConfig struct { // PriceNotifierConfig price notifier configuration struct type PriceNotifierConfig struct { - GeneralConfig GeneralNotifierConfig - Pairs []Pair + GeneralConfig GeneralNotifierConfig + Pairs []Pair + MexTokenIDsMappings map[string]fetchers.MaiarTokensPair } // GeneralNotifierConfig general price notifier configuration struct diff --git a/go.mod b/go.mod index a72476c9..b5d5b111 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/ElrondNetwork/elrond-go-core v1.1.14 github.com/ElrondNetwork/elrond-go-crypto v1.0.1 github.com/ElrondNetwork/elrond-go-logger v1.0.6 - github.com/ElrondNetwork/elrond-sdk-erdgo v1.0.19 + github.com/ElrondNetwork/elrond-sdk-erdgo v1.0.20 github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792 github.com/ethereum/go-ethereum v1.10.16 github.com/gin-contrib/cors v0.0.0-20190301062745-f9e10995c85a diff --git a/go.sum b/go.sum index f910a0f3..86a15f1f 100644 --- a/go.sum +++ b/go.sum @@ -69,8 +69,8 @@ github.com/ElrondNetwork/elrond-go-logger v1.0.4/go.mod h1:e5D+c97lKUfFdAzFX7rrI github.com/ElrondNetwork/elrond-go-logger v1.0.5/go.mod h1:cBfgx0ST/CJx8jrxJSC5aiSrvkGzcnF7sK06RD8mFxQ= github.com/ElrondNetwork/elrond-go-logger v1.0.6 h1:FGbO2C/s9cfNHag9jaKSB+sjuWUo+k8E+8iAz08Woac= github.com/ElrondNetwork/elrond-go-logger v1.0.6/go.mod h1:cBfgx0ST/CJx8jrxJSC5aiSrvkGzcnF7sK06RD8mFxQ= -github.com/ElrondNetwork/elrond-sdk-erdgo v1.0.19 h1:L97qYDgLsdnx1mI0x/cEWqv8eHaVSHJQ61L12oxvM/Y= -github.com/ElrondNetwork/elrond-sdk-erdgo v1.0.19/go.mod h1:J7HoBQq0ZaHoWtN/mR2Fd/m/m79IjaIjAp/RTvhvYBQ= +github.com/ElrondNetwork/elrond-sdk-erdgo v1.0.20 h1:nkl3yz1Kv4VHTBWYLxH7k9H4611rXUYJHjbD66DUSyY= +github.com/ElrondNetwork/elrond-sdk-erdgo v1.0.20/go.mod h1:J7HoBQq0ZaHoWtN/mR2Fd/m/m79IjaIjAp/RTvhvYBQ= github.com/ElrondNetwork/elrond-vm-common v1.1.0/go.mod h1:w3i6f8uiuRkE68Ie/gebRcLgTuHqvruJSYrFyZWuLrE= github.com/ElrondNetwork/elrond-vm-common v1.2.9/go.mod h1:B/Y8WiqHyDd7xsjNYsaYbVMp1jQgQ+z4jTJkFvj/EWI= github.com/ElrondNetwork/elrond-vm-common v1.3.2 h1:O/Wr5k7HXX7p0+U3ZsGdY5ydqfSABZvBSzwyV/xbu08=