From 4ba111c4a0732f74fff31865010bdd55572d0cf0 Mon Sep 17 00:00:00 2001 From: NibiruHeisenberg <101130700+NibiruHeisenberg@users.noreply.github.com> Date: Fri, 22 Jul 2022 00:41:34 -0700 Subject: [PATCH] feat(perp): Add position fields in ClosePosition response (#724) * Add fields to ClosePosition response * Return fields in ClosePositionResp * Update CHANGELOG.md Co-authored-by: Agent Smith --- CHANGELOG.md | 1 + proto/perp/v1/tx.proto | 24 ++ x/perp/keeper/msg_server.go | 13 +- x/perp/keeper/msg_server_test.go | 53 +++-- x/perp/types/tx.pb.go | 368 +++++++++++++++++++++++++------ 5 files changed, 373 insertions(+), 86 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 332d7ae18..112f36119 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### API Breaking - [#721](https://github.com/NibiruChain/nibiru/pull/721) - Updated proto property names to adhere to standard snake_casing and added Unlock REST endpoint +- [#724](https://github.com/NibiruChain/nibiru/pull/724) - Add position fields in `ClosePositionResponse`. ### State Machine Breaking diff --git a/proto/perp/v1/tx.proto b/proto/perp/v1/tx.proto index 2a237391d..ad6c9a5ce 100644 --- a/proto/perp/v1/tx.proto +++ b/proto/perp/v1/tx.proto @@ -168,5 +168,29 @@ message MsgClosePosition { } message MsgClosePositionResponse { + // The amount of quote assets exchanged. + string exchanged_notional_value = 1 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false]; + // The amount of base assets exchanged. + string exchanged_position_size = 2 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false]; + + // The funding payment applied on this position change, measured in quote units. + string funding_payment = 3 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false]; + + // The amount of PnL realized on this position changed, measured in quote units. + string realized_pnl = 4 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false]; + + // The amount of margin the trader receives after closing the position, from the vault. + // Should never be negative. + string margin_to_trader = 7 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false]; } \ No newline at end of file diff --git a/x/perp/keeper/msg_server.go b/x/perp/keeper/msg_server.go index 905dd260f..5ba995f5d 100644 --- a/x/perp/keeper/msg_server.go +++ b/x/perp/keeper/msg_server.go @@ -82,9 +82,18 @@ func (m msgServer) ClosePosition(goCtx context.Context, position *types.MsgClose traderAddr := sdk.MustAccAddressFromBech32(position.Sender) tokenPair := common.MustNewAssetPair(position.TokenPair) - _, err := m.k.ClosePosition(ctx, tokenPair, traderAddr) + resp, err := m.k.ClosePosition(ctx, tokenPair, traderAddr) + if err != nil { + return nil, err + } - return &types.MsgClosePositionResponse{}, err + return &types.MsgClosePositionResponse{ + ExchangedNotionalValue: resp.ExchangedNotionalValue, + ExchangedPositionSize: resp.ExchangedPositionSize, + FundingPayment: resp.FundingPayment, + RealizedPnl: resp.RealizedPnl, + MarginToTrader: resp.MarginToVault.Neg(), + }, nil } func (m msgServer) Liquidate(goCtx context.Context, msg *types.MsgLiquidate, diff --git a/x/perp/keeper/msg_server_test.go b/x/perp/keeper/msg_server_test.go index e93faeee4..275b576aa 100644 --- a/x/perp/keeper/msg_server_test.go +++ b/x/perp/keeper/msg_server_test.go @@ -324,15 +324,15 @@ func TestMsgServerClosePosition(t *testing.T) { tests := []struct { name string - pair string - sender string + pair common.AssetPair + traderAddr sdk.AccAddress expectedErr error }{ { name: "success", - pair: common.PairBTCStable.String(), - sender: sample.AccAddress().String(), + pair: common.PairBTCStable, + traderAddr: sample.AccAddress(), expectedErr: nil, }, } @@ -344,31 +344,35 @@ func TestMsgServerClosePosition(t *testing.T) { msgServer := keeper.NewMsgServerImpl(app.PerpKeeper) t.Log("create vpool") - app.VpoolKeeper.CreatePool(ctx, common.PairBTCStable, sdk.OneDec(), sdk.NewDec(1_000_000), sdk.NewDec(1_000_000), sdk.OneDec(), sdk.OneDec()) + app.VpoolKeeper.CreatePool( + ctx, + common.PairBTCStable, + /* tradeLimitRatio */ sdk.OneDec(), + /* quoteAssetReserve */ sdk.NewDec(1_000_000), + /* baseAssetReserve */ sdk.NewDec(1_000_000), + /* fluctuationLimitRatio */ sdk.OneDec(), + /* maxOracleSpreadRatio */ sdk.OneDec(), + ) app.PerpKeeper.PairMetadataState(ctx).Set(&types.PairMetadata{ Pair: common.PairBTCStable, CumulativePremiumFractions: []sdk.Dec{sdk.ZeroDec()}, }) - pair, err := common.NewAssetPair(tc.pair) - traderAddr, err2 := sdk.AccAddressFromBech32(tc.sender) - if err == nil && err2 == nil { - t.Log("create position") - require.NoError(t, app.PerpKeeper.PositionsState(ctx).Create(&types.Position{ - TraderAddress: traderAddr.String(), - Pair: pair, - Size_: sdk.OneDec(), - Margin: sdk.OneDec(), - OpenNotional: sdk.OneDec(), - LastUpdateCumulativePremiumFraction: sdk.ZeroDec(), - BlockNumber: 1, - })) - require.NoError(t, simapp.FundModuleAccount(app.BankKeeper, ctx, types.VaultModuleAccount, sdk.NewCoins(sdk.NewInt64Coin(pair.GetQuoteTokenDenom(), 1)))) - } + t.Log("create position") + require.NoError(t, app.PerpKeeper.PositionsState(ctx).Create(&types.Position{ + TraderAddress: tc.traderAddr.String(), + Pair: tc.pair, + Size_: sdk.OneDec(), + Margin: sdk.OneDec(), + OpenNotional: sdk.OneDec(), + LastUpdateCumulativePremiumFraction: sdk.ZeroDec(), + BlockNumber: 1, + })) + require.NoError(t, simapp.FundModuleAccount(app.BankKeeper, ctx, types.VaultModuleAccount, sdk.NewCoins(sdk.NewInt64Coin(tc.pair.GetQuoteTokenDenom(), 1)))) resp, err := msgServer.ClosePosition(sdk.WrapSDKContext(ctx), &types.MsgClosePosition{ - Sender: tc.sender, - TokenPair: tc.pair, + Sender: tc.traderAddr.String(), + TokenPair: tc.pair.String(), }) if tc.expectedErr != nil { @@ -377,6 +381,11 @@ func TestMsgServerClosePosition(t *testing.T) { } else { require.NoError(t, err) require.NotNil(t, resp) + assert.EqualValues(t, sdk.MustNewDecFromStr("0.999999000000999999"), resp.ExchangedNotionalValue) + assert.EqualValues(t, sdk.NewDec(-1), resp.ExchangedPositionSize) + assert.EqualValues(t, sdk.ZeroDec(), resp.FundingPayment) + assert.EqualValues(t, sdk.MustNewDecFromStr("0.999999000000999999"), resp.MarginToTrader) + assert.EqualValues(t, sdk.MustNewDecFromStr("-0.000000999999000001"), resp.RealizedPnl) } }) } diff --git a/x/perp/types/tx.pb.go b/x/perp/types/tx.pb.go index b3ca2a15d..2457ea395 100644 --- a/x/perp/types/tx.pb.go +++ b/x/perp/types/tx.pb.go @@ -544,6 +544,17 @@ func (m *MsgClosePosition) GetTokenPair() string { } type MsgClosePositionResponse struct { + // The amount of quote assets exchanged. + ExchangedNotionalValue github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,1,opt,name=exchanged_notional_value,json=exchangedNotionalValue,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"exchanged_notional_value"` + // The amount of base assets exchanged. + ExchangedPositionSize github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=exchanged_position_size,json=exchangedPositionSize,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"exchanged_position_size"` + // The funding payment applied on this position change, measured in quote units. + FundingPayment github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=funding_payment,json=fundingPayment,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"funding_payment"` + // The amount of PnL realized on this position changed, measured in quote units. + RealizedPnl github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,4,opt,name=realized_pnl,json=realizedPnl,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"realized_pnl"` + // The amount of margin the trader receives after closing the position, from the vault. + // Should never be negative. + MarginToTrader github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,7,opt,name=margin_to_trader,json=marginToTrader,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"margin_to_trader"` } func (m *MsgClosePositionResponse) Reset() { *m = MsgClosePositionResponse{} } @@ -595,68 +606,71 @@ func init() { func init() { proto.RegisterFile("perp/v1/tx.proto", fileDescriptor_28f06b306d51dcfb) } var fileDescriptor_28f06b306d51dcfb = []byte{ - // 971 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x96, 0xdd, 0x6e, 0x1b, 0x45, - 0x14, 0xc7, 0xb3, 0x89, 0x6b, 0xe2, 0x69, 0x9a, 0xa4, 0x83, 0x71, 0xb6, 0x26, 0x75, 0xa2, 0x05, - 0x41, 0x84, 0xc4, 0xae, 0x12, 0x90, 0xb8, 0x43, 0x4a, 0x52, 0x90, 0x0a, 0x71, 0x6b, 0xdc, 0x2a, - 0x48, 0x14, 0xb4, 0x8c, 0xbd, 0xc7, 0x9b, 0x51, 0xd7, 0x33, 0xdb, 0x9d, 0x59, 0x2b, 0x89, 0x2a, - 0xc4, 0xc7, 0x0b, 0x20, 0xf1, 0x0c, 0xbc, 0x07, 0x97, 0xbd, 0xac, 0xc4, 0x0d, 0xe2, 0xa2, 0x42, - 0x49, 0x25, 0x78, 0x0c, 0x34, 0xb3, 0x1f, 0xb1, 0xcd, 0x42, 0xd2, 0x25, 0x52, 0xaf, 0xec, 0xdd, - 0x73, 0xe6, 0x77, 0xfe, 0xfb, 0x9f, 0x33, 0x1f, 0x68, 0x39, 0x84, 0x28, 0x74, 0x46, 0x9b, 0x8e, - 0x3c, 0xb4, 0xc3, 0x88, 0x4b, 0x8e, 0x17, 0x19, 0xed, 0xd1, 0x28, 0xb6, 0x55, 0xc0, 0x1e, 0x6d, - 0x36, 0x57, 0x7d, 0xce, 0xfd, 0x00, 0x1c, 0x12, 0x52, 0x87, 0x30, 0xc6, 0x25, 0x91, 0x94, 0x33, - 0x91, 0x64, 0x37, 0x5b, 0x7d, 0x2e, 0x86, 0x5c, 0x38, 0x3d, 0x22, 0xc0, 0x19, 0x6d, 0xf6, 0x40, - 0x92, 0x4d, 0xa7, 0xcf, 0x29, 0x4b, 0xe3, 0x75, 0x9f, 0xfb, 0x5c, 0xff, 0x75, 0xd4, 0xbf, 0xf4, - 0xed, 0xab, 0x59, 0x55, 0x21, 0x89, 0x84, 0xe4, 0xa5, 0xf5, 0x9d, 0x81, 0x96, 0xda, 0xc2, 0xef, - 0xc2, 0x90, 0x8f, 0xa0, 0x4d, 0x22, 0x9f, 0x32, 0xdc, 0x40, 0x55, 0x01, 0xcc, 0x83, 0xc8, 0x34, - 0xd6, 0x8d, 0x8d, 0x5a, 0x37, 0x7d, 0xc2, 0x37, 0x11, 0x92, 0xfc, 0x21, 0x30, 0x37, 0x24, 0x34, - 0x32, 0x67, 0x75, 0xac, 0xa6, 0xdf, 0x74, 0x08, 0x8d, 0xf0, 0x07, 0xa8, 0x3a, 0xd4, 0x00, 0x73, - 0x6e, 0xdd, 0xd8, 0xb8, 0xba, 0x75, 0xc3, 0x4e, 0x64, 0xda, 0x4a, 0xa6, 0x9d, 0xca, 0xb4, 0x77, - 0x39, 0x65, 0x3b, 0x95, 0x27, 0xcf, 0xd6, 0x66, 0xba, 0x69, 0xba, 0xf5, 0x97, 0x81, 0x56, 0xa6, - 0x34, 0x74, 0x41, 0x84, 0x9c, 0x09, 0xc0, 0x1f, 0x22, 0x94, 0x64, 0xb9, 0x3c, 0x96, 0x5a, 0xcf, - 0x05, 0xc0, 0xb5, 0x64, 0xc8, 0xdd, 0x58, 0xe2, 0xcf, 0xd1, 0xd2, 0x20, 0x66, 0x1e, 0x65, 0xbe, - 0x1b, 0x92, 0xa3, 0x21, 0x30, 0x99, 0x08, 0xdf, 0xb1, 0x55, 0xe6, 0xef, 0xcf, 0xd6, 0xde, 0xf2, - 0xa9, 0x3c, 0x88, 0x7b, 0x76, 0x9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8b, 0xc1, 0x3c, 0x54, 0xfd, 0x90, 0x55, 0xfb, 0xd6, 0x40, - 0xd7, 0x26, 0x7b, 0x69, 0xbd, 0x00, 0x3f, 0x91, 0xd1, 0xdc, 0x38, 0x2f, 0x23, 0x57, 0xf0, 0x86, - 0x56, 0x70, 0xd3, 0x7a, 0x7d, 0x42, 0x41, 0x5f, 0xe5, 0xe6, 0x12, 0x76, 0x6e, 0x3d, 0x39, 0x69, - 0x19, 0x4f, 0x4f, 0x5a, 0xc6, 0x1f, 0x27, 0x2d, 0xe3, 0xc7, 0xd3, 0xd6, 0xcc, 0xd3, 0xd3, 0xd6, - 0xcc, 0x6f, 0xa7, 0xad, 0x99, 0x2f, 0xde, 0x19, 0x5b, 0x24, 0x77, 0x34, 0x60, 0xf7, 0x80, 0x50, - 0x96, 0xc1, 0x0e, 0x13, 0x9c, 0x5e, 0x2c, 0xbd, 0xaa, 0xbe, 0x43, 0xbf, 0xf7, 0x77, 0x00, 0x00, - 0x00, 0xff, 0xff, 0x10, 0xc3, 0x73, 0x48, 0xd0, 0x0b, 0x00, 0x00, + // 1010 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x97, 0xdd, 0x6e, 0xdc, 0x44, + 0x18, 0x86, 0xe3, 0xec, 0x36, 0x34, 0xd3, 0x34, 0xd9, 0x0e, 0xcb, 0xc6, 0x5d, 0xd2, 0x4d, 0x64, + 0x10, 0x44, 0x48, 0xd8, 0x4a, 0x40, 0xe2, 0x0c, 0x29, 0x49, 0x41, 0x2a, 0x64, 0xdb, 0x65, 0x1b, + 0x05, 0x44, 0x41, 0x66, 0x76, 0xfd, 0xad, 0x33, 0xaa, 0x77, 0xc6, 0xf5, 0x8c, 0x57, 0x49, 0x54, + 0x21, 0x7e, 0x6e, 0x00, 0x89, 0x6b, 0xe0, 0x3e, 0x38, 0xec, 0x61, 0x25, 0x4e, 0x10, 0x07, 0x15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xf1, 0xe8, 0xbc, 0xa9, 0x5b, 0xea, 0x01, + 0xec, 0xf1, 0xdd, 0x7c, 0x1e, 0xbe, 0x83, 0xea, 0x29, 0x4c, 0x3d, 0xa9, 0x0b, 0x5d, 0x2e, 0x8e, + 0x84, 0x84, 0xbe, 0xab, 0x2c, 0x4a, 0xcd, 0x38, 0x93, 0x5a, 0xd3, 0xd4, 0x16, 0x44, 0xe1, 0x07, + 0xd9, 0xfc, 0x0f, 0x63, 0xe6, 0x59, 0xdf, 0x97, 0xf4, 0x8b, 0x7b, 0x2b, 0x04, 0x96, 0xf9, 0x57, + 0xd4, 0xa5, 0x75, 0x54, 0x16, 0xd4, 0x03, 0xed, 0xd1, 0xe2, 0x66, 0x75, 0x72, 0x79, 0x6e, 0x53, + 0x0f, 0xda, 0xba, 0x02, 0x7f, 0x81, 0xf0, 0xbd, 0x98, 0x4b, 0x70, 0x89, 0x10, 0x20, 0x5d, 0xd2, + 0xe7, 0x31, 0x93, 0x66, 0xf9, 0xa9, 0x83, 0x72, 0x83, 0xc9, 0x76, 0x45, 0x93, 0xb6, 0x14, 0x68, + 0x4b, 0x73, 0xf0, 0x47, 0xe8, 0x62, 0x00, 0x03, 0x88, 0x88, 0x0f, 0xe6, 0x85, 0x42, 0xe1, 0xcb, + 0xe7, 0x63, 0x40, 0xcb, 0xca, 0xd1, 0x31, 0xa1, 0x6e, 0x40, 0xfb, 0x54, 0x9a, 0x73, 0x85, 0xe4, + 0x56, 0x15, 0x6e, 0x44, 0xed, 0xae, 0x62, 0x59, 0x8f, 0x2f, 0xe8, 0xad, 0x6b, 0x74, 0x15, 0xf2, + 0x2c, 0x8d, 0x26, 0xdf, 0x38, 0x6f, 0xf2, 0xf1, 0x01, 0x32, 0xe1, 0xb0, 0x7b, 0x40, 0x98, 0x0f, + 0x9e, 0xcb, 0xb8, 0xba, 0x47, 0x02, 0x77, 0x40, 0x82, 0x18, 0x0a, 0xee, 0x5c, 0xb5, 0x9c, 0x77, + 0x33, 0x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0xe1, 0xce, 0x9c, + 0xfe, 0xe7, 0xe8, 0x9d, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0xfe, 0x27, 0xa7, 0x11, 0xa9, 0x0d, + 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1402,6 +1416,56 @@ func (m *MsgClosePositionResponse) MarshalToSizedBuffer(dAtA []byte) (int, error _ = i var l int _ = l + { + size := m.MarginToTrader.Size() + i -= size + if _, err := m.MarginToTrader.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x3a + { + size := m.RealizedPnl.Size() + i -= size + if _, err := m.RealizedPnl.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + { + size := m.FundingPayment.Size() + i -= size + if _, err := m.FundingPayment.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + { + size := m.ExchangedPositionSize.Size() + i -= size + if _, err := m.ExchangedPositionSize.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size := m.ExchangedNotionalValue.Size() + i -= size + if _, err := m.ExchangedNotionalValue.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -1596,6 +1660,16 @@ func (m *MsgClosePositionResponse) Size() (n int) { } var l int _ = l + l = m.ExchangedNotionalValue.Size() + n += 1 + l + sovTx(uint64(l)) + l = m.ExchangedPositionSize.Size() + n += 1 + l + sovTx(uint64(l)) + l = m.FundingPayment.Size() + n += 1 + l + sovTx(uint64(l)) + l = m.RealizedPnl.Size() + n += 1 + l + sovTx(uint64(l)) + l = m.MarginToTrader.Size() + n += 1 + l + sovTx(uint64(l)) return n } @@ -3136,6 +3210,176 @@ func (m *MsgClosePositionResponse) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: MsgClosePositionResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ExchangedNotionalValue", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ExchangedNotionalValue.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ExchangedPositionSize", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ExchangedPositionSize.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FundingPayment", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.FundingPayment.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RealizedPnl", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.RealizedPnl.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MarginToTrader", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.MarginToTrader.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:])