Skip to content

Commit

Permalink
[TRA-508] Require that market exists in market map when creating new …
Browse files Browse the repository at this point in the history
…oracle market (#1960)
  • Loading branch information
chenyaoy authored Jul 25, 2024
1 parent 4199c3e commit 37f74d0
Show file tree
Hide file tree
Showing 59 changed files with 6,533 additions and 323 deletions.
4 changes: 2 additions & 2 deletions protocol/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,7 @@ func New(
feegrant.ModuleName,
consensusparamtypes.ModuleName,
icatypes.ModuleName,
marketmapmoduletypes.ModuleName, // must be before prices
pricesmoduletypes.ModuleName,
assetsmoduletypes.ModuleName,
blocktimemoduletypes.ModuleName,
Expand All @@ -1393,7 +1394,6 @@ func New(
listingmoduletypes.ModuleName,
revsharemoduletypes.ModuleName,
accountplusmoduletypes.ModuleName,
marketmapmoduletypes.ModuleName,
authz.ModuleName,
)

Expand All @@ -1419,6 +1419,7 @@ func New(
feegrant.ModuleName,
consensusparamtypes.ModuleName,
icatypes.ModuleName,
marketmapmoduletypes.ModuleName,
pricesmoduletypes.ModuleName,
assetsmoduletypes.ModuleName,
blocktimemoduletypes.ModuleName,
Expand All @@ -1437,7 +1438,6 @@ func New(
listingmoduletypes.ModuleName,
revsharemoduletypes.ModuleName,
accountplusmoduletypes.ModuleName,
marketmapmoduletypes.ModuleName,
authz.ModuleName,

// Auth must be migrated after staking.
Expand Down
4 changes: 2 additions & 2 deletions protocol/app/prepare/prepare_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func TestPrepareProposalHandler(t *testing.T) {
mockClobKeeper.On("GetOperations", mock.Anything, mock.Anything).
Return(tc.clobResp)

ctx, _, _, _, _, _ := keepertest.PricesKeepers(t)
ctx, _, _, _, _, _, _ := keepertest.PricesKeepers(t)

handler := prepare.PrepareProposalHandler(
mockTxConfig,
Expand Down Expand Up @@ -440,7 +440,7 @@ func TestPrepareProposalHandler_OtherTxs(t *testing.T) {
mockBridgeKeeper.On("GetAcknowledgeBridges", mock.Anything, mock.Anything).
Return(constants.MsgAcknowledgeBridges_Ids0_1_Height0)

ctx, _, _, _, _, _ := keepertest.PricesKeepers(t)
ctx, _, _, _, _, _, _ := keepertest.PricesKeepers(t)

handler := prepare.PrepareProposalHandler(
encodingCfg.TxConfig,
Expand Down
2 changes: 1 addition & 1 deletion protocol/app/process/full_node_process_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestFullNodeProcessProposalHandler(t *testing.T) {
// Setup.
_, bridgeKeeper, _, _, _, _, _ := keepertest.BridgeKeepers(t)

ctx, pricesKeeper, _, indexPriceCache, mockTimeProvider, _ := keepertest.PricesKeepers(t)
ctx, pricesKeeper, _, indexPriceCache, mockTimeProvider, _, _ := keepertest.PricesKeepers(t)
mockTimeProvider.On("Now").Return(constants.TimeT)
keepertest.CreateTestMarkets(t, ctx, pricesKeeper)
indexPriceCache.UpdatePrices(constants.AtTimeTSingleExchangePriceUpdate)
Expand Down
6 changes: 3 additions & 3 deletions protocol/app/process/market_prices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestDecodeUpdateMarketPricesTx(t *testing.T) {

for name, tc := range tests {
t.Run(name, func(t *testing.T) {
ctx, k, _, _, _, _ := keepertest.PricesKeepers(t)
ctx, k, _, _, _, _, _ := keepertest.PricesKeepers(t)
pricesTxDecoder := process.NewDefaultUpdateMarketPriceTxDecoder(k, encodingCfg.TxConfig.TxDecoder())
umpt, err := pricesTxDecoder.DecodeUpdateMarketPricesTx(ctx, [][]byte{tc.txBytes})
if tc.expectedErr != nil {
Expand Down Expand Up @@ -120,7 +120,7 @@ func TestUpdateMarketPricesTx_Validate(t *testing.T) {
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
// Setup.
ctx, k, _, indexPriceCache, mockTimeProvider, _ := keepertest.PricesKeepers(t)
ctx, k, _, indexPriceCache, mockTimeProvider, _, _ := keepertest.PricesKeepers(t)
mockTimeProvider.On("Now").Return(constants.TimeT)
keepertest.CreateTestMarkets(t, ctx, k)
indexPriceCache.UpdatePrices(tc.indexPrices)
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestUpdateMarketPricesTx_GetMsg(t *testing.T) {
t.Run(name, func(t *testing.T) {
var msg sdk.Msg
if tc.txBytes != nil {
ctx, k, _, _, _, _ := keepertest.PricesKeepers(t)
ctx, k, _, _, _, _, _ := keepertest.PricesKeepers(t)

// Decode.
pricesTxDecoder := process.NewDefaultUpdateMarketPriceTxDecoder(k, constants.TestEncodingCfg.TxConfig.TxDecoder())
Expand Down
2 changes: 1 addition & 1 deletion protocol/app/process/process_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func TestProcessProposalHandler_Error(t *testing.T) {
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
// Setup.
ctx, pricesKeeper, _, indexPriceCache, mockTimeProvider, _ := keepertest.PricesKeepers(t)
ctx, pricesKeeper, _, indexPriceCache, mockTimeProvider, _, _ := keepertest.PricesKeepers(t)
mockTimeProvider.On("Now").Return(constants.TimeT)
keepertest.CreateTestMarkets(t, ctx, pricesKeeper)
indexPriceCache.UpdatePrices(constants.AtTimeTSingleExchangePriceUpdate)
Expand Down
8 changes: 4 additions & 4 deletions protocol/app/process/transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func TestDecodeProcessProposalTxs_Error(t *testing.T) {
t.Run(name, func(t *testing.T) {
// Setup.
_, bridgeKeeper, _, _, _, _, _ := keepertest.BridgeKeepers(t)
ctx, pricesKeeper, _, _, _, _ := keepertest.PricesKeepers(t)
ctx, pricesKeeper, _, _, _, _, _ := keepertest.PricesKeepers(t)

// Run.
_, err := process.DecodeProcessProposalTxs(
Expand Down Expand Up @@ -188,7 +188,7 @@ func TestDecodeProcessProposalTxs_Valid(t *testing.T) {
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
// Setup.
ctx, pricesKeeper, _, _, _, _ := keepertest.PricesKeepers(t)
ctx, pricesKeeper, _, _, _, _, _ := keepertest.PricesKeepers(t)
_, bridgeKeeper, _, _, _, _, _ := keepertest.BridgeKeepers(t)

// Run.
Expand Down Expand Up @@ -318,7 +318,7 @@ func TestProcessProposalTxs_Validate_Error(t *testing.T) {
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
// Setup.
ctx, pricesKeeper, _, indexPriceCache, mockTimeProvider, _ := keepertest.PricesKeepers(t)
ctx, pricesKeeper, _, indexPriceCache, mockTimeProvider, _, _ := keepertest.PricesKeepers(t)
mockTimeProvider.On("Now").Return(constants.TimeT)
keepertest.CreateTestMarkets(t, ctx, pricesKeeper)
indexPriceCache.UpdatePrices(constants.AtTimeTSingleExchangePriceUpdate)
Expand Down Expand Up @@ -425,7 +425,7 @@ func TestProcessProposalTxs_Validate_Valid(t *testing.T) {
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
// Setup.
ctx, pricesKeeper, _, indexPriceCache, mockTimeProvider, _ := keepertest.PricesKeepers(t)
ctx, pricesKeeper, _, indexPriceCache, mockTimeProvider, _, _ := keepertest.PricesKeepers(t)
mockTimeProvider.On("Now").Return(constants.TimeT)
keepertest.CreateTestMarkets(t, ctx, pricesKeeper)
indexPriceCache.UpdatePrices(constants.AtTimeTSingleExchangePriceUpdate)
Expand Down
14 changes: 7 additions & 7 deletions protocol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ require (
cosmossdk.io/api v0.7.5
cosmossdk.io/math v1.3.0
github.com/Shopify/sarama v1.37.2
github.com/cometbft/cometbft v0.38.9
github.com/cometbft/cometbft v0.38.10
github.com/cometbft/cometbft-db v0.10.0 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.5
github.com/cosmos/cosmos-sdk v0.50.7
github.com/cosmos/cosmos-sdk v0.50.8
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/gogoproto v1.5.0
github.com/go-playground/validator/v10 v10.14.0
Expand Down Expand Up @@ -67,7 +67,7 @@ require (
github.com/pelletier/go-toml v1.9.5
github.com/rs/zerolog v1.32.0
github.com/shopspring/decimal v1.3.1
github.com/skip-mev/slinky v1.0.4-0.20240715165738-8218f83b6eb1
github.com/skip-mev/slinky v1.0.5-0.20240724193421-2d84d381bba4
github.com/spf13/viper v1.19.0
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d
go.uber.org/zap v1.27.0
Expand All @@ -84,7 +84,7 @@ require (
cloud.google.com/go/iam v1.1.6 // indirect
cloud.google.com/go/storage v1.38.0 // indirect
cosmossdk.io/collections v0.4.0 // indirect
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/depinject v1.0.0 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/4meepo/tagalign v1.3.4 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
Expand Down Expand Up @@ -423,17 +423,17 @@ require (
go.uber.org/ratelimit v0.2.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/exp/typeparams v0.0.0-20240314144324-c7f7c6466f7f // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/mod v0.19.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/oauth2 v0.20.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/term v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.22.0 // indirect
golang.org/x/tools v0.23.0 // indirect
google.golang.org/api v0.171.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
20 changes: 10 additions & 10 deletions protocol/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,8 @@ cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s=
cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0=
cosmossdk.io/core v0.11.0 h1:vtIafqUi+1ZNAE/oxLOQQ7Oek2n4S48SWLG8h/+wdbo=
cosmossdk.io/core v0.11.0/go.mod h1:LaTtayWBSoacF5xNzoF8tmLhehqlA9z1SWiPuNC6X1w=
cosmossdk.io/depinject v1.0.0-alpha.4 h1:PLNp8ZYAMPTUKyG9IK2hsbciDWqna2z1Wsl98okJopc=
cosmossdk.io/depinject v1.0.0-alpha.4/go.mod h1:HeDk7IkR5ckZ3lMGs/o91AVUc7E596vMaOmslGFM3yU=
cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050=
cosmossdk.io/depinject v1.0.0/go.mod h1:zxK/h3HgHoA/eJVtiSsoaRaRA2D5U4cJ5thIG4ssbB8=
cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0=
cosmossdk.io/errors v1.0.1/go.mod h1:MeelVSZThMi4bEakzhhhE/CKqVv3nOJDA25bIqRDu/U=
cosmossdk.io/log v1.3.1 h1:UZx8nWIkfbbNEWusZqzAx3ZGvu54TZacWib3EzUYmGI=
Expand Down Expand Up @@ -1754,8 +1754,8 @@ github.com/sivchari/tenv v1.7.1 h1:PSpuD4bu6fSmtWMxSGWcvqUUgIn7k3yOJhOIzVWn8Ak=
github.com/sivchari/tenv v1.7.1/go.mod h1:64yStXKSOxDfX47NlhVwND4dHwfZDdbp2Lyl018Icvg=
github.com/skip-mev/chaintestutil v0.0.0-20240116134208-3e49bf514803 h1:VRRVYN3wsOIOqVT3e3nDh3vyUl6RvF9QwdK4BvgPP9c=
github.com/skip-mev/chaintestutil v0.0.0-20240116134208-3e49bf514803/go.mod h1:LF2koCTmygQnz11yjSfHvNP8axdyZ2lTEw0EwI+dnno=
github.com/skip-mev/slinky v1.0.4-0.20240715165738-8218f83b6eb1 h1:eIWyyjfpFdgodF/v9C7onUUXQxSSyDOAGKFcgRAVgMo=
github.com/skip-mev/slinky v1.0.4-0.20240715165738-8218f83b6eb1/go.mod h1:+iC+HmAIqJHqeka5f96sI0bqsiXfcAjZ7sQk7nF78co=
github.com/skip-mev/slinky v1.0.5-0.20240724193421-2d84d381bba4 h1:WXwV5R+DmBd2dYFOHmh+lXOqCidtIENtDDOz4RKhJ8g=
github.com/skip-mev/slinky v1.0.5-0.20240724193421-2d84d381bba4/go.mod h1:I47xFOLQZ5d0f9cH7k9RtKoakIPLfbT0sJhinOvASBM=
github.com/sonatard/noctx v0.0.2 h1:L7Dz4De2zDQhW8S0t+KUjY0MAQJd6SgVwhzNIc4ok00=
github.com/sonatard/noctx v0.0.2/go.mod h1:kzFz+CzWSjQ2OzIm46uJZoXuBpa2+0y3T36U18dWqIo=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
Expand Down Expand Up @@ -2063,8 +2063,8 @@ golang.org/x/mod v0.6.0/go.mod h1:4mET923SAdbXp2ki8ey+zGs1SLqsuM2Y0uvdZR/fUNI=
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0=
golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8=
golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -2426,8 +2426,8 @@ golang.org/x/tools v0.3.0/go.mod h1:/rWhSS2+zyEVwoJf8YAX6L2f0ntZ7Kn/mGgAWcipA5k=
golang.org/x/tools v0.5.0/go.mod h1:N+Kgy78s5I24c24dU8OfWNEotWjutIs8SnJvn5IDq+k=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s=
golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA=
golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c=
golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg=
golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down Expand Up @@ -2669,8 +2669,8 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234015-3fc162c6f38a/go.
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230526203410-71b5a4ffd15e/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 h1:Zy9XzmMEflZ/MAaA7vNcoebnRAld7FsPW1EeBB7V0m8=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5 h1:SbSDUWW1PAO24TNpLdeheoYPd7kllICcLU52x6eD4kQ=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
Expand Down
50 changes: 50 additions & 0 deletions protocol/lib/marketmap/utils.go
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
}
44 changes: 44 additions & 0 deletions protocol/lib/marketmap/utils_test.go
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)
}
37 changes: 37 additions & 0 deletions protocol/mocks/OracleClient.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 37f74d0

Please sign in to comment.