diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 5203fb94..8b07d264 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,11 @@ func NewAppKeeper( appCodec, appKeepers.keys[subaccounttypes.StoreKey], appKeepers.GetSubspace(subaccounttypes.ModuleName), + appKeepers.BankKeeper, + appKeepers.OVMKeeper, + appKeepers.BetKeeper, + appKeepers.OrderbookKeeper, + appKeepers.HouseKeeper, ) appKeepers.SubaccountModule = subaccount.NewAppModule(appKeepers.SubaccountKeeper) 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 af00e8d8..2ad48976 100644 --- a/proto/sge/subaccount/tx.proto +++ b/proto/sge/subaccount/tx.proto @@ -2,6 +2,8 @@ syntax = "proto3"; 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"; @@ -13,7 +15,17 @@ 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 Wager(MsgWager) returns (MsgWagerResponse); + + // 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. @@ -53,4 +65,34 @@ 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 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 MsgWagerResponse { + sgenetwork.sge.bet.MsgWagerResponse 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/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/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/orderbook/keeper/bet_settle.go b/x/orderbook/keeper/bet_settle.go index d2448df6..5a019c72 100644 --- a/x/orderbook/keeper/bet_settle.go +++ b/x/orderbook/keeper/bet_settle.go @@ -22,7 +22,14 @@ func (k Keeper) RefundBettor( } // refund bettor's account from bet fee collector. - return k.refund(bettypes.BetFeeCollectorFunder{}, ctx, bettorAddress, betFee) + if err := k.refund(bettypes.BetFeeCollectorFunder{}, ctx, bettorAddress, betFee); err != nil { + return err + } + + for _, hook := range k.hooks { + hook.AfterBettorRefund(ctx, bettorAddress, betAmount, betFee) + } + return nil } // BettorWins process bets in case bettor is the winner, @@ -31,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, @@ -66,6 +73,10 @@ func (k Keeper) BettorWins( k.SetOrderBookParticipation(ctx, orderBookParticipation) } + for _, h := range k.hooks { + h.AfterBettorWin(ctx, bettorAddress, betAmount, payoutProfit) + } + return nil } @@ -73,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, @@ -104,5 +115,9 @@ func (k Keeper) BettorLoses(ctx sdk.Context, _ 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..2a1e9805 --- /dev/null +++ b/x/orderbook/keeper/hooks.go @@ -0,0 +1,16 @@ +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) + 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) { + k.hooks = append(k.hooks, hook) +} diff --git a/x/orderbook/keeper/keeper.go b/x/orderbook/keeper/keeper.go index 6277efd2..674ac853 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/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/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/create_subaccount.go b/x/subaccount/keeper/create_subaccount.go index d70d619b..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 m.keeper.HasSubAccount(sdkContext, subaccountOwner) { + if _, exists := m.keeper.GetSubAccountByOwner(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..1904b78f 100644 --- a/x/subaccount/keeper/keeper.go +++ b/x/subaccount/keeper/keeper.go @@ -4,20 +4,69 @@ import ( "github.com/cosmos/cosmos-sdk/codec" 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" ) +type BetKeeper interface { + GetBetID(ctx sdk.Context, uid string) (bettypes.UID2ID, bool) + Wager(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 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 { cdc codec.Codec storeKey sdk.StoreKey paramstore paramtypes.Subspace + bankKeeper BankKeeper + + ovmKeeper bettypes.OVMKeeper + betKeeper BetKeeper + houseKeeper HouseKeeper + obKeeper OrderBookKeeper } -func NewKeeper(cdc codec.Codec, storeKey sdk.StoreKey, ps paramtypes.Subspace) 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()) } - return Keeper{storeKey: storeKey, cdc: cdc, paramstore: ps} + k := Keeper{ + cdc: cdc, + storeKey: storeKey, + paramstore: ps, + bankKeeper: bankKeeper, + ovmKeeper: ovmKeeper, + betKeeper: betKeeper, + houseKeeper: hk, + obKeeper: obKeeper, + } + obKeeper.RegisterHook(k) + return k } diff --git a/x/subaccount/keeper/msg_server.go b/x/subaccount/keeper/msg_server.go index 8ed08584..fb3684d6 100644 --- a/x/subaccount/keeper/msg_server.go +++ b/x/subaccount/keeper/msg_server.go @@ -44,11 +44,9 @@ 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/msg_server_bet.go b/x/subaccount/keeper/msg_server_bet.go new file mode 100644 index 00000000..14be38a4 --- /dev/null +++ b/x/subaccount/keeper/msg_server_bet.go @@ -0,0 +1,70 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + 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" + "google.golang.org/grpc/status" +) + +func (m msgServer) Wager(goCtx context.Context, msg *types.MsgWager) (*types.MsgWagerResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // find subaccount + subAccountAddress, exists := m.keeper.GetSubAccountByOwner(ctx, sdk.MustAccAddressFromBech32(msg.Msg.Creator)) + if !exists { + return nil, status.Error(codes.NotFound, "subaccount not found") + } + + // 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.Props.UID) + if isFound { + return nil, sdkerrors.Wrapf(bettypes.ErrDuplicateUID, "%s", msg.Msg.Props.UID) + } + + 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) + } + + originalSender := msg.Msg.Creator + + if err = payload.Validate(originalSender); err != nil { + 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.Props, 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.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.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 new file mode 100644 index 00000000..8e4440b1 --- /dev/null +++ b/x/subaccount/keeper/msg_server_bet_test.go @@ -0,0 +1,236 @@ +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) + subAccAddr = types.NewAddressFromSubaccount(1) +) + +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 + market := addTestMarket(t, app, ctx, true) + + // start betting using the subaccount + betAmt := sdk.NewInt(1000).Mul(micro) + _, err = msgServer.Wager( + sdk.WrapSDKContext(ctx), + &types.MsgWager{Msg: testBet(t, subAccOwner, betAmt)}, + ) + require.NoError(t, err) + + // check subaccount balance + balance, exists := k.GetBalance(ctx, subAccAddr) + require.True(t, exists) + betFees := sdk.NewInt(100) + + 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.Resolve(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, 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) + require.Equal(t, + sdk.NewCoins( + sdk.NewCoin( + k.GetParams(ctx).LockedBalanceDenom, + betAmt.Sub(betFees).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.Resolve(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, 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) + }) + t.Run("resolve market – refund", func(t *testing.T) { + ctx, _ := ctx.CacheContext() + // resolve the market – refund + app.MarketKeeper.Resolve(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, prefund bool) *markettypes.Market { + 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.MsgAdd{ + Creator: testCreator, + Ticket: testAddMarketTicket, + } + wctx := sdk.WrapSDKContext(ctx) + marketSrv := marketkeeper.NewMsgServerImpl(*tApp.MarketKeeper) + resAddMarket, err := marketSrv.Add(wctx, testAddMarket) + require.Nil(t, err) + require.NotNil(t, resAddMarket) + + 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 +} + +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.MsgWager { + ticket, err := createJwtTicket(jwt.MapClaims{ + "exp": 9999999999, + "iat": 7777777777, + "selected_odds": testSelectedBetOdds, + "kyc_data": &sgetypes.KycDataPayload{ + Approved: true, + ID: better.String(), + }, + "odds_type": 1, + }) + require.NoError(t, err) + + return &bettypes.MsgWager{ + Creator: better.String(), + Props: &bettypes.WagerProps{ + UID: uuid.NewString(), + Amount: amount, + Ticket: ticket, + }, + } +} diff --git a/x/subaccount/keeper/msg_server_house.go b/x/subaccount/keeper/msg_server_house.go new file mode 100644 index 00000000..1e6d6ae8 --- /dev/null +++ b/x/subaccount/keeper/msg_server_house.go @@ -0,0 +1,164 @@ +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" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +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") + } + + // 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, + subAccountAddr.String(), + subAccountAddr.String(), + msg.Msg.MarketUID, + msg.Msg.Amount, + ) + 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, + 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) + } + + 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 { + return sdkerrors.Wrapf(housetypes.ErrInTicketPayloadValidation, "%s", err) + } + + return nil +} + +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 new file mode 100644 index 00000000..04b20e62 --- /dev/null +++ b/x/subaccount/keeper/msg_server_house_test.go @@ -0,0 +1,217 @@ +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(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) + 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) + require.True(t, exists) + require.Equal(t, subBalance.SpentAmount, deposit) + + // place bet + betMsgServer := betmodulekeeper.NewMsgServerImpl(*app.BetKeeper) + _, err = betMsgServer.Wager(sdk.WrapSDKContext(ctx), testBet(t, bettor1, bettor1Funds)) + 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() + app.MarketKeeper.Resolve(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).Sub(bettorFee).String()) + }) + + t.Run("house loses", func(t *testing.T) { + ctx, _ := ctx.CacheContext() + app.MarketKeeper.Resolve(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.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()) + }) + t.Run("house refund", func(t *testing.T) { + ctx, _ := ctx.CacheContext() + app.MarketKeeper.Resolve(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()) + }) + + // TODO: not participated 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(131999680).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 { + 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 new file mode 100644 index 00000000..1f0a7169 --- /dev/null +++ b/x/subaccount/keeper/orderbook_hooks.go @@ -0,0 +1,130 @@ +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, bettor, owner, sdk.NewCoins(sdk.NewCoin(k.GetParams(ctx).LockedBalanceDenom, profit))) + 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 + } + totalUnspent := originalAmount.Add(fee) + err := balance.Unspend(totalUnspent) + if err != nil { + panic(err) + } + 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) +} + +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) +} 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..35b8329e 100644 --- a/x/subaccount/keeper/subaccount_test.go +++ b/x/subaccount/keeper/subaccount_test.go @@ -29,26 +29,33 @@ 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) + id := k.NextID(ctx) + k.SetSubAccountOwner(ctx, types.NewAddressFromSubaccount(id), owner) // Account should have subaccount - require.True(t, k.HasSubAccount(ctx, address)) + _, exists = k.GetSubAccountByOwner(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 +75,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 +97,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 +135,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..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{ @@ -74,9 +75,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 +97,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 +109,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/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/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/msg.go b/x/subaccount/types/msg.go index cb3730c4..f3c4ac71 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 = &MsgWager{} ) func (msg *MsgCreateSubAccount) GetSigners() []sdk.AccAddress { @@ -85,3 +86,36 @@ func (msg *MsgWithdrawUnlockedBalances) GetSigners() []sdk.AccAddress { } return []sdk.AccAddress{signer} } + +func (m *MsgWager) ValidateBasic() error { + if m.Msg == nil { + return errors.ErrInvalidRequest.Wrap("msg is nil") + } + return m.Msg.ValidateBasic() +} + +func (m *MsgWager) 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 errors.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 errors.ErrInvalidRequest.Wrap("msg is nil") + } + return m.Msg.ValidateBasic() +} 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.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 +} 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 4f5ee7a7..1036932f 100644 --- a/x/subaccount/types/tx.pb.go +++ b/x/subaccount/types/tx.pb.go @@ -8,6 +8,8 @@ import ( fmt "fmt" 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" @@ -312,6 +314,276 @@ 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 MsgWager struct { + Msg *types.MsgWager `protobuf:"bytes,1,opt,name=msg,proto3" json:"msg,omitempty"` +} + +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 *MsgWager) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgWager) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgWager.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 *MsgWager) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgWager.Merge(m, src) +} +func (m *MsgWager) XXX_Size() int { + return m.Size() +} +func (m *MsgWager) XXX_DiscardUnknown() { + xxx_messageInfo_MsgWager.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgWager proto.InternalMessageInfo + +func (m *MsgWager) GetMsg() *types.MsgWager { + 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 MsgWagerResponse struct { + Response *types.MsgWagerResponse `protobuf:"bytes,1,opt,name=response,proto3" json:"response,omitempty"` +} + +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 *MsgWagerResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgWagerResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgWagerResponse.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 *MsgWagerResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgWagerResponse.Merge(m, src) +} +func (m *MsgWagerResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgWagerResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgWagerResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgWagerResponse proto.InternalMessageInfo + +func (m *MsgWagerResponse) GetResponse() *types.MsgWagerResponse { + if m != nil { + return m.Response + } + 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") @@ -319,37 +591,55 @@ 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((*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") + proto.RegisterType((*MsgHouseWithdrawResponse)(nil), "sgenetwork.sge.subaccount.MsgHouseWithdrawResponse") } 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, + // 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. @@ -368,7 +658,14 @@ 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. + 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. + HouseWithdraw(ctx context.Context, in *MsgHouseWithdraw, opts ...grpc.CallOption) (*MsgHouseWithdrawResponse, error) } type msgClient struct { @@ -406,13 +703,47 @@ func (c *msgClient) WithdrawUnlockedBalances(ctx context.Context, in *MsgWithdra return out, nil } +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 + } + 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. 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. + 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. + HouseWithdraw(context.Context, *MsgHouseWithdraw) (*MsgHouseWithdrawResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -428,6 +759,15 @@ 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) 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") +} +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) @@ -487,6 +827,60 @@ func _Msg_WithdrawUnlockedBalances_Handler(srv interface{}, ctx context.Context, return interceptor(ctx, in, info, handler) } +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).Wager(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sgenetwork.sge.subaccount.Msg/Wager", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).Wager(ctx, req.(*MsgWager)) + } + 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), @@ -503,6 +897,18 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "WithdrawUnlockedBalances", Handler: _Msg_WithdrawUnlockedBalances_Handler, }, + { + MethodName: "Wager", + Handler: _Msg_Wager_Handler, + }, + { + MethodName: "HouseDeposit", + Handler: _Msg_HouseDeposit_Handler, + }, + { + MethodName: "HouseWithdraw", + Handler: _Msg_HouseWithdraw_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "sge/subaccount/tx.proto", @@ -709,31 +1115,241 @@ func (m *MsgWithdrawUnlockedBalancesResponse) MarshalToSizedBuffer(dAtA []byte) 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 *MsgWager) 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 *MsgWager) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgWager) 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 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 *MsgWagerResponse) 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 *MsgWagerResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgWagerResponse) 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 (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 + } + return dAtA[:n], nil +} + +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 + 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 *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 + } + return dAtA[:n], nil +} + +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 + 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 (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() @@ -806,6 +1422,84 @@ func (m *MsgWithdrawUnlockedBalancesResponse) Size() (n int) { return n } +func (m *MsgWager) 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 *MsgWagerResponse) 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 *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 } @@ -1340,6 +2034,522 @@ func (m *MsgWithdrawUnlockedBalancesResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgWager) 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: MsgWager: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgWager: 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.MsgWager{} + } + 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 *MsgWagerResponse) 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: MsgWagerResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgWagerResponse: 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.MsgWagerResponse{} + } + 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 (m *MsgHouseDeposit) 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: MsgHouseDeposit: wiretype end group for non-group") + } + if fieldNum <= 0 { + 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 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 = &types1.MsgDeposit{} + } + 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 *MsgHouseDepositResponse) 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: MsgHouseDepositResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + 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:]) + 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 *MsgHouseWithdraw) 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: MsgHouseWithdraw: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgHouseWithdraw: 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 = &types1.MsgWithdraw{} + } + 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 *MsgHouseWithdrawResponse) 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: MsgHouseWithdrawResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgHouseWithdrawResponse: 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.MsgWithdrawResponse{} + } + 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