From 4d728c702e4634ab0f29b9ebf7318bc826554f0a Mon Sep 17 00:00:00 2001 From: CryptoKage2306 <26vivek06@gmail.com> Date: Mon, 23 Sep 2024 18:54:34 +0530 Subject: [PATCH 1/3] feat: add take profit price Msg --- proto/elys/perpetual/tx.proto | 13 +- x/perpetual/client/cli/tx.go | 1 + .../client/cli/tx_update_take_profit_price.go | 51 ++ .../msg_server_update_take_profit_price.go | 44 ++ x/perpetual/types/codec.go | 2 + .../types/message_update_take_profit_price.go | 53 ++ .../message_update_take_profit_price_test.go | 67 +++ x/perpetual/types/tx.pb.go | 527 ++++++++++++++++-- 8 files changed, 697 insertions(+), 61 deletions(-) create mode 100644 x/perpetual/client/cli/tx_update_take_profit_price.go create mode 100644 x/perpetual/keeper/msg_server_update_take_profit_price.go create mode 100644 x/perpetual/types/message_update_take_profit_price.go create mode 100644 x/perpetual/types/message_update_take_profit_price_test.go diff --git a/proto/elys/perpetual/tx.proto b/proto/elys/perpetual/tx.proto index 3e5b45315..a681e8ea6 100644 --- a/proto/elys/perpetual/tx.proto +++ b/proto/elys/perpetual/tx.proto @@ -21,7 +21,8 @@ service Msg { rpc AddCollateral (MsgAddCollateral ) returns (MsgAddCollateralResponse ); rpc BrokerAddCollateral (MsgBrokerAddCollateral) returns (MsgAddCollateralResponse ); rpc UpdateStopLoss (MsgUpdateStopLoss ) returns (MsgUpdateStopLossResponse ); - rpc ClosePositions (MsgClosePositions ) returns (MsgClosePositionsResponse); + rpc ClosePositions (MsgClosePositions ) returns (MsgClosePositionsResponse ); + rpc UpdateTakeProfitPrice(MsgUpdateTakeProfitPrice) returns (MsgUpdateTakeProfitPriceResponse); } message MsgOpen { string creator = 1; @@ -126,4 +127,12 @@ message MsgUpdateStopLoss { string price = 3 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; } -message MsgUpdateStopLossResponse {} \ No newline at end of file +message MsgUpdateStopLossResponse {} + +message MsgUpdateTakeProfitPrice { + string creator = 1; + uint64 id = 2; + string price = 3 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; +} + +message MsgUpdateTakeProfitPriceResponse {} \ No newline at end of file diff --git a/x/perpetual/client/cli/tx.go b/x/perpetual/client/cli/tx.go index 5536ad2d8..8d6ec5a03 100644 --- a/x/perpetual/client/cli/tx.go +++ b/x/perpetual/client/cli/tx.go @@ -32,6 +32,7 @@ func GetTxCmd() *cobra.Command { cmd.AddCommand(CmdAddCollateral()) cmd.AddCommand(CmdClosePositions()) cmd.AddCommand(CmdUpdateStopLoss()) + cmd.AddCommand(CmdUpdateTakeProfitPrice()) // this line is used by starport scaffolding # 1 return cmd diff --git a/x/perpetual/client/cli/tx_update_take_profit_price.go b/x/perpetual/client/cli/tx_update_take_profit_price.go new file mode 100644 index 000000000..154012eca --- /dev/null +++ b/x/perpetual/client/cli/tx_update_take_profit_price.go @@ -0,0 +1,51 @@ +package cli + +import ( + "errors" + "strconv" + + "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/elys-network/elys/x/perpetual/types" + "github.com/spf13/cobra" +) + +func CmdUpdateTakeProfitPrice() *cobra.Command { + cmd := &cobra.Command{ + Use: "update-take-profit-price [id] [amount]", + Short: "Broadcast message update-take-profit-price", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) (err error) { + argPrice, err := sdk.NewDecFromStr(args[0]) + if err != nil { + return errors.New("invalid take profit amount") + } + positionId, err := strconv.Atoi(args[1]) + if err != nil { + return err + } + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + msg := types.NewMsgUpdateTakeProfitPrice( + clientCtx.GetFromAddress().String(), + uint64(positionId), + math.LegacyDec(argPrice), + ) + if err := msg.ValidateBasic(); err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/perpetual/keeper/msg_server_update_take_profit_price.go b/x/perpetual/keeper/msg_server_update_take_profit_price.go new file mode 100644 index 000000000..9356e28be --- /dev/null +++ b/x/perpetual/keeper/msg_server_update_take_profit_price.go @@ -0,0 +1,44 @@ +package keeper + +import ( + "context" + "fmt" + "strconv" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/elys-network/elys/x/perpetual/types" +) + +func (k msgServer) UpdateTakeProfitPrice(goCtx context.Context, msg *types.MsgUpdateTakeProfitPrice) (*types.MsgUpdateTakeProfitPriceResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // Load existing mtp + creator := sdk.MustAccAddressFromBech32(msg.Creator) + mtp, err := k.GetMTP(ctx, creator, msg.Id) + if err != nil { + return nil, err + } + + poolId := mtp.AmmPoolId + pool, found := k.GetPool(ctx, poolId) + if !found { + return nil, errorsmod.Wrap(types.ErrPoolDoesNotExist, fmt.Sprintf("poolId: %d", poolId)) + } + + if !pool.Enabled { + return nil, errorsmod.Wrap(types.ErrPerpetualDisabled, fmt.Sprintf("poolId: %d", poolId)) + } + + mtp.TakeProfitPrice = msg.Price + k.SetMTP(ctx, &mtp) + + event := sdk.NewEvent(types.EventOpen, + sdk.NewAttribute("id", strconv.FormatInt(int64(mtp.Id), 10)), + sdk.NewAttribute("address", mtp.Address), + sdk.NewAttribute("take_profit_price", mtp.TakeProfitPrice.String()), + ) + ctx.EventManager().EmitEvent(event) + + return &types.MsgUpdateTakeProfitPriceResponse{}, nil +} diff --git a/x/perpetual/types/codec.go b/x/perpetual/types/codec.go index 7e02efe0e..55a8a7f0a 100644 --- a/x/perpetual/types/codec.go +++ b/x/perpetual/types/codec.go @@ -21,6 +21,7 @@ func RegisterCodec(cdc *codec.LegacyAmino) { legacy.RegisterAminoMsg(cdc, &MsgAddCollateral{}, "perpetual/MsgAddCollateral") legacy.RegisterAminoMsg(cdc, &MsgClosePositions{}, "perpetual/ClosePositions") legacy.RegisterAminoMsg(cdc, &MsgUpdateStopLoss{}, "perpetual/MsgUpdateStopLoss") + legacy.RegisterAminoMsg(cdc, &MsgUpdateTakeProfitPrice{}, "perpetual/MsgUpdateTakeProfitPrice") // this line is used by starport scaffolding # 2 } @@ -33,6 +34,7 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { &MsgDewhitelist{}, &MsgAddCollateral{}, &MsgUpdateStopLoss{}, + &MsgUpdateTakeProfitPrice{}, ) registry.RegisterImplementations((*sdk.Msg)(nil), &MsgClosePositions{}, diff --git a/x/perpetual/types/message_update_take_profit_price.go b/x/perpetual/types/message_update_take_profit_price.go new file mode 100644 index 000000000..c7673dfb5 --- /dev/null +++ b/x/perpetual/types/message_update_take_profit_price.go @@ -0,0 +1,53 @@ +package types + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +const TypeMsgUpdateTakeProfitPrice= "update_take_profit_price" + +var _ sdk.Msg = &MsgUpdateTakeProfitPrice{} + +func NewMsgUpdateTakeProfitPrice(creator string, id uint64, price sdk.Dec) *MsgUpdateTakeProfitPrice { + return &MsgUpdateTakeProfitPrice{ + Creator: creator, + Id: id, + Price: price, + } +} + +func (msg *MsgUpdateTakeProfitPrice) Route() string { + return RouterKey +} + +func (msg *MsgUpdateTakeProfitPrice) Type() string { + return TypeMsgUpdateTakeProfitPrice +} + +func (msg *MsgUpdateTakeProfitPrice) GetSigners() []sdk.AccAddress { + creator, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + panic(err) + } + return []sdk.AccAddress{creator} +} + +func (msg *MsgUpdateTakeProfitPrice) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgUpdateTakeProfitPrice) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + } + + if msg.Price.IsNegative() { + return fmt.Errorf("take profit price cannot be negative") + } + return nil +} \ No newline at end of file diff --git a/x/perpetual/types/message_update_take_profit_price_test.go b/x/perpetual/types/message_update_take_profit_price_test.go new file mode 100644 index 000000000..c0359bbe9 --- /dev/null +++ b/x/perpetual/types/message_update_take_profit_price_test.go @@ -0,0 +1,67 @@ +package types_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/elys-network/elys/testutil/sample" + "github.com/elys-network/elys/x/perpetual/types" + "github.com/stretchr/testify/require" +) + +func TestMsgUpdatetakeProfitPrice(t *testing.T) { + msg := types.NewMsgUpdateTakeProfitPrice(sample.AccAddress(), 1, sdk.OneDec()) + require.Equal(t, msg.Route(), types.RouterKey) + require.Equal(t, msg.Type(), types.TypeMsgUpdateTakeProfitPrice) + require.Equal(t, msg.GetSigners(), []sdk.AccAddress{sdk.MustAccAddressFromBech32(msg.Creator)}) + require.Equal(t, msg.GetSignBytes(), sdk.MustSortJSON(types.ModuleCdc.MustMarshalJSON(msg))) + msg.Creator = "" + require.PanicsWithError(t, "empty address string is not allowed", func() { msg.GetSigners() }) + tests := []struct { + name string + setter func() + errMsg string + }{ + { + name: "success", + setter: func() { + msg.Creator = sample.AccAddress() + }, + errMsg: "", + }, + { + name: "invalid address", + setter: func() { + msg.Creator = "invalid_address" + }, + errMsg: "invalid creator address", + }, + { + name: "take profit price is 0", + setter: func() { + msg.Creator = sample.AccAddress() + msg.Price = sdk.ZeroDec() + }, + errMsg: "", + }, + { + name: "take profit price is < 0", + setter: func() { + msg.Creator = sample.AccAddress() + msg.Price = sdk.OneDec().MulInt64(-1) + }, + errMsg: "take profit price cannot be negative", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + tt.setter() + err := msg.ValidateBasic() + if tt.errMsg != "" { + require.ErrorContains(t, err, tt.errMsg) + } else { + require.NoError(t, err) + } + }) + } +} diff --git a/x/perpetual/types/tx.pb.go b/x/perpetual/types/tx.pb.go index 999b20493..a79858399 100644 --- a/x/perpetual/types/tx.pb.go +++ b/x/perpetual/types/tx.pb.go @@ -984,6 +984,95 @@ func (m *MsgUpdateStopLossResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgUpdateStopLossResponse proto.InternalMessageInfo +type MsgUpdateTakeProfitPrice struct { + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + Id uint64 `protobuf:"varint,2,opt,name=id,proto3" json:"id,omitempty"` + Price github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=price,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"price"` +} + +func (m *MsgUpdateTakeProfitPrice) Reset() { *m = MsgUpdateTakeProfitPrice{} } +func (m *MsgUpdateTakeProfitPrice) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateTakeProfitPrice) ProtoMessage() {} +func (*MsgUpdateTakeProfitPrice) Descriptor() ([]byte, []int) { + return fileDescriptor_5e879ed5011cdd71, []int{19} +} +func (m *MsgUpdateTakeProfitPrice) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateTakeProfitPrice) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateTakeProfitPrice.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 *MsgUpdateTakeProfitPrice) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateTakeProfitPrice.Merge(m, src) +} +func (m *MsgUpdateTakeProfitPrice) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateTakeProfitPrice) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateTakeProfitPrice.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateTakeProfitPrice proto.InternalMessageInfo + +func (m *MsgUpdateTakeProfitPrice) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + +func (m *MsgUpdateTakeProfitPrice) GetId() uint64 { + if m != nil { + return m.Id + } + return 0 +} + +type MsgUpdateTakeProfitPriceResponse struct { +} + +func (m *MsgUpdateTakeProfitPriceResponse) Reset() { *m = MsgUpdateTakeProfitPriceResponse{} } +func (m *MsgUpdateTakeProfitPriceResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateTakeProfitPriceResponse) ProtoMessage() {} +func (*MsgUpdateTakeProfitPriceResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_5e879ed5011cdd71, []int{20} +} +func (m *MsgUpdateTakeProfitPriceResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateTakeProfitPriceResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateTakeProfitPriceResponse.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 *MsgUpdateTakeProfitPriceResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateTakeProfitPriceResponse.Merge(m, src) +} +func (m *MsgUpdateTakeProfitPriceResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateTakeProfitPriceResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateTakeProfitPriceResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateTakeProfitPriceResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgOpen)(nil), "elys.perpetual.MsgOpen") proto.RegisterType((*MsgBrokerOpen)(nil), "elys.perpetual.MsgBrokerOpen") @@ -1004,71 +1093,75 @@ func init() { proto.RegisterType((*MsgClosePositionsResponse)(nil), "elys.perpetual.MsgClosePositionsResponse") proto.RegisterType((*MsgUpdateStopLoss)(nil), "elys.perpetual.MsgUpdateStopLoss") proto.RegisterType((*MsgUpdateStopLossResponse)(nil), "elys.perpetual.MsgUpdateStopLossResponse") + proto.RegisterType((*MsgUpdateTakeProfitPrice)(nil), "elys.perpetual.MsgUpdateTakeProfitPrice") + proto.RegisterType((*MsgUpdateTakeProfitPriceResponse)(nil), "elys.perpetual.MsgUpdateTakeProfitPriceResponse") } func init() { proto.RegisterFile("elys/perpetual/tx.proto", fileDescriptor_5e879ed5011cdd71) } var fileDescriptor_5e879ed5011cdd71 = []byte{ - // 939 bytes of a gzipped FileDescriptorProto + // 975 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x57, 0xcf, 0x6f, 0xdc, 0x44, - 0x14, 0x8e, 0xf7, 0x47, 0x92, 0x7d, 0x9b, 0x6c, 0xa8, 0x1b, 0x25, 0x8e, 0x5b, 0x36, 0x1b, 0x83, - 0xc2, 0x72, 0xa8, 0xad, 0x2e, 0x1c, 0x41, 0x90, 0x1f, 0x42, 0x80, 0xba, 0x6a, 0x64, 0x54, 0x40, - 0x45, 0xb0, 0x72, 0xd6, 0x83, 0x63, 0xe2, 0x78, 0xdc, 0x99, 0xd9, 0xa6, 0x91, 0xb8, 0xc1, 0x1f, - 0xc0, 0x91, 0x23, 0x67, 0xae, 0xfc, 0x01, 0x5c, 0x7b, 0xec, 0x11, 0x81, 0x54, 0xa1, 0xe4, 0x1f, - 0x41, 0x1e, 0x8f, 0x67, 0xbd, 0xae, 0x9d, 0x2d, 0x0b, 0x51, 0x2e, 0x3d, 0xed, 0xda, 0xdf, 0x7b, - 0xdf, 0xfb, 0x66, 0xde, 0xbc, 0x6f, 0x64, 0x58, 0x47, 0xc1, 0x19, 0xb5, 0x22, 0x44, 0x22, 0xc4, - 0x46, 0x4e, 0x60, 0xb1, 0x27, 0x66, 0x44, 0x30, 0xc3, 0x6a, 0x2b, 0x06, 0x4c, 0x09, 0xe8, 0xab, - 0x1e, 0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0xcd, 0x15, 0x6d, 0xda, + 0x44, 0x84, 0xda, 0x9d, 0x16, 0x21, 0xc8, 0x5d, 0xb8, 0x5e, 0xe4, 0xa4, 0x5b, 0xa5, 0x7d, 0x9b, + 0xb5, 0xd0, 0x97, 0xd0, 0xce, 0xb9, 0xc8, 0x66, 0x69, 0xa3, 0xd2, 0x10, 0xf5, 0xb5, 0xa9, 0x21, + 0x59, 0xfe, 0x9c, 0xdf, 0x6e, 0x96, 0x9d, 0x2d, 0x11, 0x52, 0xc8, 0x5f, 0xec, 0x84, 0x32, 0x81, + 0x17, 0x8b, 0x2d, 0xa6, 0x5b, 0xaa, 0x31, 0x17, 0xa9, 0xbe, 0x7e, 0xd9, 0xc8, 0xb4, 0xe8, 0xce, + 0xfb, 0x8f, 0xcf, 0x34, 0xe9, 0xc9, 0x99, 0x26, 0xfd, 0x79, 0xa6, 0x49, 0x3f, 0x9c, 0x6b, 0x73, + 0x4f, 0xce, 0xb5, 0xb9, 0xdf, 0xce, 0xb5, 0xb9, 0xfb, 0x46, 0xc6, 0x97, 0x62, 0xd6, 0x5b, 0x01, + 0xa2, 0x27, 0x38, 0x3a, 0x62, 0x0f, 0xe6, 0xa3, 0xfc, 0x47, 0xe9, 0xc1, 0x3c, 0xfb, 0x2a, 0x7d, + 0xe3, 0xaf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7a, 0x09, 0x76, 0x3e, 0x2f, 0x0f, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1094,6 +1187,7 @@ type MsgClient interface { BrokerAddCollateral(ctx context.Context, in *MsgBrokerAddCollateral, opts ...grpc.CallOption) (*MsgAddCollateralResponse, error) UpdateStopLoss(ctx context.Context, in *MsgUpdateStopLoss, opts ...grpc.CallOption) (*MsgUpdateStopLossResponse, error) ClosePositions(ctx context.Context, in *MsgClosePositions, opts ...grpc.CallOption) (*MsgClosePositionsResponse, error) + UpdateTakeProfitPrice(ctx context.Context, in *MsgUpdateTakeProfitPrice, opts ...grpc.CallOption) (*MsgUpdateTakeProfitPriceResponse, error) } type msgClient struct { @@ -1203,6 +1297,15 @@ func (c *msgClient) ClosePositions(ctx context.Context, in *MsgClosePositions, o return out, nil } +func (c *msgClient) UpdateTakeProfitPrice(ctx context.Context, in *MsgUpdateTakeProfitPrice, opts ...grpc.CallOption) (*MsgUpdateTakeProfitPriceResponse, error) { + out := new(MsgUpdateTakeProfitPriceResponse) + err := c.cc.Invoke(ctx, "/elys.perpetual.Msg/UpdateTakeProfitPrice", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { Open(context.Context, *MsgOpen) (*MsgOpenResponse, error) @@ -1216,6 +1319,7 @@ type MsgServer interface { BrokerAddCollateral(context.Context, *MsgBrokerAddCollateral) (*MsgAddCollateralResponse, error) UpdateStopLoss(context.Context, *MsgUpdateStopLoss) (*MsgUpdateStopLossResponse, error) ClosePositions(context.Context, *MsgClosePositions) (*MsgClosePositionsResponse, error) + UpdateTakeProfitPrice(context.Context, *MsgUpdateTakeProfitPrice) (*MsgUpdateTakeProfitPriceResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -1255,6 +1359,9 @@ func (*UnimplementedMsgServer) UpdateStopLoss(ctx context.Context, req *MsgUpdat func (*UnimplementedMsgServer) ClosePositions(ctx context.Context, req *MsgClosePositions) (*MsgClosePositionsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ClosePositions not implemented") } +func (*UnimplementedMsgServer) UpdateTakeProfitPrice(ctx context.Context, req *MsgUpdateTakeProfitPrice) (*MsgUpdateTakeProfitPriceResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateTakeProfitPrice not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -1458,6 +1565,24 @@ func _Msg_ClosePositions_Handler(srv interface{}, ctx context.Context, dec func( return interceptor(ctx, in, info, handler) } +func _Msg_UpdateTakeProfitPrice_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateTakeProfitPrice) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateTakeProfitPrice(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/elys.perpetual.Msg/UpdateTakeProfitPrice", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateTakeProfitPrice(ctx, req.(*MsgUpdateTakeProfitPrice)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "elys.perpetual.Msg", HandlerType: (*MsgServer)(nil), @@ -1506,6 +1631,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "ClosePositions", Handler: _Msg_ClosePositions_Handler, }, + { + MethodName: "UpdateTakeProfitPrice", + Handler: _Msg_UpdateTakeProfitPrice_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "elys/perpetual/tx.proto", @@ -2303,6 +2432,74 @@ func (m *MsgUpdateStopLossResponse) MarshalToSizedBuffer(dAtA []byte) (int, erro return len(dAtA) - i, nil } +func (m *MsgUpdateTakeProfitPrice) 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 *MsgUpdateTakeProfitPrice) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateTakeProfitPrice) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.Price.Size() + i -= size + if _, err := m.Price.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if m.Id != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.Id)) + i-- + dAtA[i] = 0x10 + } + if len(m.Creator) > 0 { + i -= len(m.Creator) + copy(dAtA[i:], m.Creator) + i = encodeVarintTx(dAtA, i, uint64(len(m.Creator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateTakeProfitPriceResponse) 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 *MsgUpdateTakeProfitPriceResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateTakeProfitPriceResponse) 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 @@ -2628,6 +2825,33 @@ func (m *MsgUpdateStopLossResponse) Size() (n int) { return n } +func (m *MsgUpdateTakeProfitPrice) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Creator) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.Id != 0 { + n += 1 + sovTx(uint64(m.Id)) + } + l = m.Price.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateTakeProfitPriceResponse) 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 } @@ -4909,6 +5133,191 @@ func (m *MsgUpdateStopLossResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgUpdateTakeProfitPrice) 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: MsgUpdateTakeProfitPrice: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateTakeProfitPrice: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Creator", 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.Creator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) + } + m.Id = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Id |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Price", 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.Price.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + 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 *MsgUpdateTakeProfitPriceResponse) 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: MsgUpdateTakeProfitPriceResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateTakeProfitPriceResponse: 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 From de12d7b3864beab54312b340dd696d04d7d7bfc4 Mon Sep 17 00:00:00 2001 From: CryptoKage2306 <26vivek06@gmail.com> Date: Mon, 23 Sep 2024 19:24:54 +0530 Subject: [PATCH 2/3] update --- .../keeper/msg_server_update_take_profit_price.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/x/perpetual/keeper/msg_server_update_take_profit_price.go b/x/perpetual/keeper/msg_server_update_take_profit_price.go index 9356e28be..fe62bcf6a 100644 --- a/x/perpetual/keeper/msg_server_update_take_profit_price.go +++ b/x/perpetual/keeper/msg_server_update_take_profit_price.go @@ -8,6 +8,8 @@ import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/elys-network/elys/x/perpetual/types" + assetprofiletypes "github.com/elys-network/elys/x/assetprofile/types" + ptypes "github.com/elys-network/elys/x/parameter/types" ) func (k msgServer) UpdateTakeProfitPrice(goCtx context.Context, msg *types.MsgUpdateTakeProfitPrice) (*types.MsgUpdateTakeProfitPriceResponse, error) { @@ -30,7 +32,19 @@ func (k msgServer) UpdateTakeProfitPrice(goCtx context.Context, msg *types.MsgUp return nil, errorsmod.Wrap(types.ErrPerpetualDisabled, fmt.Sprintf("poolId: %d", poolId)) } + entry, found := k.assetProfileKeeper.GetEntry(ctx, ptypes.BaseCurrency) + if !found { + return nil, errorsmod.Wrapf(assetprofiletypes.ErrAssetProfileNotFound, "asset %s not found", ptypes.BaseCurrency) + } + baseCurrency := entry.Denom + mtp.TakeProfitPrice = msg.Price + mtp.TakeProfitCustody = types.CalcMTPTakeProfitCustody(&mtp) + mtp.TakeProfitLiabilities, err = k.CalcMTPTakeProfitLiability(ctx, &mtp, baseCurrency) + if err != nil { + return nil, err + } + k.SetMTP(ctx, &mtp) event := sdk.NewEvent(types.EventOpen, From 02306e8a4f9f695d7080908067cdf71fc031ac40 Mon Sep 17 00:00:00 2001 From: CryptoKage2306 <26vivek06@gmail.com> Date: Mon, 23 Sep 2024 22:54:41 +0530 Subject: [PATCH 3/3] update --- .../keeper/msg_server_update_take_profit_price.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/x/perpetual/keeper/msg_server_update_take_profit_price.go b/x/perpetual/keeper/msg_server_update_take_profit_price.go index fe62bcf6a..29a5642ca 100644 --- a/x/perpetual/keeper/msg_server_update_take_profit_price.go +++ b/x/perpetual/keeper/msg_server_update_take_profit_price.go @@ -45,6 +45,18 @@ func (k msgServer) UpdateTakeProfitPrice(goCtx context.Context, msg *types.MsgUp return nil, err } + // All take profit liability has to be in liabilities asset + err = pool.UpdateTakeProfitLiabilities(ctx, mtp.LiabilitiesAsset, mtp.TakeProfitLiabilities, true, mtp.Position) + if err != nil { + return nil, err + } + + // All take profit custody has to be in custody asset + err = pool.UpdateTakeProfitCustody(ctx, mtp.CustodyAsset, mtp.TakeProfitCustody, true, mtp.Position) + if err != nil { + return nil, err + } + k.SetMTP(ctx, &mtp) event := sdk.NewEvent(types.EventOpen,