From 29136ba0cfcedbd4930a789c87f35ecd294d1770 Mon Sep 17 00:00:00 2001 From: unknown unknown Date: Thu, 20 Jul 2023 12:59:19 +0200 Subject: [PATCH 01/20] add place bet proto --- proto/sge/subaccount/tx.proto | 17 +- x/subaccount/keeper/bet.go | 11 + x/subaccount/types/tx.pb.go | 458 ++++++++++++++++++++++++++++++++-- 3 files changed, 459 insertions(+), 27 deletions(-) create mode 100644 x/subaccount/keeper/bet.go diff --git a/proto/sge/subaccount/tx.proto b/proto/sge/subaccount/tx.proto index af00e8d8..0de83b8c 100644 --- a/proto/sge/subaccount/tx.proto +++ b/proto/sge/subaccount/tx.proto @@ -2,6 +2,7 @@ syntax = "proto3"; package sgenetwork.sge.subaccount; import "sge/subaccount/subaccount.proto"; +import "sge/bet/tx.proto"; option go_package = "github.com/sge-network/sge/x/subaccount/types"; @@ -13,7 +14,11 @@ service Msg { // TopUp defines a method for topping up a subaccount. rpc TopUp(MsgTopUp) returns (MsgTopUpResponse); + // WithdrawUnlockedBalances defines a method for withdrawing unlocked balances. rpc WithdrawUnlockedBalances(MsgWithdrawUnlockedBalances) returns (MsgWithdrawUnlockedBalancesResponse); + + // PlaceBet defines a method for placing a bet using a subaccount. + rpc PlaceBet(MsgPlaceBet) returns (MsgPlaceBetResponse); } // MsgCreateSubAccount defines the Msg/CreateSubAccount request type. @@ -53,4 +58,14 @@ message MsgWithdrawUnlockedBalances { } // MsgWithdrawUnlockedBalancesResponse defines the Msg/WithdrawUnlockedBalances response type. -message MsgWithdrawUnlockedBalancesResponse {} \ No newline at end of file +message MsgWithdrawUnlockedBalancesResponse {} + +// MsgPlaceBet wraps the MsgPlaceBet message. We need it in order not to have double interface registration conflicts. +message MsgPlaceBet { + sgenetwork.sge.bet.MsgPlaceBet msg = 1; +} + +// MsgBetResponse wraps the MsgPlaceBetResponse message. We need it in order not to have double interface registration conflicts. +message MsgPlaceBetResponse { + sgenetwork.sge.bet.MsgPlaceBetResponse response = 1; +} \ No newline at end of file diff --git a/x/subaccount/keeper/bet.go b/x/subaccount/keeper/bet.go new file mode 100644 index 00000000..ecb705e7 --- /dev/null +++ b/x/subaccount/keeper/bet.go @@ -0,0 +1,11 @@ +package keeper + +import ( + "context" + + "github.com/sge-network/sge/x/subaccount/types" +) + +func (m msgServer) PlaceBet(ctx context.Context, msg *types.MsgPlaceBet) (*types.MsgPlaceBetResponse, error) { + panic("implement me") +} diff --git a/x/subaccount/types/tx.pb.go b/x/subaccount/types/tx.pb.go index 4f5ee7a7..7c8d7016 100644 --- a/x/subaccount/types/tx.pb.go +++ b/x/subaccount/types/tx.pb.go @@ -8,6 +8,7 @@ import ( fmt "fmt" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" + types "github.com/sge-network/sge/x/bet/types" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" @@ -312,6 +313,96 @@ func (m *MsgWithdrawUnlockedBalancesResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgWithdrawUnlockedBalancesResponse proto.InternalMessageInfo +// MsgPlaceBet wraps the MsgPlaceBet message. We need it in order not to have double interface registration conflicts. +type MsgPlaceBet struct { + Msg *types.MsgPlaceBet `protobuf:"bytes,1,opt,name=msg,proto3" json:"msg,omitempty"` +} + +func (m *MsgPlaceBet) Reset() { *m = MsgPlaceBet{} } +func (m *MsgPlaceBet) String() string { return proto.CompactTextString(m) } +func (*MsgPlaceBet) ProtoMessage() {} +func (*MsgPlaceBet) Descriptor() ([]byte, []int) { + return fileDescriptor_e042e836d366badb, []int{6} +} +func (m *MsgPlaceBet) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgPlaceBet) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgPlaceBet.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 *MsgPlaceBet) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgPlaceBet.Merge(m, src) +} +func (m *MsgPlaceBet) XXX_Size() int { + return m.Size() +} +func (m *MsgPlaceBet) XXX_DiscardUnknown() { + xxx_messageInfo_MsgPlaceBet.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgPlaceBet proto.InternalMessageInfo + +func (m *MsgPlaceBet) GetMsg() *types.MsgPlaceBet { + if m != nil { + return m.Msg + } + return nil +} + +// MsgBetResponse wraps the MsgPlaceBetResponse message. We need it in order not to have double interface registration conflicts. +type MsgPlaceBetResponse struct { + Response *types.MsgPlaceBetResponse `protobuf:"bytes,1,opt,name=response,proto3" json:"response,omitempty"` +} + +func (m *MsgPlaceBetResponse) Reset() { *m = MsgPlaceBetResponse{} } +func (m *MsgPlaceBetResponse) String() string { return proto.CompactTextString(m) } +func (*MsgPlaceBetResponse) ProtoMessage() {} +func (*MsgPlaceBetResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_e042e836d366badb, []int{7} +} +func (m *MsgPlaceBetResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgPlaceBetResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgPlaceBetResponse.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 *MsgPlaceBetResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgPlaceBetResponse.Merge(m, src) +} +func (m *MsgPlaceBetResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgPlaceBetResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgPlaceBetResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgPlaceBetResponse proto.InternalMessageInfo + +func (m *MsgPlaceBetResponse) GetResponse() *types.MsgPlaceBetResponse { + if m != nil { + return m.Response + } + return nil +} + func init() { proto.RegisterType((*MsgCreateSubAccount)(nil), "sgenetwork.sge.subaccount.MsgCreateSubAccount") proto.RegisterType((*MsgCreateSubAccountResponse)(nil), "sgenetwork.sge.subaccount.MsgCreateSubAccountResponse") @@ -319,37 +410,44 @@ func init() { proto.RegisterType((*MsgTopUpResponse)(nil), "sgenetwork.sge.subaccount.MsgTopUpResponse") proto.RegisterType((*MsgWithdrawUnlockedBalances)(nil), "sgenetwork.sge.subaccount.MsgWithdrawUnlockedBalances") proto.RegisterType((*MsgWithdrawUnlockedBalancesResponse)(nil), "sgenetwork.sge.subaccount.MsgWithdrawUnlockedBalancesResponse") + proto.RegisterType((*MsgPlaceBet)(nil), "sgenetwork.sge.subaccount.MsgPlaceBet") + proto.RegisterType((*MsgPlaceBetResponse)(nil), "sgenetwork.sge.subaccount.MsgPlaceBetResponse") } func init() { proto.RegisterFile("sge/subaccount/tx.proto", fileDescriptor_e042e836d366badb) } var fileDescriptor_e042e836d366badb = []byte{ - // 389 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2f, 0x4e, 0x4f, 0xd5, - 0x2f, 0x2e, 0x4d, 0x4a, 0x4c, 0x4e, 0xce, 0x2f, 0xcd, 0x2b, 0xd1, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, - 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x2c, 0x4e, 0x4f, 0xcd, 0x4b, 0x2d, 0x29, 0xcf, 0x2f, 0xca, 0xd6, - 0x2b, 0x4e, 0x4f, 0xd5, 0x43, 0xa8, 0x91, 0x92, 0x47, 0xd3, 0x83, 0x60, 0x42, 0xf4, 0x2a, 0xad, - 0x61, 0xe4, 0x12, 0xf6, 0x2d, 0x4e, 0x77, 0x2e, 0x4a, 0x4d, 0x2c, 0x49, 0x0d, 0x2e, 0x4d, 0x72, - 0x84, 0xc8, 0x0a, 0x89, 0x71, 0xb1, 0x15, 0xa7, 0xe6, 0xa5, 0xa4, 0x16, 0x49, 0x30, 0x2a, 0x30, - 0x6a, 0x70, 0x06, 0x41, 0x79, 0x42, 0x5a, 0x5c, 0x82, 0xc5, 0xa5, 0x49, 0xf1, 0x50, 0x43, 0xe2, - 0xf3, 0xcb, 0xf3, 0x52, 0x8b, 0x24, 0x98, 0xc0, 0x4a, 0xf8, 0x8b, 0xe1, 0xda, 0xfd, 0x41, 0xc2, - 0x42, 0x81, 0x5c, 0xfc, 0x39, 0xf9, 0xc9, 0xd9, 0xa9, 0x29, 0xf1, 0x49, 0x89, 0x39, 0x89, 0x79, - 0xc9, 0xa9, 0xc5, 0x12, 0xcc, 0x0a, 0xcc, 0x1a, 0xdc, 0x46, 0x1a, 0x7a, 0x38, 0x5d, 0xac, 0xe7, - 0x03, 0xd6, 0xe1, 0x04, 0xd1, 0x10, 0xc4, 0x97, 0x83, 0xcc, 0x2d, 0x56, 0x92, 0xe5, 0x92, 0xc6, - 0xe2, 0xda, 0xa0, 0xd4, 0xe2, 0x82, 0xfc, 0xbc, 0xe2, 0x54, 0xa5, 0x69, 0x8c, 0x5c, 0x1c, 0xbe, - 0xc5, 0xe9, 0x21, 0xf9, 0x05, 0xa1, 0x05, 0x38, 0xbd, 0x20, 0xcf, 0xc5, 0x8d, 0xe4, 0x05, 0xa8, - 0xe3, 0xb9, 0x10, 0x8e, 0xa7, 0x85, 0xbb, 0x85, 0xb8, 0x04, 0x60, 0xee, 0x82, 0x3b, 0xd6, 0x14, - 0xec, 0x97, 0xf0, 0xcc, 0x92, 0x8c, 0x94, 0xa2, 0xc4, 0xf2, 0xd0, 0x3c, 0x54, 0x2d, 0xb8, 0x9c, - 0xaf, 0xa4, 0xca, 0xa5, 0x8c, 0x47, 0x1b, 0xcc, 0x74, 0xa3, 0x8f, 0x4c, 0x5c, 0xcc, 0xbe, 0xc5, - 0xe9, 0x42, 0x55, 0x5c, 0x02, 0x18, 0x91, 0xab, 0x87, 0xc7, 0x1f, 0x58, 0x82, 0x57, 0xca, 0x8c, - 0x34, 0xf5, 0x30, 0x37, 0x08, 0x45, 0x72, 0xb1, 0x42, 0xa2, 0x42, 0x19, 0xbf, 0x01, 0x60, 0x45, - 0x52, 0xda, 0x44, 0x28, 0x82, 0x1b, 0x3d, 0x89, 0x91, 0x4b, 0x02, 0x67, 0xd0, 0x11, 0x70, 0x2f, - 0x2e, 0x7d, 0x52, 0x76, 0xe4, 0xe9, 0x83, 0x39, 0xca, 0xc9, 0xfd, 0xc4, 0x23, 0x39, 0xc6, 0x0b, - 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, - 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0x74, 0xd3, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, - 0xf5, 0x8b, 0xd3, 0x53, 0x75, 0xa1, 0x96, 0x80, 0xd8, 0xfa, 0x15, 0x28, 0x99, 0xba, 0xb2, 0x20, - 0xb5, 0x38, 0x89, 0x0d, 0x9c, 0x39, 0x8d, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xd0, 0xc5, 0x07, - 0xfe, 0xf3, 0x03, 0x00, 0x00, + // 470 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x94, 0x41, 0x6b, 0x13, 0x41, + 0x18, 0x86, 0xb3, 0x2e, 0x96, 0xf8, 0x05, 0x6c, 0x5c, 0x41, 0xe3, 0x8a, 0x9b, 0xb2, 0x45, 0x0d, + 0x4a, 0x27, 0x18, 0xd1, 0xa3, 0x68, 0x7a, 0xf0, 0x62, 0x50, 0x57, 0x8b, 0xd8, 0x4b, 0xd8, 0xd9, + 0x7c, 0x4c, 0x4b, 0xd3, 0x9d, 0x65, 0xbf, 0x59, 0x52, 0xfd, 0x15, 0xe2, 0xc1, 0x5f, 0xe1, 0x0f, + 0xf1, 0xd8, 0x8b, 0xe0, 0x51, 0x92, 0x3f, 0x22, 0xd9, 0x4c, 0x26, 0x69, 0xed, 0x6e, 0xa3, 0xd0, + 0xdb, 0xcc, 0xf0, 0xbc, 0xef, 0xbe, 0xef, 0xce, 0xc7, 0xc0, 0x4d, 0x12, 0xd8, 0xa6, 0x8c, 0x87, + 0x51, 0x24, 0xb3, 0x58, 0xb5, 0xd5, 0x11, 0x4b, 0x52, 0xa9, 0xa4, 0x73, 0x8b, 0x04, 0xc6, 0xa8, + 0x46, 0x32, 0x3d, 0x60, 0x24, 0x90, 0x2d, 0x18, 0xb7, 0x79, 0x4a, 0xb3, 0x58, 0xce, 0xb4, 0x6e, + 0x7d, 0x0a, 0x70, 0x5c, 0xb8, 0xf9, 0xdf, 0x2d, 0xb8, 0xde, 0x23, 0xb1, 0x9d, 0x62, 0xa8, 0xf0, + 0x5d, 0xc6, 0x5f, 0xcc, 0x78, 0xe7, 0x06, 0xac, 0x11, 0xc6, 0x03, 0x4c, 0x1b, 0xd6, 0x86, 0xd5, + 0xba, 0x12, 0xe8, 0x9d, 0xf3, 0x00, 0xae, 0x51, 0xc6, 0xfb, 0xda, 0xb6, 0x2f, 0x47, 0x31, 0xa6, + 0x8d, 0x4b, 0x39, 0xb2, 0x4e, 0x46, 0xfe, 0x7a, 0x7a, 0xec, 0xbc, 0x85, 0xf5, 0xa1, 0x8c, 0x0e, + 0x70, 0xd0, 0xe7, 0xe1, 0x30, 0x8c, 0x23, 0xa4, 0x86, 0xbd, 0x61, 0xb7, 0x6a, 0x9d, 0x16, 0x2b, + 0xec, 0xc0, 0x5e, 0xe5, 0x8a, 0xee, 0x4c, 0x10, 0x5c, 0x1d, 0x2e, 0x6f, 0xc9, 0xbf, 0x03, 0xb7, + 0xcf, 0x48, 0x1b, 0x20, 0x25, 0x32, 0x26, 0xf4, 0xbf, 0x59, 0x50, 0xed, 0x91, 0x78, 0x2f, 0x93, + 0x9d, 0xa4, 0xb0, 0x42, 0x13, 0x6a, 0x4b, 0x15, 0x74, 0x78, 0x58, 0x84, 0xbf, 0x88, 0xdc, 0x0e, + 0xd4, 0xe7, 0xb9, 0x4c, 0xd8, 0x27, 0x79, 0x97, 0x0f, 0xfb, 0x6a, 0x6f, 0x90, 0x86, 0xa3, 0x9d, + 0xf8, 0xa4, 0xa4, 0x28, 0xbe, 0x7f, 0x17, 0x36, 0x4b, 0x64, 0xc6, 0xfd, 0x39, 0xd4, 0x7a, 0x24, + 0xde, 0x0c, 0xc3, 0x08, 0xbb, 0xa8, 0x9c, 0x47, 0x60, 0x1f, 0x92, 0xc8, 0xad, 0x6a, 0x9d, 0xe6, + 0xe9, 0x1e, 0x1c, 0x15, 0x5b, 0xa2, 0x83, 0x29, 0xeb, 0xef, 0xe6, 0x93, 0x61, 0xce, 0xb4, 0xb1, + 0xb3, 0x0d, 0xd5, 0x54, 0xaf, 0xb5, 0xdd, 0xfd, 0xf3, 0xec, 0x34, 0x1e, 0x18, 0x61, 0xe7, 0xa7, + 0x0d, 0x76, 0x8f, 0x84, 0xf3, 0x19, 0xea, 0x7f, 0x8d, 0x1e, 0x2b, 0xf9, 0xcb, 0x67, 0x5c, 0xbe, + 0xfb, 0xf4, 0xdf, 0x78, 0x53, 0xe4, 0x23, 0x5c, 0x9e, 0x0d, 0xca, 0x66, 0xb9, 0x41, 0x0e, 0xb9, + 0x0f, 0x57, 0x80, 0x8c, 0xf5, 0x57, 0x0b, 0x1a, 0x85, 0x17, 0x7b, 0x4e, 0xde, 0x22, 0x9d, 0xfb, + 0xec, 0xff, 0x74, 0x26, 0x14, 0x87, 0xaa, 0x19, 0x87, 0x7b, 0xe5, 0x5e, 0x73, 0xce, 0x65, 0xab, + 0x71, 0xf3, 0x6f, 0x74, 0x5f, 0xfe, 0x18, 0x7b, 0xd6, 0xf1, 0xd8, 0xb3, 0x7e, 0x8f, 0x3d, 0xeb, + 0xcb, 0xc4, 0xab, 0x1c, 0x4f, 0xbc, 0xca, 0xaf, 0x89, 0x57, 0xd9, 0xdd, 0x12, 0xfb, 0x6a, 0x2f, + 0xe3, 0x2c, 0x92, 0x87, 0x6d, 0x12, 0xb8, 0xa5, 0x4d, 0xa7, 0xeb, 0xf6, 0xd1, 0x89, 0x87, 0xee, + 0x53, 0x82, 0xc4, 0xd7, 0xf2, 0xe7, 0xe9, 0xf1, 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x2c, 0x38, + 0x80, 0x3e, 0x07, 0x05, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -368,7 +466,10 @@ type MsgClient interface { CreateSubAccount(ctx context.Context, in *MsgCreateSubAccount, opts ...grpc.CallOption) (*MsgCreateSubAccountResponse, error) // TopUp defines a method for topping up a subaccount. TopUp(ctx context.Context, in *MsgTopUp, opts ...grpc.CallOption) (*MsgTopUpResponse, error) + // WithdrawUnlockedBalances defines a method for withdrawing unlocked balances. WithdrawUnlockedBalances(ctx context.Context, in *MsgWithdrawUnlockedBalances, opts ...grpc.CallOption) (*MsgWithdrawUnlockedBalancesResponse, error) + // PlaceBet defines a method for placing a bet using a subaccount. + PlaceBet(ctx context.Context, in *MsgPlaceBet, opts ...grpc.CallOption) (*MsgPlaceBetResponse, error) } type msgClient struct { @@ -406,13 +507,25 @@ func (c *msgClient) WithdrawUnlockedBalances(ctx context.Context, in *MsgWithdra return out, nil } +func (c *msgClient) PlaceBet(ctx context.Context, in *MsgPlaceBet, opts ...grpc.CallOption) (*MsgPlaceBetResponse, error) { + out := new(MsgPlaceBetResponse) + err := c.cc.Invoke(ctx, "/sgenetwork.sge.subaccount.Msg/PlaceBet", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { // CreateSubAccount defines a method for creating a subaccount. CreateSubAccount(context.Context, *MsgCreateSubAccount) (*MsgCreateSubAccountResponse, error) // TopUp defines a method for topping up a subaccount. TopUp(context.Context, *MsgTopUp) (*MsgTopUpResponse, error) + // WithdrawUnlockedBalances defines a method for withdrawing unlocked balances. WithdrawUnlockedBalances(context.Context, *MsgWithdrawUnlockedBalances) (*MsgWithdrawUnlockedBalancesResponse, error) + // PlaceBet defines a method for placing a bet using a subaccount. + PlaceBet(context.Context, *MsgPlaceBet) (*MsgPlaceBetResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -428,6 +541,9 @@ func (*UnimplementedMsgServer) TopUp(ctx context.Context, req *MsgTopUp) (*MsgTo func (*UnimplementedMsgServer) WithdrawUnlockedBalances(ctx context.Context, req *MsgWithdrawUnlockedBalances) (*MsgWithdrawUnlockedBalancesResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method WithdrawUnlockedBalances not implemented") } +func (*UnimplementedMsgServer) PlaceBet(ctx context.Context, req *MsgPlaceBet) (*MsgPlaceBetResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method PlaceBet not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -487,6 +603,24 @@ func _Msg_WithdrawUnlockedBalances_Handler(srv interface{}, ctx context.Context, return interceptor(ctx, in, info, handler) } +func _Msg_PlaceBet_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgPlaceBet) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).PlaceBet(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sgenetwork.sge.subaccount.Msg/PlaceBet", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).PlaceBet(ctx, req.(*MsgPlaceBet)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "sgenetwork.sge.subaccount.Msg", HandlerType: (*MsgServer)(nil), @@ -503,6 +637,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "WithdrawUnlockedBalances", Handler: _Msg_WithdrawUnlockedBalances_Handler, }, + { + MethodName: "PlaceBet", + Handler: _Msg_PlaceBet_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "sge/subaccount/tx.proto", @@ -709,6 +847,76 @@ func (m *MsgWithdrawUnlockedBalancesResponse) MarshalToSizedBuffer(dAtA []byte) return len(dAtA) - i, nil } +func (m *MsgPlaceBet) 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 *MsgPlaceBet) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgPlaceBet) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Msg != nil { + { + size, err := m.Msg.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgPlaceBetResponse) 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 *MsgPlaceBetResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgPlaceBetResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Response != nil { + { + size, err := m.Response.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -806,6 +1014,32 @@ func (m *MsgWithdrawUnlockedBalancesResponse) Size() (n int) { return n } +func (m *MsgPlaceBet) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Msg != nil { + l = m.Msg.Size() + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgPlaceBetResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Response != nil { + l = m.Response.Size() + n += 1 + l + sovTx(uint64(l)) + } + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -1340,6 +1574,178 @@ func (m *MsgWithdrawUnlockedBalancesResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgPlaceBet) 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: MsgPlaceBet: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgPlaceBet: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Msg", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Msg == nil { + m.Msg = &types.MsgPlaceBet{} + } + if err := m.Msg.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 *MsgPlaceBetResponse) 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: MsgPlaceBetResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgPlaceBetResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Response", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Response == nil { + m.Response = &types.MsgPlaceBetResponse{} + } + if err := m.Response.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 skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 From b864a438bee10273782b8e18bb61e210b3583e9c Mon Sep 17 00:00:00 2001 From: unknown unknown Date: Fri, 21 Jul 2023 16:24:52 +0200 Subject: [PATCH 02/20] refactor use acc addr everywhere --- x/orderbook/keeper/bet_settle.go | 11 ++++ x/orderbook/keeper/hooks.go | 13 +++++ x/orderbook/keeper/keeper.go | 1 + x/subaccount/keeper/create_subaccount.go | 14 ++--- x/subaccount/keeper/create_subaccount_test.go | 10 ++-- x/subaccount/keeper/keeper.go | 2 + x/subaccount/keeper/msg_server.go | 5 +- x/subaccount/keeper/orderbook_hooks.go | 57 +++++++++++++++++++ x/subaccount/keeper/subaccount.go | 52 ++++++++--------- x/subaccount/keeper/subaccount_test.go | 40 ++++++++----- x/subaccount/keeper/topup.go | 17 +++--- x/subaccount/keeper/topup_test.go | 12 ++-- x/subaccount/keeper/withdraw.go | 20 ++++--- x/subaccount/keeper/withdraw_test.go | 14 +++-- x/subaccount/types/keys.go | 19 ++++--- x/subaccount/types/subaccount.go | 8 +++ 16 files changed, 205 insertions(+), 90 deletions(-) create mode 100644 x/orderbook/keeper/hooks.go create mode 100644 x/subaccount/keeper/orderbook_hooks.go diff --git a/x/orderbook/keeper/bet_settle.go b/x/orderbook/keeper/bet_settle.go index f8757963..0284cabd 100644 --- a/x/orderbook/keeper/bet_settle.go +++ b/x/orderbook/keeper/bet_settle.go @@ -26,6 +26,9 @@ func (k Keeper) RefundBettor( return err } + for _, hook := range k.hooks { + hook.AfterBettorRefund(ctx, bettorAddress, betAmount, betFee) + } return nil } @@ -70,6 +73,10 @@ func (k Keeper) BettorWins( k.SetOrderBookParticipation(ctx, orderBookParticipation) } + for _, h := range k.hooks { + h.AfterBettorWin(ctx, bettorAddress, betAmount, payoutProfit) + } + return nil } @@ -108,5 +115,9 @@ func (k Keeper) BettorLoses(ctx sdk.Context, address sdk.AccAddress, k.SetOrderBookParticipation(ctx, orderBookParticipation) } + for _, h := range k.hooks { + h.AfterBettorLoss(ctx, address, betAmount) + } + return nil } diff --git a/x/orderbook/keeper/hooks.go b/x/orderbook/keeper/hooks.go new file mode 100644 index 00000000..a844370b --- /dev/null +++ b/x/orderbook/keeper/hooks.go @@ -0,0 +1,13 @@ +package keeper + +import sdk "github.com/cosmos/cosmos-sdk/types" + +type Hook interface { + AfterBettorWin(ctx sdk.Context, bettor sdk.AccAddress, originalAmount, profit sdk.Int) + AfterBettorLoss(ctx sdk.Context, bettor sdk.AccAddress, originalAmount sdk.Int) + AfterBettorRefund(ctx sdk.Context, bettor sdk.AccAddress, originalAmount, fee sdk.Int) +} + +func (k *Keeper) RegisterHook(hook Hook) { + k.hooks = append(k.hooks, hook) +} diff --git a/x/orderbook/keeper/keeper.go b/x/orderbook/keeper/keeper.go index 057d0533..ca4f0acc 100644 --- a/x/orderbook/keeper/keeper.go +++ b/x/orderbook/keeper/keeper.go @@ -23,6 +23,7 @@ type Keeper struct { houseKeeper types.HouseKeeper ovmKeeper types.OVMKeeper feeGrantKeeper types.FeeGrantKeeper + hooks []Hook } // SdkExpectedKeepers contains expected keepers parameter needed by NewKeeper diff --git a/x/subaccount/keeper/create_subaccount.go b/x/subaccount/keeper/create_subaccount.go index d70d619b..fa48489b 100644 --- a/x/subaccount/keeper/create_subaccount.go +++ b/x/subaccount/keeper/create_subaccount.go @@ -25,7 +25,7 @@ func (m msgServer) CreateSubAccount( senderAccount := sdk.MustAccAddressFromBech32(request.Sender) subaccountOwner := sdk.MustAccAddressFromBech32(request.SubAccountOwner) - if m.keeper.HasSubAccount(sdkContext, subaccountOwner) { + if _, exists := m.keeper.GetSubAccountOwner(sdkContext, subaccountOwner); exists { return nil, types.ErrSubaccountAlreadyExist } @@ -33,17 +33,17 @@ func (m msgServer) CreateSubAccount( // ALERT: If someone frontruns the account creation, will be overwritten here subaccountAddress := types.NewAddressFromSubaccount(subaccountID) - address := m.accountKeeper.NewAccountWithAddress(sdkContext, subaccountAddress) - m.accountKeeper.SetAccount(sdkContext, address) + subaccountAccount := m.accountKeeper.NewAccountWithAddress(sdkContext, subaccountAddress) + m.accountKeeper.SetAccount(sdkContext, subaccountAccount) - err = m.sendCoinsToSubaccount(sdkContext, senderAccount, subaccountID, moneyToSend) + err = m.sendCoinsToSubaccount(sdkContext, senderAccount, subaccountAddress, moneyToSend) if err != nil { return nil, errors.Wrap(err, "unable to send coins") } - m.keeper.SetSubAccountOwner(sdkContext, subaccountID, subaccountOwner) - m.keeper.SetLockedBalances(sdkContext, subaccountID, request.LockedBalances) - m.keeper.SetBalance(sdkContext, subaccountID, types.Balance{ + m.keeper.SetSubAccountOwner(sdkContext, subaccountAddress, subaccountOwner) + m.keeper.SetLockedBalances(sdkContext, subaccountAddress, request.LockedBalances) + m.keeper.SetBalance(sdkContext, subaccountAddress, types.Balance{ DepositedAmount: moneyToSend, SpentAmount: sdk.ZeroInt(), WithdrawmAmount: sdk.ZeroInt(), diff --git a/x/subaccount/keeper/create_subaccount_test.go b/x/subaccount/keeper/create_subaccount_test.go index a3837c99..555ec1d8 100644 --- a/x/subaccount/keeper/create_subaccount_test.go +++ b/x/subaccount/keeper/create_subaccount_test.go @@ -48,17 +48,19 @@ func TestMsgServer_CreateSubAccount(t *testing.T) { require.Equal(t, sdk.NewInt(123), balance.Amount) // Check that we can get the account by owner - owner := app.SubaccountKeeper.GetSubAccountOwner(ctx, 1) + owner, exists := app.SubaccountKeeper.GetSubAccountOwner(ctx, types.NewAddressFromSubaccount(1)) + require.True(t, exists) require.Equal(t, account, owner) // check that balance unlocks are set correctly - lockedBalances := app.SubaccountKeeper.GetLockedBalances(ctx, 1) + lockedBalances := app.SubaccountKeeper.GetLockedBalances(ctx, types.NewAddressFromSubaccount(1)) require.Len(t, lockedBalances, 1) require.True(t, someTime.Equal(lockedBalances[0].UnlockTime)) require.Equal(t, sdk.NewInt(123), lockedBalances[0].Amount) // get the balance of the account - subaccountBalance := app.SubaccountKeeper.GetBalance(ctx, 1) + subaccountBalance, exists := app.SubaccountKeeper.GetBalance(ctx, types.NewAddressFromSubaccount(1)) + require.True(t, exists) require.Equal(t, sdk.ZeroInt(), subaccountBalance.SpentAmount) require.Equal(t, sdk.ZeroInt(), subaccountBalance.LostAmount) require.Equal(t, sdk.ZeroInt(), subaccountBalance.WithdrawmAmount) @@ -105,7 +107,7 @@ func TestMsgServer_CreateSubAccount_Errors(t *testing.T) { }, }, prepare: func(ctx sdk.Context, k keeper.Keeper) { - k.SetSubAccountOwner(ctx, 1, account) + k.SetSubAccountOwner(ctx, types.NewAddressFromSubaccount(1), account) }, expectedErr: types.ErrSubaccountAlreadyExist.Error(), }, diff --git a/x/subaccount/keeper/keeper.go b/x/subaccount/keeper/keeper.go index 90d06b35..a86dceca 100644 --- a/x/subaccount/keeper/keeper.go +++ b/x/subaccount/keeper/keeper.go @@ -3,6 +3,7 @@ package keeper import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/sge-network/sge/x/subaccount/types" ) @@ -11,6 +12,7 @@ type Keeper struct { cdc codec.Codec storeKey sdk.StoreKey paramstore paramtypes.Subspace + bankKeeper bankkeeper.Keeper } func NewKeeper(cdc codec.Codec, storeKey sdk.StoreKey, ps paramtypes.Subspace) Keeper { diff --git a/x/subaccount/keeper/msg_server.go b/x/subaccount/keeper/msg_server.go index 8ed08584..1102f7f1 100644 --- a/x/subaccount/keeper/msg_server.go +++ b/x/subaccount/keeper/msg_server.go @@ -44,11 +44,10 @@ func sumBalanceUnlocks(ctx sdk.Context, balanceUnlocks []*types.LockedBalance) ( } // sendCoinsToSubaccount sends the coins to the subaccount. -func (m msgServer) sendCoinsToSubaccount(ctx sdk.Context, senderAccount sdk.AccAddress, subaccountID uint64, moneyToSend sdk.Int) error { - subaccountAddress := types.NewAddressFromSubaccount(subaccountID) +func (m msgServer) sendCoinsToSubaccount(ctx sdk.Context, senderAccount sdk.AccAddress, subAccountAddress sdk.AccAddress, moneyToSend sdk.Int) error { denom := m.keeper.GetParams(ctx).LockedBalanceDenom - err := m.bankKeeper.SendCoins(ctx, senderAccount, subaccountAddress, sdk.NewCoins(sdk.NewCoin(denom, moneyToSend))) + err := m.bankKeeper.SendCoins(ctx, senderAccount, subAccountAddress, sdk.NewCoins(sdk.NewCoin(denom, moneyToSend))) if err != nil { return errors.Wrap(err, "unable to send coins") } diff --git a/x/subaccount/keeper/orderbook_hooks.go b/x/subaccount/keeper/orderbook_hooks.go new file mode 100644 index 00000000..7ded6a1e --- /dev/null +++ b/x/subaccount/keeper/orderbook_hooks.go @@ -0,0 +1,57 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + orderbookmodulekeeper "github.com/sge-network/sge/x/orderbook/keeper" +) + +var _ orderbookmodulekeeper.Hook = Keeper{} + +func (k Keeper) AfterBettorWin(ctx sdk.Context, bettor sdk.AccAddress, originalAmount sdk.Int, profit sdk.Int) { + balance, exists := k.GetBalance(ctx, bettor) + if !exists { + return + } + err := balance.Unspend(originalAmount) + if err != nil { + panic(err) + } + // send profits to subaccount owner + owner, exists := k.GetSubAccountOwner(ctx, bettor) + if !exists { + panic("subaccount owner not found") + } + err = k.bankKeeper.SendCoins(ctx, owner, bettor, sdk.NewCoins(sdk.NewCoin(k.GetParams(ctx).LockedBalanceDenom, originalAmount))) + if err != nil { + panic(err) + } + k.SetBalance(ctx, bettor, balance) +} + +func (k Keeper) AfterBettorLoss(ctx sdk.Context, bettor sdk.AccAddress, originalAmount sdk.Int) { + balance, exists := k.GetBalance(ctx, bettor) + if !exists { + return + } + err := balance.Unspend(originalAmount) + if err != nil { + panic(err) + } + err = balance.AddLoss(originalAmount) + if err != nil { + panic(err) + } + k.SetBalance(ctx, bettor, balance) +} + +func (k Keeper) AfterBettorRefund(ctx sdk.Context, bettor sdk.AccAddress, originalAmount, fee sdk.Int) { + balance, exists := k.GetBalance(ctx, bettor) + if !exists { + return + } + err := balance.Unspend(originalAmount.Add(fee)) + if err != nil { + panic(err) + } + k.SetBalance(ctx, bettor, balance) +} diff --git a/x/subaccount/keeper/subaccount.go b/x/subaccount/keeper/subaccount.go index 26ba1a15..a3b44d04 100644 --- a/x/subaccount/keeper/subaccount.go +++ b/x/subaccount/keeper/subaccount.go @@ -30,35 +30,30 @@ func (k Keeper) SetID(ctx sdk.Context, id uint64) { ctx.KVStore(k.storeKey).Set(subaccounttypes.SubaccountIDPrefix, sdk.Uint64ToBigEndian(id)) } -// HasSubAccount returns true if the account has a subaccount. -func (k Keeper) HasSubAccount(ctx sdk.Context, address sdk.AccAddress) bool { - store := ctx.KVStore(k.storeKey) - return store.Has(subaccounttypes.SubAccountOwnerKey(address)) -} - // SetSubAccountOwner sets the owner of a subaccount. -func (k Keeper) SetSubAccountOwner(ctx sdk.Context, id uint64, address sdk.AccAddress) { +func (k Keeper) SetSubAccountOwner(ctx sdk.Context, subAccountAddress, ownerAddress sdk.AccAddress) { store := ctx.KVStore(k.storeKey) - store.Set(subaccounttypes.SubAccountOwnerKey(address), sdk.Uint64ToBigEndian(id)) + store.Set(subaccounttypes.SubAccountOwnerKey(ownerAddress), subAccountAddress) // and reverse mapping - store.Set(subaccounttypes.SubAccountKey(id), address.Bytes()) + store.Set(subaccounttypes.SubAccountKey(subAccountAddress), ownerAddress) } // GetSubAccountByOwner returns the subaccount ID of an owner. -func (k Keeper) GetSubAccountByOwner(ctx sdk.Context, address sdk.AccAddress) uint64 { +func (k Keeper) GetSubAccountByOwner(ctx sdk.Context, address sdk.AccAddress) (sdk.AccAddress, bool) { store := ctx.KVStore(k.storeKey) - return sdk.BigEndianToUint64(store.Get(subaccounttypes.SubAccountOwnerKey(address))) + addr := store.Get(subaccounttypes.SubAccountOwnerKey(address)) + return addr, addr != nil } // GetSubAccountOwner returns the owner of a subaccount. -func (k Keeper) GetSubAccountOwner(ctx sdk.Context, id uint64) sdk.AccAddress { +func (k Keeper) GetSubAccountOwner(ctx sdk.Context, subAccountOwner sdk.AccAddress) (sdk.AccAddress, bool) { store := ctx.KVStore(k.storeKey) - return store.Get(subaccounttypes.SubAccountKey(id)) + addr := store.Get(subaccounttypes.SubAccountKey(subAccountOwner)) + return addr, addr != nil } // SetLockedBalances saves the locked balances of an account. -func (k Keeper) SetLockedBalances(ctx sdk.Context, id uint64, lockedBalances []*subaccounttypes.LockedBalance) { - account := subaccounttypes.NewAddressFromSubaccount(id) +func (k Keeper) SetLockedBalances(ctx sdk.Context, subAccountAddress sdk.AccAddress, lockedBalances []*subaccounttypes.LockedBalance) { store := ctx.KVStore(k.storeKey) for _, lockedBalance := range lockedBalances { @@ -67,16 +62,15 @@ func (k Keeper) SetLockedBalances(ctx sdk.Context, id uint64, lockedBalances []* panic(err) } store.Set( - subaccounttypes.LockedBalanceKey(account, lockedBalance.UnlockTime), + subaccounttypes.LockedBalanceKey(subAccountAddress, lockedBalance.UnlockTime), amountBytes, ) } } // GetLockedBalances returns the locked balances of an account. -func (k Keeper) GetLockedBalances(ctx sdk.Context, id uint64) []subaccounttypes.LockedBalance { - account := subaccounttypes.NewAddressFromSubaccount(id) - iterator := prefix.NewStore(ctx.KVStore(k.storeKey), subaccounttypes.LockedBalancePrefixKey(account)).Iterator(nil, nil) +func (k Keeper) GetLockedBalances(ctx sdk.Context, subAccountAddress sdk.AccAddress) []subaccounttypes.LockedBalance { + iterator := prefix.NewStore(ctx.KVStore(k.storeKey), subaccounttypes.LockedBalancePrefixKey(subAccountAddress)).Iterator(nil, nil) defer iterator.Close() var lockedBalances []subaccounttypes.LockedBalance @@ -101,9 +95,8 @@ func (k Keeper) GetLockedBalances(ctx sdk.Context, id uint64) []subaccounttypes. } // GetUnlockedBalance returns the unlocked balance of an account. -func (k Keeper) GetUnlockedBalance(ctx sdk.Context, id uint64) sdk.Int { - account := subaccounttypes.NewAddressFromSubaccount(id) - iterator := prefix.NewStore(ctx.KVStore(k.storeKey), subaccounttypes.LockedBalancePrefixKey(account)). +func (k Keeper) GetUnlockedBalance(ctx sdk.Context, subAccountAddress sdk.AccAddress) sdk.Int { + iterator := prefix.NewStore(ctx.KVStore(k.storeKey), subaccounttypes.LockedBalancePrefixKey(subAccountAddress)). Iterator(nil, sdk.FormatTimeBytes(ctx.BlockTime())) unlockedBalance := sdk.ZeroInt() @@ -122,22 +115,23 @@ func (k Keeper) GetUnlockedBalance(ctx sdk.Context, id uint64) sdk.Int { } // SetBalance saves the balance of an account. -func (k Keeper) SetBalance(ctx sdk.Context, subaccountID uint64, balance subaccounttypes.Balance) { - account := subaccounttypes.NewAddressFromSubaccount(subaccountID) +func (k Keeper) SetBalance(ctx sdk.Context, subAccountAddress sdk.AccAddress, balance subaccounttypes.Balance) { store := ctx.KVStore(k.storeKey) bz := k.cdc.MustMarshal(&balance) - store.Set(subaccounttypes.BalanceKey(account), bz) + store.Set(subaccounttypes.BalanceKey(subAccountAddress), bz) } // GetBalance returns the balance of an account. -func (k Keeper) GetBalance(ctx sdk.Context, subaccountID uint64) subaccounttypes.Balance { - account := subaccounttypes.NewAddressFromSubaccount(subaccountID) +func (k Keeper) GetBalance(ctx sdk.Context, subAccountAddress sdk.AccAddress) (subaccounttypes.Balance, bool) { store := ctx.KVStore(k.storeKey) - bz := store.Get(subaccounttypes.BalanceKey(account)) + bz := store.Get(subaccounttypes.BalanceKey(subAccountAddress)) + if bz == nil { + return subaccounttypes.Balance{}, false + } balance := subaccounttypes.Balance{} k.cdc.MustUnmarshal(bz, &balance) - return balance + return balance, true } diff --git a/x/subaccount/keeper/subaccount_test.go b/x/subaccount/keeper/subaccount_test.go index fab65f1a..33c1cb17 100644 --- a/x/subaccount/keeper/subaccount_test.go +++ b/x/subaccount/keeper/subaccount_test.go @@ -29,26 +29,34 @@ func TestSubaccountID(t *testing.T) { func TestSubAccountOwner(t *testing.T) { _, k, ctx := setupKeeperAndApp(t) - address := sample.NativeAccAddress() + owner := sample.NativeAccAddress() // Account should not have subaccount - require.Equal(t, false, k.HasSubAccount(ctx, address)) + _, exists := k.GetSubAccountOwner(ctx, owner) + require.False(t, exists) // Set subaccount owner k.NextID(ctx) ID := k.Peek(ctx) - k.SetSubAccountOwner(ctx, ID, address) + k.SetSubAccountOwner(ctx, types.NewAddressFromSubaccount(1), owner) // Account should have subaccount - require.True(t, k.HasSubAccount(ctx, address)) + _, exists = k.GetSubAccountOwner(ctx, owner) + require.True(t, exists) // Get subaccount ID - require.Equal(t, ID, k.GetSubAccountByOwner(ctx, address)) + subAccountAddress, exists := k.GetSubAccountByOwner(ctx, owner) + require.True(t, exists) + require.Equal(t, types.NewAddressFromSubaccount(ID), subAccountAddress) // Get owner of subaccount - require.Equal(t, address, k.GetSubAccountOwner(ctx, ID)) + gotOwner, exists := k.GetSubAccountOwner(ctx, subAccountAddress) + require.True(t, exists) + require.Equal(t, owner, gotOwner) // Get account ID by owner - require.Equal(t, ID, k.GetSubAccountByOwner(ctx, address)) + gotSubAccount, exists := k.GetSubAccountByOwner(ctx, owner) + require.True(t, exists) + require.Equal(t, types.NewAddressFromSubaccount(ID), gotSubAccount) } func TestSetLockedBalances(t *testing.T) { @@ -68,10 +76,12 @@ func TestSetLockedBalances(t *testing.T) { }, } - k.SetLockedBalances(ctx, 1, balanceUnlocks) + addr := types.NewAddressFromSubaccount(1) + + k.SetLockedBalances(ctx, addr, balanceUnlocks) // Get locked balances - lockedBalances := k.GetLockedBalances(ctx, 1) + lockedBalances := k.GetLockedBalances(ctx, addr) for i, lockedBalance := range lockedBalances { require.Equal(t, lockedBalance.Amount, balanceUnlocks[i].Amount) require.True(t, lockedBalance.UnlockTime.Equal(balanceUnlocks[i].UnlockTime)) @@ -88,10 +98,13 @@ func TestSetBalances(t *testing.T) { LostAmount: sdk.OneInt(), } - k.SetBalance(ctx, 1, balance) + subAccAddr := types.NewAddressFromSubaccount(1) + k.SetBalance(ctx, subAccAddr, balance) // Get balance - require.Equal(t, balance, k.GetBalance(ctx, 1)) + gotBalance, exists := k.GetBalance(ctx, subAccAddr) + require.True(t, exists) + require.Equal(t, balance, gotBalance) } func TestKeeper_GetLockedBalances(t *testing.T) { @@ -123,9 +136,10 @@ func TestKeeper_GetLockedBalances(t *testing.T) { }, } - k.SetLockedBalances(ctx, 1, balanceUnlocks) + addr := types.NewAddressFromSubaccount(1) + k.SetLockedBalances(ctx, addr, balanceUnlocks) // get unlocked balance - unlockedBalance := k.GetUnlockedBalance(ctx, 1) + unlockedBalance := k.GetUnlockedBalance(ctx, addr) require.True(t, unlockedBalance.Equal(sdk.NewInt(10000+20000))) } diff --git a/x/subaccount/keeper/topup.go b/x/subaccount/keeper/topup.go index 00aff53c..065e0595 100644 --- a/x/subaccount/keeper/topup.go +++ b/x/subaccount/keeper/topup.go @@ -18,18 +18,21 @@ func (m msgServer) TopUp(ctx context.Context, msg *types.MsgTopUp) (*types.MsgTo sender := sdk.MustAccAddressFromBech32(msg.Sender) subaccountOwner := sdk.MustAccAddressFromBech32(msg.SubAccount) - if !m.keeper.HasSubAccount(sdkContext, subaccountOwner) { + + subAccAddress, exists := m.keeper.GetSubAccountByOwner(sdkContext, subaccountOwner) + if !exists { return nil, types.ErrSubaccountDoesNotExist } - - subaccountID := m.keeper.GetSubAccountByOwner(sdkContext, subaccountOwner) - balance := m.keeper.GetBalance(sdkContext, subaccountID) + balance, exists := m.keeper.GetBalance(sdkContext, subAccAddress) + if !exists { + panic("data corruption: subaccount exists but balance does not") + } balance.DepositedAmount = balance.DepositedAmount.Add(moneyToAdd) - m.keeper.SetBalance(sdkContext, subaccountID, balance) - m.keeper.SetLockedBalances(sdkContext, subaccountID, msg.LockedBalances) + m.keeper.SetBalance(sdkContext, subAccAddress, balance) + m.keeper.SetLockedBalances(sdkContext, subAccAddress, msg.LockedBalances) - err = m.sendCoinsToSubaccount(sdkContext, sender, subaccountID, moneyToAdd) + err = m.sendCoinsToSubaccount(sdkContext, sender, subAccAddress, moneyToAdd) if err != nil { return nil, fmt.Errorf("unable to send coins: %w", err) } diff --git a/x/subaccount/keeper/topup_test.go b/x/subaccount/keeper/topup_test.go index b046b50a..c0261042 100644 --- a/x/subaccount/keeper/topup_test.go +++ b/x/subaccount/keeper/topup_test.go @@ -32,9 +32,12 @@ func TestMsgServerTopUp_HappyPath(t *testing.T) { _, err = msgServer.CreateSubAccount(sdk.WrapSDKContext(ctx), msg) require.NoError(t, err) - balance := k.GetBalance(ctx, 1) + subAccountAddr := types.NewAddressFromSubaccount(1) + + balance, exists := k.GetBalance(ctx, subAccountAddr) + require.True(t, exists) require.Equal(t, sdk.NewInt(0), balance.DepositedAmount) - balances := k.GetLockedBalances(ctx, 1) + balances := k.GetLockedBalances(ctx, subAccountAddr) require.Len(t, balances, 0) msgTopUp := &types.MsgTopUp{ @@ -51,9 +54,10 @@ func TestMsgServerTopUp_HappyPath(t *testing.T) { require.NoError(t, err) // Check balance - balance = k.GetBalance(ctx, 1) + balance, exists = k.GetBalance(ctx, subAccountAddr) + require.True(t, exists) require.Equal(t, sdk.NewInt(123), balance.DepositedAmount) - balances = k.GetLockedBalances(ctx, 1) + balances = k.GetLockedBalances(ctx, subAccountAddr) require.Len(t, balances, 1) require.True(t, afterTime.Equal(balances[0].UnlockTime)) require.Equal(t, sdk.NewInt(123), balances[0].Amount) diff --git a/x/subaccount/keeper/withdraw.go b/x/subaccount/keeper/withdraw.go index dafd92ff..59fc8379 100644 --- a/x/subaccount/keeper/withdraw.go +++ b/x/subaccount/keeper/withdraw.go @@ -11,15 +11,14 @@ func (m msgServer) WithdrawUnlockedBalances(ctx context.Context, balances *types sdkContext := sdk.UnwrapSDKContext(ctx) sender := sdk.MustAccAddressFromBech32(balances.Sender) - if !m.keeper.HasSubAccount(sdkContext, sender) { + subAccountAddress, exists := m.keeper.GetSubAccountByOwner(sdkContext, sender) + if !exists { return nil, types.ErrSubaccountDoesNotExist } params := m.keeper.GetParams(sdkContext) - subaccountID := m.keeper.GetSubAccountByOwner(sdkContext, sender) - subaccountAddr := types.NewAddressFromSubaccount(subaccountID) - balance, unlockedBalance, bankBalance := m.getBalances(sdkContext, subaccountID, subaccountAddr, params) + balance, unlockedBalance, bankBalance := m.getBalances(sdkContext, subAccountAddress, params) // calculate withdrawable balance, which is the minimum between the available balance, and // what has been unlocked so far. Also, it cannot be greater than the bank balance. @@ -30,9 +29,9 @@ func (m msgServer) WithdrawUnlockedBalances(ctx context.Context, balances *types } balance.WithdrawmAmount = balance.WithdrawmAmount.Add(withdrawableBalance) - m.keeper.SetBalance(sdkContext, subaccountID, balance) + m.keeper.SetBalance(sdkContext, subAccountAddress, balance) - err := m.bankKeeper.SendCoins(sdkContext, subaccountAddr, sender, sdk.NewCoins(sdk.NewCoin(params.LockedBalanceDenom, withdrawableBalance))) + err := m.bankKeeper.SendCoins(sdkContext, subAccountAddress, sender, sdk.NewCoins(sdk.NewCoin(params.LockedBalanceDenom, withdrawableBalance))) if err != nil { return nil, err } @@ -41,9 +40,12 @@ func (m msgServer) WithdrawUnlockedBalances(ctx context.Context, balances *types } // getBalances returns the balance, unlocked balance and bank balance of a subaccount -func (m msgServer) getBalances(sdkContext sdk.Context, subaccountID uint64, subaccountAddr sdk.AccAddress, params types.Params) (types.Balance, sdk.Int, sdk.Coin) { - balance := m.keeper.GetBalance(sdkContext, subaccountID) - unlockedBalance := m.keeper.GetUnlockedBalance(sdkContext, subaccountID) +func (m msgServer) getBalances(sdkContext sdk.Context, subaccountAddr sdk.AccAddress, params types.Params) (types.Balance, sdk.Int, sdk.Coin) { + balance, exists := m.keeper.GetBalance(sdkContext, subaccountAddr) + if !exists { + panic("data corruption: subaccount exists but balance does not") + } + unlockedBalance := m.keeper.GetUnlockedBalance(sdkContext, subaccountAddr) bankBalance := m.bankKeeper.GetBalance(sdkContext, subaccountAddr, params.LockedBalanceDenom) return balance, unlockedBalance, bankBalance diff --git a/x/subaccount/keeper/withdraw_test.go b/x/subaccount/keeper/withdraw_test.go index 1c82fbbb..5d2b3074 100644 --- a/x/subaccount/keeper/withdraw_test.go +++ b/x/subaccount/keeper/withdraw_test.go @@ -74,9 +74,11 @@ func TestMsgServer_WithdrawUnlockedBalances(t *testing.T) { t.Log("expire second locked balance, also force money to be spent") // we force some money to be spent on the subaccount to correctly test // that if the amount is unlocked but spent, it will not be withdrawable. - subaccountBalance := app.SubaccountKeeper.GetBalance(ctx, 1) + subAccountAddress := types.NewAddressFromSubaccount(1) + subaccountBalance, exists := app.SubaccountKeeper.GetBalance(ctx, subAccountAddress) + require.True(t, exists) require.NoError(t, subaccountBalance.Spend(sdk.NewInt(100))) - app.SubaccountKeeper.SetBalance(ctx, 1, subaccountBalance) + app.SubaccountKeeper.SetBalance(ctx, subAccountAddr, subaccountBalance) ctx = ctx.WithBlockTime(lockedTime2.Add(1 * time.Second)) t.Log("Withdraw unlocked balances, with 2 expires") @@ -94,9 +96,10 @@ func TestMsgServer_WithdrawUnlockedBalances(t *testing.T) { require.Equal(t, sdk.NewInt(100), balance.Amount) t.Log("after unspending the money of the subaccount, the owner will be able to get the money back when withdrawing") - subaccountBalance = app.SubaccountKeeper.GetBalance(ctx, 1) + subaccountBalance, exists = app.SubaccountKeeper.GetBalance(ctx, subAccountAddress) + require.True(t, exists) require.NoError(t, subaccountBalance.Unspend(sdk.NewInt(100))) - app.SubaccountKeeper.SetBalance(ctx, 1, subaccountBalance) + app.SubaccountKeeper.SetBalance(ctx, subAccountAddr, subaccountBalance) _, err = msgServer.WithdrawUnlockedBalances(sdk.WrapSDKContext(ctx), &types.MsgWithdrawUnlockedBalances{ Sender: subaccountOwner.String(), }) @@ -105,7 +108,8 @@ func TestMsgServer_WithdrawUnlockedBalances(t *testing.T) { // check balances balance = app.BankKeeper.GetBalance(ctx, subAccountAddr, "usge") require.Equal(t, sdk.NewInt(0), balance.Amount) - subaccountBalance = app.SubaccountKeeper.GetBalance(ctx, 1) + subaccountBalance, exists = app.SubaccountKeeper.GetBalance(ctx, subAccountAddress) + require.True(t, exists) require.Equal(t, sdk.NewInt(300), subaccountBalance.WithdrawmAmount) // check that the owner has received the last money diff --git a/x/subaccount/types/keys.go b/x/subaccount/types/keys.go index 7221301a..e2e32798 100644 --- a/x/subaccount/types/keys.go +++ b/x/subaccount/types/keys.go @@ -3,7 +3,8 @@ package types import ( "time" - "github.com/cosmos/cosmos-sdk/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" ) // module constants @@ -38,22 +39,22 @@ var ( BalancePrefix = []byte{0x04} ) -func SubAccountOwnerKey(address types.AccAddress) []byte { +func SubAccountOwnerKey(address sdk.AccAddress) []byte { return append(SubAccountOwnerPrefix, address...) } -func SubAccountKey(id uint64) []byte { - return append(SubAccountOwnerReversePrefix, types.Uint64ToBigEndian(id)...) +func SubAccountKey(subAccountAddress sdk.AccAddress) []byte { + return append(SubAccountOwnerReversePrefix, subAccountAddress...) } -func LockedBalanceKey(address types.AccAddress, unlockTime time.Time) []byte { - return append(LockedBalancePrefix, append(address.Bytes(), types.FormatTimeBytes(unlockTime)...)...) +func LockedBalanceKey(subAccountAddress sdk.AccAddress, unlockTime time.Time) []byte { + return append(LockedBalancePrefix, append(address.MustLengthPrefix(subAccountAddress), sdk.FormatTimeBytes(unlockTime)...)...) } -func LockedBalancePrefixKey(address types.AccAddress) []byte { - return append(LockedBalancePrefix, address.Bytes()...) +func LockedBalancePrefixKey(subAccountAddress sdk.AccAddress) []byte { + return append(LockedBalancePrefix, address.MustLengthPrefix(subAccountAddress)...) } -func BalanceKey(address types.AccAddress) []byte { +func BalanceKey(address sdk.AccAddress) []byte { return append(BalancePrefix, address.Bytes()...) } diff --git a/x/subaccount/types/subaccount.go b/x/subaccount/types/subaccount.go index 67341ed3..f1be3298 100644 --- a/x/subaccount/types/subaccount.go +++ b/x/subaccount/types/subaccount.go @@ -52,3 +52,11 @@ func (m *Balance) Unspend(amt sdk.Int) error { m.SpentAmount = m.SpentAmount.Sub(amt) return nil } + +func (m *Balance) AddLoss(amt sdk.Int) error { + if !amt.IsPositive() { + return fmt.Errorf("amount is not positive") + } + m.LostAmount = m.LostAmount.Add(amt) + return nil +} From 95e46e1b64e0fa04bab7cc2e5784a35982f2b37a Mon Sep 17 00:00:00 2001 From: unknown unknown Date: Fri, 21 Jul 2023 16:36:35 +0200 Subject: [PATCH 03/20] minor test fixes --- x/subaccount/keeper/create_subaccount.go | 2 +- x/subaccount/keeper/subaccount_test.go | 11 +++++------ x/subaccount/types/msg.go | 9 +++++++++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/x/subaccount/keeper/create_subaccount.go b/x/subaccount/keeper/create_subaccount.go index fa48489b..03656376 100644 --- a/x/subaccount/keeper/create_subaccount.go +++ b/x/subaccount/keeper/create_subaccount.go @@ -25,7 +25,7 @@ func (m msgServer) CreateSubAccount( senderAccount := sdk.MustAccAddressFromBech32(request.Sender) subaccountOwner := sdk.MustAccAddressFromBech32(request.SubAccountOwner) - if _, exists := m.keeper.GetSubAccountOwner(sdkContext, subaccountOwner); exists { + if _, exists := m.keeper.GetSubAccountByOwner(sdkContext, subaccountOwner); exists { return nil, types.ErrSubaccountAlreadyExist } diff --git a/x/subaccount/keeper/subaccount_test.go b/x/subaccount/keeper/subaccount_test.go index 33c1cb17..35b8329e 100644 --- a/x/subaccount/keeper/subaccount_test.go +++ b/x/subaccount/keeper/subaccount_test.go @@ -36,18 +36,17 @@ func TestSubAccountOwner(t *testing.T) { require.False(t, exists) // Set subaccount owner - k.NextID(ctx) - ID := k.Peek(ctx) - k.SetSubAccountOwner(ctx, types.NewAddressFromSubaccount(1), owner) + id := k.NextID(ctx) + k.SetSubAccountOwner(ctx, types.NewAddressFromSubaccount(id), owner) // Account should have subaccount - _, exists = k.GetSubAccountOwner(ctx, owner) + _, exists = k.GetSubAccountByOwner(ctx, owner) require.True(t, exists) // Get subaccount ID subAccountAddress, exists := k.GetSubAccountByOwner(ctx, owner) require.True(t, exists) - require.Equal(t, types.NewAddressFromSubaccount(ID), subAccountAddress) + require.Equal(t, types.NewAddressFromSubaccount(id), subAccountAddress) // Get owner of subaccount gotOwner, exists := k.GetSubAccountOwner(ctx, subAccountAddress) @@ -56,7 +55,7 @@ func TestSubAccountOwner(t *testing.T) { // Get account ID by owner gotSubAccount, exists := k.GetSubAccountByOwner(ctx, owner) require.True(t, exists) - require.Equal(t, types.NewAddressFromSubaccount(ID), gotSubAccount) + require.Equal(t, types.NewAddressFromSubaccount(id), gotSubAccount) } func TestSetLockedBalances(t *testing.T) { diff --git a/x/subaccount/types/msg.go b/x/subaccount/types/msg.go index cb3730c4..209f19ff 100644 --- a/x/subaccount/types/msg.go +++ b/x/subaccount/types/msg.go @@ -9,6 +9,7 @@ var ( _ sdk.Msg = &MsgCreateSubAccount{} _ sdk.Msg = &MsgTopUp{} _ sdk.Msg = &MsgWithdrawUnlockedBalances{} + _ sdk.Msg = &MsgPlaceBet{} ) func (msg *MsgCreateSubAccount) GetSigners() []sdk.AccAddress { @@ -85,3 +86,11 @@ func (msg *MsgWithdrawUnlockedBalances) GetSigners() []sdk.AccAddress { } return []sdk.AccAddress{signer} } + +func (m *MsgPlaceBet) ValidateBasic() error { + return m.Msg.ValidateBasic() +} + +func (m *MsgPlaceBet) GetSigners() []sdk.AccAddress { + return m.Msg.GetSigners() +} From 225835e6bd3448442fefabe3f934fa3668bf6895 Mon Sep 17 00:00:00 2001 From: unknown unknown Date: Fri, 21 Jul 2023 16:37:36 +0200 Subject: [PATCH 04/20] code clarity --- x/subaccount/keeper/orderbook_hooks.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x/subaccount/keeper/orderbook_hooks.go b/x/subaccount/keeper/orderbook_hooks.go index 7ded6a1e..92a907bd 100644 --- a/x/subaccount/keeper/orderbook_hooks.go +++ b/x/subaccount/keeper/orderbook_hooks.go @@ -49,7 +49,8 @@ func (k Keeper) AfterBettorRefund(ctx sdk.Context, bettor sdk.AccAddress, origin if !exists { return } - err := balance.Unspend(originalAmount.Add(fee)) + totalUnspent := originalAmount.Add(fee) + err := balance.Unspend(totalUnspent) if err != nil { panic(err) } From 65c255865a9e290dcdbafec0ec7f8717ab7a7883 Mon Sep 17 00:00:00 2001 From: unknown unknown Date: Fri, 21 Jul 2023 17:48:08 +0200 Subject: [PATCH 05/20] add router --- app/keepers/keepers.go | 9 +++++---- x/subaccount/keeper/bet.go | 22 +++++++++++++++++++++- x/subaccount/keeper/keeper.go | 11 +++++++++-- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index eedf969a..a0cf4f50 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -104,7 +104,7 @@ type AppKeepers struct { AuthzKeeper authzkeeper.Keeper SubaccountKeeper subaccountkeeper.Keeper - //// SGE keepers \\\\ + // // SGE keepers \\\\ BetKeeper *betmodulekeeper.Keeper MarketKeeper *marketmodulekeeper.Keeper MintKeeper mintkeeper.Keeper @@ -113,7 +113,7 @@ type AppKeepers struct { OVMKeeper *ovmmodulekeeper.Keeper SubaccountModule subaccount.AppModule - //// SGE modules \\\\ + // // SGE modules \\\\ BetModule betmodule.AppModule MarketModule marketmodule.AppModule HouseModule housemodule.AppModule @@ -344,7 +344,7 @@ func NewAppKeeper( appKeepers.SlashingKeeper, ) - //// SGE keepers \\\\ + // // SGE keepers \\\\ appKeepers.OrderbookKeeper = orderbookmodulekeeper.NewKeeper( appCodec, @@ -399,7 +399,7 @@ func NewAppKeeper( ) appKeepers.OrderbookKeeper.SetHouseKeeper(appKeepers.HouseKeeper) - //// SGE modules \\\\ + // // SGE modules \\\\ appKeepers.BetModule = betmodule.NewAppModule( appCodec, @@ -435,6 +435,7 @@ func NewAppKeeper( appCodec, appKeepers.keys[subaccounttypes.StoreKey], appKeepers.GetSubspace(subaccounttypes.ModuleName), + bApp.MsgServiceRouter(), ) appKeepers.SubaccountModule = subaccount.NewAppModule(appKeepers.SubaccountKeeper) diff --git a/x/subaccount/keeper/bet.go b/x/subaccount/keeper/bet.go index ecb705e7..d3e408cb 100644 --- a/x/subaccount/keeper/bet.go +++ b/x/subaccount/keeper/bet.go @@ -3,9 +3,29 @@ package keeper import ( "context" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/gogo/protobuf/proto" + bettypes "github.com/sge-network/sge/x/bet/types" "github.com/sge-network/sge/x/subaccount/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" ) func (m msgServer) PlaceBet(ctx context.Context, msg *types.MsgPlaceBet) (*types.MsgPlaceBetResponse, error) { - panic("implement me") + handler := m.keeper.msgRouter.Handler(msg.Msg) + if handler == nil { + return nil, status.Error(codes.Unavailable, "the message type is not supported by the subaccount router") + } + sdkResult, err := handler(sdk.UnwrapSDKContext(ctx), msg.Msg) + if err != nil { + return nil, err + } + + resp := &bettypes.MsgPlaceBetResponse{} + err = proto.Unmarshal(sdkResult.Data, resp) + if err != nil { + return nil, err + } + + return &types.MsgPlaceBetResponse{Response: resp}, nil } diff --git a/x/subaccount/keeper/keeper.go b/x/subaccount/keeper/keeper.go index a86dceca..54529a46 100644 --- a/x/subaccount/keeper/keeper.go +++ b/x/subaccount/keeper/keeper.go @@ -1,6 +1,7 @@ package keeper import ( + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" @@ -8,18 +9,24 @@ import ( "github.com/sge-network/sge/x/subaccount/types" ) +type MsgRouter interface { + Handler(msg sdk.Msg) baseapp.MsgServiceHandler +} + type Keeper struct { cdc codec.Codec storeKey sdk.StoreKey paramstore paramtypes.Subspace bankKeeper bankkeeper.Keeper + + msgRouter MsgRouter } -func NewKeeper(cdc codec.Codec, storeKey sdk.StoreKey, ps paramtypes.Subspace) Keeper { +func NewKeeper(cdc codec.Codec, storeKey sdk.StoreKey, ps paramtypes.Subspace, router MsgRouter) Keeper { // set KeyTable if it is not already set if !ps.HasKeyTable() { ps = ps.WithKeyTable(types.ParamKeyTable()) } - return Keeper{storeKey: storeKey, cdc: cdc, paramstore: ps} + return Keeper{storeKey: storeKey, cdc: cdc, paramstore: ps, msgRouter: router} } From b672bfeb722ccc137703fdbdd68342992dab0667 Mon Sep 17 00:00:00 2001 From: unknown unknown Date: Mon, 24 Jul 2023 11:38:50 +0200 Subject: [PATCH 06/20] tmp --- x/subaccount/keeper/bet.go | 18 +++- x/subaccount/keeper/bet_test.go | 141 ++++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+), 2 deletions(-) create mode 100644 x/subaccount/keeper/bet_test.go diff --git a/x/subaccount/keeper/bet.go b/x/subaccount/keeper/bet.go index d3e408cb..430fffed 100644 --- a/x/subaccount/keeper/bet.go +++ b/x/subaccount/keeper/bet.go @@ -11,12 +11,26 @@ import ( "google.golang.org/grpc/status" ) -func (m msgServer) PlaceBet(ctx context.Context, msg *types.MsgPlaceBet) (*types.MsgPlaceBetResponse, error) { +func (m msgServer) PlaceBet(goCtx context.Context, msg *types.MsgPlaceBet) (*types.MsgPlaceBetResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // address: cosmos1234 + // creator: cosmos-subaccount-1234 + + subAccAddr, exists := m.keeper.GetSubAccountByOwner(ctx, sdk.MustAccAddressFromBech32(msg.Msg.Creator)) + if !exists { + return nil, types.ErrSubaccountDoesNotExist + } + + // swap the creator address with the subaccount address + msg.Msg.Creator = subAccAddr.String() + handler := m.keeper.msgRouter.Handler(msg.Msg) if handler == nil { return nil, status.Error(codes.Unavailable, "the message type is not supported by the subaccount router") } - sdkResult, err := handler(sdk.UnwrapSDKContext(ctx), msg.Msg) + + sdkResult, err := handler(ctx, msg.Msg) if err != nil { return nil, err } diff --git a/x/subaccount/keeper/bet_test.go b/x/subaccount/keeper/bet_test.go new file mode 100644 index 00000000..a6c1c97e --- /dev/null +++ b/x/subaccount/keeper/bet_test.go @@ -0,0 +1,141 @@ +package keeper_test + +import ( + "testing" + "time" + + "github.com/cosmos/cosmos-sdk/simapp" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/golang-jwt/jwt" + "github.com/google/uuid" + "github.com/sge-network/sge/testutil/sample" + simappUtil "github.com/sge-network/sge/testutil/simapp" + sgetypes "github.com/sge-network/sge/types" + bettypes "github.com/sge-network/sge/x/bet/types" + marketkeeper "github.com/sge-network/sge/x/market/keeper" + markettypes "github.com/sge-network/sge/x/market/types" + "github.com/sge-network/sge/x/subaccount/types" + "github.com/stretchr/testify/require" +) + +var ( + testMarketUID = "5db09053-2901-4110-8fb5-c14e21f8d555" + testOddsUID1 = "6db09053-2901-4110-8fb5-c14e21f8d666" + testOddsUID2 = "5e31c60f-2025-48ce-ae79-1dc110f16358" + testOddsUID3 = "6e31c60f-2025-48ce-ae79-1dc110f16354" + testMarketOdds = []*markettypes.Odds{ + {UID: testOddsUID1, Meta: "Odds 1"}, + {UID: testOddsUID2, Meta: "Odds 2"}, + {UID: testOddsUID3, Meta: "Odds 3"}, + } + testSelectedBetOdds = &bettypes.BetOdds{ + UID: testOddsUID1, + MarketUID: testMarketUID, + Value: "4.20", + MaxLossMultiplier: sdk.MustNewDecFromStr("0.1"), + } + testCreator string +) + +var ( + subAccOwner = sample.NativeAccAddress() + subAccFunder = sample.NativeAccAddress() + micro = sdk.NewInt(1_000_000) + subAccFunds = sdk.NewInt(10_000).Mul(micro) +) + +func TestMsgServer_Bet(t *testing.T) { + app, k, msgServer, ctx := setupMsgServerAndApp(t) + + // do subaccount creation + require.NoError( + t, + simapp.FundAccount( + app.BankKeeper, + ctx, + subAccFunder, + sdk.NewCoins(sdk.NewCoin(k.GetParams(ctx).LockedBalanceDenom, subAccFunds)), + ), + ) + + _, err := msgServer.CreateSubAccount(sdk.WrapSDKContext(ctx), &types.MsgCreateSubAccount{ + Sender: subAccFunder.String(), + SubAccountOwner: subAccOwner.String(), + LockedBalances: []*types.LockedBalance{ + { + UnlockTime: time.Now().Add(24 * time.Hour), + Amount: subAccFunds, + }, + }, + }) + require.NoError(t, err) + + // add market + addTestMarket(t, app, ctx) + + // start betting using the subaccount + betAmt := sdk.NewInt(1000).Mul(micro) + _, err = msgServer.PlaceBet( + sdk.WrapSDKContext(ctx), + &types.MsgPlaceBet{Msg: testBet(t, subAccOwner, betAmt)}, + ) + require.NoError(t, err) + + // resolve the market – better wins + // resolve the market – better loses + // resolve the market – refund +} + +func addTestMarket(t testing.TB, tApp *simappUtil.TestApp, ctx sdk.Context) { + testCreator = simappUtil.TestParamUsers["user1"].Address.String() + testAddMarketClaim := jwt.MapClaims{ + "uid": testMarketUID, + "start_ts": 1111111111, + "end_ts": uint64(ctx.BlockTime().Unix()) + 1000, + "odds": testMarketOdds, + "exp": 9999999999, + "iat": 7777777777, + "meta": "Winner of x:y", + "status": markettypes.MarketStatus_MARKET_STATUS_ACTIVE, + } + testAddMarketTicket, err := createJwtTicket(testAddMarketClaim) + require.Nil(t, err) + + testAddMarket := &markettypes.MsgAddMarket{ + Creator: testCreator, + Ticket: testAddMarketTicket, + } + wctx := sdk.WrapSDKContext(ctx) + marketSrv := marketkeeper.NewMsgServerImpl(*tApp.MarketKeeper) + resAddMarket, err := marketSrv.AddMarket(wctx, testAddMarket) + require.Nil(t, err) + require.NotNil(t, resAddMarket) +} + +func createJwtTicket(claim jwt.MapClaims) (string, error) { + token := jwt.NewWithClaims(jwt.SigningMethodEdDSA, claim) + return token.SignedString(simappUtil.TestOVMPrivateKeys[0]) +} + +func testBet(t testing.TB, better sdk.AccAddress, amount sdk.Int) *bettypes.MsgPlaceBet { + ticket, err := createJwtTicket(jwt.MapClaims{ + "exp": 9999999999, + "iat": 7777777777, + "selected_odds": testSelectedBetOdds, + "kyc_data": &sgetypes.KycDataPayload{ + Approved: true, + ID: testCreator, + }, + "odds_type": 1, + }) + require.NoError(t, err) + + return &bettypes.MsgPlaceBet{ + Creator: better.String(), + Bet: &bettypes.PlaceBetFields{ + UID: uuid.NewString(), + Amount: amount, + Ticket: ticket, + }, + } +} From 1c94a110aa04b2b6f78a28892fc518c50cce18f2 Mon Sep 17 00:00:00 2001 From: unknown unknown Date: Mon, 24 Jul 2023 12:04:47 +0200 Subject: [PATCH 07/20] more adjustments --- app/keepers/keepers.go | 4 ++- x/subaccount/keeper/bet.go | 47 ++++++++++++++++++++------------- x/subaccount/keeper/bet_test.go | 36 ++++++++++++++++++++++--- x/subaccount/keeper/keeper.go | 28 ++++++++++++++------ 4 files changed, 85 insertions(+), 30 deletions(-) diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index a0cf4f50..887251aa 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -435,7 +435,9 @@ func NewAppKeeper( appCodec, appKeepers.keys[subaccounttypes.StoreKey], appKeepers.GetSubspace(subaccounttypes.ModuleName), - bApp.MsgServiceRouter(), + appKeepers.BankKeeper, + appKeepers.OVMKeeper, + appKeepers.BetKeeper, ) appKeepers.SubaccountModule = subaccount.NewAppModule(appKeepers.SubaccountKeeper) diff --git a/x/subaccount/keeper/bet.go b/x/subaccount/keeper/bet.go index 430fffed..d8e5fcf6 100644 --- a/x/subaccount/keeper/bet.go +++ b/x/subaccount/keeper/bet.go @@ -4,7 +4,7 @@ import ( "context" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/gogo/protobuf/proto" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" bettypes "github.com/sge-network/sge/x/bet/types" "github.com/sge-network/sge/x/subaccount/types" "google.golang.org/grpc/codes" @@ -14,32 +14,43 @@ import ( func (m msgServer) PlaceBet(goCtx context.Context, msg *types.MsgPlaceBet) (*types.MsgPlaceBetResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - // address: cosmos1234 - // creator: cosmos-subaccount-1234 - - subAccAddr, exists := m.keeper.GetSubAccountByOwner(ctx, sdk.MustAccAddressFromBech32(msg.Msg.Creator)) + // find subaccount + subAccountAddress, exists := m.keeper.GetSubAccountByOwner(ctx, sdk.MustAccAddressFromBech32(msg.Msg.Creator)) if !exists { - return nil, types.ErrSubaccountDoesNotExist + return nil, status.Error(codes.NotFound, "subaccount not found") } - // swap the creator address with the subaccount address - msg.Msg.Creator = subAccAddr.String() + // TODO: duplicate code from x/bet/keeper/msg_server_bet.go - handler := m.keeper.msgRouter.Handler(msg.Msg) - if handler == nil { - return nil, status.Error(codes.Unavailable, "the message type is not supported by the subaccount router") + // Check if the value already exists + _, isFound := m.keeper.betKeeper.GetBetID(ctx, msg.Msg.Bet.UID) + if isFound { + return nil, sdkerrors.Wrapf(bettypes.ErrDuplicateUID, "%s", msg.Msg.Bet.UID) } - sdkResult, err := handler(ctx, msg.Msg) + payload := &bettypes.BetPlacementTicketPayload{} + err := m.keeper.ovmKeeper.VerifyTicketUnmarshal(sdk.WrapSDKContext(ctx), msg.Msg.Bet.Ticket, &payload) if err != nil { - return nil, err + return nil, sdkerrors.Wrapf(bettypes.ErrInTicketVerification, "%s", err) } - resp := &bettypes.MsgPlaceBetResponse{} - err = proto.Unmarshal(sdkResult.Data, resp) - if err != nil { - return nil, err + originalSender := msg.Msg.Creator + + if err = payload.Validate(originalSender); err != nil { + return nil, sdkerrors.Wrapf(bettypes.ErrInTicketValidation, "%s", err) + } + + // here we swap the original sender with the subaccount address + bet := bettypes.NewBet(subAccountAddress.String(), msg.Msg.Bet, payload.OddsType, payload.SelectedOdds) + + if err := m.keeper.betKeeper.PlaceBet(ctx, bet); err != nil { + return nil, sdkerrors.Wrapf(bettypes.ErrInBetPlacement, "%s", err) } - return &types.MsgPlaceBetResponse{Response: resp}, nil + msg.Msg.EmitEvent(&ctx) + + return &types.MsgPlaceBetResponse{ + Response: &bettypes.MsgPlaceBetResponse{Bet: msg.Msg.Bet}, + }, nil + } diff --git a/x/subaccount/keeper/bet_test.go b/x/subaccount/keeper/bet_test.go index a6c1c97e..0a9e126f 100644 --- a/x/subaccount/keeper/bet_test.go +++ b/x/subaccount/keeper/bet_test.go @@ -81,9 +81,22 @@ func TestMsgServer_Bet(t *testing.T) { ) require.NoError(t, err) - // resolve the market – better wins + t.Run("resolve market – better wins", func(t *testing.T) { + ctx, _ = ctx.CacheContext() + // resolve the market – better wins + + }) // resolve the market – better loses - // resolve the market – refund + t.Run("resolve market – better loses", func(t *testing.T) { + ctx, _ = ctx.CacheContext() + // resolve the market – better loses + + }) + t.Run("resolve market – refund", func(t *testing.T) { + ctx, _ = ctx.CacheContext() + // resolve the market – refund + + }) } func addTestMarket(t testing.TB, tApp *simappUtil.TestApp, ctx sdk.Context) { @@ -110,6 +123,23 @@ func addTestMarket(t testing.TB, tApp *simappUtil.TestApp, ctx sdk.Context) { resAddMarket, err := marketSrv.AddMarket(wctx, testAddMarket) require.Nil(t, err) require.NotNil(t, resAddMarket) + + // add liquidity + err = simapp.FundAccount( + tApp.BankKeeper, + ctx, + simappUtil.TestParamUsers["user1"].Address, + sdk.NewCoins(sdk.NewCoin(tApp.SubaccountKeeper.GetParams(ctx).LockedBalanceDenom, sdk.NewInt(1_000_000).Mul(micro))), + ) + require.NoError(t, err) + _, err = tApp.OrderbookKeeper.InitiateOrderBookParticipation( + ctx, + simappUtil.TestParamUsers["user1"].Address, + resAddMarket.Data.UID, + sdk.NewInt(1_000_000).Mul(micro), + sdk.NewInt(1), + ) + require.NoError(t, err) } func createJwtTicket(claim jwt.MapClaims) (string, error) { @@ -124,7 +154,7 @@ func testBet(t testing.TB, better sdk.AccAddress, amount sdk.Int) *bettypes.MsgP "selected_odds": testSelectedBetOdds, "kyc_data": &sgetypes.KycDataPayload{ Approved: true, - ID: testCreator, + ID: better.String(), }, "odds_type": 1, }) diff --git a/x/subaccount/keeper/keeper.go b/x/subaccount/keeper/keeper.go index 54529a46..7832e2ea 100644 --- a/x/subaccount/keeper/keeper.go +++ b/x/subaccount/keeper/keeper.go @@ -1,32 +1,44 @@ package keeper import ( - "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + bettypes "github.com/sge-network/sge/x/bet/types" "github.com/sge-network/sge/x/subaccount/types" ) -type MsgRouter interface { - Handler(msg sdk.Msg) baseapp.MsgServiceHandler +type BetKeeper interface { + GetBetID(ctx sdk.Context, uid string) (bettypes.UID2ID, bool) + PlaceBet(ctx sdk.Context, bet *bettypes.Bet) error +} + +type BankKeeper interface { + SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error } type Keeper struct { cdc codec.Codec storeKey sdk.StoreKey paramstore paramtypes.Subspace - bankKeeper bankkeeper.Keeper + bankKeeper BankKeeper - msgRouter MsgRouter + ovmKeeper bettypes.OVMKeeper + betKeeper BetKeeper } -func NewKeeper(cdc codec.Codec, storeKey sdk.StoreKey, ps paramtypes.Subspace, router MsgRouter) Keeper { +func NewKeeper(cdc codec.Codec, storeKey sdk.StoreKey, ps paramtypes.Subspace, bankKeeper BankKeeper, ovmKeeper bettypes.OVMKeeper, betKeeper BetKeeper) Keeper { // set KeyTable if it is not already set if !ps.HasKeyTable() { ps = ps.WithKeyTable(types.ParamKeyTable()) } - return Keeper{storeKey: storeKey, cdc: cdc, paramstore: ps, msgRouter: router} + return Keeper{ + cdc: cdc, + storeKey: storeKey, + paramstore: ps, + bankKeeper: bankKeeper, + ovmKeeper: ovmKeeper, + betKeeper: betKeeper, + } } From 1cd157383b31b85731a45bbbe5366e6d8ec76c73 Mon Sep 17 00:00:00 2001 From: unknown unknown Date: Mon, 24 Jul 2023 15:58:48 +0200 Subject: [PATCH 08/20] test work --- app/keepers/keepers.go | 1 + x/subaccount/keeper/bet.go | 15 ++++++ x/subaccount/keeper/bet_test.go | 72 ++++++++++++++++++++++++-- x/subaccount/keeper/keeper.go | 11 +++- x/subaccount/keeper/orderbook_hooks.go | 5 +- 5 files changed, 96 insertions(+), 8 deletions(-) diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 887251aa..d4706110 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -438,6 +438,7 @@ func NewAppKeeper( appKeepers.BankKeeper, appKeepers.OVMKeeper, appKeepers.BetKeeper, + appKeepers.OrderbookKeeper, ) appKeepers.SubaccountModule = subaccount.NewAppModule(appKeepers.SubaccountKeeper) diff --git a/x/subaccount/keeper/bet.go b/x/subaccount/keeper/bet.go index d8e5fcf6..efc51cab 100644 --- a/x/subaccount/keeper/bet.go +++ b/x/subaccount/keeper/bet.go @@ -40,13 +40,28 @@ func (m msgServer) PlaceBet(goCtx context.Context, msg *types.MsgPlaceBet) (*typ return nil, sdkerrors.Wrapf(bettypes.ErrInTicketValidation, "%s", err) } + // duplication end + // here we swap the original sender with the subaccount address bet := bettypes.NewBet(subAccountAddress.String(), msg.Msg.Bet, payload.OddsType, payload.SelectedOdds) + // make subaccount balance adjustments + balance, exists := m.keeper.GetBalance(ctx, subAccountAddress) + if !exists { + panic("state corruption: subaccount balance not found") + } + + err = balance.Spend(bet.Amount) + if err != nil { + return nil, err + } + if err := m.keeper.betKeeper.PlaceBet(ctx, bet); err != nil { return nil, sdkerrors.Wrapf(bettypes.ErrInBetPlacement, "%s", err) } + m.keeper.SetBalance(ctx, subAccountAddress, balance) + msg.Msg.EmitEvent(&ctx) return &types.MsgPlaceBetResponse{ diff --git a/x/subaccount/keeper/bet_test.go b/x/subaccount/keeper/bet_test.go index 0a9e126f..76f4384f 100644 --- a/x/subaccount/keeper/bet_test.go +++ b/x/subaccount/keeper/bet_test.go @@ -71,7 +71,7 @@ func TestMsgServer_Bet(t *testing.T) { require.NoError(t, err) // add market - addTestMarket(t, app, ctx) + market := addTestMarket(t, app, ctx) // start betting using the subaccount betAmt := sdk.NewInt(1000).Mul(micro) @@ -81,25 +81,86 @@ func TestMsgServer_Bet(t *testing.T) { ) require.NoError(t, err) + // check subaccount balance + subAccAddr := types.NewAddressFromSubaccount(1) + balance, exists := k.GetBalance(ctx, subAccAddr) + require.True(t, exists) + + require.Equal(t, balance.SpentAmount, betAmt) + t.Run("resolve market – better wins", func(t *testing.T) { ctx, _ = ctx.CacheContext() // resolve the market – better wins - + app.MarketKeeper.ResolveMarket(ctx, *market, &markettypes.MarketResolutionTicketPayload{ + UID: market.UID, + ResolutionTS: uint64(ctx.BlockTime().Unix()) + 10000, + WinnerOddsUIDs: []string{testOddsUID1}, + Status: markettypes.MarketStatus_MARKET_STATUS_RESULT_DECLARED, + }) + err := app.BetKeeper.BatchMarketSettlements(ctx) + require.NoError(t, err) + + // now we check the subaccount balance + balance, exists := k.GetBalance(ctx, subAccAddr) + require.True(t, exists) + require.Equal(t, balance.SpentAmount, sdk.ZeroInt()) + + // now we want the user to have some balance which is the payout + ownerBalance := app.BankKeeper.GetAllBalances(ctx, subAccOwner) + require.Equal(t, + sdk.NewCoins( + sdk.NewCoin( + k.GetParams(ctx).LockedBalanceDenom, + betAmt.ToDec().Mul(sdk.MustNewDecFromStr("3.2")).TruncateInt(), // 4.2 - 1 = 3.2 + )), + ownerBalance, + ) }) // resolve the market – better loses t.Run("resolve market – better loses", func(t *testing.T) { ctx, _ = ctx.CacheContext() // resolve the market – better loses - + app.MarketKeeper.ResolveMarket(ctx, *market, &markettypes.MarketResolutionTicketPayload{ + UID: market.UID, + ResolutionTS: uint64(ctx.BlockTime().Unix()) + 10000, + WinnerOddsUIDs: []string{testOddsUID2}, + Status: markettypes.MarketStatus_MARKET_STATUS_RESULT_DECLARED, + }) + err := app.BetKeeper.BatchMarketSettlements(ctx) + require.NoError(t, err) + + // now we check the subaccount balance + balance, exists := k.GetBalance(ctx, subAccAddr) + require.True(t, exists) + require.Equal(t, balance.SpentAmount, sdk.ZeroInt()) + require.Equal(t, balance.LostAmount, betAmt) + // the owner has no balances + ownerBalance := app.BankKeeper.GetAllBalances(ctx, subAccOwner) + require.Equal(t, sdk.NewCoins(), ownerBalance) }) t.Run("resolve market – refund", func(t *testing.T) { ctx, _ = ctx.CacheContext() // resolve the market – refund - + app.MarketKeeper.ResolveMarket(ctx, *market, &markettypes.MarketResolutionTicketPayload{ + UID: market.UID, + ResolutionTS: uint64(ctx.BlockTime().Unix()) + 10000, + WinnerOddsUIDs: []string{testOddsUID1}, + Status: markettypes.MarketStatus_MARKET_STATUS_CANCELED, + }) + err := app.BetKeeper.BatchMarketSettlements(ctx) + require.NoError(t, err) + + // now we check the subaccount balance + balance, exists := k.GetBalance(ctx, subAccAddr) + require.True(t, exists) + require.Equal(t, balance.SpentAmount, sdk.ZeroInt()) + + // the owner balance is zero + require.Equal(t, sdk.NewCoins(), app.BankKeeper.GetAllBalances(ctx, subAccOwner)) }) } -func addTestMarket(t testing.TB, tApp *simappUtil.TestApp, ctx sdk.Context) { +func addTestMarket(t testing.TB, tApp *simappUtil.TestApp, ctx sdk.Context) *markettypes.Market { testCreator = simappUtil.TestParamUsers["user1"].Address.String() testAddMarketClaim := jwt.MapClaims{ "uid": testMarketUID, @@ -140,6 +201,7 @@ func addTestMarket(t testing.TB, tApp *simappUtil.TestApp, ctx sdk.Context) { sdk.NewInt(1), ) require.NoError(t, err) + return resAddMarket.Data } func createJwtTicket(claim jwt.MapClaims) (string, error) { diff --git a/x/subaccount/keeper/keeper.go b/x/subaccount/keeper/keeper.go index 7832e2ea..bf863b47 100644 --- a/x/subaccount/keeper/keeper.go +++ b/x/subaccount/keeper/keeper.go @@ -5,6 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" bettypes "github.com/sge-network/sge/x/bet/types" + orderbookmodulekeeper "github.com/sge-network/sge/x/orderbook/keeper" "github.com/sge-network/sge/x/subaccount/types" ) @@ -17,6 +18,10 @@ type BankKeeper interface { SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error } +type OrderBookKeeper interface { + RegisterHook(hooks orderbookmodulekeeper.Hook) +} + type Keeper struct { cdc codec.Codec storeKey sdk.StoreKey @@ -27,13 +32,13 @@ type Keeper struct { betKeeper BetKeeper } -func NewKeeper(cdc codec.Codec, storeKey sdk.StoreKey, ps paramtypes.Subspace, bankKeeper BankKeeper, ovmKeeper bettypes.OVMKeeper, betKeeper BetKeeper) Keeper { +func NewKeeper(cdc codec.Codec, storeKey sdk.StoreKey, ps paramtypes.Subspace, bankKeeper BankKeeper, ovmKeeper bettypes.OVMKeeper, betKeeper BetKeeper, obKeeper OrderBookKeeper) Keeper { // set KeyTable if it is not already set if !ps.HasKeyTable() { ps = ps.WithKeyTable(types.ParamKeyTable()) } - return Keeper{ + k := Keeper{ cdc: cdc, storeKey: storeKey, paramstore: ps, @@ -41,4 +46,6 @@ func NewKeeper(cdc codec.Codec, storeKey sdk.StoreKey, ps paramtypes.Subspace, b ovmKeeper: ovmKeeper, betKeeper: betKeeper, } + obKeeper.RegisterHook(k) + return k } diff --git a/x/subaccount/keeper/orderbook_hooks.go b/x/subaccount/keeper/orderbook_hooks.go index 92a907bd..abea013f 100644 --- a/x/subaccount/keeper/orderbook_hooks.go +++ b/x/subaccount/keeper/orderbook_hooks.go @@ -1,6 +1,8 @@ package keeper import ( + "log" + sdk "github.com/cosmos/cosmos-sdk/types" orderbookmodulekeeper "github.com/sge-network/sge/x/orderbook/keeper" ) @@ -21,7 +23,7 @@ func (k Keeper) AfterBettorWin(ctx sdk.Context, bettor sdk.AccAddress, originalA if !exists { panic("subaccount owner not found") } - err = k.bankKeeper.SendCoins(ctx, owner, bettor, sdk.NewCoins(sdk.NewCoin(k.GetParams(ctx).LockedBalanceDenom, originalAmount))) + err = k.bankKeeper.SendCoins(ctx, bettor, owner, sdk.NewCoins(sdk.NewCoin(k.GetParams(ctx).LockedBalanceDenom, profit))) if err != nil { panic(err) } @@ -55,4 +57,5 @@ func (k Keeper) AfterBettorRefund(ctx sdk.Context, bettor sdk.AccAddress, origin panic(err) } k.SetBalance(ctx, bettor, balance) + log.Printf("bettor refunded, yay!") } From 5f97c4913522c5e19f80626a62ca416af2242fa7 Mon Sep 17 00:00:00 2001 From: unknown unknown Date: Mon, 24 Jul 2023 15:59:03 +0200 Subject: [PATCH 09/20] remove logging --- x/subaccount/keeper/orderbook_hooks.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/x/subaccount/keeper/orderbook_hooks.go b/x/subaccount/keeper/orderbook_hooks.go index abea013f..9f435273 100644 --- a/x/subaccount/keeper/orderbook_hooks.go +++ b/x/subaccount/keeper/orderbook_hooks.go @@ -1,8 +1,6 @@ package keeper import ( - "log" - sdk "github.com/cosmos/cosmos-sdk/types" orderbookmodulekeeper "github.com/sge-network/sge/x/orderbook/keeper" ) @@ -57,5 +55,4 @@ func (k Keeper) AfterBettorRefund(ctx sdk.Context, bettor sdk.AccAddress, origin panic(err) } k.SetBalance(ctx, bettor, balance) - log.Printf("bettor refunded, yay!") } From b40cad4a11a36ad3cefe2f811abf1cb985284e6a Mon Sep 17 00:00:00 2001 From: unknown unknown Date: Mon, 24 Jul 2023 16:40:43 +0200 Subject: [PATCH 10/20] implement and refactor --- proto/sge/subaccount/tx.proto | 27 + .../keeper/{bet.go => msg_server_bet.go} | 0 .../{bet_test.go => msg_server_bet_test.go} | 0 x/subaccount/keeper/msg_server_house.go | 17 + x/subaccount/types/tx.pb.go | 1096 ++++++++++++++--- 5 files changed, 994 insertions(+), 146 deletions(-) rename x/subaccount/keeper/{bet.go => msg_server_bet.go} (100%) rename x/subaccount/keeper/{bet_test.go => msg_server_bet_test.go} (100%) create mode 100644 x/subaccount/keeper/msg_server_house.go diff --git a/proto/sge/subaccount/tx.proto b/proto/sge/subaccount/tx.proto index 0de83b8c..f29e8f27 100644 --- a/proto/sge/subaccount/tx.proto +++ b/proto/sge/subaccount/tx.proto @@ -3,6 +3,7 @@ package sgenetwork.sge.subaccount; import "sge/subaccount/subaccount.proto"; import "sge/bet/tx.proto"; +import "sge/house/tx.proto"; option go_package = "github.com/sge-network/sge/x/subaccount/types"; @@ -19,6 +20,12 @@ service Msg { // PlaceBet defines a method for placing a bet using a subaccount. rpc PlaceBet(MsgPlaceBet) returns (MsgPlaceBetResponse); + + // HouseDeposit defines a method for depositing funds to provide liquidity to a market. + rpc HouseDeposit(MsgHouseDeposit) returns (MsgHouseDepositResponse); + + // HouseWithdraw defines a method for withdrawing funds from a market. + rpc HouseWithdraw(MsgHouseWithdraw) returns (MsgHouseWithdrawResponse); } // MsgCreateSubAccount defines the Msg/CreateSubAccount request type. @@ -68,4 +75,24 @@ message MsgPlaceBet { // MsgBetResponse wraps the MsgPlaceBetResponse message. We need it in order not to have double interface registration conflicts. message MsgPlaceBetResponse { sgenetwork.sge.bet.MsgPlaceBetResponse response = 1; +} + +// MsgHouseDeposit wraps the MsgHouseDeposit message. We need it in order not to have double interface registration conflicts. +message MsgHouseDeposit { + sge.house.MsgDeposit msg = 1; +} + +// MsgHouseDepositResponse wraps the MsgHouseDepositResponse message. We need it in order not to have double interface registration conflicts. +message MsgHouseDepositResponse { + sge.house.MsgDepositResponse response = 1; +} + +// MsgHouseWithdraw wraps the MsgHouseWithdraw message. We need it in order not to have double interface registration conflicts. +message MsgHouseWithdraw { + sge.house.MsgWithdraw msg = 1; +} + +// MsgHouseWithdrawResponse wraps the MsgHouseWithdrawResponse message. We need it in order not to have double interface registration conflicts. +message MsgHouseWithdrawResponse { + sge.house.MsgWithdrawResponse response = 1; } \ No newline at end of file diff --git a/x/subaccount/keeper/bet.go b/x/subaccount/keeper/msg_server_bet.go similarity index 100% rename from x/subaccount/keeper/bet.go rename to x/subaccount/keeper/msg_server_bet.go diff --git a/x/subaccount/keeper/bet_test.go b/x/subaccount/keeper/msg_server_bet_test.go similarity index 100% rename from x/subaccount/keeper/bet_test.go rename to x/subaccount/keeper/msg_server_bet_test.go diff --git a/x/subaccount/keeper/msg_server_house.go b/x/subaccount/keeper/msg_server_house.go new file mode 100644 index 00000000..4651e9c2 --- /dev/null +++ b/x/subaccount/keeper/msg_server_house.go @@ -0,0 +1,17 @@ +package keeper + +import ( + "context" + + "github.com/sge-network/sge/x/subaccount/types" +) + +func (m msgServer) HouseDeposit(ctx context.Context, deposit *types.MsgHouseDeposit) (*types.MsgHouseDepositResponse, error) { + // TODO implement me + panic("implement me") +} + +func (m msgServer) HouseWithdraw(ctx context.Context, withdraw *types.MsgHouseWithdraw) (*types.MsgHouseWithdrawResponse, error) { + // TODO implement me + panic("implement me") +} diff --git a/x/subaccount/types/tx.pb.go b/x/subaccount/types/tx.pb.go index 7c8d7016..fc6ebfbd 100644 --- a/x/subaccount/types/tx.pb.go +++ b/x/subaccount/types/tx.pb.go @@ -9,6 +9,7 @@ import ( grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" types "github.com/sge-network/sge/x/bet/types" + types1 "github.com/sge-network/sge/x/house/types" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" @@ -403,6 +404,186 @@ func (m *MsgPlaceBetResponse) GetResponse() *types.MsgPlaceBetResponse { return nil } +// MsgHouseDeposit wraps the MsgHouseDeposit message. We need it in order not to have double interface registration conflicts. +type MsgHouseDeposit struct { + Msg *types1.MsgDeposit `protobuf:"bytes,1,opt,name=msg,proto3" json:"msg,omitempty"` +} + +func (m *MsgHouseDeposit) Reset() { *m = MsgHouseDeposit{} } +func (m *MsgHouseDeposit) String() string { return proto.CompactTextString(m) } +func (*MsgHouseDeposit) ProtoMessage() {} +func (*MsgHouseDeposit) Descriptor() ([]byte, []int) { + return fileDescriptor_e042e836d366badb, []int{8} +} +func (m *MsgHouseDeposit) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgHouseDeposit) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgHouseDeposit.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 *MsgHouseDeposit) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgHouseDeposit.Merge(m, src) +} +func (m *MsgHouseDeposit) XXX_Size() int { + return m.Size() +} +func (m *MsgHouseDeposit) XXX_DiscardUnknown() { + xxx_messageInfo_MsgHouseDeposit.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgHouseDeposit proto.InternalMessageInfo + +func (m *MsgHouseDeposit) GetMsg() *types1.MsgDeposit { + if m != nil { + return m.Msg + } + return nil +} + +// MsgHouseDepositResponse wraps the MsgHouseDepositResponse message. We need it in order not to have double interface registration conflicts. +type MsgHouseDepositResponse struct { + Response *types1.MsgDepositResponse `protobuf:"bytes,1,opt,name=response,proto3" json:"response,omitempty"` +} + +func (m *MsgHouseDepositResponse) Reset() { *m = MsgHouseDepositResponse{} } +func (m *MsgHouseDepositResponse) String() string { return proto.CompactTextString(m) } +func (*MsgHouseDepositResponse) ProtoMessage() {} +func (*MsgHouseDepositResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_e042e836d366badb, []int{9} +} +func (m *MsgHouseDepositResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgHouseDepositResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgHouseDepositResponse.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 *MsgHouseDepositResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgHouseDepositResponse.Merge(m, src) +} +func (m *MsgHouseDepositResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgHouseDepositResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgHouseDepositResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgHouseDepositResponse proto.InternalMessageInfo + +func (m *MsgHouseDepositResponse) GetResponse() *types1.MsgDepositResponse { + if m != nil { + return m.Response + } + return nil +} + +// MsgHouseWithdraw wraps the MsgHouseWithdraw message. We need it in order not to have double interface registration conflicts. +type MsgHouseWithdraw struct { + Msg *types1.MsgWithdraw `protobuf:"bytes,1,opt,name=msg,proto3" json:"msg,omitempty"` +} + +func (m *MsgHouseWithdraw) Reset() { *m = MsgHouseWithdraw{} } +func (m *MsgHouseWithdraw) String() string { return proto.CompactTextString(m) } +func (*MsgHouseWithdraw) ProtoMessage() {} +func (*MsgHouseWithdraw) Descriptor() ([]byte, []int) { + return fileDescriptor_e042e836d366badb, []int{10} +} +func (m *MsgHouseWithdraw) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgHouseWithdraw) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgHouseWithdraw.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 *MsgHouseWithdraw) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgHouseWithdraw.Merge(m, src) +} +func (m *MsgHouseWithdraw) XXX_Size() int { + return m.Size() +} +func (m *MsgHouseWithdraw) XXX_DiscardUnknown() { + xxx_messageInfo_MsgHouseWithdraw.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgHouseWithdraw proto.InternalMessageInfo + +func (m *MsgHouseWithdraw) GetMsg() *types1.MsgWithdraw { + if m != nil { + return m.Msg + } + return nil +} + +// MsgHouseWithdrawResponse wraps the MsgHouseWithdrawResponse message. We need it in order not to have double interface registration conflicts. +type MsgHouseWithdrawResponse struct { + Response *types1.MsgWithdrawResponse `protobuf:"bytes,1,opt,name=response,proto3" json:"response,omitempty"` +} + +func (m *MsgHouseWithdrawResponse) Reset() { *m = MsgHouseWithdrawResponse{} } +func (m *MsgHouseWithdrawResponse) String() string { return proto.CompactTextString(m) } +func (*MsgHouseWithdrawResponse) ProtoMessage() {} +func (*MsgHouseWithdrawResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_e042e836d366badb, []int{11} +} +func (m *MsgHouseWithdrawResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgHouseWithdrawResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgHouseWithdrawResponse.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 *MsgHouseWithdrawResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgHouseWithdrawResponse.Merge(m, src) +} +func (m *MsgHouseWithdrawResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgHouseWithdrawResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgHouseWithdrawResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgHouseWithdrawResponse proto.InternalMessageInfo + +func (m *MsgHouseWithdrawResponse) GetResponse() *types1.MsgWithdrawResponse { + if m != nil { + return m.Response + } + return nil +} + func init() { proto.RegisterType((*MsgCreateSubAccount)(nil), "sgenetwork.sge.subaccount.MsgCreateSubAccount") proto.RegisterType((*MsgCreateSubAccountResponse)(nil), "sgenetwork.sge.subaccount.MsgCreateSubAccountResponse") @@ -412,42 +593,53 @@ func init() { proto.RegisterType((*MsgWithdrawUnlockedBalancesResponse)(nil), "sgenetwork.sge.subaccount.MsgWithdrawUnlockedBalancesResponse") proto.RegisterType((*MsgPlaceBet)(nil), "sgenetwork.sge.subaccount.MsgPlaceBet") proto.RegisterType((*MsgPlaceBetResponse)(nil), "sgenetwork.sge.subaccount.MsgPlaceBetResponse") + proto.RegisterType((*MsgHouseDeposit)(nil), "sgenetwork.sge.subaccount.MsgHouseDeposit") + proto.RegisterType((*MsgHouseDepositResponse)(nil), "sgenetwork.sge.subaccount.MsgHouseDepositResponse") + proto.RegisterType((*MsgHouseWithdraw)(nil), "sgenetwork.sge.subaccount.MsgHouseWithdraw") + proto.RegisterType((*MsgHouseWithdrawResponse)(nil), "sgenetwork.sge.subaccount.MsgHouseWithdrawResponse") } func init() { proto.RegisterFile("sge/subaccount/tx.proto", fileDescriptor_e042e836d366badb) } var fileDescriptor_e042e836d366badb = []byte{ - // 470 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x94, 0x41, 0x6b, 0x13, 0x41, - 0x18, 0x86, 0xb3, 0x2e, 0x96, 0xf8, 0x05, 0x6c, 0x5c, 0x41, 0xe3, 0x8a, 0x9b, 0xb2, 0x45, 0x0d, - 0x4a, 0x27, 0x18, 0xd1, 0xa3, 0x68, 0x7a, 0xf0, 0x62, 0x50, 0x57, 0x8b, 0xd8, 0x4b, 0xd8, 0xd9, - 0x7c, 0x4c, 0x4b, 0xd3, 0x9d, 0x65, 0xbf, 0x59, 0x52, 0xfd, 0x15, 0xe2, 0xc1, 0x5f, 0xe1, 0x0f, - 0xf1, 0xd8, 0x8b, 0xe0, 0x51, 0x92, 0x3f, 0x22, 0xd9, 0x4c, 0x26, 0x69, 0xed, 0x6e, 0xa3, 0xd0, - 0xdb, 0xcc, 0xf0, 0xbc, 0xef, 0xbe, 0xef, 0xce, 0xc7, 0xc0, 0x4d, 0x12, 0xd8, 0xa6, 0x8c, 0x87, - 0x51, 0x24, 0xb3, 0x58, 0xb5, 0xd5, 0x11, 0x4b, 0x52, 0xa9, 0xa4, 0x73, 0x8b, 0x04, 0xc6, 0xa8, - 0x46, 0x32, 0x3d, 0x60, 0x24, 0x90, 0x2d, 0x18, 0xb7, 0x79, 0x4a, 0xb3, 0x58, 0xce, 0xb4, 0x6e, - 0x7d, 0x0a, 0x70, 0x5c, 0xb8, 0xf9, 0xdf, 0x2d, 0xb8, 0xde, 0x23, 0xb1, 0x9d, 0x62, 0xa8, 0xf0, - 0x5d, 0xc6, 0x5f, 0xcc, 0x78, 0xe7, 0x06, 0xac, 0x11, 0xc6, 0x03, 0x4c, 0x1b, 0xd6, 0x86, 0xd5, - 0xba, 0x12, 0xe8, 0x9d, 0xf3, 0x00, 0xae, 0x51, 0xc6, 0xfb, 0xda, 0xb6, 0x2f, 0x47, 0x31, 0xa6, - 0x8d, 0x4b, 0x39, 0xb2, 0x4e, 0x46, 0xfe, 0x7a, 0x7a, 0xec, 0xbc, 0x85, 0xf5, 0xa1, 0x8c, 0x0e, - 0x70, 0xd0, 0xe7, 0xe1, 0x30, 0x8c, 0x23, 0xa4, 0x86, 0xbd, 0x61, 0xb7, 0x6a, 0x9d, 0x16, 0x2b, - 0xec, 0xc0, 0x5e, 0xe5, 0x8a, 0xee, 0x4c, 0x10, 0x5c, 0x1d, 0x2e, 0x6f, 0xc9, 0xbf, 0x03, 0xb7, - 0xcf, 0x48, 0x1b, 0x20, 0x25, 0x32, 0x26, 0xf4, 0xbf, 0x59, 0x50, 0xed, 0x91, 0x78, 0x2f, 0x93, - 0x9d, 0xa4, 0xb0, 0x42, 0x13, 0x6a, 0x4b, 0x15, 0x74, 0x78, 0x58, 0x84, 0xbf, 0x88, 0xdc, 0x0e, - 0xd4, 0xe7, 0xb9, 0x4c, 0xd8, 0x27, 0x79, 0x97, 0x0f, 0xfb, 0x6a, 0x6f, 0x90, 0x86, 0xa3, 0x9d, - 0xf8, 0xa4, 0xa4, 0x28, 0xbe, 0x7f, 0x17, 0x36, 0x4b, 0x64, 0xc6, 0xfd, 0x39, 0xd4, 0x7a, 0x24, - 0xde, 0x0c, 0xc3, 0x08, 0xbb, 0xa8, 0x9c, 0x47, 0x60, 0x1f, 0x92, 0xc8, 0xad, 0x6a, 0x9d, 0xe6, - 0xe9, 0x1e, 0x1c, 0x15, 0x5b, 0xa2, 0x83, 0x29, 0xeb, 0xef, 0xe6, 0x93, 0x61, 0xce, 0xb4, 0xb1, - 0xb3, 0x0d, 0xd5, 0x54, 0xaf, 0xb5, 0xdd, 0xfd, 0xf3, 0xec, 0x34, 0x1e, 0x18, 0x61, 0xe7, 0xa7, - 0x0d, 0x76, 0x8f, 0x84, 0xf3, 0x19, 0xea, 0x7f, 0x8d, 0x1e, 0x2b, 0xf9, 0xcb, 0x67, 0x5c, 0xbe, - 0xfb, 0xf4, 0xdf, 0x78, 0x53, 0xe4, 0x23, 0x5c, 0x9e, 0x0d, 0xca, 0x66, 0xb9, 0x41, 0x0e, 0xb9, - 0x0f, 0x57, 0x80, 0x8c, 0xf5, 0x57, 0x0b, 0x1a, 0x85, 0x17, 0x7b, 0x4e, 0xde, 0x22, 0x9d, 0xfb, - 0xec, 0xff, 0x74, 0x26, 0x14, 0x87, 0xaa, 0x19, 0x87, 0x7b, 0xe5, 0x5e, 0x73, 0xce, 0x65, 0xab, - 0x71, 0xf3, 0x6f, 0x74, 0x5f, 0xfe, 0x18, 0x7b, 0xd6, 0xf1, 0xd8, 0xb3, 0x7e, 0x8f, 0x3d, 0xeb, - 0xcb, 0xc4, 0xab, 0x1c, 0x4f, 0xbc, 0xca, 0xaf, 0x89, 0x57, 0xd9, 0xdd, 0x12, 0xfb, 0x6a, 0x2f, - 0xe3, 0x2c, 0x92, 0x87, 0x6d, 0x12, 0xb8, 0xa5, 0x4d, 0xa7, 0xeb, 0xf6, 0xd1, 0x89, 0x87, 0xee, - 0x53, 0x82, 0xc4, 0xd7, 0xf2, 0xe7, 0xe9, 0xf1, 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x2c, 0x38, - 0x80, 0x3e, 0x07, 0x05, 0x00, 0x00, + // 587 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x95, 0xcf, 0x6e, 0x12, 0x51, + 0x14, 0xc6, 0x19, 0x49, 0x1b, 0x3c, 0xa8, 0xe0, 0x35, 0xb1, 0x38, 0xc6, 0x01, 0xa7, 0x51, 0xb1, + 0x4d, 0x87, 0x08, 0xd1, 0xa5, 0x51, 0xda, 0xa6, 0x2e, 0x24, 0x2a, 0xda, 0x18, 0xbb, 0x21, 0x33, + 0xc3, 0xcd, 0x85, 0x94, 0xce, 0x1d, 0xe7, 0xcc, 0x84, 0xea, 0x53, 0x18, 0x17, 0x3e, 0x85, 0x0f, + 0xe0, 0x23, 0xb8, 0xec, 0xd2, 0xa5, 0x81, 0x17, 0x31, 0xf3, 0xef, 0x32, 0x40, 0x07, 0xa8, 0x49, + 0x77, 0x77, 0x6e, 0xbe, 0xef, 0x3b, 0xbf, 0x03, 0xe7, 0xe4, 0xc2, 0x06, 0x32, 0x5a, 0x43, 0xcf, + 0xd0, 0x4d, 0x93, 0x7b, 0x96, 0x5b, 0x73, 0x4f, 0x35, 0xdb, 0xe1, 0x2e, 0x27, 0x77, 0x90, 0x51, + 0x8b, 0xba, 0x43, 0xee, 0x1c, 0x6b, 0xc8, 0xa8, 0x36, 0xd1, 0xc8, 0xe5, 0x19, 0xcf, 0xe4, 0x18, + 0x7a, 0xe5, 0xa2, 0x2f, 0x30, 0xe8, 0x24, 0x4d, 0x26, 0xfe, 0x4d, 0x8f, 0x7b, 0x48, 0xc5, 0x9d, + 0xfa, 0x53, 0x82, 0x5b, 0x2d, 0x64, 0xbb, 0x0e, 0xd5, 0x5d, 0xfa, 0xde, 0x33, 0x5e, 0x86, 0x19, + 0xe4, 0x36, 0xac, 0x23, 0xb5, 0xba, 0xd4, 0x29, 0x49, 0x15, 0xa9, 0x7a, 0xb5, 0x1d, 0x7d, 0x91, + 0x2d, 0xb8, 0x89, 0x9e, 0xd1, 0x89, 0x4a, 0x75, 0xf8, 0xd0, 0xa2, 0x4e, 0xe9, 0x4a, 0x20, 0x29, + 0xa0, 0xb0, 0xbf, 0xf1, 0xaf, 0xc9, 0x3b, 0x28, 0x0c, 0xb8, 0x79, 0x4c, 0xbb, 0x1d, 0x43, 0x1f, + 0xe8, 0x96, 0x49, 0xb1, 0x94, 0xad, 0x64, 0xab, 0xf9, 0x7a, 0x55, 0x4b, 0xed, 0x4b, 0x7b, 0x1d, + 0x38, 0x9a, 0xa1, 0xa1, 0x7d, 0x63, 0x90, 0xfc, 0x44, 0xf5, 0x1e, 0xdc, 0x3d, 0x87, 0xb6, 0x4d, + 0xd1, 0xe6, 0x16, 0x52, 0xf5, 0x87, 0x04, 0xb9, 0x16, 0xb2, 0x0f, 0xdc, 0x3e, 0xb4, 0x53, 0x5b, + 0x28, 0x43, 0x3e, 0xd1, 0x42, 0x04, 0x0f, 0x13, 0xf8, 0xcb, 0xe0, 0x26, 0x50, 0x8c, 0xb9, 0x04, + 0xec, 0xd3, 0xa0, 0x97, 0x8f, 0x7d, 0xb7, 0xd7, 0x75, 0xf4, 0xe1, 0xa1, 0x35, 0x6d, 0x49, 0xc3, + 0x57, 0x1f, 0xc0, 0xe6, 0x02, 0x9b, 0x48, 0x7f, 0x01, 0xf9, 0x16, 0xb2, 0xb7, 0x03, 0xdd, 0xa4, + 0x4d, 0xea, 0x92, 0x27, 0x90, 0x3d, 0x41, 0x16, 0x44, 0xe5, 0xeb, 0xe5, 0xd9, 0x3e, 0x0c, 0xea, + 0x6a, 0x09, 0x75, 0xdb, 0xd7, 0xaa, 0x47, 0xc1, 0x64, 0x88, 0xbb, 0x28, 0x98, 0xec, 0x42, 0xce, + 0x89, 0xce, 0x51, 0xdc, 0xa3, 0x65, 0x71, 0x91, 0xbc, 0x2d, 0x8c, 0xea, 0x3e, 0x14, 0x5a, 0xc8, + 0x5e, 0xf9, 0xb3, 0xb8, 0x47, 0x6d, 0x8e, 0x7d, 0x97, 0xd4, 0x93, 0x84, 0x95, 0xd9, 0xc8, 0x60, + 0x6c, 0xfd, 0xd0, 0x48, 0x1e, 0x22, 0x76, 0x60, 0x63, 0x26, 0x46, 0x60, 0xee, 0xcd, 0x61, 0x56, + 0x97, 0x66, 0xce, 0x73, 0x1e, 0x04, 0xff, 0x5b, 0x50, 0x20, 0xfe, 0xc5, 0x49, 0x23, 0x09, 0x7a, + 0x3f, 0x35, 0x34, 0xd6, 0x87, 0xa4, 0x3a, 0x94, 0x66, 0x83, 0x04, 0xea, 0xfe, 0x1c, 0xea, 0xe3, + 0xe5, 0xa9, 0x73, 0xac, 0xf5, 0x5f, 0x6b, 0x90, 0x6d, 0x21, 0x23, 0x5f, 0xa1, 0x38, 0xb7, 0xce, + 0xda, 0x82, 0xc9, 0x3d, 0x67, 0xa1, 0xe4, 0x67, 0x17, 0xd3, 0x8b, 0x56, 0x3e, 0xc1, 0x5a, 0xb8, + 0x7c, 0x9b, 0x8b, 0x03, 0x02, 0x91, 0xbc, 0xbd, 0x82, 0x48, 0x44, 0x7f, 0x97, 0xa0, 0x94, 0xba, + 0x2c, 0x4b, 0x78, 0xd3, 0x7c, 0xf2, 0xf3, 0xff, 0xf3, 0x09, 0x28, 0x03, 0x72, 0x62, 0xc5, 0x1e, + 0x2e, 0xce, 0x8a, 0x75, 0xb2, 0xb6, 0x9a, 0x4e, 0xd4, 0xb0, 0xe0, 0xda, 0xd4, 0xa2, 0x6c, 0x2d, + 0xf6, 0x27, 0xb5, 0x72, 0x7d, 0x75, 0xad, 0xa8, 0xf7, 0x19, 0xae, 0x4f, 0x0f, 0xfc, 0xf6, 0x0a, + 0x21, 0xb1, 0x58, 0x6e, 0x5c, 0x40, 0x1c, 0x97, 0x6c, 0x1e, 0xfc, 0x1e, 0x29, 0xd2, 0xd9, 0x48, + 0x91, 0xfe, 0x8e, 0x14, 0xe9, 0xdb, 0x58, 0xc9, 0x9c, 0x8d, 0x95, 0xcc, 0x9f, 0xb1, 0x92, 0x39, + 0xda, 0x61, 0x7d, 0xb7, 0xe7, 0x19, 0x9a, 0xc9, 0x4f, 0x6a, 0xc8, 0xe8, 0x4e, 0x94, 0xec, 0x9f, + 0x6b, 0xa7, 0x53, 0x6f, 0xe6, 0x17, 0x9b, 0xa2, 0xb1, 0x1e, 0xbc, 0x6a, 0x8d, 0x7f, 0x01, 0x00, + 0x00, 0xff, 0xff, 0xb9, 0x2f, 0x73, 0x07, 0x52, 0x07, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -470,6 +662,10 @@ type MsgClient interface { WithdrawUnlockedBalances(ctx context.Context, in *MsgWithdrawUnlockedBalances, opts ...grpc.CallOption) (*MsgWithdrawUnlockedBalancesResponse, error) // PlaceBet defines a method for placing a bet using a subaccount. PlaceBet(ctx context.Context, in *MsgPlaceBet, opts ...grpc.CallOption) (*MsgPlaceBetResponse, error) + // HouseDeposit defines a method for depositing funds to provide liquidity to a market. + HouseDeposit(ctx context.Context, in *MsgHouseDeposit, opts ...grpc.CallOption) (*MsgHouseDepositResponse, error) + // HouseWithdraw defines a method for withdrawing funds from a market. + HouseWithdraw(ctx context.Context, in *MsgHouseWithdraw, opts ...grpc.CallOption) (*MsgHouseWithdrawResponse, error) } type msgClient struct { @@ -516,6 +712,24 @@ func (c *msgClient) PlaceBet(ctx context.Context, in *MsgPlaceBet, opts ...grpc. return out, nil } +func (c *msgClient) HouseDeposit(ctx context.Context, in *MsgHouseDeposit, opts ...grpc.CallOption) (*MsgHouseDepositResponse, error) { + out := new(MsgHouseDepositResponse) + err := c.cc.Invoke(ctx, "/sgenetwork.sge.subaccount.Msg/HouseDeposit", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) HouseWithdraw(ctx context.Context, in *MsgHouseWithdraw, opts ...grpc.CallOption) (*MsgHouseWithdrawResponse, error) { + out := new(MsgHouseWithdrawResponse) + err := c.cc.Invoke(ctx, "/sgenetwork.sge.subaccount.Msg/HouseWithdraw", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { // CreateSubAccount defines a method for creating a subaccount. @@ -526,6 +740,10 @@ type MsgServer interface { WithdrawUnlockedBalances(context.Context, *MsgWithdrawUnlockedBalances) (*MsgWithdrawUnlockedBalancesResponse, error) // PlaceBet defines a method for placing a bet using a subaccount. PlaceBet(context.Context, *MsgPlaceBet) (*MsgPlaceBetResponse, error) + // HouseDeposit defines a method for depositing funds to provide liquidity to a market. + HouseDeposit(context.Context, *MsgHouseDeposit) (*MsgHouseDepositResponse, error) + // HouseWithdraw defines a method for withdrawing funds from a market. + HouseWithdraw(context.Context, *MsgHouseWithdraw) (*MsgHouseWithdrawResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -544,6 +762,12 @@ func (*UnimplementedMsgServer) WithdrawUnlockedBalances(ctx context.Context, req func (*UnimplementedMsgServer) PlaceBet(ctx context.Context, req *MsgPlaceBet) (*MsgPlaceBetResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method PlaceBet not implemented") } +func (*UnimplementedMsgServer) HouseDeposit(ctx context.Context, req *MsgHouseDeposit) (*MsgHouseDepositResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method HouseDeposit not implemented") +} +func (*UnimplementedMsgServer) HouseWithdraw(ctx context.Context, req *MsgHouseWithdraw) (*MsgHouseWithdrawResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method HouseWithdraw not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -621,6 +845,42 @@ func _Msg_PlaceBet_Handler(srv interface{}, ctx context.Context, dec func(interf return interceptor(ctx, in, info, handler) } +func _Msg_HouseDeposit_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgHouseDeposit) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).HouseDeposit(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sgenetwork.sge.subaccount.Msg/HouseDeposit", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).HouseDeposit(ctx, req.(*MsgHouseDeposit)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_HouseWithdraw_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgHouseWithdraw) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).HouseWithdraw(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sgenetwork.sge.subaccount.Msg/HouseWithdraw", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).HouseWithdraw(ctx, req.(*MsgHouseWithdraw)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "sgenetwork.sge.subaccount.Msg", HandlerType: (*MsgServer)(nil), @@ -641,6 +901,14 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "PlaceBet", Handler: _Msg_PlaceBet_Handler, }, + { + MethodName: "HouseDeposit", + Handler: _Msg_HouseDeposit_Handler, + }, + { + MethodName: "HouseWithdraw", + Handler: _Msg_HouseWithdraw_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "sge/subaccount/tx.proto", @@ -917,75 +1185,215 @@ func (m *MsgPlaceBetResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func encodeVarintTx(dAtA []byte, offset int, v uint64) int { - offset -= sovTx(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ +func (m *MsgHouseDeposit) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err } - dAtA[offset] = uint8(v) - return base + return dAtA[:n], nil } -func (m *MsgCreateSubAccount) Size() (n int) { - if m == nil { - return 0 - } + +func (m *MsgHouseDeposit) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgHouseDeposit) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i var l int _ = l - l = len(m.Sender) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - l = len(m.SubAccountOwner) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - if len(m.LockedBalances) > 0 { - for _, e := range m.LockedBalances { - l = e.Size() - n += 1 + l + sovTx(uint64(l)) + if m.Msg != nil { + { + size, err := m.Msg.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0xa } - return n + return len(dAtA) - i, nil } -func (m *MsgCreateSubAccountResponse) Size() (n int) { - if m == nil { - return 0 +func (m *MsgHouseDepositResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err } - var l int - _ = l - return n + return dAtA[:n], nil } -func (m *MsgTopUp) Size() (n int) { - if m == nil { - return 0 - } +func (m *MsgHouseDepositResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgHouseDepositResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i var l int _ = l - l = len(m.Sender) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - l = len(m.SubAccount) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - if len(m.LockedBalances) > 0 { - for _, e := range m.LockedBalances { - l = e.Size() - n += 1 + l + sovTx(uint64(l)) + if m.Response != nil { + { + size, err := m.Response.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0xa } - return n + return len(dAtA) - i, nil } -func (m *MsgTopUpResponse) Size() (n int) { - if m == nil { - return 0 +func (m *MsgHouseWithdraw) 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 *MsgHouseWithdraw) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgHouseWithdraw) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Msg != nil { + { + size, err := m.Msg.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgHouseWithdrawResponse) 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 *MsgHouseWithdrawResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgHouseWithdrawResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Response != nil { + { + size, err := m.Response.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgCreateSubAccount) 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.SubAccountOwner) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if len(m.LockedBalances) > 0 { + for _, e := range m.LockedBalances { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } + } + return n +} + +func (m *MsgCreateSubAccountResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgTopUp) 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.SubAccount) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if len(m.LockedBalances) > 0 { + for _, e := range m.LockedBalances { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } + } + return n +} + +func (m *MsgTopUpResponse) Size() (n int) { + if m == nil { + return 0 } var l int _ = l @@ -1040,6 +1448,58 @@ func (m *MsgPlaceBetResponse) Size() (n int) { return n } +func (m *MsgHouseDeposit) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Msg != nil { + l = m.Msg.Size() + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgHouseDepositResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Response != nil { + l = m.Response.Size() + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgHouseWithdraw) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Msg != nil { + l = m.Msg.Size() + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgHouseWithdrawResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Response != nil { + l = m.Response.Size() + n += 1 + l + sovTx(uint64(l)) + } + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -1069,10 +1529,208 @@ func (m *MsgCreateSubAccount) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgCreateSubAccount: wiretype end group for non-group") + return fmt.Errorf("proto: MsgCreateSubAccount: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreateSubAccount: 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 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.Sender = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SubAccountOwner", 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.SubAccountOwner = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field LockedBalances", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.LockedBalances = append(m.LockedBalances, &LockedBalance{}) + if err := m.LockedBalances[len(m.LockedBalances)-1].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 *MsgCreateSubAccountResponse) 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: MsgCreateSubAccountResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreateSubAccountResponse: 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 (m *MsgTopUp) 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: MsgTopUp: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgCreateSubAccount: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgTopUp: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -1109,7 +1767,7 @@ func (m *MsgCreateSubAccount) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SubAccountOwner", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field SubAccount", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1137,7 +1795,7 @@ func (m *MsgCreateSubAccount) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.SubAccountOwner = string(dAtA[iNdEx:postIndex]) + m.SubAccount = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 3: if wireType != 2 { @@ -1194,7 +1852,7 @@ func (m *MsgCreateSubAccount) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgCreateSubAccountResponse) Unmarshal(dAtA []byte) error { +func (m *MsgTopUpResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1217,10 +1875,10 @@ func (m *MsgCreateSubAccountResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgCreateSubAccountResponse: wiretype end group for non-group") + return fmt.Errorf("proto: MsgTopUpResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgCreateSubAccountResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgTopUpResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { default: @@ -1244,7 +1902,7 @@ func (m *MsgCreateSubAccountResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgTopUp) Unmarshal(dAtA []byte) error { +func (m *MsgWithdrawUnlockedBalances) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1267,10 +1925,10 @@ func (m *MsgTopUp) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgTopUp: wiretype end group for non-group") + return fmt.Errorf("proto: MsgWithdrawUnlockedBalances: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgTopUp: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgWithdrawUnlockedBalances: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -1305,41 +1963,109 @@ func (m *MsgTopUp) Unmarshal(dAtA []byte) error { } m.Sender = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SubAccount", 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 - } + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err } - intStringLen := int(stringLen) - if intStringLen < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthTx } - postIndex := iNdEx + intStringLen - if postIndex < 0 { + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgWithdrawUnlockedBalancesResponse) 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: MsgWithdrawUnlockedBalancesResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgWithdrawUnlockedBalancesResponse: 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 postIndex > l { + if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF } - m.SubAccount = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgPlaceBet) 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: MsgPlaceBet: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgPlaceBet: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field LockedBalances", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Msg", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -1366,8 +2092,10 @@ func (m *MsgTopUp) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.LockedBalances = append(m.LockedBalances, &LockedBalance{}) - if err := m.LockedBalances[len(m.LockedBalances)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if m.Msg == nil { + m.Msg = &types.MsgPlaceBet{} + } + if err := m.Msg.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -1392,7 +2120,7 @@ func (m *MsgTopUp) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgTopUpResponse) Unmarshal(dAtA []byte) error { +func (m *MsgPlaceBetResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1415,12 +2143,48 @@ func (m *MsgTopUpResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgTopUpResponse: wiretype end group for non-group") + return fmt.Errorf("proto: MsgPlaceBetResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgTopUpResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgPlaceBetResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Response", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Response == nil { + m.Response = &types.MsgPlaceBetResponse{} + } + if err := m.Response.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) @@ -1442,7 +2206,7 @@ func (m *MsgTopUpResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgWithdrawUnlockedBalances) Unmarshal(dAtA []byte) error { +func (m *MsgHouseDeposit) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1465,17 +2229,17 @@ func (m *MsgWithdrawUnlockedBalances) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgWithdrawUnlockedBalances: wiretype end group for non-group") + return fmt.Errorf("proto: MsgHouseDeposit: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgWithdrawUnlockedBalances: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgHouseDeposit: 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) + return fmt.Errorf("proto: wrong wireType = %d for field Msg", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -1485,23 +2249,27 @@ func (m *MsgWithdrawUnlockedBalances) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthTx } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF } - m.Sender = string(dAtA[iNdEx:postIndex]) + if m.Msg == nil { + m.Msg = &types1.MsgDeposit{} + } + if err := m.Msg.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex default: iNdEx = preIndex @@ -1524,7 +2292,7 @@ func (m *MsgWithdrawUnlockedBalances) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgWithdrawUnlockedBalancesResponse) Unmarshal(dAtA []byte) error { +func (m *MsgHouseDepositResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1547,12 +2315,48 @@ func (m *MsgWithdrawUnlockedBalancesResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgWithdrawUnlockedBalancesResponse: wiretype end group for non-group") + return fmt.Errorf("proto: MsgHouseDepositResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgWithdrawUnlockedBalancesResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgHouseDepositResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Response", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Response == nil { + m.Response = &types1.MsgDepositResponse{} + } + if err := m.Response.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) @@ -1574,7 +2378,7 @@ func (m *MsgWithdrawUnlockedBalancesResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgPlaceBet) Unmarshal(dAtA []byte) error { +func (m *MsgHouseWithdraw) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1597,10 +2401,10 @@ func (m *MsgPlaceBet) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgPlaceBet: wiretype end group for non-group") + return fmt.Errorf("proto: MsgHouseWithdraw: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgPlaceBet: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgHouseWithdraw: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -1633,7 +2437,7 @@ func (m *MsgPlaceBet) Unmarshal(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Msg == nil { - m.Msg = &types.MsgPlaceBet{} + m.Msg = &types1.MsgWithdraw{} } if err := m.Msg.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err @@ -1660,7 +2464,7 @@ func (m *MsgPlaceBet) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgPlaceBetResponse) Unmarshal(dAtA []byte) error { +func (m *MsgHouseWithdrawResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1683,10 +2487,10 @@ func (m *MsgPlaceBetResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgPlaceBetResponse: wiretype end group for non-group") + return fmt.Errorf("proto: MsgHouseWithdrawResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgPlaceBetResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgHouseWithdrawResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -1719,7 +2523,7 @@ func (m *MsgPlaceBetResponse) Unmarshal(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Response == nil { - m.Response = &types.MsgPlaceBetResponse{} + m.Response = &types1.MsgWithdrawResponse{} } if err := m.Response.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err From d76d138b3c8b0910d3579cf4db3d1d8a9cfb2cc3 Mon Sep 17 00:00:00 2001 From: unknown unknown Date: Mon, 24 Jul 2023 17:04:39 +0200 Subject: [PATCH 11/20] implement house deposit --- x/subaccount/keeper/keeper.go | 11 ++++- x/subaccount/keeper/msg_server_house.go | 59 +++++++++++++++++++++++-- 2 files changed, 65 insertions(+), 5 deletions(-) diff --git a/x/subaccount/keeper/keeper.go b/x/subaccount/keeper/keeper.go index bf863b47..0b34203e 100644 --- a/x/subaccount/keeper/keeper.go +++ b/x/subaccount/keeper/keeper.go @@ -5,6 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" bettypes "github.com/sge-network/sge/x/bet/types" + housetypes "github.com/sge-network/sge/x/house/types" orderbookmodulekeeper "github.com/sge-network/sge/x/orderbook/keeper" "github.com/sge-network/sge/x/subaccount/types" ) @@ -18,6 +19,11 @@ type BankKeeper interface { SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error } +type HouseKeeper interface { + GetParams(ctx sdk.Context) housetypes.Params + Deposit(ctx sdk.Context, creator, depositor, marketUID string, amount sdk.Int) (participationIndex uint64, err error) +} + type OrderBookKeeper interface { RegisterHook(hooks orderbookmodulekeeper.Hook) } @@ -28,8 +34,9 @@ type Keeper struct { paramstore paramtypes.Subspace bankKeeper BankKeeper - ovmKeeper bettypes.OVMKeeper - betKeeper BetKeeper + ovmKeeper bettypes.OVMKeeper + betKeeper BetKeeper + houseKeeper HouseKeeper } func NewKeeper(cdc codec.Codec, storeKey sdk.StoreKey, ps paramtypes.Subspace, bankKeeper BankKeeper, ovmKeeper bettypes.OVMKeeper, betKeeper BetKeeper, obKeeper OrderBookKeeper) Keeper { diff --git a/x/subaccount/keeper/msg_server_house.go b/x/subaccount/keeper/msg_server_house.go index 4651e9c2..b6f29c97 100644 --- a/x/subaccount/keeper/msg_server_house.go +++ b/x/subaccount/keeper/msg_server_house.go @@ -3,12 +3,65 @@ package keeper import ( "context" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + housetypes "github.com/sge-network/sge/x/house/types" "github.com/sge-network/sge/x/subaccount/types" ) -func (m msgServer) HouseDeposit(ctx context.Context, deposit *types.MsgHouseDeposit) (*types.MsgHouseDepositResponse, error) { - // TODO implement me - panic("implement me") +func (m msgServer) HouseDeposit(goCtx context.Context, msg *types.MsgHouseDeposit) (*types.MsgHouseDepositResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // check if subaccount exists + subAccountAddr, exists := m.keeper.GetSubAccountByOwner(ctx, sdk.MustAccAddressFromBech32(msg.Msg.Creator)) + if !exists { + return nil, types.ErrSubaccountDoesNotExist + } + + if err := m.houseDeposit(ctx, msg.Msg); err != nil { + return nil, sdkerrors.Wrap(err, "failed to deposit") + } + + // send house deposit from subaccount on behalf of the owner + participationIndex, err := m.keeper.houseKeeper.Deposit( + ctx, + subAccountAddr.String(), + subAccountAddr.String(), + msg.Msg.MarketUID, + msg.Msg.Amount, + ) + if err != nil { + return nil, sdkerrors.Wrap(err, "failed to deposit") + } + msg.Msg.EmitEvent(&ctx, subAccountAddr.String(), participationIndex) + return &types.MsgHouseDepositResponse{ + Response: &housetypes.MsgDepositResponse{ + MarketUID: msg.Msg.MarketUID, + ParticipationIndex: participationIndex, + }, + }, nil +} + +// TODO: This is a copy of the Deposit function from x/house/keeper/msg_server_deposit.go +func (m msgServer) houseDeposit(ctx sdk.Context, msg *housetypes.MsgDeposit) error { + + params := m.keeper.houseKeeper.GetParams(ctx) + if err := msg.ValidateSanity(ctx, ¶ms); err != nil { + return sdkerrors.Wrap(err, "invalid deposit") + } + + var payload housetypes.DepositTicketPayload + if err := m.keeper.ovmKeeper.VerifyTicketUnmarshal(sdk.WrapSDKContext(ctx), msg.Ticket, &payload); err != nil { + return sdkerrors.Wrapf(housetypes.ErrInTicketVerification, "%s", err) + } + + depositorAddr := msg.Creator + + if err := payload.Validate(depositorAddr); err != nil { + return sdkerrors.Wrapf(housetypes.ErrInTicketPayloadValidation, "%s", err) + } + + return nil } func (m msgServer) HouseWithdraw(ctx context.Context, withdraw *types.MsgHouseWithdraw) (*types.MsgHouseWithdrawResponse, error) { From 009dac2181324f25e78e38a671a15435088671b8 Mon Sep 17 00:00:00 2001 From: unknown unknown Date: Mon, 24 Jul 2023 17:20:11 +0200 Subject: [PATCH 12/20] add more hooks logic --- x/orderbook/keeper/hooks.go | 3 + x/orderbook/keeper/orderbook_settle.go | 31 ++++++++++ x/subaccount/keeper/keeper.go | 86 ++++++++++++++++++++++++++ 3 files changed, 120 insertions(+) diff --git a/x/orderbook/keeper/hooks.go b/x/orderbook/keeper/hooks.go index a844370b..2a1e9805 100644 --- a/x/orderbook/keeper/hooks.go +++ b/x/orderbook/keeper/hooks.go @@ -6,6 +6,9 @@ type Hook interface { AfterBettorWin(ctx sdk.Context, bettor sdk.AccAddress, originalAmount, profit sdk.Int) AfterBettorLoss(ctx sdk.Context, bettor sdk.AccAddress, originalAmount sdk.Int) AfterBettorRefund(ctx sdk.Context, bettor sdk.AccAddress, originalAmount, fee sdk.Int) + AfterHouseWin(ctx sdk.Context, house sdk.AccAddress, originalAmount, profit sdk.Int, fee *sdk.Int) + AfterHouseLoss(ctx sdk.Context, house sdk.AccAddress, originalAmount sdk.Int, lostAmt sdk.Int, fee *sdk.Int) + AfterHouseRefund(ctx sdk.Context, house sdk.AccAddress, originalAmount, fee sdk.Int) } func (k *Keeper) RegisterHook(hook Hook) { diff --git a/x/orderbook/keeper/orderbook_settle.go b/x/orderbook/keeper/orderbook_settle.go index 6e384c84..ff483833 100644 --- a/x/orderbook/keeper/orderbook_settle.go +++ b/x/orderbook/keeper/orderbook_settle.go @@ -108,6 +108,13 @@ func (k Keeper) settleParticipation( refundHouseDepositFeeToDepositor := false + var ( + profit sdk.Int + originalAmount sdk.Int + feeRefund *sdk.Int + cancelled bool + ) + switch market.Status { case markettypes.MarketStatus_MARKET_STATUS_RESULT_DECLARED: depositPlusProfit := bp.Liquidity.Add(bp.ActualProfit) @@ -118,6 +125,10 @@ func (k Keeper) settleParticipation( if bp.NotParticipatedInBetFulfillment() { refundHouseDepositFeeToDepositor = true } + // prepare hook variables. + profit = bp.ActualProfit + originalAmount = bp.Liquidity + case markettypes.MarketStatus_MARKET_STATUS_CANCELED, markettypes.MarketStatus_MARKET_STATUS_ABORTED: // refund participant's account from orderbook liquidity pool. @@ -125,6 +136,9 @@ func (k Keeper) settleParticipation( return err } refundHouseDepositFeeToDepositor = true + profit = sdk.ZeroInt() + originalAmount = bp.Liquidity + cancelled = true default: return sdkerrors.Wrapf( types.ErrUnknownMarketStatus, @@ -139,6 +153,7 @@ func (k Keeper) settleParticipation( if err := k.refund(housetypes.HouseFeeCollectorFunder{}, ctx, depositorAddress, bp.Fee); err != nil { return err } + feeRefund = &bp.Fee } else { // refund participant's account from house fee collector. if err := k.refund(housetypes.HouseFeeCollectorFunder{}, ctx, sdk.MustAccAddressFromBech32(market.Creator), bp.Fee); err != nil { @@ -148,5 +163,21 @@ func (k Keeper) settleParticipation( bp.IsSettled = true k.SetOrderBookParticipation(ctx, bp) + + // call hooks + switch { + case cancelled: + for _, h := range k.hooks { + h.AfterHouseRefund(ctx, depositorAddress, originalAmount, *feeRefund) + } + case profit.IsNegative(): + for _, h := range k.hooks { + h.AfterHouseLoss(ctx, depositorAddress, originalAmount, profit.Abs(), feeRefund) + } + case profit.IsPositive(), profit.IsZero(): + for _, h := range k.hooks { + h.AfterHouseWin(ctx, depositorAddress, originalAmount, profit, feeRefund) + } + } return nil } diff --git a/x/subaccount/keeper/keeper.go b/x/subaccount/keeper/keeper.go index 0b34203e..79944458 100644 --- a/x/subaccount/keeper/keeper.go +++ b/x/subaccount/keeper/keeper.go @@ -39,6 +39,92 @@ type Keeper struct { houseKeeper HouseKeeper } +func (k Keeper) AfterHouseWin(ctx sdk.Context, house sdk.AccAddress, originalAmount, profit sdk.Int, fee *sdk.Int) { + // update balance + balance, exists := k.GetBalance(ctx, house) + if !exists { + return + } + + err := balance.Unspend(originalAmount) + if err != nil { + panic(err) + } + if fee != nil { + err = balance.Unspend(*fee) + if err != nil { + panic(err) + } + } + k.SetBalance(ctx, house, balance) + + // send profits + subAccountOwner, exists := k.GetSubAccountOwner(ctx, house) + if !exists { + panic("data corruption: subaccount owner not found") + } + err = k.bankKeeper.SendCoins(ctx, house, subAccountOwner, sdk.NewCoins(sdk.NewCoin(k.GetParams(ctx).LockedBalanceDenom, profit))) + if err != nil { + panic(err) + } +} + +func (k Keeper) AfterHouseLoss(ctx sdk.Context, house sdk.AccAddress, originalAmount sdk.Int, lostAmt sdk.Int, fee *sdk.Int) { + balance, exists := k.GetBalance(ctx, house) + if !exists { + return + } + + err := balance.Unspend(originalAmount) + if err != nil { + panic(err) + } + err = balance.AddLoss(lostAmt) + if err != nil { + panic(err) + } + if fee != nil { + err = balance.Unspend(*fee) + if err != nil { + panic(err) + } + } + + k.SetBalance(ctx, house, balance) + + // send profits + profits := originalAmount.Sub(lostAmt) + if !profits.IsPositive() { + return + } + subAccountOwner, exists := k.GetSubAccountOwner(ctx, house) + if !exists { + panic("data corruption: subaccount owner not found") + } + err = k.bankKeeper.SendCoins(ctx, house, subAccountOwner, sdk.NewCoins(sdk.NewCoin(k.GetParams(ctx).LockedBalanceDenom, profits))) + if err != nil { + panic(err) + } +} + +func (k Keeper) AfterHouseRefund(ctx sdk.Context, house sdk.AccAddress, originalAmount, fee sdk.Int) { + balance, exists := k.GetBalance(ctx, house) + if !exists { + return + } + + err := balance.Unspend(originalAmount) + if err != nil { + panic(err) + } + err = balance.Unspend(fee) + if err != nil { + panic(err) + } + + k.SetBalance(ctx, house, balance) +} + func NewKeeper(cdc codec.Codec, storeKey sdk.StoreKey, ps paramtypes.Subspace, bankKeeper BankKeeper, ovmKeeper bettypes.OVMKeeper, betKeeper BetKeeper, obKeeper OrderBookKeeper) Keeper { // set KeyTable if it is not already set if !ps.HasKeyTable() { From 531bdc7868b28fa4f9da7ea04f532a6a6f2b538b Mon Sep 17 00:00:00 2001 From: unknown unknown Date: Tue, 25 Jul 2023 12:05:15 +0200 Subject: [PATCH 13/20] all tests pass --- app/keepers/keepers.go | 1 + x/subaccount/keeper/keeper.go | 101 +---------- x/subaccount/keeper/msg_server_bet_test.go | 40 +++-- x/subaccount/keeper/msg_server_house.go | 21 +++ x/subaccount/keeper/msg_server_house_test.go | 175 +++++++++++++++++++ x/subaccount/keeper/orderbook_hooks.go | 78 +++++++++ x/subaccount/types/msg.go | 26 +++ 7 files changed, 330 insertions(+), 112 deletions(-) create mode 100644 x/subaccount/keeper/msg_server_house_test.go diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index d4706110..073a6bb2 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -439,6 +439,7 @@ func NewAppKeeper( appKeepers.OVMKeeper, appKeepers.BetKeeper, appKeepers.OrderbookKeeper, + appKeepers.HouseKeeper, ) appKeepers.SubaccountModule = subaccount.NewAppModule(appKeepers.SubaccountKeeper) diff --git a/x/subaccount/keeper/keeper.go b/x/subaccount/keeper/keeper.go index 79944458..238079ef 100644 --- a/x/subaccount/keeper/keeper.go +++ b/x/subaccount/keeper/keeper.go @@ -39,105 +39,20 @@ type Keeper struct { houseKeeper HouseKeeper } -func (k Keeper) AfterHouseWin(ctx sdk.Context, house sdk.AccAddress, originalAmount, profit sdk.Int, fee *sdk.Int) { - // update balance - balance, exists := k.GetBalance(ctx, house) - if !exists { - return - } - - err := balance.Unspend(originalAmount) - if err != nil { - panic(err) - } - if fee != nil { - err = balance.Unspend(*fee) - if err != nil { - panic(err) - } - } - k.SetBalance(ctx, house, balance) - - // send profits - subAccountOwner, exists := k.GetSubAccountOwner(ctx, house) - if !exists { - panic("data corruption: subaccount owner not found") - } - err = k.bankKeeper.SendCoins(ctx, house, subAccountOwner, sdk.NewCoins(sdk.NewCoin(k.GetParams(ctx).LockedBalanceDenom, profit))) - if err != nil { - panic(err) - } -} - -func (k Keeper) AfterHouseLoss(ctx sdk.Context, house sdk.AccAddress, originalAmount sdk.Int, lostAmt sdk.Int, fee *sdk.Int) { - balance, exists := k.GetBalance(ctx, house) - if !exists { - return - } - - err := balance.Unspend(originalAmount) - if err != nil { - panic(err) - } - err = balance.AddLoss(lostAmt) - if err != nil { - panic(err) - } - if fee != nil { - err = balance.Unspend(*fee) - if err != nil { - panic(err) - } - } - - k.SetBalance(ctx, house, balance) - - // send profits - profits := originalAmount.Sub(lostAmt) - if !profits.IsPositive() { - return - } - subAccountOwner, exists := k.GetSubAccountOwner(ctx, house) - if !exists { - panic("data corruption: subaccount owner not found") - } - err = k.bankKeeper.SendCoins(ctx, house, subAccountOwner, sdk.NewCoins(sdk.NewCoin(k.GetParams(ctx).LockedBalanceDenom, profits))) - if err != nil { - panic(err) - } -} - -func (k Keeper) AfterHouseRefund(ctx sdk.Context, house sdk.AccAddress, originalAmount, fee sdk.Int) { - balance, exists := k.GetBalance(ctx, house) - if !exists { - return - } - - err := balance.Unspend(originalAmount) - if err != nil { - panic(err) - } - err = balance.Unspend(fee) - if err != nil { - panic(err) - } - - k.SetBalance(ctx, house, balance) -} - -func NewKeeper(cdc codec.Codec, storeKey sdk.StoreKey, ps paramtypes.Subspace, bankKeeper BankKeeper, ovmKeeper bettypes.OVMKeeper, betKeeper BetKeeper, obKeeper OrderBookKeeper) Keeper { +func NewKeeper(cdc codec.Codec, storeKey sdk.StoreKey, ps paramtypes.Subspace, bankKeeper BankKeeper, ovmKeeper bettypes.OVMKeeper, betKeeper BetKeeper, obKeeper OrderBookKeeper, hk HouseKeeper) Keeper { // set KeyTable if it is not already set if !ps.HasKeyTable() { ps = ps.WithKeyTable(types.ParamKeyTable()) } k := Keeper{ - cdc: cdc, - storeKey: storeKey, - paramstore: ps, - bankKeeper: bankKeeper, - ovmKeeper: ovmKeeper, - betKeeper: betKeeper, + cdc: cdc, + storeKey: storeKey, + paramstore: ps, + bankKeeper: bankKeeper, + ovmKeeper: ovmKeeper, + betKeeper: betKeeper, + houseKeeper: hk, } obKeeper.RegisterHook(k) return k diff --git a/x/subaccount/keeper/msg_server_bet_test.go b/x/subaccount/keeper/msg_server_bet_test.go index 76f4384f..9345ce16 100644 --- a/x/subaccount/keeper/msg_server_bet_test.go +++ b/x/subaccount/keeper/msg_server_bet_test.go @@ -42,6 +42,7 @@ var ( subAccFunder = sample.NativeAccAddress() micro = sdk.NewInt(1_000_000) subAccFunds = sdk.NewInt(10_000).Mul(micro) + subAccAddr = types.NewAddressFromSubaccount(1) ) func TestMsgServer_Bet(t *testing.T) { @@ -71,7 +72,7 @@ func TestMsgServer_Bet(t *testing.T) { require.NoError(t, err) // add market - market := addTestMarket(t, app, ctx) + market := addTestMarket(t, app, ctx, true) // start betting using the subaccount betAmt := sdk.NewInt(1000).Mul(micro) @@ -82,7 +83,6 @@ func TestMsgServer_Bet(t *testing.T) { require.NoError(t, err) // check subaccount balance - subAccAddr := types.NewAddressFromSubaccount(1) balance, exists := k.GetBalance(ctx, subAccAddr) require.True(t, exists) @@ -160,7 +160,7 @@ func TestMsgServer_Bet(t *testing.T) { }) } -func addTestMarket(t testing.TB, tApp *simappUtil.TestApp, ctx sdk.Context) *markettypes.Market { +func addTestMarket(t testing.TB, tApp *simappUtil.TestApp, ctx sdk.Context, prefund bool) *markettypes.Market { testCreator = simappUtil.TestParamUsers["user1"].Address.String() testAddMarketClaim := jwt.MapClaims{ "uid": testMarketUID, @@ -185,22 +185,24 @@ func addTestMarket(t testing.TB, tApp *simappUtil.TestApp, ctx sdk.Context) *mar require.Nil(t, err) require.NotNil(t, resAddMarket) - // add liquidity - err = simapp.FundAccount( - tApp.BankKeeper, - ctx, - simappUtil.TestParamUsers["user1"].Address, - sdk.NewCoins(sdk.NewCoin(tApp.SubaccountKeeper.GetParams(ctx).LockedBalanceDenom, sdk.NewInt(1_000_000).Mul(micro))), - ) - require.NoError(t, err) - _, err = tApp.OrderbookKeeper.InitiateOrderBookParticipation( - ctx, - simappUtil.TestParamUsers["user1"].Address, - resAddMarket.Data.UID, - sdk.NewInt(1_000_000).Mul(micro), - sdk.NewInt(1), - ) - require.NoError(t, err) + if prefund { + // add liquidity + err = simapp.FundAccount( + tApp.BankKeeper, + ctx, + simappUtil.TestParamUsers["user1"].Address, + sdk.NewCoins(sdk.NewCoin(tApp.SubaccountKeeper.GetParams(ctx).LockedBalanceDenom, sdk.NewInt(1_000_000).Mul(micro))), + ) + require.NoError(t, err) + _, err = tApp.OrderbookKeeper.InitiateOrderBookParticipation( + ctx, + simappUtil.TestParamUsers["user1"].Address, + resAddMarket.Data.UID, + sdk.NewInt(1_000_000).Mul(micro), + sdk.NewInt(1), + ) + require.NoError(t, err) + } return resAddMarket.Data } diff --git a/x/subaccount/keeper/msg_server_house.go b/x/subaccount/keeper/msg_server_house.go index b6f29c97..883d993a 100644 --- a/x/subaccount/keeper/msg_server_house.go +++ b/x/subaccount/keeper/msg_server_house.go @@ -22,6 +22,17 @@ func (m msgServer) HouseDeposit(goCtx context.Context, msg *types.MsgHouseDeposi return nil, sdkerrors.Wrap(err, "failed to deposit") } + // get subaccount balance, and check if it can spend + balance, exists := m.keeper.GetBalance(ctx, subAccountAddr) + if !exists { + panic("data corruption: subaccount balance not found") + } + + err := balance.Spend(msg.Msg.Amount) + if err != nil { + return nil, err + } + // send house deposit from subaccount on behalf of the owner participationIndex, err := m.keeper.houseKeeper.Deposit( ctx, @@ -33,7 +44,13 @@ func (m msgServer) HouseDeposit(goCtx context.Context, msg *types.MsgHouseDeposi if err != nil { return nil, sdkerrors.Wrap(err, "failed to deposit") } + + // update subaccount balance + m.keeper.SetBalance(ctx, subAccountAddr, balance) + + // emit event msg.Msg.EmitEvent(&ctx, subAccountAddr.String(), participationIndex) + return &types.MsgHouseDepositResponse{ Response: &housetypes.MsgDepositResponse{ MarketUID: msg.Msg.MarketUID, @@ -55,6 +72,10 @@ func (m msgServer) houseDeposit(ctx sdk.Context, msg *housetypes.MsgDeposit) err return sdkerrors.Wrapf(housetypes.ErrInTicketVerification, "%s", err) } + if payload.DepositorAddress != "" { + return sdkerrors.Wrapf(housetypes.ErrInTicketPayloadValidation, "in subaccount the depositor address must be empty") + } + depositorAddr := msg.Creator if err := payload.Validate(depositorAddr); err != nil { diff --git a/x/subaccount/keeper/msg_server_house_test.go b/x/subaccount/keeper/msg_server_house_test.go new file mode 100644 index 00000000..b12a7218 --- /dev/null +++ b/x/subaccount/keeper/msg_server_house_test.go @@ -0,0 +1,175 @@ +package keeper_test + +import ( + "testing" + "time" + + "github.com/cosmos/cosmos-sdk/simapp" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/golang-jwt/jwt" + "github.com/sge-network/sge/testutil/sample" + simappUtil "github.com/sge-network/sge/testutil/simapp" + sgetypes "github.com/sge-network/sge/types" + betmodulekeeper "github.com/sge-network/sge/x/bet/keeper" + housetypes "github.com/sge-network/sge/x/house/types" + markettypes "github.com/sge-network/sge/x/market/types" + "github.com/sge-network/sge/x/subaccount/types" + "github.com/stretchr/testify/require" +) + +var ( + bettor1 = sample.NativeAccAddress() + bettor1Funds = sdk.NewInt(10).Mul(micro) +) + +func TestMsgServer_HouseDeposit(t *testing.T) { + app, k, msgServer, ctx := setupMsgServerAndApp(t) + + // do subaccount creation + require.NoError( + t, + simapp.FundAccount( + app.BankKeeper, + ctx, + subAccFunder, + sdk.NewCoins(sdk.NewCoin(k.GetParams(ctx).LockedBalanceDenom, subAccFunds)), + ), + ) + + _, err := msgServer.CreateSubAccount(sdk.WrapSDKContext(ctx), &types.MsgCreateSubAccount{ + Sender: subAccFunder.String(), + SubAccountOwner: subAccOwner.String(), + LockedBalances: []*types.LockedBalance{ + { + UnlockTime: time.Now().Add(24 * time.Hour), + Amount: subAccFunds, + }, + }, + }) + require.NoError(t, err) + + // fund a bettor + require.NoError( + t, + simapp.FundAccount( + app.BankKeeper, + ctx, + bettor1, + sdk.NewCoins(sdk.NewCoin(k.GetParams(ctx).LockedBalanceDenom, subAccFunds)), + ), + ) + + // add market + market := addTestMarket(t, app, ctx, false) + + // do house deposit + deposit := sdk.NewInt(1000).Mul(micro) + _, err = msgServer.HouseDeposit(sdk.WrapSDKContext(ctx), houseDepositMsg(t, subAccOwner, market.UID, deposit)) + require.NoError(t, err) + // check spend + subBalance, exists := k.GetBalance(ctx, subAccAddr) + require.True(t, exists) + require.Equal(t, subBalance.SpentAmount, deposit) + + // place bet + betMsgServer := betmodulekeeper.NewMsgServerImpl(*app.BetKeeper) + _, err = betMsgServer.PlaceBet(sdk.WrapSDKContext(ctx), testBet(t, bettor1, bettor1Funds)) + require.NoError(t, err) + + participateFee := app.HouseKeeper.GetHouseParticipationFee(ctx).Mul(deposit.ToDec()).TruncateInt() + + t.Run("house wins", func(t *testing.T) { + ctx, _ = ctx.CacheContext() + app.MarketKeeper.ResolveMarket(ctx, *market, &markettypes.MarketResolutionTicketPayload{ + UID: market.UID, + ResolutionTS: uint64(ctx.BlockTime().Unix()) + 10000, + WinnerOddsUIDs: []string{testOddsUID2}, + Status: markettypes.MarketStatus_MARKET_STATUS_RESULT_DECLARED, + }) + err := app.BetKeeper.BatchMarketSettlements(ctx) + require.NoError(t, err) + err = app.OrderbookKeeper.BatchOrderBookSettlements(ctx) + require.NoError(t, err) + + subBalance, exists := k.GetBalance(ctx, subAccAddr) + require.True(t, exists) + require.NoError(t, err) + + require.Equal(t, subBalance.SpentAmount.String(), sdk.ZeroInt().Add(participateFee).String()) + // check profits were forwarded to subacc owner + ownerBalance := app.BankKeeper.GetAllBalances(ctx, subAccOwner) + require.Equal(t, ownerBalance.AmountOf(k.GetParams(ctx).LockedBalanceDenom).String(), sdk.NewInt(10).Mul(micro).String()) + }) + + t.Run("house loses", func(t *testing.T) { + ctx, _ = ctx.CacheContext() + app.MarketKeeper.ResolveMarket(ctx, *market, &markettypes.MarketResolutionTicketPayload{ + UID: market.UID, + ResolutionTS: uint64(ctx.BlockTime().Unix()) + 10000, + WinnerOddsUIDs: []string{testOddsUID1}, + Status: markettypes.MarketStatus_MARKET_STATUS_RESULT_DECLARED, + }) + err := app.BetKeeper.BatchMarketSettlements(ctx) + require.NoError(t, err) + err = app.OrderbookKeeper.BatchOrderBookSettlements(ctx) + require.NoError(t, err) + + subBalance, exists := k.GetBalance(ctx, subAccAddr) + require.True(t, exists) + require.NoError(t, err) + + require.Equal(t, subBalance.SpentAmount.String(), sdk.ZeroInt().Add(participateFee).String()) + require.Equal(t, subBalance.LostAmount, bettor1Funds.ToDec().Mul(sdk.MustNewDecFromStr("3.2")).TruncateInt()) + // check profits were forwarded to subacc owner + ownerBalance := app.BankKeeper.GetAllBalances(ctx, subAccOwner) + require.Equal(t, ownerBalance.AmountOf(k.GetParams(ctx).LockedBalanceDenom), sdk.ZeroInt()) + }) + t.Run("house refund", func(t *testing.T) { + ctx, _ = ctx.CacheContext() + app.MarketKeeper.ResolveMarket(ctx, *market, &markettypes.MarketResolutionTicketPayload{ + UID: market.UID, + ResolutionTS: uint64(ctx.BlockTime().Unix()) + 10000, + WinnerOddsUIDs: []string{testOddsUID1}, + Status: markettypes.MarketStatus_MARKET_STATUS_CANCELED, + }) + err := app.BetKeeper.BatchMarketSettlements(ctx) + require.NoError(t, err) + err = app.OrderbookKeeper.BatchOrderBookSettlements(ctx) + require.NoError(t, err) + + subBalance, exists := k.GetBalance(ctx, subAccAddr) + require.True(t, exists) + require.NoError(t, err) + + require.Equal(t, subBalance.SpentAmount, sdk.ZeroInt()) + require.Equal(t, subBalance.LostAmount, sdk.ZeroInt()) + // check profits were forwarded to subacc owner + ownerBalance := app.BankKeeper.GetAllBalances(ctx, subAccOwner) + require.Equal(t, ownerBalance.AmountOf(k.GetParams(ctx).LockedBalanceDenom), sdk.ZeroInt()) + }) +} + +func houseDepositMsg(t *testing.T, owner sdk.AccAddress, uid string, amt sdk.Int) *types.MsgHouseDeposit { + testKyc := &sgetypes.KycDataPayload{ + Approved: true, + ID: owner.String(), + } + ticketClaim := jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "kyc_data": testKyc, + } + ticket, err := simappUtil.CreateJwtTicket(ticketClaim) + require.Nil(t, err) + + inputDeposit := &housetypes.MsgDeposit{ + Creator: owner.String(), + MarketUID: uid, + Amount: amt, + Ticket: ticket, + } + + return &types.MsgHouseDeposit{ + Msg: inputDeposit, + } +} diff --git a/x/subaccount/keeper/orderbook_hooks.go b/x/subaccount/keeper/orderbook_hooks.go index 9f435273..844f200d 100644 --- a/x/subaccount/keeper/orderbook_hooks.go +++ b/x/subaccount/keeper/orderbook_hooks.go @@ -1,6 +1,8 @@ package keeper import ( + "log" + sdk "github.com/cosmos/cosmos-sdk/types" orderbookmodulekeeper "github.com/sge-network/sge/x/orderbook/keeper" ) @@ -56,3 +58,79 @@ func (k Keeper) AfterBettorRefund(ctx sdk.Context, bettor sdk.AccAddress, origin } k.SetBalance(ctx, bettor, balance) } + +func (k Keeper) AfterHouseWin(ctx sdk.Context, house sdk.AccAddress, originalAmount, profit sdk.Int, fee *sdk.Int) { + // update balance + balance, exists := k.GetBalance(ctx, house) + if !exists { + return + } + + err := balance.Unspend(originalAmount) + if err != nil { + panic(err) + } + if fee != nil { + err = balance.Unspend(*fee) + if err != nil { + panic(err) + } + } + k.SetBalance(ctx, house, balance) + + // send profits + subAccountOwner, exists := k.GetSubAccountOwner(ctx, house) + if !exists { + panic("data corruption: subaccount owner not found") + } + err = k.bankKeeper.SendCoins(ctx, house, subAccountOwner, sdk.NewCoins(sdk.NewCoin(k.GetParams(ctx).LockedBalanceDenom, profit))) + if err != nil { + panic(err) + } + +} + +func (k Keeper) AfterHouseLoss(ctx sdk.Context, house sdk.AccAddress, originalAmount sdk.Int, lostAmt sdk.Int, fee *sdk.Int) { + balance, exists := k.GetBalance(ctx, house) + if !exists { + return + } + + err := balance.Unspend(originalAmount) + if err != nil { + panic(err) + } + err = balance.AddLoss(lostAmt) + if err != nil { + panic(err) + } + if fee != nil { + err = balance.Unspend(*fee) + if err != nil { + panic(err) + } + } + + k.SetBalance(ctx, house, balance) + + log.Printf("house %s lost %s", house, lostAmt.QuoRaw(1_000_000).String()) +} + +func (k Keeper) AfterHouseRefund(ctx sdk.Context, house sdk.AccAddress, originalAmount, fee sdk.Int) { + balance, exists := k.GetBalance(ctx, house) + if !exists { + return + } + + err := balance.Unspend(originalAmount) + if err != nil { + panic(err) + } + err = balance.Unspend(fee) + if err != nil { + panic(err) + } + + k.SetBalance(ctx, house, balance) + log.Printf("house %s refunded %s", house, originalAmount.String()) +} diff --git a/x/subaccount/types/msg.go b/x/subaccount/types/msg.go index 209f19ff..8be101ec 100644 --- a/x/subaccount/types/msg.go +++ b/x/subaccount/types/msg.go @@ -3,6 +3,7 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/errors" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) var ( @@ -88,9 +89,34 @@ func (msg *MsgWithdrawUnlockedBalances) GetSigners() []sdk.AccAddress { } func (m *MsgPlaceBet) ValidateBasic() error { + if m.Msg == nil { + return sdkerrors.ErrInvalidRequest.Wrap("msg is nil") + } return m.Msg.ValidateBasic() } func (m *MsgPlaceBet) GetSigners() []sdk.AccAddress { return m.Msg.GetSigners() } + +func (m *MsgHouseDeposit) GetSigners() []sdk.AccAddress { + return m.Msg.GetSigners() +} + +func (m *MsgHouseDeposit) ValidateBasic() error { + if m.Msg == nil { + return sdkerrors.ErrInvalidRequest.Wrap("msg is nil") + } + return m.Msg.ValidateBasic() +} + +func (m *MsgHouseWithdraw) GetSigners() []sdk.AccAddress { + return m.Msg.GetSigners() +} + +func (m *MsgHouseWithdraw) ValidateBasic() error { + if m.Msg == nil { + return sdkerrors.ErrInvalidRequest.Wrap("msg is nil") + } + return m.Msg.ValidateBasic() +} From 447ea45f211d1efbecb5c6caf9250842fc6ac958 Mon Sep 17 00:00:00 2001 From: unknown unknown Date: Tue, 25 Jul 2023 12:08:28 +0200 Subject: [PATCH 14/20] all tests pass part2 --- x/subaccount/keeper/msg_server_bet_test.go | 6 +++--- x/subaccount/keeper/msg_server_house_test.go | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/x/subaccount/keeper/msg_server_bet_test.go b/x/subaccount/keeper/msg_server_bet_test.go index 9345ce16..b056c8bc 100644 --- a/x/subaccount/keeper/msg_server_bet_test.go +++ b/x/subaccount/keeper/msg_server_bet_test.go @@ -89,7 +89,7 @@ func TestMsgServer_Bet(t *testing.T) { require.Equal(t, balance.SpentAmount, betAmt) t.Run("resolve market – better wins", func(t *testing.T) { - ctx, _ = ctx.CacheContext() + ctx, _ := ctx.CacheContext() // resolve the market – better wins app.MarketKeeper.ResolveMarket(ctx, *market, &markettypes.MarketResolutionTicketPayload{ UID: market.UID, @@ -118,7 +118,7 @@ func TestMsgServer_Bet(t *testing.T) { }) // resolve the market – better loses t.Run("resolve market – better loses", func(t *testing.T) { - ctx, _ = ctx.CacheContext() + ctx, _ := ctx.CacheContext() // resolve the market – better loses app.MarketKeeper.ResolveMarket(ctx, *market, &markettypes.MarketResolutionTicketPayload{ UID: market.UID, @@ -139,7 +139,7 @@ func TestMsgServer_Bet(t *testing.T) { require.Equal(t, sdk.NewCoins(), ownerBalance) }) t.Run("resolve market – refund", func(t *testing.T) { - ctx, _ = ctx.CacheContext() + ctx, _ := ctx.CacheContext() // resolve the market – refund app.MarketKeeper.ResolveMarket(ctx, *market, &markettypes.MarketResolutionTicketPayload{ UID: market.UID, diff --git a/x/subaccount/keeper/msg_server_house_test.go b/x/subaccount/keeper/msg_server_house_test.go index b12a7218..a7ea0b7d 100644 --- a/x/subaccount/keeper/msg_server_house_test.go +++ b/x/subaccount/keeper/msg_server_house_test.go @@ -79,7 +79,7 @@ func TestMsgServer_HouseDeposit(t *testing.T) { participateFee := app.HouseKeeper.GetHouseParticipationFee(ctx).Mul(deposit.ToDec()).TruncateInt() t.Run("house wins", func(t *testing.T) { - ctx, _ = ctx.CacheContext() + ctx, _ := ctx.CacheContext() app.MarketKeeper.ResolveMarket(ctx, *market, &markettypes.MarketResolutionTicketPayload{ UID: market.UID, ResolutionTS: uint64(ctx.BlockTime().Unix()) + 10000, @@ -102,7 +102,7 @@ func TestMsgServer_HouseDeposit(t *testing.T) { }) t.Run("house loses", func(t *testing.T) { - ctx, _ = ctx.CacheContext() + ctx, _ := ctx.CacheContext() app.MarketKeeper.ResolveMarket(ctx, *market, &markettypes.MarketResolutionTicketPayload{ UID: market.UID, ResolutionTS: uint64(ctx.BlockTime().Unix()) + 10000, @@ -125,7 +125,7 @@ func TestMsgServer_HouseDeposit(t *testing.T) { require.Equal(t, ownerBalance.AmountOf(k.GetParams(ctx).LockedBalanceDenom), sdk.ZeroInt()) }) t.Run("house refund", func(t *testing.T) { - ctx, _ = ctx.CacheContext() + ctx, _ := ctx.CacheContext() app.MarketKeeper.ResolveMarket(ctx, *market, &markettypes.MarketResolutionTicketPayload{ UID: market.UID, ResolutionTS: uint64(ctx.BlockTime().Unix()) + 10000, @@ -147,6 +147,8 @@ func TestMsgServer_HouseDeposit(t *testing.T) { ownerBalance := app.BankKeeper.GetAllBalances(ctx, subAccOwner) require.Equal(t, ownerBalance.AmountOf(k.GetParams(ctx).LockedBalanceDenom), sdk.ZeroInt()) }) + + // TODO: not partecipated in bet fulfillment. } func houseDepositMsg(t *testing.T, owner sdk.AccAddress, uid string, amt sdk.Int) *types.MsgHouseDeposit { From d00301697976863ff6665709849874d949f16b5b Mon Sep 17 00:00:00 2001 From: unknown unknown Date: Tue, 25 Jul 2023 12:08:46 +0200 Subject: [PATCH 15/20] remove logging --- x/subaccount/keeper/orderbook_hooks.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/x/subaccount/keeper/orderbook_hooks.go b/x/subaccount/keeper/orderbook_hooks.go index 844f200d..45a8cc43 100644 --- a/x/subaccount/keeper/orderbook_hooks.go +++ b/x/subaccount/keeper/orderbook_hooks.go @@ -1,8 +1,6 @@ package keeper import ( - "log" - sdk "github.com/cosmos/cosmos-sdk/types" orderbookmodulekeeper "github.com/sge-network/sge/x/orderbook/keeper" ) @@ -112,8 +110,6 @@ func (k Keeper) AfterHouseLoss(ctx sdk.Context, house sdk.AccAddress, originalAm } k.SetBalance(ctx, house, balance) - - log.Printf("house %s lost %s", house, lostAmt.QuoRaw(1_000_000).String()) } func (k Keeper) AfterHouseRefund(ctx sdk.Context, house sdk.AccAddress, originalAmount, fee sdk.Int) { @@ -132,5 +128,4 @@ func (k Keeper) AfterHouseRefund(ctx sdk.Context, house sdk.AccAddress, original } k.SetBalance(ctx, house, balance) - log.Printf("house %s refunded %s", house, originalAmount.String()) } From 3925fb3c86b8c4b714ccb3a32dc5f45423a4a0db Mon Sep 17 00:00:00 2001 From: unknown unknown Date: Tue, 25 Jul 2023 15:23:27 +0200 Subject: [PATCH 16/20] add house withdrawal tests --- x/subaccount/keeper/keeper.go | 13 ++++ x/subaccount/keeper/msg_server_house.go | 81 +++++++++++++++++++- x/subaccount/keeper/msg_server_house_test.go | 41 +++++++++- 3 files changed, 130 insertions(+), 5 deletions(-) diff --git a/x/subaccount/keeper/keeper.go b/x/subaccount/keeper/keeper.go index 238079ef..5ad80a53 100644 --- a/x/subaccount/keeper/keeper.go +++ b/x/subaccount/keeper/keeper.go @@ -22,10 +22,21 @@ type BankKeeper interface { type HouseKeeper interface { GetParams(ctx sdk.Context) housetypes.Params Deposit(ctx sdk.Context, creator, depositor, marketUID string, amount sdk.Int) (participationIndex uint64, err error) + GetDeposit(ctx sdk.Context, depositorAddr, marketUID string, participationIndex uint64) (housetypes.Deposit, bool) + Withdraw(ctx sdk.Context, deposit housetypes.Deposit, creator, depositorAddr string, marketUID string, participationIndex uint64, mode housetypes.WithdrawalMode, withdrawableAmount sdk.Int) (uint64, error) } type OrderBookKeeper interface { RegisterHook(hooks orderbookmodulekeeper.Hook) + CalcWithdrawalAmount( + ctx sdk.Context, + depositorAddress string, + marketUID string, + participationIndex uint64, + mode housetypes.WithdrawalMode, + totalWithdrawnAmount sdk.Int, + amount sdk.Int, + ) (sdk.Int, error) } type Keeper struct { @@ -37,6 +48,7 @@ type Keeper struct { ovmKeeper bettypes.OVMKeeper betKeeper BetKeeper houseKeeper HouseKeeper + obKeeper OrderBookKeeper } func NewKeeper(cdc codec.Codec, storeKey sdk.StoreKey, ps paramtypes.Subspace, bankKeeper BankKeeper, ovmKeeper bettypes.OVMKeeper, betKeeper BetKeeper, obKeeper OrderBookKeeper, hk HouseKeeper) Keeper { @@ -53,6 +65,7 @@ func NewKeeper(cdc codec.Codec, storeKey sdk.StoreKey, ps paramtypes.Subspace, b ovmKeeper: ovmKeeper, betKeeper: betKeeper, houseKeeper: hk, + obKeeper: obKeeper, } obKeeper.RegisterHook(k) return k diff --git a/x/subaccount/keeper/msg_server_house.go b/x/subaccount/keeper/msg_server_house.go index 883d993a..0ffa8b25 100644 --- a/x/subaccount/keeper/msg_server_house.go +++ b/x/subaccount/keeper/msg_server_house.go @@ -7,6 +7,8 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" housetypes "github.com/sge-network/sge/x/house/types" "github.com/sge-network/sge/x/subaccount/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" ) func (m msgServer) HouseDeposit(goCtx context.Context, msg *types.MsgHouseDeposit) (*types.MsgHouseDepositResponse, error) { @@ -85,7 +87,80 @@ func (m msgServer) houseDeposit(ctx sdk.Context, msg *housetypes.MsgDeposit) err return nil } -func (m msgServer) HouseWithdraw(ctx context.Context, withdraw *types.MsgHouseWithdraw) (*types.MsgHouseWithdrawResponse, error) { - // TODO implement me - panic("implement me") +func (m msgServer) HouseWithdraw(goCtx context.Context, withdraw *types.MsgHouseWithdraw) (*types.MsgHouseWithdrawResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // check if subaccount exists + subAccountAddr, exists := m.keeper.GetSubAccountByOwner(ctx, sdk.MustAccAddressFromBech32(withdraw.Msg.Creator)) + if !exists { + return nil, types.ErrSubaccountDoesNotExist + } + + subAccountBalance, exists := m.keeper.GetBalance(ctx, subAccountAddr) + if !exists { + panic("data corruption: subaccount balance not found") + } + + withdrawable, resp, err := m.houseWithdraw(ctx, withdraw.Msg, subAccountAddr) + if err != nil { + return nil, err + } + + err = subAccountBalance.Unspend(withdrawable) + if err != nil { + panic("data corruption: it must be possible to unspend an house withdrawal") + } + + m.keeper.SetBalance(ctx, subAccountAddr, subAccountBalance) + return &types.MsgHouseWithdrawResponse{ + Response: resp, + }, nil + +} + +func (m msgServer) houseWithdraw(ctx sdk.Context, msg *housetypes.MsgWithdraw, subAccAddr sdk.AccAddress) (sdk.Int, *housetypes.MsgWithdrawResponse, error) { + var payload housetypes.WithdrawTicketPayload + if err := m.keeper.ovmKeeper.VerifyTicketUnmarshal(sdk.WrapSDKContext(ctx), msg.Ticket, &payload); err != nil { + return sdk.Int{}, nil, sdkerrors.Wrapf(housetypes.ErrInTicketVerification, "%s", err) + } + + if payload.DepositorAddress != "" { + return sdk.Int{}, nil, status.Errorf(codes.InvalidArgument, "in subaccount the depositor address must be empty") + } + + if err := payload.Validate(msg.Creator); err != nil { + return sdk.Int{}, nil, sdkerrors.Wrapf(housetypes.ErrInTicketPayloadValidation, "%s", err) + } + + // Get the deposit object + deposit, found := m.keeper.houseKeeper.GetDeposit(ctx, subAccAddr.String(), msg.MarketUID, msg.ParticipationIndex) + if !found { + return sdk.Int{}, nil, sdkerrors.Wrapf(housetypes.ErrDepositNotFound, ": %s, %d", msg.MarketUID, msg.ParticipationIndex) + } + + withdrawable, err := m.keeper.obKeeper.CalcWithdrawalAmount(ctx, + subAccAddr.String(), + msg.MarketUID, + msg.ParticipationIndex, + msg.Mode, + deposit.TotalWithdrawalAmount, + msg.Amount, + ) + if err != nil { + return sdk.Int{}, nil, sdkerrors.Wrapf(housetypes.ErrInTicketVerification, "%s", err) + } + + id, err := m.keeper.houseKeeper.Withdraw(ctx, deposit, msg.Creator, subAccAddr.String(), msg.MarketUID, + msg.ParticipationIndex, msg.Mode, withdrawable) + if err != nil { + return sdk.Int{}, nil, sdkerrors.Wrap(err, "process withdrawal") + } + + msg.EmitEvent(&ctx, subAccAddr.String(), id) + + return withdrawable, &housetypes.MsgWithdrawResponse{ + ID: id, + MarketUID: msg.MarketUID, + ParticipationIndex: msg.ParticipationIndex, + }, nil } diff --git a/x/subaccount/keeper/msg_server_house_test.go b/x/subaccount/keeper/msg_server_house_test.go index a7ea0b7d..5b900fa1 100644 --- a/x/subaccount/keeper/msg_server_house_test.go +++ b/x/subaccount/keeper/msg_server_house_test.go @@ -22,7 +22,7 @@ var ( bettor1Funds = sdk.NewInt(10).Mul(micro) ) -func TestMsgServer_HouseDeposit(t *testing.T) { +func TestMsgServer(t *testing.T) { app, k, msgServer, ctx := setupMsgServerAndApp(t) // do subaccount creation @@ -64,7 +64,7 @@ func TestMsgServer_HouseDeposit(t *testing.T) { // do house deposit deposit := sdk.NewInt(1000).Mul(micro) - _, err = msgServer.HouseDeposit(sdk.WrapSDKContext(ctx), houseDepositMsg(t, subAccOwner, market.UID, deposit)) + depResp, err := msgServer.HouseDeposit(sdk.WrapSDKContext(ctx), houseDepositMsg(t, subAccOwner, market.UID, deposit)) require.NoError(t, err) // check spend subBalance, exists := k.GetBalance(ctx, subAccAddr) @@ -149,6 +149,43 @@ func TestMsgServer_HouseDeposit(t *testing.T) { }) // TODO: not partecipated in bet fulfillment. + + t.Run("withdrawal", func(t *testing.T) { + ctx, _ := ctx.CacheContext() + _, err := msgServer.HouseWithdraw(sdk.WrapSDKContext(ctx), &types.MsgHouseWithdraw{Msg: houseWithdrawMsg(t, subAccOwner, deposit, depResp.Response.ParticipationIndex)}) + require.NoError(t, err) + + // do subaccount balance check + subBalance, exists := k.GetBalance(ctx, subAccAddr) + require.True(t, exists) + + require.Equal(t, subBalance.SpentAmount.String(), sdk.NewInt(132000000).String()) // NOTE: there was a match in the bet + participate fee + require.Equal(t, subBalance.LostAmount.String(), sdk.ZeroInt().String()) + }) +} + +func houseWithdrawMsg(t testing.TB, owner sdk.AccAddress, amt sdk.Int, partecipationIndex uint64) *housetypes.MsgWithdraw { + testKyc := &sgetypes.KycDataPayload{ + Approved: true, + ID: owner.String(), + } + ticketClaim := jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "kyc_data": testKyc, + } + ticket, err := simappUtil.CreateJwtTicket(ticketClaim) + require.Nil(t, err) + + inputWithdraw := &housetypes.MsgWithdraw{ + Creator: owner.String(), + MarketUID: testMarketUID, + Amount: amt, + ParticipationIndex: partecipationIndex, + Mode: housetypes.WithdrawalMode_WITHDRAWAL_MODE_FULL, + Ticket: ticket, + } + return inputWithdraw } func houseDepositMsg(t *testing.T, owner sdk.AccAddress, uid string, amt sdk.Int) *types.MsgHouseDeposit { From 6827247f11ce7bf917f446e8f57a9eb993b9a4f1 Mon Sep 17 00:00:00 2001 From: unknown unknown Date: Wed, 26 Jul 2023 20:10:16 +0200 Subject: [PATCH 17/20] fix conflicts --- go.mod | 3 +- go.sum | 2 + proto/sge/subaccount/tx.proto | 10 +- types/kyc.pb.go | 2 +- x/bet/types/bet.pb.go | 2 +- x/bet/types/bet_odds.pb.go | 2 +- x/bet/types/constraints.pb.go | 2 +- x/bet/types/genesis.pb.go | 2 +- x/bet/types/params.pb.go | 2 +- x/bet/types/query.pb.go | 2 +- x/bet/types/query.pb.gw.go | 14 +- x/bet/types/ticket.pb.go | 2 +- x/bet/types/wager.pb.go | 2 +- x/house/types/authz.pb.go | 2 +- x/house/types/deposit.pb.go | 2 +- x/house/types/genesis.pb.go | 2 +- x/house/types/params.pb.go | 2 +- x/house/types/query.pb.go | 2 +- x/house/types/query.pb.gw.go | 10 +- x/house/types/ticket.pb.go | 2 +- x/house/types/tx.pb.go | 2 +- x/house/types/withdraw.pb.go | 2 +- x/market/types/genesis.pb.go | 2 +- x/market/types/market.pb.go | 2 +- x/market/types/odds.pb.go | 2 +- x/market/types/params.pb.go | 2 +- x/market/types/query.pb.go | 2 +- x/market/types/query.pb.gw.go | 8 +- x/market/types/ticket.pb.go | 2 +- x/market/types/tx.pb.go | 2 +- x/mint/types/genesis.pb.go | 2 +- x/mint/types/minter.pb.go | 2 +- x/mint/types/params.pb.go | 2 +- x/mint/types/phase.pb.go | 2 +- x/mint/types/query.pb.go | 2 +- x/mint/types/query.pb.gw.go | 10 +- x/orderbook/keeper/bet_settle.go | 8 +- x/orderbook/types/exposure.pb.go | 2 +- x/orderbook/types/genesis.pb.go | 2 +- x/orderbook/types/orderbook.pb.go | 2 +- x/orderbook/types/params.pb.go | 2 +- x/orderbook/types/participation.pb.go | 2 +- x/orderbook/types/query.pb.go | 2 +- x/orderbook/types/query.pb.gw.go | 22 +- x/ovm/types/genesis.pb.go | 2 +- x/ovm/types/params.pb.go | 2 +- x/ovm/types/proposal.pb.go | 2 +- x/ovm/types/query.pb.go | 2 +- x/ovm/types/query.pb.gw.go | 8 +- x/subaccount/keeper/keeper.go | 2 +- x/subaccount/keeper/msg_server_bet.go | 20 +- x/subaccount/keeper/msg_server_bet_test.go | 22 +- x/subaccount/keeper/msg_server_house_test.go | 8 +- x/subaccount/types/genesis.pb.go | 2 +- x/subaccount/types/msg.go | 6 +- x/subaccount/types/params.pb.go | 2 +- x/subaccount/types/subaccount.pb.go | 4 +- x/subaccount/types/tx.pb.go | 204 +++++++++---------- 58 files changed, 223 insertions(+), 220 deletions(-) diff --git a/go.mod b/go.mod index 79878dd9..67ab01e5 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.18 require ( github.com/cosmos/cosmos-sdk v0.45.16 + github.com/cosmos/gogoproto v1.4.10 github.com/cosmos/ibc-go/v4 v4.4.2 github.com/gogo/protobuf v1.3.3 github.com/golang-jwt/jwt v3.2.2+incompatible @@ -22,7 +23,6 @@ require ( github.com/tendermint/tm-db v0.6.7 google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc google.golang.org/grpc v1.55.0 - google.golang.org/protobuf v1.30.0 gopkg.in/yaml.v2 v2.4.0 mvdan.cc/gofumpt v0.4.0 ) @@ -276,6 +276,7 @@ require ( golang.org/x/tools v0.6.0 // indirect google.golang.org/genproto v0.0.0-20230526203410-71b5a4ffd15e // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect + google.golang.org/protobuf v1.30.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect honnef.co/go/tools v0.3.3 // indirect diff --git a/go.sum b/go.sum index 41bc70da..77175069 100644 --- a/go.sum +++ b/go.sum @@ -277,6 +277,8 @@ github.com/cosmos/cosmos-sdk/ics23/go v0.8.0/go.mod h1:2a4dBq88TUoqoWAU5eu0lGvpF github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= +github.com/cosmos/gogoproto v1.4.10 h1:QH/yT8X+c0F4ZDacDv3z+xE3WU1P1Z3wQoLMBRJoKuI= +github.com/cosmos/gogoproto v1.4.10/go.mod h1:3aAZzeRWpAwr+SS/LLkICX2/kDFyaYVzckBDzygIxek= github.com/cosmos/gorocksdb v1.2.0 h1:d0l3jJG8M4hBouIZq0mDUHZ+zjOx044J3nGRskwTb4Y= github.com/cosmos/gorocksdb v1.2.0/go.mod h1:aaKvKItm514hKfNJpUJXnnOWeBnk2GL4+Qw9NHizILw= github.com/cosmos/iavl v0.19.5 h1:rGA3hOrgNxgRM5wYcSCxgQBap7fW82WZgY78V9po/iY= diff --git a/proto/sge/subaccount/tx.proto b/proto/sge/subaccount/tx.proto index f29e8f27..2ad48976 100644 --- a/proto/sge/subaccount/tx.proto +++ b/proto/sge/subaccount/tx.proto @@ -19,7 +19,7 @@ service Msg { rpc WithdrawUnlockedBalances(MsgWithdrawUnlockedBalances) returns (MsgWithdrawUnlockedBalancesResponse); // PlaceBet defines a method for placing a bet using a subaccount. - rpc PlaceBet(MsgPlaceBet) returns (MsgPlaceBetResponse); + rpc Wager(MsgWager) returns (MsgWagerResponse); // HouseDeposit defines a method for depositing funds to provide liquidity to a market. rpc HouseDeposit(MsgHouseDeposit) returns (MsgHouseDepositResponse); @@ -68,13 +68,13 @@ message MsgWithdrawUnlockedBalances { message MsgWithdrawUnlockedBalancesResponse {} // MsgPlaceBet wraps the MsgPlaceBet message. We need it in order not to have double interface registration conflicts. -message MsgPlaceBet { - sgenetwork.sge.bet.MsgPlaceBet msg = 1; +message MsgWager { + sgenetwork.sge.bet.MsgWager msg = 1; } // MsgBetResponse wraps the MsgPlaceBetResponse message. We need it in order not to have double interface registration conflicts. -message MsgPlaceBetResponse { - sgenetwork.sge.bet.MsgPlaceBetResponse response = 1; +message MsgWagerResponse { + sgenetwork.sge.bet.MsgWagerResponse response = 1; } // MsgHouseDeposit wraps the MsgHouseDeposit message. We need it in order not to have double interface registration conflicts. diff --git a/types/kyc.pb.go b/types/kyc.pb.go index 1f347d6b..3bb5e3e7 100644 --- a/types/kyc.pb.go +++ b/types/kyc.pb.go @@ -5,7 +5,7 @@ package types import ( fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/bet/types/bet.pb.go b/x/bet/types/bet.pb.go index 41414642..32f77381 100644 --- a/x/bet/types/bet.pb.go +++ b/x/bet/types/bet.pb.go @@ -6,7 +6,7 @@ package types import ( fmt "fmt" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/bet/types/bet_odds.pb.go b/x/bet/types/bet_odds.pb.go index e4a5928c..63352cc3 100644 --- a/x/bet/types/bet_odds.pb.go +++ b/x/bet/types/bet_odds.pb.go @@ -6,7 +6,7 @@ package types import ( fmt "fmt" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/bet/types/constraints.pb.go b/x/bet/types/constraints.pb.go index aa572eb3..553b6b33 100644 --- a/x/bet/types/constraints.pb.go +++ b/x/bet/types/constraints.pb.go @@ -6,7 +6,7 @@ package types import ( fmt "fmt" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/bet/types/genesis.pb.go b/x/bet/types/genesis.pb.go index 1aedd019..3a8a5ad6 100644 --- a/x/bet/types/genesis.pb.go +++ b/x/bet/types/genesis.pb.go @@ -5,7 +5,7 @@ package types import ( fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/bet/types/params.pb.go b/x/bet/types/params.pb.go index fd59c4b4..a67d1717 100644 --- a/x/bet/types/params.pb.go +++ b/x/bet/types/params.pb.go @@ -5,7 +5,7 @@ package types import ( fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/bet/types/query.pb.go b/x/bet/types/query.pb.go index e448237b..de11c8e2 100644 --- a/x/bet/types/query.pb.go +++ b/x/bet/types/query.pb.go @@ -7,7 +7,7 @@ import ( context "context" fmt "fmt" query "github.com/cosmos/cosmos-sdk/types/query" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" types "github.com/sge-network/sge/x/market/types" diff --git a/x/bet/types/query.pb.gw.go b/x/bet/types/query.pb.gw.go index 66f0a76b..42f323cf 100644 --- a/x/bet/types/query.pb.gw.go +++ b/x/bet/types/query.pb.gw.go @@ -785,19 +785,19 @@ 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{"sge", "bet", "params"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"sge", "bet", "params"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_Bet_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 1, 0, 4, 1, 5, 3}, []string{"sge", "bet", "creator", "uid"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_Bet_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 1, 0, 4, 1, 5, 3}, []string{"sge", "bet", "creator", "uid"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_BetsByCreator_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 2, 2, 3}, []string{"sge", "bet", "creator", "bets"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_BetsByCreator_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 2, 2, 3}, []string{"sge", "bet", "creator", "bets"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_Bets_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"sge", "bet", "bets"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_Bets_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"sge", "bet", "bets"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_PendingBets_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"sge", "bet", "bets", "pending", "market_uid"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_PendingBets_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"sge", "bet", "bets", "pending", "market_uid"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_SettledBetsOfHeight_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"sge", "bet", "bets", "settled", "block_height"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_SettledBetsOfHeight_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"sge", "bet", "bets", "settled", "block_height"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_BetsByUIDs_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"sge", "bet", "bets-by-uids", "items"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_BetsByUIDs_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"sge", "bet", "bets-by-uids", "items"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( diff --git a/x/bet/types/ticket.pb.go b/x/bet/types/ticket.pb.go index f3b90d28..e183ad41 100644 --- a/x/bet/types/ticket.pb.go +++ b/x/bet/types/ticket.pb.go @@ -5,7 +5,7 @@ package types import ( fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" types "github.com/sge-network/sge/types" io "io" diff --git a/x/bet/types/wager.pb.go b/x/bet/types/wager.pb.go index 9307b5cc..2123470c 100644 --- a/x/bet/types/wager.pb.go +++ b/x/bet/types/wager.pb.go @@ -6,7 +6,7 @@ package types import ( fmt "fmt" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/house/types/authz.pb.go b/x/house/types/authz.pb.go index 3018100f..4455a49f 100644 --- a/x/house/types/authz.pb.go +++ b/x/house/types/authz.pb.go @@ -6,7 +6,7 @@ package types import ( fmt "fmt" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/house/types/deposit.pb.go b/x/house/types/deposit.pb.go index b565c9b0..c6d672de 100644 --- a/x/house/types/deposit.pb.go +++ b/x/house/types/deposit.pb.go @@ -6,7 +6,7 @@ package types import ( fmt "fmt" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/house/types/genesis.pb.go b/x/house/types/genesis.pb.go index 0859f687..4b7450d5 100644 --- a/x/house/types/genesis.pb.go +++ b/x/house/types/genesis.pb.go @@ -5,7 +5,7 @@ package types import ( fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/house/types/params.pb.go b/x/house/types/params.pb.go index 4e311a37..a001ac4f 100644 --- a/x/house/types/params.pb.go +++ b/x/house/types/params.pb.go @@ -6,7 +6,7 @@ package types import ( fmt "fmt" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/house/types/query.pb.go b/x/house/types/query.pb.go index 6a4cc08e..7d5ba59e 100644 --- a/x/house/types/query.pb.go +++ b/x/house/types/query.pb.go @@ -7,7 +7,7 @@ import ( context "context" fmt "fmt" query "github.com/cosmos/cosmos-sdk/types/query" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" _ "google.golang.org/genproto/googleapis/api/annotations" diff --git a/x/house/types/query.pb.gw.go b/x/house/types/query.pb.gw.go index e0d62790..52ca0b2b 100644 --- a/x/house/types/query.pb.gw.go +++ b/x/house/types/query.pb.gw.go @@ -617,15 +617,15 @@ 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{"sge", "house", "params"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"sge", "house", "params"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_Deposits_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"sge", "house", "deposits"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_Deposits_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"sge", "house", "deposits"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_DepositsByAccount_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"sge", "house", "deposits", "address"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_DepositsByAccount_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"sge", "house", "deposits", "address"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_WithdrawalsByAccount_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"sge", "house", "withdrawals", "address"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_WithdrawalsByAccount_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"sge", "house", "withdrawals", "address"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_Withdrawal_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 1, 0, 4, 1, 5, 3, 1, 0, 4, 1, 5, 4, 1, 0, 4, 1, 5, 5}, []string{"sge", "withdrawal", "depositor_address", "market_uid", "participation_index", "id"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_Withdrawal_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 1, 0, 4, 1, 5, 3, 1, 0, 4, 1, 5, 4, 1, 0, 4, 1, 5, 5}, []string{"sge", "withdrawal", "depositor_address", "market_uid", "participation_index", "id"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( diff --git a/x/house/types/ticket.pb.go b/x/house/types/ticket.pb.go index 4fcf60b6..15e2fe33 100644 --- a/x/house/types/ticket.pb.go +++ b/x/house/types/ticket.pb.go @@ -5,7 +5,7 @@ package types import ( fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" types "github.com/sge-network/sge/types" io "io" diff --git a/x/house/types/tx.pb.go b/x/house/types/tx.pb.go index 98b2d68f..f7e28712 100644 --- a/x/house/types/tx.pb.go +++ b/x/house/types/tx.pb.go @@ -7,7 +7,7 @@ import ( context "context" fmt "fmt" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" grpc "google.golang.org/grpc" diff --git a/x/house/types/withdraw.pb.go b/x/house/types/withdraw.pb.go index 4b6dd9c1..c5c9c735 100644 --- a/x/house/types/withdraw.pb.go +++ b/x/house/types/withdraw.pb.go @@ -6,7 +6,7 @@ package types import ( fmt "fmt" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/market/types/genesis.pb.go b/x/market/types/genesis.pb.go index 3a00db83..deb9a0d0 100644 --- a/x/market/types/genesis.pb.go +++ b/x/market/types/genesis.pb.go @@ -5,7 +5,7 @@ package types import ( fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/market/types/market.pb.go b/x/market/types/market.pb.go index d3baca4d..a1df2459 100644 --- a/x/market/types/market.pb.go +++ b/x/market/types/market.pb.go @@ -5,7 +5,7 @@ package types import ( fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/market/types/odds.pb.go b/x/market/types/odds.pb.go index 5221d543..13713231 100644 --- a/x/market/types/odds.pb.go +++ b/x/market/types/odds.pb.go @@ -5,7 +5,7 @@ package types import ( fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/market/types/params.pb.go b/x/market/types/params.pb.go index e6990781..b8afdd91 100644 --- a/x/market/types/params.pb.go +++ b/x/market/types/params.pb.go @@ -5,7 +5,7 @@ package types import ( fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/market/types/query.pb.go b/x/market/types/query.pb.go index e1a30d88..9e954c53 100644 --- a/x/market/types/query.pb.go +++ b/x/market/types/query.pb.go @@ -7,7 +7,7 @@ import ( context "context" fmt "fmt" query "github.com/cosmos/cosmos-sdk/types/query" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" _ "google.golang.org/genproto/googleapis/api/annotations" diff --git a/x/market/types/query.pb.gw.go b/x/market/types/query.pb.gw.go index f078ca9d..be2302a8 100644 --- a/x/market/types/query.pb.gw.go +++ b/x/market/types/query.pb.gw.go @@ -418,13 +418,13 @@ 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{"sge", "market", "params"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"sge", "market", "params"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_Market_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"sge", "market", "uid"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_Market_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"sge", "market", "uid"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_Markets_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"sge", "market", "markets"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_Markets_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"sge", "market", "markets"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_MarketsByUIDs_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"sge", "market", "markets_by_uids", "uids"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_MarketsByUIDs_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"sge", "market", "markets_by_uids", "uids"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( diff --git a/x/market/types/ticket.pb.go b/x/market/types/ticket.pb.go index 04b494c5..7c0e3bc1 100644 --- a/x/market/types/ticket.pb.go +++ b/x/market/types/ticket.pb.go @@ -5,7 +5,7 @@ package types import ( fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/market/types/tx.pb.go b/x/market/types/tx.pb.go index 5242ffb8..4417dde6 100644 --- a/x/market/types/tx.pb.go +++ b/x/market/types/tx.pb.go @@ -6,7 +6,7 @@ package types import ( context "context" fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" grpc "google.golang.org/grpc" diff --git a/x/mint/types/genesis.pb.go b/x/mint/types/genesis.pb.go index b24a0985..d48ba8d1 100644 --- a/x/mint/types/genesis.pb.go +++ b/x/mint/types/genesis.pb.go @@ -5,7 +5,7 @@ package types import ( fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/mint/types/minter.pb.go b/x/mint/types/minter.pb.go index 0a7b25c3..96d27e8b 100644 --- a/x/mint/types/minter.pb.go +++ b/x/mint/types/minter.pb.go @@ -6,7 +6,7 @@ package types import ( fmt "fmt" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/mint/types/params.pb.go b/x/mint/types/params.pb.go index 37683c47..41a365ae 100644 --- a/x/mint/types/params.pb.go +++ b/x/mint/types/params.pb.go @@ -6,7 +6,7 @@ package types import ( fmt "fmt" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/mint/types/phase.pb.go b/x/mint/types/phase.pb.go index d75e02ad..151c38f3 100644 --- a/x/mint/types/phase.pb.go +++ b/x/mint/types/phase.pb.go @@ -6,7 +6,7 @@ package types import ( fmt "fmt" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/mint/types/query.pb.go b/x/mint/types/query.pb.go index 7c8df81b..d5b8ca5e 100644 --- a/x/mint/types/query.pb.go +++ b/x/mint/types/query.pb.go @@ -7,7 +7,7 @@ import ( context "context" fmt "fmt" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" _ "google.golang.org/genproto/googleapis/api/annotations" diff --git a/x/mint/types/query.pb.gw.go b/x/mint/types/query.pb.gw.go index 3ba92606..ce3ff122 100644 --- a/x/mint/types/query.pb.gw.go +++ b/x/mint/types/query.pb.gw.go @@ -389,15 +389,15 @@ 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{"sge", "mint", "params"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"sge", "mint", "params"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_Inflation_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "mint", "v1beta1", "inflation"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_Inflation_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "mint", "v1beta1", "inflation"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_PhaseStep_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "mint", "v1beta1", "phasestep"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_PhaseStep_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "mint", "v1beta1", "phasestep"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_PhaseProvisions_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "mint", "v1beta1", "phase_provisions"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_PhaseProvisions_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "mint", "v1beta1", "phase_provisions"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_EndPhaseStatus_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "mint", "v1beta1", "endphase_status"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_EndPhaseStatus_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "mint", "v1beta1", "endphase_status"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( diff --git a/x/orderbook/keeper/bet_settle.go b/x/orderbook/keeper/bet_settle.go index dbbd2a11..5a019c72 100644 --- a/x/orderbook/keeper/bet_settle.go +++ b/x/orderbook/keeper/bet_settle.go @@ -38,8 +38,8 @@ func (k Keeper) RefundBettor( func (k Keeper) BettorWins( ctx sdk.Context, bettorAddress sdk.AccAddress, - _ sdk.Int, - _ sdk.Int, + betAmount sdk.Int, + payoutProfit sdk.Int, _ string, betFulfillments []*bettypes.BetFulfillment, orderBookUID string, @@ -84,8 +84,8 @@ func (k Keeper) BettorWins( // adds the bet amount to the actual profit of the participation // for each of the bet fulfillment records and, // removes the payout lock. -func (k Keeper) BettorLoses(ctx sdk.Context, _ sdk.AccAddress, - _ sdk.Int, +func (k Keeper) BettorLoses(ctx sdk.Context, address sdk.AccAddress, + betAmount sdk.Int, _ sdk.Int, _ string, betFulfillments []*bettypes.BetFulfillment, diff --git a/x/orderbook/types/exposure.pb.go b/x/orderbook/types/exposure.pb.go index 69f69fc1..9b8f8885 100644 --- a/x/orderbook/types/exposure.pb.go +++ b/x/orderbook/types/exposure.pb.go @@ -6,7 +6,7 @@ package types import ( fmt "fmt" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/orderbook/types/genesis.pb.go b/x/orderbook/types/genesis.pb.go index 48a1e11c..192e9abb 100644 --- a/x/orderbook/types/genesis.pb.go +++ b/x/orderbook/types/genesis.pb.go @@ -5,7 +5,7 @@ package types import ( fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/orderbook/types/orderbook.pb.go b/x/orderbook/types/orderbook.pb.go index 7a7a606b..2915dc3a 100644 --- a/x/orderbook/types/orderbook.pb.go +++ b/x/orderbook/types/orderbook.pb.go @@ -5,7 +5,7 @@ package types import ( fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/orderbook/types/params.pb.go b/x/orderbook/types/params.pb.go index a603d07d..e8d4d430 100644 --- a/x/orderbook/types/params.pb.go +++ b/x/orderbook/types/params.pb.go @@ -5,7 +5,7 @@ package types import ( fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/orderbook/types/participation.pb.go b/x/orderbook/types/participation.pb.go index 77d2154a..a453156c 100644 --- a/x/orderbook/types/participation.pb.go +++ b/x/orderbook/types/participation.pb.go @@ -6,7 +6,7 @@ package types import ( fmt "fmt" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/orderbook/types/query.pb.go b/x/orderbook/types/query.pb.go index a58a48c7..55bf6e8d 100644 --- a/x/orderbook/types/query.pb.go +++ b/x/orderbook/types/query.pb.go @@ -7,7 +7,7 @@ import ( context "context" fmt "fmt" query "github.com/cosmos/cosmos-sdk/types/query" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" _ "google.golang.org/genproto/googleapis/api/annotations" diff --git a/x/orderbook/types/query.pb.gw.go b/x/orderbook/types/query.pb.gw.go index 6091038a..b3472daf 100644 --- a/x/orderbook/types/query.pb.gw.go +++ b/x/orderbook/types/query.pb.gw.go @@ -1329,27 +1329,27 @@ 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{"sge", "orderbook", "params"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"sge", "orderbook", "params"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_OrderBooks_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"sge", "orderbook", "status"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_OrderBooks_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"sge", "orderbook", "status"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_OrderBook_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"sge", "orderbook", "order_book_uid"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_OrderBook_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"sge", "orderbook", "order_book_uid"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_OrderBookParticipations_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3}, []string{"sge", "orderbook", "order_book_uid", "participations"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_OrderBookParticipations_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3}, []string{"sge", "orderbook", "order_book_uid", "participations"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_OrderBookParticipation_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"sge", "orderbook", "order_book_uid", "participations", "participation_index"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_OrderBookParticipation_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"sge", "orderbook", "order_book_uid", "participations", "participation_index"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_OrderBookExposures_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3}, []string{"sge", "orderbook", "order_book_uid", "exposures"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_OrderBookExposures_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3}, []string{"sge", "orderbook", "order_book_uid", "exposures"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_OrderBookExposure_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"sge", "orderbook", "order_book_uid", "exposures", "odds_uid"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_OrderBookExposure_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"sge", "orderbook", "order_book_uid", "exposures", "odds_uid"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_OrderBookParticipationExposures_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3}, []string{"sge", "orderbook", "order_book_uid", "participation-exposures"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_OrderBookParticipationExposures_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3}, []string{"sge", "orderbook", "order_book_uid", "participation-exposures"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_ParticipationExposures_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"sge", "orderbook", "order_book_uid", "participation-exposures", "participation_index"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_ParticipationExposures_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"sge", "orderbook", "order_book_uid", "participation-exposures", "participation_index"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_HistoricalParticipationExposures_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3}, []string{"sge", "orderbook", "order_book_uid", "historical-participation-exposures"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_HistoricalParticipationExposures_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3}, []string{"sge", "orderbook", "order_book_uid", "historical-participation-exposures"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_ParticipationFulfilledBets_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3, 1, 0, 4, 1, 5, 4, 2, 5}, []string{"sge", "orderbook", "order_book_uid", "participations", "participation_index", "fulfilled_bets"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_ParticipationFulfilledBets_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3, 1, 0, 4, 1, 5, 4, 2, 5}, []string{"sge", "orderbook", "order_book_uid", "participations", "participation_index", "fulfilled_bets"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( diff --git a/x/ovm/types/genesis.pb.go b/x/ovm/types/genesis.pb.go index 1a7378ca..7d6585ce 100644 --- a/x/ovm/types/genesis.pb.go +++ b/x/ovm/types/genesis.pb.go @@ -5,7 +5,7 @@ package types import ( fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/ovm/types/params.pb.go b/x/ovm/types/params.pb.go index 2fa89419..b1147ddd 100644 --- a/x/ovm/types/params.pb.go +++ b/x/ovm/types/params.pb.go @@ -5,7 +5,7 @@ package types import ( fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/ovm/types/proposal.pb.go b/x/ovm/types/proposal.pb.go index 0aa3fa4c..495f57da 100644 --- a/x/ovm/types/proposal.pb.go +++ b/x/ovm/types/proposal.pb.go @@ -5,7 +5,7 @@ package types import ( fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/ovm/types/query.pb.go b/x/ovm/types/query.pb.go index 10ee1e3d..2fb8cd60 100644 --- a/x/ovm/types/query.pb.go +++ b/x/ovm/types/query.pb.go @@ -7,7 +7,7 @@ import ( context "context" fmt "fmt" query "github.com/cosmos/cosmos-sdk/types/query" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" _ "google.golang.org/genproto/googleapis/api/annotations" diff --git a/x/ovm/types/query.pb.gw.go b/x/ovm/types/query.pb.gw.go index 52c43071..376dcd1b 100644 --- a/x/ovm/types/query.pb.gw.go +++ b/x/ovm/types/query.pb.gw.go @@ -452,13 +452,13 @@ 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{"sge", "ovm", "params"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"sge", "ovm", "params"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_PubKeys_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"sge", "ovm", "pub_keys"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_PubKeys_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"sge", "ovm", "pub_keys"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_PublicKeysChangeProposal_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 1, 0, 4, 1, 5, 4}, []string{"sge", "ovm", "pubkeys_proposal", "status", "id"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_PublicKeysChangeProposal_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 1, 0, 4, 1, 5, 4}, []string{"sge", "ovm", "pubkeys_proposal", "status", "id"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_PublicKeysChangeProposals_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"sge", "ovm", "pubkeys_proposals", "status"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_PublicKeysChangeProposals_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"sge", "ovm", "pubkeys_proposals", "status"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( diff --git a/x/subaccount/keeper/keeper.go b/x/subaccount/keeper/keeper.go index 5ad80a53..1904b78f 100644 --- a/x/subaccount/keeper/keeper.go +++ b/x/subaccount/keeper/keeper.go @@ -12,7 +12,7 @@ import ( type BetKeeper interface { GetBetID(ctx sdk.Context, uid string) (bettypes.UID2ID, bool) - PlaceBet(ctx sdk.Context, bet *bettypes.Bet) error + Wager(ctx sdk.Context, bet *bettypes.Bet) error } type BankKeeper interface { diff --git a/x/subaccount/keeper/msg_server_bet.go b/x/subaccount/keeper/msg_server_bet.go index efc51cab..f84ad6e3 100644 --- a/x/subaccount/keeper/msg_server_bet.go +++ b/x/subaccount/keeper/msg_server_bet.go @@ -11,7 +11,7 @@ import ( "google.golang.org/grpc/status" ) -func (m msgServer) PlaceBet(goCtx context.Context, msg *types.MsgPlaceBet) (*types.MsgPlaceBetResponse, error) { +func (m msgServer) Wager(goCtx context.Context, msg *types.MsgWager) (*types.MsgWagerResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) // find subaccount @@ -23,13 +23,13 @@ func (m msgServer) PlaceBet(goCtx context.Context, msg *types.MsgPlaceBet) (*typ // TODO: duplicate code from x/bet/keeper/msg_server_bet.go // Check if the value already exists - _, isFound := m.keeper.betKeeper.GetBetID(ctx, msg.Msg.Bet.UID) + _, isFound := m.keeper.betKeeper.GetBetID(ctx, msg.Msg.Props.UID) if isFound { - return nil, sdkerrors.Wrapf(bettypes.ErrDuplicateUID, "%s", msg.Msg.Bet.UID) + return nil, sdkerrors.Wrapf(bettypes.ErrDuplicateUID, "%s", msg.Msg.Props.UID) } - payload := &bettypes.BetPlacementTicketPayload{} - err := m.keeper.ovmKeeper.VerifyTicketUnmarshal(sdk.WrapSDKContext(ctx), msg.Msg.Bet.Ticket, &payload) + payload := &bettypes.WagerTicketPayload{} + err := m.keeper.ovmKeeper.VerifyTicketUnmarshal(sdk.WrapSDKContext(ctx), msg.Msg.Props.Ticket, &payload) if err != nil { return nil, sdkerrors.Wrapf(bettypes.ErrInTicketVerification, "%s", err) } @@ -43,7 +43,7 @@ func (m msgServer) PlaceBet(goCtx context.Context, msg *types.MsgPlaceBet) (*typ // duplication end // here we swap the original sender with the subaccount address - bet := bettypes.NewBet(subAccountAddress.String(), msg.Msg.Bet, payload.OddsType, payload.SelectedOdds) + bet := bettypes.NewBet(subAccountAddress.String(), msg.Msg.Props, payload.OddsType, payload.SelectedOdds) // make subaccount balance adjustments balance, exists := m.keeper.GetBalance(ctx, subAccountAddress) @@ -56,16 +56,16 @@ func (m msgServer) PlaceBet(goCtx context.Context, msg *types.MsgPlaceBet) (*typ return nil, err } - if err := m.keeper.betKeeper.PlaceBet(ctx, bet); err != nil { - return nil, sdkerrors.Wrapf(bettypes.ErrInBetPlacement, "%s", err) + if err := m.keeper.betKeeper.Wager(ctx, bet); err != nil { + return nil, sdkerrors.Wrapf(bettypes.ErrInWager, "%s", err) } m.keeper.SetBalance(ctx, subAccountAddress, balance) msg.Msg.EmitEvent(&ctx) - return &types.MsgPlaceBetResponse{ - Response: &bettypes.MsgPlaceBetResponse{Bet: msg.Msg.Bet}, + return &types.MsgWagerResponse{ + Response: &bettypes.MsgWagerResponse{Props: msg.Msg.Props}, }, nil } diff --git a/x/subaccount/keeper/msg_server_bet_test.go b/x/subaccount/keeper/msg_server_bet_test.go index b056c8bc..9397499a 100644 --- a/x/subaccount/keeper/msg_server_bet_test.go +++ b/x/subaccount/keeper/msg_server_bet_test.go @@ -76,9 +76,9 @@ func TestMsgServer_Bet(t *testing.T) { // start betting using the subaccount betAmt := sdk.NewInt(1000).Mul(micro) - _, err = msgServer.PlaceBet( + _, err = msgServer.Wager( sdk.WrapSDKContext(ctx), - &types.MsgPlaceBet{Msg: testBet(t, subAccOwner, betAmt)}, + &types.MsgWager{Msg: testBet(t, subAccOwner, betAmt)}, ) require.NoError(t, err) @@ -91,7 +91,7 @@ func TestMsgServer_Bet(t *testing.T) { t.Run("resolve market – better wins", func(t *testing.T) { ctx, _ := ctx.CacheContext() // resolve the market – better wins - app.MarketKeeper.ResolveMarket(ctx, *market, &markettypes.MarketResolutionTicketPayload{ + app.MarketKeeper.Resolve(ctx, *market, &markettypes.MarketResolutionTicketPayload{ UID: market.UID, ResolutionTS: uint64(ctx.BlockTime().Unix()) + 10000, WinnerOddsUIDs: []string{testOddsUID1}, @@ -103,7 +103,7 @@ func TestMsgServer_Bet(t *testing.T) { // now we check the subaccount balance balance, exists := k.GetBalance(ctx, subAccAddr) require.True(t, exists) - require.Equal(t, balance.SpentAmount, sdk.ZeroInt()) + require.Equal(t, balance.SpentAmount.String(), sdk.ZeroInt().String()) // now we want the user to have some balance which is the payout ownerBalance := app.BankKeeper.GetAllBalances(ctx, subAccOwner) @@ -120,7 +120,7 @@ func TestMsgServer_Bet(t *testing.T) { t.Run("resolve market – better loses", func(t *testing.T) { ctx, _ := ctx.CacheContext() // resolve the market – better loses - app.MarketKeeper.ResolveMarket(ctx, *market, &markettypes.MarketResolutionTicketPayload{ + app.MarketKeeper.Resolve(ctx, *market, &markettypes.MarketResolutionTicketPayload{ UID: market.UID, ResolutionTS: uint64(ctx.BlockTime().Unix()) + 10000, WinnerOddsUIDs: []string{testOddsUID2}, @@ -141,7 +141,7 @@ func TestMsgServer_Bet(t *testing.T) { t.Run("resolve market – refund", func(t *testing.T) { ctx, _ := ctx.CacheContext() // resolve the market – refund - app.MarketKeeper.ResolveMarket(ctx, *market, &markettypes.MarketResolutionTicketPayload{ + app.MarketKeeper.Resolve(ctx, *market, &markettypes.MarketResolutionTicketPayload{ UID: market.UID, ResolutionTS: uint64(ctx.BlockTime().Unix()) + 10000, WinnerOddsUIDs: []string{testOddsUID1}, @@ -175,13 +175,13 @@ func addTestMarket(t testing.TB, tApp *simappUtil.TestApp, ctx sdk.Context, pref testAddMarketTicket, err := createJwtTicket(testAddMarketClaim) require.Nil(t, err) - testAddMarket := &markettypes.MsgAddMarket{ + testAddMarket := &markettypes.MsgAdd{ Creator: testCreator, Ticket: testAddMarketTicket, } wctx := sdk.WrapSDKContext(ctx) marketSrv := marketkeeper.NewMsgServerImpl(*tApp.MarketKeeper) - resAddMarket, err := marketSrv.AddMarket(wctx, testAddMarket) + resAddMarket, err := marketSrv.Add(wctx, testAddMarket) require.Nil(t, err) require.NotNil(t, resAddMarket) @@ -211,7 +211,7 @@ func createJwtTicket(claim jwt.MapClaims) (string, error) { return token.SignedString(simappUtil.TestOVMPrivateKeys[0]) } -func testBet(t testing.TB, better sdk.AccAddress, amount sdk.Int) *bettypes.MsgPlaceBet { +func testBet(t testing.TB, better sdk.AccAddress, amount sdk.Int) *bettypes.MsgWager { ticket, err := createJwtTicket(jwt.MapClaims{ "exp": 9999999999, "iat": 7777777777, @@ -224,9 +224,9 @@ func testBet(t testing.TB, better sdk.AccAddress, amount sdk.Int) *bettypes.MsgP }) require.NoError(t, err) - return &bettypes.MsgPlaceBet{ + return &bettypes.MsgWager{ Creator: better.String(), - Bet: &bettypes.PlaceBetFields{ + Props: &bettypes.WagerProps{ UID: uuid.NewString(), Amount: amount, Ticket: ticket, diff --git a/x/subaccount/keeper/msg_server_house_test.go b/x/subaccount/keeper/msg_server_house_test.go index 5b900fa1..ec1f6e62 100644 --- a/x/subaccount/keeper/msg_server_house_test.go +++ b/x/subaccount/keeper/msg_server_house_test.go @@ -73,14 +73,14 @@ func TestMsgServer(t *testing.T) { // place bet betMsgServer := betmodulekeeper.NewMsgServerImpl(*app.BetKeeper) - _, err = betMsgServer.PlaceBet(sdk.WrapSDKContext(ctx), testBet(t, bettor1, bettor1Funds)) + _, err = betMsgServer.Wager(sdk.WrapSDKContext(ctx), testBet(t, bettor1, bettor1Funds)) require.NoError(t, err) participateFee := app.HouseKeeper.GetHouseParticipationFee(ctx).Mul(deposit.ToDec()).TruncateInt() t.Run("house wins", func(t *testing.T) { ctx, _ := ctx.CacheContext() - app.MarketKeeper.ResolveMarket(ctx, *market, &markettypes.MarketResolutionTicketPayload{ + app.MarketKeeper.Resolve(ctx, *market, &markettypes.MarketResolutionTicketPayload{ UID: market.UID, ResolutionTS: uint64(ctx.BlockTime().Unix()) + 10000, WinnerOddsUIDs: []string{testOddsUID2}, @@ -103,7 +103,7 @@ func TestMsgServer(t *testing.T) { t.Run("house loses", func(t *testing.T) { ctx, _ := ctx.CacheContext() - app.MarketKeeper.ResolveMarket(ctx, *market, &markettypes.MarketResolutionTicketPayload{ + app.MarketKeeper.Resolve(ctx, *market, &markettypes.MarketResolutionTicketPayload{ UID: market.UID, ResolutionTS: uint64(ctx.BlockTime().Unix()) + 10000, WinnerOddsUIDs: []string{testOddsUID1}, @@ -126,7 +126,7 @@ func TestMsgServer(t *testing.T) { }) t.Run("house refund", func(t *testing.T) { ctx, _ := ctx.CacheContext() - app.MarketKeeper.ResolveMarket(ctx, *market, &markettypes.MarketResolutionTicketPayload{ + app.MarketKeeper.Resolve(ctx, *market, &markettypes.MarketResolutionTicketPayload{ UID: market.UID, ResolutionTS: uint64(ctx.BlockTime().Unix()) + 10000, WinnerOddsUIDs: []string{testOddsUID1}, diff --git a/x/subaccount/types/genesis.pb.go b/x/subaccount/types/genesis.pb.go index 28a1118f..e61b6d7e 100644 --- a/x/subaccount/types/genesis.pb.go +++ b/x/subaccount/types/genesis.pb.go @@ -5,7 +5,7 @@ package types import ( fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/subaccount/types/msg.go b/x/subaccount/types/msg.go index 8be101ec..84aa7575 100644 --- a/x/subaccount/types/msg.go +++ b/x/subaccount/types/msg.go @@ -10,7 +10,7 @@ var ( _ sdk.Msg = &MsgCreateSubAccount{} _ sdk.Msg = &MsgTopUp{} _ sdk.Msg = &MsgWithdrawUnlockedBalances{} - _ sdk.Msg = &MsgPlaceBet{} + _ sdk.Msg = &MsgWager{} ) func (msg *MsgCreateSubAccount) GetSigners() []sdk.AccAddress { @@ -88,14 +88,14 @@ func (msg *MsgWithdrawUnlockedBalances) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{signer} } -func (m *MsgPlaceBet) ValidateBasic() error { +func (m *MsgWager) ValidateBasic() error { if m.Msg == nil { return sdkerrors.ErrInvalidRequest.Wrap("msg is nil") } return m.Msg.ValidateBasic() } -func (m *MsgPlaceBet) GetSigners() []sdk.AccAddress { +func (m *MsgWager) GetSigners() []sdk.AccAddress { return m.Msg.GetSigners() } diff --git a/x/subaccount/types/params.pb.go b/x/subaccount/types/params.pb.go index 64bfaacb..22637f2d 100644 --- a/x/subaccount/types/params.pb.go +++ b/x/subaccount/types/params.pb.go @@ -5,7 +5,7 @@ package types import ( fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" diff --git a/x/subaccount/types/subaccount.pb.go b/x/subaccount/types/subaccount.pb.go index 4061409d..dd2b656c 100644 --- a/x/subaccount/types/subaccount.pb.go +++ b/x/subaccount/types/subaccount.pb.go @@ -6,10 +6,10 @@ package types import ( fmt "fmt" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" + _ "github.com/gogo/protobuf/types" github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" - _ "google.golang.org/protobuf/types/known/timestamppb" io "io" math "math" math_bits "math/bits" diff --git a/x/subaccount/types/tx.pb.go b/x/subaccount/types/tx.pb.go index fc6ebfbd..1036932f 100644 --- a/x/subaccount/types/tx.pb.go +++ b/x/subaccount/types/tx.pb.go @@ -315,22 +315,22 @@ func (m *MsgWithdrawUnlockedBalancesResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgWithdrawUnlockedBalancesResponse proto.InternalMessageInfo // MsgPlaceBet wraps the MsgPlaceBet message. We need it in order not to have double interface registration conflicts. -type MsgPlaceBet struct { - Msg *types.MsgPlaceBet `protobuf:"bytes,1,opt,name=msg,proto3" json:"msg,omitempty"` +type MsgWager struct { + Msg *types.MsgWager `protobuf:"bytes,1,opt,name=msg,proto3" json:"msg,omitempty"` } -func (m *MsgPlaceBet) Reset() { *m = MsgPlaceBet{} } -func (m *MsgPlaceBet) String() string { return proto.CompactTextString(m) } -func (*MsgPlaceBet) ProtoMessage() {} -func (*MsgPlaceBet) Descriptor() ([]byte, []int) { +func (m *MsgWager) Reset() { *m = MsgWager{} } +func (m *MsgWager) String() string { return proto.CompactTextString(m) } +func (*MsgWager) ProtoMessage() {} +func (*MsgWager) Descriptor() ([]byte, []int) { return fileDescriptor_e042e836d366badb, []int{6} } -func (m *MsgPlaceBet) XXX_Unmarshal(b []byte) error { +func (m *MsgWager) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgPlaceBet) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgWager) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgPlaceBet.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgWager.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -340,19 +340,19 @@ func (m *MsgPlaceBet) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) return b[:n], nil } } -func (m *MsgPlaceBet) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgPlaceBet.Merge(m, src) +func (m *MsgWager) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgWager.Merge(m, src) } -func (m *MsgPlaceBet) XXX_Size() int { +func (m *MsgWager) XXX_Size() int { return m.Size() } -func (m *MsgPlaceBet) XXX_DiscardUnknown() { - xxx_messageInfo_MsgPlaceBet.DiscardUnknown(m) +func (m *MsgWager) XXX_DiscardUnknown() { + xxx_messageInfo_MsgWager.DiscardUnknown(m) } -var xxx_messageInfo_MsgPlaceBet proto.InternalMessageInfo +var xxx_messageInfo_MsgWager proto.InternalMessageInfo -func (m *MsgPlaceBet) GetMsg() *types.MsgPlaceBet { +func (m *MsgWager) GetMsg() *types.MsgWager { if m != nil { return m.Msg } @@ -360,22 +360,22 @@ func (m *MsgPlaceBet) GetMsg() *types.MsgPlaceBet { } // MsgBetResponse wraps the MsgPlaceBetResponse message. We need it in order not to have double interface registration conflicts. -type MsgPlaceBetResponse struct { - Response *types.MsgPlaceBetResponse `protobuf:"bytes,1,opt,name=response,proto3" json:"response,omitempty"` +type MsgWagerResponse struct { + Response *types.MsgWagerResponse `protobuf:"bytes,1,opt,name=response,proto3" json:"response,omitempty"` } -func (m *MsgPlaceBetResponse) Reset() { *m = MsgPlaceBetResponse{} } -func (m *MsgPlaceBetResponse) String() string { return proto.CompactTextString(m) } -func (*MsgPlaceBetResponse) ProtoMessage() {} -func (*MsgPlaceBetResponse) Descriptor() ([]byte, []int) { +func (m *MsgWagerResponse) Reset() { *m = MsgWagerResponse{} } +func (m *MsgWagerResponse) String() string { return proto.CompactTextString(m) } +func (*MsgWagerResponse) ProtoMessage() {} +func (*MsgWagerResponse) Descriptor() ([]byte, []int) { return fileDescriptor_e042e836d366badb, []int{7} } -func (m *MsgPlaceBetResponse) XXX_Unmarshal(b []byte) error { +func (m *MsgWagerResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgPlaceBetResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgWagerResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgPlaceBetResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgWagerResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -385,19 +385,19 @@ func (m *MsgPlaceBetResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, return b[:n], nil } } -func (m *MsgPlaceBetResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgPlaceBetResponse.Merge(m, src) +func (m *MsgWagerResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgWagerResponse.Merge(m, src) } -func (m *MsgPlaceBetResponse) XXX_Size() int { +func (m *MsgWagerResponse) XXX_Size() int { return m.Size() } -func (m *MsgPlaceBetResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgPlaceBetResponse.DiscardUnknown(m) +func (m *MsgWagerResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgWagerResponse.DiscardUnknown(m) } -var xxx_messageInfo_MsgPlaceBetResponse proto.InternalMessageInfo +var xxx_messageInfo_MsgWagerResponse proto.InternalMessageInfo -func (m *MsgPlaceBetResponse) GetResponse() *types.MsgPlaceBetResponse { +func (m *MsgWagerResponse) GetResponse() *types.MsgWagerResponse { if m != nil { return m.Response } @@ -591,8 +591,8 @@ func init() { proto.RegisterType((*MsgTopUpResponse)(nil), "sgenetwork.sge.subaccount.MsgTopUpResponse") proto.RegisterType((*MsgWithdrawUnlockedBalances)(nil), "sgenetwork.sge.subaccount.MsgWithdrawUnlockedBalances") proto.RegisterType((*MsgWithdrawUnlockedBalancesResponse)(nil), "sgenetwork.sge.subaccount.MsgWithdrawUnlockedBalancesResponse") - proto.RegisterType((*MsgPlaceBet)(nil), "sgenetwork.sge.subaccount.MsgPlaceBet") - proto.RegisterType((*MsgPlaceBetResponse)(nil), "sgenetwork.sge.subaccount.MsgPlaceBetResponse") + proto.RegisterType((*MsgWager)(nil), "sgenetwork.sge.subaccount.MsgWager") + proto.RegisterType((*MsgWagerResponse)(nil), "sgenetwork.sge.subaccount.MsgWagerResponse") proto.RegisterType((*MsgHouseDeposit)(nil), "sgenetwork.sge.subaccount.MsgHouseDeposit") proto.RegisterType((*MsgHouseDepositResponse)(nil), "sgenetwork.sge.subaccount.MsgHouseDepositResponse") proto.RegisterType((*MsgHouseWithdraw)(nil), "sgenetwork.sge.subaccount.MsgHouseWithdraw") @@ -602,44 +602,44 @@ func init() { func init() { proto.RegisterFile("sge/subaccount/tx.proto", fileDescriptor_e042e836d366badb) } var fileDescriptor_e042e836d366badb = []byte{ - // 587 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x95, 0xcf, 0x6e, 0x12, 0x51, - 0x14, 0xc6, 0x19, 0x49, 0x1b, 0x3c, 0xa8, 0xe0, 0x35, 0xb1, 0x38, 0xc6, 0x01, 0xa7, 0x51, 0xb1, - 0x4d, 0x87, 0x08, 0xd1, 0xa5, 0x51, 0xda, 0xa6, 0x2e, 0x24, 0x2a, 0xda, 0x18, 0xbb, 0x21, 0x33, - 0xc3, 0xcd, 0x85, 0x94, 0xce, 0x1d, 0xe7, 0xcc, 0x84, 0xea, 0x53, 0x18, 0x17, 0x3e, 0x85, 0x0f, - 0xe0, 0x23, 0xb8, 0xec, 0xd2, 0xa5, 0x81, 0x17, 0x31, 0xf3, 0xef, 0x32, 0x40, 0x07, 0xa8, 0x49, - 0x77, 0x77, 0x6e, 0xbe, 0xef, 0x3b, 0xbf, 0x03, 0xe7, 0xe4, 0xc2, 0x06, 0x32, 0x5a, 0x43, 0xcf, - 0xd0, 0x4d, 0x93, 0x7b, 0x96, 0x5b, 0x73, 0x4f, 0x35, 0xdb, 0xe1, 0x2e, 0x27, 0x77, 0x90, 0x51, - 0x8b, 0xba, 0x43, 0xee, 0x1c, 0x6b, 0xc8, 0xa8, 0x36, 0xd1, 0xc8, 0xe5, 0x19, 0xcf, 0xe4, 0x18, - 0x7a, 0xe5, 0xa2, 0x2f, 0x30, 0xe8, 0x24, 0x4d, 0x26, 0xfe, 0x4d, 0x8f, 0x7b, 0x48, 0xc5, 0x9d, - 0xfa, 0x53, 0x82, 0x5b, 0x2d, 0x64, 0xbb, 0x0e, 0xd5, 0x5d, 0xfa, 0xde, 0x33, 0x5e, 0x86, 0x19, - 0xe4, 0x36, 0xac, 0x23, 0xb5, 0xba, 0xd4, 0x29, 0x49, 0x15, 0xa9, 0x7a, 0xb5, 0x1d, 0x7d, 0x91, - 0x2d, 0xb8, 0x89, 0x9e, 0xd1, 0x89, 0x4a, 0x75, 0xf8, 0xd0, 0xa2, 0x4e, 0xe9, 0x4a, 0x20, 0x29, - 0xa0, 0xb0, 0xbf, 0xf1, 0xaf, 0xc9, 0x3b, 0x28, 0x0c, 0xb8, 0x79, 0x4c, 0xbb, 0x1d, 0x43, 0x1f, - 0xe8, 0x96, 0x49, 0xb1, 0x94, 0xad, 0x64, 0xab, 0xf9, 0x7a, 0x55, 0x4b, 0xed, 0x4b, 0x7b, 0x1d, - 0x38, 0x9a, 0xa1, 0xa1, 0x7d, 0x63, 0x90, 0xfc, 0x44, 0xf5, 0x1e, 0xdc, 0x3d, 0x87, 0xb6, 0x4d, - 0xd1, 0xe6, 0x16, 0x52, 0xf5, 0x87, 0x04, 0xb9, 0x16, 0xb2, 0x0f, 0xdc, 0x3e, 0xb4, 0x53, 0x5b, - 0x28, 0x43, 0x3e, 0xd1, 0x42, 0x04, 0x0f, 0x13, 0xf8, 0xcb, 0xe0, 0x26, 0x50, 0x8c, 0xb9, 0x04, - 0xec, 0xd3, 0xa0, 0x97, 0x8f, 0x7d, 0xb7, 0xd7, 0x75, 0xf4, 0xe1, 0xa1, 0x35, 0x6d, 0x49, 0xc3, - 0x57, 0x1f, 0xc0, 0xe6, 0x02, 0x9b, 0x48, 0x7f, 0x01, 0xf9, 0x16, 0xb2, 0xb7, 0x03, 0xdd, 0xa4, - 0x4d, 0xea, 0x92, 0x27, 0x90, 0x3d, 0x41, 0x16, 0x44, 0xe5, 0xeb, 0xe5, 0xd9, 0x3e, 0x0c, 0xea, - 0x6a, 0x09, 0x75, 0xdb, 0xd7, 0xaa, 0x47, 0xc1, 0x64, 0x88, 0xbb, 0x28, 0x98, 0xec, 0x42, 0xce, - 0x89, 0xce, 0x51, 0xdc, 0xa3, 0x65, 0x71, 0x91, 0xbc, 0x2d, 0x8c, 0xea, 0x3e, 0x14, 0x5a, 0xc8, - 0x5e, 0xf9, 0xb3, 0xb8, 0x47, 0x6d, 0x8e, 0x7d, 0x97, 0xd4, 0x93, 0x84, 0x95, 0xd9, 0xc8, 0x60, - 0x6c, 0xfd, 0xd0, 0x48, 0x1e, 0x22, 0x76, 0x60, 0x63, 0x26, 0x46, 0x60, 0xee, 0xcd, 0x61, 0x56, - 0x97, 0x66, 0xce, 0x73, 0x1e, 0x04, 0xff, 0x5b, 0x50, 0x20, 0xfe, 0xc5, 0x49, 0x23, 0x09, 0x7a, - 0x3f, 0x35, 0x34, 0xd6, 0x87, 0xa4, 0x3a, 0x94, 0x66, 0x83, 0x04, 0xea, 0xfe, 0x1c, 0xea, 0xe3, - 0xe5, 0xa9, 0x73, 0xac, 0xf5, 0x5f, 0x6b, 0x90, 0x6d, 0x21, 0x23, 0x5f, 0xa1, 0x38, 0xb7, 0xce, - 0xda, 0x82, 0xc9, 0x3d, 0x67, 0xa1, 0xe4, 0x67, 0x17, 0xd3, 0x8b, 0x56, 0x3e, 0xc1, 0x5a, 0xb8, - 0x7c, 0x9b, 0x8b, 0x03, 0x02, 0x91, 0xbc, 0xbd, 0x82, 0x48, 0x44, 0x7f, 0x97, 0xa0, 0x94, 0xba, - 0x2c, 0x4b, 0x78, 0xd3, 0x7c, 0xf2, 0xf3, 0xff, 0xf3, 0x09, 0x28, 0x03, 0x72, 0x62, 0xc5, 0x1e, - 0x2e, 0xce, 0x8a, 0x75, 0xb2, 0xb6, 0x9a, 0x4e, 0xd4, 0xb0, 0xe0, 0xda, 0xd4, 0xa2, 0x6c, 0x2d, - 0xf6, 0x27, 0xb5, 0x72, 0x7d, 0x75, 0xad, 0xa8, 0xf7, 0x19, 0xae, 0x4f, 0x0f, 0xfc, 0xf6, 0x0a, - 0x21, 0xb1, 0x58, 0x6e, 0x5c, 0x40, 0x1c, 0x97, 0x6c, 0x1e, 0xfc, 0x1e, 0x29, 0xd2, 0xd9, 0x48, - 0x91, 0xfe, 0x8e, 0x14, 0xe9, 0xdb, 0x58, 0xc9, 0x9c, 0x8d, 0x95, 0xcc, 0x9f, 0xb1, 0x92, 0x39, - 0xda, 0x61, 0x7d, 0xb7, 0xe7, 0x19, 0x9a, 0xc9, 0x4f, 0x6a, 0xc8, 0xe8, 0x4e, 0x94, 0xec, 0x9f, - 0x6b, 0xa7, 0x53, 0x6f, 0xe6, 0x17, 0x9b, 0xa2, 0xb1, 0x1e, 0xbc, 0x6a, 0x8d, 0x7f, 0x01, 0x00, - 0x00, 0xff, 0xff, 0xb9, 0x2f, 0x73, 0x07, 0x52, 0x07, 0x00, 0x00, + // 579 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x95, 0x41, 0x6e, 0xd3, 0x40, + 0x18, 0x85, 0x63, 0xa2, 0x56, 0xe5, 0x0f, 0x90, 0x30, 0x48, 0x34, 0x18, 0x70, 0x83, 0x0b, 0x52, + 0x68, 0x55, 0x47, 0x4a, 0x04, 0x0b, 0x16, 0x08, 0x4a, 0xab, 0xb2, 0x20, 0x42, 0x84, 0x56, 0x15, + 0x6c, 0x22, 0x3b, 0x19, 0x4d, 0xa2, 0xa6, 0x1e, 0xe3, 0xdf, 0x56, 0x0a, 0xa7, 0x40, 0x2c, 0x38, + 0x05, 0x12, 0xd7, 0x60, 0xd9, 0x25, 0x4b, 0x94, 0x5c, 0x04, 0x79, 0x6c, 0x4f, 0x9c, 0xa4, 0x8e, + 0x53, 0x24, 0x76, 0xe3, 0xd1, 0x7b, 0x6f, 0xbe, 0x67, 0xcd, 0xaf, 0x81, 0x75, 0x64, 0xb4, 0x86, + 0xbe, 0x65, 0x76, 0x3a, 0xdc, 0xb7, 0xbd, 0x9a, 0x77, 0x66, 0x38, 0x2e, 0xf7, 0x38, 0xb9, 0x83, + 0x8c, 0xda, 0xd4, 0x1b, 0x72, 0xf7, 0xc4, 0x40, 0x46, 0x8d, 0x89, 0x46, 0xdd, 0x98, 0xf1, 0x4c, + 0x96, 0xa1, 0x57, 0x2d, 0x05, 0x02, 0x8b, 0x4e, 0xd2, 0x54, 0x12, 0xec, 0xf4, 0xb8, 0x8f, 0x54, + 0xee, 0xe9, 0x3f, 0x14, 0xb8, 0xd5, 0x44, 0xf6, 0xca, 0xa5, 0xa6, 0x47, 0xdf, 0xfb, 0xd6, 0xcb, + 0x30, 0x83, 0xdc, 0x86, 0x55, 0xa4, 0x76, 0x97, 0xba, 0x65, 0xa5, 0xa2, 0x54, 0xaf, 0xb6, 0xa2, + 0x2f, 0xb2, 0x05, 0x37, 0xd1, 0xb7, 0xda, 0xd1, 0x51, 0x6d, 0x3e, 0xb4, 0xa9, 0x5b, 0xbe, 0x22, + 0x24, 0x45, 0x94, 0xf6, 0xb7, 0xc1, 0x36, 0x79, 0x07, 0xc5, 0x01, 0xef, 0x9c, 0xd0, 0x6e, 0xdb, + 0x32, 0x07, 0xa6, 0xdd, 0xa1, 0x58, 0xce, 0x57, 0xf2, 0xd5, 0x42, 0xbd, 0x6a, 0xa4, 0xf6, 0x32, + 0xde, 0x08, 0xc7, 0x6e, 0x68, 0x68, 0xdd, 0x18, 0x24, 0x3f, 0x51, 0xbf, 0x0f, 0x77, 0x2f, 0xa0, + 0x6d, 0x51, 0x74, 0xb8, 0x8d, 0x54, 0xff, 0xae, 0xc0, 0x5a, 0x13, 0xd9, 0x21, 0x77, 0x8e, 0x9c, + 0xd4, 0x0a, 0x1b, 0x50, 0x48, 0x54, 0x88, 0xe0, 0x61, 0x02, 0xff, 0x3f, 0xb8, 0x09, 0x94, 0x62, + 0x2e, 0x09, 0xfb, 0x44, 0x74, 0x39, 0xee, 0x7b, 0xbd, 0xae, 0x6b, 0x0e, 0x8f, 0xec, 0x69, 0x4b, + 0x1a, 0xbe, 0xfe, 0x08, 0x36, 0x17, 0xd8, 0x64, 0xfa, 0x33, 0xf1, 0x27, 0x8e, 0x4d, 0x46, 0x5d, + 0x62, 0x40, 0xfe, 0x14, 0x99, 0xc8, 0x29, 0xd4, 0xef, 0xcd, 0x96, 0xb0, 0xa8, 0x67, 0xc4, 0xd2, + 0x56, 0x20, 0xd4, 0x0f, 0x05, 0x6d, 0xb8, 0x11, 0xe5, 0x91, 0x17, 0xb0, 0xe6, 0x46, 0xeb, 0x28, + 0xe8, 0xe1, 0xc2, 0xa0, 0x48, 0xdb, 0x92, 0x2e, 0x7d, 0x1f, 0x8a, 0x4d, 0x64, 0xaf, 0x83, 0xfb, + 0xb7, 0x47, 0x1d, 0x8e, 0x7d, 0x8f, 0xd4, 0x93, 0x60, 0x95, 0xd9, 0x3c, 0x71, 0x55, 0x83, 0xc4, + 0x48, 0x1e, 0xc2, 0xb5, 0x61, 0x7d, 0x26, 0x46, 0x32, 0xee, 0xcd, 0x31, 0x56, 0x33, 0x33, 0xe7, + 0x39, 0x0f, 0x44, 0x7b, 0x71, 0x40, 0xfc, 0x97, 0x49, 0x23, 0x09, 0xfa, 0x20, 0x35, 0x34, 0xd6, + 0x87, 0xa4, 0x26, 0x94, 0x67, 0x83, 0x24, 0xea, 0xfe, 0x1c, 0xea, 0xe3, 0xec, 0xd4, 0x39, 0xd6, + 0xfa, 0xcf, 0x15, 0xc8, 0x37, 0x91, 0x91, 0x2f, 0x50, 0x9a, 0x1b, 0x61, 0x63, 0xc1, 0x6d, 0xbd, + 0x60, 0x88, 0xd4, 0xa7, 0x97, 0xd3, 0xcb, 0x2a, 0x1f, 0x60, 0x25, 0x1c, 0xb8, 0xcd, 0xc5, 0x01, + 0x42, 0xa4, 0x6e, 0x2f, 0x21, 0x92, 0xd1, 0xdf, 0x14, 0x28, 0xa7, 0x0e, 0x48, 0x06, 0x6f, 0x9a, + 0x4f, 0x7d, 0xfe, 0x6f, 0xbe, 0x64, 0xdf, 0x70, 0xac, 0x32, 0xfa, 0x0a, 0x51, 0x56, 0xdf, 0xe9, + 0x21, 0xb3, 0xe1, 0xda, 0xd4, 0x7c, 0x6c, 0x2d, 0x36, 0x27, 0xb5, 0x6a, 0x7d, 0x79, 0xad, 0x3c, + 0xef, 0x13, 0x5c, 0x9f, 0xbe, 0xe7, 0xdb, 0x4b, 0x84, 0xc4, 0x62, 0xb5, 0x71, 0x09, 0x71, 0x7c, + 0xe4, 0xee, 0xc1, 0xaf, 0x91, 0xa6, 0x9c, 0x8f, 0x34, 0xe5, 0xcf, 0x48, 0x53, 0xbe, 0x8e, 0xb5, + 0xdc, 0xf9, 0x58, 0xcb, 0xfd, 0x1e, 0x6b, 0xb9, 0x8f, 0x3b, 0xac, 0xef, 0xf5, 0x7c, 0xcb, 0xe8, + 0xf0, 0xd3, 0x1a, 0x32, 0xba, 0x13, 0x25, 0x07, 0xeb, 0xda, 0xd9, 0xd4, 0xf3, 0xf8, 0xd9, 0xa1, + 0x68, 0xad, 0x8a, 0x07, 0xac, 0xf1, 0x37, 0x00, 0x00, 0xff, 0xff, 0x1f, 0xf0, 0x28, 0xa5, 0x3d, + 0x07, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -661,7 +661,7 @@ type MsgClient interface { // WithdrawUnlockedBalances defines a method for withdrawing unlocked balances. WithdrawUnlockedBalances(ctx context.Context, in *MsgWithdrawUnlockedBalances, opts ...grpc.CallOption) (*MsgWithdrawUnlockedBalancesResponse, error) // PlaceBet defines a method for placing a bet using a subaccount. - PlaceBet(ctx context.Context, in *MsgPlaceBet, opts ...grpc.CallOption) (*MsgPlaceBetResponse, error) + Wager(ctx context.Context, in *MsgWager, opts ...grpc.CallOption) (*MsgWagerResponse, error) // HouseDeposit defines a method for depositing funds to provide liquidity to a market. HouseDeposit(ctx context.Context, in *MsgHouseDeposit, opts ...grpc.CallOption) (*MsgHouseDepositResponse, error) // HouseWithdraw defines a method for withdrawing funds from a market. @@ -703,9 +703,9 @@ func (c *msgClient) WithdrawUnlockedBalances(ctx context.Context, in *MsgWithdra return out, nil } -func (c *msgClient) PlaceBet(ctx context.Context, in *MsgPlaceBet, opts ...grpc.CallOption) (*MsgPlaceBetResponse, error) { - out := new(MsgPlaceBetResponse) - err := c.cc.Invoke(ctx, "/sgenetwork.sge.subaccount.Msg/PlaceBet", in, out, opts...) +func (c *msgClient) Wager(ctx context.Context, in *MsgWager, opts ...grpc.CallOption) (*MsgWagerResponse, error) { + out := new(MsgWagerResponse) + err := c.cc.Invoke(ctx, "/sgenetwork.sge.subaccount.Msg/Wager", in, out, opts...) if err != nil { return nil, err } @@ -739,7 +739,7 @@ type MsgServer interface { // WithdrawUnlockedBalances defines a method for withdrawing unlocked balances. WithdrawUnlockedBalances(context.Context, *MsgWithdrawUnlockedBalances) (*MsgWithdrawUnlockedBalancesResponse, error) // PlaceBet defines a method for placing a bet using a subaccount. - PlaceBet(context.Context, *MsgPlaceBet) (*MsgPlaceBetResponse, error) + Wager(context.Context, *MsgWager) (*MsgWagerResponse, error) // HouseDeposit defines a method for depositing funds to provide liquidity to a market. HouseDeposit(context.Context, *MsgHouseDeposit) (*MsgHouseDepositResponse, error) // HouseWithdraw defines a method for withdrawing funds from a market. @@ -759,8 +759,8 @@ func (*UnimplementedMsgServer) TopUp(ctx context.Context, req *MsgTopUp) (*MsgTo func (*UnimplementedMsgServer) WithdrawUnlockedBalances(ctx context.Context, req *MsgWithdrawUnlockedBalances) (*MsgWithdrawUnlockedBalancesResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method WithdrawUnlockedBalances not implemented") } -func (*UnimplementedMsgServer) PlaceBet(ctx context.Context, req *MsgPlaceBet) (*MsgPlaceBetResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method PlaceBet not implemented") +func (*UnimplementedMsgServer) Wager(ctx context.Context, req *MsgWager) (*MsgWagerResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Wager not implemented") } func (*UnimplementedMsgServer) HouseDeposit(ctx context.Context, req *MsgHouseDeposit) (*MsgHouseDepositResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method HouseDeposit not implemented") @@ -827,20 +827,20 @@ func _Msg_WithdrawUnlockedBalances_Handler(srv interface{}, ctx context.Context, return interceptor(ctx, in, info, handler) } -func _Msg_PlaceBet_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgPlaceBet) +func _Msg_Wager_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgWager) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(MsgServer).PlaceBet(ctx, in) + return srv.(MsgServer).Wager(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/sgenetwork.sge.subaccount.Msg/PlaceBet", + FullMethod: "/sgenetwork.sge.subaccount.Msg/Wager", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).PlaceBet(ctx, req.(*MsgPlaceBet)) + return srv.(MsgServer).Wager(ctx, req.(*MsgWager)) } return interceptor(ctx, in, info, handler) } @@ -898,8 +898,8 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ Handler: _Msg_WithdrawUnlockedBalances_Handler, }, { - MethodName: "PlaceBet", - Handler: _Msg_PlaceBet_Handler, + MethodName: "Wager", + Handler: _Msg_Wager_Handler, }, { MethodName: "HouseDeposit", @@ -1115,7 +1115,7 @@ func (m *MsgWithdrawUnlockedBalancesResponse) MarshalToSizedBuffer(dAtA []byte) return len(dAtA) - i, nil } -func (m *MsgPlaceBet) Marshal() (dAtA []byte, err error) { +func (m *MsgWager) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1125,12 +1125,12 @@ func (m *MsgPlaceBet) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgPlaceBet) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgWager) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgPlaceBet) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgWager) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -1150,7 +1150,7 @@ func (m *MsgPlaceBet) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *MsgPlaceBetResponse) Marshal() (dAtA []byte, err error) { +func (m *MsgWagerResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1160,12 +1160,12 @@ func (m *MsgPlaceBetResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgPlaceBetResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgWagerResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgPlaceBetResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgWagerResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -1422,7 +1422,7 @@ func (m *MsgWithdrawUnlockedBalancesResponse) Size() (n int) { return n } -func (m *MsgPlaceBet) Size() (n int) { +func (m *MsgWager) Size() (n int) { if m == nil { return 0 } @@ -1435,7 +1435,7 @@ func (m *MsgPlaceBet) Size() (n int) { return n } -func (m *MsgPlaceBetResponse) Size() (n int) { +func (m *MsgWagerResponse) Size() (n int) { if m == nil { return 0 } @@ -2034,7 +2034,7 @@ func (m *MsgWithdrawUnlockedBalancesResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgPlaceBet) Unmarshal(dAtA []byte) error { +func (m *MsgWager) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -2057,10 +2057,10 @@ func (m *MsgPlaceBet) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgPlaceBet: wiretype end group for non-group") + return fmt.Errorf("proto: MsgWager: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgPlaceBet: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgWager: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -2093,7 +2093,7 @@ func (m *MsgPlaceBet) Unmarshal(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Msg == nil { - m.Msg = &types.MsgPlaceBet{} + m.Msg = &types.MsgWager{} } if err := m.Msg.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err @@ -2120,7 +2120,7 @@ func (m *MsgPlaceBet) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgPlaceBetResponse) Unmarshal(dAtA []byte) error { +func (m *MsgWagerResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -2143,10 +2143,10 @@ func (m *MsgPlaceBetResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgPlaceBetResponse: wiretype end group for non-group") + return fmt.Errorf("proto: MsgWagerResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgPlaceBetResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgWagerResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -2179,7 +2179,7 @@ func (m *MsgPlaceBetResponse) Unmarshal(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Response == nil { - m.Response = &types.MsgPlaceBetResponse{} + m.Response = &types.MsgWagerResponse{} } if err := m.Response.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err From 815e876fa52f69bf26fab61601b45b16c62dcd0c Mon Sep 17 00:00:00 2001 From: unknown unknown Date: Wed, 26 Jul 2023 20:51:15 +0200 Subject: [PATCH 18/20] fix more tests --- x/subaccount/keeper/msg_server_bet_test.go | 9 +++++---- x/subaccount/keeper/msg_server_house_test.go | 9 ++++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/x/subaccount/keeper/msg_server_bet_test.go b/x/subaccount/keeper/msg_server_bet_test.go index 9397499a..8e4440b1 100644 --- a/x/subaccount/keeper/msg_server_bet_test.go +++ b/x/subaccount/keeper/msg_server_bet_test.go @@ -85,6 +85,7 @@ func TestMsgServer_Bet(t *testing.T) { // check subaccount balance balance, exists := k.GetBalance(ctx, subAccAddr) require.True(t, exists) + betFees := sdk.NewInt(100) require.Equal(t, balance.SpentAmount, betAmt) @@ -103,7 +104,7 @@ func TestMsgServer_Bet(t *testing.T) { // now we check the subaccount balance balance, exists := k.GetBalance(ctx, subAccAddr) require.True(t, exists) - require.Equal(t, balance.SpentAmount.String(), sdk.ZeroInt().String()) + require.Equal(t, sdk.ZeroInt().Add(betFees).String(), balance.SpentAmount.String()) // now we want the user to have some balance which is the payout ownerBalance := app.BankKeeper.GetAllBalances(ctx, subAccOwner) @@ -111,7 +112,7 @@ func TestMsgServer_Bet(t *testing.T) { sdk.NewCoins( sdk.NewCoin( k.GetParams(ctx).LockedBalanceDenom, - betAmt.ToDec().Mul(sdk.MustNewDecFromStr("3.2")).TruncateInt(), // 4.2 - 1 = 3.2 + betAmt.Sub(betFees).ToDec().Mul(sdk.MustNewDecFromStr("3.2")).TruncateInt(), // 4.2 - 1 = 3.2 )), ownerBalance, ) @@ -132,8 +133,8 @@ func TestMsgServer_Bet(t *testing.T) { // now we check the subaccount balance balance, exists := k.GetBalance(ctx, subAccAddr) require.True(t, exists) - require.Equal(t, balance.SpentAmount, sdk.ZeroInt()) - require.Equal(t, balance.LostAmount, betAmt) + require.Equal(t, sdk.ZeroInt().Add(betFees).String(), balance.SpentAmount.String()) + require.Equal(t, betAmt.Sub(betFees), balance.LostAmount) // the owner has no balances ownerBalance := app.BankKeeper.GetAllBalances(ctx, subAccOwner) require.Equal(t, sdk.NewCoins(), ownerBalance) diff --git a/x/subaccount/keeper/msg_server_house_test.go b/x/subaccount/keeper/msg_server_house_test.go index ec1f6e62..de6f38fa 100644 --- a/x/subaccount/keeper/msg_server_house_test.go +++ b/x/subaccount/keeper/msg_server_house_test.go @@ -77,6 +77,7 @@ func TestMsgServer(t *testing.T) { require.NoError(t, err) participateFee := app.HouseKeeper.GetHouseParticipationFee(ctx).Mul(deposit.ToDec()).TruncateInt() + bettorFee := sdk.NewInt(100) t.Run("house wins", func(t *testing.T) { ctx, _ := ctx.CacheContext() @@ -98,7 +99,9 @@ func TestMsgServer(t *testing.T) { require.Equal(t, subBalance.SpentAmount.String(), sdk.ZeroInt().Add(participateFee).String()) // check profits were forwarded to subacc owner ownerBalance := app.BankKeeper.GetAllBalances(ctx, subAccOwner) - require.Equal(t, ownerBalance.AmountOf(k.GetParams(ctx).LockedBalanceDenom).String(), sdk.NewInt(10).Mul(micro).String()) + require.Equal(t, + ownerBalance.AmountOf(k.GetParams(ctx).LockedBalanceDenom).String(), + sdk.NewInt(10).Mul(micro).Sub(bettorFee).String()) }) t.Run("house loses", func(t *testing.T) { @@ -119,7 +122,7 @@ func TestMsgServer(t *testing.T) { require.NoError(t, err) require.Equal(t, subBalance.SpentAmount.String(), sdk.ZeroInt().Add(participateFee).String()) - require.Equal(t, subBalance.LostAmount, bettor1Funds.ToDec().Mul(sdk.MustNewDecFromStr("3.2")).TruncateInt()) + require.Equal(t, subBalance.LostAmount, bettor1Funds.Sub(bettorFee).ToDec().Mul(sdk.MustNewDecFromStr("3.2")).TruncateInt()) // check profits were forwarded to subacc owner ownerBalance := app.BankKeeper.GetAllBalances(ctx, subAccOwner) require.Equal(t, ownerBalance.AmountOf(k.GetParams(ctx).LockedBalanceDenom), sdk.ZeroInt()) @@ -159,7 +162,7 @@ func TestMsgServer(t *testing.T) { subBalance, exists := k.GetBalance(ctx, subAccAddr) require.True(t, exists) - require.Equal(t, subBalance.SpentAmount.String(), sdk.NewInt(132000000).String()) // NOTE: there was a match in the bet + participate fee + require.Equal(t, subBalance.SpentAmount.String(), sdk.NewInt(131999680).String()) // NOTE: there was a match in the bet + participate fee require.Equal(t, subBalance.LostAmount.String(), sdk.ZeroInt().String()) }) } From dd1124e348249bdfaea37bf7c7e2bef03040d40b Mon Sep 17 00:00:00 2001 From: unknown unknown Date: Tue, 1 Aug 2023 09:54:38 +0200 Subject: [PATCH 19/20] fmt --- x/mint/types/tx.pb.go | 2 +- x/subaccount/keeper/msg_server.go | 1 - x/subaccount/keeper/msg_server_bet.go | 1 - x/subaccount/keeper/msg_server_house.go | 2 -- x/subaccount/keeper/orderbook_hooks.go | 1 - 5 files changed, 1 insertion(+), 6 deletions(-) diff --git a/x/mint/types/tx.pb.go b/x/mint/types/tx.pb.go index 3d6c0fc7..b9a9d907 100644 --- a/x/mint/types/tx.pb.go +++ b/x/mint/types/tx.pb.go @@ -79,4 +79,4 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ Methods: []grpc.MethodDesc{}, Streams: []grpc.StreamDesc{}, Metadata: "sge/mint/tx.proto", -} \ No newline at end of file +} diff --git a/x/subaccount/keeper/msg_server.go b/x/subaccount/keeper/msg_server.go index 1102f7f1..fb3684d6 100644 --- a/x/subaccount/keeper/msg_server.go +++ b/x/subaccount/keeper/msg_server.go @@ -45,7 +45,6 @@ func sumBalanceUnlocks(ctx sdk.Context, balanceUnlocks []*types.LockedBalance) ( // sendCoinsToSubaccount sends the coins to the subaccount. func (m msgServer) sendCoinsToSubaccount(ctx sdk.Context, senderAccount sdk.AccAddress, subAccountAddress sdk.AccAddress, moneyToSend sdk.Int) error { - denom := m.keeper.GetParams(ctx).LockedBalanceDenom err := m.bankKeeper.SendCoins(ctx, senderAccount, subAccountAddress, sdk.NewCoins(sdk.NewCoin(denom, moneyToSend))) if err != nil { diff --git a/x/subaccount/keeper/msg_server_bet.go b/x/subaccount/keeper/msg_server_bet.go index f84ad6e3..14be38a4 100644 --- a/x/subaccount/keeper/msg_server_bet.go +++ b/x/subaccount/keeper/msg_server_bet.go @@ -67,5 +67,4 @@ func (m msgServer) Wager(goCtx context.Context, msg *types.MsgWager) (*types.Msg return &types.MsgWagerResponse{ Response: &bettypes.MsgWagerResponse{Props: msg.Msg.Props}, }, nil - } diff --git a/x/subaccount/keeper/msg_server_house.go b/x/subaccount/keeper/msg_server_house.go index 0ffa8b25..1e6d6ae8 100644 --- a/x/subaccount/keeper/msg_server_house.go +++ b/x/subaccount/keeper/msg_server_house.go @@ -63,7 +63,6 @@ func (m msgServer) HouseDeposit(goCtx context.Context, msg *types.MsgHouseDeposi // TODO: This is a copy of the Deposit function from x/house/keeper/msg_server_deposit.go func (m msgServer) houseDeposit(ctx sdk.Context, msg *housetypes.MsgDeposit) error { - params := m.keeper.houseKeeper.GetParams(ctx) if err := msg.ValidateSanity(ctx, ¶ms); err != nil { return sdkerrors.Wrap(err, "invalid deposit") @@ -115,7 +114,6 @@ func (m msgServer) HouseWithdraw(goCtx context.Context, withdraw *types.MsgHouse return &types.MsgHouseWithdrawResponse{ Response: resp, }, nil - } func (m msgServer) houseWithdraw(ctx sdk.Context, msg *housetypes.MsgWithdraw, subAccAddr sdk.AccAddress) (sdk.Int, *housetypes.MsgWithdrawResponse, error) { diff --git a/x/subaccount/keeper/orderbook_hooks.go b/x/subaccount/keeper/orderbook_hooks.go index 45a8cc43..1f0a7169 100644 --- a/x/subaccount/keeper/orderbook_hooks.go +++ b/x/subaccount/keeper/orderbook_hooks.go @@ -85,7 +85,6 @@ func (k Keeper) AfterHouseWin(ctx sdk.Context, house sdk.AccAddress, originalAmo if err != nil { panic(err) } - } func (k Keeper) AfterHouseLoss(ctx sdk.Context, house sdk.AccAddress, originalAmount sdk.Int, lostAmt sdk.Int, fee *sdk.Int) { From 14757718734bf127bd153e153e69990c31749320 Mon Sep 17 00:00:00 2001 From: unknown unknown Date: Tue, 1 Aug 2023 11:38:52 +0200 Subject: [PATCH 20/20] lint once more --- x/subaccount/keeper/msg_server_house_test.go | 2 +- x/subaccount/keeper/withdraw_test.go | 1 + x/subaccount/types/msg.go | 7 +++---- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/x/subaccount/keeper/msg_server_house_test.go b/x/subaccount/keeper/msg_server_house_test.go index de6f38fa..04b20e62 100644 --- a/x/subaccount/keeper/msg_server_house_test.go +++ b/x/subaccount/keeper/msg_server_house_test.go @@ -151,7 +151,7 @@ func TestMsgServer(t *testing.T) { require.Equal(t, ownerBalance.AmountOf(k.GetParams(ctx).LockedBalanceDenom), sdk.ZeroInt()) }) - // TODO: not partecipated in bet fulfillment. + // TODO: not participated in bet fulfillment. t.Run("withdrawal", func(t *testing.T) { ctx, _ := ctx.CacheContext() diff --git a/x/subaccount/keeper/withdraw_test.go b/x/subaccount/keeper/withdraw_test.go index 5d2b3074..50734aa8 100644 --- a/x/subaccount/keeper/withdraw_test.go +++ b/x/subaccount/keeper/withdraw_test.go @@ -22,6 +22,7 @@ func TestMsgServer_WithdrawUnlockedBalances(t *testing.T) { t.Log("fund sender account") err := simapp.FundAccount(app.BankKeeper, ctx, sender, sdk.NewCoins(sdk.NewInt64Coin("usge", 1000))) + require.NoError(t, err) t.Log("Create sub account") _, err = msgServer.CreateSubAccount(sdk.WrapSDKContext(ctx), &types.MsgCreateSubAccount{ diff --git a/x/subaccount/types/msg.go b/x/subaccount/types/msg.go index 84aa7575..f3c4ac71 100644 --- a/x/subaccount/types/msg.go +++ b/x/subaccount/types/msg.go @@ -3,7 +3,6 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/errors" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) var ( @@ -90,7 +89,7 @@ func (msg *MsgWithdrawUnlockedBalances) GetSigners() []sdk.AccAddress { func (m *MsgWager) ValidateBasic() error { if m.Msg == nil { - return sdkerrors.ErrInvalidRequest.Wrap("msg is nil") + return errors.ErrInvalidRequest.Wrap("msg is nil") } return m.Msg.ValidateBasic() } @@ -105,7 +104,7 @@ func (m *MsgHouseDeposit) GetSigners() []sdk.AccAddress { func (m *MsgHouseDeposit) ValidateBasic() error { if m.Msg == nil { - return sdkerrors.ErrInvalidRequest.Wrap("msg is nil") + return errors.ErrInvalidRequest.Wrap("msg is nil") } return m.Msg.ValidateBasic() } @@ -116,7 +115,7 @@ func (m *MsgHouseWithdraw) GetSigners() []sdk.AccAddress { func (m *MsgHouseWithdraw) ValidateBasic() error { if m.Msg == nil { - return sdkerrors.ErrInvalidRequest.Wrap("msg is nil") + return errors.ErrInvalidRequest.Wrap("msg is nil") } return m.Msg.ValidateBasic() }