Skip to content

Commit

Permalink
fix: remove odds type other than decimal
Browse files Browse the repository at this point in the history
  • Loading branch information
scorpioborn committed Oct 31, 2023
1 parent 415e28c commit f776996
Show file tree
Hide file tree
Showing 27 changed files with 181 additions and 811 deletions.
27 changes: 13 additions & 14 deletions docs/specs/Bet/04_State.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,48 +89,47 @@ 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;
string odds_value = 4;
// amount is the wager amount.
string amount = 6 [
string amount = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
// fee is the betting fee user needs to pay for placing a bet
string fee = 7 [
string fee = 6 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
// status is the status of the bet, such as `unspecified` or `settled`.
Status status = 8;
Status status = 7;
// result is the result of the bet, such as `won` or `lost`.
Result result = 9;
Result result = 8;
// creator is the bettor address.
string creator = 10;
string creator = 9;
// created_at is the bet placement timestamp.
int64 created_at = 11;
int64 created_at = 10;
// settlement_height is the block height at which the bet is settled.
int64 settlement_height = 12;
int64 settlement_height = 11;
// max_loss_multiplier is the multiplier coefficient of max loss.
string max_loss_multiplier = 13 [
string max_loss_multiplier = 12 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// bet_fulfillment is the fulfillment data.
repeated BetFulfillment bet_fulfillment = 14;
repeated BetFulfillment bet_fulfillment = 13;
// meta is metadata for bet
MetaData meta = 14;
// Status of the Bet.
enum Status {
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
26 changes: 11 additions & 15 deletions proto/sge/bet/bet.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,51 +31,47 @@ 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;
string odds_value = 4;

// amount is the wager amount.
string amount = 6 [
string amount = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];

// fee is the betting fee user needs to pay for placing a bet
string fee = 7 [
string fee = 6 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];

// status is the status of the bet, such as `unspecified` or `settled`.
Status status = 8;
Status status = 7;

// result is the result of the bet, such as `won` or `lost`.
Result result = 9;
Result result = 8;

// creator is the bettor address.
string creator = 10;
string creator = 9;

// created_at is the bet placement timestamp.
int64 created_at = 11;
int64 created_at = 10;

// settlement_height is the block height at which the bet is settled.
int64 settlement_height = 12;
int64 settlement_height = 11;

// max_loss_multiplier is the multiplier coefficient of max loss.
string max_loss_multiplier = 13 [
string max_loss_multiplier = 12 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

// bet_fulfillment is the fulfillment data.
repeated BetFulfillment bet_fulfillment = 14;
repeated BetFulfillment bet_fulfillment = 13;

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

// Status of the Bet.
enum Status {
Expand Down
8 changes: 2 additions & 6 deletions proto/sge/bet/ticket.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import "gogoproto/gogo.proto";
import "sge/type/kyc.proto";
import "sge/bet/bet_odds.proto";
import "sge/bet/bet.proto";
import "sge/bet/odds_type.proto";

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

Expand All @@ -17,11 +16,8 @@ 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;
repeated BetOddsCompact all_odds = 3;
// meta is metadata for bet placement
MetaData meta = 5;
MetaData meta = 4;
}
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
2 changes: 1 addition & 1 deletion x/bet/keeper/msg_server_bet.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (k msgServer) Wager(
return nil, sdkerrors.Wrapf(types.ErrInTicketValidation, "%s", err)
}

bet := types.NewBet(msg.Creator, msg.Props, payload.OddsType, payload.SelectedOdds, payload.Meta)
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)
Expand Down
2 changes: 0 additions & 2 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 Down Expand Up @@ -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
4 changes: 2 additions & 2 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,7 +57,7 @@ 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)
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
1 change: 0 additions & 1 deletion x/bet/simulation/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func TestDecodeStore(t *testing.T) {
Amount: sdk.NewInt(10),
Ticket: "",
},
types.OddsType_ODDS_TYPE_DECIMAL,
&types.BetOdds{
UID: uuid.NewString(),
MarketUID: uuid.NewString(),
Expand Down
Loading

0 comments on commit f776996

Please sign in to comment.