Skip to content

Commit

Permalink
Merge branch 'main' into ryan/clientless-param-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
rbajollari authored Aug 26, 2024
2 parents cfdfdf4 + 3db3979 commit d8cc362
Show file tree
Hide file tree
Showing 13 changed files with 1,393 additions and 168 deletions.
60 changes: 9 additions & 51 deletions config/currency_provider_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ import (
)

const (
coinGeckoRestURL = "https://api.coingecko.com/api/v3/coins"
coinGeckoListEndpoint = "list"
coinGeckoTickersEndpoint = "tickers"
osmosisRestURL = "https://api.osmo-api.prod.ojo.network"
osmosisAssetPairsEndpoint = "assetpairs"
crescentRestURL = "https://api.cresc-api.prod.ojo.network"
crescentAssetPairsEndpoint = "assetpairs"
requestTimeout = time.Second * 2
trackingPeriod = time.Hour * 24
coinGeckoRestURL = "https://api.coingecko.com/api/v3/coins"
coinGeckoListEndpoint = "list"
coinGeckoTickersEndpoint = "tickers"
osmosisRestURL = "https://api.osmo-api.prod.ojo.network"
osmosisAssetPairsEndpoint = "assetpairs"
requestTimeout = time.Second * 2
trackingPeriod = time.Hour * 24
)

