Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Bet module, module accounts definition.
There is one account in the Bet module.
Bet Fee Collector: This account holds the betting fee transferred from the bettor to the bet_fee_collector
module account.
During bet wagering, the betting fee is transferred from the bettor's account to the bet module account of the Bet module.
Name of the account: bet_fee_collector
This section elaborates on the transaction message handler methods being exposed by the Bet module.
When a wager transaction is processed, the following things happen:
If KYC is not ignored, KYC validation of the user should be approved and KYC ID should be equal to the creator's address.
Then, invoke the OVM module to validate the ticket.
After the ticket validation, the Order Book module is invoked to manage the transfer of funds involved in the process and distribute the participation exposures.
Then, a new bet will be created with the given data and stored in the bet module's KVStore, in the following way:
The RPC for adding a market is as follows:
The request message for Wager
is MsgWager
. The proto for the request message is as follows:
The response message Wager
is MsgWagerResponse
. The proto for the request message is as follows:
SGE blockchain application bet module description
The Bet module receives and processes requests to accept wagers and settles bets. In the case of wagering, it validates the request and places the bet.
For the settlement, the blockchain automatically queries resolved markets and then for each of these markets, checks the result of the market, and determines the betting result, then the order book
The module responsible for the participation and fund management distribution will transfer the calculated values to the participants and the bettor accounts according to the settlement status.
Bet module CLI.
This section specifies the queries, transactions, and required payloads. By following this section, one can get a deep understanding of the functioning of the bet
module in the SGE Network chain.
Bet module parameter types and definition.
The Bet module has the following parameters:
Batch Settlement Count: this is the count of bets to be settled automatically in each block.
Max bet by UID query count: is the max count of bets to be returned in the bets by UID list query.
Constraints: contains the bet wagering constraints.
The proto for the params is as follows:
Constraints define the constraints that will apply while accepting bets. The following constraints can be applied to the bet acceptance criteria:
Min Amount: Blockchain should not accept bets with a bet amount (after the deduction of the bet fee) less than the value stored in this field.
Fee: Blockchain should set a fee for every bet it accepts.
The proto for the constraints are as follows:
Defines the way in which the state of the Bet is being stored in the chain.
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:
uid
: It is the unique identifier of a bet.
market_uid
: It is the unique identifier of a market.
odds_uid
: It is the unique identifier of an odds.
odds_type
: It denotes the type of odds.
odds_value
: It is the value of odds
amount
: It is the total wager amount for a bet.
bet_fee
: It is the number of tokens deducted from the amount (or total wager amount) as the betting fee.
status
: It denotes the status of the bet that whether the bet is placed or settled, etc.
result
: It is the result of the bet after the bet settlement.
creator
: It is the creator of the transaction, which means the Bettor.
created_at
: It is the timestamp at which the bet was placed on the system.
settlement_height
: is the height at that the bet will be settled.
max_loss_multiplier
: is the multiplier coefficient of the maximum loss.
bet_fulfillment
: is the fulfillment of the participation item and payout amount.
The proto for the Bet messages is as follows:
It states the various types of the state a bet can have throughout its lifetime.
It states the various types of states the result of a bet can have after the bet settlement.
It states the various types of odds that the system supports.
The Bet message is used to store the map of UIDs and sequential numeric IDs generated by the blockchain:
The active bet holds the information required for the bets that are not settled yet.
The active bet holds the information required for the bets that are settled.
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.
The fulfillment data structure for the participation and payout amount.
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.
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.
The main logic of the Bet module definitions and methods.
There are several steps for an incoming bet to be placed:
Check for duplicate UID
Validate the Ticket and unmarshal it to the wager payload type types.WagerTicketPayload
KYC validation according to the creator address in the message and the KYC address of the ticket if required.
Get the corresponding market from the market module and validate the odds existence.
Validate the minimum bet amount according to the module parameters.
Calculate and set the betting fee.
Validate and calculate the payout profit according to the odds type, bet amount, and odds value.
Call ProcessWager
method of the Order Book module. this method handles the lock/unlock of the payout, participations, and bet fulfillments and transfers the payout and fees to the corresponding module accounts.
Set the initial Status
, Result
,CreatedAt
, and BetFulfillments
attributes.
Calculate the sequential ID, Set bet statistics, and bet to the bet module state.
There are several steps for an incoming bet to be settled:
Check UUID validity
Get the corresponding bet object
Validates the bet creator stored in the state with the incoming bettorAddress
of the settlement message.
Check the bet status not to be canceled or settled before.
Get the corresponding market from the market store and check if it exists, and is not aborted or canceled. If it is, calculate the payout and refund the bettor using RefundBettor
method of the Order Book module keeper then sets the bet status as settled and finalizes the method.
Sets the proper bet result according to the WinnerOddsUIDs
.
According to the bet result determined in the previous step, call BettorWins
or BettorLoses
of the Order Book module keeper.
Set the settled bet in the bet module state.
This is being used in the bet module end blocker in order to settle the bets automatically in batch.
Bet module CLI queries.
Queries of this module can be used to get the data of bets placed in the blockchain and params. The following queries have been exposed by the Bet module:
Queries of this module can be used to get the data of bets placed in the blockchain and params. The following queries have been exposed by the Bet module:
The below table explains the details of the argument required for the above query:
The below table explains the details of the argument required for the above query:
The below table explains the details of the argument required for the above query:
The below table explains the details of the argument required for the above query:
The creator:uid pair is separated by a colon :
and each pair is separated by a comma ,
from other pairs.
The exposed transactions CLI commands and ticket payloads by the Bet module.
The below transaction can be used to place a bet on the blockchain.
The below table specifies the details of the arguments used in the above transaction:
The payload for the place-bet transaction is as follows:
The values in the payload should be changed according to the data.
The details of the payload parameters are stated in the below table:
Params | Description | Type | Validation | Example |
---|
Params | Description | Type | Validation | Example |
---|
Params | Description | Type | Validation | Example |
---|
Params | Description | Type | Validation | Example |
---|
Argument | Description | Type | Validation | Example |
---|
Params | Description | Type | Validation | Example |
---|
creator | creator account address | string |
| sge1059gavv45jdp0l7c4kkskr0jae02j9cxmjr3f3 |
uid | UID of market | string |
| 0435e5b6-635f-11ed-90a6-bb470175dfce |
creator | creator account address | string |
| sge1059gavv45jdp0l7c4kkskr0jae02j9cxmjr3f3 |
UID | UUID of the bet | string |
| 0435e5b6-635f-11ed-90a6-bb470175dfce |
creator:uid | creator account address and UID pair list | string |
| sge1059gavv45jdp0l7c4kkskr0jae02j9cxmjr3f3:0435e5b6-635f-11ed-90a6-bb470175dfce |
uid | Unique Identifier of a the bet | string |
| 0435e5b6-635f-11ed-90a6-bb470175dfce |
amount | It is the total wager amount (contains bet fee also) | Integer |
| 100000000 |
ticket | Used for market verification. | String (JWT token) |
| 1eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiI5OTkxYzYwZi0yMDI1LTQ4Y2UtYWU3OS0xZGMxMTBmMTY5OTkiLCJ4aWQiOiJCZXRPZGQiLCJuYW1lIjoiMSIsImJldF9ldmVudF91aWQiOiI1NTMxYzYwZi0yMDI1 |
selected_odds | The selected odds for the bet | Odds Value will be validated according to the OddsType selected in the bet placement message. there are three types of validation according to the Decimal, Fractional and Moenyline odds | { "uid": "9991c60f-2025-48ce-ae79-1dc110f16990", "market_uid": "5531c60f-2025-48ce-ae79-1dc110f16007", "value": "2.0"} |
uid | Unique identifier of the odds on which the bet should be placed |
| "uid": "2231c60f-2025-48ce-ae79-1dc110f16444" |
value | Value of the odd selected by the bettor | sdk.Dec |
| "value": "5.0" |
market_uid | Unique identifier of the market on which the bet should be placed |
| "market_uid": "5531c60f-2025-48ce-ae79-1dc110f16001 |
kyc_data | Data related to the user kyc | KycData | { "ignore": true, "approved": true, "id": "userID" } |
kyc_ignore | If indend to disable the KYC validation should be set as true | boolean | false |
kyc_approved | Tells whether KYC is approved for the user or not | boolean | true |
kyc_id | Account address of the user | string |
| sge1na4f4c8m9hzlxqttl4jfnnyhsd94hsg9ykqxez |
max_loss_multiplier | A coefficient for maximum loss prevention | string | should be less than one | 0.5 |
odds_type | Type of the odds | uint32 | 1 |
iat | Epoch timestamp for issuance of the ticket by oracle in seconds | int64 | 1657270827 |
exp | Ticket-expiration epoch timestamp in seconds | int64 | 1657270827 |
iss | Issuer of the ticket | string | “Oracle” |
sub | Subject of the payload or mostly the name of the transaction | string | “Place Bet” |
Should be a proper UUID ()
Should be a proper UUID ()