diff --git a/proto/perp/v1/tx.proto b/proto/perp/v1/tx.proto index 7c06aff28..f4f6df314 100644 --- a/proto/perp/v1/tx.proto +++ b/proto/perp/v1/tx.proto @@ -30,6 +30,10 @@ service Msg { option (google.api.http).post = "/nibiru/perp/open_position"; } + rpc ClosePosition(MsgClosePosition) returns (MsgClosePositionResponse) { + option (google.api.http).post = "/nibiru/perp/close_position"; + } + } // -------------------------- RemoveMargin -------------------------- @@ -110,4 +114,14 @@ message MsgOpenPositionResponse { } // -------------------------- ClosePosition -------------------------- -// TODO \ No newline at end of file + +message MsgClosePosition { + bytes sender = 1 [ + (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"]; + + string token_pair = 2; +} + +message MsgClosePositionResponse { + +} \ No newline at end of file diff --git a/x/perp/client/cli/cli_test.go b/x/perp/client/cli/cli_test.go index 73be74aac..47f9961a7 100644 --- a/x/perp/client/cli/cli_test.go +++ b/x/perp/client/cli/cli_test.go @@ -26,6 +26,7 @@ type IntegrationTestSuite struct { cfg testutilcli.Config network *testutilcli.Network + users []sdk.AccAddress } func (s *IntegrationTestSuite) SetupSuite() { @@ -54,6 +55,14 @@ func (s *IntegrationTestSuite) SetupSuite() { FluctuationLimitRatio: sdk.MustNewDecFromStr("0.2"), MaxOracleSpreadRatio: sdk.MustNewDecFromStr("0.2"), }, + { + Pair: "eth:unibi", + BaseAssetReserve: sdk.MustNewDecFromStr("10000000"), + QuoteAssetReserve: sdk.MustNewDecFromStr("60000000000"), + TradeLimitRatio: sdk.MustNewDecFromStr("0.8"), + FluctuationLimitRatio: sdk.MustNewDecFromStr("0.2"), + MaxOracleSpreadRatio: sdk.MustNewDecFromStr("0.2"), + }, } genesisState[vpooltypes.ModuleName] = s.cfg.Codec.MustMarshalJSON(vpoolGenesis) @@ -65,6 +74,12 @@ func (s *IntegrationTestSuite) SetupSuite() { sdk.ZeroDec(), }, }, + { + Pair: "eth:unibi", + CumulativePremiumFractions: []sdk.Dec{ + sdk.ZeroDec(), + }, + }, } genesisState[perptypes.ModuleName] = s.cfg.Codec.MustMarshalJSON(perpGenesis) @@ -76,6 +91,20 @@ func (s *IntegrationTestSuite) SetupSuite() { _, err := s.network.WaitForHeight(1) s.Require().NoError(err) + + val := s.network.Validators[0] + info, _, err := val.ClientCtx.Keyring. + NewMnemonic("user1", keyring.English, sdk.FullFundraiserPath, "", hd.Secp256k1) + s.Require().NoError(err) + user1 := sdk.AccAddress(info.GetPubKey().Address()) + + info2, _, err := val.ClientCtx.Keyring. + NewMnemonic("user2", keyring.English, sdk.FullFundraiserPath, "", hd.Secp256k1) + s.Require().NoError(err) + user2 := sdk.AccAddress(info2.GetPubKey().Address()) + + // TODO: figure out why using user2 gives a "key not found" error + s.users = []sdk.AccAddress{user1, user2} } func (s *IntegrationTestSuite) TearDownSuite() { @@ -90,13 +119,9 @@ func (s *IntegrationTestSuite) TestOpenPositionCmd() { Token1: "unibi", } - info, _, err := val.ClientCtx.Keyring. - NewMnemonic("user1", keyring.English, sdk.FullFundraiserPath, "", hd.Secp256k1) - s.Require().NoError(err) - - user := sdk.AccAddress(info.GetPubKey().Address()) + user := s.users[0] - _, err = utils.FillWalletFromValidator(user, + _, err := utils.FillWalletFromValidator(user, sdk.NewCoins( sdk.NewInt64Coin(s.cfg.BondDenom, 20_000), sdk.NewInt64Coin(common.GovDenom, 100_000_000), @@ -184,6 +209,47 @@ func (s *IntegrationTestSuite) TestOpenPositionCmd() { s.Require().Equal(sdk.MustNewDecFromStr("999900"), queryResp.Position.OpenNotional) } +func (s *IntegrationTestSuite) TestPositionEmptyAndClose() { + val := s.network.Validators[0] + pair := common.AssetPair{ + Token0: "eth", + Token1: "unibi", + } + + user := s.users[0] + + _, err := utils.FillWalletFromValidator(user, + sdk.NewCoins( + sdk.NewInt64Coin(s.cfg.BondDenom, 20_000), + sdk.NewInt64Coin(common.GovDenom, 100_000_000), + sdk.NewInt64Coin(common.CollDenom, 100_000_000), + ), + val, + s.cfg.BondDenom, + ) + s.Require().NoError(err) + + // verify trader has no position (empty) + _, err = testutilcli.QueryTraderPosition(val.ClientCtx, pair, user) + s.Require().True(strings.Contains(err.Error(), "no position found")) + + // close position should produce error + args := []string{ + "--from", + user.String(), + fmt.Sprintf("%s%s%s", "eth", common.PairSeparator, "unibi"), + } + commonArgs := []string{ + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(10))).String()), + } + // TODO: fix that this err doesn't get propagated back up to show up here + res, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cli.ClosePositionCmd(), append(args, commonArgs...)) + s.T().Logf("res: %+v", res) + s.T().Logf("err: %+v", err) +} + func TestIntegrationTestSuite(t *testing.T) { suite.Run(t, new(IntegrationTestSuite)) } diff --git a/x/perp/client/cli/tx.go b/x/perp/client/cli/tx.go index 481c1c02f..f247f040c 100644 --- a/x/perp/client/cli/tx.go +++ b/x/perp/client/cli/tx.go @@ -100,6 +100,42 @@ func OpenPositionCmd() *cobra.Command { return cmd } +// TODO: how is a position idenitfiied? by pair? by id? +func ClosePositionCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "close-position [pair]", + Short: "Closes a position", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + txf := tx.NewFactoryCLI(clientCtx, cmd.Flags()). + WithTxConfig(clientCtx.TxConfig).WithAccountRetriever(clientCtx.AccountRetriever) + + msg := &types.MsgClosePosition{ + Sender: clientCtx.GetFromAddress(), + TokenPair: args[0], + } + if err = msg.ValidateBasic(); err != nil { + return err + } + + err = tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg) + if err != nil { + return err + } + return nil + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} + /* RemoveMarginCmd is a CLI command that removes margin from a position, realizing any outstanding funding payments and decreasing the margin ratio. diff --git a/x/perp/handler.go b/x/perp/handler.go index d346d79e0..146448978 100644 --- a/x/perp/handler.go +++ b/x/perp/handler.go @@ -37,6 +37,9 @@ func NewHandler(k keeper.Keeper) sdk.Handler { case *types.MsgLiquidate: res, err := msgServer.Liquidate(sdk.WrapSDKContext(ctx), msg) return sdk.WrapServiceResult(ctx, res, err) + case *types.MsgClosePosition: + res, err := msgServer.ClosePosition(sdk.WrapSDKContext(ctx), msg) + return sdk.WrapServiceResult(ctx, res, err) default: errMsg := fmt.Sprintf( "unrecognized %s message type: %T", types.ModuleName, msg) diff --git a/x/perp/keeper/clearing_house.go b/x/perp/keeper/clearing_house.go index 8b1f9f11f..d13464c3f 100644 --- a/x/perp/keeper/clearing_house.go +++ b/x/perp/keeper/clearing_house.go @@ -150,6 +150,35 @@ func (k Keeper) OpenPosition( }) } +func (k Keeper) ClosePosition( + ctx sdk.Context, + pair common.AssetPair, + traderAddr sdk.AccAddress, +) (err error) { + // checks + err = k.requireVpool(ctx, pair) + if err != nil { + return err + } + + position, err := k.GetPosition(ctx, pair, traderAddr) + if err != nil { + // TODO: propagate this back to the cli + return err + } + + _, err = k.closePositionEntirely( + ctx, + *position, + sdk.ZeroDec(), // TODO: double check this + ) + + if err != nil { + return err + } + return nil +} + /* increases a position by increasedNotional amount in margin units. Calculates the amount of margin required given the leverage parameter. diff --git a/x/perp/keeper/msg_server.go b/x/perp/keeper/msg_server.go index 184afc0fa..fab3d41e1 100644 --- a/x/perp/keeper/msg_server.go +++ b/x/perp/keeper/msg_server.go @@ -66,3 +66,21 @@ func (k msgServer) Liquidate(goCtx context.Context, msg *types.MsgLiquidate, return response, nil } + +func (k msgServer) ClosePosition(goCtx context.Context, req *types.MsgClosePosition, +) (*types.MsgClosePositionResponse, error) { + pair, err := common.NewAssetPairFromStr(req.TokenPair) + if err != nil { + panic(err) // must not happen + } + + ctx := sdk.UnwrapSDKContext(goCtx) + + // TODO: fix that this err doesn't get returned if using tx broadcast in cli_test + err = k.k.ClosePosition(ctx, pair, req.Sender) + if err != nil { + return nil, sdkerrors.Wrap(vpooltypes.ErrClosingPosition, err.Error()) + } + + return &types.MsgClosePositionResponse{}, nil +} diff --git a/x/perp/types/codec.go b/x/perp/types/codec.go index ae29e2f5f..476c3603b 100644 --- a/x/perp/types/codec.go +++ b/x/perp/types/codec.go @@ -11,6 +11,7 @@ func RegisterCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(&MsgRemoveMargin{}, "perp/remove_margin", nil) cdc.RegisterConcrete(&MsgAddMargin{}, "perp/add_margin", nil) cdc.RegisterConcrete(&MsgLiquidate{}, "perp/liquidate", nil) + cdc.RegisterConcrete(&MsgClosePosition{}, "perp/close_position", nil) } func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { @@ -21,6 +22,7 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { &MsgAddMargin{}, &MsgLiquidate{}, &MsgOpenPosition{}, + &MsgClosePosition{}, ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) diff --git a/x/perp/types/msgs.go b/x/perp/types/msgs.go index b134d8aab..d9174edf2 100644 --- a/x/perp/types/msgs.go +++ b/x/perp/types/msgs.go @@ -101,3 +101,29 @@ func (m MsgLiquidate) GetSignBytes() []byte { func (m MsgLiquidate) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{m.Sender} } + +// MsgClosePosition + +func (m MsgClosePosition) Route() string { return RouterKey } +func (m MsgClosePosition) Type() string { return "liquidate_msg" } + +func (m MsgClosePosition) ValidateBasic() error { + if err := sdk.VerifyAddressFormat(m.Sender); err != nil { + return err + } + if err := sdk.VerifyAddressFormat(m.Sender); err != nil { + return err + } + if _, err := common.NewAssetPairFromStr(m.TokenPair); err != nil { + return err + } + return nil +} + +func (m MsgClosePosition) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) +} + +func (m MsgClosePosition) GetSigners() []sdk.AccAddress { + return []sdk.AccAddress{m.Sender} +} diff --git a/x/perp/types/tx.pb.go b/x/perp/types/tx.pb.go index b6bea289b..bbb9a6971 100644 --- a/x/perp/types/tx.pb.go +++ b/x/perp/types/tx.pb.go @@ -449,6 +449,94 @@ func (m *MsgOpenPositionResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgOpenPositionResponse proto.InternalMessageInfo +type MsgClosePosition struct { + Sender github_com_cosmos_cosmos_sdk_types.AccAddress `protobuf:"bytes,1,opt,name=sender,proto3,casttype=github.com/cosmos/cosmos-sdk/types.AccAddress" json:"sender,omitempty"` + TokenPair string `protobuf:"bytes,2,opt,name=token_pair,json=tokenPair,proto3" json:"token_pair,omitempty"` +} + +func (m *MsgClosePosition) Reset() { *m = MsgClosePosition{} } +func (m *MsgClosePosition) String() string { return proto.CompactTextString(m) } +func (*MsgClosePosition) ProtoMessage() {} +func (*MsgClosePosition) Descriptor() ([]byte, []int) { + return fileDescriptor_28f06b306d51dcfb, []int{8} +} +func (m *MsgClosePosition) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgClosePosition) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgClosePosition.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 *MsgClosePosition) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgClosePosition.Merge(m, src) +} +func (m *MsgClosePosition) XXX_Size() int { + return m.Size() +} +func (m *MsgClosePosition) XXX_DiscardUnknown() { + xxx_messageInfo_MsgClosePosition.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgClosePosition proto.InternalMessageInfo + +func (m *MsgClosePosition) GetSender() github_com_cosmos_cosmos_sdk_types.AccAddress { + if m != nil { + return m.Sender + } + return nil +} + +func (m *MsgClosePosition) GetTokenPair() string { + if m != nil { + return m.TokenPair + } + return "" +} + +type MsgClosePositionResponse struct { +} + +func (m *MsgClosePositionResponse) Reset() { *m = MsgClosePositionResponse{} } +func (m *MsgClosePositionResponse) String() string { return proto.CompactTextString(m) } +func (*MsgClosePositionResponse) ProtoMessage() {} +func (*MsgClosePositionResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_28f06b306d51dcfb, []int{9} +} +func (m *MsgClosePositionResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgClosePositionResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgClosePositionResponse.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 *MsgClosePositionResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgClosePositionResponse.Merge(m, src) +} +func (m *MsgClosePositionResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgClosePositionResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgClosePositionResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgClosePositionResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgRemoveMargin)(nil), "nibiru.perp.v1.MsgRemoveMargin") proto.RegisterType((*MsgRemoveMarginResponse)(nil), "nibiru.perp.v1.MsgRemoveMarginResponse") @@ -458,60 +546,65 @@ func init() { proto.RegisterType((*MsgLiquidateResponse)(nil), "nibiru.perp.v1.MsgLiquidateResponse") proto.RegisterType((*MsgOpenPosition)(nil), "nibiru.perp.v1.MsgOpenPosition") proto.RegisterType((*MsgOpenPositionResponse)(nil), "nibiru.perp.v1.MsgOpenPositionResponse") + proto.RegisterType((*MsgClosePosition)(nil), "nibiru.perp.v1.MsgClosePosition") + proto.RegisterType((*MsgClosePositionResponse)(nil), "nibiru.perp.v1.MsgClosePositionResponse") } func init() { proto.RegisterFile("perp/v1/tx.proto", fileDescriptor_28f06b306d51dcfb) } var fileDescriptor_28f06b306d51dcfb = []byte{ - // 760 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x55, 0xcf, 0x6b, 0x13, 0x4f, - 0x14, 0xcf, 0x36, 0xfd, 0x86, 0x6f, 0xc6, 0xd0, 0xd6, 0x35, 0xb4, 0x69, 0xa8, 0x9b, 0xb2, 0x88, - 0x06, 0xa1, 0xbb, 0xa4, 0x1e, 0xbc, 0x09, 0x49, 0xab, 0x50, 0x6d, 0x6c, 0x58, 0x05, 0x41, 0x85, - 0x65, 0x92, 0x7d, 0xdd, 0x0e, 0xcd, 0xce, 0x6c, 0x77, 0x66, 0x43, 0x0b, 0x3d, 0xf9, 0x17, 0x08, - 0xfe, 0x25, 0x8a, 0x78, 0x16, 0xbc, 0xf4, 0x58, 0xf0, 0x22, 0x1e, 0x8a, 0xb4, 0xfd, 0x2b, 0x3c, - 0xc9, 0xce, 0x6e, 0xb6, 0x49, 0x8d, 0x1a, 0x7b, 0x28, 0x78, 0x4a, 0x98, 0xf7, 0xde, 0xe7, 0xf3, - 0x7e, 0x7d, 0xde, 0xa2, 0x19, 0x1f, 0x02, 0xdf, 0xec, 0xd5, 0x4c, 0xb1, 0x6b, 0xf8, 0x01, 0x13, - 0x4c, 0x9d, 0xa2, 0xa4, 0x4d, 0x82, 0xd0, 0x88, 0x0c, 0x46, 0xaf, 0x56, 0x5e, 0x70, 0x19, 0x73, - 0xbb, 0x60, 0x62, 0x9f, 0x98, 0x98, 0x52, 0x26, 0xb0, 0x20, 0x8c, 0xf2, 0xd8, 0xbb, 0xac, 0x75, - 0x18, 0xf7, 0x18, 0x37, 0xdb, 0x98, 0x83, 0xd9, 0xab, 0xb5, 0x41, 0xe0, 0x9a, 0xd9, 0x61, 0x84, - 0x26, 0xf6, 0xa2, 0xcb, 0x5c, 0x26, 0xff, 0x9a, 0xd1, 0xbf, 0xe4, 0xf5, 0x5a, 0x9f, 0x95, 0x0b, - 0x2c,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 0x81, 0xcd, 0x7a, 0x2c, 0xe3, 0x57, 0xb6, 0x30, 0xa1, 0x7d, 0xac, - 0xdd, 0x18, 0x4d, 0x6e, 0x58, 0x3b, 0x27, 0x3f, 0xe4, 0x77, 0x7e, 0x04, 0x00, 0x00, 0xff, 0xff, - 0x88, 0x6f, 0x04, 0xc5, 0x55, 0x08, 0x00, 0x00, + // 813 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x56, 0xdf, 0x6b, 0xeb, 0x54, + 0x1c, 0x6f, 0x6e, 0x6b, 0xb1, 0xc7, 0xba, 0xcd, 0x58, 0xb6, 0x2c, 0xee, 0xa6, 0x25, 0x8a, 0x16, + 0xe1, 0x26, 0x74, 0x3e, 0xf8, 0x26, 0xb4, 0xbb, 0x0a, 0xd3, 0xd5, 0x5b, 0xa2, 0x20, 0xa8, 0x10, + 0x4e, 0x93, 0xef, 0x72, 0x0f, 0xb7, 0x39, 0x27, 0x37, 0xe7, 0xa4, 0x6c, 0xb0, 0x07, 0xf1, 0x2f, + 0x10, 0xfc, 0x4b, 0x14, 0xf1, 0x59, 0xf0, 0x65, 0x8f, 0x03, 0x5f, 0xc4, 0x87, 0x21, 0x9b, 0xe0, + 0xff, 0xe0, 0x93, 0xe4, 0x24, 0xcd, 0x9a, 0x1a, 0x5c, 0xdd, 0xc3, 0xc0, 0xa7, 0x86, 0x9c, 0xcf, + 0xf9, 0x7c, 0x3e, 0xdf, 0x9f, 0x29, 0xda, 0x8a, 0x20, 0x8e, 0xec, 0xf9, 0xc0, 0x16, 0x27, 0x56, + 0x14, 0x33, 0xc1, 0xd4, 0x0d, 0x4a, 0xa6, 0x24, 0x4e, 0xac, 0xf4, 0xc0, 0x9a, 0x0f, 0xf4, 0xbd, + 0x80, 0xb1, 0x60, 0x06, 0x36, 0x8e, 0x88, 0x8d, 0x29, 0x65, 0x02, 0x0b, 0xc2, 0x28, 0xcf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 0xa9, 0xa8, 0x99, 0xdb, 0x25, 0xc5, 0x59, 0xa1, 0x71, 0x86, 0xda, 0xa5, 0x91, + 0xae, 0x4a, 0xf0, 0x32, 0xa0, 0x32, 0xc1, 0x95, 0xcd, 0x55, 0x9d, 0x60, 0x16, 0xa5, 0xfd, 0xb0, + 0x50, 0xfb, 0x4a, 0x41, 0x2f, 0x97, 0xdb, 0xaf, 0x57, 0x41, 0x5f, 0x42, 0xe8, 0xfd, 0xdb, 0x10, + 0x85, 0x83, 0xd7, 0xa5, 0x83, 0x87, 0xe6, 0x6b, 0x25, 0x07, 0x5e, 0x8a, 0x2d, 0x2c, 0x8c, 0x1e, + 0x9f, 0x5f, 0x19, 0xca, 0xc5, 0x95, 0xa1, 0xfc, 0x7e, 0x65, 0x28, 0xdf, 0x5c, 0x1b, 0xb5, 0x8b, + 0x6b, 0xa3, 0xf6, 0xeb, 0xb5, 0x51, 0xfb, 0xfc, 0xed, 0xa5, 0xae, 0xff, 0x58, 0x12, 0x1c, 0x3c, + 0xc5, 0x84, 0x2e, 0xc8, 0x4e, 0x32, 0x3a, 0xd9, 0xfd, 0xd3, 0xa6, 0xfc, 0x97, 0xf3, 0xce, 0xdf, + 0x01, 0x00, 0x00, 0xff, 0xff, 0xb5, 0xdb, 0xb0, 0x9a, 0x72, 0x09, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -532,6 +625,7 @@ type MsgClient interface { // liquidate an existing position. Liquidate(ctx context.Context, in *MsgLiquidate, opts ...grpc.CallOption) (*MsgLiquidateResponse, error) OpenPosition(ctx context.Context, in *MsgOpenPosition, opts ...grpc.CallOption) (*MsgOpenPositionResponse, error) + ClosePosition(ctx context.Context, in *MsgClosePosition, opts ...grpc.CallOption) (*MsgClosePositionResponse, error) } type msgClient struct { @@ -578,6 +672,15 @@ func (c *msgClient) OpenPosition(ctx context.Context, in *MsgOpenPosition, opts return out, nil } +func (c *msgClient) ClosePosition(ctx context.Context, in *MsgClosePosition, opts ...grpc.CallOption) (*MsgClosePositionResponse, error) { + out := new(MsgClosePositionResponse) + err := c.cc.Invoke(ctx, "/nibiru.perp.v1.Msg/ClosePosition", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { RemoveMargin(context.Context, *MsgRemoveMargin) (*MsgRemoveMarginResponse, error) @@ -586,6 +689,7 @@ type MsgServer interface { // liquidate an existing position. Liquidate(context.Context, *MsgLiquidate) (*MsgLiquidateResponse, error) OpenPosition(context.Context, *MsgOpenPosition) (*MsgOpenPositionResponse, error) + ClosePosition(context.Context, *MsgClosePosition) (*MsgClosePositionResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -604,6 +708,9 @@ func (*UnimplementedMsgServer) Liquidate(ctx context.Context, req *MsgLiquidate) func (*UnimplementedMsgServer) OpenPosition(ctx context.Context, req *MsgOpenPosition) (*MsgOpenPositionResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method OpenPosition not implemented") } +func (*UnimplementedMsgServer) ClosePosition(ctx context.Context, req *MsgClosePosition) (*MsgClosePositionResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ClosePosition not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -681,6 +788,24 @@ func _Msg_OpenPosition_Handler(srv interface{}, ctx context.Context, dec func(in return interceptor(ctx, in, info, handler) } +func _Msg_ClosePosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgClosePosition) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).ClosePosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/nibiru.perp.v1.Msg/ClosePosition", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).ClosePosition(ctx, req.(*MsgClosePosition)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "nibiru.perp.v1.Msg", HandlerType: (*MsgServer)(nil), @@ -701,6 +826,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "OpenPosition", Handler: _Msg_OpenPosition_Handler, }, + { + MethodName: "ClosePosition", + Handler: _Msg_ClosePosition_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "perp/v1/tx.proto", @@ -1048,6 +1177,66 @@ func (m *MsgOpenPositionResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) return len(dAtA) - i, nil } +func (m *MsgClosePosition) 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 *MsgClosePosition) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgClosePosition) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.TokenPair) > 0 { + i -= len(m.TokenPair) + copy(dAtA[i:], m.TokenPair) + i = encodeVarintTx(dAtA, i, uint64(len(m.TokenPair))) + i-- + dAtA[i] = 0x12 + } + if len(m.Sender) > 0 { + i -= len(m.Sender) + copy(dAtA[i:], m.Sender) + i = encodeVarintTx(dAtA, i, uint64(len(m.Sender))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgClosePositionResponse) 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 *MsgClosePositionResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgClosePositionResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -1188,6 +1377,32 @@ func (m *MsgOpenPositionResponse) Size() (n int) { return n } +func (m *MsgClosePosition) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Sender) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.TokenPair) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgClosePositionResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -2212,6 +2427,172 @@ func (m *MsgOpenPositionResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgClosePosition) 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 ErrIntOverflowTx + } + 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: MsgClosePosition: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgClosePosition: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Sender", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Sender = append(m.Sender[:0], dAtA[iNdEx:postIndex]...) + if m.Sender == nil { + m.Sender = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TokenPair", 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 + } + m.TokenPair = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgClosePositionResponse) 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 ErrIntOverflowTx + } + 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: MsgClosePositionResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgClosePositionResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/perp/types/tx.pb.gw.go b/x/perp/types/tx.pb.gw.go index 28f98194c..86065c231 100644 --- a/x/perp/types/tx.pb.gw.go +++ b/x/perp/types/tx.pb.gw.go @@ -175,6 +175,42 @@ func local_request_Msg_OpenPosition_0(ctx context.Context, marshaler runtime.Mar } +var ( + filter_Msg_ClosePosition_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Msg_ClosePosition_0(ctx context.Context, marshaler runtime.Marshaler, client MsgClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq MsgClosePosition + 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_Msg_ClosePosition_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.ClosePosition(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Msg_ClosePosition_0(ctx context.Context, marshaler runtime.Marshaler, server MsgServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq MsgClosePosition + 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_Msg_ClosePosition_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.ClosePosition(ctx, &protoReq) + return msg, metadata, err + +} + // RegisterMsgHandlerServer registers the http handlers for service Msg to "mux". // UnaryRPC :call MsgServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. @@ -261,6 +297,26 @@ func RegisterMsgHandlerServer(ctx context.Context, mux *runtime.ServeMux, server }) + mux.Handle("POST", pattern_Msg_ClosePosition_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.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Msg_ClosePosition_0(rctx, inboundMarshaler, server, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Msg_ClosePosition_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -382,6 +438,26 @@ func RegisterMsgHandlerClient(ctx context.Context, mux *runtime.ServeMux, client }) + mux.Handle("POST", pattern_Msg_ClosePosition_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_Msg_ClosePosition_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Msg_ClosePosition_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -393,6 +469,8 @@ var ( pattern_Msg_Liquidate_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"nibiru", "perp", "liquidate"}, "", runtime.AssumeColonVerbOpt(false))) pattern_Msg_OpenPosition_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"nibiru", "perp", "open_position"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Msg_ClosePosition_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"nibiru", "perp", "close_position"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( @@ -403,4 +481,6 @@ var ( forward_Msg_Liquidate_0 = runtime.ForwardResponseMessage forward_Msg_OpenPosition_0 = runtime.ForwardResponseMessage + + forward_Msg_ClosePosition_0 = runtime.ForwardResponseMessage ) diff --git a/x/vpool/types/errors.go b/x/vpool/types/errors.go index 75e275394..1c0b5f1ba 100644 --- a/x/vpool/types/errors.go +++ b/x/vpool/types/errors.go @@ -11,4 +11,5 @@ var ( ErrOverFluctuationLimit = sdkerrors.Register(ModuleName, 6, "price is over fluctuation limit") ErrAssetOverUserLimit = sdkerrors.Register(ModuleName, 7, "amout of assets traded is over user-defined limit") ErrOpeningPosition = sdkerrors.Register(ModuleName, 8, "error opening position") + ErrClosingPosition = sdkerrors.Register(ModuleName, 9, "error closing position") ) diff --git a/x/vpool/types/vpool.pb.go b/x/vpool/types/vpool.pb.go index 2d5353ad7..edd766239 100644 --- a/x/vpool/types/vpool.pb.go +++ b/x/vpool/types/vpool.pb.go @@ -4,15 +4,14 @@ package types import ( - "fmt" - "io" - "math" - math_bits "math/bits" - + fmt "fmt" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" _ "github.com/gogo/protobuf/gogoproto" - "github.com/gogo/protobuf/proto" + proto "github.com/gogo/protobuf/proto" _ "github.com/regen-network/cosmos-proto" + io "io" + math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used.