From 16e191282bb05bb0a9fc1661caa9b4ad8359fd3a Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 19 Dec 2022 23:37:58 -0500 Subject: [PATCH 01/15] feat(x/twap): geometric twap code gen query boilerplate --- proto/osmosis/twap/v1beta1/query.proto | 49 + x/twap/client/cli/query.go | 2 +- x/twap/client/grpc/grpc_query.go | 20 + x/twap/client/query_proto_wrap.go | 25 +- x/twap/client/queryproto/query.pb.go | 1435 ++++++++++++++++++++--- x/twap/client/queryproto/query.pb.gw.go | 166 +++ 6 files changed, 1517 insertions(+), 180 deletions(-) diff --git a/proto/osmosis/twap/v1beta1/query.proto b/proto/osmosis/twap/v1beta1/query.proto index 95374ece07c..618af945bcd 100644 --- a/proto/osmosis/twap/v1beta1/query.proto +++ b/proto/osmosis/twap/v1beta1/query.proto @@ -26,6 +26,14 @@ service Query { option deprecated = true; option (google.api.http).get = "/osmosis/twap/v1beta1/ArithmeticTwapToNow"; } + rpc GeometricTwap(GeometricTwapRequest) returns (GeometricTwapResponse) { + option (google.api.http).get = "/osmosis/twap/v1beta1/GeometricTwap"; + } + rpc GeometricTwapToNow(GeometricTwapToNowRequest) + returns (GeometricTwapToNowResponse) { + option deprecated = true; + option (google.api.http).get = "/osmosis/twap/v1beta1/GeometricTwapToNow"; + } } message ArithmeticTwapRequest { @@ -69,5 +77,46 @@ message ArithmeticTwapToNowResponse { ]; } +message GeometricTwapRequest { + 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 GeometricTwapResponse { + string arithmetic_twap = 1 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.moretags) = "yaml:\"geometric_twap\"", + (gogoproto.nullable) = false + ]; +} + +message GeometricTwapToNowRequest { + 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 GeometricTwapToNowResponse { + string geometric_twap = 1 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.moretags) = "yaml:\"geometric_twap\"", + (gogoproto.nullable) = false + ]; +} + message ParamsRequest {} message ParamsResponse { Params params = 1 [ (gogoproto.nullable) = false ]; } diff --git a/x/twap/client/cli/query.go b/x/twap/client/cli/query.go index 13bccff1e1a..ed1d1a570a8 100644 --- a/x/twap/client/cli/query.go +++ b/x/twap/client/cli/query.go @@ -26,7 +26,7 @@ func GetQueryCmd() *cobra.Command { // GetQueryTwapCommand returns multiplier of an asset by denom. func GetQueryTwapCommand() *cobra.Command { cmd := &cobra.Command{ - Use: "twap [poolid] [base denom] [start time] [end time]", + Use: "twap [type] [poolid] [base denom] [start time] [end time]", Short: "Query twap", Long: osmocli.FormatLongDescDirect(`Query twap for pool. Start time must be unix time. End time can be unix time or duration. diff --git a/x/twap/client/grpc/grpc_query.go b/x/twap/client/grpc/grpc_query.go index b40021bf7eb..8c655765a7f 100644 --- a/x/twap/client/grpc/grpc_query.go +++ b/x/twap/client/grpc/grpc_query.go @@ -50,3 +50,23 @@ func (q Querier) ArithmeticTwap(grpcCtx context.Context, return q.Q.ArithmeticTwap(ctx, *req) } +func (q Querier) GeometricTwapToNow(grpcCtx context.Context, + req *queryproto.GeometricTwapToNowRequest, +) (*queryproto.GeometricTwapToNowResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "empty request") + } + ctx := sdk.UnwrapSDKContext(grpcCtx) + return q.Q.GeometricTwapToNow(ctx, *req) +} + +func (q Querier) GeometricTwap(grpcCtx context.Context, + req *queryproto.GeometricTwapRequest, +) (*queryproto.GeometricTwapResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "empty request") + } + ctx := sdk.UnwrapSDKContext(grpcCtx) + return q.Q.GeometricTwap(ctx, *req) +} + diff --git a/x/twap/client/query_proto_wrap.go b/x/twap/client/query_proto_wrap.go index 1d03b34e579..0e4fbae362c 100644 --- a/x/twap/client/query_proto_wrap.go +++ b/x/twap/client/query_proto_wrap.go @@ -1,6 +1,7 @@ package client import ( + "errors" "time" sdk "github.com/cosmos/cosmos-sdk/types" @@ -16,7 +17,7 @@ type Querier struct { } func (q Querier) ArithmeticTwap(ctx sdk.Context, - req queryproto.ArithmeticTwapRequest, // nolint: staticcheck + req queryproto.ArithmeticTwapRequest, ) (*queryproto.ArithmeticTwapResponse, error) { if req.EndTime == nil { req.EndTime = &time.Time{} @@ -27,19 +28,35 @@ func (q Querier) ArithmeticTwap(ctx sdk.Context, twap, err := q.K.GetArithmeticTwap(ctx, req.PoolId, req.BaseAsset, req.QuoteAsset, req.StartTime, *req.EndTime) - // nolint: staticcheck return &queryproto.ArithmeticTwapResponse{ArithmeticTwap: twap}, err } func (q Querier) ArithmeticTwapToNow(ctx sdk.Context, - req queryproto.ArithmeticTwapToNowRequest, // nolint: staticcheck + req queryproto.ArithmeticTwapToNowRequest, ) (*queryproto.ArithmeticTwapToNowResponse, error) { twap, err := q.K.GetArithmeticTwapToNow(ctx, req.PoolId, req.BaseAsset, req.QuoteAsset, req.StartTime) - // nolint: staticcheck return &queryproto.ArithmeticTwapToNowResponse{ArithmeticTwap: twap}, err } +func (q Querier) GeometricTwap(ctx sdk.Context, + req queryproto.GeometricTwapRequest, +) (*queryproto.GeometricTwapResponse, error) { + if req.EndTime == nil { + req.EndTime = &time.Time{} + } + if (*req.EndTime == time.Time{}) { + *req.EndTime = ctx.BlockTime() + } + return nil, errors.New("not implemented") +} + +func (q Querier) GeometricTwapToNow(ctx sdk.Context, + req queryproto.GeometricTwapToNowRequest, +) (*queryproto.GeometricTwapToNowResponse, error) { + return nil, errors.New("not implemented") +} + func (q Querier) Params(ctx sdk.Context, req queryproto.ParamsRequest, ) (*queryproto.ParamsResponse, error) { diff --git a/x/twap/client/queryproto/query.pb.go b/x/twap/client/queryproto/query.pb.go index 5856b31e1df..42292669bbe 100644 --- a/x/twap/client/queryproto/query.pb.go +++ b/x/twap/client/queryproto/query.pb.go @@ -257,6 +257,224 @@ func (m *ArithmeticTwapToNowResponse) XXX_DiscardUnknown() { var xxx_messageInfo_ArithmeticTwapToNowResponse proto.InternalMessageInfo +type GeometricTwapRequest 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 *GeometricTwapRequest) Reset() { *m = GeometricTwapRequest{} } +func (m *GeometricTwapRequest) String() string { return proto.CompactTextString(m) } +func (*GeometricTwapRequest) ProtoMessage() {} +func (*GeometricTwapRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_141a22dba58615af, []int{4} +} +func (m *GeometricTwapRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GeometricTwapRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GeometricTwapRequest.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 *GeometricTwapRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_GeometricTwapRequest.Merge(m, src) +} +func (m *GeometricTwapRequest) XXX_Size() int { + return m.Size() +} +func (m *GeometricTwapRequest) XXX_DiscardUnknown() { + xxx_messageInfo_GeometricTwapRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_GeometricTwapRequest proto.InternalMessageInfo + +func (m *GeometricTwapRequest) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *GeometricTwapRequest) GetBaseAsset() string { + if m != nil { + return m.BaseAsset + } + return "" +} + +func (m *GeometricTwapRequest) GetQuoteAsset() string { + if m != nil { + return m.QuoteAsset + } + return "" +} + +func (m *GeometricTwapRequest) GetStartTime() time.Time { + if m != nil { + return m.StartTime + } + return time.Time{} +} + +func (m *GeometricTwapRequest) GetEndTime() *time.Time { + if m != nil { + return m.EndTime + } + return nil +} + +type GeometricTwapResponse 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:"geometric_twap"` +} + +func (m *GeometricTwapResponse) Reset() { *m = GeometricTwapResponse{} } +func (m *GeometricTwapResponse) String() string { return proto.CompactTextString(m) } +func (*GeometricTwapResponse) ProtoMessage() {} +func (*GeometricTwapResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_141a22dba58615af, []int{5} +} +func (m *GeometricTwapResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GeometricTwapResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GeometricTwapResponse.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 *GeometricTwapResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_GeometricTwapResponse.Merge(m, src) +} +func (m *GeometricTwapResponse) XXX_Size() int { + return m.Size() +} +func (m *GeometricTwapResponse) XXX_DiscardUnknown() { + xxx_messageInfo_GeometricTwapResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_GeometricTwapResponse proto.InternalMessageInfo + +type GeometricTwapToNowRequest 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 *GeometricTwapToNowRequest) Reset() { *m = GeometricTwapToNowRequest{} } +func (m *GeometricTwapToNowRequest) String() string { return proto.CompactTextString(m) } +func (*GeometricTwapToNowRequest) ProtoMessage() {} +func (*GeometricTwapToNowRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_141a22dba58615af, []int{6} +} +func (m *GeometricTwapToNowRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GeometricTwapToNowRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GeometricTwapToNowRequest.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 *GeometricTwapToNowRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_GeometricTwapToNowRequest.Merge(m, src) +} +func (m *GeometricTwapToNowRequest) XXX_Size() int { + return m.Size() +} +func (m *GeometricTwapToNowRequest) XXX_DiscardUnknown() { + xxx_messageInfo_GeometricTwapToNowRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_GeometricTwapToNowRequest proto.InternalMessageInfo + +func (m *GeometricTwapToNowRequest) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *GeometricTwapToNowRequest) GetBaseAsset() string { + if m != nil { + return m.BaseAsset + } + return "" +} + +func (m *GeometricTwapToNowRequest) GetQuoteAsset() string { + if m != nil { + return m.QuoteAsset + } + return "" +} + +func (m *GeometricTwapToNowRequest) GetStartTime() time.Time { + if m != nil { + return m.StartTime + } + return time.Time{} +} + +type GeometricTwapToNowResponse struct { + GeometricTwap github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,1,opt,name=geometric_twap,json=geometricTwap,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"geometric_twap" yaml:"geometric_twap"` +} + +func (m *GeometricTwapToNowResponse) Reset() { *m = GeometricTwapToNowResponse{} } +func (m *GeometricTwapToNowResponse) String() string { return proto.CompactTextString(m) } +func (*GeometricTwapToNowResponse) ProtoMessage() {} +func (*GeometricTwapToNowResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_141a22dba58615af, []int{7} +} +func (m *GeometricTwapToNowResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GeometricTwapToNowResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GeometricTwapToNowResponse.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 *GeometricTwapToNowResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_GeometricTwapToNowResponse.Merge(m, src) +} +func (m *GeometricTwapToNowResponse) XXX_Size() int { + return m.Size() +} +func (m *GeometricTwapToNowResponse) XXX_DiscardUnknown() { + xxx_messageInfo_GeometricTwapToNowResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_GeometricTwapToNowResponse proto.InternalMessageInfo + type ParamsRequest struct { } @@ -264,7 +482,7 @@ func (m *ParamsRequest) Reset() { *m = ParamsRequest{} } func (m *ParamsRequest) String() string { return proto.CompactTextString(m) } func (*ParamsRequest) ProtoMessage() {} func (*ParamsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_141a22dba58615af, []int{4} + return fileDescriptor_141a22dba58615af, []int{8} } func (m *ParamsRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -301,7 +519,7 @@ func (m *ParamsResponse) Reset() { *m = ParamsResponse{} } func (m *ParamsResponse) String() string { return proto.CompactTextString(m) } func (*ParamsResponse) ProtoMessage() {} func (*ParamsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_141a22dba58615af, []int{5} + return fileDescriptor_141a22dba58615af, []int{9} } func (m *ParamsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -342,6 +560,10 @@ func init() { proto.RegisterType((*ArithmeticTwapResponse)(nil), "osmosis.twap.v1beta1.ArithmeticTwapResponse") proto.RegisterType((*ArithmeticTwapToNowRequest)(nil), "osmosis.twap.v1beta1.ArithmeticTwapToNowRequest") proto.RegisterType((*ArithmeticTwapToNowResponse)(nil), "osmosis.twap.v1beta1.ArithmeticTwapToNowResponse") + proto.RegisterType((*GeometricTwapRequest)(nil), "osmosis.twap.v1beta1.GeometricTwapRequest") + proto.RegisterType((*GeometricTwapResponse)(nil), "osmosis.twap.v1beta1.GeometricTwapResponse") + proto.RegisterType((*GeometricTwapToNowRequest)(nil), "osmosis.twap.v1beta1.GeometricTwapToNowRequest") + proto.RegisterType((*GeometricTwapToNowResponse)(nil), "osmosis.twap.v1beta1.GeometricTwapToNowResponse") proto.RegisterType((*ParamsRequest)(nil), "osmosis.twap.v1beta1.ParamsRequest") proto.RegisterType((*ParamsResponse)(nil), "osmosis.twap.v1beta1.ParamsResponse") } @@ -349,50 +571,58 @@ func init() { func init() { proto.RegisterFile("osmosis/twap/v1beta1/query.proto", fileDescriptor_141a22dba58615af) } var fileDescriptor_141a22dba58615af = []byte{ - // 676 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x95, 0x4f, 0x4f, 0xd4, 0x4e, - 0x18, 0xc7, 0x77, 0x16, 0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ad, 0x4a, 0xa6, 0x25, 0xb4, 0x58, 0xcc, 0x34, 0x04, 0xf2, - 0x01, 0xc0, 0xcb, 0x05, 0x47, 0x02, 0xdd, 0xba, 0x48, 0xcf, 0xd3, 0xdf, 0x83, 0x51, 0xff, 0x83, - 0x0a, 0x8d, 0x7a, 0x5b, 0xa2, 0xae, 0xa0, 0x1b, 0x17, 0x41, 0x95, 0xa5, 0xaf, 0xcb, 0xa0, 0xf1, - 0xe4, 0xe0, 0xc8, 0x04, 0x87, 0x47, 0x26, 0xf8, 0x7e, 0x64, 0x82, 0xfd, 0x63, 0xb3, 0x74, 0x78, - 0x6c, 0x96, 0xbe, 0x1c, 0x9b, 0xa5, 0x67, 0x77, 0x4e, 0x1d, 0x4f, 0xed, 0xb8, 0xd6, 0xc1, 0x2d, - 0x36, 0xb0, 0xdf, 0xad, 0x6f, 0xb8, 0x2f, 0x55, 0x13, 0xbf, 0x13, 0x92, 0x98, 0xab, 0xff, 0x09, - 0xf5, 0x51, 0x55, 0xe4, 0x63, 0xe3, 0x67, 0x00, 0x00, 0x00, 0xff, 0xff, 0x99, 0x01, 0xcf, 0x37, - 0x02, 0x07, 0x00, 0x00, + // 811 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x96, 0x41, 0x4f, 0x1b, 0x47, + 0x14, 0xc7, 0x3d, 0x2e, 0x98, 0x7a, 0x10, 0x46, 0x9d, 0x02, 0x85, 0x05, 0x76, 0xad, 0x85, 0x22, + 0x17, 0xc3, 0x2e, 0x86, 0x9e, 0x50, 0x2f, 0x58, 0x95, 0x68, 0xa5, 0xaa, 0x6a, 0x2d, 0x54, 0x55, + 0xbd, 0x58, 0x63, 0x7b, 0xba, 0xac, 0xe2, 0xdd, 0x59, 0xef, 0x8e, 0x21, 0xbe, 0xe6, 0x94, 0x28, + 0x39, 0x20, 0x45, 0x91, 0x92, 0x43, 0xf2, 0x09, 0x72, 0xc8, 0xc7, 0xe0, 0x94, 0x20, 0xe5, 0x12, + 0xe5, 0xe0, 0x44, 0x90, 0x4f, 0xc0, 0x27, 0x88, 0x76, 0x66, 0xd6, 0xf1, 0x3a, 0x0b, 0x31, 0x52, + 0xa4, 0x08, 0x29, 0x27, 0x33, 0xf3, 0xfe, 0xef, 0xbd, 0xdf, 0xbc, 0xb7, 0x6f, 0x06, 0x98, 0xa7, + 0x81, 0x43, 0x03, 0x3b, 0x30, 0xd9, 0x21, 0xf6, 0xcc, 0x83, 0x52, 0x8d, 0x30, 0x5c, 0x32, 0x5b, + 0x6d, 0xe2, 0x77, 0x0c, 0xcf, 0xa7, 0x8c, 0xa2, 0x29, 0xa9, 0x30, 0x42, 0x85, 0x21, 0x15, 0xca, + 0x94, 0x45, 0x2d, 0xca, 0x05, 0x66, 0xf8, 0x97, 0xd0, 0x2a, 0x2b, 0x89, 0xd1, 0xc2, 0x45, 0xd5, + 0x27, 0x75, 0xea, 0x37, 0xa4, 0x4e, 0x4f, 0xd4, 0x59, 0xc4, 0x25, 0x61, 0x22, 0xa1, 0x51, 0xeb, + 0x5c, 0x64, 0xd6, 0x70, 0x40, 0x7a, 0x92, 0x3a, 0xb5, 0x5d, 0x69, 0x5f, 0xed, 0xb7, 0x73, 0xe0, + 0x9e, 0xca, 0xc3, 0x96, 0xed, 0x62, 0x66, 0xd3, 0x48, 0xbb, 0x60, 0x51, 0x6a, 0x35, 0x89, 0x89, + 0x3d, 0xdb, 0xc4, 0xae, 0x4b, 0x19, 0x37, 0x46, 0x99, 0xe6, 0xa4, 0x95, 0xaf, 0x6a, 0xed, 0xff, + 0x4d, 0xec, 0x76, 0x22, 0x93, 0x48, 0x52, 0x15, 0x27, 0x15, 0x0b, 0x69, 0xd2, 0x06, 0xbd, 0x98, + 0xed, 0x90, 0x80, 0x61, 0xc7, 0x13, 0x02, 0xfd, 0x49, 0x1a, 0x4e, 0xef, 0xf8, 0x36, 0xdb, 0x77, + 0x08, 0xb3, 0x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, 0x57, 0xd9, 0x55, 0x0b, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -410,6 +640,8 @@ type QueryClient interface { Params(ctx context.Context, in *ParamsRequest, opts ...grpc.CallOption) (*ParamsResponse, error) ArithmeticTwap(ctx context.Context, in *ArithmeticTwapRequest, opts ...grpc.CallOption) (*ArithmeticTwapResponse, error) ArithmeticTwapToNow(ctx context.Context, in *ArithmeticTwapToNowRequest, opts ...grpc.CallOption) (*ArithmeticTwapToNowResponse, error) + GeometricTwap(ctx context.Context, in *GeometricTwapRequest, opts ...grpc.CallOption) (*GeometricTwapResponse, error) + GeometricTwapToNow(ctx context.Context, in *GeometricTwapToNowRequest, opts ...grpc.CallOption) (*GeometricTwapToNowResponse, error) } type queryClient struct { @@ -448,11 +680,32 @@ func (c *queryClient) ArithmeticTwapToNow(ctx context.Context, in *ArithmeticTwa return out, nil } +func (c *queryClient) GeometricTwap(ctx context.Context, in *GeometricTwapRequest, opts ...grpc.CallOption) (*GeometricTwapResponse, error) { + out := new(GeometricTwapResponse) + err := c.cc.Invoke(ctx, "/osmosis.twap.v1beta1.Query/GeometricTwap", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// Deprecated: Do not use. +func (c *queryClient) GeometricTwapToNow(ctx context.Context, in *GeometricTwapToNowRequest, opts ...grpc.CallOption) (*GeometricTwapToNowResponse, error) { + out := new(GeometricTwapToNowResponse) + err := c.cc.Invoke(ctx, "/osmosis.twap.v1beta1.Query/GeometricTwapToNow", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // QueryServer is the server API for Query service. type QueryServer interface { Params(context.Context, *ParamsRequest) (*ParamsResponse, error) ArithmeticTwap(context.Context, *ArithmeticTwapRequest) (*ArithmeticTwapResponse, error) ArithmeticTwapToNow(context.Context, *ArithmeticTwapToNowRequest) (*ArithmeticTwapToNowResponse, error) + GeometricTwap(context.Context, *GeometricTwapRequest) (*GeometricTwapResponse, error) + GeometricTwapToNow(context.Context, *GeometricTwapToNowRequest) (*GeometricTwapToNowResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -468,6 +721,12 @@ func (*UnimplementedQueryServer) ArithmeticTwap(ctx context.Context, req *Arithm func (*UnimplementedQueryServer) ArithmeticTwapToNow(ctx context.Context, req *ArithmeticTwapToNowRequest) (*ArithmeticTwapToNowResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ArithmeticTwapToNow not implemented") } +func (*UnimplementedQueryServer) GeometricTwap(ctx context.Context, req *GeometricTwapRequest) (*GeometricTwapResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GeometricTwap not implemented") +} +func (*UnimplementedQueryServer) GeometricTwapToNow(ctx context.Context, req *GeometricTwapToNowRequest) (*GeometricTwapToNowResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GeometricTwapToNow not implemented") +} func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) @@ -527,6 +786,42 @@ func _Query_ArithmeticTwapToNow_Handler(srv interface{}, ctx context.Context, de return interceptor(ctx, in, info, handler) } +func _Query_GeometricTwap_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GeometricTwapRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).GeometricTwap(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/osmosis.twap.v1beta1.Query/GeometricTwap", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).GeometricTwap(ctx, req.(*GeometricTwapRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_GeometricTwapToNow_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GeometricTwapToNowRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).GeometricTwapToNow(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/osmosis.twap.v1beta1.Query/GeometricTwapToNow", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).GeometricTwapToNow(ctx, req.(*GeometricTwapToNowRequest)) + } + return interceptor(ctx, in, info, handler) +} + var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "osmosis.twap.v1beta1.Query", HandlerType: (*QueryServer)(nil), @@ -543,6 +838,14 @@ var _Query_serviceDesc = grpc.ServiceDesc{ MethodName: "ArithmeticTwapToNow", Handler: _Query_ArithmeticTwapToNow_Handler, }, + { + MethodName: "GeometricTwap", + Handler: _Query_GeometricTwap_Handler, + }, + { + MethodName: "GeometricTwapToNow", + Handler: _Query_GeometricTwapToNow_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "osmosis/twap/v1beta1/query.proto", @@ -724,7 +1027,7 @@ func (m *ArithmeticTwapToNowResponse) MarshalToSizedBuffer(dAtA []byte) (int, er return len(dAtA) - i, nil } -func (m *ParamsRequest) Marshal() (dAtA []byte, err error) { +func (m *GeometricTwapRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -734,20 +1037,57 @@ func (m *ParamsRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *ParamsRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *GeometricTwapRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *ParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *GeometricTwapRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l + if m.EndTime != nil { + n4, err4 := github_com_gogo_protobuf_types.StdTimeMarshalTo(*m.EndTime, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(*m.EndTime):]) + if err4 != nil { + return 0, err4 + } + i -= n4 + i = encodeVarintQuery(dAtA, i, uint64(n4)) + i-- + dAtA[i] = 0x2a + } + n5, err5 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.StartTime, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.StartTime):]) + if err5 != nil { + return 0, err5 + } + i -= n5 + i = encodeVarintQuery(dAtA, i, uint64(n5)) + 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 *ParamsResponse) Marshal() (dAtA []byte, err error) { +func (m *GeometricTwapResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -757,137 +1097,882 @@ func (m *ParamsResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *ParamsResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *GeometricTwapResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *ParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *GeometricTwapResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l { - size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { + size := m.ArithmeticTwap.Size() + i -= size + if _, err := m.ArithmeticTwap.MarshalTo(dAtA[i:]); err != nil { return 0, err } - i -= size - 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)) + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *GeometricTwapToNowRequest) 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 *GeometricTwapToNowRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GeometricTwapToNowRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + n6, err6 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.StartTime, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.StartTime):]) + if err6 != nil { + return 0, err6 + } + i -= n6 + i = encodeVarintQuery(dAtA, i, uint64(n6)) + 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 *GeometricTwapToNowResponse) 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 *GeometricTwapToNowResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GeometricTwapToNowResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.GeometricTwap.Size() + i -= size + if _, err := m.GeometricTwap.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 *ParamsRequest) 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 *ParamsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *ParamsResponse) 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 *ParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + 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 (m *GeometricTwapRequest) 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 *GeometricTwapResponse) 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 *GeometricTwapToNowRequest) 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 *GeometricTwapToNowResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.GeometricTwap.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *ParamsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *ParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.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 + } } - 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 + if iNdEx > l { + return io.ErrUnexpectedEOF } - var l int - _ = l - l = m.ArithmeticTwap.Size() - n += 1 + l + sovQuery(uint64(l)) - return n + return nil } - -func (m *ParamsRequest) Size() (n int) { - if m == nil { - return 0 +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 + } } - var l int - _ = l - return n -} -func (m *ParamsResponse) Size() (n int) { - if m == nil { - return 0 + if iNdEx > l { + return io.ErrUnexpectedEOF } - var l int - _ = l - l = m.Params.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)))) + return nil } -func (m *ArithmeticTwapRequest) Unmarshal(dAtA []byte) error { +func (m *GeometricTwapRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -910,10 +1995,10 @@ func (m *ArithmeticTwapRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: ArithmeticTwapRequest: wiretype end group for non-group") + return fmt.Errorf("proto: GeometricTwapRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: ArithmeticTwapRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: GeometricTwapRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -1089,7 +2174,7 @@ func (m *ArithmeticTwapRequest) Unmarshal(dAtA []byte) error { } return nil } -func (m *ArithmeticTwapResponse) Unmarshal(dAtA []byte) error { +func (m *GeometricTwapResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1112,10 +2197,10 @@ func (m *ArithmeticTwapResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: ArithmeticTwapResponse: wiretype end group for non-group") + return fmt.Errorf("proto: GeometricTwapResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: ArithmeticTwapResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: GeometricTwapResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -1173,7 +2258,7 @@ func (m *ArithmeticTwapResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *ArithmeticTwapToNowRequest) Unmarshal(dAtA []byte) error { +func (m *GeometricTwapToNowRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1196,10 +2281,10 @@ func (m *ArithmeticTwapToNowRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: ArithmeticTwapToNowRequest: wiretype end group for non-group") + return fmt.Errorf("proto: GeometricTwapToNowRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: ArithmeticTwapToNowRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: GeometricTwapToNowRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -1339,7 +2424,7 @@ func (m *ArithmeticTwapToNowRequest) Unmarshal(dAtA []byte) error { } return nil } -func (m *ArithmeticTwapToNowResponse) Unmarshal(dAtA []byte) error { +func (m *GeometricTwapToNowResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1362,15 +2447,15 @@ func (m *ArithmeticTwapToNowResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: ArithmeticTwapToNowResponse: wiretype end group for non-group") + return fmt.Errorf("proto: GeometricTwapToNowResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: ArithmeticTwapToNowResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: GeometricTwapToNowResponse: 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) + return fmt.Errorf("proto: wrong wireType = %d for field GeometricTwap", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1398,7 +2483,7 @@ func (m *ArithmeticTwapToNowResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.ArithmeticTwap.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.GeometricTwap.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/twap/client/queryproto/query.pb.gw.go b/x/twap/client/queryproto/query.pb.gw.go index b9f76d10fb9..911f16155ac 100644 --- a/x/twap/client/queryproto/query.pb.gw.go +++ b/x/twap/client/queryproto/query.pb.gw.go @@ -123,6 +123,78 @@ func local_request_Query_ArithmeticTwapToNow_0(ctx context.Context, marshaler ru } +var ( + filter_Query_GeometricTwap_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_GeometricTwap_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GeometricTwapRequest + 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_GeometricTwap_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.GeometricTwap(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_GeometricTwap_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GeometricTwapRequest + 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_GeometricTwap_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.GeometricTwap(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_GeometricTwapToNow_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_GeometricTwapToNow_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GeometricTwapToNowRequest + 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_GeometricTwapToNow_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.GeometricTwapToNow(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_GeometricTwapToNow_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GeometricTwapToNowRequest + 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_GeometricTwapToNow_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.GeometricTwapToNow(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. @@ -198,6 +270,52 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) + mux.Handle("GET", pattern_Query_GeometricTwap_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_GeometricTwap_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_GeometricTwap_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_GeometricTwapToNow_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_GeometricTwapToNow_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_GeometricTwapToNow_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -299,6 +417,46 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) + mux.Handle("GET", pattern_Query_GeometricTwap_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_GeometricTwap_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_GeometricTwap_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_GeometricTwapToNow_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_GeometricTwapToNow_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_GeometricTwapToNow_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -308,6 +466,10 @@ var ( pattern_Query_ArithmeticTwap_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"osmosis", "twap", "v1beta1", "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", "v1beta1", "ArithmeticTwapToNow"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_GeometricTwap_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"osmosis", "twap", "v1beta1", "GeometricTwap"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_GeometricTwapToNow_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"osmosis", "twap", "v1beta1", "GeometricTwapToNow"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( @@ -316,4 +478,8 @@ var ( forward_Query_ArithmeticTwap_0 = runtime.ForwardResponseMessage forward_Query_ArithmeticTwapToNow_0 = runtime.ForwardResponseMessage + + forward_Query_GeometricTwap_0 = runtime.ForwardResponseMessage + + forward_Query_GeometricTwapToNow_0 = runtime.ForwardResponseMessage ) From 2f91cab6deb3eb931dfec3fb07f338fdd5e69e12 Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 19 Dec 2022 23:39:59 -0500 Subject: [PATCH 02/15] revert cli change --- x/twap/client/cli/query.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/twap/client/cli/query.go b/x/twap/client/cli/query.go index ed1d1a570a8..13bccff1e1a 100644 --- a/x/twap/client/cli/query.go +++ b/x/twap/client/cli/query.go @@ -26,7 +26,7 @@ func GetQueryCmd() *cobra.Command { // GetQueryTwapCommand returns multiplier of an asset by denom. func GetQueryTwapCommand() *cobra.Command { cmd := &cobra.Command{ - Use: "twap [type] [poolid] [base denom] [start time] [end time]", + Use: "twap [poolid] [base denom] [start time] [end time]", Short: "Query twap", Long: osmocli.FormatLongDescDirect(`Query twap for pool. Start time must be unix time. End time can be unix time or duration. From 0e889e2c2c2607b2c2f4127d4cb2991e0d196dc7 Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 20 Dec 2022 00:17:52 -0500 Subject: [PATCH 03/15] query gen --- proto/osmosis/twap/v1beta1/query.yml | 12 +++++++++++ x/twap/client/grpc/grpc_query.go | 32 ++++++++++++++-------------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/proto/osmosis/twap/v1beta1/query.yml b/proto/osmosis/twap/v1beta1/query.yml index 6763392aaaf..514bb092e9d 100644 --- a/proto/osmosis/twap/v1beta1/query.yml +++ b/proto/osmosis/twap/v1beta1/query.yml @@ -15,6 +15,18 @@ queries: query_func: "k.GetArithmeticTwapToNow" cli: cmd: "ArithmeticTwapToNow" + GeometricTwap: + proto_wrapper: + default_values: + Req.end_time: "ctx.BlockTime()" + query_func: "k.GetGeometricTwap" + cli: + cmd: "ArithmeticTwap" + GeometricTwapToNow: + proto_wrapper: + query_func: "k.GetGeometricTwapToNow" + cli: + cmd: "GeometricTwapToNow" Params: proto_wrapper: query_func: "k.GetParams" diff --git a/x/twap/client/grpc/grpc_query.go b/x/twap/client/grpc/grpc_query.go index 8c655765a7f..49277d1fc3c 100644 --- a/x/twap/client/grpc/grpc_query.go +++ b/x/twap/client/grpc/grpc_query.go @@ -30,43 +30,43 @@ func (q Querier) Params(grpcCtx context.Context, return q.Q.Params(ctx, *req) } -func (q Querier) ArithmeticTwapToNow(grpcCtx context.Context, - req *queryproto.ArithmeticTwapToNowRequest, -) (*queryproto.ArithmeticTwapToNowResponse, error) { +func (q Querier) GeometricTwapToNow(grpcCtx context.Context, + req *queryproto.GeometricTwapToNowRequest, +) (*queryproto.GeometricTwapToNowResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } ctx := sdk.UnwrapSDKContext(grpcCtx) - return q.Q.ArithmeticTwapToNow(ctx, *req) + return q.Q.GeometricTwapToNow(ctx, *req) } -func (q Querier) ArithmeticTwap(grpcCtx context.Context, - req *queryproto.ArithmeticTwapRequest, -) (*queryproto.ArithmeticTwapResponse, error) { +func (q Querier) GeometricTwap(grpcCtx context.Context, + req *queryproto.GeometricTwapRequest, +) (*queryproto.GeometricTwapResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } ctx := sdk.UnwrapSDKContext(grpcCtx) - return q.Q.ArithmeticTwap(ctx, *req) + return q.Q.GeometricTwap(ctx, *req) } -func (q Querier) GeometricTwapToNow(grpcCtx context.Context, - req *queryproto.GeometricTwapToNowRequest, -) (*queryproto.GeometricTwapToNowResponse, error) { +func (q Querier) ArithmeticTwapToNow(grpcCtx context.Context, + req *queryproto.ArithmeticTwapToNowRequest, +) (*queryproto.ArithmeticTwapToNowResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } ctx := sdk.UnwrapSDKContext(grpcCtx) - return q.Q.GeometricTwapToNow(ctx, *req) + return q.Q.ArithmeticTwapToNow(ctx, *req) } -func (q Querier) GeometricTwap(grpcCtx context.Context, - req *queryproto.GeometricTwapRequest, -) (*queryproto.GeometricTwapResponse, error) { +func (q Querier) ArithmeticTwap(grpcCtx context.Context, + req *queryproto.ArithmeticTwapRequest, +) (*queryproto.ArithmeticTwapResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } ctx := sdk.UnwrapSDKContext(grpcCtx) - return q.Q.GeometricTwap(ctx, *req) + return q.Q.ArithmeticTwap(ctx, *req) } From b463786ca24c6bb9057f1e8ae08d1534983f250c Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 20 Dec 2022 20:21:20 -0500 Subject: [PATCH 04/15] wire up API --- proto/osmosis/twap/v1beta1/query.proto | 2 +- x/twap/client/query_proto_wrap.go | 10 ++- x/twap/client/queryproto/query.pb.go | 112 ++++++++++++------------- 3 files changed, 64 insertions(+), 60 deletions(-) diff --git a/proto/osmosis/twap/v1beta1/query.proto b/proto/osmosis/twap/v1beta1/query.proto index 618af945bcd..50bddf24c3d 100644 --- a/proto/osmosis/twap/v1beta1/query.proto +++ b/proto/osmosis/twap/v1beta1/query.proto @@ -93,7 +93,7 @@ message GeometricTwapRequest { ]; } message GeometricTwapResponse { - string arithmetic_twap = 1 [ + string geometric_twap = 1 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.moretags) = "yaml:\"geometric_twap\"", (gogoproto.nullable) = false diff --git a/x/twap/client/query_proto_wrap.go b/x/twap/client/query_proto_wrap.go index 0e4fbae362c..ab5eb51f1af 100644 --- a/x/twap/client/query_proto_wrap.go +++ b/x/twap/client/query_proto_wrap.go @@ -1,7 +1,6 @@ package client import ( - "errors" "time" sdk "github.com/cosmos/cosmos-sdk/types" @@ -48,13 +47,18 @@ func (q Querier) GeometricTwap(ctx sdk.Context, if (*req.EndTime == time.Time{}) { *req.EndTime = ctx.BlockTime() } - return nil, errors.New("not implemented") + + twap, err := q.K.GetGeometricTwap(ctx, req.PoolId, req.BaseAsset, req.QuoteAsset, req.StartTime, *req.EndTime) + + return &queryproto.GeometricTwapResponse{GeometricTwap: twap}, err } func (q Querier) GeometricTwapToNow(ctx sdk.Context, req queryproto.GeometricTwapToNowRequest, ) (*queryproto.GeometricTwapToNowResponse, error) { - return nil, errors.New("not implemented") + twap, err := q.K.GetGeometricTwapToNow(ctx, req.PoolId, req.BaseAsset, req.QuoteAsset, req.StartTime) + + return &queryproto.GeometricTwapToNowResponse{GeometricTwap: twap}, err } func (q Querier) Params(ctx sdk.Context, diff --git a/x/twap/client/queryproto/query.pb.go b/x/twap/client/queryproto/query.pb.go index 42292669bbe..59e4c34b760 100644 --- a/x/twap/client/queryproto/query.pb.go +++ b/x/twap/client/queryproto/query.pb.go @@ -334,7 +334,7 @@ func (m *GeometricTwapRequest) GetEndTime() *time.Time { } type GeometricTwapResponse 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:"geometric_twap"` + GeometricTwap github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,1,opt,name=geometric_twap,json=geometricTwap,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"geometric_twap" yaml:"geometric_twap"` } func (m *GeometricTwapResponse) Reset() { *m = GeometricTwapResponse{} } @@ -571,58 +571,58 @@ func init() { func init() { proto.RegisterFile("osmosis/twap/v1beta1/query.proto", fileDescriptor_141a22dba58615af) } var fileDescriptor_141a22dba58615af = []byte{ - // 811 bytes of a gzipped FileDescriptorProto + // 805 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x96, 0x41, 0x4f, 0x1b, 0x47, 0x14, 0xc7, 0x3d, 0x2e, 0x98, 0x7a, 0x10, 0x46, 0x9d, 0x02, 0x85, 0x05, 0x76, 0xad, 0x85, 0x22, - 0x17, 0xc3, 0x2e, 0x86, 0x9e, 0x50, 0x2f, 0x58, 0x95, 0x68, 0xa5, 0xaa, 0x6a, 0x2d, 0x54, 0x55, - 0xbd, 0x58, 0x63, 0x7b, 0xba, 0xac, 0xe2, 0xdd, 0x59, 0xef, 0x8e, 0x21, 0xbe, 0xe6, 0x94, 0x28, - 0x39, 0x20, 0x45, 0x91, 0x92, 0x43, 0xf2, 0x09, 0x72, 0xc8, 0xc7, 0xe0, 0x94, 0x20, 0xe5, 0x12, - 0xe5, 0xe0, 0x44, 0x90, 0x4f, 0xc0, 0x27, 0x88, 0x76, 0x66, 0xd6, 0xf1, 0x3a, 0x0b, 0x31, 0x52, - 0xa4, 0x08, 0x29, 0x27, 0x33, 0xf3, 0xfe, 0xef, 0xbd, 0xdf, 0xbc, 0xb7, 0x6f, 0x06, 0x98, 0xa7, - 0x81, 0x43, 0x03, 0x3b, 0x30, 0xd9, 0x21, 0xf6, 0xcc, 0x83, 0x52, 0x8d, 0x30, 0x5c, 0x32, 0x5b, - 0x6d, 0xe2, 0x77, 0x0c, 0xcf, 0xa7, 0x8c, 0xa2, 0x29, 0xa9, 0x30, 0x42, 0x85, 0x21, 0x15, 0xca, - 0x94, 0x45, 0x2d, 0xca, 0x05, 0x66, 0xf8, 0x97, 0xd0, 0x2a, 0x2b, 0x89, 0xd1, 0xc2, 0x45, 0xd5, - 0x27, 0x75, 0xea, 0x37, 0xa4, 0x4e, 0x4f, 0xd4, 0x59, 0xc4, 0x25, 0x61, 0x22, 0xa1, 0x51, 0xeb, - 0x5c, 0x64, 0xd6, 0x70, 0x40, 0x7a, 0x92, 0x3a, 0xb5, 0x5d, 0x69, 0x5f, 0xed, 0xb7, 0x73, 0xe0, - 0x9e, 0xca, 0xc3, 0x96, 0xed, 0x62, 0x66, 0xd3, 0x48, 0xbb, 0x60, 0x51, 0x6a, 0x35, 0x89, 0x89, - 0x3d, 0xdb, 0xc4, 0xae, 0x4b, 0x19, 0x37, 0x46, 0x99, 0xe6, 0xa4, 0x95, 0xaf, 0x6a, 0xed, 0xff, - 0x4d, 0xec, 0x76, 0x22, 0x93, 0x48, 0x52, 0x15, 0x27, 0x15, 0x0b, 0x69, 0xd2, 0x06, 0xbd, 0x98, - 0xed, 0x90, 0x80, 0x61, 0xc7, 0x13, 0x02, 0xfd, 0x49, 0x1a, 0x4e, 0xef, 0xf8, 0x36, 0xdb, 0x77, - 0x08, 0xb3, 0xeb, 0x7b, 0x87, 0xd8, 0xab, 0x90, 0x56, 0x9b, 0x04, 0x0c, 0xfd, 0x00, 0xc7, 0x3c, - 0x4a, 0x9b, 0x55, 0xbb, 0x31, 0x0b, 0xf2, 0xa0, 0x30, 0x52, 0xc9, 0x84, 0xcb, 0xdf, 0x1b, 0x68, - 0x11, 0xc2, 0xf0, 0x38, 0x55, 0x1c, 0x04, 0x84, 0xcd, 0xa6, 0xf3, 0xa0, 0x90, 0xad, 0x64, 0xc3, - 0x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20, 0x87, 0x7c, 0x0c, 0x4e, 0x09, 0x52, 0x2e, + 0x51, 0x0e, 0x4e, 0x04, 0xf9, 0x04, 0x7c, 0x82, 0x68, 0x67, 0x66, 0x1d, 0xaf, 0xb3, 0x22, 0xe6, + 0x84, 0x90, 0x72, 0x32, 0xf3, 0xde, 0xff, 0xbd, 0xf7, 0x9b, 0x37, 0xfb, 0x66, 0x80, 0x45, 0x1a, + 0xba, 0x34, 0x74, 0x42, 0x93, 0x1d, 0x63, 0xdf, 0x3c, 0xaa, 0xd4, 0x09, 0xc3, 0x15, 0xb3, 0xdd, + 0x21, 0x41, 0xd7, 0xf0, 0x03, 0xca, 0x28, 0x9a, 0x91, 0x0a, 0x23, 0x52, 0x18, 0x52, 0xa1, 0xcc, + 0xd8, 0xd4, 0xa6, 0x5c, 0x60, 0x46, 0x7f, 0x09, 0xad, 0xb2, 0x96, 0x9a, 0x2d, 0x5a, 0xd4, 0x02, + 0xd2, 0xa0, 0x41, 0x53, 0xea, 0xf4, 0x54, 0x9d, 0x4d, 0x3c, 0x12, 0x15, 0x12, 0x1a, 0xb5, 0xc1, + 0x45, 0x66, 0x1d, 0x87, 0xa4, 0x2f, 0x69, 0x50, 0xc7, 0x93, 0xfe, 0xf5, 0x41, 0x3f, 0x07, 0xee, + 0xab, 0x7c, 0x6c, 0x3b, 0x1e, 0x66, 0x0e, 0x8d, 0xb5, 0x4b, 0x36, 0xa5, 0x76, 0x8b, 0x98, 0xd8, + 0x77, 0x4c, 0xec, 0x79, 0x94, 0x71, 0x67, 0x5c, 0x69, 0x41, 0x7a, 0xf9, 0xaa, 0xde, 0xf9, 0xdb, + 0xc4, 0x5e, 0x37, 0x76, 0x89, 0x22, 0x35, 0xb1, 0x53, 0xb1, 0x90, 0x2e, 0x6d, 0x38, 0x8a, 0x39, + 0x2e, 0x09, 0x19, 0x76, 0x7d, 0x21, 0xd0, 0x9f, 0x64, 0xe1, 0xec, 0x5e, 0xe0, 0xb0, 0x43, 0x97, + 0x30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x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1108,9 +1108,9 @@ func (m *GeometricTwapResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { var l int _ = l { - size := m.ArithmeticTwap.Size() + size := m.GeometricTwap.Size() i -= size - if _, err := m.ArithmeticTwap.MarshalTo(dAtA[i:]); err != nil { + if _, err := m.GeometricTwap.MarshalTo(dAtA[i:]); err != nil { return 0, err } i = encodeVarintQuery(dAtA, i, uint64(size)) @@ -1372,7 +1372,7 @@ func (m *GeometricTwapResponse) Size() (n int) { } var l int _ = l - l = m.ArithmeticTwap.Size() + l = m.GeometricTwap.Size() n += 1 + l + sovQuery(uint64(l)) return n } @@ -2205,7 +2205,7 @@ func (m *GeometricTwapResponse) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ArithmeticTwap", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field GeometricTwap", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -2233,7 +2233,7 @@ func (m *GeometricTwapResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.ArithmeticTwap.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.GeometricTwap.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex From 8af2e1bff85c892e28b8e99ae3f332e30b1adc26 Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 20 Dec 2022 20:26:09 -0500 Subject: [PATCH 05/15] test --- x/twap/client/query_proto_wrap_test.go | 40 +++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/x/twap/client/query_proto_wrap_test.go b/x/twap/client/query_proto_wrap_test.go index d66a01b28dd..8353588f0fc 100644 --- a/x/twap/client/query_proto_wrap_test.go +++ b/x/twap/client/query_proto_wrap_test.go @@ -151,7 +151,7 @@ func (suite *QueryTestSuite) TestQueryTwap() { for _, tc := range testCases { tc := tc - suite.Run(tc.name, func() { + suite.Run(tc.name+" arithmetic", func() { client := client.Querier{K: *suite.App.TwapKeeper} startTime := validStartTime @@ -188,5 +188,43 @@ func (suite *QueryTestSuite) TestQueryTwap() { suite.Require().Equal(tc.result, resultToNow.ArithmeticTwap.String()) } }) + + suite.Run(tc.name+" geometric", func() { + client := client.Querier{K: *suite.App.TwapKeeper} + + startTime := validStartTime + if tc.startTimeOverwrite != nil { + startTime = *tc.startTimeOverwrite + } + + result, err := client.GeometricTwap(ctx, queryproto.GeometricTwapRequest{ + PoolId: tc.poolId, + BaseAsset: tc.baseAssetDenom, + QuoteAsset: tc.quoteAssetDenom, + StartTime: startTime, + EndTime: tc.endTime, + }) + + if tc.expectErr { + suite.Require().Error(err, "expected error - GeometricTwap") + } else { + suite.Require().NoError(err, "unexpected error - GeometricTwap") + suite.Require().Equal(tc.result, result.GeometricTwap.String()) + } + + resultToNow, err := client.GeometricTwapToNow(ctx, queryproto.GeometricTwapToNowRequest{ + PoolId: tc.poolId, + BaseAsset: tc.baseAssetDenom, + QuoteAsset: tc.quoteAssetDenom, + StartTime: startTime, + }) + + if tc.expectErr { + suite.Require().Error(err, "expected error - GeometricTwapToNow") + } else { + suite.Require().NoError(err, "unexpected error - GeometricTwapToNow") + suite.Require().Equal(tc.result, resultToNow.GeometricTwap.String()) + } + }) } } From f91681f5659b5c3de6d491cf6963e071f6ec2a66 Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 20 Dec 2022 20:50:01 -0500 Subject: [PATCH 06/15] fix --- x/twap/client/query_proto_wrap_test.go | 28 ++++++++++++++++---------- x/twap/export_test.go | 2 -- x/twap/logic.go | 17 +++++----------- x/twap/logic_test.go | 7 ++++--- x/twap/strategy_test.go | 26 ++++++++++++++++++++++++ 5 files changed, 52 insertions(+), 28 deletions(-) diff --git a/x/twap/client/query_proto_wrap_test.go b/x/twap/client/query_proto_wrap_test.go index 8353588f0fc..e41256d94c4 100644 --- a/x/twap/client/query_proto_wrap_test.go +++ b/x/twap/client/query_proto_wrap_test.go @@ -49,14 +49,15 @@ func (suite *QueryTestSuite) TestQueryTwap() { ) testCases := []struct { - name string - poolId uint64 - baseAssetDenom string - quoteAssetDenom string - startTimeOverwrite *time.Time - endTime *time.Time - expectErr bool - result string + name string + poolId uint64 + baseAssetDenom string + quoteAssetDenom string + startTimeOverwrite *time.Time + endTime *time.Time + expectErr bool + result string + geometricResultOverwrite string }{ { name: "non-existant pool", @@ -108,7 +109,8 @@ func (suite *QueryTestSuite) TestQueryTwap() { quoteAssetDenom: "tokenD", endTime: &newBlockTime, - result: sdk.MustNewDecFromStr("1.333333330000000000").String(), + result: sdk.MustNewDecFromStr("1.333333330000000000").String(), + geometricResultOverwrite: sdk.MustNewDecFromStr("1.333333333333333333").String(), }, { name: "tokenD in terms of tokenE (1)", @@ -196,6 +198,10 @@ func (suite *QueryTestSuite) TestQueryTwap() { if tc.startTimeOverwrite != nil { startTime = *tc.startTimeOverwrite } + expectedGeometricResult := tc.result + if tc.geometricResultOverwrite != "" { + expectedGeometricResult = tc.geometricResultOverwrite + } result, err := client.GeometricTwap(ctx, queryproto.GeometricTwapRequest{ PoolId: tc.poolId, @@ -209,7 +215,7 @@ func (suite *QueryTestSuite) TestQueryTwap() { suite.Require().Error(err, "expected error - GeometricTwap") } else { suite.Require().NoError(err, "unexpected error - GeometricTwap") - suite.Require().Equal(tc.result, result.GeometricTwap.String()) + suite.Require().Equal(expectedGeometricResult, result.GeometricTwap.String()) } resultToNow, err := client.GeometricTwapToNow(ctx, queryproto.GeometricTwapToNowRequest{ @@ -223,7 +229,7 @@ func (suite *QueryTestSuite) TestQueryTwap() { suite.Require().Error(err, "expected error - GeometricTwapToNow") } else { suite.Require().NoError(err, "unexpected error - GeometricTwapToNow") - suite.Require().Equal(tc.result, resultToNow.GeometricTwap.String()) + suite.Require().Equal(expectedGeometricResult, resultToNow.GeometricTwap.String()) } }) } diff --git a/x/twap/export_test.go b/x/twap/export_test.go index d9483f059fb..1ccbbd47ab8 100644 --- a/x/twap/export_test.go +++ b/x/twap/export_test.go @@ -15,8 +15,6 @@ type ( GeometricTwapStrategy = geometric ) -var GeometricTwapMathBase = geometricTwapMathBase - func (k Keeper) StoreNewRecord(ctx sdk.Context, record types.TwapRecord) { k.storeNewRecord(ctx, record) } diff --git a/x/twap/logic.go b/x/twap/logic.go index 63c824c6ef0..f23db2e2f4b 100644 --- a/x/twap/logic.go +++ b/x/twap/logic.go @@ -11,15 +11,6 @@ import ( "github.com/osmosis-labs/osmosis/v13/x/twap/types" ) -// geometricTwapMathBase is the base used for geometric twap calculation -// in logarithm and power math functions. -// See twapLog and computeGeometricTwap functions for more details. -var ( - geometricTwapMathBase = sdk.NewDec(2) - // TODO: analyze choice. - geometricTwapPowPrecision = sdk.MustNewDecFromStr("0.00000001") -) - func newTwapRecord(k types.AmmInterface, ctx sdk.Context, poolId uint64, denom0, denom1 string) (types.TwapRecord, error) { denom0, denom1, err := types.LexicographicalOrderDenoms(denom0, denom1) if err != nil { @@ -268,13 +259,15 @@ func computeTwap(startRecord types.TwapRecord, endRecord types.TwapRecord, quote } // twapLog returns the logarithm of the given spot price, base 2. -// TODO: basic test func twapLog(price sdk.Dec) sdk.Dec { return osmomath.BigDecFromSDKDec(price).LogBase2().SDKDec() } // twapPow exponentiates the geometricTwapMathBase to the given exponent. -// TODO: basic test and benchmark. func twapPow(exponent sdk.Dec) sdk.Dec { - return osmomath.PowApprox(geometricTwapMathBase, exponent, geometricTwapPowPrecision) + exp2 := osmomath.Exp2(osmomath.BigDecFromSDKDec(exponent.Abs())) + if exponent.IsNegative() { + return osmomath.OneDec().Quo(exp2).SDKDec() + } + return osmomath.Exp2(osmomath.BigDecFromSDKDec(exponent)).SDKDec() } diff --git a/x/twap/logic_test.go b/x/twap/logic_test.go index 4ff239d6dec..51932e62cac 100644 --- a/x/twap/logic_test.go +++ b/x/twap/logic_test.go @@ -1327,12 +1327,13 @@ func (s *TestSuite) TestTwapLog() { var expectedValue = osmomath.MustNewDecFromStr("99.525973560175362367") result := twap.TwapLog(priceValue.SDKDec()) - result_by_customBaseLog := priceValue.CustomBaseLog(osmomath.BigDecFromSDKDec(twap.GeometricTwapMathBase)) + result_by_customBaseLog := priceValue.CustomBaseLog(geometricTwapMathBase) s.Require().True(expectedValue.Sub(osmomath.BigDecFromSDKDec(result)).Abs().LTE(expectedErrTolerance)) s.Require().True(result_by_customBaseLog.Sub(osmomath.BigDecFromSDKDec(result)).Abs().LTE(expectedErrTolerance)) } -func (s *TestSuite) TestTwapPow() { +// TestTwapPow_CorrectBase tests that the right base is used for the twap power function. +func (s *TestSuite) TestTwapPow_CorrectBase() { var expectedErrTolerance = osmomath.MustNewDecFromStr("0.00000100") // "TwapPow(0.5) = 1.41421356" // From: https://www.wolframalpha.com/input?i2d=true&i=power+base+2+exponent+0.5+with+9+digits @@ -1340,7 +1341,7 @@ func (s *TestSuite) TestTwapPow() { expectedValue := osmomath.MustNewDecFromStr("1.41421356") result := twap.TwapPow(exponentValue.SDKDec()) - result_by_mathPow := math.Pow(twap.GeometricTwapMathBase.MustFloat64(), exponentValue.SDKDec().MustFloat64()) + result_by_mathPow := math.Pow(geometricTwapMathBase.MustFloat64(), exponentValue.SDKDec().MustFloat64()) s.Require().True(expectedValue.Sub(osmomath.BigDecFromSDKDec(result)).Abs().LTE(expectedErrTolerance)) s.Require().True(osmomath.MustNewDecFromStr(fmt.Sprint(result_by_mathPow)).Sub(osmomath.BigDecFromSDKDec(result)).Abs().LTE(expectedErrTolerance)) } diff --git a/x/twap/strategy_test.go b/x/twap/strategy_test.go index d4f4d529911..6ff60879494 100644 --- a/x/twap/strategy_test.go +++ b/x/twap/strategy_test.go @@ -7,6 +7,7 @@ import ( "github.com/osmosis-labs/osmosis/v13/app/apptesting/osmoassert" "github.com/osmosis-labs/osmosis/v13/osmomath" + gammtypes "github.com/osmosis-labs/osmosis/v13/x/gamm/types" "github.com/osmosis-labs/osmosis/v13/x/twap" "github.com/osmosis-labs/osmosis/v13/x/twap/types" ) @@ -21,6 +22,13 @@ type computeTwapTestCase struct { expPanic bool } +// geometricTwapMathBase is the base used for geometric twap calculation +// in logarithm and power math functions. +// See twapLog and computeGeometricTwap functions for more details. +var ( + geometricTwapMathBase = osmomath.NewBigDec(2) +) + // TestComputeArithmeticTwap tests computeTwap on various inputs. // The test vectors are structured by setting up different start and records, // based on time interval, and their accumulator values. @@ -300,3 +308,21 @@ func (s *TestSuite) TestComputeGeometricStrategyTwap_ThreeAsset() { }) } } + +// TestTwapPow_MaxSpotPrice_NoOverflow tests that no overflow occurs at log_2{max spot price values}. +// and that the epsilon is within the tolerated multiplicative error. +func (s *TestSuite) TestTwapLogPow_MaxSpotPrice_NoOverflow() { + errTolerance := osmomath.ErrTolerance{ + MultiplicativeTolerance: sdk.OneDec().Quo(sdk.NewDec(10).Power(18)), + RoundingDir: osmomath.RoundDown, + } + + oneYear := OneSec.MulInt64(60 * 60 * 24 * 365) + + oneYearTimesMaxSpotPrice := oneYear.Mul(gammtypes.MaxSpotPrice) + + exponentValue := twap.TwapLog(oneYearTimesMaxSpotPrice) + finalValue := twap.TwapPow(exponentValue) + + s.Equal(0, errTolerance.CompareBigDec(osmomath.BigDecFromSDKDec(oneYearTimesMaxSpotPrice), osmomath.BigDecFromSDKDec(finalValue))) +} From 9a8ce34b2db9bea7685a5a7d2ceb8970c5686fbc Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 20 Dec 2022 21:08:27 -0500 Subject: [PATCH 07/15] fixes --- x/twap/client/query_proto_wrap_test.go | 37 ++++++++++++++------------ x/twap/strategy.go | 13 ++++++--- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/x/twap/client/query_proto_wrap_test.go b/x/twap/client/query_proto_wrap_test.go index e41256d94c4..1157bbeb230 100644 --- a/x/twap/client/query_proto_wrap_test.go +++ b/x/twap/client/query_proto_wrap_test.go @@ -49,15 +49,14 @@ func (suite *QueryTestSuite) TestQueryTwap() { ) testCases := []struct { - name string - poolId uint64 - baseAssetDenom string - quoteAssetDenom string - startTimeOverwrite *time.Time - endTime *time.Time - expectErr bool - result string - geometricResultOverwrite string + name string + poolId uint64 + baseAssetDenom string + quoteAssetDenom string + startTimeOverwrite *time.Time + endTime *time.Time + expectErr bool + result string }{ { name: "non-existant pool", @@ -109,8 +108,16 @@ func (suite *QueryTestSuite) TestQueryTwap() { quoteAssetDenom: "tokenD", endTime: &newBlockTime, - result: sdk.MustNewDecFromStr("1.333333330000000000").String(), - geometricResultOverwrite: sdk.MustNewDecFromStr("1.333333333333333333").String(), + result: sdk.MustNewDecFromStr("1.333333330000000000").String(), + }, + { + name: "tokenB in terms of tokenC (rounded decimal of 2/3)", + poolId: poolID, + baseAssetDenom: "tokenC", + quoteAssetDenom: "tokenB", + endTime: &newBlockTime, + + result: sdk.MustNewDecFromStr("0.666666670000000000").String(), }, { name: "tokenD in terms of tokenE (1)", @@ -198,10 +205,6 @@ func (suite *QueryTestSuite) TestQueryTwap() { if tc.startTimeOverwrite != nil { startTime = *tc.startTimeOverwrite } - expectedGeometricResult := tc.result - if tc.geometricResultOverwrite != "" { - expectedGeometricResult = tc.geometricResultOverwrite - } result, err := client.GeometricTwap(ctx, queryproto.GeometricTwapRequest{ PoolId: tc.poolId, @@ -215,7 +218,7 @@ func (suite *QueryTestSuite) TestQueryTwap() { suite.Require().Error(err, "expected error - GeometricTwap") } else { suite.Require().NoError(err, "unexpected error - GeometricTwap") - suite.Require().Equal(expectedGeometricResult, result.GeometricTwap.String()) + suite.Require().Equal(result.GeometricTwap.String(), result.GeometricTwap.String()) } resultToNow, err := client.GeometricTwapToNow(ctx, queryproto.GeometricTwapToNowRequest{ @@ -229,7 +232,7 @@ func (suite *QueryTestSuite) TestQueryTwap() { suite.Require().Error(err, "expected error - GeometricTwapToNow") } else { suite.Require().NoError(err, "unexpected error - GeometricTwapToNow") - suite.Require().Equal(expectedGeometricResult, resultToNow.GeometricTwap.String()) + suite.Require().Equal(result.GeometricTwap.String(), resultToNow.GeometricTwap.String()) } }) } diff --git a/x/twap/strategy.go b/x/twap/strategy.go index ecbdd4d4794..bf3039a7eaa 100644 --- a/x/twap/strategy.go +++ b/x/twap/strategy.go @@ -2,7 +2,11 @@ package twap import ( sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/osmosis-labs/osmosis/v13/osmomath" "github.com/osmosis-labs/osmosis/v13/x/twap/types" + + gammtypes "github.com/osmosis-labs/osmosis/v13/x/gamm/types" ) // twapStrategy is an interface for computing TWAPs. @@ -42,11 +46,14 @@ func (s *geometric) computeTwap(startRecord types.TwapRecord, endRecord types.Tw timeDelta := endRecord.Time.Sub(startRecord.Time) arithmeticMeanOfLogPrices := types.AccumDiffDivDuration(accumDiff, timeDelta) - geometricMeanDenom0 := twapPow(arithmeticMeanOfLogPrices) + result := twapPow(arithmeticMeanOfLogPrices) // N.B.: Geometric mean of recprocals is reciprocal of geometric mean. // https://proofwiki.org/wiki/Geometric_Mean_of_Reciprocals_is_Reciprocal_of_Geometric_Mean if quoteAsset == startRecord.Asset1Denom { - return sdk.OneDec().Quo(geometricMeanDenom0) + result = sdk.OneDec().Quo(result) } - return geometricMeanDenom0 + + // N.B. we round because this is the max number of significant figures supported + // by the underlying spot price function. + return osmomath.SigFigRound(result, gammtypes.SpotPriceSigFigs) } From 9e3e51e63ca4ad806b75c1daf4fa2e5b146ccbb5 Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 20 Dec 2022 22:38:14 -0500 Subject: [PATCH 08/15] cli --- x/twap/client/cli/query.go | 51 ++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/x/twap/client/cli/query.go b/x/twap/client/cli/query.go index 13bccff1e1a..ec5fc2a3542 100644 --- a/x/twap/client/cli/query.go +++ b/x/twap/client/cli/query.go @@ -7,6 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/golang/protobuf/proto" "github.com/spf13/cobra" "github.com/osmosis-labs/osmosis/v13/osmoutils/osmocli" @@ -26,18 +27,18 @@ func GetQueryCmd() *cobra.Command { // GetQueryTwapCommand returns multiplier of an asset by denom. func GetQueryTwapCommand() *cobra.Command { cmd := &cobra.Command{ - Use: "twap [poolid] [base denom] [start time] [end time]", + Use: "twap [twap type] [poolid] [base denom] [start time] [end time]", Short: "Query twap", Long: osmocli.FormatLongDescDirect(`Query twap for pool. Start time must be unix time. End time can be unix time or duration. Example: -{{.CommandPrefix}} twap 1 uosmo 1667088000 24h -{{.CommandPrefix}} twap 1 uosmo 1667088000 1667174400 +{{.CommandPrefix}} twap geometric 1 uosmo 1667088000 24h +{{.CommandPrefix}} twap arithmetic 1 uosmo 1667088000 1667174400 `, types.ModuleName), Args: cobra.ExactArgs(4), RunE: func(cmd *cobra.Command, args []string) error { // boilerplate parse fields - poolId, baseDenom, startTime, endTime, err := twapQueryParseArgs(args) + isArithmetic, poolId, baseDenom, startTime, endTime, err := twapQueryParseArgs(args) if err != nil { return err } @@ -65,13 +66,25 @@ Example: poolId, baseDenom, liquidity.Liquidity[0], liquidity.Liquidity[1]) } - res, err := queryClient.ArithmeticTwap(cmd.Context(), &queryproto.ArithmeticTwapRequest{ - PoolId: poolId, - BaseAsset: baseDenom, - QuoteAsset: quoteDenom, - StartTime: startTime, - EndTime: &endTime, - }) + var res proto.Message + if isArithmetic { + res, err = queryClient.ArithmeticTwap(cmd.Context(), &queryproto.ArithmeticTwapRequest{ + PoolId: poolId, + BaseAsset: baseDenom, + QuoteAsset: quoteDenom, + StartTime: startTime, + EndTime: &endTime, + }) + } else { + res, err = queryClient.GeometricTwap(cmd.Context(), &queryproto.GeometricTwapRequest{ + PoolId: poolId, + BaseAsset: baseDenom, + QuoteAsset: quoteDenom, + StartTime: startTime, + EndTime: &endTime, + }) + } + if err != nil { return err } @@ -85,19 +98,25 @@ Example: return cmd } -func twapQueryParseArgs(args []string) (poolId uint64, baseDenom string, startTime time.Time, endTime time.Time, err error) { +func twapQueryParseArgs(args []string) (isArithmetic bool, poolId uint64, baseDenom string, startTime time.Time, endTime time.Time, err error) { + twapTypeStr := args[0] + isArithmetic = twapTypeStr == "arithmetic" + if !isArithmetic && twapTypeStr != "geometric" { + panic(fmt.Sprintf("invalid twap type %s", twapTypeStr)) + } + // boilerplate parse fields // - poolId, err = osmocli.ParseUint(args[0], "poolId") + poolId, err = osmocli.ParseUint(args[1], "poolId") if err != nil { return } // - baseDenom = strings.TrimSpace(args[1]) + baseDenom = strings.TrimSpace(args[2]) // - startTime, err = osmocli.ParseUnixTime(args[2], "start time") + startTime, err = osmocli.ParseUnixTime(args[3], "start time") if err != nil { return } @@ -115,5 +134,5 @@ func twapQueryParseArgs(args []string) (poolId uint64, baseDenom string, startTi } endTime = startTime.Add(duration) } - return poolId, baseDenom, startTime, endTime, nil + return isArithmetic, poolId, baseDenom, startTime, endTime, nil } From 46bd041fc193d769e16c7c971acd70df34ff7119 Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 20 Dec 2022 22:49:15 -0500 Subject: [PATCH 09/15] lint --- x/twap/client/cli/query.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/twap/client/cli/query.go b/x/twap/client/cli/query.go index ec5fc2a3542..bb0ad0c8827 100644 --- a/x/twap/client/cli/query.go +++ b/x/twap/client/cli/query.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/golang/protobuf/proto" + "github.com/gogo/protobuf/proto" "github.com/spf13/cobra" "github.com/osmosis-labs/osmosis/v13/osmoutils/osmocli" From 048142fa470fb2c16d9dc52e1ea1b54bb2f86afa Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 21 Dec 2022 13:20:37 -0800 Subject: [PATCH 10/15] refactor via flag --- x/twap/client/cli/query.go | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/x/twap/client/cli/query.go b/x/twap/client/cli/query.go index bb0ad0c8827..3e9ba6b4ad3 100644 --- a/x/twap/client/cli/query.go +++ b/x/twap/client/cli/query.go @@ -16,6 +16,10 @@ import ( "github.com/osmosis-labs/osmosis/v13/x/twap/types" ) +const ( + flagIsArithmetic = "is-arithmetic" +) + // GetQueryCmd returns the cli query commands for this module. func GetQueryCmd() *cobra.Command { cmd := osmocli.QueryIndexCmd(types.ModuleName) @@ -27,7 +31,7 @@ func GetQueryCmd() *cobra.Command { // GetQueryTwapCommand returns multiplier of an asset by denom. func GetQueryTwapCommand() *cobra.Command { cmd := &cobra.Command{ - Use: "twap [twap type] [poolid] [base denom] [start time] [end time]", + Use: "twap [poolid] [base denom] [start time] [end time]", Short: "Query twap", Long: osmocli.FormatLongDescDirect(`Query twap for pool. Start time must be unix time. End time can be unix time or duration. @@ -38,7 +42,11 @@ Example: Args: cobra.ExactArgs(4), RunE: func(cmd *cobra.Command, args []string) error { // boilerplate parse fields - isArithmetic, poolId, baseDenom, startTime, endTime, err := twapQueryParseArgs(args) + poolId, baseDenom, startTime, endTime, err := twapQueryParseArgs(args) + if err != nil { + return err + } + isArithmetic, err := cmd.Flags().GetBool(flagIsArithmetic) if err != nil { return err } @@ -94,29 +102,24 @@ Example: } flags.AddQueryFlagsToCmd(cmd) + cmd.Flags().Bool(flagIsArithmetic, true, "Type of twap to query. Arithmetic TWAP if true. Geometric TWAP if false.") return cmd } -func twapQueryParseArgs(args []string) (isArithmetic bool, poolId uint64, baseDenom string, startTime time.Time, endTime time.Time, err error) { - twapTypeStr := args[0] - isArithmetic = twapTypeStr == "arithmetic" - if !isArithmetic && twapTypeStr != "geometric" { - panic(fmt.Sprintf("invalid twap type %s", twapTypeStr)) - } - +func twapQueryParseArgs(args []string) (poolId uint64, baseDenom string, startTime time.Time, endTime time.Time, err error) { // boilerplate parse fields // - poolId, err = osmocli.ParseUint(args[1], "poolId") + poolId, err = osmocli.ParseUint(args[0], "poolId") if err != nil { return } // - baseDenom = strings.TrimSpace(args[2]) + baseDenom = strings.TrimSpace(args[1]) // - startTime, err = osmocli.ParseUnixTime(args[3], "start time") + startTime, err = osmocli.ParseUnixTime(args[2], "start time") if err != nil { return } @@ -134,5 +137,5 @@ func twapQueryParseArgs(args []string) (isArithmetic bool, poolId uint64, baseDe } endTime = startTime.Add(duration) } - return isArithmetic, poolId, baseDenom, startTime, endTime, nil + return poolId, baseDenom, startTime, endTime, nil } From 215948582fefe4d593a85ab101a1a68e8101b83b Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 21 Dec 2022 13:24:24 -0800 Subject: [PATCH 11/15] refactor --- x/twap/client/cli/query.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/x/twap/client/cli/query.go b/x/twap/client/cli/query.go index 3e9ba6b4ad3..e963006911a 100644 --- a/x/twap/client/cli/query.go +++ b/x/twap/client/cli/query.go @@ -17,7 +17,7 @@ import ( ) const ( - flagIsArithmetic = "is-arithmetic" + flagIsGeometric = "geometric" ) // GetQueryCmd returns the cli query commands for this module. @@ -34,10 +34,11 @@ func GetQueryTwapCommand() *cobra.Command { Use: "twap [poolid] [base denom] [start time] [end time]", Short: "Query twap", Long: osmocli.FormatLongDescDirect(`Query twap for pool. Start time must be unix time. End time can be unix time or duration. + Provide 'geometric' flag to specify whether to use arithmetic or geometric TWAP. Arithmetic (false) by default. Example: -{{.CommandPrefix}} twap geometric 1 uosmo 1667088000 24h -{{.CommandPrefix}} twap arithmetic 1 uosmo 1667088000 1667174400 +{{.CommandPrefix}} twap 1 uosmo 1667088000 24h +{{.CommandPrefix}} twap 1 uosmo 1667088000 1667174400 --geometric `, types.ModuleName), Args: cobra.ExactArgs(4), RunE: func(cmd *cobra.Command, args []string) error { @@ -46,7 +47,7 @@ Example: if err != nil { return err } - isArithmetic, err := cmd.Flags().GetBool(flagIsArithmetic) + isGeometric, err := cmd.Flags().GetBool(flagIsGeometric) if err != nil { return err } @@ -75,8 +76,8 @@ Example: } var res proto.Message - if isArithmetic { - res, err = queryClient.ArithmeticTwap(cmd.Context(), &queryproto.ArithmeticTwapRequest{ + if isGeometric { + res, err = queryClient.GeometricTwap(cmd.Context(), &queryproto.GeometricTwapRequest{ PoolId: poolId, BaseAsset: baseDenom, QuoteAsset: quoteDenom, @@ -84,7 +85,7 @@ Example: EndTime: &endTime, }) } else { - res, err = queryClient.GeometricTwap(cmd.Context(), &queryproto.GeometricTwapRequest{ + res, err = queryClient.ArithmeticTwap(cmd.Context(), &queryproto.ArithmeticTwapRequest{ PoolId: poolId, BaseAsset: baseDenom, QuoteAsset: quoteDenom, @@ -102,7 +103,7 @@ Example: } flags.AddQueryFlagsToCmd(cmd) - cmd.Flags().Bool(flagIsArithmetic, true, "Type of twap to query. Arithmetic TWAP if true. Geometric TWAP if false.") + cmd.Flags().Bool(flagIsGeometric, false, "Type of twap to query. Geometric TWAP if true. Arithmetic TWAP if false.") return cmd } From 79b0abfd0b1bb23499291312dabcf89c3eba7064 Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 21 Dec 2022 13:45:32 -0800 Subject: [PATCH 12/15] refactor --- x/twap/client/cli/query.go | 133 +++++++++++++++++++++++-------------- 1 file changed, 84 insertions(+), 49 deletions(-) diff --git a/x/twap/client/cli/query.go b/x/twap/client/cli/query.go index e963006911a..54a917b49fb 100644 --- a/x/twap/client/cli/query.go +++ b/x/twap/client/cli/query.go @@ -1,13 +1,13 @@ package twapcli import ( + "context" "fmt" "strings" "time" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/gogo/protobuf/proto" "github.com/spf13/cobra" "github.com/osmosis-labs/osmosis/v13/osmoutils/osmocli" @@ -16,29 +16,25 @@ import ( "github.com/osmosis-labs/osmosis/v13/x/twap/types" ) -const ( - flagIsGeometric = "geometric" -) - // GetQueryCmd returns the cli query commands for this module. func GetQueryCmd() *cobra.Command { cmd := osmocli.QueryIndexCmd(types.ModuleName) - cmd.AddCommand(GetQueryTwapCommand()) + cmd.AddCommand(GetQueryArithmeticCommand()) + cmd.AddCommand(GetQueryGeometricCommand()) return cmd } -// GetQueryTwapCommand returns multiplier of an asset by denom. -func GetQueryTwapCommand() *cobra.Command { +// GetQueryArithmeticCommand returns an arithmetic twap query command. +func GetQueryArithmeticCommand() *cobra.Command { cmd := &cobra.Command{ - Use: "twap [poolid] [base denom] [start time] [end time]", - Short: "Query twap", - Long: osmocli.FormatLongDescDirect(`Query twap for pool. Start time must be unix time. End time can be unix time or duration. - Provide 'geometric' flag to specify whether to use arithmetic or geometric TWAP. Arithmetic (false) by default. + Use: "arithmetic [poolid] [base denom] [start time] [end time]", + Short: "Query arithmetic twap", + Long: osmocli.FormatLongDescDirect(`Query arithmetic twap for pool. Start time must be unix time. End time can be unix time or duration. Example: -{{.CommandPrefix}} twap 1 uosmo 1667088000 24h -{{.CommandPrefix}} twap 1 uosmo 1667088000 1667174400 --geometric +{{.CommandPrefix}} arithmetic 1 uosmo 1667088000 24h +{{.CommandPrefix}} arithmetic 1 uosmo 1667088000 1667174400 `, types.ModuleName), Args: cobra.ExactArgs(4), RunE: func(cmd *cobra.Command, args []string) error { @@ -47,53 +43,69 @@ Example: if err != nil { return err } - isGeometric, err := cmd.Flags().GetBool(flagIsGeometric) - if err != nil { - return err - } clientCtx, err := client.GetClientQueryContext(cmd) + quoteDenom, err := getQuoteDenomFromLiquidity(cmd.Context(), clientCtx, poolId, baseDenom) if err != nil { return err } + queryClient := queryproto.NewQueryClient(clientCtx) - gammClient := gammtypes.NewQueryClient(clientCtx) - liquidity, err := gammClient.TotalPoolLiquidity(cmd.Context(), &gammtypes.QueryTotalPoolLiquidityRequest{PoolId: poolId}) + res, err := queryClient.ArithmeticTwap(cmd.Context(), &queryproto.ArithmeticTwapRequest{ + PoolId: poolId, + BaseAsset: baseDenom, + QuoteAsset: quoteDenom, + StartTime: startTime, + EndTime: &endTime, + }) + 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]) + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +// GetQueryGeometricCommand returns a geometric twap query command. +func GetQueryGeometricCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "geometric [poolid] [base denom] [start time] [end time]", + Short: "Query geometric twap", + Long: osmocli.FormatLongDescDirect(`Query geometric twap for pool. Start time must be unix time. End time can be unix time or duration. + +Example: +{{.CommandPrefix}} geometric 1 uosmo 1667088000 24h +{{.CommandPrefix}} geometric 1 uosmo 1667088000 1667174400 +`, types.ModuleName), + Args: cobra.ExactArgs(4), + RunE: func(cmd *cobra.Command, args []string) error { + // boilerplate parse fields + poolId, baseDenom, startTime, endTime, err := twapQueryParseArgs(args) + if err != nil { + return err } - var res proto.Message - if isGeometric { - res, err = queryClient.GeometricTwap(cmd.Context(), &queryproto.GeometricTwapRequest{ - PoolId: poolId, - BaseAsset: baseDenom, - QuoteAsset: quoteDenom, - StartTime: startTime, - EndTime: &endTime, - }) - } else { - res, err = queryClient.ArithmeticTwap(cmd.Context(), &queryproto.ArithmeticTwapRequest{ - PoolId: poolId, - BaseAsset: baseDenom, - QuoteAsset: quoteDenom, - StartTime: startTime, - EndTime: &endTime, - }) + clientCtx, err := client.GetClientQueryContext(cmd) + quoteDenom, err := getQuoteDenomFromLiquidity(cmd.Context(), clientCtx, poolId, baseDenom) + if err != nil { + return err } + queryClient := queryproto.NewQueryClient(clientCtx) + res, err := queryClient.GeometricTwap(cmd.Context(), &queryproto.GeometricTwapRequest{ + PoolId: poolId, + BaseAsset: baseDenom, + QuoteAsset: quoteDenom, + StartTime: startTime, + EndTime: &endTime, + }) + if err != nil { return err } @@ -103,11 +115,34 @@ Example: } flags.AddQueryFlagsToCmd(cmd) - cmd.Flags().Bool(flagIsGeometric, false, "Type of twap to query. Geometric TWAP if true. Arithmetic TWAP if false.") return cmd } +// getQuoteDenomFromLiquidity gets the quote liquidity denom from the pool. In addition, validates that base denom +// exists in the pool. Fails if not. +func getQuoteDenomFromLiquidity(ctx context.Context, clientCtx client.Context, poolId uint64, baseDenom string) (string, error) { + gammClient := gammtypes.NewQueryClient(clientCtx) + liquidity, err := gammClient.TotalPoolLiquidity(ctx, &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]) + } + return quoteDenom, nil +} + func twapQueryParseArgs(args []string) (poolId uint64, baseDenom string, startTime time.Time, endTime time.Time, err error) { // boilerplate parse fields // From ba9b320571f76240fdbd2d43241f9b5a3ac31c64 Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 21 Dec 2022 13:54:47 -0800 Subject: [PATCH 13/15] fixes --- x/twap/client/cli/query.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/x/twap/client/cli/query.go b/x/twap/client/cli/query.go index 54a917b49fb..2a079ddd19f 100644 --- a/x/twap/client/cli/query.go +++ b/x/twap/client/cli/query.go @@ -43,8 +43,10 @@ Example: if err != nil { return err } - clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } quoteDenom, err := getQuoteDenomFromLiquidity(cmd.Context(), clientCtx, poolId, baseDenom) if err != nil { return err @@ -90,14 +92,16 @@ Example: if err != nil { return err } - clientCtx, err := client.GetClientQueryContext(cmd) quoteDenom, err := getQuoteDenomFromLiquidity(cmd.Context(), clientCtx, poolId, baseDenom) if err != nil { return err } - queryClient := queryproto.NewQueryClient(clientCtx) + if err != nil { + return err + } + res, err := queryClient.GeometricTwap(cmd.Context(), &queryproto.GeometricTwapRequest{ PoolId: poolId, BaseAsset: baseDenom, From 08971c290f84e19b832ccf54068e8bed132b4c12 Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 21 Dec 2022 21:58:30 -0500 Subject: [PATCH 14/15] lint --- x/twap/client/cli/query.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/x/twap/client/cli/query.go b/x/twap/client/cli/query.go index 2a079ddd19f..415061bb44b 100644 --- a/x/twap/client/cli/query.go +++ b/x/twap/client/cli/query.go @@ -93,6 +93,9 @@ Example: return err } clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } quoteDenom, err := getQuoteDenomFromLiquidity(cmd.Context(), clientCtx, poolId, baseDenom) if err != nil { return err From 99df055c3980110b65145d79e4cc0ff8ac9ba066 Mon Sep 17 00:00:00 2001 From: Roman Date: Thu, 22 Dec 2022 12:51:42 -0800 Subject: [PATCH 15/15] add arithmetic twap alias --- x/twap/client/cli/query.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/x/twap/client/cli/query.go b/x/twap/client/cli/query.go index 415061bb44b..2e448d0a0be 100644 --- a/x/twap/client/cli/query.go +++ b/x/twap/client/cli/query.go @@ -28,8 +28,9 @@ func GetQueryCmd() *cobra.Command { // GetQueryArithmeticCommand returns an arithmetic twap query command. func GetQueryArithmeticCommand() *cobra.Command { cmd := &cobra.Command{ - Use: "arithmetic [poolid] [base denom] [start time] [end time]", - Short: "Query arithmetic twap", + Use: "arithmetic [poolid] [base denom] [start time] [end time]", + Short: "Query arithmetic twap", + Aliases: []string{"twap"}, Long: osmocli.FormatLongDescDirect(`Query arithmetic twap for pool. Start time must be unix time. End time can be unix time or duration. Example: