-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TRA-508] Require that market exists in market map when creating new …
…oracle market (#1960)
- Loading branch information
Showing
59 changed files
with
6,533 additions
and
323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package marketmap | ||
|
||
import ( | ||
pricestypes "github.com/dydxprotocol/v4-chain/protocol/x/prices/types" | ||
"github.com/skip-mev/slinky/oracle/config" | ||
"github.com/skip-mev/slinky/providers/apis/dydx" | ||
dydxtypes "github.com/skip-mev/slinky/providers/apis/dydx/types" | ||
marketmaptypes "github.com/skip-mev/slinky/x/marketmap/types" | ||
"go.uber.org/zap" | ||
) | ||
|
||
// Construct a MarketMap struct from a slice of MarketParams | ||
func ConstructMarketMapFromParams( | ||
allMarketParams []pricestypes.MarketParam, | ||
) (marketmaptypes.MarketMap, error) { | ||
// fill out config with dummy variables to pass validation. This handler is only used to run the | ||
// ConvertMarketParamsToMarketMap member function. | ||
h, err := dydx.NewAPIHandler(zap.NewNop(), config.APIConfig{ | ||
Enabled: true, | ||
Timeout: 1, | ||
Interval: 1, | ||
ReconnectTimeout: 1, | ||
MaxQueries: 1, | ||
Atomic: false, | ||
Endpoints: []config.Endpoint{{URL: "upgrade"}}, | ||
BatchSize: 0, | ||
Name: dydx.Name, | ||
}) | ||
if err != nil { | ||
return marketmaptypes.MarketMap{}, err | ||
} | ||
|
||
var mpr dydxtypes.QueryAllMarketParamsResponse | ||
for _, mp := range allMarketParams { | ||
mpr.MarketParams = append(mpr.MarketParams, dydxtypes.MarketParam{ | ||
Id: mp.Id, | ||
Pair: mp.Pair, | ||
Exponent: mp.Exponent, | ||
MinExchanges: mp.MinExchanges, | ||
MinPriceChangePpm: mp.MinPriceChangePpm, | ||
ExchangeConfigJson: mp.ExchangeConfigJson, | ||
}) | ||
} | ||
mm, err := h.ConvertMarketParamsToMarketMap(mpr) | ||
if err != nil { | ||
return marketmaptypes.MarketMap{}, err | ||
} | ||
|
||
return mm.MarketMap, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package marketmap_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/dydxprotocol/v4-chain/protocol/lib/marketmap" | ||
pricestypes "github.com/dydxprotocol/v4-chain/protocol/x/prices/types" | ||
slinkytypes "github.com/skip-mev/slinky/pkg/types" | ||
marketmaptypes "github.com/skip-mev/slinky/x/marketmap/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestConstructMarketMapFromParams(t *testing.T) { | ||
marketParams := []pricestypes.MarketParam{ | ||
{ | ||
Pair: "BTC-USD", | ||
Exponent: -8, | ||
MinExchanges: 1, | ||
MinPriceChangePpm: 10, | ||
ExchangeConfigJson: `{"exchanges":[{"exchangeName":"Binance","ticker":"BTCUSDT"}]}`, | ||
}, | ||
} | ||
|
||
expectedMarketMap := marketmaptypes.MarketMap{ | ||
Markets: map[string]marketmaptypes.Market{ | ||
"BTC/USD": { | ||
Ticker: marketmaptypes.Ticker{ | ||
CurrencyPair: slinkytypes.CurrencyPair{Base: "BTC", Quote: "USD"}, | ||
Decimals: 8, | ||
MinProviderCount: 1, | ||
Enabled: true, | ||
Metadata_JSON: "", | ||
}, | ||
ProviderConfigs: []marketmaptypes.ProviderConfig{ | ||
{Name: "binance_ws", OffChainTicker: "BTCUSDT"}, | ||
}, | ||
}, | ||
}, | ||
} | ||
marketMap, err := marketmap.ConstructMarketMapFromParams(marketParams) | ||
require.NoError(t, err) | ||
require.NotNil(t, marketMap) | ||
require.Equal(t, expectedMarketMap, marketMap) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.