@block52/poker-vm-sdk 1.16.0 → 1.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -4473,24 +4473,33 @@ function isSet$2b(value) {
4473
4473
  return value !== null && value !== undefined;
4474
4474
  }
4475
4475
 
4476
- // Proto-generated MessageFns types need casting to cosmjs GeneratedType
4476
+ /**
4477
+ * Adapts a ts-proto MessageFns to cosmjs's GeneratedType (poker-vm#1939).
4478
+ * cosmjs types its writer as protobufjs's Writer class; ours is @bufbuild's
4479
+ * BinaryWriter, a different class with the same contract. The Registry only
4480
+ * calls fromPartial, encode(...).finish() and decode(bytes), all of which
4481
+ * MessageFns provides, so this is the one place that bridges the two. Both
4482
+ * writer types are classes with private members, so no structural adapter can
4483
+ * satisfy GeneratedType without this cast.
4484
+ */
4485
+ const asGeneratedType = (fns) => fns;
4477
4486
  const msgTypes$u = [
4478
- ["/pokerchain.poker.v1.MsgUpdateParams", MsgUpdateParams$d],
4479
- ["/pokerchain.poker.v1.MsgCreateGame", MsgCreateGame],
4480
- ["/pokerchain.poker.v1.MsgJoinGame", MsgJoinGame],
4481
- ["/pokerchain.poker.v1.MsgLeaveGame", MsgLeaveGame],
4482
- ["/pokerchain.poker.v1.MsgRecordHandEnd", MsgRecordHandEnd],
4483
- ["/pokerchain.poker.v1.MsgDealCards", MsgDealCards],
4484
- ["/pokerchain.poker.v1.MsgPerformAction", MsgPerformAction],
4485
- ["/pokerchain.poker.v1.MsgMint", MsgMint],
4486
- ["/pokerchain.poker.v1.MsgBurn", MsgBurn],
4487
- ["/pokerchain.poker.v1.MsgProcessDeposit", MsgProcessDeposit],
4488
- ["/pokerchain.poker.v1.MsgInitiateWithdrawal", MsgInitiateWithdrawal],
4489
- ["/pokerchain.poker.v1.MsgUpdateEthBlockHeight", MsgUpdateEthBlockHeight],
4490
- ["/pokerchain.poker.v1.MsgTopUp", MsgTopUp],
4491
- ["/pokerchain.poker.v1.MsgDeleteGame", MsgDeleteGame],
4492
- ["/pokerchain.poker.v1.MsgForceCloseGame", MsgForceCloseGame],
4493
- ["/pokerchain.poker.v1.MsgRegisterNftAvatar", MsgRegisterNftAvatar],
4487
+ ["/pokerchain.poker.v1.MsgUpdateParams", asGeneratedType(MsgUpdateParams$d)],
4488
+ ["/pokerchain.poker.v1.MsgCreateGame", asGeneratedType(MsgCreateGame)],
4489
+ ["/pokerchain.poker.v1.MsgJoinGame", asGeneratedType(MsgJoinGame)],
4490
+ ["/pokerchain.poker.v1.MsgLeaveGame", asGeneratedType(MsgLeaveGame)],
4491
+ ["/pokerchain.poker.v1.MsgRecordHandEnd", asGeneratedType(MsgRecordHandEnd)],
4492
+ ["/pokerchain.poker.v1.MsgDealCards", asGeneratedType(MsgDealCards)],
4493
+ ["/pokerchain.poker.v1.MsgPerformAction", asGeneratedType(MsgPerformAction)],
4494
+ ["/pokerchain.poker.v1.MsgMint", asGeneratedType(MsgMint)],
4495
+ ["/pokerchain.poker.v1.MsgBurn", asGeneratedType(MsgBurn)],
4496
+ ["/pokerchain.poker.v1.MsgProcessDeposit", asGeneratedType(MsgProcessDeposit)],
4497
+ ["/pokerchain.poker.v1.MsgInitiateWithdrawal", asGeneratedType(MsgInitiateWithdrawal)],
4498
+ ["/pokerchain.poker.v1.MsgUpdateEthBlockHeight", asGeneratedType(MsgUpdateEthBlockHeight)],
4499
+ ["/pokerchain.poker.v1.MsgTopUp", asGeneratedType(MsgTopUp)],
4500
+ ["/pokerchain.poker.v1.MsgDeleteGame", asGeneratedType(MsgDeleteGame)],
4501
+ ["/pokerchain.poker.v1.MsgForceCloseGame", asGeneratedType(MsgForceCloseGame)],
4502
+ ["/pokerchain.poker.v1.MsgRegisterNftAvatar", asGeneratedType(MsgRegisterNftAvatar)],
4494
4503
  ];
