Store

Defines the way in which the state of the Bet is being stored in the chain.

Bet

The Bet message is used to store the data of a particular bet placed in the blockchain. The bet entity consists of the following fields:

  1. uid: It is the unique identifier of a bet.

  2. market_uid: It is the unique identifier of a market.

  3. odds_uid: It is the unique identifier of an odds.

  4. odds_type: It denotes the type of odds.

  5. odds_value: It is the value of odds

  6. amount: It is the total wager amount for a bet.

  7. bet_fee: It is the number of tokens deducted from the amount (or total wager amount) as the betting fee.

  8. status: It denotes the status of the bet that whether the bet is placed or settled, etc.

  9. result: It is the result of the bet after the bet settlement.

  10. creator: It is the creator of the transaction, which means the Bettor.

  11. created_at: It is the timestamp at which the bet was placed on the system.

  12. settlement_height: is the height at that the bet will be settled.

  13. max_loss_multiplier: is the multiplier coefficient of the maximum loss.

  14. bet_fulfillment: is the fulfillment of the participation item and payout amount.

The proto for the Bet messages is as follows:

// Bet is the transaction order placed by a bettor on a specific event and odd
message Bet {
  // uid is the universal unique identifier assigned to a bet.
  string uid = 1 [
    (gogoproto.customname) = "UID",
    (gogoproto.jsontag) = "uid",
    json_name = "uid"
  ];

  // market_uid is the universal unique identifier of
  // the market on which the bet is placed.
  string market_uid = 2 [
    (gogoproto.customname) = "MarketUID",
    (gogoproto.jsontag) = "market_uid",
    json_name = "market_uid"
  ];

  // odds_uid is the universal unique identifier,
  // of the odds on which the bet is placed.
  string odds_uid = 3 [
    (gogoproto.customname) = "OddsUID",
    (gogoproto.jsontag) = "odds_uid",
    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;

  // amount is the wager amount.
  string amount = 6 [
    (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 [
    (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;

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

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

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

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

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

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

Enums

Bet Status

It states the various types of the state a bet can have throughout its lifetime.

// Status of the Bet.
enum Status {
    // the invalid or unknown
    STATUS_UNSPECIFIED = 0;
    // bet is placed
    STATUS_PLACED = 1;
    // bet is canceled by Bettor
    STATUS_CANCELED = 2;
    // bet is aborted
    STATUS_ABORTED = 3;
    // bet is pending for getting placed
    STATUS_PENDING = 4;
    // bet result is declared
    STATUS_RESULT_DECLARED = 5;
    // the bet is settled
    STATUS_SETTLED = 6;
}

Result

It states the various types of states the result of a bet can have after the bet settlement.

// Result of the bet.
enum Result {
  // the invalid or unknown
  RESULT_UNSPECIFIED = 0;
  // bet result is pending
  RESULT_PENDING = 1;
  // bet won by the bettor
  RESULT_WON = 2;
  // bet lost by the bettor
  RESULT_LOST = 3;
  // bet is refunded
  RESULT_REFUNDED = 4;
}

Odds Type

It states the various types of odds that the system supports.

// OddsType is the representation of the type of the odds.
enum OddsType {
  // invalid odds type
  ODDS_TYPE_UNSPECIFIED = 0;
  // decimal odds type (european)
  ODDS_TYPE_DECIMAL = 1;
  // fractional odds type (british)
  ODDS_TYPE_FRACTIONAL = 2;
  // moneyline odds type (american)
  ODDS_TYPE_MONEYLINE = 3;
}

UID2ID

The Bet message is used to store the map of UIDs and sequential numeric IDs generated by the blockchain:

// UID2ID is the type for mapping UIDs and Sequential IDs of bets.
message UID2ID {
  // uid is the universal unique identifier assigned to the bet.
  string uid = 1 [
    (gogoproto.customname) = "UID",
    (gogoproto.jsontag) = "uid",
    json_name = "uid"
  ];

  // id is an autogenerated sequential id for a bet.
  uint64 id = 2 [
    (gogoproto.customname) = "ID",
    (gogoproto.jsontag) = "id",
    json_name = "id"
  ];
}

PendingBet

The active bet holds the information required for the bets that are not settled yet.

// PendingBet is the type for an unsettled bet
message PendingBet {
  // uid is the universal unique identifier for the bet.
  string uid = 1 [
    (gogoproto.customname) = "UID",
    (gogoproto.jsontag) = "uid",
    json_name = "uid"
  ];
  // creator is the bettor address.
  string creator = 2;
}

SettledBet

The active bet holds the information required for the bets that are settled.

// SettledBet is the type for a settled bet.
message SettledBet {
  // uid is the universal unique identifier for the bet.
  string uid = 1 [
    (gogoproto.customname) = "UID",
    (gogoproto.jsontag) = "uid",
    json_name = "uid"
  ];
  // bettor_address is the bech32 address of the bettor account.
  string bettor_address = 2;
}

Betstats

The Bet message is used to store any statistics that need to be tracked by the blockchain, currently, it tracks the total count of bets only.

message BetStats {
  // count is the total count of bets
  uint64 count = 1;
}

BetFulfillnent

The fulfillment data structure for the participation and payout amount.

// BetFulfillment: A bet can be fulfilled by multiple users participating as a
// house Every participant is exposed to a share of risk or payout associated
// with the bet For the risk exposure on a bet, an estimated bet amount is also
// allocated to the participant This bet amount is the amount participant
// receive if the bettor loose the bet
message BetFulfillment {
  // participant_address is the bech32-encoded address of the participant
  // fulfilling bet.
  string participant_address = 1
      [ (gogoproto.moretags) = "yaml:\"participant_address\"" ];
  // participation_index is the index in initial participation queue index
  uint64 participation_index = 2
      [ (gogoproto.moretags) = "yaml:\"participation_index\"" ];
  // bet amount fulfilled by the participation
  string bet_amount = 3 [
    (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
    (gogoproto.nullable) = false,
    (gogoproto.moretags) = "yaml:\"bet_amount\""
  ];
  // payout_profit is the fulfilled profit by the participation.
  string payout_profit = 4 [
    (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
    (gogoproto.nullable) = false,
    (gogoproto.moretags) = "yaml:\"payout_profit\""
  ];
}

Payout

Supported Odds Types

Note: Let bet_amount be 3564819

  • Decimal(European): Calculated as bet_amount * oddsValue ex. 3564819 * 1.29 = 4598616.51.

  • Fractional(British): Calculated as bet_amount + (bet_amount * fraction) ex. 3564819 + (3564819 * 2/7) = 4583338.71.

  • Moneyline(American): Calculated as:

    • Positive odds value: bet_amount + (bet_amount * |oddsValue/100|) ex. 3564819 + 3564819 * |+350/100| = 16041685.50 the result will be rounded to floor.

    • Negative odds value: bet_amount + (bet_amount * |100/oddsValue|) ex. 3564819 + 3564819 * |100/-350| = 4583338.71 the result will be rounded to floor.

Precision

Some of the Online Calculators round the division result to two-digit precision in Fractional and Moneyline calculations. In other words, these online calculators try to convert Moneyline and Fractional odds to Decimal odds and then calculate the payout according to the calculated rounded decimal value. This approach makes a big difference in the resulting payout. SGE-Network is accepting bets with usge that may have a high value in the market. For this kind of value, it is better to have a high-precision calculation in the blockchain code.

Note: The final calculated payout amounts are rounded to 2-digit float values, so we have a small portion of lost benefits/payouts.

Last updated