Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Selected Odds in Bet Meta #274

Merged
merged 18 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions docs/specs/Bet/04_State.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ message Bet {
json_name = "odds_uid"
];

// odds_type is the type of odds that
// user choose such as decimal, fractional, etc
sgenetwork.sge.bet.OddsType odds_type = 4;

// odds_value is the odds on which the bet is placed.
string odds_value = 5;

Expand Down Expand Up @@ -132,6 +128,9 @@ message Bet {
// bet_fulfillment is the fulfillment data.
repeated BetFulfillment bet_fulfillment = 14;

// meta is metadata for bet
MetaData meta = 15;

// Status of the Bet.
enum Status {
// the invalid or unknown
Expand Down
1 change: 0 additions & 1 deletion docs/specs/Bet/05_State_Transitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ newBet := &types.Bet{
UID: msg.UID,
MarketUID: <msg.Ticket.MarketUID>,
OddsUID: <msg.Ticket.OddsUID>,
OddsType: <msg.OddsType>,
OddsValue: <msg.Ticket.OddsValue>,
Amount: msg.Amount,
BetFee: <will be calculated>,
Expand Down
2 changes: 0 additions & 2 deletions docs/specs/Bet/06_Messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ message MsgWagerResponse { WagerProps props = 1; }
"approved": true,
"id": "sge1w77wnncp6w6llqt0ysgahpxjscg8wspw43jvtd"
},
"odds_type":1,
"exp": 1667863498866062000,
"iat": 1667827498,
"iss": "Oracle",
Expand All @@ -85,7 +84,6 @@ The transaction will fail if:
- Provided bet UID is already set
- Empty or invalid odds UID in ticket
- Empty, negative or invalid odds value in ticket
- Invalid bet value according to the selected `OddsType`
- There is no any market with the given marketUID
- The market is not active for accepting bet (it's not active or status in not `PENDING`)
- The market has expired
Expand Down
15 changes: 11 additions & 4 deletions proto/sge/bet/bet.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ message Bet {
json_name = "odds_uid"
];

// odds_type is the type of odds that
// user choose such as decimal, fractional, etc
sgenetwork.sge.bet.OddsType odds_type = 4;

// odds_value is the odds on which the bet is placed.
string odds_value = 5;

Expand Down Expand Up @@ -74,6 +70,9 @@ message Bet {
// bet_fulfillment is the fulfillment data.
repeated BetFulfillment bet_fulfillment = 14;

// meta is metadata for bet
MetaData meta = 15 [ (gogoproto.nullable) = false ];

// Status of the Bet.
enum Status {
// the invalid or unknown
Expand Down Expand Up @@ -174,3 +173,11 @@ message BetFulfillment {
(gogoproto.moretags) = "yaml:\"payout_profit\""
];
}

// metadata for bet
message MetaData {
// selected_odds_type is metadata for bet
sgenetwork.sge.bet.OddsType selected_odds_type = 1;
// selected_odds_value is metadata for bet
string selected_odds_value = 2;
}
9 changes: 5 additions & 4 deletions proto/sge/bet/ticket.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package sgenetwork.sge.bet;
import "gogoproto/gogo.proto";
import "sge/type/kyc.proto";
import "sge/bet/bet_odds.proto";
import "sge/bet/odds_type.proto";
import "sge/bet/bet.proto";

option go_package = "github.com/sge-network/sge/x/bet/types";

Expand All @@ -16,9 +16,10 @@ message WagerTicketPayload {
// kyc_data contains the details of user kyc.
sgenetwork.sge.type.KycDataPayload kyc_data = 2
[ (gogoproto.nullable) = false ];
// odds_type is the type of odds that are going to be placed
// such as decimal, fraction, moneyline.
sgenetwork.sge.bet.OddsType odds_type = 3;
// all odds for the selected market.
repeated BetOddsCompact all_odds = 4;
// meta is metadata for bet placement
MetaData meta = 5 [ (gogoproto.nullable) = false ];
// context contains the data from services and just for processing purpose.
string context = 6;
}
5 changes: 5 additions & 0 deletions proto/sge/house/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ message Params {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

// max_withdrawal_count is the maximum number of withdrawals allowed
// per participation index.
uint64 max_withdrawal_count = 3
[ (gogoproto.moretags) = "yaml:\"max_withdrawal_count\""];
}
1 change: 0 additions & 1 deletion x/bet/keeper/bet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func createNBet(
items[i].UID = cast.ToString(i)
items[i].Creator = testCreator
items[i].OddsValue = "10"
items[i].OddsType = types.OddsType_ODDS_TYPE_DECIMAL
items[i].Amount = sdk.NewInt(10)
items[i].Fee = sdk.NewInt(1)
items[i].MarketUID = testMarketUID
Expand Down
1 change: 0 additions & 1 deletion x/bet/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ func placeTestBet(
"iat": 7777777777,
"selected_odds": selectedOdds,
"kyc_data": testKyc,
"odds_type": 1,
"all_odds": testBetOdds,
}
testWagerTicket, err := createJwtTicket(testWagerClaim)
Expand Down
4 changes: 2 additions & 2 deletions x/bet/keeper/msg_server_bet.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ func (k msgServer) Wager(
return nil, sdkerrors.Wrapf(types.ErrInTicketValidation, "%s", err)
}

bet := types.NewBet(msg.Creator, msg.Props, payload.OddsType, payload.SelectedOdds)
bet := types.NewBet(msg.Creator, msg.Props, payload.SelectedOdds, payload.Meta)

if err := k.Keeper.Wager(ctx, bet, payload.OddsMap()); err != nil {
return nil, sdkerrors.Wrapf(types.ErrInWager, "%s", err)
return nil, err
}

msg.EmitEvent(&ctx)
Expand Down
4 changes: 1 addition & 3 deletions x/bet/keeper/msg_server_bet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ func TestBetMsgServerWager(t *testing.T) {
"iat": 1111111111,
"selected_odds": testSelectedBetOdds,
"kyc_data": testKyc,
"odds_type": types.OddsType_ODDS_TYPE_DECIMAL,
"all_odds": testBetOdds,
}
wagerTicket, err := createJwtTicket(wagerClaim)
Expand All @@ -106,7 +105,7 @@ func TestBetMsgServerWager(t *testing.T) {
}

_, err = msgk.Wager(wctx, inputBet)
require.ErrorIs(t, types.ErrInWager, err)
require.ErrorIs(t, types.ErrNoMatchingMarket, err)
})

t.Run("Success", func(t *testing.T) {
Expand All @@ -119,7 +118,6 @@ func TestBetMsgServerWager(t *testing.T) {
"iat": 1111111111,
"selected_odds": testSelectedBetOdds,
"kyc_data": testKyc,
"odds_type": types.OddsType_ODDS_TYPE_DECIMAL,
"all_odds": testBetOdds,
}
wagerTicket, err := createJwtTicket(wagerClaim)
Expand Down
4 changes: 2 additions & 2 deletions x/bet/keeper/settle.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (k Keeper) Settle(ctx sdk.Context, bettorAddressStr, betUID string) error {

if market.Status == markettypes.MarketStatus_MARKET_STATUS_ABORTED ||
market.Status == markettypes.MarketStatus_MARKET_STATUS_CANCELED {
payoutProfit, err := types.CalculatePayoutProfit(bet.OddsType, bet.OddsValue, bet.Amount)
payoutProfit, err := types.CalculatePayoutProfit(bet.OddsValue, bet.Amount)
if err != nil {
return err
}
Expand Down Expand Up @@ -109,7 +109,7 @@ func (k Keeper) settleResolved(ctx sdk.Context, bet *types.Bet) error {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "%s", err)
}

payout, err := types.CalculatePayoutProfit(bet.OddsType, bet.OddsValue, bet.Amount)
payout, err := types.CalculatePayoutProfit(bet.OddsValue, bet.Amount)
if err != nil {
return err
}
Expand Down
5 changes: 0 additions & 5 deletions x/bet/keeper/settle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func TestSettleBet(t *testing.T) {
bet: &types.Bet{
MarketUID: testMarketUID,
OddsValue: "10",
OddsType: types.OddsType_ODDS_TYPE_DECIMAL,
Amount: sdk.NewInt(1000000),
Creator: testCreator,
OddsUID: testOddsUID1,
Expand All @@ -71,7 +70,6 @@ func TestSettleBet(t *testing.T) {
bet: &types.Bet{
MarketUID: testMarketUID,
OddsValue: "10",
OddsType: types.OddsType_ODDS_TYPE_DECIMAL,
Amount: sdk.NewInt(1000000),
Creator: testCreator,
OddsUID: testOddsUID1,
Expand All @@ -91,7 +89,6 @@ func TestSettleBet(t *testing.T) {
bet: &types.Bet{
MarketUID: testMarketUID,
OddsValue: "10",
OddsType: types.OddsType_ODDS_TYPE_DECIMAL,
Amount: sdk.NewInt(1000000),
Creator: testCreator,
OddsUID: testOddsUID1,
Expand All @@ -111,7 +108,6 @@ func TestSettleBet(t *testing.T) {
bet: &types.Bet{
MarketUID: testMarketUID,
OddsValue: "10",
OddsType: types.OddsType_ODDS_TYPE_DECIMAL,
Amount: sdk.NewInt(1000000),
Creator: testCreator,
OddsUID: testOddsUID1,
Expand All @@ -132,7 +128,6 @@ func TestSettleBet(t *testing.T) {
bet: &types.Bet{
MarketUID: testMarketUID,
OddsValue: "10",
OddsType: types.OddsType_ODDS_TYPE_DECIMAL,
Amount: sdk.NewInt(1000000),
Creator: testCreator,
OddsUID: testOddsUID1,
Expand Down
6 changes: 3 additions & 3 deletions x/bet/keeper/wager.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (k Keeper) Wager(ctx sdk.Context, bet *types.Bet, betOdds map[string]*types
bet.SetFee(betConstraints.Fee)

// calculate payoutProfit
payoutProfit, err := types.CalculatePayoutProfit(bet.OddsType, bet.OddsValue, bet.Amount)
payoutProfit, err := types.CalculatePayoutProfit(bet.OddsValue, bet.Amount)
if err != nil {
return err
}
Expand All @@ -57,10 +57,10 @@ func (k Keeper) Wager(ctx sdk.Context, bet *types.Bet, betOdds map[string]*types

betFulfillment, err := k.orderbookKeeper.ProcessWager(
ctx, bet.UID, bet.MarketUID, bet.OddsUID, bet.MaxLossMultiplier, bet.Amount, payoutProfit,
bettorAddress, bet.Fee, bet.OddsType, bet.OddsValue, betID, betOdds, market.OddsUIDS(),
bettorAddress, bet.Fee, bet.OddsValue, betID, betOdds, market.OddsUIDS(),
)
if err != nil {
return sdkerrors.Wrapf(types.ErrInOBWagerProcessing, "%s", err)
return err
}

// set bet as placed
Expand Down
3 changes: 0 additions & 3 deletions x/bet/keeper/wager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ func TestWager(t *testing.T) {
OddsUID: "notExistOdds",
Amount: sdk.NewInt(1000),
OddsValue: "5",
OddsType: types.OddsType_ODDS_TYPE_DECIMAL,
Creator: simappUtil.TestParamUsers["user1"].Address.String(),
},
betOdds: map[string]*types.BetOddsCompact{
Expand Down Expand Up @@ -151,7 +150,6 @@ func TestWager(t *testing.T) {
OddsUID: "odds1",
Amount: sdk.NewInt(100),
OddsValue: "5",
OddsType: types.OddsType_ODDS_TYPE_DECIMAL,
Creator: simappUtil.TestParamUsers["user1"].Address.String(),
},
betOdds: map[string]*types.BetOddsCompact{
Expand Down Expand Up @@ -191,7 +189,6 @@ func TestWager(t *testing.T) {
OddsUID: "odds1",
Amount: sdk.NewInt(1000000),
OddsValue: "5",
OddsType: types.OddsType_ODDS_TYPE_DECIMAL,
Creator: simappUtil.TestParamUsers["user1"].Address.String(),
MaxLossMultiplier: sdk.MustNewDecFromStr("0.1"),
},
Expand Down
8 changes: 6 additions & 2 deletions x/bet/simulation/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ func TestDecodeStore(t *testing.T) {
Amount: sdk.NewInt(10),
Ticket: "",
},
types.OddsType_ODDS_TYPE_DECIMAL,
&types.BetOdds{
UID: uuid.NewString(),
MarketUID: uuid.NewString(),
Value: "100",
MaxLossMultiplier: sdk.NewDec(1),
})
},
types.MetaData{
SelectedOddsType: types.OddsType_ODDS_TYPE_DECIMAL,
SelectedOddsValue: "1.5",
},
)

betUID := types.UID2ID{
UID: bet.UID,
Expand Down
Loading
Loading