4495
4504
 
4496
4505
  /**
@@ -56127,6 +56136,9 @@ exports.NonPlayerActionType = void 0;
56127
56136
  // player's bet (they're matched) but excluded from the first-to-act /
56128
56137
  // has-acted scans (it's a non-player action, like DEAD_SMALL_BLIND).
56129
56138
  NonPlayerActionType["POST"] = "post";
56139
+ // A missed small blind posted dead on sitting back in (poker-vm#2200).
56140
+ // Recorded in ANTE; in the pot but not a bet anyone must match (like ANTE).
56141
+ NonPlayerActionType["POST_DEAD"] = "post-dead";
56130
56142
  NonPlayerActionType["SIT_IN"] = "sit-in";
56131
56143
  // Sit in and wait for the big blind — distinct action from SIT_IN (post now)
56132
56144
  // so each has a single responsibility. Sets WAITING_FOR_BIG_BLIND. (#2139)
@@ -56140,12 +56152,13 @@ exports.NonPlayerActionType = void 0;
56140
56152
  // SHOW at showdown — and records THAT action; no "timeout" turn is ever
56141
56153
  // written to previousActions. Rejected while the turn has time remaining.
56142
56154
  NonPlayerActionType["TIMEOUT"] = "timeout";
56143
- // Time bank (ui#19): the player to act extends their turn's action-clock
56144
- // deadline by gameOptions.timeBankMs, once per decision, up to
56145
- // gameOptions.timeBankCapMs held per player (refilled per orbit in ui#20).
56146
- // Records a no-chip turn that does NOT advance the betting order or move the
56147
- // clock anchor; the deadline is derived by counting TIME_BANK turns for the
56148
- // current turn. Rejected off-turn, past the deadline, or with no bank left.
56155
+ // Time bank (ui#19/#20): the player to act extends their turn's action-clock
56156
+ // deadline by their whole bank, once per decision: gameOptions.timeBankMs
56157
+ // the first time, 30s the second, then 5s refilling 5s per orbit up to
56158
+ // gameOptions.timeBankCapMs. Records a no-chip turn that does NOT advance the
56159
+ // betting order or move the clock anchor; the deadline adds the user's
56160
+ // PlayerDTO.timeBankLastGrantMs for the current turn. Rejected off-turn,
56161
+ // past the deadline, or with no bank left.
56149
56162
  NonPlayerActionType["TIME_BANK"] = "time-bank";
56150
56163
  NonPlayerActionType["TOP_UP"] = "top-up";
56151
56164
  // Scheduled single-table tournament (poker-vm#2680): any registered player
@@ -56236,6 +56249,8 @@ const BLIND_PRESETS = ["turbo", "standard", "deep_stack", "hyper_turbo"];
56236
56249
  const BLIND_PROGRESSIONS = ["double", "linear", "percentage", "table"];
56237
56250
  const SIT_OUT_METHOD_NEXT_HAND = "next-hand";
56238
56251
  const SIT_OUT_METHOD_NEXT_BB = "next-bb";
56252
+ const TOURNAMENT_STATUSES = ["registering", "running", "finished", "cancelled"];
56253
+ const TOURNAMENT_ENTRANT_STATUSES = ["registered", "playing", "busted", "unregistered"];
56239
56254
  exports.SUIT = void 0;
56240
56255
  (function (SUIT) {
56241
56256
  SUIT[SUIT["CLUBS"] = 1] = "CLUBS";
@@ -57156,6 +57171,91 @@ function levelMinutes(options) {
57156
57171
  return options.blindLevelDuration;
57157
57172
  }
57158
57173
 
57174
+ /**
57175
+ * Parses the `leaderboard` JSON string of the chain's TournamentLeaderboard
57176
+ * query (block52/pokerchain#405, poker-vm#2613) into a LeaderboardDTO. Checks
57177
+ * the required fields and throws on anything missing or mistyped — never fills
57178
+ * a default (Commandment 7): a malformed board is a chain/engine bug to surface.
57179
+ */
57180
+ function parseLeaderboardDTO(json) {
57181
+ if (json === "") {
57182
+ throw new Error("tournament leaderboard: empty leaderboard JSON");
57183
+ }
57184
+ const raw = JSON.parse(json);
57185
+ if (!isRecord(raw)) {
57186
+ throw new Error("tournament leaderboard: expected a JSON object");
57187
+ }
57188
+ requireString(raw, "tournamentId", "leaderboard");
57189
+ requireStatus(raw, "leaderboard");
57190
+ requireNumber(raw, "entrants", "leaderboard");
57191
+ requireNumber(raw, "remaining", "leaderboard");
57192
+ requireString(raw, "averageStack", "leaderboard");
57193
+ requireString(raw, "prizePool", "leaderboard");
57194
+ if (!Array.isArray(raw.payouts)) {
57195
+ throw new Error("tournament leaderboard: payouts must be an array");
57196
+ }
57197
+ raw.payouts.forEach((p, i) => {
57198
+ const where = `payouts[${i}]`;
57199
+ if (!isRecord(p))
57200
+ throw new Error(`tournament leaderboard: ${where} must be an object`);
57201
+ requireNumber(p, "place", where);
57202
+ requireString(p, "amount", where);
57203
+ });
57204
+ if (raw.clock !== undefined) {
57205
+ if (!isRecord(raw.clock))
57206
+ throw new Error("tournament leaderboard: clock must be an object");
57207
+ requireNumber(raw.clock, "level", "clock");
57208
+ requireString(raw.clock, "smallBlind", "clock");
57209
+ requireString(raw.clock, "bigBlind", "clock");
57210
+ requireString(raw.clock, "ante", "clock");
57211
+ optionalNumber(raw.clock, "levelStartTime", "clock");
57212
+ }
57213
+ optionalNumber(raw, "nextLevelAt", "leaderboard");
57214
+ if (!Array.isArray(raw.entries)) {
57215
+ throw new Error("tournament leaderboard: entries must be an array");
57216
+ }
57217
+ raw.entries.forEach((e, i) => requireEntry(e, `entries[${i}]`));
57218
+ return raw;
57219
+ }
57220
+ function requireEntry(e, where) {
57221
+ if (!isRecord(e))
57222
+ throw new Error(`tournament leaderboard: ${where} must be an object`);
57223
+ requireNumber(e, "rank", where);
57224
+ requireString(e, "address", where);
57225
+ if (!TOURNAMENT_ENTRANT_STATUSES.includes(e.status)) {
57226
+ throw new Error(`tournament leaderboard: ${where}.status "${String(e.status)}" is not an entrant status`);
57227
+ }
57228
+ requireString(e, "stack", where);
57229
+ optionalString(e, "tableId", where);
57230
+ optionalNumber(e, "seat", where);
57231
+ optionalNumber(e, "place", where);
57232
+ optionalString(e, "payout", where);
57233
+ }
57234
+ function requireStatus(o, where) {
57235
+ if (!TOURNAMENT_STATUSES.includes(o.status)) {
57236
+ throw new Error(`tournament leaderboard: ${where}.status "${String(o.status)}" is not a tournament status`);
57237
+ }
57238
+ }
57239
+ function isRecord(v) {
57240
+ return typeof v === "object" && v !== null && !Array.isArray(v);
57241
+ }
57242
+ function requireString(o, key, where) {
57243
+ if (typeof o[key] !== "string")
57244
+ throw new Error(`tournament leaderboard: ${where}.${key} must be a string`);
57245
+ }
57246
+ function requireNumber(o, key, where) {
57247
+ if (typeof o[key] !== "number")
57248
+ throw new Error(`tournament leaderboard: ${where}.${key} must be a number`);
57249
+ }
57250
+ function optionalString(o, key, where) {
57251
+ if (o[key] !== undefined)
57252
+ requireString(o, key, where);
57253
+ }
57254
+ function optionalNumber(o, key, where) {
57255
+ if (o[key] !== undefined)
57256
+ requireNumber(o, key, where);
57257
+ }
57258
+
57159
57259
  /**
57160
57260
  * Poker hand types in order of strength (weakest to strongest)
57161
57261
  */