type (
Expand Down Expand Up @@ -90,12 +88,7 @@ func NewCurrencyProviderTracker(
return nil, err
}

crescentAPIPairs, err := currencyProviderTracker.getCrescentAPIPairs()
if err != nil {
return nil, err
}

if err := currencyProviderTracker.setCurrencyProviders(osmosisAPIPairs, crescentAPIPairs); err != nil {
if err := currencyProviderTracker.setCurrencyProviders(osmosisAPIPairs); err != nil {
return nil, err
}

Expand Down Expand Up @@ -159,36 +152,10 @@ func (t *CurrencyProviderTracker) getOsmosisAPIPairs() (map[string]string, error
return osmosisAPIPairs, nil
}

// getCrescentAPIPairs queries the crescent-api assetpairs endpoint to get the asset pairs
// supported by it.
func (t *CurrencyProviderTracker) getCrescentAPIPairs() (map[string]string, error) {
client := &http.Client{
Timeout: requestTimeout,
}
crescentAPIPairs := make(map[string]string)

crescentResp, err := client.Get(fmt.Sprintf("%s/%s", crescentRestURL, crescentAssetPairsEndpoint))
if err != nil {
return nil, err
}
defer crescentResp.Body.Close()
var assetPairsResponse []assetPair
if err = json.NewDecoder(crescentResp.Body).Decode(&assetPairsResponse); err != nil {
return nil, err
}

for _, assetPair := range assetPairsResponse {
crescentAPIPairs[assetPair.Base] = assetPair.Quote
}

return crescentAPIPairs, nil
}

// setCurrencyProviders queries CoinGecko's tickers endpoint to get all the exchanges
// that support each price feeder currency pair and store it in the CurrencyProviders map.
func (t *CurrencyProviderTracker) setCurrencyProviders(
osmosisAPIPairs map[string]string,
crescentAPIPairs map[string]string,
) error {
client := &http.Client{
Timeout: requestTimeout,
Expand All @@ -199,11 +166,6 @@ func (t *CurrencyProviderTracker) setCurrencyProviders(
t.CurrencyProviders[pair.Base] = append(t.CurrencyProviders[pair.Base], "osmosis")
}

// check if its a pair supported by the crescent api
if crescentAPIPairs[strings.ToUpper(pair.Base)] == strings.ToUpper(pair.Quote) {
t.CurrencyProviders[pair.Base] = append(t.CurrencyProviders[pair.Base], "crescent")
}

// check if CoinGecko API supports pair
pairBaseID := t.coinIDSymbolMap[strings.ToLower(pair.Base)]
coinGeckoResp, err := client.Get(fmt.Sprintf("%s/%s/%s", coinGeckoRestURL, pairBaseID, coinGeckoTickersEndpoint))
Expand Down Expand Up @@ -259,11 +221,7 @@ func (t *CurrencyProviderTracker) trackCurrencyProviders(ctx context.Context) {
if err != nil {
t.logger.Error().Err(err).Msg("failed to query osmosis-api for available asset pairs")
}
crescentAPIPairs, err := t.getOsmosisAPIPairs()
if err != nil {
t.logger.Error().Err(err).Msg("failed to query crescent-api for available asset pairs")
}
if err := t.setCurrencyProviders(osmosisAPIPairs, crescentAPIPairs); err != nil {
if err := t.setCurrencyProviders(osmosisAPIPairs); err != nil {
t.logger.Error().Err(err).Msg("failed to set available providers for currencies")
}

Expand Down
38 changes: 21 additions & 17 deletions config/supported_assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,26 @@ var (
// SupportedProviders defines a lookup table of all the supported currency API
// providers and whether or not they require an API key to be passed in.
SupportedProviders = map[types.ProviderName]APIKeyRequired{
provider.ProviderKraken: false,
provider.ProviderBinance: false,
provider.ProviderBinanceUS: false,
provider.ProviderCrescent: false,
provider.ProviderOsmosis: false,
provider.ProviderOkx: false,
provider.ProviderHuobi: false,
provider.ProviderGate: false,
provider.ProviderCoinbase: false,
provider.ProviderBitget: false,
provider.ProviderMexc: false,
provider.ProviderCrypto: false,
provider.ProviderPolygon: true,
provider.ProviderEthUniswap: false,
provider.ProviderKujira: false,
provider.ProviderAstroport: false,
provider.ProviderMock: false,
provider.ProviderKraken: false,
provider.ProviderBinance: false,
provider.ProviderBinanceUS: false,
provider.ProviderOsmosis: false,
provider.ProviderOkx: false,
provider.ProviderHuobi: false,
provider.ProviderGate: false,
provider.ProviderCoinbase: false,
provider.ProviderBitget: false,
provider.ProviderMexc: false,
provider.ProviderCrypto: false,
provider.ProviderPolygon: true,
provider.ProviderEthUniswap: false,
provider.ProviderEthCamelot: false,
provider.ProviderEthBalancer: false,
provider.ProviderEthPancake: false,
provider.ProviderEthCurve: false,
provider.ProviderKujira: false,
provider.ProviderAstroport: false,
provider.ProviderMock: false,
}

// SupportedConversions defines a lookup table for which currency pairs we
Expand All @@ -47,6 +50,7 @@ var (
{Base: "OSMO", Quote: "USDT"}: {},
{Base: "JUNO", Quote: "USDT"}: {},
{Base: "WETH", Quote: "USDC"}: {},
{Base: "WBTC", Quote: "BTC"}: {},
{Base: "WBTC", Quote: "WETH"}: {},
{Base: "INJ", Quote: "USDT"}: {},
{Base: "TIA", Quote: "USDT"}: {},
Expand Down
15 changes: 12 additions & 3 deletions oracle/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,6 @@ func NewProvider(
case provider.ProviderPolygon:
return provider.NewPolygonProvider(ctx, logger, endpoint, providerPairs...)

case provider.ProviderCrescent:
return provider.NewCrescentProvider(ctx, logger, endpoint, providerPairs...)

case provider.ProviderKujira:
return provider.NewKujiraProvider(ctx, logger, endpoint, providerPairs...)

Expand All @@ -525,6 +522,18 @@ func NewProvider(
case provider.ProviderEthUniswap:
return provider.NewUniswapProvider(ctx, logger, endpoint, providerPairs...)

case provider.ProviderEthCamelot:
return provider.NewCamelotProvider(ctx, logger, endpoint, providerPairs...)

case provider.ProviderEthBalancer:
return provider.NewBalancerProvider(ctx, logger, endpoint, providerPairs...)

case provider.ProviderEthPancake:
return provider.NewPancakeProvider(ctx, logger, endpoint, providerPairs...)

case provider.ProviderEthCurve:
return provider.NewCurveProvider(ctx, logger, endpoint, providerPairs...)

case provider.ProviderAstroport:
return provider.NewAstroportProvider(ctx, logger, endpoint, providerPairs...)
}
Expand Down
Loading

0 comments on commit d8cc362

Please sign in to comment.