diff --git a/CHANGELOG.md b/CHANGELOG.md index ffc8d7f0c..6e845cc87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Features * [#791](https://github.com/NibiruChain/nibiru/pull/791) Add the x/oracle module +* [#810](https://github.com/NibiruChain/nibiru/pull/810) - feat(x/perp): expose 'marginRatioIndex' and block number on QueryTraderPosition ## [v0.12.1](https://github.com/NibiruChain/nibiru/releases/tag/v0.12.1) - 2022-08-04 diff --git a/proto/perp/v1/query.proto b/proto/perp/v1/query.proto index dd0bfd083..dc7b2b895 100644 --- a/proto/perp/v1/query.proto +++ b/proto/perp/v1/query.proto @@ -15,7 +15,7 @@ service Query { option (google.api.http).get = "/nibiru/perp/params"; } - rpc TraderPosition(QueryTraderPositionRequest) returns (QueryTraderPositionResponse) { + rpc QueryTraderPosition(QueryTraderPositionRequest) returns (QueryTraderPositionResponse) { option (google.api.http).get = "/nibiru/perp/trader_position"; } } @@ -54,10 +54,21 @@ message QueryTraderPositionResponse { (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; - // The position's margin ratio, calculated from margin, unrealized PnL, and position notional. - string margin_ratio = 4 [ + /* margin ratio of the position based on the mark price, mark TWAP. The higher + value of the possible margin ratios (TWAP and instantaneous) is taken to be + 'marginRatioMark'. Calculated from margin, unrealized PnL, and position notional. */ + string margin_ratio_mark = 4 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; + + /* margin ratio of the position based on the index price. Calculated from margin, + unrealized PnL, and position notional. */ + string margin_ratio_index = 5 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false]; + + // BlockNumber is current block number at the time of query. + int64 block_number = 7; } // ---------------------------------------- OtherQuery \ No newline at end of file diff --git a/x/oracle/types/oracle.pb.go b/x/oracle/types/oracle.pb.go index 3a38a56b1..6a3b1f6d0 100644 --- a/x/oracle/types/oracle.pb.go +++ b/x/oracle/types/oracle.pb.go @@ -137,7 +137,7 @@ var xxx_messageInfo_Pair proto.InternalMessageInfo // struct for aggregate prevoting on the ExchangeRateVote. // The purpose of aggregate prevote is to hide vote exchange rates with hash -// which is formatted as hex string in SHA256("{salt}:({pair},{exchange_rate})|...|({pair},{exchange_rate}):{voter}") +// which is formatted as hex string in SHA256("{salt}:({pair},{exchange_rate})|...,({pair},{exchange_rate}):{voter}") type AggregateExchangeRatePrevote struct { Hash string `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty" yaml:"hash"` Voter string `protobuf:"bytes,2,opt,name=voter,proto3" json:"voter,omitempty" yaml:"voter"` diff --git a/x/perp/client/cli/cli_test.go b/x/perp/client/cli/cli_test.go index 1b5a7f48f..5b62a362c 100644 --- a/x/perp/client/cli/cli_test.go +++ b/x/perp/client/cli/cli_test.go @@ -153,6 +153,8 @@ func (s *IntegrationTestSuite) TearDownSuite() { s.network.Cleanup() } +// TODO test: Include checks for queryResp.MarginRatioIndex +// https://github.com/NibiruChain/nibiru/issues/809 func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { val := s.network.Validators[0] @@ -200,7 +202,7 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(sdk.NewDec(1_000_000), queryResp.Position.OpenNotional) s.EqualValues(sdk.MustNewDecFromStr("999999.999999999999999359"), queryResp.PositionNotional) s.EqualValues(sdk.MustNewDecFromStr("-0.000000000000000641"), queryResp.UnrealizedPnl) - s.EqualValues(sdk.NewDec(1), queryResp.MarginRatio) + s.EqualValues(sdk.NewDec(1), queryResp.MarginRatioMark) s.T().Log("C. open position with 2x leverage and zero baseAmtLimit") args = []string{ @@ -226,7 +228,7 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(sdk.NewDec(3_000_000), queryResp.Position.OpenNotional) s.EqualValues(sdk.MustNewDecFromStr("3000000.000000000000000938"), queryResp.PositionNotional) s.EqualValues(sdk.MustNewDecFromStr("0.000000000000000938"), queryResp.UnrealizedPnl) - s.EqualValues(sdk.MustNewDecFromStr("0.666666666666666667"), queryResp.MarginRatio) + s.EqualValues(sdk.MustNewDecFromStr("0.666666666666666667"), queryResp.MarginRatioMark) s.T().Log("D. Open a reverse position smaller than the existing position") args = []string{ @@ -260,7 +262,7 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(sdk.NewDec(2_999_900), queryResp.Position.OpenNotional) s.EqualValues(sdk.MustNewDecFromStr("2999899.999999999999999506"), queryResp.PositionNotional) s.EqualValues(sdk.MustNewDecFromStr("-0.000000000000000494"), queryResp.UnrealizedPnl) - s.EqualValues(sdk.MustNewDecFromStr("0.666688889629654322"), queryResp.MarginRatio) + s.EqualValues(sdk.MustNewDecFromStr("0.666688889629654322"), queryResp.MarginRatioMark) s.T().Log("E. Open a reverse position larger than the existing position") args = []string{ @@ -288,7 +290,7 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(sdk.MustNewDecFromStr("1000099.999999999999999651"), queryResp.PositionNotional) s.EqualValues(sdk.MustNewDecFromStr("0.000000000000000843"), queryResp.UnrealizedPnl) // there is a random delta due to twap margin ratio calculation and random block times in the in-process network - s.InDelta(1, queryResp.MarginRatio.MustFloat64(), 0.001) + s.InDelta(1, queryResp.MarginRatioMark.MustFloat64(), 0.001) s.T().Log("F. Close position") args = []string{ diff --git a/x/perp/client/cli/query.go b/x/perp/client/cli/query.go index 041e4be23..d18753f95 100644 --- a/x/perp/client/cli/query.go +++ b/x/perp/client/cli/query.go @@ -88,7 +88,7 @@ func CmdQueryPosition() *cobra.Command { return err } - res, err := queryClient.TraderPosition( + res, err := queryClient.QueryTraderPosition( cmd.Context(), &types.QueryTraderPositionRequest{ Trader: trader.String(), TokenPair: tokenPair.String(), diff --git a/x/perp/keeper/grpc_query.go b/x/perp/keeper/grpc_query.go index ff1da0401..adb04f320 100644 --- a/x/perp/keeper/grpc_query.go +++ b/x/perp/keeper/grpc_query.go @@ -21,7 +21,7 @@ func NewQuerier(k Keeper) queryServer { var _ types.QueryServer = queryServer{} -func (q queryServer) TraderPosition( +func (q queryServer) QueryTraderPosition( goCtx context.Context, req *types.QueryTraderPositionRequest, ) (*types.QueryTraderPositionResponse, error) { if req == nil { @@ -49,16 +49,24 @@ func (q queryServer) TraderPosition( return nil, err } - marginRatio, err := q.Keeper.GetMarginRatio(ctx, *position, types.MarginCalculationPriceOption_MAX_PNL) + marginRatioMark, err := q.Keeper.GetMarginRatio(ctx, *position, types.MarginCalculationPriceOption_MAX_PNL) if err != nil { return nil, err } + marginRatioIndex, err := q.Keeper.GetMarginRatio(ctx, *position, types.MarginCalculationPriceOption_INDEX) + if err != nil { + // The index portion of the query fails silently as not to distrupt all + // position queries when oracles aren't posting prices. + q.Keeper.Logger(ctx).Error(err.Error()) + } return &types.QueryTraderPositionResponse{ Position: position, PositionNotional: positionNotional, UnrealizedPnl: unrealizedPnl, - MarginRatio: marginRatio, + MarginRatioMark: marginRatioMark, + MarginRatioIndex: marginRatioIndex, + BlockNumber: ctx.BlockHeight(), }, nil } diff --git a/x/perp/keeper/grpc_query_test.go b/x/perp/keeper/grpc_query_test.go index a15afa744..8299b7152 100644 --- a/x/perp/keeper/grpc_query_test.go +++ b/x/perp/keeper/grpc_query_test.go @@ -117,7 +117,7 @@ func TestQueryPosition(t *testing.T) { t.Log("query position") ctx = ctx.WithBlockTime(ctx.BlockTime().Add(time.Second)) - resp, err := queryServer.TraderPosition( + resp, err := queryServer.QueryTraderPosition( sdk.WrapSDKContext(ctx), &types.QueryTraderPositionRequest{ Trader: traderAddr.String(), @@ -131,7 +131,9 @@ func TestQueryPosition(t *testing.T) { assert.Equal(t, tc.expectedPositionNotional, resp.PositionNotional) assert.Equal(t, tc.expectedUnrealizedPnl, resp.UnrealizedPnl) - assert.Equal(t, tc.expectedMarginRatio, resp.MarginRatio) + assert.Equal(t, tc.expectedMarginRatio, resp.MarginRatioMark) + // assert.Equal(t, tc.expectedMarginRatioIndex, resp.MarginRatioIndex) + // TODO https://github.com/NibiruChain/nibiru/issues/809 }) } } diff --git a/x/perp/types/query.pb.go b/x/perp/types/query.pb.go index 4f6682eb5..2e1506cf0 100644 --- a/x/perp/types/query.pb.go +++ b/x/perp/types/query.pb.go @@ -174,8 +174,15 @@ type QueryTraderPositionResponse struct { PositionNotional github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=position_notional,json=positionNotional,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"position_notional"` // The position's unrealized PnL. UnrealizedPnl github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=unrealized_pnl,json=unrealizedPnl,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"unrealized_pnl"` - // The position's margin ratio, calculated from margin, unrealized PnL, and position notional. - MarginRatio github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,4,opt,name=margin_ratio,json=marginRatio,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"margin_ratio"` + // margin ratio of the position based on the mark price, mark TWAP. The higher + // value of the possible margin ratios (TWAP and instantaneous) is taken to be + // 'marginRatioMark'. Calculated from margin, unrealized PnL, and position notional. + MarginRatioMark github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,4,opt,name=margin_ratio_mark,json=marginRatioMark,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"margin_ratio_mark"` + // margin ratio of the position based on the index price. Calculated from margin, + // unrealized PnL, and position notional. + MarginRatioIndex github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,5,opt,name=margin_ratio_index,json=marginRatioIndex,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"margin_ratio_index"` + // BlockNumber is current block number at the time of query. + BlockNumber int64 `protobuf:"varint,7,opt,name=block_number,json=blockNumber,proto3" json:"block_number,omitempty"` } func (m *QueryTraderPositionResponse) Reset() { *m = QueryTraderPositionResponse{} } @@ -218,6 +225,13 @@ func (m *QueryTraderPositionResponse) GetPosition() *Position { return nil } +func (m *QueryTraderPositionResponse) GetBlockNumber() int64 { + if m != nil { + return m.BlockNumber + } + return 0 +} + func init() { proto.RegisterType((*QueryParamsRequest)(nil), "nibiru.perp.v1.QueryParamsRequest") proto.RegisterType((*QueryParamsResponse)(nil), "nibiru.perp.v1.QueryParamsResponse") @@ -228,38 +242,41 @@ func init() { func init() { proto.RegisterFile("perp/v1/query.proto", fileDescriptor_8212d8958be09421) } var fileDescriptor_8212d8958be09421 = []byte{ - // 485 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x93, 0xcf, 0x6f, 0xd3, 0x30, - 0x14, 0xc7, 0x9b, 0x32, 0x2a, 0xe6, 0x41, 0x05, 0xee, 0x98, 0xa2, 0x6c, 0x64, 0x28, 0x20, 0x84, - 0x86, 0x88, 0xb5, 0xc1, 0x5f, 0x50, 0x76, 0x43, 0x9a, 0xba, 0x00, 0x17, 0x38, 0x44, 0x6e, 0x6b, - 0x65, 0xd6, 0x52, 0xdb, 0xb3, 0x9d, 0x89, 0x71, 0xe4, 0xc6, 0x09, 0x24, 0xfe, 0xa9, 0x1d, 0x27, - 0x71, 0x41, 0x3b, 0x4c, 0xa8, 0xe5, 0x0f, 0x41, 0xfe, 0x91, 0x42, 0x58, 0x85, 0xd0, 0x4e, 0x76, - 0xdf, 0xfb, 0xfa, 0xf3, 0xbe, 0x7d, 0xef, 0x05, 0xf4, 0x04, 0x91, 0x02, 0x1d, 0x6f, 0xa3, 0xa3, - 0x8a, 0xc8, 0x93, 0x54, 0x48, 0xae, 0x39, 0xec, 0x32, 0x3a, 0xa4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 0xb1, 0x5f, 0xdb, 0xb3, 0x5f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x18, 0x52, 0x93, - 0x1b, 0xdd, 0x03, 0x00, 0x00, + // 536 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x93, 0x4f, 0x6f, 0xd3, 0x30, + 0x18, 0xc6, 0x9b, 0x76, 0x2b, 0xcc, 0x83, 0xc1, 0xdc, 0x31, 0x45, 0xdd, 0xc8, 0x46, 0x40, 0x68, + 0x1a, 0x22, 0xd1, 0x06, 0x9f, 0xa0, 0xec, 0x82, 0x10, 0x55, 0x09, 0x70, 0x19, 0x48, 0x91, 0xdb, + 0x5a, 0x99, 0xd5, 0xc4, 0xce, 0x6c, 0x67, 0xda, 0x38, 0xf2, 0x01, 0x10, 0x12, 0x7c, 0xa8, 0x1d, + 0x27, 0x71, 0x41, 0x1c, 0x26, 0xd4, 0xee, 0x83, 0x20, 0xff, 0x69, 0x59, 0x58, 0x85, 0xa6, 0x9e, + 0xec, 0xbe, 0xef, 0xe3, 0x9f, 0x9f, 0xe6, 0x7d, 0x0c, 0x1a, 0x39, 0xe6, 0x79, 0x78, 0xb4, 0x13, + 0x1e, 0x16, 0x98, 0x9f, 0x04, 0x39, 0x67, 0x92, 0xc1, 0x25, 0x4a, 0xba, 0x84, 0x17, 0x81, 0xea, + 0x05, 0x47, 0x3b, 0xcd, 0x95, 0x84, 0x25, 0x4c, 0xb7, 0x42, 0xb5, 0x33, 0xaa, 0xe6, 0x7a, 0xc2, + 0x58, 0x92, 0xe2, 0x10, 0xe5, 0x24, 0x44, 0x94, 0x32, 0x89, 0x24, 0x61, 0x54, 0xd8, 0xee, 0x04, + 0x2c, 0x24, 0x92, 0xd8, 0x14, 0xfd, 0x15, 0x00, 0xdf, 0xa8, 0x7b, 0x3a, 0x88, 0xa3, 0x4c, 0x44, + 0xf8, 0xb0, 0xc0, 0x42, 0x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ff, + 0x83, 0xa0, 0xeb, 0xc3, 0x6c, 0x04, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -276,7 +293,7 @@ const _ = grpc.SupportPackageIsVersion4 type QueryClient interface { // Parameters queries the parameters of the x/perp module. Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) - TraderPosition(ctx context.Context, in *QueryTraderPositionRequest, opts ...grpc.CallOption) (*QueryTraderPositionResponse, error) + QueryTraderPosition(ctx context.Context, in *QueryTraderPositionRequest, opts ...grpc.CallOption) (*QueryTraderPositionResponse, error) } type queryClient struct { @@ -296,9 +313,9 @@ func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts . return out, nil } -func (c *queryClient) TraderPosition(ctx context.Context, in *QueryTraderPositionRequest, opts ...grpc.CallOption) (*QueryTraderPositionResponse, error) { +func (c *queryClient) QueryTraderPosition(ctx context.Context, in *QueryTraderPositionRequest, opts ...grpc.CallOption) (*QueryTraderPositionResponse, error) { out := new(QueryTraderPositionResponse) - err := c.cc.Invoke(ctx, "/nibiru.perp.v1.Query/TraderPosition", in, out, opts...) + err := c.cc.Invoke(ctx, "/nibiru.perp.v1.Query/QueryTraderPosition", in, out, opts...) if err != nil { return nil, err } @@ -309,7 +326,7 @@ func (c *queryClient) TraderPosition(ctx context.Context, in *QueryTraderPositio type QueryServer interface { // Parameters queries the parameters of the x/perp module. Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) - TraderPosition(context.Context, *QueryTraderPositionRequest) (*QueryTraderPositionResponse, error) + QueryTraderPosition(context.Context, *QueryTraderPositionRequest) (*QueryTraderPositionResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -319,8 +336,8 @@ type UnimplementedQueryServer struct { func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") } -func (*UnimplementedQueryServer) TraderPosition(ctx context.Context, req *QueryTraderPositionRequest) (*QueryTraderPositionResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method TraderPosition not implemented") +func (*UnimplementedQueryServer) QueryTraderPosition(ctx context.Context, req *QueryTraderPositionRequest) (*QueryTraderPositionResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method QueryTraderPosition not implemented") } func RegisterQueryServer(s grpc1.Server, srv QueryServer) { @@ -345,20 +362,20 @@ func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interf return interceptor(ctx, in, info, handler) } -func _Query_TraderPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { +func _Query_QueryTraderPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(QueryTraderPositionRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(QueryServer).TraderPosition(ctx, in) + return srv.(QueryServer).QueryTraderPosition(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/nibiru.perp.v1.Query/TraderPosition", + FullMethod: "/nibiru.perp.v1.Query/QueryTraderPosition", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).TraderPosition(ctx, req.(*QueryTraderPositionRequest)) + return srv.(QueryServer).QueryTraderPosition(ctx, req.(*QueryTraderPositionRequest)) } return interceptor(ctx, in, info, handler) } @@ -372,8 +389,8 @@ var _Query_serviceDesc = grpc.ServiceDesc{ Handler: _Query_Params_Handler, }, { - MethodName: "TraderPosition", - Handler: _Query_TraderPosition_Handler, + MethodName: "QueryTraderPosition", + Handler: _Query_QueryTraderPosition_Handler, }, }, Streams: []grpc.StreamDesc{}, @@ -493,10 +510,25 @@ func (m *QueryTraderPositionResponse) MarshalToSizedBuffer(dAtA []byte) (int, er _ = i var l int _ = l + if m.BlockNumber != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.BlockNumber)) + i-- + dAtA[i] = 0x38 + } + { + size := m.MarginRatioIndex.Size() + i -= size + if _, err := m.MarginRatioIndex.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a { - size := m.MarginRatio.Size() + size := m.MarginRatioMark.Size() i -= size - if _, err := m.MarginRatio.MarshalTo(dAtA[i:]); err != nil { + if _, err := m.MarginRatioMark.MarshalTo(dAtA[i:]); err != nil { return 0, err } i = encodeVarintQuery(dAtA, i, uint64(size)) @@ -600,8 +632,13 @@ func (m *QueryTraderPositionResponse) Size() (n int) { n += 1 + l + sovQuery(uint64(l)) l = m.UnrealizedPnl.Size() n += 1 + l + sovQuery(uint64(l)) - l = m.MarginRatio.Size() + l = m.MarginRatioMark.Size() + n += 1 + l + sovQuery(uint64(l)) + l = m.MarginRatioIndex.Size() n += 1 + l + sovQuery(uint64(l)) + if m.BlockNumber != 0 { + n += 1 + sovQuery(uint64(m.BlockNumber)) + } return n } @@ -993,7 +1030,7 @@ func (m *QueryTraderPositionResponse) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 4: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MarginRatio", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field MarginRatioMark", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1021,10 +1058,63 @@ func (m *QueryTraderPositionResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.MarginRatio.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.MarginRatioMark.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MarginRatioIndex", 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.MarginRatioIndex.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 7: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field BlockNumber", wireType) + } + m.BlockNumber = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.BlockNumber |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) diff --git a/x/perp/types/query.pb.gw.go b/x/perp/types/query.pb.gw.go index ec40a0e6a..0fd134914 100644 --- a/x/perp/types/query.pb.gw.go +++ b/x/perp/types/query.pb.gw.go @@ -50,37 +50,37 @@ func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshal } var ( - filter_Query_TraderPosition_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} + filter_Query_QueryTraderPosition_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} ) -func request_Query_TraderPosition_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func request_Query_QueryTraderPosition_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryTraderPositionRequest 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_TraderPosition_0); err != nil { + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_QueryTraderPosition_0); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - msg, err := client.TraderPosition(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + msg, err := client.QueryTraderPosition(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } -func local_request_Query_TraderPosition_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func local_request_Query_QueryTraderPosition_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryTraderPositionRequest 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_TraderPosition_0); err != nil { + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_QueryTraderPosition_0); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - msg, err := server.TraderPosition(ctx, &protoReq) + msg, err := server.QueryTraderPosition(ctx, &protoReq) return msg, metadata, err } @@ -111,7 +111,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) - mux.Handle("GET", pattern_Query_TraderPosition_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_QueryTraderPosition_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) @@ -120,14 +120,14 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_Query_TraderPosition_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_Query_QueryTraderPosition_0(rctx, inboundMarshaler, server, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_Query_TraderPosition_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_QueryTraderPosition_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -192,7 +192,7 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) - mux.Handle("GET", pattern_Query_TraderPosition_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_QueryTraderPosition_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) @@ -201,14 +201,14 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_Query_TraderPosition_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_Query_QueryTraderPosition_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_TraderPosition_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_QueryTraderPosition_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -218,11 +218,11 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie var ( pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"nibiru", "perp", "params"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_TraderPosition_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"nibiru", "perp", "trader_position"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_QueryTraderPosition_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"nibiru", "perp", "trader_position"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( forward_Query_Params_0 = runtime.ForwardResponseMessage - forward_Query_TraderPosition_0 = runtime.ForwardResponseMessage + forward_Query_QueryTraderPosition_0 = runtime.ForwardResponseMessage )