@@ -58599,10 +58699,10 @@ class CosmosClient {
58599
58699
  async getGameState(gameId) {
58600
58700
  try {
58601
58701
  const response = await this.restClient.get(`/block52/pokerchain/poker/v1/game_state/${gameId}`);
58602
- if (response.data) {
58603
- return response.data;
58702
+ if (!response.data) {
58703
+ throw new Error(`Empty game state response for ${gameId}`);
58604
58704
  }
58605
- return {};
58705
+ return response.data;
58606
58706
  }
58607
58707
  catch (error) {
58608
58708
  console.error("Error fetching game state:", error);
@@ -58615,10 +58715,10 @@ class CosmosClient {
58615
58715
  async getGame(gameId) {
58616
58716
  try {
58617
58717
  const response = await this.restClient.get(`/block52/pokerchain/poker/v1/game/${gameId}`);
58618
- if (response.data) {
58619
- return response.data;
58718
+ if (!response.data) {
58719
+ throw new Error(`Empty game response for ${gameId}`);
58620
58720
  }
58621
- return {};
58721
+ return response.data;
58622
58722
  }
58623
58723
  catch (error) {
58624
58724
  console.error("Error fetching game:", error);
@@ -58665,9 +58765,11 @@ class CosmosClient {
58665
58765
  }
58666
58766
  catch (error) {
58667
58767
  console.error("❌ [CosmosClient] Error listing games:");
58668
- console.error(" Message:", error.message);
58669
- console.error(" Response status:", error.response?.status);
58670
- console.error(" Response data:", error.response?.data);
58768
+ if (axios.isAxiosError(error)) {
58769
+ console.error(" Message:", error.message);
58770
+ console.error(" Response status:", error.response?.status);
58771
+ console.error(" Response data:", error.response?.data);
58772
+ }
58671
58773
  console.error(" Full error:", error);
58672
58774
  throw error;
58673
58775
  }
@@ -58773,9 +58875,10 @@ class CosmosClient {
58773
58875
  */
58774
58876
  async listWithdrawalRequests(cosmosAddress) {
58775
58877
  try {
58878
+ // The chain serves withdrawal_requests; list_withdrawal_requests is a 501 (poker-vm#1939).
58776
58879
  const url = cosmosAddress
58777
- ? `/block52/pokerchain/poker/v1/list_withdrawal_requests?cosmos_address=${cosmosAddress}`
58778
- : `/block52/pokerchain/poker/v1/list_withdrawal_requests`;
58880
+ ? `/block52/pokerchain/poker/v1/withdrawal_requests?cosmos_address=${encodeURIComponent(cosmosAddress)}`
58881
+ : `/block52/pokerchain/poker/v1/withdrawal_requests`;
58779
58882
  const response = await this.restClient.get(url);
58780
58883
  return response.data.withdrawal_requests || [];
58781
58884
  }
@@ -58784,6 +58887,35 @@ class CosmosClient {
58784
58887
  return [];
58785
58888
  }
58786
58889
  }
58890
+ /**
58891
+ * A multi-table tournament's live standings (block52/pokerchain#405,
58892
+ * poker-vm#2613), ranked by the engine: the chain runs engine.Leaderboard
58893
+ * over the stored tournament state and serves the LeaderboardDTO verbatim.
58894
+ * Unauthenticated: standings are public.
58895
+ *
58896
+ * @returns the board, or null when the chain has no tournament with this ID
58897
+ * (gRPC NotFound, HTTP 404). Any other failure — including an empty or
58898
+ * malformed leaderboard — throws.
58899
+ */
58900
+ async getTournamentLeaderboard(tournamentId) {
58901
+ if (tournamentId === "") {
58902
+ throw new Error("tournamentId is required");
58903
+ }
58904
+ try {
58905
+ const response = await this.restClient.get(`/block52/pokerchain/poker/v1/tournament_leaderboard/${encodeURIComponent(tournamentId)}`);
58906
+ if (!response.data || typeof response.data.leaderboard !== "string") {
58907
+ throw new Error(`Empty tournament leaderboard response for ${tournamentId}`);
58908
+ }
58909
+ return parseLeaderboardDTO(response.data.leaderboard);
58910
+ }
58911
+ catch (error) {
58912
+ if (isGrpcNotFound(error)) {
58913
+ return null;
58914
+ }
58915
+ console.error("Error fetching tournament leaderboard:", error);
58916
+ throw error;
58917
+ }
58918
+ }
58787
58919
  /**
58788
58920
  * Calculate equity for multiple hands using Monte Carlo simulation
58789
58921
  * Used when players are all-in and showing to display win percentages
@@ -58854,6 +58986,19 @@ const getDefaultCosmosConfig = (domain = "localhost") => ({
58854
58986
  denom: "stake", // Use stake as the denomination (lowercase, as stored on blockchain)
58855
58987
  gasPrice: "0.0stake" // Gas price in stake (not used in REST-only mode)
58856
58988
  });
58989
+ /** gRPC code NOT_FOUND as grpc-gateway reports it in an error body. */
58990
+ const GRPC_NOT_FOUND = 5;
58991
+ /**
58992
+ * True for a grpc-gateway NotFound reply: HTTP 404 whose body carries gRPC code
58993
+ * 5. An unknown route (an older chain without the query) is a 501, not this.
58994
+ */
58995
+ function isGrpcNotFound(error) {
58996
+ if (!axios.isAxiosError(error) || error.response?.status !== 404) {
58997
+ return false;
58998
+ }
58999
+ const body = error.response.data;
59000
+ return typeof body === "object" && body !== null && body.code === GRPC_NOT_FOUND;
59001
+ }
58857
59002
 
58858
59003
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
58859
59004
 
@@ -71808,7 +71953,7 @@ class SigningCosmosClient extends CosmosClient {
71808
71953
  if (!denom) {
71809
71954
  denom = this.config.denom;
71810
71955
  }
71811
- const coins = [{ denom: denom, amount: amount.toString() }];
71956
+ const coins = [{ denom, amount: amount.toString() }];
71812
71957
  const fee = gaslessFee();
71813
71958
  const result = await this.signingClient.sendTokens(fromAddress, toAddress, coins, fee, memo || "");
71814
71959
  assertExecuted("send tokens", result);
@@ -72660,84 +72805,28 @@ class SigningCosmosClient extends CosmosClient {
72660
72805
  }
72661
72806
  }
72662
72807
  /**
72663
- * Get next action index for a game - matches original client pattern
72664
- * Checks previousActions array first, falls back to actionCount + 1
72665
- */
72666
- async getNextActionIndex(gameId) {
72667
- try {
72668
- const gameState = await this.queryGameState(gameId);
72669
- if (!gameState) {
72670
- throw new Error("Game state not found");
72671
- }
72672
- let nextIndex;
72673
- // Match original client logic exactly
72674
- if (!gameState.previousActions || gameState.previousActions.length === 0) {
72675
- nextIndex = gameState.actionCount + 1;
72676
- console.log("📊 Action Index Calculation:", {
72677
- gameId: gameId.substring(0, 20) + "...",
72678
- method: "actionCount + 1",
72679
- actionCount: gameState.actionCount,
72680
- nextIndex,
72681
- previousActionsLength: 0
72682
- });
72683
- }
72684
- else {
72685
- const lastAction = gameState.previousActions[gameState.previousActions.length - 1];
72686
- nextIndex = lastAction.index + 1;
72687
- console.log("📊 Action Index Calculation:", {
72688
- gameId: gameId.substring(0, 20) + "...",
72689
- method: "lastAction.index + 1",
72690
- lastActionIndex: lastAction.index,
72691
- nextIndex,
72692
- previousActionsLength: gameState.previousActions.length,
72693
- lastAction: {
72694
- action: lastAction.action,
72695
- player: lastAction.playerId?.substring(0, 10) + "...",
72696
- round: lastAction.round
72697
- }
72698
- });
72699
- }
72700
- return nextIndex;
72701
- }
72702
- catch (error) {
72703
- console.error(`Error getting next action index: ${error.message}`);
72704
- throw error; // Rethrow to be handled by caller
72705
- }
72706
- }
72707
- /**
72708
- * Query all games from the blockchain
72808
+ * Query all games from the blockchain.
72809
+ * Same as listGames(); the old /pokerchain/poker/v1/games path is a 501 (poker-vm#1939).
72709
72810
  */
72710
72811
  async queryGames() {
72711
- try {
72712
- const response = await fetch(`${this.config.restEndpoint}/pokerchain/poker/v1/games`);
72713
- if (!response.ok) {
72714
- throw new Error(`Failed to query games: ${response.statusText}`);
72715
- }
72716
- const data = await response.json();
72717
- // The response has games as a JSON string, need to parse it
72718
- if (data.games) {
72719
- return JSON.parse(data.games);
72720
- }
72721
- return [];
72722
- }
72723
- catch (error) {
72724
- console.error("❌ queryGames() failed:", error);
72725
- throw error;
72726
- }
72812
+ return this.listGames();
72727
72813
  }
72728
72814
  /**
72729
- * Query game state for a specific game
72815
+ * Query the public game state for a game (hole cards masked), or null when the
72816
+ * chain has none. Uses game_state_public: the game_state query needs a signed
72817
+ * player address (poker-vm#1939).
72730
72818
  */
72731
72819
  async queryGameState(gameId) {
72732
72820
  try {
72733
- const response = await fetch(`${this.config.restEndpoint}/block52/pokerchain/poker/v1/game_state/${encodeURIComponent(gameId)}`);
72821
+ const response = await fetch(`${this.config.restEndpoint}/block52/pokerchain/poker/v1/game_state_public/${encodeURIComponent(gameId)}`);
72734
72822
  if (!response.ok) {
72735
72823
  throw new Error(`Failed to query game state: ${response.statusText}`);
72736
72824
  }
72737
72825
  const data = await response.json();
72738
72826
  // The response has game_state as a JSON string, need to parse it
72739
72827
  if (data.game_state) {
72740
- return JSON.parse(data.game_state);
72828
+ const state = JSON.parse(data.game_state);
72829
+ return state;
72741
72830
  }
72742
72831
  return null;
72743
72832
  }
@@ -72874,6 +72963,8 @@ exports.SIT_IN_METHOD_POST_NOW = SIT_IN_METHOD_POST_NOW;
72874
72963
  exports.SIT_OUT_METHOD_NEXT_BB = SIT_OUT_METHOD_NEXT_BB;
72875
72964
  exports.SIT_OUT_METHOD_NEXT_HAND = SIT_OUT_METHOD_NEXT_HAND;
72876
72965
  exports.SigningCosmosClient = SigningCosmosClient;
72966
+ exports.TOURNAMENT_ENTRANT_STATUSES = TOURNAMENT_ENTRANT_STATUSES;
72967
+ exports.TOURNAMENT_STATUSES = TOURNAMENT_STATUSES;
72877
72968
  exports.TxExecutionError = TxExecutionError;
72878
72969
  exports.ValidatorBond = ValidatorBond;
72879
72970
  exports.WithdrawalRequest = WithdrawalRequest;
@@ -72911,6 +73002,7 @@ exports.lateRegistrationClosesAt = lateRegistrationClosesAt;
72911
73002
  exports.parseBlindStructure = parseBlindStructure;
72912
73003
  exports.parseGameFormat = parseGameFormat;
72913
73004
  exports.parseGameVariant = parseGameVariant;
73005
+ exports.parseLeaderboardDTO = parseLeaderboardDTO;
72914
73006
  exports.registry = registry;
72915
73007
  exports.resolveBlindPreset = resolveBlindPreset;
72916
73008
  exports.roundBlind = roundBlind;