From 40734d5e6b77f1188dabf41181a29a91ab26a698 Mon Sep 17 00:00:00 2001 From: roman Date: Thu, 21 Sep 2023 15:27:26 -0400 Subject: [PATCH 01/11] feat: make PoolModuleI CalculateSpotPrice API return BigDec --- app/apptesting/gamm.go | 8 ++--- app/apptesting/test_suite.go | 2 +- app/upgrades/v16/upgrades_test.go | 2 +- app/upgrades/v17/upgrades_test.go | 4 +-- tests/mocks/pool_module.go | 4 +-- x/concentrated-liquidity/pool.go | 18 +++++----- x/concentrated-liquidity/pool_test.go | 10 ++++-- x/cosmwasmpool/pool_module.go | 8 ++--- x/gamm/keeper/grpc_query.go | 8 +++-- x/gamm/keeper/grpc_query_test.go | 16 ++++----- x/gamm/keeper/pool_service.go | 28 ++++++++------- x/gamm/keeper/pool_service_test.go | 4 +-- x/gamm/keeper/swap_test.go | 4 +-- .../pool-models/balancer/pool_suite_test.go | 16 ++++----- x/gamm/types/constants.go | 3 +- x/poolmanager/client/query_proto_wrap.go | 4 ++- x/poolmanager/router.go | 8 ++--- x/poolmanager/router_test.go | 10 +++--- x/poolmanager/types/expected_keepers.go | 2 +- x/twap/api_test.go | 2 +- x/twap/listeners_test.go | 6 ++-- x/twap/logic.go | 34 +++++++++++++------ x/twap/types/expected_interfaces.go | 2 +- x/twap/types/twapmock/amminterface.go | 9 +++-- x/twap/types/utils.go | 5 ++- x/txfees/keeper/feetokens.go | 13 ++++--- x/txfees/keeper/grpc_query.go | 3 +- x/txfees/types/expected_keepers.go | 2 +- 28 files changed, 136 insertions(+), 99 deletions(-) diff --git a/app/apptesting/gamm.go b/app/apptesting/gamm.go index 9cc7bae8db6..2c94d867bd2 100644 --- a/app/apptesting/gamm.go +++ b/app/apptesting/gamm.go @@ -87,8 +87,8 @@ func (s *KeeperTestHelper) PrepareBalancerPoolWithCoinsAndWeights(coins sdk.Coin } var zeroDec = osmomath.ZeroDec() -var oneThirdSpotPriceUnits = osmomath.NewDec(1).Quo(osmomath.NewDec(3)). - MulIntMut(gammtypes.SpotPriceSigFigs).RoundInt().ToLegacyDec().QuoInt(gammtypes.SpotPriceSigFigs) +var oneThirdSpotPriceUnits = osmomath.BigDecFromDec(osmomath.NewDec(1).Quo(osmomath.NewDec(3)). + MulIntMut(gammtypes.SpotPriceSigFigs).RoundInt().ToLegacyDec().QuoInt(gammtypes.SpotPriceSigFigs)) // PrepareBalancerPool returns a Balancer pool's pool-ID with pool params set in PrepareBalancerPoolWithPoolParams. func (s *KeeperTestHelper) PrepareBalancerPool() uint64 { @@ -99,10 +99,10 @@ func (s *KeeperTestHelper) PrepareBalancerPool() uint64 { spotPrice, err := s.App.GAMMKeeper.CalculateSpotPrice(s.Ctx, poolId, FOO, BAR) s.NoError(err) - s.Equal(osmomath.NewDec(2), spotPrice) + s.Equal(osmomath.NewBigDec(2), spotPrice) spotPrice, err = s.App.GAMMKeeper.CalculateSpotPrice(s.Ctx, poolId, BAR, BAZ) s.NoError(err) - s.Equal(osmomath.NewDecWithPrec(15, 1), spotPrice) + s.Equal(osmomath.NewBigDecWithPrec(15, 1), spotPrice) spotPrice, err = s.App.GAMMKeeper.CalculateSpotPrice(s.Ctx, poolId, BAZ, FOO) s.NoError(err) s.Equal(oneThirdSpotPriceUnits, spotPrice) diff --git a/app/apptesting/test_suite.go b/app/apptesting/test_suite.go index 201195a2882..b80d9c18f55 100644 --- a/app/apptesting/test_suite.go +++ b/app/apptesting/test_suite.go @@ -393,7 +393,7 @@ func (s *KeeperTestHelper) SetupGammPoolsWithBondDenomMultiplier(multipliers []o // SwapAndSetSpotPrice runs a swap to set Spot price of a pool using arbitrary values // returns spot price after the arbitrary swap. -func (s *KeeperTestHelper) SwapAndSetSpotPrice(poolId uint64, fromAsset sdk.Coin, toAsset sdk.Coin) osmomath.Dec { +func (s *KeeperTestHelper) SwapAndSetSpotPrice(poolId uint64, fromAsset sdk.Coin, toAsset sdk.Coin) osmomath.BigDec { // create a dummy account acc1 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address().Bytes()) diff --git a/app/upgrades/v16/upgrades_test.go b/app/upgrades/v16/upgrades_test.go index 43c51029b64..e88a30260d9 100644 --- a/app/upgrades/v16/upgrades_test.go +++ b/app/upgrades/v16/upgrades_test.go @@ -147,7 +147,7 @@ func (s *UpgradeTestSuite) TestUpgrade() { s.Require().Equal(v16.DAIIBCDenom, concentratedTypePool.GetToken1()) // Validate that the spot price of the CL pool is what we expect - osmoassert.Equal(s.T(), multiplicativeTolerance, concentratedTypePool.GetCurrentSqrtPrice().PowerInteger(2), osmomath.BigDecFromDec(balancerSpotPrice)) + osmoassert.Equal(s.T(), multiplicativeTolerance, concentratedTypePool.GetCurrentSqrtPrice().PowerInteger(2), balancerSpotPrice) // Validate that link was created. migrationInfo, err := s.App.GAMMKeeper.GetAllMigrationInfo(s.Ctx) diff --git a/app/upgrades/v17/upgrades_test.go b/app/upgrades/v17/upgrades_test.go index 6e320a5b181..10ac7e95a2e 100644 --- a/app/upgrades/v17/upgrades_test.go +++ b/app/upgrades/v17/upgrades_test.go @@ -295,7 +295,7 @@ func (s *UpgradeTestSuite) TestUpgrade() { s.Require().Equal(assetPair.QuoteAsset, concentratedTypePool.GetToken1()) // Validate that the spot price of the CL pool is what we expect - osmoassert.Equal(s.T(), multiplicativeTolerance, concentratedTypePool.GetCurrentSqrtPrice().PowerInteger(2), osmomath.BigDecFromDec(balancerSpotPrice)) + osmoassert.Equal(s.T(), multiplicativeTolerance, concentratedTypePool.GetCurrentSqrtPrice().PowerInteger(2), balancerSpotPrice) // Validate that the link is correct. migrationInfo, err := s.App.GAMMKeeper.GetAllMigrationInfo(s.Ctx) @@ -461,7 +461,7 @@ func (s *UpgradeTestSuite) TestUpgrade() { s.Require().Equal(quoteAsset, concentratedTypePool.GetToken1()) // Validate that the spot price of the CL pool is what we expect - osmoassert.Equal(s.T(), multiplicativeTolerance, concentratedTypePool.GetCurrentSqrtPrice().PowerInteger(2), osmomath.BigDecFromDec(balancerSpotPrice)) + osmoassert.Equal(s.T(), multiplicativeTolerance, concentratedTypePool.GetCurrentSqrtPrice().PowerInteger(2), balancerSpotPrice) // Validate that the link is correct. migrationInfo, err := s.App.GAMMKeeper.GetAllMigrationInfo(s.Ctx) diff --git a/tests/mocks/pool_module.go b/tests/mocks/pool_module.go index 7822b08077d..1103e9c6caa 100644 --- a/tests/mocks/pool_module.go +++ b/tests/mocks/pool_module.go @@ -260,10 +260,10 @@ func (mr *MockPoolModuleIMockRecorder) CalcOutAmtGivenIn(ctx, poolI, tokenIn, to } // CalculateSpotPrice mocks base method. -func (m *MockPoolModuleI) CalculateSpotPrice(ctx types.Context, poolId uint64, quoteAssetDenom, baseAssetDenom string) (osmomath.Dec, error) { +func (m *MockPoolModuleI) CalculateSpotPrice(ctx types.Context, poolId uint64, quoteAssetDenom, baseAssetDenom string) (osmomath.BigDec, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "CalculateSpotPrice", ctx, poolId, quoteAssetDenom, baseAssetDenom) - ret0, _ := ret[0].(osmomath.Dec) + ret0, _ := ret[0].(osmomath.BigDec) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/x/concentrated-liquidity/pool.go b/x/concentrated-liquidity/pool.go index e944c53ee89..3c49c1033d4 100644 --- a/x/concentrated-liquidity/pool.go +++ b/x/concentrated-liquidity/pool.go @@ -165,36 +165,34 @@ func (k Keeper) CalculateSpotPrice( poolId uint64, quoteAssetDenom string, baseAssetDenom string, -) (spotPrice osmomath.Dec, err error) { +) (spotPrice osmomath.BigDec, err error) { concentratedPool, err := k.getPoolById(ctx, poolId) if err != nil { - return osmomath.Dec{}, err + return osmomath.BigDec{}, err } hasPositions, err := k.HasAnyPositionForPool(ctx, poolId) if err != nil { - return osmomath.Dec{}, err + return osmomath.BigDec{}, err } if !hasPositions { - return osmomath.Dec{}, types.NoSpotPriceWhenNoLiquidityError{PoolId: poolId} + return osmomath.BigDec{}, types.NoSpotPriceWhenNoLiquidityError{PoolId: poolId} } price, err := concentratedPool.SpotPrice(ctx, quoteAssetDenom, baseAssetDenom) if err != nil { - return osmomath.Dec{}, err + return osmomath.BigDec{}, err } if price.IsZero() { - return osmomath.Dec{}, types.PriceBoundError{ProvidedPrice: price, MinSpotPrice: types.MinSpotPriceV2, MaxSpotPrice: types.MaxSpotPrice} + return osmomath.BigDec{}, types.PriceBoundError{ProvidedPrice: price, MinSpotPrice: types.MinSpotPriceV2, MaxSpotPrice: types.MaxSpotPrice} } if price.GT(types.MaxSpotPriceBigDec) || price.LT(types.MinSpotPriceBigDec) { - return osmomath.Dec{}, types.PriceBoundError{ProvidedPrice: price, MinSpotPrice: types.MinSpotPriceBigDec, MaxSpotPrice: types.MaxSpotPrice} + return osmomath.BigDec{}, types.PriceBoundError{ProvidedPrice: price, MinSpotPrice: types.MinSpotPriceBigDec, MaxSpotPrice: types.MaxSpotPrice} } - // TODO: remove before https://github.com/osmosis-labs/osmosis/issues/5726 is complete. - // Acceptable for backwards compatibility with v19.x. - return price.Dec(), nil + return price, nil } // GetTotalPoolLiquidity returns the coins in the pool owned by all LPs diff --git a/x/concentrated-liquidity/pool_test.go b/x/concentrated-liquidity/pool_test.go index ff6ba0fac47..1d2f359aa45 100644 --- a/x/concentrated-liquidity/pool_test.go +++ b/x/concentrated-liquidity/pool_test.go @@ -271,7 +271,7 @@ func (s *KeeperTestSuite) TestCalculateSpotPrice() { spotPrice, err := s.App.ConcentratedLiquidityKeeper.CalculateSpotPrice(s.Ctx, poolId, ETH, USDC) s.Require().Error(err) s.Require().ErrorAs(err, &types.NoSpotPriceWhenNoLiquidityError{PoolId: poolId}) - s.Require().Equal(osmomath.Dec{}, spotPrice) + s.Require().Equal(osmomath.BigDec{}, spotPrice) // set up default position to have proper spot price s.SetupDefaultPosition(defaultPoolId) @@ -279,12 +279,16 @@ func (s *KeeperTestSuite) TestCalculateSpotPrice() { // ETH is token0 so its price will be the DefaultCurrSqrtPrice squared spotPriceBaseETH, err := s.App.ConcentratedLiquidityKeeper.CalculateSpotPrice(s.Ctx, poolId, USDC, ETH) s.Require().NoError(err) - s.Require().Equal(spotPriceBaseETH, DefaultCurrSqrtPrice.PowerInteger(2).Dec()) + // TODO: remove Dec truncation before https://github.com/osmosis-labs/osmosis/issues/5726 is complete + // Currently exists for state-compatibility with v19.x + s.Require().Equal(spotPriceBaseETH.Dec(), DefaultCurrSqrtPrice.PowerInteger(2).Dec()) // test that we have correct values for reversed quote asset and base asset spotPriceBaseUSDC, err := s.App.ConcentratedLiquidityKeeper.CalculateSpotPrice(s.Ctx, poolId, ETH, USDC) s.Require().NoError(err) - s.Require().Equal(spotPriceBaseUSDC, osmomath.OneBigDec().Quo(DefaultCurrSqrtPrice.PowerInteger(2)).Dec()) + // TODO: remove Dec truncation before https://github.com/osmosis-labs/osmosis/issues/5726 is complete + // Currently exists for state-compatibility with v19.x + s.Require().Equal(spotPriceBaseUSDC.Dec(), osmomath.OneBigDec().Quo(DefaultCurrSqrtPrice.PowerInteger(2)).Dec()) // try getting spot price from a non-existent pool spotPrice, err = s.App.ConcentratedLiquidityKeeper.CalculateSpotPrice(s.Ctx, poolId+1, USDC, ETH) diff --git a/x/cosmwasmpool/pool_module.go b/x/cosmwasmpool/pool_module.go index 52d05c381fa..c744519e64a 100644 --- a/x/cosmwasmpool/pool_module.go +++ b/x/cosmwasmpool/pool_module.go @@ -168,19 +168,19 @@ func (k Keeper) CalculateSpotPrice( poolId uint64, quoteAssetDenom string, baseAssetDenom string, -) (price osmomath.Dec, err error) { +) (price osmomath.BigDec, err error) { cosmwasmPool, err := k.GetPoolById(ctx, poolId) if err != nil { - return osmomath.Dec{}, err + return osmomath.BigDec{}, err } spotPriceBigDec, err := cosmwasmPool.SpotPrice(ctx, quoteAssetDenom, baseAssetDenom) if err != nil { - return osmomath.Dec{}, err + return osmomath.BigDec{}, err } // Truncation is acceptable here since the only reason cosmwasmPool returns a BigDec // is to maintain compatibility with the `PoolI.SpotPrice` API. - return spotPriceBigDec.Dec(), nil + return spotPriceBigDec, nil } // SwapExactAmountIn performs a swap operation with a specified input amount in a CosmWasm-based liquidity pool. diff --git a/x/gamm/keeper/grpc_query.go b/x/gamm/keeper/grpc_query.go index 035e15150f9..8448cb35c14 100644 --- a/x/gamm/keeper/grpc_query.go +++ b/x/gamm/keeper/grpc_query.go @@ -383,7 +383,9 @@ func (q Querier) SpotPrice(ctx context.Context, req *types.QuerySpotPriceRequest } return &types.QuerySpotPriceResponse{ - SpotPrice: sp.String(), + // Note: truncation exists here to maintain backwards compatibility. + // This query has historically had 18 decimals in response. + SpotPrice: sp.Dec().String(), }, nil } @@ -412,7 +414,9 @@ func (q QuerierV2) SpotPrice(ctx context.Context, req *v2types.QuerySpotPriceReq // Deeprecated: use alternate in x/poolmanager // nolint: staticcheck return &v2types.QuerySpotPriceResponse{ - SpotPrice: sp.String(), + // Note: truncation exists here to maintain backwards compatibility. + // This query has historically had 18 decimals in response. + SpotPrice: sp.Dec().String(), }, nil } diff --git a/x/gamm/keeper/grpc_query_test.go b/x/gamm/keeper/grpc_query_test.go index 9fd82d27b36..a200e3b1e58 100644 --- a/x/gamm/keeper/grpc_query_test.go +++ b/x/gamm/keeper/grpc_query_test.go @@ -897,12 +897,12 @@ func (s *KeeperTestSuite) TestQueryStableswapPoolSpotPrice() { } else { s.Require().NoError(err, "unexpected error") // We allow for a small geometric error due to our spot price being an approximation - expectedSpotPrice := osmomath.MustNewDecFromStr(tc.result) - actualSpotPrice := osmomath.MustNewDecFromStr(result.SpotPrice) + expectedSpotPrice := osmomath.MustNewBigDecFromStr(tc.result) + actualSpotPrice := osmomath.MustNewBigDecFromStr(result.SpotPrice) diff := (expectedSpotPrice.Sub(actualSpotPrice)).Abs() - errTerm := diff.Quo(osmomath.MinDec(expectedSpotPrice, actualSpotPrice)) + errTerm := diff.Quo(osmomath.MinBigDec(expectedSpotPrice, actualSpotPrice)) - s.Require().True(errTerm.LT(osmomath.NewDecWithPrec(1, 3)), "Expected: %d, Actual: %d", expectedSpotPrice, actualSpotPrice) + s.Require().True(errTerm.LT(osmomath.NewBigDecWithPrec(1, 3)), "Expected: %d, Actual: %d", expectedSpotPrice, actualSpotPrice) } }) } @@ -980,12 +980,12 @@ func (s *KeeperTestSuite) TestV2QueryStableswapPoolSpotPrice() { s.Require().NoError(err, "unexpected error") // We allow for a small geometric error due to our spot price being an approximation - expectedSpotPrice := osmomath.MustNewDecFromStr(tc.result) - actualSpotPrice := osmomath.MustNewDecFromStr(result.SpotPrice) + expectedSpotPrice := osmomath.MustNewBigDecFromStr(tc.result) + actualSpotPrice := osmomath.MustNewBigDecFromStr(result.SpotPrice) diff := (expectedSpotPrice.Sub(actualSpotPrice)).Abs() - errTerm := diff.Quo(osmomath.MinDec(expectedSpotPrice, actualSpotPrice)) + errTerm := diff.Quo(osmomath.MinBigDec(expectedSpotPrice, actualSpotPrice)) - s.Require().True(errTerm.LT(osmomath.NewDecWithPrec(1, 3)), "Expected: %d, Actual: %d", expectedSpotPrice, actualSpotPrice) + s.Require().True(errTerm.LT(osmomath.NewBigDecWithPrec(1, 3)), "Expected: %d, Actual: %d", expectedSpotPrice, actualSpotPrice) } }) } diff --git a/x/gamm/keeper/pool_service.go b/x/gamm/keeper/pool_service.go index 9afe42600ff..4bc1cbaee3f 100644 --- a/x/gamm/keeper/pool_service.go +++ b/x/gamm/keeper/pool_service.go @@ -26,39 +26,41 @@ func (k Keeper) CalculateSpotPrice( poolID uint64, quoteAssetDenom string, baseAssetDenom string, -) (spotPrice osmomath.Dec, err error) { +) (spotPrice osmomath.BigDec, err error) { pool, err := k.GetPoolAndPoke(ctx, poolID) if err != nil { - return osmomath.Dec{}, err + return osmomath.BigDec{}, err } // defer to catch panics, in case something internal overflows. defer func() { if r := recover(); r != nil { - spotPrice = osmomath.Dec{} + spotPrice = osmomath.BigDec{} err = types.ErrSpotPriceInternal } }() - spotPriceBigDec, err := pool.SpotPrice(ctx, quoteAssetDenom, baseAssetDenom) + spotPrice, err = pool.SpotPrice(ctx, quoteAssetDenom, baseAssetDenom) if err != nil { - return osmomath.Dec{}, err + return osmomath.BigDec{}, err } - // Truncation is acceptable here because both stableswap and balancer - // only support 18 decimal places and wrap around the 36 BigDec for - // compatibility with the `PoolI.SpotPrice` API - spotPrice = spotPriceBigDec.Dec() + // TODO: this is done to maintain state-compatibility with v19.x + // Remove after https://github.com/osmosis-labs/osmosis/issues/6064 is complete. + spotPrice.ChopPrecisionMut(osmomath.PrecisionDec) // if spotPrice greater than max spot price, return an error - if spotPrice.GT(types.MaxSpotPrice) { - return types.MaxSpotPrice, types.ErrSpotPriceOverflow + if spotPrice.GT(types.MaxSpotPriceBigDec) { + return types.MaxSpotPriceBigDec, types.ErrSpotPriceOverflow } else if !spotPrice.IsPositive() { - return osmomath.Dec{}, types.ErrSpotPriceInternal + return osmomath.BigDec{}, types.ErrSpotPriceInternal } // we want to round this to `SpotPriceSigFigs` of precision - spotPrice = osmomath.SigFigRound(spotPrice, types.SpotPriceSigFigs) + // Truncation is acceptable here because both stableswap and balancer + // only support 18 decimal places and wrap around the 36 BigDec for + // compatibility with the `PoolI.SpotPrice` API + spotPrice = osmomath.BigDecFromDec(osmomath.SigFigRound(spotPrice.Dec(), types.SpotPriceSigFigs)) return spotPrice, err } diff --git a/x/gamm/keeper/pool_service_test.go b/x/gamm/keeper/pool_service_test.go index d10d2676ae2..6f066fe14d5 100644 --- a/x/gamm/keeper/pool_service_test.go +++ b/x/gamm/keeper/pool_service_test.go @@ -434,11 +434,11 @@ func (s *KeeperTestSuite) TestSpotPriceOverflow() { s.Require().NoError(poolErr) s.Require().ErrorIs(keeperErr, types.ErrSpotPriceOverflow) s.Require().Error(keeperErr) - s.Require().Equal(types.MaxSpotPrice, keeperSpotPrice) + s.Require().Equal(types.MaxSpotPriceBigDec, keeperSpotPrice) } else if tc.panics { s.Require().ErrorIs(keeperErr, types.ErrSpotPriceInternal) s.Require().Error(keeperErr) - s.Require().Equal(osmomath.Dec{}, keeperSpotPrice) + s.Require().Equal(osmomath.BigDec{}, keeperSpotPrice) } else { s.Require().NoError(poolErr) s.Require().NoError(keeperErr) diff --git a/x/gamm/keeper/swap_test.go b/x/gamm/keeper/swap_test.go index 7428a567f31..c18d622c769 100644 --- a/x/gamm/keeper/swap_test.go +++ b/x/gamm/keeper/swap_test.go @@ -161,7 +161,7 @@ func (s *KeeperTestSuite) TestBalancerPoolSimpleSwapExactAmountIn() { } // Ratio of the token out should be between the before spot price and after spot price. - tradeAvgPrice := test.param.tokenIn.Amount.ToLegacyDec().Quo(tokenOutAmount.ToLegacyDec()) + tradeAvgPrice := osmomath.BigDecFromDec(test.param.tokenIn.Amount.ToLegacyDec().Quo(tokenOutAmount.ToLegacyDec())) s.True(tradeAvgPrice.GT(spotPriceBefore) && tradeAvgPrice.LT(spotPriceAfter), "test: %v", test.name) } else { _, err := keeper.SwapExactAmountIn(ctx, s.TestAccs[0], pool, test.param.tokenIn, test.param.tokenOutDenom, test.param.tokenOutMinAmount, spreadFactor) @@ -413,7 +413,7 @@ func (s *KeeperTestSuite) TestBalancerPoolSimpleSwapExactAmountOut() { s.NoError(err, "test: %v", test.name) // Ratio of the token out should be between the before spot price and after spot price. - tradeAvgPrice := tokenInAmount.ToLegacyDec().Quo(test.param.tokenOut.Amount.ToLegacyDec()) + tradeAvgPrice := osmomath.BigDecFromDec(tokenInAmount.ToLegacyDec().Quo(test.param.tokenOut.Amount.ToLegacyDec())) s.True(tradeAvgPrice.GT(spotPriceBefore) && tradeAvgPrice.LT(spotPriceAfter), "test: %v", test.name) } else { _, err := keeper.SwapExactAmountOut(s.Ctx, s.TestAccs[0], pool, test.param.tokenInDenom, test.param.tokenInMaxAmount, test.param.tokenOut, spreadFactor) diff --git a/x/gamm/pool-models/balancer/pool_suite_test.go b/x/gamm/pool-models/balancer/pool_suite_test.go index 083b57cdd7b..321bba39bda 100644 --- a/x/gamm/pool-models/balancer/pool_suite_test.go +++ b/x/gamm/pool-models/balancer/pool_suite_test.go @@ -638,49 +638,49 @@ func (s *KeeperTestSuite) TestBalancerSpotPrice() { baseDenomPoolInput sdk.Coin quoteDenomPoolInput sdk.Coin expectError bool - expectedOutput osmomath.Dec + expectedOutput osmomath.BigDec }{ { name: "equal value", baseDenomPoolInput: sdk.NewInt64Coin(baseDenom, 100), quoteDenomPoolInput: sdk.NewInt64Coin(quoteDenom, 100), expectError: false, - expectedOutput: osmomath.MustNewDecFromStr("1"), + expectedOutput: osmomath.MustNewBigDecFromStr("1"), }, { name: "1:2 ratio", baseDenomPoolInput: sdk.NewInt64Coin(baseDenom, 100), quoteDenomPoolInput: sdk.NewInt64Coin(quoteDenom, 200), expectError: false, - expectedOutput: osmomath.MustNewDecFromStr("0.500000000000000000"), + expectedOutput: osmomath.MustNewBigDecFromStr("0.500000000000000000"), }, { name: "2:1 ratio", baseDenomPoolInput: sdk.NewInt64Coin(baseDenom, 200), quoteDenomPoolInput: sdk.NewInt64Coin(quoteDenom, 100), expectError: false, - expectedOutput: osmomath.MustNewDecFromStr("2.000000000000000000"), + expectedOutput: osmomath.MustNewBigDecFromStr("2.000000000000000000"), }, { name: "rounding after sigfig ratio", baseDenomPoolInput: sdk.NewInt64Coin(baseDenom, 220), quoteDenomPoolInput: sdk.NewInt64Coin(quoteDenom, 115), expectError: false, - expectedOutput: osmomath.MustNewDecFromStr("1.913043480000000000"), // ans is 1.913043478260869565, rounded is 1.91304348 + expectedOutput: osmomath.MustNewBigDecFromStr("1.913043480000000000"), // ans is 1.913043478260869565, rounded is 1.91304348 }, { name: "check number of sig figs", baseDenomPoolInput: sdk.NewInt64Coin(baseDenom, 100), quoteDenomPoolInput: sdk.NewInt64Coin(quoteDenom, 300), expectError: false, - expectedOutput: osmomath.MustNewDecFromStr("0.333333330000000000"), + expectedOutput: osmomath.MustNewBigDecFromStr("0.333333330000000000"), }, { name: "check number of sig figs high sizes", baseDenomPoolInput: sdk.NewInt64Coin(baseDenom, 343569192534), quoteDenomPoolInput: sdk.NewCoin(quoteDenom, osmomath.MustNewDecFromStr("186633424395479094888742").TruncateInt()), expectError: false, - expectedOutput: osmomath.MustNewDecFromStr("0.000000000001840877"), + expectedOutput: osmomath.MustNewBigDecFromStr("0.000000000001840877"), }, } @@ -819,7 +819,7 @@ func (s *KeeperTestSuite) TestBalancerSpotPriceBounds() { s.Require().Error(err, "test: %s", tc.name) } else { s.Require().NoError(err, "test: %s", tc.name) - s.Require().True(spotPrice.Equal(tc.expectedOutput), + s.Require().True(spotPrice.Equal(osmomath.BigDecFromDec(tc.expectedOutput)), "test: %s\nSpot price wrong, got %s, expected %s\n", tc.name, spotPrice, tc.expectedOutput) } diff --git a/x/gamm/types/constants.go b/x/gamm/types/constants.go index 25a66a11566..fdbdff429e9 100644 --- a/x/gamm/types/constants.go +++ b/x/gamm/types/constants.go @@ -33,7 +33,8 @@ var ( // Internal note: Ctrl+F for MaxSpotPrice in code if ever changed. // Other tests depend on being equal to MaxSpotPrice, // but don't directly import it due to import issues. - MaxSpotPrice = osmomath.NewDec(2).Power(128).Sub(osmomath.OneDec()) + MaxSpotPrice = osmomath.NewDec(2).Power(128).Sub(osmomath.OneDec()) + MaxSpotPriceBigDec = osmomath.BigDecFromDec(MaxSpotPrice) // MinSpotPrice is the minimum supported spot price. Anything less than this will error. // It is limited by osmomath.Dec's precision. MinSpotPrice = osmomath.SmallestDec() diff --git a/x/poolmanager/client/query_proto_wrap.go b/x/poolmanager/client/query_proto_wrap.go index c057423dce3..ee3970c8415 100644 --- a/x/poolmanager/client/query_proto_wrap.go +++ b/x/poolmanager/client/query_proto_wrap.go @@ -219,7 +219,9 @@ func (q Querier) SpotPrice(ctx sdk.Context, req queryproto.SpotPriceRequest) (*q } return &queryproto.SpotPriceResponse{ - SpotPrice: sp.String(), + // Note: truncation exists here to maintain backwards compatibility. + // This query has historically had 18 decimals in response. + SpotPrice: sp.Dec().String(), }, err } diff --git a/x/poolmanager/router.go b/x/poolmanager/router.go index a9542bcd52e..6e829157475 100644 --- a/x/poolmanager/router.go +++ b/x/poolmanager/router.go @@ -554,15 +554,15 @@ func (k Keeper) RouteCalculateSpotPrice( poolId uint64, quoteAssetDenom string, baseAssetDenom string, -) (price osmomath.Dec, err error) { +) (price osmomath.BigDec, err error) { swapModule, err := k.GetPoolModule(ctx, poolId) if err != nil { - return osmomath.Dec{}, err + return osmomath.BigDec{}, err } price, err = swapModule.CalculateSpotPrice(ctx, poolId, quoteAssetDenom, baseAssetDenom) if err != nil { - return osmomath.Dec{}, err + return osmomath.BigDec{}, err } return price, nil @@ -886,7 +886,7 @@ func (k Keeper) trackVolume(ctx sdk.Context, poolId uint64, volumeGenerated sdk. // Multiply `volumeGenerated.Amount.ToDec()` by this spot price. // While rounding does not particularly matter here, we round down to ensure that we do not overcount volume. - volumeInOsmo := volumeGenerated.Amount.ToLegacyDec().Mul(osmoPerInputToken).TruncateInt() + volumeInOsmo := osmomath.BigDecFromSDKInt(volumeGenerated.Amount).Mul(osmoPerInputToken).Dec().TruncateInt() // Add this new volume to the global tracked volume for the pool ID k.addVolume(ctx, poolId, sdk.NewCoin(OSMO, volumeInOsmo)) diff --git a/x/poolmanager/router_test.go b/x/poolmanager/router_test.go index 9dbfd913b74..bd2bc26aef2 100644 --- a/x/poolmanager/router_test.go +++ b/x/poolmanager/router_test.go @@ -320,7 +320,7 @@ func (s *KeeperTestSuite) TestRouteCalculateSpotPrice() { setPositionForCLPool bool routesOverwrite map[types.PoolType]types.PoolModuleI - expectedSpotPrice osmomath.Dec + expectedSpotPrice osmomath.BigDec expectError error }{ @@ -329,14 +329,14 @@ func (s *KeeperTestSuite) TestRouteCalculateSpotPrice() { poolId: 1, quoteAssetDenom: "bar", baseAssetDenom: "baz", - expectedSpotPrice: osmomath.MustNewDecFromStr("1.5"), + expectedSpotPrice: osmomath.MustNewBigDecFromStr("1.5"), }, "valid stableswap pool": { preCreatePoolType: types.Stableswap, poolId: 1, quoteAssetDenom: "bar", baseAssetDenom: "baz", - expectedSpotPrice: osmomath.MustNewDecFromStr("0.99999998"), + expectedSpotPrice: osmomath.MustNewBigDecFromStr("0.99999998"), }, "valid concentrated liquidity pool with position": { preCreatePoolType: types.Concentrated, @@ -347,7 +347,7 @@ func (s *KeeperTestSuite) TestRouteCalculateSpotPrice() { // We generate this value using the scripts in x/concentrated-liquidity/python // Exact output: 5000.000000000000000129480272834995458481 // SDK Bankers rounded output: 5000.000000000000000129 - expectedSpotPrice: osmomath.MustNewDecFromStr("5000.000000000000000129"), + expectedSpotPrice: osmomath.MustNewBigDecFromStr("5000.000000000000000129"), }, "valid concentrated liquidity pool without position": { preCreatePoolType: types.Concentrated, @@ -365,7 +365,7 @@ func (s *KeeperTestSuite) TestRouteCalculateSpotPrice() { quoteAssetDenom: apptesting.DefaultTransmuterDenomA, baseAssetDenom: apptesting.DefaultTransmuterDenomB, // For transmuter, the spot price is always 1. (hard-coded even if no liquidity) - expectedSpotPrice: osmomath.OneDec(), + expectedSpotPrice: osmomath.OneBigDec(), }, "non-existent pool": { preCreatePoolType: types.Balancer, diff --git a/x/poolmanager/types/expected_keepers.go b/x/poolmanager/types/expected_keepers.go index d182992888b..5150a392478 100644 --- a/x/poolmanager/types/expected_keepers.go +++ b/x/poolmanager/types/expected_keepers.go @@ -48,7 +48,7 @@ type PoolModuleI interface { poolId uint64, quoteAssetDenom string, baseAssetDenom string, - ) (price osmomath.Dec, err error) + ) (price osmomath.BigDec, err error) SwapExactAmountIn( ctx sdk.Context, diff --git a/x/twap/api_test.go b/x/twap/api_test.go index 6bed4b7ddda..e9727ca4e03 100644 --- a/x/twap/api_test.go +++ b/x/twap/api_test.go @@ -899,7 +899,7 @@ func (s *TestSuite) TestGeometricTwapToNow_BalancerPool_Randomized() { osmomath.ErrTolerance{ MultiplicativeTolerance: osmomath.SmallestDec(), }.CompareBigDec( - osmomath.BigDecFromDec(spotPrice), + spotPrice, osmomath.BigDecFromDec(twap), ) }) diff --git a/x/twap/listeners_test.go b/x/twap/listeners_test.go index 31336fd9b26..24bcdf26012 100644 --- a/x/twap/listeners_test.go +++ b/x/twap/listeners_test.go @@ -205,7 +205,8 @@ func (s *TestSuite) TestEndBlock() { // check if spot price has been correctly updated in twap record asset0sp, err := s.App.PoolManagerKeeper.RouteCalculateSpotPrice(s.Ctx, poolId, twapAfterBlock1.Asset0Denom, twapAfterBlock1.Asset1Denom) s.Require().NoError(err) - s.Require().Equal(asset0sp, twapAfterBlock1.P0LastSpotPrice) + // Note: twap only supports decimal precision of 18. Thus, truncation. + s.Require().Equal(asset0sp.Dec(), twapAfterBlock1.P0LastSpotPrice) // run basic swap on block two for price change if tc.block2Swap { @@ -233,7 +234,8 @@ func (s *TestSuite) TestEndBlock() { // check if spot price has been correctly updated in twap record asset0sp, err = s.App.PoolManagerKeeper.RouteCalculateSpotPrice(s.Ctx, poolId, twapAfterBlock1.Asset0Denom, twapAfterBlock2.Asset1Denom) s.Require().NoError(err) - s.Require().Equal(asset0sp, twapAfterBlock2.P0LastSpotPrice) + // Note: twap only supports decimal precision of 18. Thus, truncation. + s.Require().Equal(asset0sp.Dec(), twapAfterBlock2.P0LastSpotPrice) }) } } diff --git a/x/twap/logic.go b/x/twap/logic.go index 8f3bf80d520..6fb294a2bab 100644 --- a/x/twap/logic.go +++ b/x/twap/logic.go @@ -47,28 +47,40 @@ func getSpotPrices( ) (sp0 osmomath.Dec, sp1 osmomath.Dec, latestErrTime time.Time) { latestErrTime = previousErrorTime // sp0 = denom0 quote, denom1 base. - sp0, err0 := k.RouteCalculateSpotPrice(ctx, poolId, denom0, denom1) + sp0BigDec, err0 := k.RouteCalculateSpotPrice(ctx, poolId, denom0, denom1) // sp1 = denom0 base, denom1 quote. - sp1, err1 := k.RouteCalculateSpotPrice(ctx, poolId, denom1, denom0) + sp1BigDec, err1 := k.RouteCalculateSpotPrice(ctx, poolId, denom1, denom0) + if err0 != nil || err1 != nil { latestErrTime = ctx.BlockTime() // In the event of an error, we just sanity replace empty values with zero values // so that the numbers can be still be calculated within TWAPs over error values // TODO: Should we be using the last spot price? - if (sp0 == osmomath.Dec{}) { - sp0 = osmomath.ZeroDec() + if (sp0BigDec == osmomath.BigDec{}) { + sp0BigDec = osmomath.ZeroBigDec() } - if (sp1 == osmomath.Dec{}) { - sp1 = osmomath.ZeroDec() + if (sp1BigDec == osmomath.BigDec{}) { + sp1BigDec = osmomath.ZeroBigDec() } } - if sp0.GT(types.MaxSpotPrice) { - sp0, latestErrTime = types.MaxSpotPrice, ctx.BlockTime() + if sp0BigDec.GT(types.MaxSpotPriceBigDec) { + sp0BigDec, latestErrTime = types.MaxSpotPriceBigDec, ctx.BlockTime() } - if sp1.GT(types.MaxSpotPrice) { - sp1, latestErrTime = types.MaxSpotPrice, ctx.BlockTime() + if sp1BigDec.GT(types.MaxSpotPriceBigDec) { + sp1BigDec, latestErrTime = types.MaxSpotPriceBigDec, ctx.BlockTime() } - return sp0, sp1, latestErrTime + + // Note: truncation is appropriate since we don not support greater precision by design. + // If support for pools with outlier spot prices is needed in the future, then this should be revisited. + // if !sp0BigDec.IsNil() { + // sp0 = sp0BigDec.Dec() + // } + + // if !sp1BigDec.IsNil() { + // sp1 = sp1BigDec.Dec() + // } + + return sp0BigDec.Dec(), sp1BigDec.Dec(), latestErrTime } // mustTrackCreatedPool is a wrapper around afterCreatePool that panics on error. diff --git a/x/twap/types/expected_interfaces.go b/x/twap/types/expected_interfaces.go index fd02f632770..a767b8ee94b 100644 --- a/x/twap/types/expected_interfaces.go +++ b/x/twap/types/expected_interfaces.go @@ -18,5 +18,5 @@ type PoolManagerInterface interface { poolID uint64, quoteAssetDenom string, baseAssetDenom string, - ) (price osmomath.Dec, err error) + ) (price osmomath.BigDec, err error) } diff --git a/x/twap/types/twapmock/amminterface.go b/x/twap/types/twapmock/amminterface.go index 508db6204dd..7f6fa915a22 100644 --- a/x/twap/types/twapmock/amminterface.go +++ b/x/twap/types/twapmock/amminterface.go @@ -74,10 +74,15 @@ func (p *ProgrammedPoolManagerInterface) RouteCalculateSpotPrice(ctx sdk.Context poolId uint64, quoteDenom, baseDenom string, -) (price osmomath.Dec, err error) { +) (price osmomath.BigDec, err error) { input := SpotPriceInput{poolId, baseDenom, quoteDenom} if res, ok := p.programmedSpotPrice[input]; ok { - return res.Sp, res.Err + + if (res.Sp == osmomath.Dec{}) { + return osmomath.BigDec{}, res.Err + } + + return osmomath.BigDecFromDec(res.Sp), res.Err } return p.underlyingKeeper.RouteCalculateSpotPrice(ctx, poolId, quoteDenom, baseDenom) } diff --git a/x/twap/types/utils.go b/x/twap/types/utils.go index cd112f2a8f9..dbc7ecd3029 100644 --- a/x/twap/types/utils.go +++ b/x/twap/types/utils.go @@ -8,7 +8,10 @@ import ( "github.com/osmosis-labs/osmosis/osmomath" ) -var MaxSpotPrice = osmomath.NewDec(2).Power(128).Sub(osmomath.OneDec()) +var ( + MaxSpotPrice = osmomath.NewDec(2).Power(128).Sub(osmomath.OneDec()) + MaxSpotPriceBigDec = osmomath.BigDecFromDec(MaxSpotPrice) +) // GetAllUniqueDenomPairs returns all unique pairs of denoms, where for every pair // (X, Y), X < Y. diff --git a/x/txfees/keeper/feetokens.go b/x/txfees/keeper/feetokens.go index f4eea8230fb..06136f2bdde 100644 --- a/x/txfees/keeper/feetokens.go +++ b/x/txfees/keeper/feetokens.go @@ -32,27 +32,30 @@ func (k Keeper) ConvertToBaseToken(ctx sdk.Context, inputFee sdk.Coin) (sdk.Coin return sdk.Coin{}, err } - return sdk.NewCoin(baseDenom, spotPrice.MulInt(inputFee.Amount).RoundInt()), nil + // Note: spotPrice truncation is done here for maintaining state-compatibility with v19.x + // It should be changed to support full spot price precision before + // https://github.com/osmosis-labs/osmosis/issues/6064 is complete + return sdk.NewCoin(baseDenom, spotPrice.Dec().MulInt(inputFee.Amount).RoundInt()), nil } // CalcFeeSpotPrice converts the provided tx fees into their equivalent value in the base denomination. // Spot Price Calculation: spotPrice / (1 - spreadFactor), // where spotPrice is defined as: // (tokenBalanceIn / tokenWeightIn) / (tokenBalanceOut / tokenWeightOut) -func (k Keeper) CalcFeeSpotPrice(ctx sdk.Context, inputDenom string) (osmomath.Dec, error) { +func (k Keeper) CalcFeeSpotPrice(ctx sdk.Context, inputDenom string) (osmomath.BigDec, error) { baseDenom, err := k.GetBaseDenom(ctx) if err != nil { - return osmomath.Dec{}, err + return osmomath.BigDec{}, err } feeToken, err := k.GetFeeToken(ctx, inputDenom) if err != nil { - return osmomath.Dec{}, err + return osmomath.BigDec{}, err } spotPrice, err := k.spotPriceCalculator.CalculateSpotPrice(ctx, feeToken.PoolID, baseDenom, feeToken.Denom) if err != nil { - return osmomath.Dec{}, err + return osmomath.BigDec{}, err } return spotPrice, nil } diff --git a/x/txfees/keeper/grpc_query.go b/x/txfees/keeper/grpc_query.go index a415be99425..89a543bf06d 100644 --- a/x/txfees/keeper/grpc_query.go +++ b/x/txfees/keeper/grpc_query.go @@ -51,7 +51,8 @@ func (q Querier) DenomSpotPrice(ctx context.Context, req *types.QueryDenomSpotPr return nil, err } - return &types.QueryDenomSpotPriceResponse{PoolID: feeToken.PoolID, SpotPrice: spotPrice}, nil + // TODO: remove truncation before https://github.com/osmosis-labs/osmosis/issues/6064 is fully complete. + return &types.QueryDenomSpotPriceResponse{PoolID: feeToken.PoolID, SpotPrice: spotPrice.Dec()}, nil } func (q Querier) DenomPoolId(ctx context.Context, req *types.QueryDenomPoolIdRequest) (*types.QueryDenomPoolIdResponse, error) { diff --git a/x/txfees/types/expected_keepers.go b/x/txfees/types/expected_keepers.go index cf9858b0ca5..adf9579fdb1 100644 --- a/x/txfees/types/expected_keepers.go +++ b/x/txfees/types/expected_keepers.go @@ -11,7 +11,7 @@ import ( // SpotPriceCalculator defines the contract that must be fulfilled by a spot price calculator // The x/gamm keeper is expected to satisfy this interface. type SpotPriceCalculator interface { - CalculateSpotPrice(ctx sdk.Context, poolId uint64, quoteDenom, baseDenom string) (osmomath.Dec, error) + CalculateSpotPrice(ctx sdk.Context, poolId uint64, quoteDenom, baseDenom string) (osmomath.BigDec, error) } // PoolManager defines the contract needed for swap related APIs. From a38a388431a5e824f17fa54fc3d6d12872d6c4f0 Mon Sep 17 00:00:00 2001 From: roman Date: Thu, 21 Sep 2023 15:35:10 -0400 Subject: [PATCH 02/11] updates --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 258f0b11965..c2e7179ca12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#6279](https://github.com/osmosis-labs/osmosis/pull/6279) fix prop-597 introduced issue * [#6282](https://github.com/osmosis-labs/osmosis/pull/6282) Fix CreateCanonicalConcentratedLiquidityPoolAndMigrationLink overriding migration records +### API Breaks + +* [#6487](https://github.com/osmosis-labs/osmosis/pull/6487) make PoolModuleI CalculateSpotPrice API return BigDec + ## v19.1.0 ### Features From 785834bd8349b28e6cb902e94575089008538681 Mon Sep 17 00:00:00 2001 From: roman Date: Thu, 21 Sep 2023 15:38:54 -0400 Subject: [PATCH 03/11] clean up --- x/twap/logic.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/x/twap/logic.go b/x/twap/logic.go index 6fb294a2bab..0cbef84e63d 100644 --- a/x/twap/logic.go +++ b/x/twap/logic.go @@ -70,16 +70,6 @@ func getSpotPrices( sp1BigDec, latestErrTime = types.MaxSpotPriceBigDec, ctx.BlockTime() } - // Note: truncation is appropriate since we don not support greater precision by design. - // If support for pools with outlier spot prices is needed in the future, then this should be revisited. - // if !sp0BigDec.IsNil() { - // sp0 = sp0BigDec.Dec() - // } - - // if !sp1BigDec.IsNil() { - // sp1 = sp1BigDec.Dec() - // } - return sp0BigDec.Dec(), sp1BigDec.Dec(), latestErrTime } From 6ad4aff9bc16995f83323d30169678414474aaf7 Mon Sep 17 00:00:00 2001 From: roman Date: Thu, 21 Sep 2023 15:39:20 -0400 Subject: [PATCH 04/11] updates --- x/twap/logic.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/x/twap/logic.go b/x/twap/logic.go index 0cbef84e63d..d00b55df794 100644 --- a/x/twap/logic.go +++ b/x/twap/logic.go @@ -70,6 +70,8 @@ func getSpotPrices( sp1BigDec, latestErrTime = types.MaxSpotPriceBigDec, ctx.BlockTime() } + // Note: truncation is appropriate since we don not support greater precision by design. + // If support for pools with outlier spot prices is needed in the future, then this should be revisited. return sp0BigDec.Dec(), sp1BigDec.Dec(), latestErrTime } From 27c2635ccc71c93f17384fe575478947a3652f4b Mon Sep 17 00:00:00 2001 From: roman Date: Thu, 21 Sep 2023 15:48:30 -0400 Subject: [PATCH 05/11] updates --- x/twap/types/twapmock/amminterface.go | 1 - 1 file changed, 1 deletion(-) diff --git a/x/twap/types/twapmock/amminterface.go b/x/twap/types/twapmock/amminterface.go index 7f6fa915a22..3ab1a79c32f 100644 --- a/x/twap/types/twapmock/amminterface.go +++ b/x/twap/types/twapmock/amminterface.go @@ -77,7 +77,6 @@ func (p *ProgrammedPoolManagerInterface) RouteCalculateSpotPrice(ctx sdk.Context ) (price osmomath.BigDec, err error) { input := SpotPriceInput{poolId, baseDenom, quoteDenom} if res, ok := p.programmedSpotPrice[input]; ok { - if (res.Sp == osmomath.Dec{}) { return osmomath.BigDec{}, res.Err } From db82881666e09800e5c92a81f0db932caeb05d5c Mon Sep 17 00:00:00 2001 From: roman Date: Thu, 21 Sep 2023 17:34:48 -0400 Subject: [PATCH 06/11] feat(poolmaanger): v2 SpotPrice query with 36 decimals --- cmd/querygen/main.go | 12 +- cmd/querygen/templates/grpcTemplate.go | 7 +- cmd/querygen/templates/grpc_template.tmpl | 9 +- proto/osmosis/poolmanager/v2/query.proto | 44 ++ proto/osmosis/poolmanager/v2/query.yml | 10 + .../client/grpc/grpc_query.go | 1 + x/cosmwasmpool/client/grpc/grpc_query.go | 1 + x/downtime-detector/client/grpc/grpc_query.go | 1 + x/ibc-rate-limit/client/grpc/grpc_query.go | 1 + x/poolmanager/client/cli/query.go | 12 + x/poolmanager/client/grpc/grpc_query.go | 1 + x/poolmanager/client/grpcv2/grpc_query.go | 33 + x/poolmanager/client/query_proto_wrap.go | 24 +- x/poolmanager/client/queryprotov2/query.pb.go | 694 ++++++++++++++++++ .../client/queryprotov2/query.pb.gw.go | 207 ++++++ x/poolmanager/module/module.go | 6 + x/twap/client/grpc/grpc_query.go | 1 + x/valset-pref/client/grpc/grpc_query.go | 1 + 18 files changed, 1055 insertions(+), 10 deletions(-) create mode 100644 proto/osmosis/poolmanager/v2/query.proto create mode 100644 proto/osmosis/poolmanager/v2/query.yml create mode 100644 x/poolmanager/client/grpcv2/grpc_query.go create mode 100644 x/poolmanager/client/queryprotov2/query.pb.go create mode 100644 x/poolmanager/client/queryprotov2/query.pb.gw.go diff --git a/cmd/querygen/main.go b/cmd/querygen/main.go index ad10942a965..95b3784f73e 100644 --- a/cmd/querygen/main.go +++ b/cmd/querygen/main.go @@ -74,16 +74,24 @@ func codegenQueryYml(filepath string) error { func codegenGrpcPackage(queryYml templates.QueryYml) error { grpcTemplateData := templates.GrpcTemplateFromQueryYml(queryYml) + // If proto path contains v2 then add folder and template + // suffix to properly package the files. + grpcTemplateData.VersionSuffix = "" + if strings.Contains(grpcTemplateData.ProtoPath, "v2") { + fmt.Println(grpcTemplateData.ProtoPath) + grpcTemplateData.VersionSuffix = "v2" + } + // create directory fsClientPath := templates.ParseFilePathFromImportPath(grpcTemplateData.ClientPath) - if err := os.MkdirAll(fsClientPath+"/grpc", os.ModePerm); err != nil { + if err := os.MkdirAll(fsClientPath+"/grpc"+grpcTemplateData.VersionSuffix, os.ModePerm); err != nil { // ignore directory already exists error if !errors.Is(err, os.ErrExist) { return err } } // generate file - f, err := os.Create(fsClientPath + "/grpc/grpc_query.go") + f, err := os.Create(fsClientPath + "/grpc" + grpcTemplateData.VersionSuffix + "/grpc_query.go") if err != nil { return err } diff --git a/cmd/querygen/templates/grpcTemplate.go b/cmd/querygen/templates/grpcTemplate.go index a0c129f7c0a..47f313f251a 100644 --- a/cmd/querygen/templates/grpcTemplate.go +++ b/cmd/querygen/templates/grpcTemplate.go @@ -3,9 +3,10 @@ package templates import "sort" type GrpcTemplate struct { - ProtoPath string - ClientPath string - Queries []GrpcQuery + ProtoPath string + ClientPath string + Queries []GrpcQuery + VersionSuffix string } type GrpcQuery struct { diff --git a/cmd/querygen/templates/grpc_template.tmpl b/cmd/querygen/templates/grpc_template.tmpl index 0b63645e478..f1e94f4fcc8 100644 --- a/cmd/querygen/templates/grpc_template.tmpl +++ b/cmd/querygen/templates/grpc_template.tmpl @@ -2,6 +2,7 @@ package grpc // THIS FILE IS GENERATED CODE, DO NOT EDIT // SOURCE AT `{{.ProtoPath}}` +{{ $version := .VersionSuffix }} import ( context "context" @@ -11,20 +12,20 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "{{.ClientPath}}" - "{{.ClientPath}}/queryproto" + "{{.ClientPath}}/queryproto{{$version}}" ) type Querier struct { Q client.Querier } -var _ queryproto.QueryServer = Querier{} +var _ queryproto{{$version}}.QueryServer = Querier{} {{range .Queries -}} func (q Querier) {{.QueryName}}(grpcCtx context.Context, - req *queryproto.{{.QueryName}}Request, -) ({{ if .Response }}{{.Response}}{{else}}*queryproto.{{.QueryName}}Response{{end}}, error) { + req *queryproto{{$version}}.{{.QueryName}}Request, +) ({{ if .Response }}{{.Response}}{{else}}*queryproto{{$version}}.{{.QueryName}}Response{{end}}, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } diff --git a/proto/osmosis/poolmanager/v2/query.proto b/proto/osmosis/poolmanager/v2/query.proto new file mode 100644 index 00000000000..f7b4ba0e299 --- /dev/null +++ b/proto/osmosis/poolmanager/v2/query.proto @@ -0,0 +1,44 @@ +syntax = "proto3"; +package osmosis.poolmanager.v2; + +import "gogoproto/gogo.proto"; + +import "google/api/annotations.proto"; +import "google/protobuf/any.proto"; +import "cosmos_proto/cosmos.proto"; +import "google/protobuf/timestamp.proto"; + +option go_package = "github.com/osmosis-labs/osmosis/v19/x/poolmanager/client/queryprotov2"; + +service Query { + // SpotPrice defines a gRPC query handler that returns the spot price given + // a base denomination and a quote denomination. + // The returned spot price has 36 decimal places. However, some of + // modules perform sig fig rounding so most of the rightmost decimals can be + // zeroes. + rpc SpotPrice(SpotPriceRequest) returns (SpotPriceResponse) { + option (google.api.http).get = + "/osmosis/poolmanager/v2/pools/{pool_id}/prices"; + } +} + +// SpotPriceRequest defines the gRPC request structure for a SpotPrice +// query. +message SpotPriceRequest { + uint64 pool_id = 1 [ (gogoproto.moretags) = "yaml:\"pool_id\"" ]; + string base_asset_denom = 2 + [ (gogoproto.moretags) = "yaml:\"base_asset_denom\"" ]; + string quote_asset_denom = 3 + [ (gogoproto.moretags) = "yaml:\"quote_asset_denom\"" ]; +} + +// SpotPriceResponse defines the gRPC response structure for a SpotPrice +// query. +message SpotPriceResponse { + // String of the BigDec. Ex) 10.203uatom + string spot_price = 1 [ + (gogoproto.customtype) = "github.com/osmosis-labs/osmosis/osmomath.BigDec", + (gogoproto.moretags) = "yaml:\"spot_price\"", + (gogoproto.nullable) = false + ]; +} diff --git a/proto/osmosis/poolmanager/v2/query.yml b/proto/osmosis/poolmanager/v2/query.yml new file mode 100644 index 00000000000..ad583478281 --- /dev/null +++ b/proto/osmosis/poolmanager/v2/query.yml @@ -0,0 +1,10 @@ +keeper: + path: "github.com/osmosis-labs/osmosis/v19/x/poolmanager" + struct: "Keeper" +client_path: "github.com/osmosis-labs/osmosis/v19/x/poolmanager/client" +queries: + SpotPrice: + proto_wrapper: + query_func: "k.RouteCalculateSpotPrice" + cli: + cmd: "SpotPrice" diff --git a/x/concentrated-liquidity/client/grpc/grpc_query.go b/x/concentrated-liquidity/client/grpc/grpc_query.go index 0b3fd0fc4b5..79a7eb24546 100644 --- a/x/concentrated-liquidity/client/grpc/grpc_query.go +++ b/x/concentrated-liquidity/client/grpc/grpc_query.go @@ -3,6 +3,7 @@ package grpc // THIS FILE IS GENERATED CODE, DO NOT EDIT // SOURCE AT `proto/osmosis/concentrated-liquidity/query.yml` + import ( context "context" diff --git a/x/cosmwasmpool/client/grpc/grpc_query.go b/x/cosmwasmpool/client/grpc/grpc_query.go index b45bce290fd..22d7df261a3 100644 --- a/x/cosmwasmpool/client/grpc/grpc_query.go +++ b/x/cosmwasmpool/client/grpc/grpc_query.go @@ -3,6 +3,7 @@ package grpc // THIS FILE IS GENERATED CODE, DO NOT EDIT // SOURCE AT `proto/osmosis/cosmwasmpool/v1beta1/query.yml` + import ( context "context" diff --git a/x/downtime-detector/client/grpc/grpc_query.go b/x/downtime-detector/client/grpc/grpc_query.go index 18cba74d32f..5caeb089411 100644 --- a/x/downtime-detector/client/grpc/grpc_query.go +++ b/x/downtime-detector/client/grpc/grpc_query.go @@ -3,6 +3,7 @@ package grpc // THIS FILE IS GENERATED CODE, DO NOT EDIT // SOURCE AT `proto/osmosis/downtime-detector/v1beta1/query.yml` + import ( context "context" diff --git a/x/ibc-rate-limit/client/grpc/grpc_query.go b/x/ibc-rate-limit/client/grpc/grpc_query.go index 56d22c9989e..d208e355043 100644 --- a/x/ibc-rate-limit/client/grpc/grpc_query.go +++ b/x/ibc-rate-limit/client/grpc/grpc_query.go @@ -3,6 +3,7 @@ package grpc // THIS FILE IS GENERATED CODE, DO NOT EDIT // SOURCE AT `proto/osmosis/ibc-rate-limit/v1beta1/query.yml` + import ( context "context" diff --git a/x/poolmanager/client/cli/query.go b/x/poolmanager/client/cli/query.go index f0fea8d598f..b7e4a741f85 100644 --- a/x/poolmanager/client/cli/query.go +++ b/x/poolmanager/client/cli/query.go @@ -9,6 +9,7 @@ import ( "github.com/osmosis-labs/osmosis/osmoutils/osmocli" "github.com/osmosis-labs/osmosis/v19/x/poolmanager/client/queryproto" + "github.com/osmosis-labs/osmosis/v19/x/poolmanager/client/queryprotov2" "github.com/osmosis-labs/osmosis/v19/x/poolmanager/types" ) @@ -29,6 +30,7 @@ func GetQueryCmd() *cobra.Command { osmocli.AddQueryCmd(cmd, queryproto.NewQueryClient, GetCmdTotalPoolLiquidity) osmocli.AddQueryCmd(cmd, queryproto.NewQueryClient, GetCmdAllPools) osmocli.AddQueryCmd(cmd, queryproto.NewQueryClient, GetCmdPool) + osmocli.AddQueryCmd(cmd, queryprotov2.NewQueryClient, GetCmdSpotPriceV2) cmd.AddCommand( osmocli.GetParams[*queryproto.ParamsRequest]( types.ModuleName, queryproto.NewQueryClient), @@ -103,6 +105,16 @@ func GetCmdSpotPrice() (*osmocli.QueryDescriptor, *queryproto.SpotPriceRequest) }, &queryproto.SpotPriceRequest{} } +func GetCmdSpotPriceV2() (*osmocli.QueryDescriptor, *queryprotov2.SpotPriceRequest) { + return &osmocli.QueryDescriptor{ + Use: "spot-price-v2", + Short: "Query spot-price with 36 decimals", + Long: `Query spot-price with 36 decimals +{{.CommandPrefix}} spot-price-v2 1 uosmo ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2 +`, + }, &queryprotov2.SpotPriceRequest{} +} + func EstimateSwapExactAmountInParseArgs(args []string, fs *flag.FlagSet) (proto.Message, error) { poolID, err := strconv.Atoi(args[0]) if err != nil { diff --git a/x/poolmanager/client/grpc/grpc_query.go b/x/poolmanager/client/grpc/grpc_query.go index cb4842b39bc..87158fb73a2 100644 --- a/x/poolmanager/client/grpc/grpc_query.go +++ b/x/poolmanager/client/grpc/grpc_query.go @@ -3,6 +3,7 @@ package grpc // THIS FILE IS GENERATED CODE, DO NOT EDIT // SOURCE AT `proto/osmosis/poolmanager/v1beta1/query.yml` + import ( context "context" diff --git a/x/poolmanager/client/grpcv2/grpc_query.go b/x/poolmanager/client/grpcv2/grpc_query.go new file mode 100644 index 00000000000..4ad6fb6c7ec --- /dev/null +++ b/x/poolmanager/client/grpcv2/grpc_query.go @@ -0,0 +1,33 @@ +package grpc + +// THIS FILE IS GENERATED CODE, DO NOT EDIT +// SOURCE AT `proto/osmosis/poolmanager/v2/query.yml` + + +import ( + context "context" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/osmosis-labs/osmosis/v19/x/poolmanager/client" + "github.com/osmosis-labs/osmosis/v19/x/poolmanager/client/queryprotov2" +) + +type Querier struct { + Q client.Querier +} + +var _ queryprotov2.QueryServer = Querier{} + +func (q Querier) SpotPrice(grpcCtx context.Context, + req *queryprotov2.SpotPriceRequest, +) (*queryprotov2.SpotPriceResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "empty request") + } + ctx := sdk.UnwrapSDKContext(grpcCtx) + return q.Q.SpotPriceV2(ctx, *req) +} + diff --git a/x/poolmanager/client/query_proto_wrap.go b/x/poolmanager/client/query_proto_wrap.go index ee3970c8415..b50a7f6f9d6 100644 --- a/x/poolmanager/client/query_proto_wrap.go +++ b/x/poolmanager/client/query_proto_wrap.go @@ -9,6 +9,7 @@ import ( "github.com/osmosis-labs/osmosis/v19/x/poolmanager" "github.com/osmosis-labs/osmosis/v19/x/poolmanager/client/queryproto" + "github.com/osmosis-labs/osmosis/v19/x/poolmanager/client/queryprotov2" "github.com/osmosis-labs/osmosis/v19/x/poolmanager/types" ) @@ -203,7 +204,7 @@ func (q Querier) AllPools(ctx sdk.Context, req queryproto.AllPoolsRequest) (*que }, nil } -// SpotPrice returns the spot price of the pool with the given quote and base asset denoms. +// SpotPrice returns the spot price of the pool with the given quote and base asset denoms. 18 decimals. func (q Querier) SpotPrice(ctx sdk.Context, req queryproto.SpotPriceRequest) (*queryproto.SpotPriceResponse, error) { if req.BaseAssetDenom == "" { return nil, status.Error(codes.InvalidArgument, "invalid base asset denom") @@ -225,6 +226,27 @@ func (q Querier) SpotPrice(ctx sdk.Context, req queryproto.SpotPriceRequest) (*q }, err } +// SpotPriceV2 returns the spot price of the pool with the given quote and base asset denoms. 36 decimals. +func (q Querier) SpotPriceV2(ctx sdk.Context, req queryprotov2.SpotPriceRequest) (*queryprotov2.SpotPriceResponse, error) { + if req.BaseAssetDenom == "" { + return nil, status.Error(codes.InvalidArgument, "invalid base asset denom") + } + + if req.QuoteAssetDenom == "" { + return nil, status.Error(codes.InvalidArgument, "invalid quote asset denom") + } + + sp, err := q.K.RouteCalculateSpotPrice(ctx, req.PoolId, req.QuoteAssetDenom, req.BaseAssetDenom) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return &queryprotov2.SpotPriceResponse{ + // Note: that this is a BigDec yielding 36 decimals. + SpotPrice: sp, + }, err +} + // TotalPoolLiquidity returns the total liquidity of the pool. func (q Querier) TotalPoolLiquidity(ctx sdk.Context, req queryproto.TotalPoolLiquidityRequest) (*queryproto.TotalPoolLiquidityResponse, error) { if req.PoolId == 0 { diff --git a/x/poolmanager/client/queryprotov2/query.pb.go b/x/poolmanager/client/queryprotov2/query.pb.go new file mode 100644 index 00000000000..7cf27174531 --- /dev/null +++ b/x/poolmanager/client/queryprotov2/query.pb.go @@ -0,0 +1,694 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: osmosis/poolmanager/v2/query.proto + +package queryprotov2 + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/cosmos-sdk/codec/types" + _ "github.com/gogo/protobuf/gogoproto" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + _ "github.com/gogo/protobuf/types" + github_com_osmosis_labs_osmosis_osmomath "github.com/osmosis-labs/osmosis/osmomath" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// SpotPriceRequest defines the gRPC request structure for a SpotPrice +// query. +type SpotPriceRequest struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty" yaml:"pool_id"` + BaseAssetDenom string `protobuf:"bytes,2,opt,name=base_asset_denom,json=baseAssetDenom,proto3" json:"base_asset_denom,omitempty" yaml:"base_asset_denom"` + QuoteAssetDenom string `protobuf:"bytes,3,opt,name=quote_asset_denom,json=quoteAssetDenom,proto3" json:"quote_asset_denom,omitempty" yaml:"quote_asset_denom"` +} + +func (m *SpotPriceRequest) Reset() { *m = SpotPriceRequest{} } +func (m *SpotPriceRequest) String() string { return proto.CompactTextString(m) } +func (*SpotPriceRequest) ProtoMessage() {} +func (*SpotPriceRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_eb2850debe8fb398, []int{0} +} +func (m *SpotPriceRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SpotPriceRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SpotPriceRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *SpotPriceRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_SpotPriceRequest.Merge(m, src) +} +func (m *SpotPriceRequest) XXX_Size() int { + return m.Size() +} +func (m *SpotPriceRequest) XXX_DiscardUnknown() { + xxx_messageInfo_SpotPriceRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_SpotPriceRequest proto.InternalMessageInfo + +func (m *SpotPriceRequest) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *SpotPriceRequest) GetBaseAssetDenom() string { + if m != nil { + return m.BaseAssetDenom + } + return "" +} + +func (m *SpotPriceRequest) GetQuoteAssetDenom() string { + if m != nil { + return m.QuoteAssetDenom + } + return "" +} + +// SpotPriceResponse defines the gRPC response structure for a SpotPrice +// query. +type SpotPriceResponse struct { + // String of the BigDec. Ex) 10.203uatom + SpotPrice github_com_osmosis_labs_osmosis_osmomath.BigDec `protobuf:"bytes,1,opt,name=spot_price,json=spotPrice,proto3,customtype=github.com/osmosis-labs/osmosis/osmomath.BigDec" json:"spot_price" yaml:"spot_price"` +} + +func (m *SpotPriceResponse) Reset() { *m = SpotPriceResponse{} } +func (m *SpotPriceResponse) String() string { return proto.CompactTextString(m) } +func (*SpotPriceResponse) ProtoMessage() {} +func (*SpotPriceResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_eb2850debe8fb398, []int{1} +} +func (m *SpotPriceResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SpotPriceResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SpotPriceResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *SpotPriceResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_SpotPriceResponse.Merge(m, src) +} +func (m *SpotPriceResponse) XXX_Size() int { + return m.Size() +} +func (m *SpotPriceResponse) XXX_DiscardUnknown() { + xxx_messageInfo_SpotPriceResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_SpotPriceResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*SpotPriceRequest)(nil), "osmosis.poolmanager.v2.SpotPriceRequest") + proto.RegisterType((*SpotPriceResponse)(nil), "osmosis.poolmanager.v2.SpotPriceResponse") +} + +func init() { + proto.RegisterFile("osmosis/poolmanager/v2/query.proto", fileDescriptor_eb2850debe8fb398) +} + +var fileDescriptor_eb2850debe8fb398 = []byte{ + // 468 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0x41, 0x8b, 0xd3, 0x40, + 0x14, 0xee, 0xac, 0xba, 0xd2, 0x39, 0xac, 0xdb, 0x41, 0xb4, 0xd6, 0x25, 0x59, 0xe6, 0x54, 0x11, + 0x33, 0x5a, 0x41, 0xd0, 0x9b, 0x65, 0x17, 0x14, 0x3c, 0x68, 0xbc, 0x79, 0x09, 0x93, 0x74, 0xcc, + 0x0e, 0x26, 0x79, 0x69, 0x67, 0x52, 0x2c, 0x22, 0x88, 0xbf, 0x40, 0xf0, 0xe2, 0xd9, 0x5f, 0xb3, + 0xc7, 0x82, 0x17, 0xf1, 0x10, 0xa4, 0xf5, 0x17, 0xf4, 0x17, 0xc8, 0xcc, 0xa4, 0xee, 0x6e, 0x55, + 0xf4, 0x94, 0xf7, 0xde, 0xf7, 0xcd, 0xf7, 0xde, 0xcb, 0xfb, 0x30, 0x05, 0x95, 0x83, 0x92, 0x8a, + 0x95, 0x00, 0x59, 0xce, 0x0b, 0x9e, 0x8a, 0x09, 0x9b, 0x0e, 0xd8, 0xb8, 0x12, 0x93, 0x59, 0x50, + 0x4e, 0x40, 0x03, 0xb9, 0xd2, 0x70, 0x82, 0x53, 0x9c, 0x60, 0x3a, 0xe8, 0x5d, 0x4e, 0x21, 0x05, + 0x4b, 0x61, 0x26, 0x72, 0xec, 0xde, 0x5e, 0x0a, 0x90, 0x66, 0x82, 0xf1, 0x52, 0x32, 0x5e, 0x14, + 0xa0, 0xb9, 0x96, 0x50, 0xa8, 0x06, 0xbd, 0xd6, 0xa0, 0x36, 0x8b, 0xab, 0x97, 0x8c, 0x17, 0xb3, + 0x35, 0x94, 0xd8, 0x3e, 0x91, 0x53, 0x74, 0x49, 0x03, 0xf9, 0x9b, 0xaf, 0xb4, 0xcc, 0x85, 0xd2, + 0x3c, 0x2f, 0x1d, 0x81, 0xce, 0x11, 0xde, 0x7d, 0x5e, 0x82, 0x7e, 0x3a, 0x91, 0x89, 0x08, 0xc5, + 0xb8, 0x12, 0x4a, 0x93, 0x9b, 0xf8, 0xa2, 0x99, 0x38, 0x92, 0xa3, 0x2e, 0xda, 0x47, 0xfd, 0xf3, + 0x43, 0xb2, 0xaa, 0xfd, 0x9d, 0x19, 0xcf, 0xb3, 0x07, 0xb4, 0x01, 0x68, 0xb8, 0x6d, 0xa2, 0xc7, + 0x23, 0x72, 0x88, 0x77, 0x63, 0xae, 0x44, 0xc4, 0x95, 0x12, 0x3a, 0x1a, 0x89, 0x02, 0xf2, 0xee, + 0xd6, 0x3e, 0xea, 0xb7, 0x87, 0xd7, 0x57, 0xb5, 0x7f, 0xd5, 0xbd, 0xda, 0x64, 0xd0, 0x70, 0xc7, + 0x94, 0x1e, 0x9a, 0xca, 0x81, 0x29, 0x90, 0x47, 0xb8, 0x33, 0xae, 0x40, 0x9f, 0xd5, 0x39, 0x67, + 0x75, 0xf6, 0x56, 0xb5, 0xdf, 0x75, 0x3a, 0xbf, 0x51, 0x68, 0x78, 0xc9, 0xd6, 0x4e, 0x94, 0xe8, + 0x3b, 0x84, 0x3b, 0xa7, 0x56, 0x52, 0x25, 0x14, 0x4a, 0x90, 0x57, 0x18, 0xab, 0x12, 0x74, 0x54, + 0x9a, 0xaa, 0x5d, 0xab, 0x3d, 0x7c, 0x72, 0x5c, 0xfb, 0xad, 0x6f, 0xb5, 0xcf, 0x52, 0xa9, 0x8f, + 0xaa, 0x38, 0x48, 0x20, 0x67, 0xcd, 0xc9, 0x6e, 0x65, 0x3c, 0x56, 0xeb, 0xc4, 0x7e, 0x73, 0xae, + 0x8f, 0x82, 0xa1, 0x4c, 0x0f, 0x44, 0xb2, 0xaa, 0xfd, 0x8e, 0x9b, 0xe7, 0x44, 0x92, 0x86, 0x6d, + 0xb5, 0x6e, 0x3a, 0xf8, 0x8c, 0xf0, 0x85, 0x67, 0xc6, 0x08, 0xe4, 0x13, 0xc2, 0xed, 0x5f, 0xc3, + 0x90, 0x7e, 0xf0, 0x67, 0x47, 0x04, 0x9b, 0x27, 0xe8, 0xdd, 0xf8, 0x0f, 0xa6, 0xdb, 0x8c, 0xde, + 0x7b, 0xff, 0xe5, 0xc7, 0xc7, 0xad, 0xdb, 0x24, 0x60, 0x7f, 0xb1, 0xa4, 0x49, 0x15, 0x7b, 0xd3, + 0x5c, 0xee, 0x2d, 0xb3, 0xf3, 0xaa, 0x61, 0x74, 0xbc, 0xf0, 0xd0, 0x7c, 0xe1, 0xa1, 0xef, 0x0b, + 0x0f, 0x7d, 0x58, 0x7a, 0xad, 0xf9, 0xd2, 0x6b, 0x7d, 0x5d, 0x7a, 0xad, 0x17, 0x87, 0xff, 0xfa, + 0x1f, 0xd3, 0x3b, 0xf7, 0xd9, 0xeb, 0x33, 0x6d, 0x92, 0x4c, 0x8a, 0x42, 0x3b, 0xf7, 0x5b, 0x67, + 0x4d, 0x07, 0xf1, 0xb6, 0x0d, 0xee, 0xfe, 0x0c, 0x00, 0x00, 0xff, 0xff, 0x84, 0x43, 0x0f, 0x11, + 0x2b, 0x03, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryClient is the client API for Query service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryClient interface { + // SpotPrice defines a gRPC query handler that returns the spot price given + // a base denomination and a quote denomination. + // The returned spot price has 36 decimal places. However, some of + // modules perform sig fig rounding so most of the rightmost decimals can be + // zeroes. + SpotPrice(ctx context.Context, in *SpotPriceRequest, opts ...grpc.CallOption) (*SpotPriceResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) SpotPrice(ctx context.Context, in *SpotPriceRequest, opts ...grpc.CallOption) (*SpotPriceResponse, error) { + out := new(SpotPriceResponse) + err := c.cc.Invoke(ctx, "/osmosis.poolmanager.v2.Query/SpotPrice", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // SpotPrice defines a gRPC query handler that returns the spot price given + // a base denomination and a quote denomination. + // The returned spot price has 36 decimal places. However, some of + // modules perform sig fig rounding so most of the rightmost decimals can be + // zeroes. + SpotPrice(context.Context, *SpotPriceRequest) (*SpotPriceResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) SpotPrice(ctx context.Context, req *SpotPriceRequest) (*SpotPriceResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method SpotPrice not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_SpotPrice_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SpotPriceRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).SpotPrice(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/osmosis.poolmanager.v2.Query/SpotPrice", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).SpotPrice(ctx, req.(*SpotPriceRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "osmosis.poolmanager.v2.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "SpotPrice", + Handler: _Query_SpotPrice_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "osmosis/poolmanager/v2/query.proto", +} + +func (m *SpotPriceRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *SpotPriceRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SpotPriceRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.QuoteAssetDenom) > 0 { + i -= len(m.QuoteAssetDenom) + copy(dAtA[i:], m.QuoteAssetDenom) + i = encodeVarintQuery(dAtA, i, uint64(len(m.QuoteAssetDenom))) + i-- + dAtA[i] = 0x1a + } + if len(m.BaseAssetDenom) > 0 { + i -= len(m.BaseAssetDenom) + copy(dAtA[i:], m.BaseAssetDenom) + i = encodeVarintQuery(dAtA, i, uint64(len(m.BaseAssetDenom))) + i-- + dAtA[i] = 0x12 + } + if m.PoolId != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *SpotPriceResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *SpotPriceResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SpotPriceResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.SpotPrice.Size() + i -= size + if _, err := m.SpotPrice.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *SpotPriceRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovQuery(uint64(m.PoolId)) + } + l = len(m.BaseAssetDenom) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = len(m.QuoteAssetDenom) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *SpotPriceResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.SpotPrice.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *SpotPriceRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: SpotPriceRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SpotPriceRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BaseAssetDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.BaseAssetDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field QuoteAssetDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.QuoteAssetDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *SpotPriceResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: SpotPriceResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SpotPriceResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SpotPrice", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.SpotPrice.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/poolmanager/client/queryprotov2/query.pb.gw.go b/x/poolmanager/client/queryprotov2/query.pb.gw.go new file mode 100644 index 00000000000..0382d52e879 --- /dev/null +++ b/x/poolmanager/client/queryprotov2/query.pb.gw.go @@ -0,0 +1,207 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: osmosis/poolmanager/v2/query.proto + +/* +Package queryprotov2 is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package queryprotov2 + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +var ( + filter_Query_SpotPrice_0 = &utilities.DoubleArray{Encoding: map[string]int{"pool_id": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} +) + +func request_Query_SpotPrice_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq SpotPriceRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["pool_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id") + } + + protoReq.PoolId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_SpotPrice_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.SpotPrice(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_SpotPrice_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq SpotPriceRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["pool_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id") + } + + protoReq.PoolId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_SpotPrice_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.SpotPrice(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_SpotPrice_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_SpotPrice_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_SpotPrice_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_SpotPrice_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_SpotPrice_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_SpotPrice_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_SpotPrice_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 2, 5}, []string{"osmosis", "poolmanager", "v2", "pools", "pool_id", "prices"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_SpotPrice_0 = runtime.ForwardResponseMessage +) diff --git a/x/poolmanager/module/module.go b/x/poolmanager/module/module.go index de231e5e4a8..4302505ff35 100644 --- a/x/poolmanager/module/module.go +++ b/x/poolmanager/module/module.go @@ -21,7 +21,9 @@ import ( pmclient "github.com/osmosis-labs/osmosis/v19/x/poolmanager/client" "github.com/osmosis-labs/osmosis/v19/x/poolmanager/client/cli" "github.com/osmosis-labs/osmosis/v19/x/poolmanager/client/grpc" + grpcv2 "github.com/osmosis-labs/osmosis/v19/x/poolmanager/client/grpcv2" "github.com/osmosis-labs/osmosis/v19/x/poolmanager/client/queryproto" + "github.com/osmosis-labs/osmosis/v19/x/poolmanager/client/queryprotov2" "github.com/osmosis-labs/osmosis/v19/x/poolmanager/types" ) @@ -60,6 +62,9 @@ func (b AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux if err := queryproto.RegisterQueryHandlerClient(context.Background(), mux, queryproto.NewQueryClient(clientCtx)); err != nil { panic(err) } + if err := queryprotov2.RegisterQueryHandlerClient(context.Background(), mux, queryprotov2.NewQueryClient(clientCtx)); err != nil { + panic(err) + } } func (b AppModuleBasic) GetTxCmd() *cobra.Command { @@ -85,6 +90,7 @@ type AppModule struct { func (am AppModule) RegisterServices(cfg module.Configurator) { types.RegisterMsgServer(cfg.MsgServer(), poolmanager.NewMsgServerImpl(&am.k)) queryproto.RegisterQueryServer(cfg.QueryServer(), grpc.Querier{Q: pmclient.NewQuerier(am.k)}) + queryprotov2.RegisterQueryServer(cfg.QueryServer(), grpcv2.Querier{Q: pmclient.NewQuerier(am.k)}) } func NewAppModule(poolmanagerKeeper poolmanager.Keeper, gammKeeper types.PoolModuleI) AppModule { diff --git a/x/twap/client/grpc/grpc_query.go b/x/twap/client/grpc/grpc_query.go index 7dd67e8a897..5d4ac9020c3 100644 --- a/x/twap/client/grpc/grpc_query.go +++ b/x/twap/client/grpc/grpc_query.go @@ -3,6 +3,7 @@ package grpc // THIS FILE IS GENERATED CODE, DO NOT EDIT // SOURCE AT `proto/osmosis/twap/v1beta1/query.yml` + import ( context "context" diff --git a/x/valset-pref/client/grpc/grpc_query.go b/x/valset-pref/client/grpc/grpc_query.go index 93aa3ed639b..8076d89eed3 100644 --- a/x/valset-pref/client/grpc/grpc_query.go +++ b/x/valset-pref/client/grpc/grpc_query.go @@ -3,6 +3,7 @@ package grpc // THIS FILE IS GENERATED CODE, DO NOT EDIT // SOURCE AT `proto/osmosis/valset-pref/v1beta1/query.yml` + import ( context "context" From 18b8168fd4c51096109fe82005a6e5d95491e359 Mon Sep 17 00:00:00 2001 From: roman Date: Thu, 21 Sep 2023 17:36:56 -0400 Subject: [PATCH 07/11] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2e7179ca12..0934e54f16a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#6416](https://github.com/osmosis-labs/osmosis/pull/6416) feat[CL]: add num initialized ticks query * [#6420](https://github.com/osmosis-labs/osmosis/pull/6420) feat[CL]: Creates a governance set whitelist of addresses that can bypass the normal pool creation restrictions on concentrated liquidity pools +* [#6488](https://github.com/osmosis-labs/osmosis/pull/6488) v2 SpotPrice CLI and GRPC query with 36 decimals in poolmanager ### State Breaking From 344c709cbae07b59120171b34febdf17db32b01f Mon Sep 17 00:00:00 2001 From: roman Date: Thu, 21 Sep 2023 17:38:24 -0400 Subject: [PATCH 08/11] clean up --- cmd/querygen/main.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/querygen/main.go b/cmd/querygen/main.go index 95b3784f73e..36adcc694cc 100644 --- a/cmd/querygen/main.go +++ b/cmd/querygen/main.go @@ -12,6 +12,8 @@ import ( "github.com/osmosis-labs/osmosis/v19/cmd/querygen/templates" ) +const V2 = "v2" + var grpcTemplate template.Template func main() { @@ -77,9 +79,9 @@ func codegenGrpcPackage(queryYml templates.QueryYml) error { // If proto path contains v2 then add folder and template // suffix to properly package the files. grpcTemplateData.VersionSuffix = "" - if strings.Contains(grpcTemplateData.ProtoPath, "v2") { + if strings.Contains(grpcTemplateData.ProtoPath, V2) { fmt.Println(grpcTemplateData.ProtoPath) - grpcTemplateData.VersionSuffix = "v2" + grpcTemplateData.VersionSuffix = V2 } // create directory From a01f95a111d4845c11bf0cb695ccfc80ed0aa529 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 21 Sep 2023 21:41:46 +0000 Subject: [PATCH 09/11] Generated protofile changes --- x/poolmanager/client/grpcv2/grpc_query.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/poolmanager/client/grpcv2/grpc_query.go b/x/poolmanager/client/grpcv2/grpc_query.go index 4ad6fb6c7ec..c0fbd1ecb1b 100644 --- a/x/poolmanager/client/grpcv2/grpc_query.go +++ b/x/poolmanager/client/grpcv2/grpc_query.go @@ -28,6 +28,6 @@ func (q Querier) SpotPrice(grpcCtx context.Context, return nil, status.Error(codes.InvalidArgument, "empty request") } ctx := sdk.UnwrapSDKContext(grpcCtx) - return q.Q.SpotPriceV2(ctx, *req) + return q.Q.SpotPrice(ctx, *req) } From a7bd31083053f9777f3cb4d890807fe5b9057110 Mon Sep 17 00:00:00 2001 From: roman Date: Thu, 21 Sep 2023 22:09:50 -0400 Subject: [PATCH 10/11] querygen updates --- cmd/querygen/main.go | 7 +- cmd/querygen/templates/grpc_template.tmpl | 10 +-- proto/osmosis/poolmanager/v2/query.proto | 4 +- .../client/grpc/grpc_query.go | 4 +- x/cosmwasmpool/client/grpc/grpc_query.go | 4 +- x/downtime-detector/client/grpc/grpc_query.go | 4 +- x/ibc-rate-limit/client/grpc/grpc_query.go | 4 +- x/poolmanager/client/grpc/grpc_query.go | 4 +- x/poolmanager/client/grpcv2/grpc_query.go | 10 +-- x/poolmanager/client/query_proto_wrap.go | 12 ++- x/poolmanager/client/queryprotov2/query.pb.go | 88 +++++++++---------- .../client/queryprotov2/query.pb.gw.go | 30 +++---- x/poolmanager/module/module.go | 4 +- x/twap/client/grpc/grpc_query.go | 4 +- x/valset-pref/client/grpc/grpc_query.go | 4 +- 15 files changed, 103 insertions(+), 90 deletions(-) diff --git a/cmd/querygen/main.go b/cmd/querygen/main.go index 36adcc694cc..b4ae604e11b 100644 --- a/cmd/querygen/main.go +++ b/cmd/querygen/main.go @@ -33,7 +33,11 @@ func main() { } func parseTemplates() error { - grpcTemplatePtr, err := template.ParseFiles("cmd/querygen/templates/grpc_template.tmpl") + // Create a function to upper vase the version suffix if it exists. + funcMap := template.FuncMap{ + "ToUpper": strings.ToUpper, + } + grpcTemplatePtr, err := template.New("grpc_template.tmpl").Funcs(funcMap).ParseFiles("cmd/querygen/templates/grpc_template.tmpl") if err != nil { return err } @@ -80,7 +84,6 @@ func codegenGrpcPackage(queryYml templates.QueryYml) error { // suffix to properly package the files. grpcTemplateData.VersionSuffix = "" if strings.Contains(grpcTemplateData.ProtoPath, V2) { - fmt.Println(grpcTemplateData.ProtoPath) grpcTemplateData.VersionSuffix = V2 } diff --git a/cmd/querygen/templates/grpc_template.tmpl b/cmd/querygen/templates/grpc_template.tmpl index f1e94f4fcc8..d70e1f726eb 100644 --- a/cmd/querygen/templates/grpc_template.tmpl +++ b/cmd/querygen/templates/grpc_template.tmpl @@ -1,8 +1,8 @@ -package grpc +{{ $version := .VersionSuffix }} +package grpc{{$version}} // THIS FILE IS GENERATED CODE, DO NOT EDIT // SOURCE AT `{{.ProtoPath}}` -{{ $version := .VersionSuffix }} import ( context "context" @@ -16,21 +16,21 @@ import ( ) type Querier struct { - Q client.Querier + Q client.Querier{{ $version | ToUpper }} } var _ queryproto{{$version}}.QueryServer = Querier{} {{range .Queries -}} -func (q Querier) {{.QueryName}}(grpcCtx context.Context, +func (q Querier) {{.QueryName}}{{ $version | ToUpper }}(grpcCtx context.Context, req *queryproto{{$version}}.{{.QueryName}}Request, ) ({{ if .Response }}{{.Response}}{{else}}*queryproto{{$version}}.{{.QueryName}}Response{{end}}, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } ctx := sdk.UnwrapSDKContext(grpcCtx) - return q.Q.{{.QueryName}}(ctx, *req) + return q.Q.{{.QueryName}}{{ $version | ToUpper }}(ctx, *req) } {{end -}} diff --git a/proto/osmosis/poolmanager/v2/query.proto b/proto/osmosis/poolmanager/v2/query.proto index f7b4ba0e299..aeb3f9fd0e4 100644 --- a/proto/osmosis/poolmanager/v2/query.proto +++ b/proto/osmosis/poolmanager/v2/query.proto @@ -11,12 +11,12 @@ import "google/protobuf/timestamp.proto"; option go_package = "github.com/osmosis-labs/osmosis/v19/x/poolmanager/client/queryprotov2"; service Query { - // SpotPrice defines a gRPC query handler that returns the spot price given + // SpotPriceV2 defines a gRPC query handler that returns the spot price given // a base denomination and a quote denomination. // The returned spot price has 36 decimal places. However, some of // modules perform sig fig rounding so most of the rightmost decimals can be // zeroes. - rpc SpotPrice(SpotPriceRequest) returns (SpotPriceResponse) { + rpc SpotPriceV2(SpotPriceRequest) returns (SpotPriceResponse) { option (google.api.http).get = "/osmosis/poolmanager/v2/pools/{pool_id}/prices"; } diff --git a/x/concentrated-liquidity/client/grpc/grpc_query.go b/x/concentrated-liquidity/client/grpc/grpc_query.go index 79a7eb24546..ee3c0e66361 100644 --- a/x/concentrated-liquidity/client/grpc/grpc_query.go +++ b/x/concentrated-liquidity/client/grpc/grpc_query.go @@ -1,9 +1,9 @@ -package grpc + +package grpc // THIS FILE IS GENERATED CODE, DO NOT EDIT // SOURCE AT `proto/osmosis/concentrated-liquidity/query.yml` - import ( context "context" diff --git a/x/cosmwasmpool/client/grpc/grpc_query.go b/x/cosmwasmpool/client/grpc/grpc_query.go index 22d7df261a3..abd44c6e103 100644 --- a/x/cosmwasmpool/client/grpc/grpc_query.go +++ b/x/cosmwasmpool/client/grpc/grpc_query.go @@ -1,9 +1,9 @@ -package grpc + +package grpc // THIS FILE IS GENERATED CODE, DO NOT EDIT // SOURCE AT `proto/osmosis/cosmwasmpool/v1beta1/query.yml` - import ( context "context" diff --git a/x/downtime-detector/client/grpc/grpc_query.go b/x/downtime-detector/client/grpc/grpc_query.go index 5caeb089411..0c727ace1f1 100644 --- a/x/downtime-detector/client/grpc/grpc_query.go +++ b/x/downtime-detector/client/grpc/grpc_query.go @@ -1,9 +1,9 @@ -package grpc + +package grpc // THIS FILE IS GENERATED CODE, DO NOT EDIT // SOURCE AT `proto/osmosis/downtime-detector/v1beta1/query.yml` - import ( context "context" diff --git a/x/ibc-rate-limit/client/grpc/grpc_query.go b/x/ibc-rate-limit/client/grpc/grpc_query.go index d208e355043..249209cde9e 100644 --- a/x/ibc-rate-limit/client/grpc/grpc_query.go +++ b/x/ibc-rate-limit/client/grpc/grpc_query.go @@ -1,9 +1,9 @@ -package grpc + +package grpc // THIS FILE IS GENERATED CODE, DO NOT EDIT // SOURCE AT `proto/osmosis/ibc-rate-limit/v1beta1/query.yml` - import ( context "context" diff --git a/x/poolmanager/client/grpc/grpc_query.go b/x/poolmanager/client/grpc/grpc_query.go index 87158fb73a2..937127d5c8b 100644 --- a/x/poolmanager/client/grpc/grpc_query.go +++ b/x/poolmanager/client/grpc/grpc_query.go @@ -1,9 +1,9 @@ -package grpc + +package grpc // THIS FILE IS GENERATED CODE, DO NOT EDIT // SOURCE AT `proto/osmosis/poolmanager/v1beta1/query.yml` - import ( context "context" diff --git a/x/poolmanager/client/grpcv2/grpc_query.go b/x/poolmanager/client/grpcv2/grpc_query.go index c0fbd1ecb1b..13d59f759c4 100644 --- a/x/poolmanager/client/grpcv2/grpc_query.go +++ b/x/poolmanager/client/grpcv2/grpc_query.go @@ -1,9 +1,9 @@ -package grpc + +package grpcv2 // THIS FILE IS GENERATED CODE, DO NOT EDIT // SOURCE AT `proto/osmosis/poolmanager/v2/query.yml` - import ( context "context" @@ -16,18 +16,18 @@ import ( ) type Querier struct { - Q client.Querier + Q client.QuerierV2 } var _ queryprotov2.QueryServer = Querier{} -func (q Querier) SpotPrice(grpcCtx context.Context, +func (q Querier) SpotPriceV2(grpcCtx context.Context, req *queryprotov2.SpotPriceRequest, ) (*queryprotov2.SpotPriceResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } ctx := sdk.UnwrapSDKContext(grpcCtx) - return q.Q.SpotPrice(ctx, *req) + return q.Q.SpotPriceV2(ctx, *req) } diff --git a/x/poolmanager/client/query_proto_wrap.go b/x/poolmanager/client/query_proto_wrap.go index b50a7f6f9d6..5c8dd35dda8 100644 --- a/x/poolmanager/client/query_proto_wrap.go +++ b/x/poolmanager/client/query_proto_wrap.go @@ -23,6 +23,16 @@ func NewQuerier(k poolmanager.Keeper) Querier { return Querier{k} } +// QuerierV2 defines a wrapper around the x/poolmanager keeper providing gRPC method +// handlers for v2 queries. +type QuerierV2 struct { + K poolmanager.Keeper +} + +func NewV2Querier(k poolmanager.Keeper) QuerierV2 { + return QuerierV2{K: k} +} + func (q Querier) Params(ctx sdk.Context, req queryproto.ParamsRequest, ) (*queryproto.ParamsResponse, error) { @@ -227,7 +237,7 @@ func (q Querier) SpotPrice(ctx sdk.Context, req queryproto.SpotPriceRequest) (*q } // SpotPriceV2 returns the spot price of the pool with the given quote and base asset denoms. 36 decimals. -func (q Querier) SpotPriceV2(ctx sdk.Context, req queryprotov2.SpotPriceRequest) (*queryprotov2.SpotPriceResponse, error) { +func (q QuerierV2) SpotPriceV2(ctx sdk.Context, req queryprotov2.SpotPriceRequest) (*queryprotov2.SpotPriceResponse, error) { if req.BaseAssetDenom == "" { return nil, status.Error(codes.InvalidArgument, "invalid base asset denom") } diff --git a/x/poolmanager/client/queryprotov2/query.pb.go b/x/poolmanager/client/queryprotov2/query.pb.go index 7cf27174531..12049791d39 100644 --- a/x/poolmanager/client/queryprotov2/query.pb.go +++ b/x/poolmanager/client/queryprotov2/query.pb.go @@ -145,37 +145,37 @@ func init() { } var fileDescriptor_eb2850debe8fb398 = []byte{ - // 468 bytes of a gzipped FileDescriptorProto + // 471 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0x41, 0x8b, 0xd3, 0x40, - 0x14, 0xee, 0xac, 0xba, 0xd2, 0x39, 0xac, 0xdb, 0x41, 0xb4, 0xd6, 0x25, 0x59, 0xe6, 0x54, 0x11, - 0x33, 0x5a, 0x41, 0xd0, 0x9b, 0x65, 0x17, 0x14, 0x3c, 0x68, 0xbc, 0x79, 0x09, 0x93, 0x74, 0xcc, - 0x0e, 0x26, 0x79, 0x69, 0x67, 0x52, 0x2c, 0x22, 0x88, 0xbf, 0x40, 0xf0, 0xe2, 0xd9, 0x5f, 0xb3, - 0xc7, 0x82, 0x17, 0xf1, 0x10, 0xa4, 0xf5, 0x17, 0xf4, 0x17, 0xc8, 0xcc, 0xa4, 0xee, 0x6e, 0x55, - 0xf4, 0x94, 0xf7, 0xde, 0xf7, 0xcd, 0xf7, 0xde, 0xcb, 0xfb, 0x30, 0x05, 0x95, 0x83, 0x92, 0x8a, - 0x95, 0x00, 0x59, 0xce, 0x0b, 0x9e, 0x8a, 0x09, 0x9b, 0x0e, 0xd8, 0xb8, 0x12, 0x93, 0x59, 0x50, - 0x4e, 0x40, 0x03, 0xb9, 0xd2, 0x70, 0x82, 0x53, 0x9c, 0x60, 0x3a, 0xe8, 0x5d, 0x4e, 0x21, 0x05, - 0x4b, 0x61, 0x26, 0x72, 0xec, 0xde, 0x5e, 0x0a, 0x90, 0x66, 0x82, 0xf1, 0x52, 0x32, 0x5e, 0x14, - 0xa0, 0xb9, 0x96, 0x50, 0xa8, 0x06, 0xbd, 0xd6, 0xa0, 0x36, 0x8b, 0xab, 0x97, 0x8c, 0x17, 0xb3, - 0x35, 0x94, 0xd8, 0x3e, 0x91, 0x53, 0x74, 0x49, 0x03, 0xf9, 0x9b, 0xaf, 0xb4, 0xcc, 0x85, 0xd2, - 0x3c, 0x2f, 0x1d, 0x81, 0xce, 0x11, 0xde, 0x7d, 0x5e, 0x82, 0x7e, 0x3a, 0x91, 0x89, 0x08, 0xc5, - 0xb8, 0x12, 0x4a, 0x93, 0x9b, 0xf8, 0xa2, 0x99, 0x38, 0x92, 0xa3, 0x2e, 0xda, 0x47, 0xfd, 0xf3, - 0x43, 0xb2, 0xaa, 0xfd, 0x9d, 0x19, 0xcf, 0xb3, 0x07, 0xb4, 0x01, 0x68, 0xb8, 0x6d, 0xa2, 0xc7, - 0x23, 0x72, 0x88, 0x77, 0x63, 0xae, 0x44, 0xc4, 0x95, 0x12, 0x3a, 0x1a, 0x89, 0x02, 0xf2, 0xee, - 0xd6, 0x3e, 0xea, 0xb7, 0x87, 0xd7, 0x57, 0xb5, 0x7f, 0xd5, 0xbd, 0xda, 0x64, 0xd0, 0x70, 0xc7, - 0x94, 0x1e, 0x9a, 0xca, 0x81, 0x29, 0x90, 0x47, 0xb8, 0x33, 0xae, 0x40, 0x9f, 0xd5, 0x39, 0x67, - 0x75, 0xf6, 0x56, 0xb5, 0xdf, 0x75, 0x3a, 0xbf, 0x51, 0x68, 0x78, 0xc9, 0xd6, 0x4e, 0x94, 0xe8, - 0x3b, 0x84, 0x3b, 0xa7, 0x56, 0x52, 0x25, 0x14, 0x4a, 0x90, 0x57, 0x18, 0xab, 0x12, 0x74, 0x54, - 0x9a, 0xaa, 0x5d, 0xab, 0x3d, 0x7c, 0x72, 0x5c, 0xfb, 0xad, 0x6f, 0xb5, 0xcf, 0x52, 0xa9, 0x8f, - 0xaa, 0x38, 0x48, 0x20, 0x67, 0xcd, 0xc9, 0x6e, 0x65, 0x3c, 0x56, 0xeb, 0xc4, 0x7e, 0x73, 0xae, - 0x8f, 0x82, 0xa1, 0x4c, 0x0f, 0x44, 0xb2, 0xaa, 0xfd, 0x8e, 0x9b, 0xe7, 0x44, 0x92, 0x86, 0x6d, - 0xb5, 0x6e, 0x3a, 0xf8, 0x8c, 0xf0, 0x85, 0x67, 0xc6, 0x08, 0xe4, 0x13, 0xc2, 0xed, 0x5f, 0xc3, - 0x90, 0x7e, 0xf0, 0x67, 0x47, 0x04, 0x9b, 0x27, 0xe8, 0xdd, 0xf8, 0x0f, 0xa6, 0xdb, 0x8c, 0xde, - 0x7b, 0xff, 0xe5, 0xc7, 0xc7, 0xad, 0xdb, 0x24, 0x60, 0x7f, 0xb1, 0xa4, 0x49, 0x15, 0x7b, 0xd3, - 0x5c, 0xee, 0x2d, 0xb3, 0xf3, 0xaa, 0x61, 0x74, 0xbc, 0xf0, 0xd0, 0x7c, 0xe1, 0xa1, 0xef, 0x0b, - 0x0f, 0x7d, 0x58, 0x7a, 0xad, 0xf9, 0xd2, 0x6b, 0x7d, 0x5d, 0x7a, 0xad, 0x17, 0x87, 0xff, 0xfa, - 0x1f, 0xd3, 0x3b, 0xf7, 0xd9, 0xeb, 0x33, 0x6d, 0x92, 0x4c, 0x8a, 0x42, 0x3b, 0xf7, 0x5b, 0x67, - 0x4d, 0x07, 0xf1, 0xb6, 0x0d, 0xee, 0xfe, 0x0c, 0x00, 0x00, 0xff, 0xff, 0x84, 0x43, 0x0f, 0x11, - 0x2b, 0x03, 0x00, 0x00, + 0x14, 0xee, 0xac, 0xba, 0xb2, 0x23, 0xac, 0xdb, 0x20, 0x5a, 0xeb, 0x92, 0x2c, 0x73, 0xaa, 0x88, + 0x19, 0x8d, 0x20, 0xe8, 0xcd, 0xb0, 0x0b, 0x0a, 0x1e, 0x34, 0x82, 0x07, 0x2f, 0x61, 0x92, 0x8e, + 0xd9, 0xc1, 0x24, 0x2f, 0xed, 0x4c, 0x8a, 0x45, 0x04, 0xf1, 0x17, 0x08, 0xde, 0x3c, 0xfb, 0x63, + 0xf6, 0x58, 0xf0, 0x22, 0x1e, 0x82, 0xb4, 0xfe, 0x82, 0xfe, 0x02, 0x99, 0x99, 0xd4, 0xdd, 0xad, + 0x8a, 0x9e, 0xf2, 0xde, 0xfb, 0xbe, 0xf9, 0xde, 0x7b, 0x79, 0x1f, 0x26, 0x20, 0x0b, 0x90, 0x42, + 0xd2, 0x0a, 0x20, 0x2f, 0x58, 0xc9, 0x32, 0x3e, 0xa6, 0x93, 0x80, 0x8e, 0x6a, 0x3e, 0x9e, 0xfa, + 0xd5, 0x18, 0x14, 0x38, 0x97, 0x5b, 0x8e, 0x7f, 0x82, 0xe3, 0x4f, 0x82, 0xfe, 0xa5, 0x0c, 0x32, + 0x30, 0x14, 0xaa, 0x23, 0xcb, 0xee, 0xef, 0x66, 0x00, 0x59, 0xce, 0x29, 0xab, 0x04, 0x65, 0x65, + 0x09, 0x8a, 0x29, 0x01, 0xa5, 0x6c, 0xd1, 0xab, 0x2d, 0x6a, 0xb2, 0xa4, 0x7e, 0x49, 0x59, 0x39, + 0x5d, 0x41, 0xa9, 0xe9, 0x13, 0x5b, 0x45, 0x9b, 0xb4, 0x90, 0xb7, 0xfe, 0x4a, 0x89, 0x82, 0x4b, + 0xc5, 0x8a, 0xca, 0x12, 0xc8, 0x0c, 0xe1, 0x9d, 0x67, 0x15, 0xa8, 0x27, 0x63, 0x91, 0xf2, 0x88, + 0x8f, 0x6a, 0x2e, 0x95, 0x73, 0x03, 0x9f, 0xd7, 0x13, 0xc7, 0x62, 0xd8, 0x43, 0x7b, 0x68, 0x70, + 0x36, 0x74, 0x96, 0x8d, 0xb7, 0x3d, 0x65, 0x45, 0x7e, 0x9f, 0xb4, 0x00, 0x89, 0x36, 0x75, 0xf4, + 0x68, 0xe8, 0x1c, 0xe0, 0x9d, 0x84, 0x49, 0x1e, 0x33, 0x29, 0xb9, 0x8a, 0x87, 0xbc, 0x84, 0xa2, + 0xb7, 0xb1, 0x87, 0x06, 0x5b, 0xe1, 0xb5, 0x65, 0xe3, 0x5d, 0xb1, 0xaf, 0xd6, 0x19, 0x24, 0xda, + 0xd6, 0xa5, 0x07, 0xba, 0xb2, 0xaf, 0x0b, 0xce, 0x43, 0xdc, 0x1d, 0xd5, 0xa0, 0x4e, 0xeb, 0x9c, + 0x31, 0x3a, 0xbb, 0xcb, 0xc6, 0xeb, 0x59, 0x9d, 0xdf, 0x28, 0x24, 0xba, 0x68, 0x6a, 0xc7, 0x4a, + 0xe4, 0x1d, 0xc2, 0xdd, 0x13, 0x2b, 0xc9, 0x0a, 0x4a, 0xc9, 0x9d, 0x57, 0x18, 0xcb, 0x0a, 0x54, + 0x5c, 0xe9, 0xaa, 0x59, 0x6b, 0x2b, 0x7c, 0x7c, 0xd4, 0x78, 0x9d, 0x6f, 0x8d, 0x47, 0x33, 0xa1, + 0x0e, 0xeb, 0xc4, 0x4f, 0xa1, 0xa0, 0xed, 0xc9, 0x6e, 0xe6, 0x2c, 0x91, 0xab, 0xc4, 0x7c, 0x0b, + 0xa6, 0x0e, 0xfd, 0x50, 0x64, 0xfb, 0x3c, 0x5d, 0x36, 0x5e, 0xd7, 0xce, 0x73, 0x2c, 0x49, 0xa2, + 0x2d, 0xb9, 0x6a, 0x1a, 0x7c, 0x46, 0xf8, 0xdc, 0x53, 0x6d, 0x04, 0xe7, 0x13, 0xc2, 0x17, 0x7e, + 0x0d, 0xf3, 0x3c, 0x70, 0x06, 0xfe, 0x9f, 0x3d, 0xe1, 0xaf, 0x1f, 0xa1, 0x7f, 0xfd, 0x3f, 0x98, + 0x76, 0x37, 0x72, 0xf7, 0xfd, 0x97, 0x1f, 0x1f, 0x37, 0x6e, 0x39, 0x3e, 0xfd, 0x8b, 0x29, 0x75, + 0x2a, 0xe9, 0x9b, 0xf6, 0x76, 0x6f, 0xa9, 0x99, 0x58, 0x86, 0xf1, 0xd1, 0xdc, 0x45, 0xb3, 0xb9, + 0x8b, 0xbe, 0xcf, 0x5d, 0xf4, 0x61, 0xe1, 0x76, 0x66, 0x0b, 0xb7, 0xf3, 0x75, 0xe1, 0x76, 0x5e, + 0x1c, 0xfc, 0xeb, 0x8f, 0x4c, 0x6e, 0xdf, 0xa3, 0xaf, 0x4f, 0xb5, 0x49, 0x73, 0xc1, 0x4b, 0x65, + 0xfd, 0x6f, 0xbc, 0x35, 0x09, 0x92, 0x4d, 0x13, 0xdc, 0xf9, 0x19, 0x00, 0x00, 0xff, 0xff, 0x48, + 0xf8, 0xd8, 0x89, 0x2d, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -190,12 +190,12 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type QueryClient interface { - // SpotPrice defines a gRPC query handler that returns the spot price given + // SpotPriceV2 defines a gRPC query handler that returns the spot price given // a base denomination and a quote denomination. // The returned spot price has 36 decimal places. However, some of // modules perform sig fig rounding so most of the rightmost decimals can be // zeroes. - SpotPrice(ctx context.Context, in *SpotPriceRequest, opts ...grpc.CallOption) (*SpotPriceResponse, error) + SpotPriceV2(ctx context.Context, in *SpotPriceRequest, opts ...grpc.CallOption) (*SpotPriceResponse, error) } type queryClient struct { @@ -206,9 +206,9 @@ func NewQueryClient(cc grpc1.ClientConn) QueryClient { return &queryClient{cc} } -func (c *queryClient) SpotPrice(ctx context.Context, in *SpotPriceRequest, opts ...grpc.CallOption) (*SpotPriceResponse, error) { +func (c *queryClient) SpotPriceV2(ctx context.Context, in *SpotPriceRequest, opts ...grpc.CallOption) (*SpotPriceResponse, error) { out := new(SpotPriceResponse) - err := c.cc.Invoke(ctx, "/osmosis.poolmanager.v2.Query/SpotPrice", in, out, opts...) + err := c.cc.Invoke(ctx, "/osmosis.poolmanager.v2.Query/SpotPriceV2", in, out, opts...) if err != nil { return nil, err } @@ -217,40 +217,40 @@ func (c *queryClient) SpotPrice(ctx context.Context, in *SpotPriceRequest, opts // QueryServer is the server API for Query service. type QueryServer interface { - // SpotPrice defines a gRPC query handler that returns the spot price given + // SpotPriceV2 defines a gRPC query handler that returns the spot price given // a base denomination and a quote denomination. // The returned spot price has 36 decimal places. However, some of // modules perform sig fig rounding so most of the rightmost decimals can be // zeroes. - SpotPrice(context.Context, *SpotPriceRequest) (*SpotPriceResponse, error) + SpotPriceV2(context.Context, *SpotPriceRequest) (*SpotPriceResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. type UnimplementedQueryServer struct { } -func (*UnimplementedQueryServer) SpotPrice(ctx context.Context, req *SpotPriceRequest) (*SpotPriceResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method SpotPrice not implemented") +func (*UnimplementedQueryServer) SpotPriceV2(ctx context.Context, req *SpotPriceRequest) (*SpotPriceResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method SpotPriceV2 not implemented") } func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) } -func _Query_SpotPrice_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { +func _Query_SpotPriceV2_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(SpotPriceRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(QueryServer).SpotPrice(ctx, in) + return srv.(QueryServer).SpotPriceV2(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/osmosis.poolmanager.v2.Query/SpotPrice", + FullMethod: "/osmosis.poolmanager.v2.Query/SpotPriceV2", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).SpotPrice(ctx, req.(*SpotPriceRequest)) + return srv.(QueryServer).SpotPriceV2(ctx, req.(*SpotPriceRequest)) } return interceptor(ctx, in, info, handler) } @@ -260,8 +260,8 @@ var _Query_serviceDesc = grpc.ServiceDesc{ HandlerType: (*QueryServer)(nil), Methods: []grpc.MethodDesc{ { - MethodName: "SpotPrice", - Handler: _Query_SpotPrice_Handler, + MethodName: "SpotPriceV2", + Handler: _Query_SpotPriceV2_Handler, }, }, Streams: []grpc.StreamDesc{}, diff --git a/x/poolmanager/client/queryprotov2/query.pb.gw.go b/x/poolmanager/client/queryprotov2/query.pb.gw.go index 0382d52e879..c1a7669cac7 100644 --- a/x/poolmanager/client/queryprotov2/query.pb.gw.go +++ b/x/poolmanager/client/queryprotov2/query.pb.gw.go @@ -34,10 +34,10 @@ var _ = descriptor.ForMessage var _ = metadata.Join var ( - filter_Query_SpotPrice_0 = &utilities.DoubleArray{Encoding: map[string]int{"pool_id": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} + filter_Query_SpotPriceV2_0 = &utilities.DoubleArray{Encoding: map[string]int{"pool_id": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} ) -func request_Query_SpotPrice_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func request_Query_SpotPriceV2_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq SpotPriceRequest var metadata runtime.ServerMetadata @@ -62,16 +62,16 @@ func request_Query_SpotPrice_0(ctx context.Context, marshaler runtime.Marshaler, if err := req.ParseForm(); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_SpotPrice_0); err != nil { + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_SpotPriceV2_0); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - msg, err := client.SpotPrice(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + msg, err := client.SpotPriceV2(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } -func local_request_Query_SpotPrice_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func local_request_Query_SpotPriceV2_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq SpotPriceRequest var metadata runtime.ServerMetadata @@ -96,11 +96,11 @@ func local_request_Query_SpotPrice_0(ctx context.Context, marshaler runtime.Mars if err := req.ParseForm(); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_SpotPrice_0); err != nil { + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_SpotPriceV2_0); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - msg, err := server.SpotPrice(ctx, &protoReq) + msg, err := server.SpotPriceV2(ctx, &protoReq) return msg, metadata, err } @@ -111,7 +111,7 @@ func local_request_Query_SpotPrice_0(ctx context.Context, marshaler runtime.Mars // Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { - mux.Handle("GET", pattern_Query_SpotPrice_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_SpotPriceV2_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream @@ -122,7 +122,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_Query_SpotPrice_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_Query_SpotPriceV2_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { @@ -130,7 +130,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } - forward_Query_SpotPrice_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_SpotPriceV2_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -175,7 +175,7 @@ func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc // "QueryClient" to call the correct interceptors. func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { - mux.Handle("GET", pattern_Query_SpotPrice_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_SpotPriceV2_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) @@ -184,14 +184,14 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_Query_SpotPrice_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_Query_SpotPriceV2_0(rctx, inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_Query_SpotPrice_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_SpotPriceV2_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -199,9 +199,9 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie } var ( - pattern_Query_SpotPrice_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 2, 5}, []string{"osmosis", "poolmanager", "v2", "pools", "pool_id", "prices"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_SpotPriceV2_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 2, 5}, []string{"osmosis", "poolmanager", "v2", "pools", "pool_id", "prices"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( - forward_Query_SpotPrice_0 = runtime.ForwardResponseMessage + forward_Query_SpotPriceV2_0 = runtime.ForwardResponseMessage ) diff --git a/x/poolmanager/module/module.go b/x/poolmanager/module/module.go index 4302505ff35..f5392c571f2 100644 --- a/x/poolmanager/module/module.go +++ b/x/poolmanager/module/module.go @@ -21,7 +21,7 @@ import ( pmclient "github.com/osmosis-labs/osmosis/v19/x/poolmanager/client" "github.com/osmosis-labs/osmosis/v19/x/poolmanager/client/cli" "github.com/osmosis-labs/osmosis/v19/x/poolmanager/client/grpc" - grpcv2 "github.com/osmosis-labs/osmosis/v19/x/poolmanager/client/grpcv2" + "github.com/osmosis-labs/osmosis/v19/x/poolmanager/client/grpcv2" "github.com/osmosis-labs/osmosis/v19/x/poolmanager/client/queryproto" "github.com/osmosis-labs/osmosis/v19/x/poolmanager/client/queryprotov2" "github.com/osmosis-labs/osmosis/v19/x/poolmanager/types" @@ -90,7 +90,7 @@ type AppModule struct { func (am AppModule) RegisterServices(cfg module.Configurator) { types.RegisterMsgServer(cfg.MsgServer(), poolmanager.NewMsgServerImpl(&am.k)) queryproto.RegisterQueryServer(cfg.QueryServer(), grpc.Querier{Q: pmclient.NewQuerier(am.k)}) - queryprotov2.RegisterQueryServer(cfg.QueryServer(), grpcv2.Querier{Q: pmclient.NewQuerier(am.k)}) + queryprotov2.RegisterQueryServer(cfg.QueryServer(), grpcv2.Querier{Q: pmclient.NewV2Querier(am.k)}) } func NewAppModule(poolmanagerKeeper poolmanager.Keeper, gammKeeper types.PoolModuleI) AppModule { diff --git a/x/twap/client/grpc/grpc_query.go b/x/twap/client/grpc/grpc_query.go index 5d4ac9020c3..d2efc90e832 100644 --- a/x/twap/client/grpc/grpc_query.go +++ b/x/twap/client/grpc/grpc_query.go @@ -1,9 +1,9 @@ -package grpc + +package grpc // THIS FILE IS GENERATED CODE, DO NOT EDIT // SOURCE AT `proto/osmosis/twap/v1beta1/query.yml` - import ( context "context" diff --git a/x/valset-pref/client/grpc/grpc_query.go b/x/valset-pref/client/grpc/grpc_query.go index 8076d89eed3..c05ad27bb17 100644 --- a/x/valset-pref/client/grpc/grpc_query.go +++ b/x/valset-pref/client/grpc/grpc_query.go @@ -1,9 +1,9 @@ -package grpc + +package grpc // THIS FILE IS GENERATED CODE, DO NOT EDIT // SOURCE AT `proto/osmosis/valset-pref/v1beta1/query.yml` - import ( context "context" From d2cf2ed175bb3a0c7462fef1fee6674aa430a61a Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Wed, 27 Sep 2023 14:29:53 -0500 Subject: [PATCH 11/11] Update cmd/querygen/main.go --- cmd/querygen/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/querygen/main.go b/cmd/querygen/main.go index b4ae604e11b..584df936cad 100644 --- a/cmd/querygen/main.go +++ b/cmd/querygen/main.go @@ -33,7 +33,7 @@ func main() { } func parseTemplates() error { - // Create a function to upper vase the version suffix if it exists. + // Create a function to upper case the version suffix if it exists. funcMap := template.FuncMap{ "ToUpper": strings.ToUpper, }