diff --git a/indexer/packages/v4-protos/src/codegen/dydxprotocol/prices/market_param.ts b/indexer/packages/v4-protos/src/codegen/dydxprotocol/prices/market_param.ts index d945e1c82f..95ed7d6c89 100644 --- a/indexer/packages/v4-protos/src/codegen/dydxprotocol/prices/market_param.ts +++ b/indexer/packages/v4-protos/src/codegen/dydxprotocol/prices/market_param.ts @@ -18,8 +18,12 @@ export interface MarketParam { * For example if `Exponent == -5` then a `Value` of `1,000,000,000` * represents ``$10,000`. Therefore `10 ^ Exponent` represents the smallest * price step (in dollars) that can be recorded. + * + * Deprecated since v7.1.x. This value is now determined from the marketmap. */ + /** @deprecated */ + exponent: number; /** * The minimum number of exchanges that should be reporting a live price for @@ -58,8 +62,12 @@ export interface MarketParamSDKType { * For example if `Exponent == -5` then a `Value` of `1,000,000,000` * represents ``$10,000`. Therefore `10 ^ Exponent` represents the smallest * price step (in dollars) that can be recorded. + * + * Deprecated since v7.1.x. This value is now determined from the marketmap. */ + /** @deprecated */ + exponent: number; /** * The minimum number of exchanges that should be reporting a live price for diff --git a/indexer/packages/v4-protos/src/codegen/dydxprotocol/prices/market_price.ts b/indexer/packages/v4-protos/src/codegen/dydxprotocol/prices/market_price.ts index e8cd1ae596..5320c2c801 100644 --- a/indexer/packages/v4-protos/src/codegen/dydxprotocol/prices/market_price.ts +++ b/indexer/packages/v4-protos/src/codegen/dydxprotocol/prices/market_price.ts @@ -8,6 +8,9 @@ export interface MarketPrice { /** * Static value. The exponent of the price. See the comment on the duplicate * MarketParam field for more information. + * + * As of v7.1.x, this value is determined from the marketmap instead of + * needing to match the MarketParam field. */ exponent: number; @@ -26,6 +29,9 @@ export interface MarketPriceSDKType { /** * Static value. The exponent of the price. See the comment on the duplicate * MarketParam field for more information. + * + * As of v7.1.x, this value is determined from the marketmap instead of + * needing to match the MarketParam field. */ exponent: number; diff --git a/proto/dydxprotocol/prices/market_param.proto b/proto/dydxprotocol/prices/market_param.proto index 0ad48809bd..4b90b2877b 100644 --- a/proto/dydxprotocol/prices/market_param.proto +++ b/proto/dydxprotocol/prices/market_param.proto @@ -18,7 +18,9 @@ message MarketParam { // For example if `Exponent == -5` then a `Value` of `1,000,000,000` // represents ``$10,000`. Therefore `10 ^ Exponent` represents the smallest // price step (in dollars) that can be recorded. - sint32 exponent = 3; + // + // Deprecated since v7.1.x. This value is now determined from the marketmap. + sint32 exponent = 3 [ deprecated = true ]; // The minimum number of exchanges that should be reporting a live price for // a price update to be considered valid. diff --git a/proto/dydxprotocol/prices/market_price.proto b/proto/dydxprotocol/prices/market_price.proto index acfd996750..a77078bc78 100644 --- a/proto/dydxprotocol/prices/market_price.proto +++ b/proto/dydxprotocol/prices/market_price.proto @@ -10,6 +10,9 @@ message MarketPrice { // Static value. The exponent of the price. See the comment on the duplicate // MarketParam field for more information. + // + // As of v7.1.x, this value is determined from the marketmap instead of + // needing to match the MarketParam field. sint32 exponent = 2; // The variable value that is updated by oracle price updates. `0` if it has diff --git a/protocol/app/ante/market_update_test.go b/protocol/app/ante/market_update_test.go index f7ca81c160..b1e3dc1460 100644 --- a/protocol/app/ante/market_update_test.go +++ b/protocol/app/ante/market_update_test.go @@ -1,10 +1,11 @@ package ante_test import ( - storetypes "cosmossdk.io/store/types" "math/rand" "testing" + storetypes "cosmossdk.io/store/types" + sdkmath "cosmossdk.io/math" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/dydxprotocol/v4-chain/protocol/dtypes" @@ -185,7 +186,7 @@ var ( Base: "TESTING", Quote: "USD", }, - Decimals: 1, + Decimals: 8, MinProviderCount: 1, Enabled: false, Metadata_JSON: "", @@ -199,7 +200,7 @@ var ( Base: "TESTING", Quote: "USD", }, - Decimals: 1, + Decimals: 8, MinProviderCount: 1, Enabled: false, Metadata_JSON: "", @@ -218,7 +219,7 @@ var ( Base: "TESTING", Quote: "USD", }, - Decimals: 1, + Decimals: 8, MinProviderCount: 1, Enabled: true, Metadata_JSON: "", @@ -237,7 +238,7 @@ var ( Base: "TESTING", Quote: "USD", }, - Decimals: 1, + Decimals: 8, MinProviderCount: 1, Enabled: true, Metadata_JSON: "", @@ -763,7 +764,7 @@ func TestValidateMarketUpdateDecorator_AnteHandle(t *testing.T) { ctx, mmtypes.Market{ Ticker: mmtypes.Ticker{ - Decimals: uint64(pair.market.Exponent), + Decimals: uint64(pair.market.Exponent * -1), Enabled: false, // will be enabled later CurrencyPair: cp, }, diff --git a/protocol/mocks/PricesKeeper.go b/protocol/mocks/PricesKeeper.go index f2e053b193..7eecd7edb1 100644 --- a/protocol/mocks/PricesKeeper.go +++ b/protocol/mocks/PricesKeeper.go @@ -150,6 +150,34 @@ func (_m *PricesKeeper) GetCurrencyPairFromID(ctx types.Context, id uint64) (pkg return r0, r1 } +// GetExponent provides a mock function with given fields: ctx, ticker +func (_m *PricesKeeper) GetExponent(ctx types.Context, ticker string) (int32, error) { + ret := _m.Called(ctx, ticker) + + if len(ret) == 0 { + panic("no return value specified for GetExponent") + } + + var r0 int32 + var r1 error + if rf, ok := ret.Get(0).(func(types.Context, string) (int32, error)); ok { + return rf(ctx, ticker) + } + if rf, ok := ret.Get(0).(func(types.Context, string) int32); ok { + r0 = rf(ctx, ticker) + } else { + r0 = ret.Get(0).(int32) + } + + if rf, ok := ret.Get(1).(func(types.Context, string) error); ok { + r1 = rf(ctx, ticker) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // GetIDForCurrencyPair provides a mock function with given fields: ctx, cp func (_m *PricesKeeper) GetIDForCurrencyPair(ctx types.Context, cp pkgtypes.CurrencyPair) (uint64, bool) { ret := _m.Called(ctx, cp) diff --git a/protocol/testing/e2e/gov/prices_test.go b/protocol/testing/e2e/gov/prices_test.go index 89f2b996b8..f73996e6ed 100644 --- a/protocol/testing/e2e/gov/prices_test.go +++ b/protocol/testing/e2e/gov/prices_test.go @@ -67,20 +67,6 @@ func TestUpdateMarketParam(t *testing.T) { }, expectedProposalStatus: govtypesv1.ProposalStatus_PROPOSAL_STATUS_FAILED, }, - "Failure: exponent is updated": { - msg: &pricestypes.MsgUpdateMarketParam{ - Authority: lib.GovModuleAddress.String(), - MarketParam: pricestypes.MarketParam{ - Id: MODIFIED_MARKET_PARAM.Id, - Pair: MODIFIED_MARKET_PARAM.Pair, - Exponent: MODIFIED_MARKET_PARAM.Exponent + 1, // update to exponent is not permitted. - MinExchanges: MODIFIED_MARKET_PARAM.MinExchanges, - MinPriceChangePpm: MODIFIED_MARKET_PARAM.MinPriceChangePpm, - ExchangeConfigJson: MODIFIED_MARKET_PARAM.ExchangeConfigJson, - }, - }, - expectedProposalStatus: govtypesv1.ProposalStatus_PROPOSAL_STATUS_FAILED, - }, "Failure: empty pair": { msg: &pricestypes.MsgUpdateMarketParam{ Authority: lib.GovModuleAddress.String(), diff --git a/protocol/testutil/app/order.go b/protocol/testutil/app/order.go index 69cd7208f1..56a2096f8c 100644 --- a/protocol/testutil/app/order.go +++ b/protocol/testutil/app/order.go @@ -40,11 +40,17 @@ func MustMakeOrderFromHumanInput( if !exists { panic(fmt.Sprintf("marketParam does not exist: %v", perp.Params.MarketId)) } - marketPrice := pricestest.MustHumanPriceToMarketPrice(humanPrice, marketParams.Exponent) + + exponent, err := app.PricesKeeper.GetExponent(ctx, marketParams.Pair) + if err != nil { + panic(err) + } + + marketPrice := pricestest.MustHumanPriceToMarketPrice(humanPrice, exponent) subticks := clobtypes.PriceToSubticks( pricestypes.MarketPrice{ Price: marketPrice, - Exponent: marketParams.Exponent, + Exponent: exponent, }, clobPair, perp.Params.AtomicResolution, diff --git a/protocol/testutil/constants/genesis.go b/protocol/testutil/constants/genesis.go index a33db9f187..2c6a3862f6 100644 --- a/protocol/testutil/constants/genesis.go +++ b/protocol/testutil/constants/genesis.go @@ -4002,7 +4002,7 @@ const GenesisState = `{ }, { "exchange_config_json": "{\"exchanges\":[{\"exchangeName\":\"Binance\",\"ticker\":\"\\\"LINKUSDT\\\"\"},{\"exchangeName\":\"BinanceUS\",\"ticker\":\"\\\"LINKUSD\\\"\"},{\"exchangeName\":\"CoinbasePro\",\"ticker\":\"LINK-USD\"},{\"exchangeName\":\"CryptoCom\",\"ticker\":\"LINK_USD\"},{\"exchangeName\":\"Huobi\",\"ticker\":\"linkusdt\"},{\"exchangeName\":\"Kraken\",\"ticker\":\"LINKUSD\"},{\"exchangeName\":\"Kucoin\",\"ticker\":\"LINK-USDT\"},{\"exchangeName\":\"Okx\",\"ticker\":\"LINK-USDT\"}]}", - "exponent": -8, + "exponent": -9, "id": 2, "min_exchanges": 1, "min_price_change_ppm": 2000, @@ -4170,7 +4170,7 @@ const GenesisState = `{ }, { "exchange_config_json": "{\"exchanges\":[{\"exchangeName\":\"Binance\",\"ticker\":\"\\\"MKRUSDT\\\"\"},{\"exchangeName\":\"BinanceUS\",\"ticker\":\"\\\"MKRUSD\\\"\"},{\"exchangeName\":\"Bitfinex\",\"ticker\":\"tMKRUSD\"},{\"exchangeName\":\"CoinbasePro\",\"ticker\":\"MKR-USD\"},{\"exchangeName\":\"Gate\",\"ticker\":\"MKR_USDT\"},{\"exchangeName\":\"Huobi\",\"ticker\":\"mkrusdt\"},{\"exchangeName\":\"Kucoin\",\"ticker\":\"MKR-USDT\"},{\"exchangeName\":\"Okx\",\"ticker\":\"MKR-USDT\"}]}", - "exponent": -7, + "exponent": -6, "id": 23, "min_exchanges": 1, "min_price_change_ppm": 2000, @@ -4186,7 +4186,7 @@ const GenesisState = `{ }, { "exchange_config_json": "{\"exchanges\":[{\"exchangeName\":\"Binance\",\"ticker\":\"\\\"XLMUSDT\\\"\"},{\"exchangeName\":\"BinanceUS\",\"ticker\":\"\\\"XLMUSD\\\"\"},{\"exchangeName\":\"Bitfinex\",\"ticker\":\"tXLMUSD\"},{\"exchangeName\":\"CoinbasePro\",\"ticker\":\"XLM-USD\"},{\"exchangeName\":\"Gate\",\"ticker\":\"XLM_USDT\"},{\"exchangeName\":\"Kraken\",\"ticker\":\"XXLMZUSD\"},{\"exchangeName\":\"Kucoin\",\"ticker\":\"XLM-USDT\"},{\"exchangeName\":\"Okx\",\"ticker\":\"XLM-USDT\"}]}", - "exponent": -11, + "exponent": -10, "id": 25, "min_exchanges": 1, "min_price_change_ppm": 2000, @@ -4261,7 +4261,7 @@ const GenesisState = `{ "price": 1500000000 }, { - "exponent": -8, + "exponent": -9, "id": 2, "price": 700000000 }, @@ -4366,7 +4366,7 @@ const GenesisState = `{ "price": 2200000000 }, { - "exponent": -7, + "exponent": -6, "id": 23, "price": 7100000000 }, @@ -4376,7 +4376,7 @@ const GenesisState = `{ "price": 7000000000 }, { - "exponent": -11, + "exponent": -10, "id": 25, "price": 10000000000 }, diff --git a/protocol/x/prices/keeper/market.go b/protocol/x/prices/keeper/market.go index 8a7fde8dd8..d5c76cc310 100644 --- a/protocol/x/prices/keeper/market.go +++ b/protocol/x/prices/keeper/market.go @@ -57,7 +57,7 @@ func (k Keeper) CreateMarket( ) } currencyPairStr := currencyPair.String() - _, err = k.MarketMapKeeper.GetMarket(ctx, currencyPairStr) + marketMapDetails, err := k.MarketMapKeeper.GetMarket(ctx, currencyPairStr) if err != nil { return types.MarketParam{}, errorsmod.Wrapf( types.ErrTickerNotFoundInMarketMap, @@ -65,6 +65,14 @@ func (k Keeper) CreateMarket( ) } + // Check that the exponent of market price is the negation of the decimals value in the market map + if marketPrice.Exponent != int32(marketMapDetails.Ticker.Decimals)*-1 { + return types.MarketParam{}, errorsmod.Wrapf( + types.ErrInvalidMarketPriceExponent, + currencyPairStr, + ) + } + paramBytes := k.cdc.MustMarshal(&marketParam) priceBytes := k.cdc.MustMarshal(&marketPrice) @@ -87,7 +95,8 @@ func (k Keeper) CreateMarket( marketParam.Id, marketParam.Pair, marketParam.MinPriceChangePpm, - marketParam.Exponent, + // The exponent in market price is the source of truth, the exponent of the param is deprecated as of v7.1.x + marketPrice.Exponent, ), ), ) @@ -111,6 +120,24 @@ func (k Keeper) CreateMarket( return marketParam, nil } +// Get the exponent for a market as the negation of the decimals value in the market map +func (k Keeper) GetExponent(ctx sdk.Context, ticker string) (int32, error) { + currencyPair, err := slinky.MarketPairToCurrencyPair(ticker) + if err != nil { + k.Logger(ctx).Error("Could not convert market pair to currency pair", "error", err) + return 0, err + } + + marketMapDetails, err := k.MarketMapKeeper.GetMarket(ctx, currencyPair.String()) + if err != nil { + return 0, errorsmod.Wrapf( + types.ErrTickerNotFoundInMarketMap, + ticker, + ) + } + return int32(marketMapDetails.Ticker.Decimals) * -1, nil +} + // GetAllMarketParamPrices returns a slice of MarketParam, MarketPrice tuples for all markets. func (k Keeper) GetAllMarketParamPrices(ctx sdk.Context) ([]types.MarketParamPrice, error) { marketParams := k.GetAllMarketParams(ctx) diff --git a/protocol/x/prices/keeper/market_param.go b/protocol/x/prices/keeper/market_param.go index f0559bb75a..e62f92fc88 100644 --- a/protocol/x/prices/keeper/market_param.go +++ b/protocol/x/prices/keeper/market_param.go @@ -40,10 +40,6 @@ func (k Keeper) ModifyMarketParam( } // Validate update is permitted. - if updatedMarketParam.Exponent != existingParam.Exponent { - return types.MarketParam{}, - errorsmod.Wrapf(types.ErrMarketExponentCannotBeUpdated, lib.UintToString(updatedMarketParam.Id)) - } for _, market := range k.GetAllMarketParams(ctx) { if market.Pair == updatedMarketParam.Pair && market.Id != updatedMarketParam.Id { return types.MarketParam{}, errorsmod.Wrapf(types.ErrMarketParamPairAlreadyExists, updatedMarketParam.Pair) diff --git a/protocol/x/prices/keeper/market_test.go b/protocol/x/prices/keeper/market_test.go index b5586fabc8..380803db28 100644 --- a/protocol/x/prices/keeper/market_test.go +++ b/protocol/x/prices/keeper/market_test.go @@ -110,13 +110,12 @@ func TestCreateMarket_Errors(t *testing.T) { validExchangeConfigJson := `{"exchanges":[{"exchangeName":"Binance","ticker":"BTCUSDT"}]}` tests := map[string]struct { // Setup - pair string - minExchanges uint32 - minPriceChangePpm uint32 - price uint64 - marketPriceIdDoesntMatchMarketParamId bool - marketPriceExponentDoesntMatchMarketParamExponent bool - exchangeConfigJson string + pair string + minExchanges uint32 + minPriceChangePpm uint32 + price uint64 + marketPriceIdDoesntMatchMarketParamId bool + exchangeConfigJson string // Expected expectedErr string }{ @@ -163,18 +162,6 @@ func TestCreateMarket_Errors(t *testing.T) { "market param id 1 does not match market price id 2", ).Error(), }, - "Market param and price exponents don't match": { - pair: constants.BtcUsdPair, - minExchanges: uint32(2), - minPriceChangePpm: uint32(50), - price: constants.FiveBillion, - marketPriceExponentDoesntMatchMarketParamExponent: true, - exchangeConfigJson: validExchangeConfigJson, - expectedErr: errorsmod.Wrap( - types.ErrInvalidInput, - "market param 1 exponent -6 does not match market price 1 exponent -5", - ).Error(), - }, "Pair already exists": { pair: "0-0", minExchanges: uint32(2), @@ -201,9 +188,6 @@ func TestCreateMarket_Errors(t *testing.T) { } marketPriceExponentOffset := int32(0) - if tc.marketPriceExponentDoesntMatchMarketParamExponent { - marketPriceExponentOffset = int32(1) - } _, err := keeper.CreateMarket( ctx, diff --git a/protocol/x/prices/keeper/msg_server_create_oracle_market.go b/protocol/x/prices/keeper/msg_server_create_oracle_market.go index 837666916c..9c326340f0 100644 --- a/protocol/x/prices/keeper/msg_server_create_oracle_market.go +++ b/protocol/x/prices/keeper/msg_server_create_oracle_market.go @@ -44,12 +44,17 @@ func (k msgServer) CreateOracleMarket( ctx := lib.UnwrapSDKContext(goCtx, types.ModuleName) + exponent, err := k.Keeper.GetExponent(ctx, msg.Params.Pair) + if err != nil { + return nil, err + } + // Use zero oracle price to create the new market. // Note that valid oracle price updates cannot be zero (checked in MsgUpdateMarketPrices.ValidateBasic), // so a zero oracle price indicates that the oracle price has never been updated. zeroMarketPrice := types.MarketPrice{ Id: msg.Params.Id, - Exponent: msg.Params.Exponent, + Exponent: exponent, Price: 0, } if _, err = k.Keeper.CreateMarket(ctx, msg.Params, zeroMarketPrice); err != nil { diff --git a/protocol/x/prices/keeper/msg_server_create_oracle_market_test.go b/protocol/x/prices/keeper/msg_server_create_oracle_market_test.go index 86075a0efb..016e1c1e98 100644 --- a/protocol/x/prices/keeper/msg_server_create_oracle_market_test.go +++ b/protocol/x/prices/keeper/msg_server_create_oracle_market_test.go @@ -54,20 +54,16 @@ func TestCreateOracleMarket(t *testing.T) { ).Param, }, expectedMarkets: []pricestypes.MarketParamPrice{}, - expectedErr: "Pair cannot be empty", + expectedErr: "incorrectly formatted CurrencyPair", }, - "Failure: typo in exchange config json": { + "Failure: market not found in MarketMap": { setup: func(t *testing.T, ctx sdk.Context, pricesKeeper *keeper.Keeper) {}, msg: &pricestypes.MsgCreateOracleMarket{ Authority: lib.GovModuleAddress.String(), - Params: pricestest.GenerateMarketParamPrice( - pricestest.WithPair("BTC-USD"), - pricestest.WithExponent(-8), // for both Param and Price - pricestest.WithExchangeConfigJson(`{"exchanges":[{"exchangeName":"Binance"""}]}`), - ).Param, + Params: testMarket1.Param, }, + expectedErr: "Ticker not found in market map", expectedMarkets: []pricestypes.MarketParamPrice{}, - expectedErr: "ExchangeConfigJson string is not valid", }, "Failure: oracle market id already exists": { setup: func(t *testing.T, ctx sdk.Context, pricesKeeper *keeper.Keeper) { @@ -77,6 +73,14 @@ func TestCreateOracleMarket(t *testing.T) { pricesKeeper, []pricestypes.MarketParamPrice{testMarket1}, ) + keepertest.CreateMarketsInMarketMapFromParams( + t, + ctx, + pricesKeeper.MarketMapKeeper.(*marketmapkeeper.Keeper), + []pricestypes.MarketParam{pricestest.GenerateMarketParamPrice( + pricestest.WithId(1), // same id as testMarket1 + ).Param}, + ) }, msg: &pricestypes.MsgCreateOracleMarket{ Authority: lib.GovModuleAddress.String(), diff --git a/protocol/x/prices/keeper/msg_server_update_market_param_test.go b/protocol/x/prices/keeper/msg_server_update_market_param_test.go index b04959a7a6..3d11628cc1 100644 --- a/protocol/x/prices/keeper/msg_server_update_market_param_test.go +++ b/protocol/x/prices/keeper/msg_server_update_market_param_test.go @@ -108,20 +108,6 @@ func TestUpdateMarketParam(t *testing.T) { }, expectedErr: "Invalid input", }, - "Failure: update market exponent": { - msg: &pricestypes.MsgUpdateMarketParam{ - Authority: lib.GovModuleAddress.String(), - MarketParam: pricestypes.MarketParam{ - Id: testMarketParam.Id, - Pair: testMarketParam.Pair, - Exponent: testMarketParam.Exponent + 1, // cannot be updated - MinExchanges: testMarketParam.MinExchanges, - MinPriceChangePpm: testMarketParam.MinPriceChangePpm, - ExchangeConfigJson: "{}", - }, - }, - expectedErr: "Market exponent cannot be updated", - }, "Failure: empty authority": { msg: &pricestypes.MsgUpdateMarketParam{ Authority: "", diff --git a/protocol/x/prices/module_test.go b/protocol/x/prices/module_test.go index b5c8d0dfa4..bc24360462 100644 --- a/protocol/x/prices/module_test.go +++ b/protocol/x/prices/module_test.go @@ -142,14 +142,6 @@ func TestAppModuleBasic_ValidateGenesisErr(t *testing.T) { `"exchangeConfigJson":"{}"}]}`, expectedErr: "expected the same number of market prices and market params", }, - "Bad state: Invalid price": { - genesisJson: `{"market_params":[{"pair": "DENT-USD","minExchanges":1,"minPriceChangePpm":1,` + - `"exchangeConfigJson":"{}"}],"market_prices": [{"exponent":1,"price": "0"}]}`, - expectedErr: errorsmod.Wrap( - pricestypes.ErrInvalidInput, - "market param 0 exponent 0 does not match market price 0 exponent 1", - ).Error(), - }, } for name, tc := range tests { t.Run(name, func(t *testing.T) { diff --git a/protocol/x/prices/simulation/genesis.go b/protocol/x/prices/simulation/genesis.go index 8e04899360..b29ea23bd0 100644 --- a/protocol/x/prices/simulation/genesis.go +++ b/protocol/x/prices/simulation/genesis.go @@ -5,6 +5,7 @@ package simulation import ( "fmt" "math/rand" + "strings" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -47,8 +48,10 @@ func genMarketExponent(r *rand.Rand, isReasonableGenesis bool) int { // genMarketName return randomized market name. func genMarketName(r *rand.Rand, existingMarketNames map[string]bool) string { marketName := simtypes.RandStringOfLength(r, simtypes.RandIntBetween(r, 3, 6)) + "-USD" + marketName = strings.ToUpper(marketName) for existingMarketNames[marketName] { marketName = simtypes.RandStringOfLength(r, simtypes.RandIntBetween(r, 3, 6)) + "-USD" + marketName = strings.ToUpper(marketName) } return marketName } diff --git a/protocol/x/prices/types/errors.go b/protocol/x/prices/types/errors.go index a549fef86e..a1235e7f65 100644 --- a/protocol/x/prices/types/errors.go +++ b/protocol/x/prices/types/errors.go @@ -30,9 +30,14 @@ var ( 206, "Market pair conversion to currency pair failed", ) - ErrTickerNotFoundInMarketMap = errorsmod.Register(ModuleName, 207, "Ticker not found in market map") - ErrMarketCouldNotBeDisabled = errorsmod.Register(ModuleName, 208, "Market could not be disabled") - ErrMarketCouldNotBeEnabled = errorsmod.Register(ModuleName, 209, "Market could not be enabled") + ErrTickerNotFoundInMarketMap = errorsmod.Register(ModuleName, 207, "Ticker not found in market map") + ErrMarketCouldNotBeDisabled = errorsmod.Register(ModuleName, 208, "Market could not be disabled") + ErrMarketCouldNotBeEnabled = errorsmod.Register(ModuleName, 209, "Market could not be enabled") + ErrInvalidMarketPriceExponent = errorsmod.Register( + ModuleName, + 210, + "Market price exponent does not match the negation of the Decimals value in the market map", + ) // 300 - 399: Price related errors. ErrIndexPriceNotAvailable = errorsmod.Register(ModuleName, 300, "Index price is not available") diff --git a/protocol/x/prices/types/market_param.pb.go b/protocol/x/prices/types/market_param.pb.go index 3be2180d28..4dbfd10c4f 100644 --- a/protocol/x/prices/types/market_param.pb.go +++ b/protocol/x/prices/types/market_param.pb.go @@ -35,7 +35,9 @@ type MarketParam struct { // For example if `Exponent == -5` then a `Value` of `1,000,000,000` // represents “$10,000`. Therefore `10 ^ Exponent` represents the smallest // price step (in dollars) that can be recorded. - Exponent int32 `protobuf:"zigzag32,3,opt,name=exponent,proto3" json:"exponent,omitempty"` + // + // Deprecated since v7.1.x. This value is now determined from the marketmap. + Exponent int32 `protobuf:"zigzag32,3,opt,name=exponent,proto3" json:"exponent,omitempty"` // Deprecated: Do not use. // The minimum number of exchanges that should be reporting a live price for // a price update to be considered valid. MinExchanges uint32 `protobuf:"varint,4,opt,name=min_exchanges,json=minExchanges,proto3" json:"min_exchanges,omitempty"` @@ -94,6 +96,7 @@ func (m *MarketParam) GetPair() string { return "" } +// Deprecated: Do not use. func (m *MarketParam) GetExponent() int32 { if m != nil { return m.Exponent @@ -131,25 +134,25 @@ func init() { } var fileDescriptor_39174a2dba54f799 = []byte{ - // 284 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x54, 0x90, 0x3f, 0x4b, 0xc4, 0x30, - 0x1c, 0x86, 0x2f, 0xf5, 0x3c, 0x34, 0x7a, 0xc2, 0xc5, 0x1b, 0x82, 0x43, 0x28, 0x0a, 0xd2, 0xc5, - 0x56, 0xd0, 0xc1, 0xd9, 0xc3, 0x45, 0x10, 0x4a, 0x47, 0x97, 0x90, 0x4b, 0x63, 0x1b, 0x35, 0x7f, - 0x68, 0xa3, 0xf4, 0xbe, 0x85, 0x1f, 0xcb, 0xf1, 0x16, 0xc1, 0x51, 0xda, 0x2f, 0x22, 0xcd, 0xd1, - 0x43, 0xb7, 0xe4, 0x7d, 0x1e, 0x7e, 0xbc, 0xbc, 0xf0, 0x3c, 0x5f, 0xe5, 0x8d, 0xad, 0x8c, 0x33, - 0xdc, 0xbc, 0x26, 0xb6, 0x92, 0x5c, 0xd4, 0x89, 0x62, 0xd5, 0x8b, 0x70, 0xd4, 0xb2, 0x8a, 0xa9, - 0xd8, 0x43, 0x74, 0xfc, 0xd7, 0x8b, 0x37, 0xde, 0xe9, 0x17, 0x80, 0x07, 0x0f, 0xde, 0x4d, 0x7b, - 0x15, 0x1d, 0xc1, 0x40, 0xe6, 0x18, 0x84, 0x20, 0x9a, 0x66, 0x81, 0xcc, 0x11, 0x82, 0x63, 0xcb, - 0x64, 0x85, 0x83, 0x10, 0x44, 0xfb, 0x99, 0x7f, 0xa3, 0x13, 0xb8, 0x27, 0x1a, 0x6b, 0xb4, 0xd0, - 0x0e, 0xef, 0x84, 0x20, 0x9a, 0x65, 0xdb, 0x3f, 0x3a, 0x83, 0x53, 0x25, 0x35, 0x15, 0x0d, 0x2f, - 0x99, 0x2e, 0x44, 0x8d, 0xc7, 0xfe, 0xd4, 0xa1, 0x92, 0xfa, 0x6e, 0xc8, 0x50, 0x02, 0xe7, 0xbd, - 0xe4, 0x2b, 0xd0, 0x4d, 0x48, 0xad, 0x55, 0x78, 0xd7, 0xbb, 0x33, 0x25, 0x75, 0xda, 0xa3, 0x85, - 0x27, 0xa9, 0x55, 0xe8, 0x12, 0xce, 0x87, 0x8b, 0x94, 0x1b, 0xfd, 0x24, 0x0b, 0xfa, 0x5c, 0x1b, - 0x8d, 0x27, 0xbe, 0x15, 0x1a, 0xd8, 0xc2, 0xa3, 0xfb, 0xda, 0xe8, 0xdb, 0xec, 0xb3, 0x25, 0x60, - 0xdd, 0x12, 0xf0, 0xd3, 0x12, 0xf0, 0xd1, 0x91, 0xd1, 0xba, 0x23, 0xa3, 0xef, 0x8e, 0x8c, 0x1e, - 0x6f, 0x0a, 0xe9, 0xca, 0xb7, 0x65, 0xcc, 0x8d, 0x4a, 0xfe, 0x2d, 0xf7, 0x7e, 0x7d, 0xc1, 0x4b, - 0x26, 0x75, 0xb2, 0x4d, 0x9a, 0x61, 0x4d, 0xb7, 0xb2, 0xa2, 0x5e, 0x4e, 0x3c, 0xb8, 0xfa, 0x0d, - 0x00, 0x00, 0xff, 0xff, 0x98, 0x21, 0x4b, 0x29, 0x71, 0x01, 0x00, 0x00, + // 285 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x54, 0x90, 0x4f, 0x4b, 0xc3, 0x30, + 0x14, 0xc0, 0x97, 0x3a, 0x87, 0x46, 0x27, 0x2c, 0xee, 0x90, 0x53, 0x28, 0x0a, 0xd2, 0x8b, 0xad, + 0xa0, 0x07, 0xcf, 0x1b, 0x5e, 0x04, 0xa1, 0xf4, 0xe8, 0x25, 0x64, 0x69, 0x6c, 0xa3, 0xe6, 0x0f, + 0x6d, 0x94, 0xee, 0x5b, 0xf8, 0xb1, 0x3c, 0xee, 0xa8, 0x37, 0x69, 0xbf, 0x88, 0x34, 0xa3, 0x43, + 0x6f, 0x8f, 0xdf, 0xef, 0xc7, 0xe3, 0xf1, 0xe0, 0x45, 0xbe, 0xce, 0x1b, 0x5b, 0x19, 0x67, 0xb8, + 0x79, 0x4d, 0x6c, 0x25, 0xb9, 0xa8, 0x13, 0xc5, 0xaa, 0x17, 0xe1, 0xa8, 0x65, 0x15, 0x53, 0xb1, + 0x97, 0xe8, 0xf4, 0x6f, 0x17, 0x6f, 0xbb, 0xb3, 0x6f, 0x00, 0x8f, 0x1e, 0x7c, 0x9b, 0xf6, 0x29, + 0x3a, 0x81, 0x81, 0xcc, 0x31, 0x08, 0x41, 0x34, 0xcd, 0x02, 0x99, 0x23, 0x04, 0xc7, 0x96, 0xc9, + 0x0a, 0x07, 0x21, 0x88, 0x0e, 0x33, 0x3f, 0x23, 0x02, 0x0f, 0x44, 0x63, 0x8d, 0x16, 0xda, 0xe1, + 0xbd, 0x10, 0x44, 0xb3, 0x45, 0x80, 0x41, 0xb6, 0x63, 0xe8, 0x1c, 0x4e, 0x95, 0xd4, 0x54, 0x34, + 0xbc, 0x64, 0xba, 0x10, 0x35, 0x1e, 0xfb, 0x75, 0xc7, 0x4a, 0xea, 0xbb, 0x81, 0xa1, 0x04, 0xce, + 0xfb, 0xc8, 0x9f, 0x41, 0xb7, 0x90, 0x5a, 0xab, 0xf0, 0xbe, 0x6f, 0x67, 0x4a, 0xea, 0xb4, 0x57, + 0x4b, 0x6f, 0x52, 0xab, 0xd0, 0x15, 0x9c, 0x0f, 0x1b, 0x29, 0x37, 0xfa, 0x49, 0x16, 0xf4, 0xb9, + 0x36, 0x1a, 0x4f, 0xfc, 0x65, 0x68, 0x70, 0x4b, 0xaf, 0xee, 0x6b, 0xa3, 0x17, 0xd9, 0x67, 0x4b, + 0xc0, 0xa6, 0x25, 0xe0, 0xa7, 0x25, 0xe0, 0xa3, 0x23, 0xa3, 0x4d, 0x47, 0x46, 0x5f, 0x1d, 0x19, + 0x3d, 0xde, 0x16, 0xd2, 0x95, 0x6f, 0xab, 0x98, 0x1b, 0x95, 0xfc, 0xfb, 0xde, 0xfb, 0xcd, 0x25, + 0x2f, 0x99, 0xd4, 0xc9, 0x8e, 0x34, 0xc3, 0x47, 0xdd, 0xda, 0x8a, 0x7a, 0x35, 0xf1, 0xe2, 0xfa, + 0x37, 0x00, 0x00, 0xff, 0xff, 0x7c, 0xfb, 0xf1, 0xbc, 0x75, 0x01, 0x00, 0x00, } func (m *MarketParam) Marshal() (dAtA []byte, err error) { diff --git a/protocol/x/prices/types/market_price.go b/protocol/x/prices/types/market_price.go index c88e7192f4..e90a9a0cc7 100644 --- a/protocol/x/prices/types/market_price.go +++ b/protocol/x/prices/types/market_price.go @@ -14,15 +14,5 @@ func (mp *MarketPrice) ValidateFromParam(marketParam MarketParam) error { mp.Id, ) } - if marketParam.Exponent != mp.Exponent { - return errorsmod.Wrapf( - ErrInvalidInput, - "market param %d exponent %d does not match market price %d exponent %d", - marketParam.Id, - marketParam.Exponent, - mp.Id, - mp.Exponent, - ) - } return nil } diff --git a/protocol/x/prices/types/market_price.pb.go b/protocol/x/prices/types/market_price.pb.go index 9da0bdef89..a86b2f60ed 100644 --- a/protocol/x/prices/types/market_price.pb.go +++ b/protocol/x/prices/types/market_price.pb.go @@ -28,6 +28,9 @@ type MarketPrice struct { Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` // Static value. The exponent of the price. See the comment on the duplicate // MarketParam field for more information. + // + // As of v7.1.x, this value is determined from the marketmap instead of + // needing to match the MarketParam field. Exponent int32 `protobuf:"zigzag32,2,opt,name=exponent,proto3" json:"exponent,omitempty"` // The variable value that is updated by oracle price updates. `0` if it has // never been updated, `>0` otherwise. diff --git a/protocol/x/prices/types/types.go b/protocol/x/prices/types/types.go index ba32185e93..1940a39ae6 100644 --- a/protocol/x/prices/types/types.go +++ b/protocol/x/prices/types/types.go @@ -31,6 +31,7 @@ type PricesKeeper interface { GetAllMarketParams(ctx sdk.Context) (marketParams []MarketParam) GetMarketPrice(ctx sdk.Context, id uint32) (marketPrice MarketPrice, err error) GetAllMarketPrices(ctx sdk.Context) (marketPrices []MarketPrice) + GetExponent(ctx sdk.Context, ticker string) (exponent int32, err error) HasAuthority(authority string) bool // Validation related.