Store

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

OrderBook

The OrderBook message is used to store the data of a particular order book in the blockchain. The OrderBook entity consists of the following fields:

  1. uid: The UID of the order book.

  2. participation_count: The count of participation in this book.

  3. odds_count: Count of odds registered in the market related to this book.

  4. status: the status of the book.

The proto for the Order Book messages is as follows:

// OrderBook represents the order book maintained against a market.
message OrderBook {
  option (gogoproto.equal) = false;
  option (gogoproto.goproto_getters) = false;
  option (gogoproto.goproto_stringer) = false;

  // uid is the universal unique identifier of the order book.
  string uid = 1 [
    (gogoproto.customname) = "UID",
    (gogoproto.jsontag) = "uid",
    json_name = "uid"
  ];

  // participation_count is the count of participations in the order book.
  uint64 participation_count = 2
      [ (gogoproto.moretags) = "yaml:\"participation_count\"" ];

  // odds_count is the count of the odds in the order book.
  uint64 odds_count = 3 [ (gogoproto.moretags) = "yaml:\"odds_count\"" ];

  // status represents the status of the order book.
  OrderBookStatus status = 4;
}

Enums

// OrderBookStatus is the enum type for the status of the orderbook.
enum OrderBookStatus {
  // invalid
  ORDER_BOOK_STATUS_UNSPECIFIED = 0;
  // active
  ORDER_BOOK_STATUS_STATUS_ACTIVE = 1;
  // resolved not settled
  ORDER_BOOK_STATUS_STATUS_RESOLVED = 2;
  // resolved and settled
  ORDER_BOOK_STATUS_STATUS_SETTLED = 3;
}

OrderBookParticipation

The BookParticipation message is used to store the data of a particular participation in the OrderBook in the blockchain. The BookParticipation entity consists of the following fields:

  1. index: The sequential index of participation in a book.

  2. order_book_uid: The uinque identifier of the OrderBook.

  3. participant_address: The account address of the participant.

  4. liquidity: The amount of participation minus fees.

  5. current_round_liquidity: Participations are calculated in multiple rounds depending on the payout amount.

  6. exposures_not_filled: The count of exposures that are not filled till now.

  7. total_bet_amount: Total value of bet amount that is calculated from the payout.

  8. current_round_total_bet_amount: Total value of bet amount in the current round calculations.

  9. max_loss: Maximum possible loss of participation.

  10. current_round_max_loss_odds_uid: UID list of odds with maximum calculated loss.

  11. actual_profit: The pure profit that goes to the participant account balance.

  12. is_settled: Show whether the participation is settled or not.

The proto for the Order Book messages is as follows:

