Skip to content

Commit

Permalink
Merge pull request #236 from ElrondNetwork/price-feeder-maiar-exchange
Browse files Browse the repository at this point in the history
Support for maiar exchange into priceFeeder
  • Loading branch information
sstanculeanu authored May 6, 2022
2 parents c2221a4 + bfe6ba4 commit 34a353b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 10 deletions.
27 changes: 25 additions & 2 deletions cmd/priceFeeder/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand All @@ -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"
12 changes: 9 additions & 3 deletions cmd/priceFeeder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 4 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 34a353b

Please sign in to comment.