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

refactor: Provider Ticker Interface (PR1) #322

Merged
merged 33 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
babeaab
init
davidterpay Apr 5, 2024
6d54324
init
davidterpay Apr 5, 2024
cec8b81
remove code that should not be here
davidterpay Apr 5, 2024
38f8f80
remove code that should not be here v2
davidterpay Apr 5, 2024
32b7d22
testing nit
davidterpay Apr 5, 2024
28034d4
Merge branch 'feat/market-map-2' into terpay/api-provider-tickers
davidterpay Apr 5, 2024
3b8217f
cr
davidterpay Apr 7, 2024
95b4e47
removing decimals from if
davidterpay Apr 8, 2024
5581809
refactor: API Price Providers with Provider Ticker Interface (PR2) (#…
davidterpay Apr 8, 2024
e53d510
factory methods
davidterpay Apr 8, 2024
3af0b0f
oracle math done
davidterpay Apr 8, 2024
debb736
done with build
davidterpay Apr 9, 2024
e0a7529
done with build
davidterpay Apr 9, 2024
73e6d9c
done with dydx basic changes
davidterpay Apr 9, 2024
706ce14
updating
davidterpay Apr 9, 2024
1e46c4f
update
davidterpay Apr 9, 2024
0f28608
dydx provider done
davidterpay Apr 9, 2024
ad98cbc
done with oracle testing
davidterpay Apr 9, 2024
e9a621c
Merge branch 'feat/market-map-2' into terpay/api-provider-tickers
davidterpay Apr 9, 2024
be3a4e4
Merge branch 'feat/market-map-2' into terpay/api-provider-tickers
davidterpay Apr 9, 2024
bacb26d
done with providers
davidterpay Apr 9, 2024
3b1a5e5
build
davidterpay Apr 9, 2024
435c62d
configs
davidterpay Apr 9, 2024
4bbdedb
config nit
davidterpay Apr 9, 2024
fa9efc9
nits
davidterpay Apr 9, 2024
e485a54
update aggregator
davidterpay Apr 9, 2024
63c6cff
refactor: marketmap full conversion (#333)
Apr 9, 2024
a05faf3
ok
Apr 9, 2024
6bd6031
Merge branch 'feat/market-map-2' into terpay/api-provider-tickers
Apr 9, 2024
3222c50
nits
davidterpay Apr 9, 2024
b0c8f47
tidy
davidterpay Apr 9, 2024
4e159c4
remove GetProvider
davidterpay Apr 9, 2024
fbbc002
refactor: `mm2` -> `marketmap` (#334)
Apr 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 30 additions & 60 deletions cmd/slinky-config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"github.com/skip-mev/slinky/providers/websockets/mexc"
"github.com/skip-mev/slinky/providers/websockets/okx"
mmclienttypes "github.com/skip-mev/slinky/service/clients/marketmap/types"
mmtypes "github.com/skip-mev/slinky/x/marketmap/types"
mmtypes "github.com/skip-mev/slinky/x/mm2/types"
)

const (
Expand Down Expand Up @@ -86,16 +86,13 @@ var (
updateInterval time.Duration
// maxPriceAge is the maximum age of a price that the oracle will accept.
maxPriceAge time.Duration

// raydium-enabled determine whether or not the raydium defi provider will be configured.
raydiumEnabled bool

// solana node url is the solana node that the raydium provider will connect to.
solanaNodeURLs []string

// ProviderToMarkets defines a map of provider names to their respective market
// configurations. This is used to generate the local market config file.
ProviderToMarkets = map[string]types.TickerToProviderConfig{
ProviderToMarkets = map[string]types.CurrencyPairsToProviderTickers{
// ----------------------------------------------------------- //
// ---------------------Start API Providers-------------------- //
// ----------------------------------------------------------- //
Expand Down Expand Up @@ -344,10 +341,8 @@ func createOracleConfig() error {
if strings.ToLower(chain) == constants.DYDX {
// Filter out the providers that are not supported by the dYdX chain.
validProviders := make(map[string]struct{})
for _, providers := range dydx.ProviderMapping {
for _, provider := range providers {
validProviders[provider] = struct{}{}
}
for _, slinkyProvider := range dydx.ProviderMapping {
validProviders[slinkyProvider] = struct{}{}
}

ps := make([]config.ProviderConfig, 0)
Expand Down Expand Up @@ -444,11 +439,9 @@ func createMarketMap() error {
var (
// Tickers defines a map of tickers to their respective ticker configurations. This
// contains all of the tickers that are supported by the oracle.
tickers = make(map[string]mmtypes.Ticker)
// TickersToProviders defines a map of tickers to their respective providers. This
// contains all of the providers that are supported per ticker.
tickersToProviders = make(map[string]mmtypes.Providers)
tickersToPaths = make(map[string]mmtypes.Paths)
marketMap = mmtypes.MarketMap{
Markets: make(map[string]mmtypes.Market),
}
)

// if raydium is enabled, configure the raydium markets based on the local raydium_pairs fixture
Expand All @@ -458,50 +451,32 @@ func createMarketMap() error {

// Iterate through all of the provider ticker configurations and update the
// tickers and tickers to providers maps.
for name, providerConfig := range ProviderToMarkets {
for ticker, config := range providerConfig {
tickerStr := ticker.String()

// Add the ticker to the tickers map iff the ticker does not already exist. If the
// ticker already exists, ensure that the ticker configuration is the same.
if t, ok := tickers[tickerStr]; !ok {
tickers[tickerStr] = ticker
} else if t != ticker {
return fmt.Errorf("ticker %s already exists with different configuration for provider %s", tickerStr, name)
for _, providerConfig := range ProviderToMarkets {
for cp, config := range providerConfig {
ticker := mmtypes.Ticker{
CurrencyPair: cp,
Decimals: 18,
aljo242 marked this conversation as resolved.
Show resolved Hide resolved
MinProviderCount: 1,
}

// Instantiate the providers for a given ticker.
if _, ok := tickersToProviders[tickerStr]; !ok {
tickersToProviders[tickerStr] = mmtypes.Providers{}
// Add the ticker to the tickers map iff the ticker does not already exist.
if _, ok := marketMap.Markets[ticker.String()]; !ok {
marketMap.Markets[ticker.String()] = mmtypes.Market{
Ticker: ticker,
ProviderConfigs: make([]mmtypes.ProviderConfig, 0),
}
}

// Add the provider to the tickers to providers map.
providers := tickersToProviders[tickerStr].Providers
providers = append(providers, config)
tickersToProviders[tickerStr] = mmtypes.Providers{Providers: providers}

if _, ok := tickersToPaths[tickerStr]; !ok {
tickersToPaths[tickerStr] = mmtypes.Paths{}
}
paths := tickersToPaths[tickerStr].Paths
paths = append(paths, mmtypes.Path{Operations: []mmtypes.Operation{
{
CurrencyPair: ticker.CurrencyPair,
Invert: false,
Provider: config.Name,
},
}})
tickersToPaths[tickerStr] = mmtypes.Paths{Paths: paths}
market := marketMap.Markets[ticker.String()]
market.ProviderConfigs = append(market.ProviderConfigs, mmtypes.ProviderConfig{
Name: config.Name,
OffChainTicker: config.OffChainTicker,
Metadata_JSON: config.JSON,
})
marketMap.Markets[ticker.String()] = market
}
}

// Create a new market map from the provider to market map.
marketMap := mmtypes.MarketMap{
Tickers: tickers,
Providers: tickersToProviders,
Paths: tickersToPaths,
}

// Validate the market map.
if err := marketMap.ValidateBasic(); err != nil {
return fmt.Errorf("error validating the market map: %w", err)
Expand Down Expand Up @@ -538,7 +513,7 @@ type TickerMetaData struct {
TickerMetaData raydium.TickerMetadata `json:"ticker_metadata"`
}

func addRaydiumMarkets(providerToMarkets map[string]map[mmtypes.Ticker]mmtypes.ProviderConfig) map[string]map[mmtypes.Ticker]mmtypes.ProviderConfig {
func addRaydiumMarkets(providerToMarkets map[string]types.CurrencyPairsToProviderTickers) map[string]types.CurrencyPairsToProviderTickers {
// read the raydium_pairs fixture
if !raydiumEnabled {
return providerToMarkets
Expand All @@ -565,17 +540,12 @@ func addRaydiumMarkets(providerToMarkets map[string]map[mmtypes.Ticker]mmtypes.P
}

// add the raydium markets to the provider to markets map
providerToMarkets[raydium.Name] = make(map[mmtypes.Ticker]mmtypes.ProviderConfig)
providerToMarkets[raydium.Name] = make(types.CurrencyPairsToProviderTickers)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nivasan1 can you make sure this still functions as desired.

for _, pair := range raydiumPairs {
providerToMarkets[raydium.Name][mmtypes.Ticker{
CurrencyPair: pair.Cp,
Decimals: 18,
MinProviderCount: 1,
Enabled: true,
Metadata_JSON: marshalToJSONString(pair.TickerMetaData),
}] = mmtypes.ProviderConfig{
providerToMarkets[raydium.Name][pair.Cp] = types.DefaultProviderTicker{
Name: raydium.Name,
OffChainTicker: pair.Cp.String(),
JSON: marshalToJSONString(pair.TickerMetaData),
}
}

Expand Down
5 changes: 2 additions & 3 deletions cmd/slinky/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ import (
"github.com/skip-mev/slinky/oracle/config"
oraclemetrics "github.com/skip-mev/slinky/oracle/metrics"
"github.com/skip-mev/slinky/oracle/orchestrator"
"github.com/skip-mev/slinky/oracle/types"
oraclemath "github.com/skip-mev/slinky/pkg/math/oracle"
oraclefactory "github.com/skip-mev/slinky/providers/factories/oracle"
oracleserver "github.com/skip-mev/slinky/service/servers/oracle"
promserver "github.com/skip-mev/slinky/service/servers/prometheus"
mmtypes "github.com/skip-mev/slinky/x/marketmap/types"
mmtypes "github.com/skip-mev/slinky/x/mm2/types"
)

var (
Expand Down Expand Up @@ -104,7 +103,7 @@ func runOracle() error {

var marketCfg mmtypes.MarketMap
if marketCfgPath != "" {
marketCfg, err = types.ReadMarketConfigFromFile(marketCfgPath)
marketCfg, err = mmtypes.ReadMarketConfigFromFile(marketCfgPath)
if err != nil {
return fmt.Errorf("failed to read market config file: %s", err.Error())
}
Expand Down
Loading
Loading