diff --git a/protocol/app/upgrades.go b/protocol/app/upgrades.go index 14d510bcea..5e4cc471b5 100644 --- a/protocol/app/upgrades.go +++ b/protocol/app/upgrades.go @@ -30,6 +30,7 @@ func (app *App) setupUpgradeHandlers() { v7_0_0.CreateUpgradeHandler( app.ModuleManager, app.configurator, + app.PricesKeeper, ), ) } diff --git a/protocol/app/upgrades/v7.0.0/upgrade.go b/protocol/app/upgrades/v7.0.0/upgrade.go index 83e98e42cd..292dfbc361 100644 --- a/protocol/app/upgrades/v7.0.0/upgrade.go +++ b/protocol/app/upgrades/v7.0.0/upgrade.go @@ -2,16 +2,39 @@ package v_7_0_0 import ( "context" + "fmt" upgradetypes "cosmossdk.io/x/upgrade/types" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + "github.com/dydxprotocol/v4-chain/protocol/lib" + "github.com/dydxprotocol/v4-chain/protocol/lib/slinky" + pricestypes "github.com/dydxprotocol/v4-chain/protocol/x/prices/types" ) +func initCurrencyPairIDCache(ctx sdk.Context, k pricestypes.PricesKeeper) { + marketParams := k.GetAllMarketParams(ctx) + for _, mp := range marketParams { + currencyPair, err := slinky.MarketPairToCurrencyPair(mp.Pair) + if err != nil { + panic(fmt.Sprintf("failed to convert market param pair to currency pair: %s", err)) + } + k.AddCurrencyPairIDToStore(ctx, mp.Id, currencyPair) + } +} + func CreateUpgradeHandler( mm *module.Manager, configurator module.Configurator, + pricesKeeper pricestypes.PricesKeeper, ) upgradetypes.UpgradeHandler { return func(ctx context.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + sdkCtx := lib.UnwrapSDKContext(ctx, "app/upgrades") + sdkCtx.Logger().Info(fmt.Sprintf("Running %s Upgrade...", UpgradeName)) + + // Initialize the currency pair ID cache for all existing market params. + initCurrencyPairIDCache(sdkCtx, pricesKeeper) + return mm.RunMigrations(ctx, configurator, vm) } } diff --git a/protocol/mocks/AnteDecorator.go b/protocol/mocks/AnteDecorator.go index 45c714b86b..bf8874661a 100644 --- a/protocol/mocks/AnteDecorator.go +++ b/protocol/mocks/AnteDecorator.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/AppOptions.go b/protocol/mocks/AppOptions.go index 6646281624..824a897ff5 100644 --- a/protocol/mocks/AppOptions.go +++ b/protocol/mocks/AppOptions.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/BankKeeper.go b/protocol/mocks/BankKeeper.go index c4c0d1467f..e2dc2f1cab 100644 --- a/protocol/mocks/BankKeeper.go +++ b/protocol/mocks/BankKeeper.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/BridgeKeeper.go b/protocol/mocks/BridgeKeeper.go index 2d62770240..972fccb630 100644 --- a/protocol/mocks/BridgeKeeper.go +++ b/protocol/mocks/BridgeKeeper.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/BridgeQueryClient.go b/protocol/mocks/BridgeQueryClient.go index 6cf94c339b..849c7a282d 100644 --- a/protocol/mocks/BridgeQueryClient.go +++ b/protocol/mocks/BridgeQueryClient.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/BridgeServiceClient.go b/protocol/mocks/BridgeServiceClient.go index e34276bc47..598e51f7cb 100644 --- a/protocol/mocks/BridgeServiceClient.go +++ b/protocol/mocks/BridgeServiceClient.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/CacheMultiStore.go b/protocol/mocks/CacheMultiStore.go index 8344ddeb1f..b5e0d29d24 100644 --- a/protocol/mocks/CacheMultiStore.go +++ b/protocol/mocks/CacheMultiStore.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/Configurator.go b/protocol/mocks/Configurator.go index f470be2d9b..4aa135d751 100644 --- a/protocol/mocks/Configurator.go +++ b/protocol/mocks/Configurator.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/DelayMsgKeeper.go b/protocol/mocks/DelayMsgKeeper.go index f2eb381c74..cc7ed98c79 100644 --- a/protocol/mocks/DelayMsgKeeper.go +++ b/protocol/mocks/DelayMsgKeeper.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/EthClient.go b/protocol/mocks/EthClient.go index 4e986c9a67..28e3194edf 100644 --- a/protocol/mocks/EthClient.go +++ b/protocol/mocks/EthClient.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/ExchangeConfigUpdater.go b/protocol/mocks/ExchangeConfigUpdater.go index a786bbc69e..266d2c9592 100644 --- a/protocol/mocks/ExchangeConfigUpdater.go +++ b/protocol/mocks/ExchangeConfigUpdater.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/ExchangeQueryHandler.go b/protocol/mocks/ExchangeQueryHandler.go index da46fc1b17..575335c728 100644 --- a/protocol/mocks/ExchangeQueryHandler.go +++ b/protocol/mocks/ExchangeQueryHandler.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/ExchangeToMarketPrices.go b/protocol/mocks/ExchangeToMarketPrices.go index 413ce9a1ea..34d89c65ce 100644 --- a/protocol/mocks/ExchangeToMarketPrices.go +++ b/protocol/mocks/ExchangeToMarketPrices.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/ExtendVoteHandler.go b/protocol/mocks/ExtendVoteHandler.go index 1b62aad1f4..755e96c66c 100644 --- a/protocol/mocks/ExtendVoteHandler.go +++ b/protocol/mocks/ExtendVoteHandler.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/FileHandler.go b/protocol/mocks/FileHandler.go index 6e135882d9..04cfcd6b3d 100644 --- a/protocol/mocks/FileHandler.go +++ b/protocol/mocks/FileHandler.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/GrpcClient.go b/protocol/mocks/GrpcClient.go index 66fc532d75..77444c79f5 100644 --- a/protocol/mocks/GrpcClient.go +++ b/protocol/mocks/GrpcClient.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/GrpcServer.go b/protocol/mocks/GrpcServer.go index 5ee3a2ef7e..4ed12be5f4 100644 --- a/protocol/mocks/GrpcServer.go +++ b/protocol/mocks/GrpcServer.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/HealthCheckable.go b/protocol/mocks/HealthCheckable.go index 9300c2a452..57b818ab0c 100644 --- a/protocol/mocks/HealthCheckable.go +++ b/protocol/mocks/HealthCheckable.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/IndexerEventManager.go b/protocol/mocks/IndexerEventManager.go index e211874424..b9529b8c2c 100644 --- a/protocol/mocks/IndexerEventManager.go +++ b/protocol/mocks/IndexerEventManager.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/IndexerMessageSender.go b/protocol/mocks/IndexerMessageSender.go index 6df930a5f0..e3eb79dba5 100644 --- a/protocol/mocks/IndexerMessageSender.go +++ b/protocol/mocks/IndexerMessageSender.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/Logger.go b/protocol/mocks/Logger.go index 8ecbbc30f0..77bb60a329 100644 --- a/protocol/mocks/Logger.go +++ b/protocol/mocks/Logger.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/MarketPairFetcher.go b/protocol/mocks/MarketPairFetcher.go index e59fa94ffd..fa9588f982 100644 --- a/protocol/mocks/MarketPairFetcher.go +++ b/protocol/mocks/MarketPairFetcher.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/MemClob.go b/protocol/mocks/MemClob.go index 2694474f2c..e5f0aa26bf 100644 --- a/protocol/mocks/MemClob.go +++ b/protocol/mocks/MemClob.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/MemClobKeeper.go b/protocol/mocks/MemClobKeeper.go index 8eacc26019..a897a64e8e 100644 --- a/protocol/mocks/MemClobKeeper.go +++ b/protocol/mocks/MemClobKeeper.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/MsgRouter.go b/protocol/mocks/MsgRouter.go index 969463f98e..f197b38d9c 100644 --- a/protocol/mocks/MsgRouter.go +++ b/protocol/mocks/MsgRouter.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/MultiStore.go b/protocol/mocks/MultiStore.go index 786b202df3..20e9c3830a 100644 --- a/protocol/mocks/MultiStore.go +++ b/protocol/mocks/MultiStore.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/OracleClient.go b/protocol/mocks/OracleClient.go index 6fd3d92491..651361d160 100644 --- a/protocol/mocks/OracleClient.go +++ b/protocol/mocks/OracleClient.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/PerpetualsClobKeeper.go b/protocol/mocks/PerpetualsClobKeeper.go index c02f98bd0d..fdd11d89e4 100644 --- a/protocol/mocks/PerpetualsClobKeeper.go +++ b/protocol/mocks/PerpetualsClobKeeper.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/PerpetualsKeeper.go b/protocol/mocks/PerpetualsKeeper.go index c632ae3ad0..ed2237ba87 100644 --- a/protocol/mocks/PerpetualsKeeper.go +++ b/protocol/mocks/PerpetualsKeeper.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/PrepareBridgeKeeper.go b/protocol/mocks/PrepareBridgeKeeper.go index 83908496de..36fca8fedd 100644 --- a/protocol/mocks/PrepareBridgeKeeper.go +++ b/protocol/mocks/PrepareBridgeKeeper.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/PrepareClobKeeper.go b/protocol/mocks/PrepareClobKeeper.go index cea7823495..8105410fb6 100644 --- a/protocol/mocks/PrepareClobKeeper.go +++ b/protocol/mocks/PrepareClobKeeper.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/PreparePerpetualsKeeper.go b/protocol/mocks/PreparePerpetualsKeeper.go index 2bbbce3948..f049653c34 100644 --- a/protocol/mocks/PreparePerpetualsKeeper.go +++ b/protocol/mocks/PreparePerpetualsKeeper.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/PriceFeedMutableMarketConfigs.go b/protocol/mocks/PriceFeedMutableMarketConfigs.go index f69eebe004..3190949974 100644 --- a/protocol/mocks/PriceFeedMutableMarketConfigs.go +++ b/protocol/mocks/PriceFeedMutableMarketConfigs.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/PriceFetcher.go b/protocol/mocks/PriceFetcher.go index d204cb9754..b00ee2de3e 100644 --- a/protocol/mocks/PriceFetcher.go +++ b/protocol/mocks/PriceFetcher.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/PriceUpdateGenerator.go b/protocol/mocks/PriceUpdateGenerator.go index 023397e5fd..a33d85d6bd 100644 --- a/protocol/mocks/PriceUpdateGenerator.go +++ b/protocol/mocks/PriceUpdateGenerator.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/PricesKeeper.go b/protocol/mocks/PricesKeeper.go index 4c8e6b9b16..f2e053b193 100644 --- a/protocol/mocks/PricesKeeper.go +++ b/protocol/mocks/PricesKeeper.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks @@ -19,6 +19,11 @@ type PricesKeeper struct { mock.Mock } +// AddCurrencyPairIDToStore provides a mock function with given fields: ctx, id, cp +func (_m *PricesKeeper) AddCurrencyPairIDToStore(ctx types.Context, id uint32, cp pkgtypes.CurrencyPair) { + _m.Called(ctx, id, cp) +} + // CreateMarket provides a mock function with given fields: ctx, param, price func (_m *PricesKeeper) CreateMarket(ctx types.Context, param pricestypes.MarketParam, price pricestypes.MarketPrice) (pricestypes.MarketParam, error) { ret := _m.Called(ctx, param, price) @@ -315,11 +320,6 @@ func (_m *PricesKeeper) HasAuthority(authority string) bool { return r0 } -// InitializeCurrencyPairIdCache provides a mock function with given fields: ctx -func (_m *PricesKeeper) InitializeCurrencyPairIdCache(ctx types.Context) { - _m.Called(ctx) -} - // Logger provides a mock function with given fields: ctx func (_m *PricesKeeper) Logger(ctx types.Context) log.Logger { ret := _m.Called(ctx) diff --git a/protocol/mocks/ProcessBridgeKeeper.go b/protocol/mocks/ProcessBridgeKeeper.go index 22aafc0760..b0a1493c7b 100644 --- a/protocol/mocks/ProcessBridgeKeeper.go +++ b/protocol/mocks/ProcessBridgeKeeper.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/ProcessClobKeeper.go b/protocol/mocks/ProcessClobKeeper.go index 5cb6eec4ff..92e5c3b08b 100644 --- a/protocol/mocks/ProcessClobKeeper.go +++ b/protocol/mocks/ProcessClobKeeper.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/ProcessPerpetualKeeper.go b/protocol/mocks/ProcessPerpetualKeeper.go index bba5655110..97615ae57d 100644 --- a/protocol/mocks/ProcessPerpetualKeeper.go +++ b/protocol/mocks/ProcessPerpetualKeeper.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/ProcessStakingKeeper.go b/protocol/mocks/ProcessStakingKeeper.go index 453a220b15..29f6f5acaf 100644 --- a/protocol/mocks/ProcessStakingKeeper.go +++ b/protocol/mocks/ProcessStakingKeeper.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/QueryClient.go b/protocol/mocks/QueryClient.go index 8435844f38..2e2eeefe3e 100644 --- a/protocol/mocks/QueryClient.go +++ b/protocol/mocks/QueryClient.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/QueryServer.go b/protocol/mocks/QueryServer.go index 76c551ab3d..2db0d13114 100644 --- a/protocol/mocks/QueryServer.go +++ b/protocol/mocks/QueryServer.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/RequestHandler.go b/protocol/mocks/RequestHandler.go index 13256d3ca5..ba03ea51a0 100644 --- a/protocol/mocks/RequestHandler.go +++ b/protocol/mocks/RequestHandler.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/SendingKeeper.go b/protocol/mocks/SendingKeeper.go index e02990983b..4d1ca91487 100644 --- a/protocol/mocks/SendingKeeper.go +++ b/protocol/mocks/SendingKeeper.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/Server.go b/protocol/mocks/Server.go index e43c337cd9..eb888a4b0a 100644 --- a/protocol/mocks/Server.go +++ b/protocol/mocks/Server.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/SubaccountsKeeper.go b/protocol/mocks/SubaccountsKeeper.go index 62c0391855..6c14481c68 100644 --- a/protocol/mocks/SubaccountsKeeper.go +++ b/protocol/mocks/SubaccountsKeeper.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks @@ -186,6 +186,24 @@ func (_m *SubaccountsKeeper) GetRandomSubaccount(ctx types.Context, _a1 *rand.Ra return r0, r1 } +// GetStreamSubaccountUpdate provides a mock function with given fields: ctx, id, snapshot +func (_m *SubaccountsKeeper) GetStreamSubaccountUpdate(ctx types.Context, id subaccountstypes.SubaccountId, snapshot bool) subaccountstypes.StreamSubaccountUpdate { + ret := _m.Called(ctx, id, snapshot) + + if len(ret) == 0 { + panic("no return value specified for GetStreamSubaccountUpdate") + } + + var r0 subaccountstypes.StreamSubaccountUpdate + if rf, ok := ret.Get(0).(func(types.Context, subaccountstypes.SubaccountId, bool) subaccountstypes.StreamSubaccountUpdate); ok { + r0 = rf(ctx, id, snapshot) + } else { + r0 = ret.Get(0).(subaccountstypes.StreamSubaccountUpdate) + } + + return r0 +} + // GetSubaccount provides a mock function with given fields: ctx, id func (_m *SubaccountsKeeper) GetSubaccount(ctx types.Context, id subaccountstypes.SubaccountId) subaccountstypes.Subaccount { ret := _m.Called(ctx, id) @@ -232,6 +250,11 @@ func (_m *SubaccountsKeeper) LegacyGetNegativeTncSubaccountSeenAtBlock(ctx types return r0, r1 } +// SendFinalizedSubaccountUpdates provides a mock function with given fields: ctx, subaccountUpdates +func (_m *SubaccountsKeeper) SendFinalizedSubaccountUpdates(ctx types.Context, subaccountUpdates []subaccountstypes.StreamSubaccountUpdate) { + _m.Called(ctx, subaccountUpdates) +} + // SetNegativeTncSubaccountSeenAtBlock provides a mock function with given fields: ctx, perpetualId, blockHeight func (_m *SubaccountsKeeper) SetNegativeTncSubaccountSeenAtBlock(ctx types.Context, perpetualId uint32, blockHeight uint32) error { ret := _m.Called(ctx, perpetualId, blockHeight) diff --git a/protocol/mocks/TimeProvider.go b/protocol/mocks/TimeProvider.go index ec89493830..9b9bd347b8 100644 --- a/protocol/mocks/TimeProvider.go +++ b/protocol/mocks/TimeProvider.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/TxBuilder.go b/protocol/mocks/TxBuilder.go index 1d20fca1ca..19e1f53f83 100644 --- a/protocol/mocks/TxBuilder.go +++ b/protocol/mocks/TxBuilder.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/TxConfig.go b/protocol/mocks/TxConfig.go index d5ef3d0597..d4fee668f6 100644 --- a/protocol/mocks/TxConfig.go +++ b/protocol/mocks/TxConfig.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/UpdateMarketPriceTxDecoder.go b/protocol/mocks/UpdateMarketPriceTxDecoder.go index 070d0844b7..7194cefc72 100644 --- a/protocol/mocks/UpdateMarketPriceTxDecoder.go +++ b/protocol/mocks/UpdateMarketPriceTxDecoder.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/VaultKeeper.go b/protocol/mocks/VaultKeeper.go index b2af9b08f1..340b733dff 100644 --- a/protocol/mocks/VaultKeeper.go +++ b/protocol/mocks/VaultKeeper.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks @@ -64,24 +64,6 @@ func (_m *VaultKeeper) GetTotalShares(ctx types.Context, vaultId vaulttypes.Vaul return r0, r1 } -// GetVaultClobOrderClientId provides a mock function with given fields: ctx, side, layer -func (_m *VaultKeeper) GetVaultClobOrderClientId(ctx types.Context, side clobtypes.Order_Side, layer uint8) uint32 { - ret := _m.Called(ctx, side, layer) - - if len(ret) == 0 { - panic("no return value specified for GetVaultClobOrderClientId") - } - - var r0 uint32 - if rf, ok := ret.Get(0).(func(types.Context, clobtypes.Order_Side, uint8) uint32); ok { - r0 = rf(ctx, side, layer) - } else { - r0 = ret.Get(0).(uint32) - } - - return r0 -} - // GetVaultClobOrders provides a mock function with given fields: ctx, vaultId func (_m *VaultKeeper) GetVaultClobOrders(ctx types.Context, vaultId vaulttypes.VaultId) ([]*clobtypes.Order, error) { ret := _m.Called(ctx, vaultId) diff --git a/protocol/scripts/governance/vote_in_dev.sh b/protocol/scripts/governance/vote_in_dev.sh old mode 100644 new mode 100755 diff --git a/protocol/x/prices/abci.go b/protocol/x/prices/abci.go deleted file mode 100644 index 8b2ee16f8c..0000000000 --- a/protocol/x/prices/abci.go +++ /dev/null @@ -1,14 +0,0 @@ -package prices - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/dydxprotocol/v4-chain/protocol/x/prices/types" -) - -// PreBlocker executes all ABCI PreBlock logic respective to the prices module. -func PreBlocker( - ctx sdk.Context, - keeper types.PricesKeeper, -) { - keeper.InitializeCurrencyPairIdCache(ctx) -} diff --git a/protocol/x/prices/keeper/currency_pair_id_cache.go b/protocol/x/prices/keeper/currency_pair_id_cache.go deleted file mode 100644 index b47f05b2fa..0000000000 --- a/protocol/x/prices/keeper/currency_pair_id_cache.go +++ /dev/null @@ -1,73 +0,0 @@ -package keeper - -import ( - "sync" -) - -// CurrencyPairIDCache handles the caching logic of currency-pairs to their corresponding IDs. This -// data-structure is thread-safe, allowing concurrent reads + synchronized writes. -type CurrencyPairIDCache struct { - // ID -> CurrencyPair - idToCurrencyPair map[uint64]string - // CurrencyPair -> ID - currencyPairToID map[string]uint64 - // lock - sync.RWMutex -} - -// NewCurrencyPairIDCache creates a new CurrencyPairIDCache -func NewCurrencyPairIDCache() *CurrencyPairIDCache { - return &CurrencyPairIDCache{ - idToCurrencyPair: make(map[uint64]string), - currencyPairToID: make(map[string]uint64), - } -} - -// AddCurrencyPair adds a currency pair to the cache. This method takes out a write lock on the cache -// or blocks until one is available before updating the cache. -func (c *CurrencyPairIDCache) AddCurrencyPair(id uint64, currencyPair string) { - // acquire write lock - c.Lock() - defer c.Unlock() - - // update cache - c.idToCurrencyPair[id] = currencyPair - c.currencyPairToID[currencyPair] = id -} - -// GetCurrencyPairFromID returns the currency pair from the cache -func (c *CurrencyPairIDCache) GetCurrencyPairFromID(id uint64) (string, bool) { - // acquire read lock - c.RLock() - defer c.RUnlock() - - // get currency pair from cache - currencyPair, found := c.idToCurrencyPair[id] - return currencyPair, found -} - -// GetIDForCurrencyPair returns the ID for the currency pair from the cache -func (c *CurrencyPairIDCache) GetIDForCurrencyPair(currencyPair string) (uint64, bool) { - // acquire read lock - c.RLock() - defer c.RUnlock() - - // get ID for currency pair from cache - id, found := c.currencyPairToID[currencyPair] - return id, found -} - -// Remove removes the currency-pair (by ID) from the cache. This method takes out a write lock on the -// cache or blocks until one is available before updating the cache. -func (c *CurrencyPairIDCache) Remove(id uint64) { - // acquire write lock - c.Lock() - defer c.Unlock() - - // remove currency pair from cache - currencyPair, found := c.idToCurrencyPair[id] - if found { - delete(c.idToCurrencyPair, id) - delete(c.currencyPairToID, currencyPair) - } -} diff --git a/protocol/x/prices/keeper/keeper.go b/protocol/x/prices/keeper/keeper.go index 66132d1aaf..7d1a31960b 100644 --- a/protocol/x/prices/keeper/keeper.go +++ b/protocol/x/prices/keeper/keeper.go @@ -2,7 +2,6 @@ package keeper import ( "fmt" - "sync/atomic" "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" @@ -17,16 +16,14 @@ import ( type ( Keeper struct { - cdc codec.BinaryCodec - storeKey storetypes.StoreKey - indexPriceCache *pricefeedtypes.MarketToExchangePrices - timeProvider libtime.TimeProvider - indexerEventManager indexer_manager.IndexerEventManager - authorities map[string]struct{} - currencyPairIDCache *CurrencyPairIDCache - currencyPairIdCacheInitialized *atomic.Bool - RevShareKeeper types.RevShareKeeper - MarketMapKeeper types.MarketMapKeeper + cdc codec.BinaryCodec + storeKey storetypes.StoreKey + indexPriceCache *pricefeedtypes.MarketToExchangePrices + timeProvider libtime.TimeProvider + indexerEventManager indexer_manager.IndexerEventManager + authorities map[string]struct{} + RevShareKeeper types.RevShareKeeper + MarketMapKeeper types.MarketMapKeeper } ) @@ -43,16 +40,14 @@ func NewKeeper( marketMapKeeper types.MarketMapKeeper, ) *Keeper { return &Keeper{ - cdc: cdc, - storeKey: storeKey, - indexPriceCache: indexPriceCache, - timeProvider: timeProvider, - indexerEventManager: indexerEventManager, - authorities: lib.UniqueSliceToSet(authorities), - currencyPairIDCache: NewCurrencyPairIDCache(), - currencyPairIdCacheInitialized: &atomic.Bool{}, // Initialized to false - RevShareKeeper: revShareKeeper, - MarketMapKeeper: marketMapKeeper, + cdc: cdc, + storeKey: storeKey, + indexPriceCache: indexPriceCache, + timeProvider: timeProvider, + indexerEventManager: indexerEventManager, + authorities: lib.UniqueSliceToSet(authorities), + RevShareKeeper: revShareKeeper, + MarketMapKeeper: marketMapKeeper, } } @@ -71,13 +66,3 @@ func (k Keeper) HasAuthority(authority string) bool { _, ok := k.authorities[authority] return ok } - -func (k Keeper) InitializeCurrencyPairIdCache(ctx sdk.Context) { - alreadyInitialized := k.currencyPairIdCacheInitialized.Swap(true) - if alreadyInitialized { - return - } - - // Load the currency pair IDs for the markets from the x/prices state. - k.LoadCurrencyPairIDCache(ctx) -} diff --git a/protocol/x/prices/keeper/market.go b/protocol/x/prices/keeper/market.go index c0756208e8..8a7fde8dd8 100644 --- a/protocol/x/prices/keeper/market.go +++ b/protocol/x/prices/keeper/market.go @@ -75,7 +75,7 @@ func (k Keeper) CreateMarket( marketPriceStore.Set(lib.Uint32ToKey(marketPrice.Id), priceBytes) // add the pair to the currency-pair-id cache - k.currencyPairIDCache.AddCurrencyPair(uint64(marketParam.Id), currencyPairStr) + k.AddCurrencyPairIDToStore(ctx, marketParam.Id, currencyPair) // Generate indexer event. k.GetIndexerEventManager().AddTxnEvent( diff --git a/protocol/x/prices/keeper/market_param.go b/protocol/x/prices/keeper/market_param.go index 6cea433b5b..0d6edaaa0d 100644 --- a/protocol/x/prices/keeper/market_param.go +++ b/protocol/x/prices/keeper/market_param.go @@ -66,11 +66,26 @@ func (k Keeper) ModifyMarketParam( // if the market pair has been changed, we need to update the in-memory market pair cache if existingParam.Pair != updatedMarketParam.Pair { - // remove the old cache entry - k.currencyPairIDCache.Remove(uint64(existingParam.Id)) + oldCurrencyPair, err := slinky.MarketPairToCurrencyPair(existingParam.Pair) + if err == nil { + k.RemoveCurrencyPairFromStore(ctx, oldCurrencyPair) + } else { + return types.MarketParam{}, errorsmod.Wrap( + types.ErrMarketPairConversionFailed, + existingParam.Pair, + ) + } // add the new cache entry - k.currencyPairIDCache.AddCurrencyPair(uint64(updatedMarketParam.Id), cp.String()) + newCurrencyPair, err := slinky.MarketPairToCurrencyPair(updatedMarketParam.Pair) + if err == nil { + k.AddCurrencyPairIDToStore(ctx, updatedMarketParam.Id, newCurrencyPair) + } else { + return types.MarketParam{}, errorsmod.Wrap( + types.ErrMarketPairConversionFailed, + updatedMarketParam.Pair, + ) + } } // Generate indexer event. @@ -111,26 +126,6 @@ func (k Keeper) GetMarketParam( return market, true } -// LoadCurrencyPairIDCache loads the currency pair id cache from the store. -func (k Keeper) LoadCurrencyPairIDCache(ctx sdk.Context) { - marketParamStore := k.getMarketParamStore(ctx) - - iterator := marketParamStore.Iterator(nil, nil) - defer iterator.Close() - - for ; iterator.Valid(); iterator.Next() { - marketParam := types.MarketParam{} - k.cdc.MustUnmarshal(iterator.Value(), &marketParam) - - cp, err := slinky.MarketPairToCurrencyPair(marketParam.Pair) - if err == nil { - k.currencyPairIDCache.AddCurrencyPair(uint64(marketParam.Id), cp.String()) - } else { - k.Logger(ctx).Error("failed to add currency pair to cache", "pair", marketParam.Pair) - } - } -} - // GetAllMarketParams returns all market params. func (k Keeper) GetAllMarketParams(ctx sdk.Context) []types.MarketParam { marketParamStore := k.getMarketParamStore(ctx) diff --git a/protocol/x/prices/keeper/market_param_test.go b/protocol/x/prices/keeper/market_param_test.go index 6961dba860..6f9bd9a1c0 100644 --- a/protocol/x/prices/keeper/market_param_test.go +++ b/protocol/x/prices/keeper/market_param_test.go @@ -137,6 +137,14 @@ func TestModifyMarketParam_Errors(t *testing.T) { exchangeConfigJson: validExchangeConfigJson, expectedErr: errorsmod.Wrap(types.ErrInvalidInput, constants.ErrorMsgMarketPairCannotBeEmpty).Error(), }, + "Pair name invalid": { + targetId: 0, + pair: "test", // pair must be in format {Base}-{Quote} + minExchanges: uint32(2), + minPriceChangePpm: uint32(50), + exchangeConfigJson: validExchangeConfigJson, + expectedErr: errorsmod.Wrap(types.ErrMarketPairConversionFailed, "test").Error(), + }, "Invalid min price change: zero": { targetId: 0, pair: constants.BtcUsdPair, diff --git a/protocol/x/prices/keeper/market_test.go b/protocol/x/prices/keeper/market_test.go index c9a2bb0ea4..b5586fabc8 100644 --- a/protocol/x/prices/keeper/market_test.go +++ b/protocol/x/prices/keeper/market_test.go @@ -51,6 +51,10 @@ func TestCreateMarket(t *testing.T) { mmMarket, _ := marketMapKeeper.GetMarket(ctx, currencyPair.String()) require.False(t, mmMarket.Ticker.Enabled) + // Verify that currency pair is not in the CurrencyPairToID cache + _, found := keeper.GetIDForCurrencyPair(ctx, currencyPair) + require.False(t, found) + marketParam, err := keeper.CreateMarket( ctx, testMarketParams, @@ -74,6 +78,11 @@ func TestCreateMarket(t *testing.T) { require.Equal(t, uint32(2), marketParam.MinExchanges) require.Equal(t, uint32(9999), marketParam.MinPriceChangePpm) + // Verify that currency pair is in the CurrencyPairToID cache + cpID, found := keeper.GetIDForCurrencyPair(ctx, currencyPair) + require.True(t, found) + require.Equal(t, uint64(marketParam.Id), cpID) + // Verify expected price of 0 created. require.Equal(t, uint32(0), marketPrice.Id) require.Equal(t, int32(-6), marketPrice.Exponent) diff --git a/protocol/x/prices/keeper/slinky_adapter.go b/protocol/x/prices/keeper/slinky_adapter.go index ee390bb84c..9cb12ae3e7 100644 --- a/protocol/x/prices/keeper/slinky_adapter.go +++ b/protocol/x/prices/keeper/slinky_adapter.go @@ -2,10 +2,11 @@ package keeper import ( "fmt" - "strings" "cosmossdk.io/math" + "cosmossdk.io/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" + gogotypes "github.com/cosmos/gogoproto/types" slinkytypes "github.com/skip-mev/slinky/pkg/types" oracletypes "github.com/skip-mev/slinky/x/oracle/types" @@ -21,25 +22,18 @@ import ( * store for converting to and from Slinky's on chain price data. */ -func (k Keeper) GetCurrencyPairFromID(ctx sdk.Context, id uint64) (cp slinkytypes.CurrencyPair, found bool) { - // check in the keeper's cache first - pair, found := k.currencyPairIDCache.GetCurrencyPairFromID(id) - if found { - cp, err := slinkytypes.CurrencyPairFromString(pair) - if err != nil { - k.Logger(ctx).Error("CurrencyPairFromString", "error", err) - return cp, false - } - return cp, true - } +// getCurrencyPairIDStore returns a prefix store for market IDs corresponding to currency pairs. +func (k Keeper) getCurrencyPairIDStore(ctx sdk.Context) prefix.Store { + return prefix.NewStore(ctx.KVStore(k.storeKey), []byte(types.CurrencyPairIDPrefix)) +} +func (k Keeper) GetCurrencyPairFromID(ctx sdk.Context, id uint64) (cp slinkytypes.CurrencyPair, found bool) { mp, found := k.GetMarketParam(ctx, uint32(id)) if !found { return cp, false } - pair = mp.Pair - cp, err := slinky.MarketPairToCurrencyPair(pair) + cp, err := slinky.MarketPairToCurrencyPair(mp.Pair) if err != nil { k.Logger(ctx).Error("CurrencyPairFromString", "error", err) return cp, false @@ -49,28 +43,40 @@ func (k Keeper) GetCurrencyPairFromID(ctx sdk.Context, id uint64) (cp slinkytype } func (k Keeper) GetIDForCurrencyPair(ctx sdk.Context, cp slinkytypes.CurrencyPair) (uint64, bool) { - // check in the keeper's cache first - id, found := k.currencyPairIDCache.GetIDForCurrencyPair(cp.String()) + // Try to get corresponding market ID of the currency pair from the store + marketId, found := k.GetCurrencyPairIDFromStore(ctx, cp) if found { - return id, true + return uint64(marketId), true } - // if not found, iterate through all market params and find the id - mps := k.GetAllMarketParams(ctx) - for _, mp := range mps { - mpCp, err := slinky.MarketPairToCurrencyPair(mp.Pair) - if err != nil { - k.Logger(ctx).Error("market param pair invalid format", "pair", mp.Pair) - continue - } - - // compare the currency pairs to the one that we're looking for - if strings.EqualFold(mpCp.String(), cp.String()) { - return uint64(mp.Id), true - } + return 0, false +} + +func (k Keeper) GetCurrencyPairIDFromStore(ctx sdk.Context, cp slinkytypes.CurrencyPair) (marketId uint64, found bool) { + currencyPairString := cp.String() + currencyPairIDStore := k.getCurrencyPairIDStore(ctx) + var result gogotypes.UInt64Value + b := currencyPairIDStore.Get([]byte(currencyPairString)) + if b == nil { + return 0, false + } else { + k.cdc.MustUnmarshal(b, &result) + return result.Value, true } +} - return 0, false +func (k Keeper) AddCurrencyPairIDToStore(ctx sdk.Context, marketId uint32, cp slinkytypes.CurrencyPair) { + currencyPairString := cp.String() + currencyPairIDStore := k.getCurrencyPairIDStore(ctx) + value := gogotypes.UInt64Value{Value: uint64(marketId)} + b := k.cdc.MustMarshal(&value) + currencyPairIDStore.Set([]byte(currencyPairString), b) +} + +func (k Keeper) RemoveCurrencyPairFromStore(ctx sdk.Context, cp slinkytypes.CurrencyPair) { + currencyPairString := cp.String() + currencyPairIDStore := k.getCurrencyPairIDStore(ctx) + currencyPairIDStore.Delete([]byte(currencyPairString)) } func (k Keeper) GetPriceForCurrencyPair(ctx sdk.Context, cp slinkytypes.CurrencyPair) (oracletypes.QuotePrice, error) { diff --git a/protocol/x/prices/keeper/slinky_adapter_test.go b/protocol/x/prices/keeper/slinky_adapter_test.go index f1434820dd..36dedb8cd5 100644 --- a/protocol/x/prices/keeper/slinky_adapter_test.go +++ b/protocol/x/prices/keeper/slinky_adapter_test.go @@ -12,6 +12,31 @@ import ( "github.com/dydxprotocol/v4-chain/protocol/x/prices/types" ) +func TestCurrencyPairIDStoreFunctions(t *testing.T) { + ctx, keeper, _, _, _, _, _ := keepertest.PricesKeepers(t) + + currencyPair := oracletypes.CurrencyPair{ + Base: "BTC", + Quote: "USD", + } + + // Add the currency pair ID to the store + marketID := uint32(1) + keeper.AddCurrencyPairIDToStore(ctx, marketID, currencyPair) + + // Retrieve the currency pair ID from the store + storedMarketID, found := keeper.GetCurrencyPairIDFromStore(ctx, currencyPair) + + require.True(t, found) + require.Equal(t, uint64(marketID), storedMarketID) + + // Remove the currency pair ID from the store + keeper.RemoveCurrencyPairFromStore(ctx, currencyPair) + + _, found = keeper.GetCurrencyPairIDFromStore(ctx, currencyPair) + require.False(t, found) +} + func TestGetCurrencyPairFromID(t *testing.T) { ctx, keeper, _, _, mockTimeProvider, _, _ := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) @@ -26,7 +51,7 @@ func TestGetCurrencyPairFromID(t *testing.T) { require.True(t, found) } _, found := keeper.GetCurrencyPairFromID(ctx, uint64(marketNumber+1)) - require.True(t, !found) + require.False(t, found) } func TestIDForCurrencyPair(t *testing.T) { @@ -50,7 +75,7 @@ func TestIDForCurrencyPair(t *testing.T) { Base: fmt.Sprint(marketNumber + 1), Quote: fmt.Sprint(marketNumber + 1), }) - require.True(t, !found) + require.False(t, found) } func TestGetPriceForCurrencyPair(t *testing.T) { diff --git a/protocol/x/prices/module.go b/protocol/x/prices/module.go index c272976664..2eebce011b 100644 --- a/protocol/x/prices/module.go +++ b/protocol/x/prices/module.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "time" "cosmossdk.io/core/appmodule" @@ -14,11 +13,8 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - "github.com/dydxprotocol/v4-chain/protocol/lib" - "github.com/dydxprotocol/v4-chain/protocol/lib/metrics" "github.com/dydxprotocol/v4-chain/protocol/x/prices/client/cli" "github.com/dydxprotocol/v4-chain/protocol/x/prices/keeper" "github.com/dydxprotocol/v4-chain/protocol/x/prices/types" @@ -155,17 +151,5 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw return cdc.MustMarshalJSON(genState) } -// PreBlock executes all ABCI PreBlock logic respective to the prices module. -func (am AppModule) PreBlock(ctx context.Context) (appmodule.ResponsePreBlock, error) { - defer telemetry.ModuleMeasureSince(am.Name(), time.Now(), metrics.PreBlocker) - PreBlocker( - lib.UnwrapSDKContext(ctx, types.ModuleName), - am.keeper, - ) - return sdk.ResponsePreBlock{ - ConsensusParamsChanged: false, - }, nil -} - // ConsensusVersion implements ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 1 } diff --git a/protocol/x/prices/types/keys.go b/protocol/x/prices/types/keys.go index 9e5af39ad6..1aa3137e13 100644 --- a/protocol/x/prices/types/keys.go +++ b/protocol/x/prices/types/keys.go @@ -17,6 +17,9 @@ const ( // MarketPriceKeyPrefix is the prefix to retrieve all MarketPrices MarketPriceKeyPrefix = "Price:" + // CurrencyPairIDPrefix is the prefix to retrieve the market ID for a currency pair + CurrencyPairIDPrefix = "CurrencyPairID:" + // NextIDKey is the key for the next market ID NextMarketIDKey = "NextMarketID" ) diff --git a/protocol/x/prices/types/keys_test.go b/protocol/x/prices/types/keys_test.go index 598a46f803..ec89b9ee3a 100644 --- a/protocol/x/prices/types/keys_test.go +++ b/protocol/x/prices/types/keys_test.go @@ -15,4 +15,5 @@ func TestModuleKeys(t *testing.T) { func TestStateKeys(t *testing.T) { require.Equal(t, "Param:", types.MarketParamKeyPrefix) require.Equal(t, "Price:", types.MarketPriceKeyPrefix) + require.Equal(t, "CurrencyPairID:", types.CurrencyPairIDPrefix) } diff --git a/protocol/x/prices/types/types.go b/protocol/x/prices/types/types.go index aada507c64..ba32185e93 100644 --- a/protocol/x/prices/types/types.go +++ b/protocol/x/prices/types/types.go @@ -33,8 +33,6 @@ type PricesKeeper interface { GetAllMarketPrices(ctx sdk.Context) (marketPrices []MarketPrice) HasAuthority(authority string) bool - InitializeCurrencyPairIdCache(ctx sdk.Context) - // Validation related. PerformStatefulPriceUpdateValidation( ctx sdk.Context, @@ -49,6 +47,9 @@ type PricesKeeper interface { // Misc. Logger(ctx sdk.Context) log.Logger + // Currency Pair ID cache + AddCurrencyPairIDToStore(ctx sdk.Context, id uint32, cp slinkytypes.CurrencyPair) + // Slinky compat GetCurrencyPairFromID(ctx sdk.Context, id uint64) (cp slinkytypes.CurrencyPair, found bool) GetIDForCurrencyPair(ctx sdk.Context, cp slinkytypes.CurrencyPair) (uint64, bool)