From 1ccbdae6fe6ea283bf82caa71636d0c6faa491d4 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Thu, 10 Nov 2022 17:42:35 -0800 Subject: [PATCH] v2 spot price queries (#3335) * Make v2 queries * More WIP * Add twap query v2 * Update twap query in whitelist * Add changelog * v2 query test * Add wasmbinding test (cherry picked from commit 6c4f423057c0696440f49956d6e0d156e232f34d) --- CHANGELOG.md | 4 + app/apptesting/gamm.go | 38 +- proto/osmosis/gamm/v2/query.proto | 38 + proto/osmosis/twap/v2/query.proto | 66 ++ wasmbinding/query_plugin_test.go | 44 +- wasmbinding/stargate_whitelist.go | 7 +- x/gamm/keeper/grpc_query.go | 36 + x/gamm/keeper/grpc_query_test.go | 101 ++ x/gamm/module.go | 5 +- x/gamm/v2types/query.pb.go | 690 +++++++++++ x/gamm/v2types/query.pb.gw.go | 207 ++++ x/twap/client/cli/query.go | 113 +- x/twap/client/grpc/grpc_query_v2.go | 43 + x/twap/client/v2query_proto_wrap.go | 34 + x/twap/client/v2queryproto/query.pb.go | 1309 +++++++++++++++++++++ x/twap/client/v2queryproto/query.pb.gw.go | 254 ++++ x/twap/twapmodule/module.go | 5 +- 17 files changed, 2952 insertions(+), 42 deletions(-) create mode 100644 proto/osmosis/gamm/v2/query.proto create mode 100644 proto/osmosis/twap/v2/query.proto create mode 100644 x/gamm/v2types/query.pb.go create mode 100644 x/gamm/v2types/query.pb.gw.go create mode 100644 x/twap/client/grpc/grpc_query_v2.go create mode 100644 x/twap/client/v2query_proto_wrap.go create mode 100644 x/twap/client/v2queryproto/query.pb.go create mode 100644 x/twap/client/v2queryproto/query.pb.gw.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 68a99950ccb..64a2270e7fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#2739](https://github.com/osmosis-labs/osmosis/pull/2739) Add pool type query * [#2956](https://github.com/osmosis-labs/osmosis/issues/2956) Add queries for calculating amount of shares/tokens you get by providing X tokens/shares when entering/exiting a pool * [#3313](https://github.com/osmosis-labs/osmosis/pull/3313) Upgrade to IBC v3.4.0, allowing for IBC transfers with metadata. +* [#3335](https://github.com/osmosis-labs/osmosis/pull/3335) Add v2 spot price queries + - The v1beta1 queries actually have base asset and quote asset reversed, so you were always getting 1/correct spot price. People fixed this by reordering the arguments. + - This PR adds v2 queries for doing the correct thing, and giving people time to migrate from v1beta1 queries to v2. + - It also changes cosmwasm to only allow the v2 queries, as no contracts on Osmosis mainnet uses the v1beta1 queries. ### Bug fixes diff --git a/app/apptesting/gamm.go b/app/apptesting/gamm.go index 6b06817608f..8bb3a36a3a8 100644 --- a/app/apptesting/gamm.go +++ b/app/apptesting/gamm.go @@ -14,6 +14,24 @@ var DefaultAcctFunds sdk.Coins = sdk.NewCoins( sdk.NewCoin("bar", sdk.NewInt(10000000)), sdk.NewCoin("baz", sdk.NewInt(10000000)), ) +var DefaultPoolAssets = []balancer.PoolAsset{ + { + Weight: sdk.NewInt(100), + Token: sdk.NewCoin("foo", sdk.NewInt(5000000)), + }, + { + Weight: sdk.NewInt(200), + Token: sdk.NewCoin("bar", sdk.NewInt(5000000)), + }, + { + Weight: sdk.NewInt(300), + Token: sdk.NewCoin("baz", sdk.NewInt(5000000)), + }, + { + Weight: sdk.NewInt(400), + Token: sdk.NewCoin("uosmo", sdk.NewInt(5000000)), + }, +} // PrepareBalancerPoolWithCoins returns a balancer pool // consisted of given coins with equal weight. @@ -68,25 +86,7 @@ func (s *KeeperTestHelper) PrepareBalancerPoolWithPoolParams(poolParams balancer // Mint some assets to the account. s.FundAcc(s.TestAccs[0], DefaultAcctFunds) - poolAssets := []balancer.PoolAsset{ - { - Weight: sdk.NewInt(100), - Token: sdk.NewCoin("foo", sdk.NewInt(5000000)), - }, - { - Weight: sdk.NewInt(200), - Token: sdk.NewCoin("bar", sdk.NewInt(5000000)), - }, - { - Weight: sdk.NewInt(300), - Token: sdk.NewCoin("baz", sdk.NewInt(5000000)), - }, - { - Weight: sdk.NewInt(400), - Token: sdk.NewCoin("uosmo", sdk.NewInt(5000000)), - }, - } - msg := balancer.NewMsgCreateBalancerPool(s.TestAccs[0], poolParams, poolAssets, "") + msg := balancer.NewMsgCreateBalancerPool(s.TestAccs[0], poolParams, DefaultPoolAssets, "") poolId, err := s.App.GAMMKeeper.CreatePool(s.Ctx, msg) s.NoError(err) return poolId diff --git a/proto/osmosis/gamm/v2/query.proto b/proto/osmosis/gamm/v2/query.proto new file mode 100644 index 00000000000..c712253d2ec --- /dev/null +++ b/proto/osmosis/gamm/v2/query.proto @@ -0,0 +1,38 @@ +syntax = "proto3"; +package osmosis.gamm.v2; + +import "gogoproto/gogo.proto"; +import "osmosis/gamm/v1beta1/tx.proto"; + +import "cosmos/base/v1beta1/coin.proto"; +import "cosmos/base/query/v1beta1/pagination.proto"; +import "google/api/annotations.proto"; +import "google/protobuf/any.proto"; +import "cosmos_proto/cosmos.proto"; + +option go_package = "github.com/osmosis-labs/osmosis/v12/x/gamm/v2types"; + +service Query { + // SpotPrice defines a gRPC query handler that returns the spot price given + // a base denomination and a quote denomination. + rpc SpotPrice(QuerySpotPriceRequest) returns (QuerySpotPriceResponse) { + option (google.api.http).get = "/osmosis/gamm/v2/pools/{pool_id}/prices"; + } +} + +// QuerySpotPriceRequest defines the gRPC request structure for a SpotPrice +// query. +message QuerySpotPriceRequest { + 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\"" ]; +} + +// QuerySpotPriceResponse defines the gRPC response structure for a SpotPrice +// query. +message QuerySpotPriceResponse { + // String of the Dec. Ex) 10.203uatom + string spot_price = 1 [ (gogoproto.moretags) = "yaml:\"spot_price\"" ]; +} diff --git a/proto/osmosis/twap/v2/query.proto b/proto/osmosis/twap/v2/query.proto new file mode 100644 index 00000000000..4a051eddfe0 --- /dev/null +++ b/proto/osmosis/twap/v2/query.proto @@ -0,0 +1,66 @@ +syntax = "proto3"; +package osmosis.twap.v2; + +import "gogoproto/gogo.proto"; +import "osmosis/twap/v1beta1/twap_record.proto"; +import "osmosis/twap/v1beta1/genesis.proto"; + +import "cosmos/base/v1beta1/coin.proto"; +import "cosmos/base/query/v1beta1/pagination.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/v12/x/twap/client/v2queryproto"; + +service Query { + rpc ArithmeticTwap(ArithmeticTwapRequest) returns (ArithmeticTwapResponse) { + option (google.api.http).get = "/osmosis/twap/v2/ArithmeticTwap"; + } + rpc ArithmeticTwapToNow(ArithmeticTwapToNowRequest) + returns (ArithmeticTwapToNowResponse) { + option (google.api.http).get = "/osmosis/twap/v2/ArithmeticTwapToNow"; + } +} + +message ArithmeticTwapRequest { + uint64 pool_id = 1; + string base_asset = 2; + string quote_asset = 3; + google.protobuf.Timestamp start_time = 4 [ + (gogoproto.nullable) = false, + (gogoproto.stdtime) = true, + (gogoproto.moretags) = "yaml:\"start_time\"" + ]; + google.protobuf.Timestamp end_time = 5 [ + (gogoproto.nullable) = true, + (gogoproto.stdtime) = true, + (gogoproto.moretags) = "yaml:\"end_time\"" + ]; +} +message ArithmeticTwapResponse { + string arithmetic_twap = 1 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.moretags) = "yaml:\"arithmetic_twap\"", + (gogoproto.nullable) = false + ]; +} + +message ArithmeticTwapToNowRequest { + uint64 pool_id = 1; + string base_asset = 2; + string quote_asset = 3; + google.protobuf.Timestamp start_time = 4 [ + (gogoproto.nullable) = false, + (gogoproto.stdtime) = true, + (gogoproto.moretags) = "yaml:\"start_time\"" + ]; +} +message ArithmeticTwapToNowResponse { + string arithmetic_twap = 1 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.moretags) = "yaml:\"arithmetic_twap\"", + (gogoproto.nullable) = false + ]; +} diff --git a/wasmbinding/query_plugin_test.go b/wasmbinding/query_plugin_test.go index 0d40b7f423c..32b60595827 100644 --- a/wasmbinding/query_plugin_test.go +++ b/wasmbinding/query_plugin_test.go @@ -16,8 +16,13 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" proto "github.com/golang/protobuf/proto" "github.com/stretchr/testify/suite" + "github.com/tendermint/tendermint/crypto/ed25519" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + "github.com/osmosis-labs/osmosis/v12/app/apptesting" + "github.com/osmosis-labs/osmosis/v12/x/gamm/pool-models/balancer" + gammv2types "github.com/osmosis-labs/osmosis/v12/x/gamm/v2types" + "github.com/osmosis-labs/osmosis/v12/app" epochtypes "github.com/osmosis-labs/osmosis/v12/x/epochs/types" lockuptypes "github.com/osmosis-labs/osmosis/v12/x/lockup/types" @@ -47,10 +52,11 @@ func (suite *StargateTestSuite) TestStargateQuerier() { testSetup func() path string requestData func() []byte - responseProtoStruct interface{} + responseProtoStruct codec.ProtoMarshaler expectedQuerierError bool expectedUnMarshalError bool resendRequest bool + checkResponseStruct bool }{ { name: "happy path", @@ -63,6 +69,35 @@ func (suite *StargateTestSuite) TestStargateQuerier() { }, responseProtoStruct: &epochtypes.QueryEpochsInfoResponse{}, }, + { + name: "happy path gamm", + path: "/osmosis.gamm.v2.Query/SpotPrice", + testSetup: func() { + pk := ed25519.GenPrivKey().PubKey() + sender := sdk.AccAddress(pk.Address()) + err := simapp.FundAccount(suite.app.BankKeeper, suite.ctx, sender, apptesting.DefaultAcctFunds) + suite.Require().NoError(err) + msg := balancer.NewMsgCreateBalancerPool(sender, + balancer.NewPoolParams(sdk.ZeroDec(), sdk.ZeroDec(), nil), + apptesting.DefaultPoolAssets, "") + _, err = suite.app.GAMMKeeper.CreatePool(suite.ctx, msg) + suite.NoError(err) + }, + requestData: func() []byte { + queryrequest := gammv2types.QuerySpotPriceRequest{ + PoolId: 1, + BaseAssetDenom: "bar", + QuoteAssetDenom: "uosmo", + } + bz, err := proto.Marshal(&queryrequest) + suite.Require().NoError(err) + return bz + }, + checkResponseStruct: true, + responseProtoStruct: &gammv2types.QuerySpotPriceResponse{ + SpotPrice: sdk.NewDecWithPrec(5, 1).String(), + }, + }, { name: "unregistered path(not whitelisted)", path: "/osmosis.lockup.Query/AccountLockedLongerDuration", @@ -192,6 +227,13 @@ func (suite *StargateTestSuite) TestStargateQuerier() { suite.Require().Error(err) return } + if tc.checkResponseStruct { + expectedResponse, err := proto.Marshal(tc.responseProtoStruct) + suite.Require().NoError(err) + expJsonResp, err := wasmbinding.ConvertProtoToJSONMarshal(tc.responseProtoStruct, expectedResponse, suite.app.AppCodec()) + suite.Require().NoError(err) + suite.Require().Equal(expJsonResp, stargateResponse) + } suite.Require().NoError(err) diff --git a/wasmbinding/stargate_whitelist.go b/wasmbinding/stargate_whitelist.go index 68d7e987366..723180d31b6 100644 --- a/wasmbinding/stargate_whitelist.go +++ b/wasmbinding/stargate_whitelist.go @@ -15,6 +15,7 @@ import ( epochtypes "github.com/osmosis-labs/osmosis/v12/x/epochs/types" gammtypes "github.com/osmosis-labs/osmosis/v12/x/gamm/types" + gammv2types "github.com/osmosis-labs/osmosis/v12/x/gamm/v2types" incentivestypes "github.com/osmosis-labs/osmosis/v12/x/incentives/types" lockuptypes "github.com/osmosis-labs/osmosis/v12/x/lockup/types" minttypes "github.com/osmosis-labs/osmosis/v12/x/mint/types" @@ -22,6 +23,7 @@ import ( superfluidtypes "github.com/osmosis-labs/osmosis/v12/x/superfluid/types" tokenfactorytypes "github.com/osmosis-labs/osmosis/v12/x/tokenfactory/types" twapquerytypes "github.com/osmosis-labs/osmosis/v12/x/twap/client/queryproto" + twapv2querytypes "github.com/osmosis-labs/osmosis/v12/x/twap/client/v2queryproto" txfeestypes "github.com/osmosis-labs/osmosis/v12/x/txfees/types" ) @@ -78,6 +80,7 @@ func init() { setWhitelistedQuery("/osmosis.gamm.v1beta1.Query/TotalPoolLiquidity", &gammtypes.QueryTotalPoolLiquidityResponse{}) setWhitelistedQuery("/osmosis.gamm.v1beta1.Query/TotalShares", &gammtypes.QueryTotalSharesResponse{}) setWhitelistedQuery("/osmosis.gamm.v1beta1.Query/SpotPrice", &gammtypes.QuerySpotPriceResponse{}) + setWhitelistedQuery("/osmosis.gamm.v2.Query/SpotPrice", &gammv2types.QuerySpotPriceResponse{}) // incentives setWhitelistedQuery("/osmosis.incentives.Query/ModuleToDistributeCoins", &incentivestypes.ModuleToDistributeCoinsResponse{}) @@ -115,8 +118,8 @@ func init() { // Does not include denoms_from_creator, TBD if this is the index we want contracts to use instead of admin // twap - setWhitelistedQuery("/osmosis.twap.v1beta1.Query/ArithmeticTwap", &twapquerytypes.ArithmeticTwapResponse{}) - setWhitelistedQuery("/osmosis.twap.v1beta1.Query/ArithmeticTwapToNow", &twapquerytypes.ArithmeticTwapToNowResponse{}) + setWhitelistedQuery("/osmosis.twap.v2.Query/ArithmeticTwap", &twapv2querytypes.ArithmeticTwapResponse{}) + setWhitelistedQuery("/osmosis.twap.v2.Query/ArithmeticTwapToNow", &twapv2querytypes.ArithmeticTwapToNowResponse{}) setWhitelistedQuery("/osmosis.twap.v1beta1.Query/Params", &twapquerytypes.ParamsResponse{}) } diff --git a/x/gamm/keeper/grpc_query.go b/x/gamm/keeper/grpc_query.go index d918c6f2fda..3335dc8b281 100644 --- a/x/gamm/keeper/grpc_query.go +++ b/x/gamm/keeper/grpc_query.go @@ -16,6 +16,7 @@ import ( "github.com/osmosis-labs/osmosis/v12/x/gamm/pool-models/balancer" "github.com/osmosis-labs/osmosis/v12/x/gamm/types" + "github.com/osmosis-labs/osmosis/v12/x/gamm/v2types" ) var sdkIntMaxValue = sdk.NewInt(0) @@ -44,6 +45,16 @@ func NewQuerier(k Keeper) Querier { return Querier{Keeper: k} } +// QuerierV2 defines a wrapper around the x/gamm keeper providing gRPC method +// handlers for v2 queries. +type QuerierV2 struct { + Keeper +} + +func NewV2Querier(k Keeper) QuerierV2 { + return QuerierV2{Keeper: k} +} + // Pool checks if a pool exists and their respective poolWeights. func (q Querier) Pool( ctx context.Context, @@ -371,6 +382,31 @@ func (q Querier) SpotPrice(ctx context.Context, req *types.QuerySpotPriceRequest }, nil } +func (q QuerierV2) SpotPrice(ctx context.Context, req *v2types.QuerySpotPriceRequest) (*v2types.QuerySpotPriceResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "empty request") + } + + 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") + } + + sdkCtx := sdk.UnwrapSDKContext(ctx) + + sp, err := q.Keeper.CalculateSpotPrice(sdkCtx, req.PoolId, req.QuoteAssetDenom, req.BaseAssetDenom) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return &v2types.QuerySpotPriceResponse{ + SpotPrice: sp.String(), + }, nil +} + // TotalLiquidity returns total liquidity across all pools. func (q Querier) TotalLiquidity(ctx context.Context, _ *types.QueryTotalLiquidityRequest) (*types.QueryTotalLiquidityResponse, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) diff --git a/x/gamm/keeper/grpc_query_test.go b/x/gamm/keeper/grpc_query_test.go index d41e060b25c..0d0cac60a0c 100644 --- a/x/gamm/keeper/grpc_query_test.go +++ b/x/gamm/keeper/grpc_query_test.go @@ -11,6 +11,7 @@ import ( "github.com/osmosis-labs/osmosis/v12/x/gamm/pool-models/balancer" balancertypes "github.com/osmosis-labs/osmosis/v12/x/gamm/pool-models/balancer" "github.com/osmosis-labs/osmosis/v12/x/gamm/types" + "github.com/osmosis-labs/osmosis/v12/x/gamm/v2types" ) func (suite *KeeperTestSuite) TestCalcExitPoolCoinsFromShares() { @@ -622,3 +623,103 @@ func (suite *KeeperTestSuite) TestQueryBalancerPoolSpotPrice() { }) } } + +func (suite *KeeperTestSuite) TestV2QueryBalancerPoolSpotPrice() { + v2queryClient := v2types.NewQueryClient(suite.QueryHelper) + coins := sdk.NewCoins( + sdk.NewInt64Coin("tokenA", 1000), + sdk.NewInt64Coin("tokenB", 2000), + sdk.NewInt64Coin("tokenC", 3000), + sdk.NewInt64Coin("tokenD", 4000), + sdk.NewInt64Coin("tokenE", 4000), // 4000 intentional + ) + poolID := suite.PrepareBalancerPoolWithCoins(coins...) + + testCases := []struct { + name string + req *v2types.QuerySpotPriceRequest + expectErr bool + result string + }{ + { + name: "non-existant pool", + req: &v2types.QuerySpotPriceRequest{ + PoolId: 0, + BaseAssetDenom: "tokenA", + QuoteAssetDenom: "tokenB", + }, + expectErr: true, + }, + { + name: "missing asset denoms", + req: &v2types.QuerySpotPriceRequest{ + PoolId: poolID, + }, + expectErr: true, + }, + { + name: "missing pool ID and quote denom", + req: &v2types.QuerySpotPriceRequest{ + BaseAssetDenom: "tokenA", + }, + expectErr: true, + }, + { + name: "missing pool ID and base denom", + req: &v2types.QuerySpotPriceRequest{ + QuoteAssetDenom: "tokenB", + }, + expectErr: true, + }, + { + name: "tokenA in terms of tokenB", + req: &v2types.QuerySpotPriceRequest{ + PoolId: poolID, + BaseAssetDenom: "tokenA", + QuoteAssetDenom: "tokenB", + }, + result: sdk.NewDec(2).String(), + }, + { + name: "tokenB in terms of tokenA", + req: &v2types.QuerySpotPriceRequest{ + PoolId: poolID, + BaseAssetDenom: "tokenB", + QuoteAssetDenom: "tokenA", + }, + result: sdk.NewDecWithPrec(5, 1).String(), + }, + { + name: "tokenC in terms of tokenD (rounded decimal of 4/3)", + req: &v2types.QuerySpotPriceRequest{ + PoolId: poolID, + BaseAssetDenom: "tokenC", + QuoteAssetDenom: "tokenD", + }, + result: sdk.MustNewDecFromStr("1.333333330000000000").String(), + }, + { + name: "tokenD in terms of tokenE (1)", + req: &v2types.QuerySpotPriceRequest{ + PoolId: poolID, + BaseAssetDenom: "tokenD", + QuoteAssetDenom: "tokenE", + }, + result: sdk.OneDec().String(), + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + result, err := v2queryClient.SpotPrice(gocontext.Background(), tc.req) + if tc.expectErr { + suite.Require().Error(err, "expected error") + } else { + suite.Require().NoError(err, "unexpected error") + suite.Require().Equal(tc.result, result.SpotPrice) + } + }) + } +} diff --git a/x/gamm/module.go b/x/gamm/module.go index 829916316f5..454f19c0c05 100644 --- a/x/gamm/module.go +++ b/x/gamm/module.go @@ -32,6 +32,7 @@ import ( "github.com/osmosis-labs/osmosis/v12/x/gamm/pool-models/stableswap" simulation "github.com/osmosis-labs/osmosis/v12/x/gamm/simulation" "github.com/osmosis-labs/osmosis/v12/x/gamm/types" + "github.com/osmosis-labs/osmosis/v12/x/gamm/v2types" ) var ( @@ -74,7 +75,8 @@ func (b AppModuleBasic) RegisterRESTRoutes(ctx client.Context, r *mux.Router) { } func (b AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { - types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) //nolint:errcheck + types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) //nolint:errcheck + v2types.RegisterQueryHandlerClient(context.Background(), mux, v2types.NewQueryClient(clientCtx)) //nolint:errcheck } func (b AppModuleBasic) GetTxCmd() *cobra.Command { @@ -105,6 +107,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { balancer.RegisterMsgServer(cfg.MsgServer(), keeper.NewBalancerMsgServerImpl(&am.keeper)) stableswap.RegisterMsgServer(cfg.MsgServer(), keeper.NewStableswapMsgServerImpl(&am.keeper)) types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQuerier(am.keeper)) + v2types.RegisterQueryServer(cfg.QueryServer(), keeper.NewV2Querier(am.keeper)) } func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, diff --git a/x/gamm/v2types/query.pb.go b/x/gamm/v2types/query.pb.go new file mode 100644 index 00000000000..69319ab39bb --- /dev/null +++ b/x/gamm/v2types/query.pb.go @@ -0,0 +1,690 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: osmosis/gamm/v2/query.proto + +package v2types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/cosmos-sdk/codec/types" + _ "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/cosmos-sdk/types/query" + _ "github.com/gogo/protobuf/gogoproto" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + _ "github.com/osmosis-labs/osmosis/v12/x/gamm/types" + _ "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 + +// QuerySpotPriceRequest defines the gRPC request structure for a SpotPrice +// query. +type QuerySpotPriceRequest 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 *QuerySpotPriceRequest) Reset() { *m = QuerySpotPriceRequest{} } +func (m *QuerySpotPriceRequest) String() string { return proto.CompactTextString(m) } +func (*QuerySpotPriceRequest) ProtoMessage() {} +func (*QuerySpotPriceRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_49ff000e88fc374c, []int{0} +} +func (m *QuerySpotPriceRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QuerySpotPriceRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QuerySpotPriceRequest.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 *QuerySpotPriceRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QuerySpotPriceRequest.Merge(m, src) +} +func (m *QuerySpotPriceRequest) XXX_Size() int { + return m.Size() +} +func (m *QuerySpotPriceRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QuerySpotPriceRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QuerySpotPriceRequest proto.InternalMessageInfo + +func (m *QuerySpotPriceRequest) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *QuerySpotPriceRequest) GetBaseAssetDenom() string { + if m != nil { + return m.BaseAssetDenom + } + return "" +} + +func (m *QuerySpotPriceRequest) GetQuoteAssetDenom() string { + if m != nil { + return m.QuoteAssetDenom + } + return "" +} + +// QuerySpotPriceResponse defines the gRPC response structure for a SpotPrice +// query. +type QuerySpotPriceResponse struct { + // String of the Dec. Ex) 10.203uatom + SpotPrice string `protobuf:"bytes,1,opt,name=spot_price,json=spotPrice,proto3" json:"spot_price,omitempty" yaml:"spot_price"` +} + +func (m *QuerySpotPriceResponse) Reset() { *m = QuerySpotPriceResponse{} } +func (m *QuerySpotPriceResponse) String() string { return proto.CompactTextString(m) } +func (*QuerySpotPriceResponse) ProtoMessage() {} +func (*QuerySpotPriceResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_49ff000e88fc374c, []int{1} +} +func (m *QuerySpotPriceResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QuerySpotPriceResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QuerySpotPriceResponse.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 *QuerySpotPriceResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QuerySpotPriceResponse.Merge(m, src) +} +func (m *QuerySpotPriceResponse) XXX_Size() int { + return m.Size() +} +func (m *QuerySpotPriceResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QuerySpotPriceResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QuerySpotPriceResponse proto.InternalMessageInfo + +func (m *QuerySpotPriceResponse) GetSpotPrice() string { + if m != nil { + return m.SpotPrice + } + return "" +} + +func init() { + proto.RegisterType((*QuerySpotPriceRequest)(nil), "osmosis.gamm.v2.QuerySpotPriceRequest") + proto.RegisterType((*QuerySpotPriceResponse)(nil), "osmosis.gamm.v2.QuerySpotPriceResponse") +} + +func init() { proto.RegisterFile("osmosis/gamm/v2/query.proto", fileDescriptor_49ff000e88fc374c) } + +var fileDescriptor_49ff000e88fc374c = []byte{ + // 459 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0x41, 0x8b, 0x13, 0x31, + 0x14, 0xc7, 0x9b, 0x55, 0x57, 0x9a, 0xc3, 0xae, 0x1b, 0x5c, 0xad, 0xdd, 0x75, 0xba, 0xcc, 0xc1, + 0x5d, 0x15, 0x27, 0x74, 0xf4, 0xe4, 0xcd, 0xa2, 0xa0, 0x20, 0xa2, 0xe3, 0xcd, 0xcb, 0x90, 0x69, + 0xe3, 0x38, 0xd0, 0x99, 0x97, 0xf6, 0x65, 0xca, 0x16, 0xf1, 0xe2, 0x5d, 0x10, 0x3c, 0xf8, 0x95, + 0x3c, 0x2e, 0x88, 0xe0, 0xa9, 0x48, 0xeb, 0x27, 0xe8, 0x27, 0x90, 0x24, 0x33, 0x5d, 0xb7, 0x0a, + 0x7b, 0x4b, 0xde, 0xef, 0x9f, 0x5f, 0x92, 0xc7, 0xa3, 0x7b, 0x80, 0x39, 0x60, 0x86, 0x3c, 0x15, + 0x79, 0xce, 0x27, 0x21, 0x1f, 0x95, 0x72, 0x3c, 0x0d, 0xd4, 0x18, 0x34, 0xb0, 0xed, 0x0a, 0x06, + 0x06, 0x06, 0x93, 0xb0, 0x7d, 0x35, 0x85, 0x14, 0x2c, 0xe3, 0x66, 0xe5, 0x62, 0xed, 0x9b, 0x67, + 0x1d, 0xdd, 0x44, 0x6a, 0xd1, 0xe5, 0xfa, 0xb8, 0xc2, 0x5e, 0xdf, 0x72, 0x9e, 0x08, 0x94, 0x2b, + 0xda, 0x87, 0xac, 0xa8, 0xf8, 0x9d, 0xbf, 0xb9, 0xbd, 0x7e, 0x95, 0x52, 0x22, 0xcd, 0x0a, 0xa1, + 0x33, 0xa8, 0xb3, 0xfb, 0x29, 0x40, 0x3a, 0x94, 0x5c, 0xa8, 0x8c, 0x8b, 0xa2, 0x00, 0x6d, 0x21, + 0x56, 0xf4, 0x46, 0x45, 0xed, 0x2e, 0x29, 0xdf, 0x72, 0x51, 0x4c, 0x6b, 0xe4, 0x2e, 0x89, 0xdd, + 0xe3, 0xdd, 0xc6, 0x21, 0xff, 0x07, 0xa1, 0xbb, 0xaf, 0xcc, 0xb5, 0xaf, 0x15, 0xe8, 0x97, 0xe3, + 0xac, 0x2f, 0x23, 0x39, 0x2a, 0x25, 0x6a, 0x76, 0x97, 0x5e, 0x56, 0x00, 0xc3, 0x38, 0x1b, 0xb4, + 0xc8, 0x01, 0x39, 0xba, 0xd8, 0x63, 0xcb, 0x59, 0x67, 0x6b, 0x2a, 0xf2, 0xe1, 0x43, 0xbf, 0x02, + 0x7e, 0xb4, 0x69, 0x56, 0xcf, 0x06, 0xec, 0x09, 0xbd, 0x62, 0x7e, 0x10, 0x0b, 0x44, 0xa9, 0xe3, + 0x81, 0x2c, 0x20, 0x6f, 0x6d, 0x1c, 0x90, 0xa3, 0x66, 0x6f, 0x6f, 0x39, 0xeb, 0x5c, 0x77, 0xa7, + 0xd6, 0x13, 0x7e, 0xb4, 0x65, 0x4a, 0x8f, 0x4c, 0xe5, 0xb1, 0x29, 0xb0, 0xa7, 0x74, 0x67, 0x54, + 0x82, 0x3e, 0xeb, 0xb9, 0x60, 0x3d, 0xfb, 0xcb, 0x59, 0xa7, 0xe5, 0x3c, 0xff, 0x44, 0xfc, 0x68, + 0xdb, 0xd6, 0x4e, 0x4d, 0xfe, 0x0b, 0x7a, 0x6d, 0xfd, 0x5b, 0xa8, 0xa0, 0x40, 0xc9, 0x1e, 0x50, + 0x8a, 0x0a, 0x74, 0xac, 0x4c, 0xd5, 0x7e, 0xad, 0xd9, 0xdb, 0x5d, 0xce, 0x3a, 0x3b, 0x4e, 0x7e, + 0xca, 0xfc, 0xa8, 0x89, 0xf5, 0xe9, 0xf0, 0x2b, 0xa1, 0x97, 0xac, 0x90, 0x7d, 0x22, 0xb4, 0xb9, + 0xb2, 0xb2, 0x5b, 0xc1, 0xda, 0x98, 0x04, 0xff, 0xed, 0x66, 0xfb, 0xf0, 0xdc, 0x9c, 0x7b, 0x9e, + 0xcf, 0x3f, 0x7e, 0xff, 0xfd, 0x65, 0xe3, 0x36, 0x3b, 0xe4, 0xeb, 0xc3, 0x69, 0x5a, 0x8d, 0xfc, + 0x7d, 0xd5, 0xfb, 0x0f, 0xdc, 0x3e, 0x12, 0x7b, 0xcf, 0xbf, 0xcd, 0x3d, 0x72, 0x32, 0xf7, 0xc8, + 0xaf, 0xb9, 0x47, 0x3e, 0x2f, 0xbc, 0xc6, 0xc9, 0xc2, 0x6b, 0xfc, 0x5c, 0x78, 0x8d, 0x37, 0x61, + 0x9a, 0xe9, 0x77, 0x65, 0x12, 0xf4, 0x21, 0xaf, 0x65, 0xf7, 0x86, 0x22, 0xc1, 0x95, 0x79, 0xd2, + 0x0d, 0xf9, 0x71, 0xed, 0xd7, 0x53, 0x25, 0x31, 0xd9, 0xb4, 0x63, 0x71, 0xff, 0x4f, 0x00, 0x00, + 0x00, 0xff, 0xff, 0xa4, 0xe1, 0x10, 0x77, 0x1b, 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. + SpotPrice(ctx context.Context, in *QuerySpotPriceRequest, opts ...grpc.CallOption) (*QuerySpotPriceResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) SpotPrice(ctx context.Context, in *QuerySpotPriceRequest, opts ...grpc.CallOption) (*QuerySpotPriceResponse, error) { + out := new(QuerySpotPriceResponse) + err := c.cc.Invoke(ctx, "/osmosis.gamm.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. + SpotPrice(context.Context, *QuerySpotPriceRequest) (*QuerySpotPriceResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) SpotPrice(ctx context.Context, req *QuerySpotPriceRequest) (*QuerySpotPriceResponse, 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(QuerySpotPriceRequest) + 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.gamm.v2.Query/SpotPrice", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).SpotPrice(ctx, req.(*QuerySpotPriceRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "osmosis.gamm.v2.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "SpotPrice", + Handler: _Query_SpotPrice_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "osmosis/gamm/v2/query.proto", +} + +func (m *QuerySpotPriceRequest) 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 *QuerySpotPriceRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QuerySpotPriceRequest) 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 *QuerySpotPriceResponse) 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 *QuerySpotPriceResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QuerySpotPriceResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.SpotPrice) > 0 { + i -= len(m.SpotPrice) + copy(dAtA[i:], m.SpotPrice) + i = encodeVarintQuery(dAtA, i, uint64(len(m.SpotPrice))) + 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 *QuerySpotPriceRequest) 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 *QuerySpotPriceResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.SpotPrice) + if l > 0 { + 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 *QuerySpotPriceRequest) 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: QuerySpotPriceRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QuerySpotPriceRequest: 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 *QuerySpotPriceResponse) 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: QuerySpotPriceResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QuerySpotPriceResponse: 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 + } + m.SpotPrice = 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 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/gamm/v2types/query.pb.gw.go b/x/gamm/v2types/query.pb.gw.go new file mode 100644 index 00000000000..2195093b816 --- /dev/null +++ b/x/gamm/v2types/query.pb.gw.go @@ -0,0 +1,207 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: osmosis/gamm/v2/query.proto + +/* +Package v2types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package v2types + +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 QuerySpotPriceRequest + 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 QuerySpotPriceRequest + 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", "gamm", "v2", "pools", "pool_id", "prices"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_SpotPrice_0 = runtime.ForwardResponseMessage +) diff --git a/x/twap/client/cli/query.go b/x/twap/client/cli/query.go index 36d30875b74..65d019ff45a 100644 --- a/x/twap/client/cli/query.go +++ b/x/twap/client/cli/query.go @@ -13,6 +13,7 @@ import ( gammtypes "github.com/osmosis-labs/osmosis/v12/x/gamm/types" "github.com/osmosis-labs/osmosis/v12/x/twap/client/queryproto" + "github.com/osmosis-labs/osmosis/v12/x/twap/client/v2queryproto" "github.com/osmosis-labs/osmosis/v12/x/twap/types" ) @@ -28,17 +29,18 @@ func GetQueryCmd() *cobra.Command { } cmd.AddCommand(GetQueryTwapCommand()) + cmd.AddCommand(GetQueryTwapLegacyCommand()) return cmd } -// GetCmdAssetMultiplier returns multiplier of an asset by denom. +// GetQueryTwapCommand returns multiplier of an asset by denom. func GetQueryTwapCommand() *cobra.Command { cmd := &cobra.Command{ Use: "twap [poolid] [base denom] [start time] [end time]", Short: "Query twap", Long: strings.TrimSpace( - fmt.Sprintf(`Query twap for pull. Start time must be unix time. End time can be unix time or duration. + fmt.Sprintf(`Query twap for pool. Start time must be unix time. End time can be unix time or duration. Example: $ %s q twap 1 uosmo 1667088000 24h @@ -50,32 +52,74 @@ $ %s q twap 1 uosmo 1667088000 1667174400 Args: cobra.ExactArgs(4), RunE: func(cmd *cobra.Command, args []string) error { // boilerplate parse fields - // - poolId, err := parseUint(args[0], "poolId") + poolId, baseDenom, startTime, endTime, err := twapQueryParseArgs(args) if err != nil { return err } - // - baseDenom := strings.TrimSpace(args[1]) + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := v2queryproto.NewQueryClient(clientCtx) + gammClient := gammtypes.NewQueryClient(clientCtx) + liquidity, err := gammClient.TotalPoolLiquidity(cmd.Context(), &gammtypes.QueryTotalPoolLiquidityRequest{PoolId: poolId}) + if err != nil { + return err + } + if len(liquidity.Liquidity) != 2 { + return fmt.Errorf("pool %d has %d assets of liquidity, CLI support only exists for 2 assets right now.", poolId, len(liquidity.Liquidity)) + } + quoteDenom := "" + if liquidity.Liquidity[0].Denom == baseDenom { + quoteDenom = liquidity.Liquidity[1].Denom + } else if liquidity.Liquidity[1].Denom == baseDenom { + quoteDenom = liquidity.Liquidity[0].Denom + } else { + return fmt.Errorf("pool %d doesn't have provided baseDenom %s, has %s and %s", + poolId, baseDenom, liquidity.Liquidity[0], liquidity.Liquidity[1]) + } - // - startTime, err := parseUnixTime(args[2], "start time") + res, err := queryClient.ArithmeticTwap(cmd.Context(), &v2queryproto.ArithmeticTwapRequest{ + PoolId: poolId, + BaseAsset: baseDenom, + QuoteAsset: quoteDenom, + StartTime: startTime, + EndTime: &endTime, + }) if err != nil { return err } - // END TIME PARSE: ONEOF {, } - // try parsing in unix time, if failed try parsing in duration - endTime, err := parseUnixTime(args[3], "end time") + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +// GetQueryTwapCommand returns multiplier of an asset by denom. +func GetQueryTwapLegacyCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "twap-legacy [poolid] [base denom] [start time] [end time]", + Short: "Query twap", + Long: strings.TrimSpace( + fmt.Sprintf(`Query twap for pool. Start time must be unix time. End time can be unix time or duration. + +Example: +$ %s q twap 1 uosmo 1667088000 24h +$ %s q twap 1 uosmo 1667088000 1667174400 +`, + version.AppName, version.AppName, + ), + ), + Args: cobra.ExactArgs(4), + RunE: func(cmd *cobra.Command, args []string) error { + poolId, baseDenom, startTime, endTime, err := twapQueryParseArgs(args) if err != nil { - // TODO if we don't use protoreflect: - // make better error combiner, rather than just returning last error - duration, err := time.ParseDuration(args[3]) - if err != nil { - return err - } - endTime = startTime.Add(duration) + return err } clientCtx, err := client.GetClientQueryContext(cmd) @@ -121,6 +165,39 @@ $ %s q twap 1 uosmo 1667088000 1667174400 return cmd } +func twapQueryParseArgs(args []string) (poolId uint64, baseDenom string, startTime time.Time, endTime time.Time, err error) { + // boilerplate parse fields + // + poolId, err = parseUint(args[0], "poolId") + if err != nil { + return + } + + // + baseDenom = strings.TrimSpace(args[1]) + + // + startTime, err = parseUnixTime(args[2], "start time") + if err != nil { + return + } + + // END TIME PARSE: ONEOF {, } + // try parsing in unix time, if failed try parsing in duration + endTime, err = parseUnixTime(args[3], "end time") + if err != nil { + // TODO if we don't use protoreflect: + // make better error combiner, rather than just returning last error + duration, err2 := time.ParseDuration(args[3]) + if err2 != nil { + err = err2 + return + } + endTime = startTime.Add(duration) + } + return poolId, baseDenom, startTime, endTime, nil +} + func parseUint(arg string, fieldName string) (uint64, error) { v, err := strconv.ParseUint(arg, 10, 64) if err != nil { diff --git a/x/twap/client/grpc/grpc_query_v2.go b/x/twap/client/grpc/grpc_query_v2.go new file mode 100644 index 00000000000..587ed7b371a --- /dev/null +++ b/x/twap/client/grpc/grpc_query_v2.go @@ -0,0 +1,43 @@ +package grpc + +// THIS FILE IS GENERATED CODE, DO NOT EDIT +// SOURCE AT `proto/osmosis/twap/v1beta1/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/v12/x/twap/client" + "github.com/osmosis-labs/osmosis/v12/x/twap/client/v2queryproto" +) + +type QuerierV2 struct { + Q client.QuerierV2 +} + +var _ v2queryproto.QueryServer = QuerierV2{} + + +func (q QuerierV2) ArithmeticTwapToNow(grpcCtx context.Context, + req *v2queryproto.ArithmeticTwapToNowRequest, +) (*v2queryproto.ArithmeticTwapToNowResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "empty request") + } + ctx := sdk.UnwrapSDKContext(grpcCtx) + return q.Q.ArithmeticTwapToNow(ctx, *req) +} + +func (q QuerierV2) ArithmeticTwap(grpcCtx context.Context, + req *v2queryproto.ArithmeticTwapRequest, +) (*v2queryproto.ArithmeticTwapResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "empty request") + } + ctx := sdk.UnwrapSDKContext(grpcCtx) + return q.Q.ArithmeticTwap(ctx, *req) +} + diff --git a/x/twap/client/v2query_proto_wrap.go b/x/twap/client/v2query_proto_wrap.go new file mode 100644 index 00000000000..4f9ece83558 --- /dev/null +++ b/x/twap/client/v2query_proto_wrap.go @@ -0,0 +1,34 @@ +package client + +import ( + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/osmosis-labs/osmosis/v12/x/twap" + "github.com/osmosis-labs/osmosis/v12/x/twap/client/v2queryproto" +) + +// This file should evolve to being code gen'd, off of `proto/twap/v1beta/query.yml` + +type QuerierV2 struct { + K twap.Keeper +} + +func (q QuerierV2) ArithmeticTwap(ctx sdk.Context, + req v2queryproto.ArithmeticTwapRequest, +) (*v2queryproto.ArithmeticTwapResponse, error) { + if (req.EndTime == nil || *req.EndTime == time.Time{}) { + *req.EndTime = ctx.BlockTime() + } + + twap, err := q.K.GetArithmeticTwap(ctx, req.PoolId, req.QuoteAsset, req.BaseAsset, req.StartTime, *req.EndTime) + return &v2queryproto.ArithmeticTwapResponse{ArithmeticTwap: twap}, err +} + +func (q QuerierV2) ArithmeticTwapToNow(ctx sdk.Context, + req v2queryproto.ArithmeticTwapToNowRequest, +) (*v2queryproto.ArithmeticTwapToNowResponse, error) { + twap, err := q.K.GetArithmeticTwapToNow(ctx, req.PoolId, req.QuoteAsset, req.BaseAsset, req.StartTime) + return &v2queryproto.ArithmeticTwapToNowResponse{ArithmeticTwap: twap}, err +} diff --git a/x/twap/client/v2queryproto/query.pb.go b/x/twap/client/v2queryproto/query.pb.go new file mode 100644 index 00000000000..5fa50a5f2e5 --- /dev/null +++ b/x/twap/client/v2queryproto/query.pb.go @@ -0,0 +1,1309 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: osmosis/twap/v2/query.proto + +package v2queryproto + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/cosmos-sdk/codec/types" + _ "github.com/cosmos/cosmos-sdk/types" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/cosmos-sdk/types/query" + _ "github.com/gogo/protobuf/gogoproto" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + _ "github.com/gogo/protobuf/types" + github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" + _ "github.com/osmosis-labs/osmosis/v12/x/twap/types" + _ "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" + time "time" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf +var _ = time.Kitchen + +// 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 + +type ArithmeticTwapRequest struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + BaseAsset string `protobuf:"bytes,2,opt,name=base_asset,json=baseAsset,proto3" json:"base_asset,omitempty"` + QuoteAsset string `protobuf:"bytes,3,opt,name=quote_asset,json=quoteAsset,proto3" json:"quote_asset,omitempty"` + StartTime time.Time `protobuf:"bytes,4,opt,name=start_time,json=startTime,proto3,stdtime" json:"start_time" yaml:"start_time"` + EndTime *time.Time `protobuf:"bytes,5,opt,name=end_time,json=endTime,proto3,stdtime" json:"end_time,omitempty" yaml:"end_time"` +} + +func (m *ArithmeticTwapRequest) Reset() { *m = ArithmeticTwapRequest{} } +func (m *ArithmeticTwapRequest) String() string { return proto.CompactTextString(m) } +func (*ArithmeticTwapRequest) ProtoMessage() {} +func (*ArithmeticTwapRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_ebc93508b9209896, []int{0} +} +func (m *ArithmeticTwapRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ArithmeticTwapRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ArithmeticTwapRequest.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 *ArithmeticTwapRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_ArithmeticTwapRequest.Merge(m, src) +} +func (m *ArithmeticTwapRequest) XXX_Size() int { + return m.Size() +} +func (m *ArithmeticTwapRequest) XXX_DiscardUnknown() { + xxx_messageInfo_ArithmeticTwapRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_ArithmeticTwapRequest proto.InternalMessageInfo + +func (m *ArithmeticTwapRequest) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *ArithmeticTwapRequest) GetBaseAsset() string { + if m != nil { + return m.BaseAsset + } + return "" +} + +func (m *ArithmeticTwapRequest) GetQuoteAsset() string { + if m != nil { + return m.QuoteAsset + } + return "" +} + +func (m *ArithmeticTwapRequest) GetStartTime() time.Time { + if m != nil { + return m.StartTime + } + return time.Time{} +} + +func (m *ArithmeticTwapRequest) GetEndTime() *time.Time { + if m != nil { + return m.EndTime + } + return nil +} + +type ArithmeticTwapResponse struct { + ArithmeticTwap github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,1,opt,name=arithmetic_twap,json=arithmeticTwap,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"arithmetic_twap" yaml:"arithmetic_twap"` +} + +func (m *ArithmeticTwapResponse) Reset() { *m = ArithmeticTwapResponse{} } +func (m *ArithmeticTwapResponse) String() string { return proto.CompactTextString(m) } +func (*ArithmeticTwapResponse) ProtoMessage() {} +func (*ArithmeticTwapResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_ebc93508b9209896, []int{1} +} +func (m *ArithmeticTwapResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ArithmeticTwapResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ArithmeticTwapResponse.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 *ArithmeticTwapResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_ArithmeticTwapResponse.Merge(m, src) +} +func (m *ArithmeticTwapResponse) XXX_Size() int { + return m.Size() +} +func (m *ArithmeticTwapResponse) XXX_DiscardUnknown() { + xxx_messageInfo_ArithmeticTwapResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_ArithmeticTwapResponse proto.InternalMessageInfo + +type ArithmeticTwapToNowRequest struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + BaseAsset string `protobuf:"bytes,2,opt,name=base_asset,json=baseAsset,proto3" json:"base_asset,omitempty"` + QuoteAsset string `protobuf:"bytes,3,opt,name=quote_asset,json=quoteAsset,proto3" json:"quote_asset,omitempty"` + StartTime time.Time `protobuf:"bytes,4,opt,name=start_time,json=startTime,proto3,stdtime" json:"start_time" yaml:"start_time"` +} + +func (m *ArithmeticTwapToNowRequest) Reset() { *m = ArithmeticTwapToNowRequest{} } +func (m *ArithmeticTwapToNowRequest) String() string { return proto.CompactTextString(m) } +func (*ArithmeticTwapToNowRequest) ProtoMessage() {} +func (*ArithmeticTwapToNowRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_ebc93508b9209896, []int{2} +} +func (m *ArithmeticTwapToNowRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ArithmeticTwapToNowRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ArithmeticTwapToNowRequest.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 *ArithmeticTwapToNowRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_ArithmeticTwapToNowRequest.Merge(m, src) +} +func (m *ArithmeticTwapToNowRequest) XXX_Size() int { + return m.Size() +} +func (m *ArithmeticTwapToNowRequest) XXX_DiscardUnknown() { + xxx_messageInfo_ArithmeticTwapToNowRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_ArithmeticTwapToNowRequest proto.InternalMessageInfo + +func (m *ArithmeticTwapToNowRequest) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *ArithmeticTwapToNowRequest) GetBaseAsset() string { + if m != nil { + return m.BaseAsset + } + return "" +} + +func (m *ArithmeticTwapToNowRequest) GetQuoteAsset() string { + if m != nil { + return m.QuoteAsset + } + return "" +} + +func (m *ArithmeticTwapToNowRequest) GetStartTime() time.Time { + if m != nil { + return m.StartTime + } + return time.Time{} +} + +type ArithmeticTwapToNowResponse struct { + ArithmeticTwap github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,1,opt,name=arithmetic_twap,json=arithmeticTwap,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"arithmetic_twap" yaml:"arithmetic_twap"` +} + +func (m *ArithmeticTwapToNowResponse) Reset() { *m = ArithmeticTwapToNowResponse{} } +func (m *ArithmeticTwapToNowResponse) String() string { return proto.CompactTextString(m) } +func (*ArithmeticTwapToNowResponse) ProtoMessage() {} +func (*ArithmeticTwapToNowResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_ebc93508b9209896, []int{3} +} +func (m *ArithmeticTwapToNowResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ArithmeticTwapToNowResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ArithmeticTwapToNowResponse.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 *ArithmeticTwapToNowResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_ArithmeticTwapToNowResponse.Merge(m, src) +} +func (m *ArithmeticTwapToNowResponse) XXX_Size() int { + return m.Size() +} +func (m *ArithmeticTwapToNowResponse) XXX_DiscardUnknown() { + xxx_messageInfo_ArithmeticTwapToNowResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_ArithmeticTwapToNowResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*ArithmeticTwapRequest)(nil), "osmosis.twap.v2.ArithmeticTwapRequest") + proto.RegisterType((*ArithmeticTwapResponse)(nil), "osmosis.twap.v2.ArithmeticTwapResponse") + proto.RegisterType((*ArithmeticTwapToNowRequest)(nil), "osmosis.twap.v2.ArithmeticTwapToNowRequest") + proto.RegisterType((*ArithmeticTwapToNowResponse)(nil), "osmosis.twap.v2.ArithmeticTwapToNowResponse") +} + +func init() { proto.RegisterFile("osmosis/twap/v2/query.proto", fileDescriptor_ebc93508b9209896) } + +var fileDescriptor_ebc93508b9209896 = []byte{ + // 607 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x54, 0x3d, 0x6f, 0xd3, 0x40, + 0x18, 0xce, 0x85, 0x7e, 0x90, 0xab, 0xd4, 0x0a, 0x03, 0xa5, 0xb8, 0xd4, 0x2e, 0x16, 0x4a, 0x2b, + 0x68, 0x7d, 0xaa, 0xd9, 0x18, 0x90, 0x5a, 0x31, 0xc0, 0x82, 0x84, 0xd5, 0xa1, 0x62, 0xb1, 0x2e, + 0xf6, 0xe1, 0x5a, 0xc4, 0x3e, 0xc7, 0x77, 0x49, 0xc9, 0xca, 0x08, 0x4b, 0x25, 0xf6, 0xfe, 0x0b, + 0xfe, 0x43, 0x37, 0x2a, 0xb1, 0x20, 0x06, 0x83, 0x12, 0x7e, 0x41, 0x7e, 0x01, 0xba, 0x3b, 0x3b, + 0x24, 0x56, 0xa4, 0xb0, 0x21, 0x26, 0xfb, 0xde, 0xe7, 0x79, 0x9f, 0xf7, 0x79, 0xdf, 0xfb, 0x80, + 0x9b, 0x94, 0xc5, 0x94, 0x45, 0x0c, 0xf1, 0x33, 0x9c, 0xa2, 0x9e, 0x83, 0x3a, 0x5d, 0x92, 0xf5, + 0xed, 0x34, 0xa3, 0x9c, 0x6a, 0x6b, 0x05, 0x68, 0x0b, 0xd0, 0xee, 0x39, 0xfa, 0xad, 0x90, 0x86, + 0x54, 0x62, 0x48, 0xfc, 0x29, 0x9a, 0xde, 0x9c, 0xd6, 0x38, 0x68, 0x11, 0x8e, 0x0f, 0xe4, 0xc2, + 0xcb, 0x88, 0x4f, 0xb3, 0xa0, 0xe0, 0x59, 0x33, 0x79, 0x21, 0x49, 0x88, 0xa8, 0xa1, 0x38, 0x86, + 0x2f, 0x49, 0xa8, 0x85, 0x19, 0x19, 0x53, 0x7c, 0x1a, 0x25, 0x05, 0xfe, 0x70, 0x12, 0x97, 0x5e, + 0xc7, 0xac, 0x14, 0x87, 0x51, 0x82, 0x79, 0x44, 0x4b, 0xee, 0xbd, 0x90, 0xd2, 0xb0, 0x4d, 0x10, + 0x4e, 0x23, 0x84, 0x93, 0x84, 0x72, 0x09, 0x96, 0x95, 0xee, 0x16, 0xa8, 0x5c, 0xb5, 0xba, 0x6f, + 0x10, 0x4e, 0xfa, 0x25, 0xa4, 0x8a, 0x78, 0xaa, 0x53, 0xb5, 0x28, 0x20, 0xb3, 0x9a, 0xc5, 0xa3, + 0x98, 0x30, 0x8e, 0xe3, 0x54, 0x11, 0xac, 0x8b, 0x3a, 0xbc, 0x7d, 0x98, 0x45, 0xfc, 0x34, 0x26, + 0x3c, 0xf2, 0x8f, 0xcf, 0x70, 0xea, 0x92, 0x4e, 0x97, 0x30, 0xae, 0xdd, 0x81, 0xcb, 0x29, 0xa5, + 0x6d, 0x2f, 0x0a, 0x36, 0xc0, 0x36, 0xd8, 0x5d, 0x70, 0x97, 0xc4, 0xf2, 0x45, 0xa0, 0x6d, 0x41, + 0x28, 0xda, 0xf1, 0x30, 0x63, 0x84, 0x6f, 0xd4, 0xb7, 0xc1, 0x6e, 0xc3, 0x6d, 0x88, 0xc8, 0xa1, + 0x08, 0x68, 0x26, 0x5c, 0xe9, 0x74, 0x29, 0x2f, 0xf1, 0x6b, 0x12, 0x87, 0x32, 0xa4, 0x08, 0x27, + 0x10, 0x32, 0x8e, 0x33, 0xee, 0x09, 0x2f, 0x1b, 0x0b, 0xdb, 0x60, 0x77, 0xc5, 0xd1, 0x6d, 0x65, + 0xd4, 0x2e, 0x8d, 0xda, 0xc7, 0xa5, 0xd1, 0xa3, 0xad, 0xcb, 0xdc, 0xac, 0x8d, 0x72, 0xf3, 0x46, + 0x1f, 0xc7, 0xed, 0x27, 0xd6, 0x9f, 0x5c, 0xeb, 0xfc, 0x87, 0x09, 0xdc, 0x86, 0x0c, 0x08, 0xba, + 0xe6, 0xc2, 0xeb, 0x24, 0x09, 0x94, 0xee, 0xe2, 0x5c, 0xdd, 0xcd, 0xcb, 0xdc, 0x04, 0xa3, 0xdc, + 0x5c, 0x53, 0xba, 0x65, 0xa6, 0x52, 0x5d, 0x26, 0x49, 0x20, 0xa8, 0xd6, 0x47, 0x00, 0xd7, 0xab, + 0x03, 0x62, 0x29, 0x4d, 0x18, 0xd1, 0x3a, 0x70, 0x0d, 0x8f, 0x11, 0x4f, 0x9c, 0x12, 0x39, 0xa9, + 0xc6, 0xd1, 0x73, 0xe1, 0xf8, 0x7b, 0x6e, 0x36, 0xc3, 0x88, 0x9f, 0x76, 0x5b, 0xb6, 0x4f, 0xe3, + 0x62, 0x5b, 0x8a, 0xcf, 0x3e, 0x0b, 0xde, 0x22, 0xde, 0x4f, 0x09, 0xb3, 0x9f, 0x11, 0x7f, 0x94, + 0x9b, 0xeb, 0xca, 0x43, 0x45, 0xce, 0x72, 0x57, 0xf1, 0x54, 0x69, 0xeb, 0x0b, 0x80, 0xfa, 0xb4, + 0x9b, 0x63, 0xfa, 0x92, 0x9e, 0xfd, 0xbf, 0x7b, 0x66, 0x9d, 0x03, 0xb8, 0x39, 0xb3, 0xa3, 0x7f, + 0x36, 0x64, 0xe7, 0x73, 0x1d, 0x2e, 0xbe, 0x12, 0x77, 0x55, 0xfb, 0x00, 0xe0, 0xea, 0xb4, 0x39, + 0xad, 0x69, 0x57, 0x5e, 0x19, 0x7b, 0xe6, 0xf5, 0xd1, 0x77, 0xe6, 0xf2, 0x54, 0x83, 0xd6, 0xce, + 0xfb, 0xaf, 0xbf, 0x3e, 0xd5, 0xef, 0x6b, 0x26, 0xaa, 0xbe, 0x6d, 0x95, 0xca, 0x17, 0x00, 0xde, + 0x9c, 0x31, 0x29, 0xed, 0xd1, 0x9c, 0x4a, 0x93, 0x27, 0x44, 0xdf, 0xfb, 0x3b, 0x72, 0xe1, 0x6d, + 0x4f, 0x7a, 0x6b, 0x6a, 0x0f, 0xe6, 0x78, 0x93, 0x59, 0x47, 0x27, 0x97, 0x03, 0x03, 0x5c, 0x0d, + 0x0c, 0xf0, 0x73, 0x60, 0x80, 0xf3, 0xa1, 0x51, 0xbb, 0x1a, 0x1a, 0xb5, 0x6f, 0x43, 0xa3, 0xf6, + 0xfa, 0xe9, 0xc4, 0x1e, 0x15, 0x4a, 0xfb, 0x6d, 0xdc, 0x62, 0x63, 0xd9, 0xde, 0x81, 0x83, 0xde, + 0x29, 0x71, 0xbf, 0x1d, 0x91, 0x84, 0xa3, 0x9e, 0x23, 0x9f, 0x4b, 0x75, 0xb6, 0x96, 0xe4, 0xe7, + 0xf1, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0x24, 0x71, 0xc0, 0x60, 0xff, 0x05, 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 { + ArithmeticTwap(ctx context.Context, in *ArithmeticTwapRequest, opts ...grpc.CallOption) (*ArithmeticTwapResponse, error) + ArithmeticTwapToNow(ctx context.Context, in *ArithmeticTwapToNowRequest, opts ...grpc.CallOption) (*ArithmeticTwapToNowResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) ArithmeticTwap(ctx context.Context, in *ArithmeticTwapRequest, opts ...grpc.CallOption) (*ArithmeticTwapResponse, error) { + out := new(ArithmeticTwapResponse) + err := c.cc.Invoke(ctx, "/osmosis.twap.v2.Query/ArithmeticTwap", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) ArithmeticTwapToNow(ctx context.Context, in *ArithmeticTwapToNowRequest, opts ...grpc.CallOption) (*ArithmeticTwapToNowResponse, error) { + out := new(ArithmeticTwapToNowResponse) + err := c.cc.Invoke(ctx, "/osmosis.twap.v2.Query/ArithmeticTwapToNow", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + ArithmeticTwap(context.Context, *ArithmeticTwapRequest) (*ArithmeticTwapResponse, error) + ArithmeticTwapToNow(context.Context, *ArithmeticTwapToNowRequest) (*ArithmeticTwapToNowResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) ArithmeticTwap(ctx context.Context, req *ArithmeticTwapRequest) (*ArithmeticTwapResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ArithmeticTwap not implemented") +} +func (*UnimplementedQueryServer) ArithmeticTwapToNow(ctx context.Context, req *ArithmeticTwapToNowRequest) (*ArithmeticTwapToNowResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ArithmeticTwapToNow not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_ArithmeticTwap_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ArithmeticTwapRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).ArithmeticTwap(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/osmosis.twap.v2.Query/ArithmeticTwap", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).ArithmeticTwap(ctx, req.(*ArithmeticTwapRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_ArithmeticTwapToNow_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ArithmeticTwapToNowRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).ArithmeticTwapToNow(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/osmosis.twap.v2.Query/ArithmeticTwapToNow", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).ArithmeticTwapToNow(ctx, req.(*ArithmeticTwapToNowRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "osmosis.twap.v2.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "ArithmeticTwap", + Handler: _Query_ArithmeticTwap_Handler, + }, + { + MethodName: "ArithmeticTwapToNow", + Handler: _Query_ArithmeticTwapToNow_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "osmosis/twap/v2/query.proto", +} + +func (m *ArithmeticTwapRequest) 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 *ArithmeticTwapRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ArithmeticTwapRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.EndTime != nil { + n1, err1 := github_com_gogo_protobuf_types.StdTimeMarshalTo(*m.EndTime, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(*m.EndTime):]) + if err1 != nil { + return 0, err1 + } + i -= n1 + i = encodeVarintQuery(dAtA, i, uint64(n1)) + i-- + dAtA[i] = 0x2a + } + n2, err2 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.StartTime, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.StartTime):]) + if err2 != nil { + return 0, err2 + } + i -= n2 + i = encodeVarintQuery(dAtA, i, uint64(n2)) + i-- + dAtA[i] = 0x22 + if len(m.QuoteAsset) > 0 { + i -= len(m.QuoteAsset) + copy(dAtA[i:], m.QuoteAsset) + i = encodeVarintQuery(dAtA, i, uint64(len(m.QuoteAsset))) + i-- + dAtA[i] = 0x1a + } + if len(m.BaseAsset) > 0 { + i -= len(m.BaseAsset) + copy(dAtA[i:], m.BaseAsset) + i = encodeVarintQuery(dAtA, i, uint64(len(m.BaseAsset))) + 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 *ArithmeticTwapResponse) 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 *ArithmeticTwapResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ArithmeticTwapResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.ArithmeticTwap.Size() + i -= size + if _, err := m.ArithmeticTwap.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *ArithmeticTwapToNowRequest) 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 *ArithmeticTwapToNowRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ArithmeticTwapToNowRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + n3, err3 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.StartTime, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.StartTime):]) + if err3 != nil { + return 0, err3 + } + i -= n3 + i = encodeVarintQuery(dAtA, i, uint64(n3)) + i-- + dAtA[i] = 0x22 + if len(m.QuoteAsset) > 0 { + i -= len(m.QuoteAsset) + copy(dAtA[i:], m.QuoteAsset) + i = encodeVarintQuery(dAtA, i, uint64(len(m.QuoteAsset))) + i-- + dAtA[i] = 0x1a + } + if len(m.BaseAsset) > 0 { + i -= len(m.BaseAsset) + copy(dAtA[i:], m.BaseAsset) + i = encodeVarintQuery(dAtA, i, uint64(len(m.BaseAsset))) + 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 *ArithmeticTwapToNowResponse) 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 *ArithmeticTwapToNowResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ArithmeticTwapToNowResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.ArithmeticTwap.Size() + i -= size + if _, err := m.ArithmeticTwap.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 *ArithmeticTwapRequest) 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.BaseAsset) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = len(m.QuoteAsset) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.StartTime) + n += 1 + l + sovQuery(uint64(l)) + if m.EndTime != nil { + l = github_com_gogo_protobuf_types.SizeOfStdTime(*m.EndTime) + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *ArithmeticTwapResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.ArithmeticTwap.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *ArithmeticTwapToNowRequest) 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.BaseAsset) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = len(m.QuoteAsset) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.StartTime) + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *ArithmeticTwapToNowResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.ArithmeticTwap.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 *ArithmeticTwapRequest) 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: ArithmeticTwapRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ArithmeticTwapRequest: 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 BaseAsset", 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.BaseAsset = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field QuoteAsset", 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.QuoteAsset = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StartTime", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.StartTime, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EndTime", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.EndTime == nil { + m.EndTime = new(time.Time) + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(m.EndTime, 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 (m *ArithmeticTwapResponse) 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: ArithmeticTwapResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ArithmeticTwapResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ArithmeticTwap", 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.ArithmeticTwap.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 (m *ArithmeticTwapToNowRequest) 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: ArithmeticTwapToNowRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ArithmeticTwapToNowRequest: 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 BaseAsset", 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.BaseAsset = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field QuoteAsset", 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.QuoteAsset = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StartTime", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.StartTime, 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 (m *ArithmeticTwapToNowResponse) 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: ArithmeticTwapToNowResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ArithmeticTwapToNowResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ArithmeticTwap", 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.ArithmeticTwap.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/twap/client/v2queryproto/query.pb.gw.go b/x/twap/client/v2queryproto/query.pb.gw.go new file mode 100644 index 00000000000..5e9e118e57a --- /dev/null +++ b/x/twap/client/v2queryproto/query.pb.gw.go @@ -0,0 +1,254 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: osmosis/twap/v2/query.proto + +/* +Package v2queryproto is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package v2queryproto + +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_ArithmeticTwap_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_ArithmeticTwap_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ArithmeticTwapRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_ArithmeticTwap_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.ArithmeticTwap(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_ArithmeticTwap_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ArithmeticTwapRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_ArithmeticTwap_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.ArithmeticTwap(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_ArithmeticTwapToNow_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_ArithmeticTwapToNow_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ArithmeticTwapToNowRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_ArithmeticTwapToNow_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.ArithmeticTwapToNow(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_ArithmeticTwapToNow_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ArithmeticTwapToNowRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_ArithmeticTwapToNow_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.ArithmeticTwapToNow(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_ArithmeticTwap_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_ArithmeticTwap_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_ArithmeticTwap_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_ArithmeticTwapToNow_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_ArithmeticTwapToNow_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_ArithmeticTwapToNow_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_ArithmeticTwap_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_ArithmeticTwap_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_ArithmeticTwap_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_ArithmeticTwapToNow_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_ArithmeticTwapToNow_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_ArithmeticTwapToNow_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_ArithmeticTwap_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"osmosis", "twap", "v2", "ArithmeticTwap"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_ArithmeticTwapToNow_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"osmosis", "twap", "v2", "ArithmeticTwapToNow"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_ArithmeticTwap_0 = runtime.ForwardResponseMessage + + forward_Query_ArithmeticTwapToNow_0 = runtime.ForwardResponseMessage +) diff --git a/x/twap/twapmodule/module.go b/x/twap/twapmodule/module.go index b75a1b25c9f..fd4eff8c2c1 100644 --- a/x/twap/twapmodule/module.go +++ b/x/twap/twapmodule/module.go @@ -21,6 +21,7 @@ import ( twapcli "github.com/osmosis-labs/osmosis/v12/x/twap/client/cli" "github.com/osmosis-labs/osmosis/v12/x/twap/client/grpc" "github.com/osmosis-labs/osmosis/v12/x/twap/client/queryproto" + "github.com/osmosis-labs/osmosis/v12/x/twap/client/v2queryproto" "github.com/osmosis-labs/osmosis/v12/x/twap/types" ) @@ -55,7 +56,8 @@ func (b AppModuleBasic) RegisterRESTRoutes(ctx client.Context, r *mux.Router) { } func (b AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { - queryproto.RegisterQueryHandlerClient(context.Background(), mux, queryproto.NewQueryClient(clientCtx)) //nolint:errcheck + queryproto.RegisterQueryHandlerClient(context.Background(), mux, queryproto.NewQueryClient(clientCtx)) //nolint:errcheck + v2queryproto.RegisterQueryHandlerClient(context.Background(), mux, v2queryproto.NewQueryClient(clientCtx)) //nolint:errcheck } func (b AppModuleBasic) GetTxCmd() *cobra.Command { @@ -79,6 +81,7 @@ type AppModule struct { func (am AppModule) RegisterServices(cfg module.Configurator) { queryproto.RegisterQueryServer(cfg.QueryServer(), grpc.Querier{Q: twapclient.Querier{K: am.k}}) + v2queryproto.RegisterQueryServer(cfg.QueryServer(), grpc.QuerierV2{Q: twapclient.QuerierV2{K: am.k}}) } func NewAppModule(twapKeeper twap.Keeper) AppModule {