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.