// OrderBookParticipation represents the participants of an order book.
message OrderBookParticipation {
  option (gogoproto.equal) = false;
  option (gogoproto.goproto_getters) = false;
  option (gogoproto.goproto_stringer) = false;

  // index is the index of the participation in the participation queue.
  uint64 index = 1 [ (gogoproto.moretags) = "yaml:\"index\"" ];

  // order_book_uid is the unique identifier corresponding to the order book.
  string order_book_uid = 2 [
    (gogoproto.customname) = "OrderBookUID",
    (gogoproto.jsontag) = "order_book_uid",
    json_name = "order_book_uid"
  ];

  // participant_address is the bech32-encoded address of the participant.
  string participant_address = 3
      [ (gogoproto.moretags) = "yaml:\"participant_address\"" ];

  // liquidity is the total initial liquidity provided.
  string liquidity = 4 [
    (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
    (gogoproto.nullable) = false,
    (gogoproto.moretags) = "yaml:\"liquidity\""
  ];

  // fee is the amount of fee to be paid if participation happens.
  string fee = 5 [
    (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
    (gogoproto.nullable) = false,
    (gogoproto.moretags) = "yaml:\"fee\""
  ];

  // current_round_liquidity is the liquidity provided for the current round.
  string current_round_liquidity = 6 [
    (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
    (gogoproto.nullable) = false,
    (gogoproto.moretags) = "yaml:\"current_round_liquidity\""
  ];

  // exposures_not_filled represents if all of the exposures of the
  // participation are filled or not.
  uint64 exposures_not_filled = 7
      [ (gogoproto.moretags) = "yaml:\"exposures_not_filled\"" ];

  // total_bet_amount is the total bet amount corresponding to all exposures.
  string total_bet_amount = 8 [
    (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
    (gogoproto.nullable) = false,
    (gogoproto.moretags) = "yaml:\"total_bet_amount\""
  ];

  // current_round_total_bet_amount is the total bet amount corresponding to all
  // exposures in the current round.
  string current_round_total_bet_amount = 9 [
    (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
    (gogoproto.nullable) = false,
    (gogoproto.moretags) = "yaml:\"current_round_total_bet_amount\""
  ];

  // max_loss is the total bet amount corresponding to all exposure.
  string max_loss = 10 [
    (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
    (gogoproto.nullable) = false,
    (gogoproto.moretags) = "yaml:\"max_loss\""
  ];

  // current_round_max_loss is the current round max loss.
  string current_round_max_loss = 11 [
    (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
    (gogoproto.nullable) = false,
    (gogoproto.moretags) = "yaml:\"current_round_max_loss\""
  ];

  // current_round_max_loss_odds_uid is the total max loss corresponding to
  // all exposures.
  string current_round_max_loss_odds_uid = 12 [
    (gogoproto.customname) = "CurrentRoundMaxLossOddsUID",
    (gogoproto.jsontag) = "current_round_max_loss_odds_uid",
    json_name = "current_round_max_loss_odds_uid",
    (gogoproto.moretags) = "yaml:\"current_round_max_loss_odds_uid\""
  ];

  // actual_profit is the actual profit of the participation fulfillment.
  string actual_profit = 13 [
    (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
    (gogoproto.nullable) = false,
    (gogoproto.moretags) = "yaml:\"actual_profit\""
  ];

  // is_settled represents if the participation is settled or not.
  bool is_settled = 14 [ (gogoproto.moretags) = "yaml:\"is_settled\"" ];
}

ParticipationBetPair

The ParticipationBetPair message is used to store the data of a particular participation and bet in the OrderBook in the blockchain. The ParticipationBetPair entity consists of the following fields:

  1. order_book_uid: The uinque identifier of the OrderBook.

  2. participant_index: The index of participation in a book.

  3. bet_uid: True unique identifier of bet that payout was done from participation.

// ParticipationBetPair represents the book participation and bet bond.
message ParticipationBetPair {
  // order_book_uid is the unique identifier corresponding to the order book
  string order_book_uid = 1 [
    (gogoproto.customname) = "OrderBookUID",
    (gogoproto.jsontag) = "order_book_uid",
    json_name = "order_book_uid"
  ];

  // participation_index is the index of participation corresponding to the bet
  // fulfillment.
  uint64 participation_index = 2
      [ (gogoproto.moretags) = "yaml:\"participation_index\"" ];

  // bet_uid is the bet universal unique identifier of the bet that is
  // fulfilled.
  string bet_uid = 3 [
    (gogoproto.customname) = "BetUID",
    (gogoproto.jsontag) = "bet_uid",
    json_name = "bet_uid"
  ];
}

OrderBookOddsExposure

The BookOddsExposure message is used to store the data of a particular exposure of odds in the OrderBook in the blockchain. The BookOddsExposure entity consists of the following fields:

  1. order_book_uid: The uinque identifier of the OrderBook.

  2. odds_uid: The unique identifier of the odds.

  3. fulfillment_queue: The queue of bet fulfillment for the odds exposure.

// OrderBookOddsExposure represents the exposures taken on odds.
message OrderBookOddsExposure {
  option (gogoproto.equal) = false;
  option (gogoproto.goproto_getters) = false;
  option (gogoproto.goproto_stringer) = false;

  // order_book_uid is the universally unique identifier corresponding to the
  // order book.
  string order_book_uid = 1 [
    (gogoproto.customname) = "OrderBookUID",
    (gogoproto.jsontag) = "order_book_uid",
    json_name = "order_book_uid"
  ];

  // odds_uid is the universally unique identifier of the odds.
  string odds_uid = 2 [
    (gogoproto.customname) = "OddsUID",
    (gogoproto.jsontag) = "odds_uid",
    json_name = "odds_uid"
  ];

  // fulfillment_queue is the slice of indices of participations to be
  // fulfilled.
  repeated uint64 fulfillment_queue = 3
      [ (gogoproto.moretags) = "yaml:\"fulfillment_queue\"" ];
}

ParticipationExposure

The ParticipationExposure message is used to store the data of a particular exposure of participation in the OrderBook in the blockchain. The ParticipationExposure entity consists of the following fields:

  1. order_book_uid: The uinque identifier of the OrderBook.

  2. odds_uid: The unique identifier of the Odds.

  3. participation_index: The index of participation in the Order book.

  4. exposure: The exposure is the payout that should be done.

  5. bet_amount: The calculated bet amount of the expected payout.

  6. is_fulfilled: Fulfillment status of the exposure.

  7. round: Current round of calculation of exposures.

// ParticipationExposure represents the exposures taken on odds by
// participations.
message ParticipationExposure {
  option (gogoproto.equal) = false;
  option (gogoproto.goproto_getters) = false;
  option (gogoproto.goproto_stringer) = false;

  // order_book_uid is the universally unique identifier of the order book that
  // the exposure is being set.
  string order_book_uid = 1 [
    (gogoproto.customname) = "OrderBookUID",
    (gogoproto.jsontag) = "order_book_uid",
    json_name = "order_book_uid"
  ];

  // odds_uid is the odds universal unique identifier that the exposure is being
  // set.
  string odds_uid = 2 [
    (gogoproto.customname) = "OddsUID",
    (gogoproto.jsontag) = "odds_uid",
    json_name = "odds_uid"
  ];

  // participation_index is the index of participation in the queue.
  uint64 participation_index = 3
      [ (gogoproto.moretags) = "yaml:\"participation_index\"" ];

  // exposure is the total exposure taken on given odds.
  string exposure = 4 [
    (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
    (gogoproto.nullable) = false,
    (gogoproto.moretags) = "yaml:\"exposure\""
  ];

  // bet_amount is the total bet amount corresponding to the exposure.
  string bet_amount = 5 [
    (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
    (gogoproto.nullable) = false,
    (gogoproto.moretags) = "yaml:\"bet_amount\""
  ];

  // is_fulfilled represents if the participation exposure is fulfilled or not.
  bool is_fulfilled = 6 [ (gogoproto.moretags) = "yaml:\"is_fulfilled\"" ];

  // round is the current round number in the queue.
  uint64 round = 7 [ (gogoproto.moretags) = "yaml:\"round\"" ];
}

OrderBookStats

The OrderBookStats message is used to store the statistics data of Order Books in the blockchain. The OrderBookStats entity consists of the following fields:

  1. resolved_unsettled: The list of resolved markets that have unsettled bets.

// OrderBookStats holds statistics of the order-book
message OrderBookStats {
  // resolved_unsettled is the list of book ids that needs to be settled.
  repeated string resolved_unsettled = 1;
}

Purpose

The purpose of this lock is to maintain idempotency in the system. The payout lock checks for idempotency whenever an exported keeper function of the module is invoked by any other module. It follows the following conditions:

  1. While wagering

    • If a payout lock (or bet UID) exists in the store, then the wager request is rejected, inferring that the bet has already been placed in the blockchain with the same bet UID.

    • If the payout lock does not exist, then the wager request is accepted and a payout lock with the bet UID of the bet is stored in the blockchain.

  2. While bet settlement

    • If the payout lock does not exist in the store, then the bet settlement request is rejected.

    • If the payout lock exists, then the bet settlement request is accepted, the settlement is processed, and the payout is deleted from the store.

Last updated