@block52/poker-vm-sdk 1.15.0 → 1.17.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.esm.js CHANGED
@@ -4471,24 +4471,33 @@ function isSet$2b(value) {
4471
4471
  return value !== null && value !== undefined;
4472
4472
  }
4473
4473
 
4474
- // Proto-generated MessageFns types need casting to cosmjs GeneratedType
4474
+ /**
4475
+ * Adapts a ts-proto MessageFns to cosmjs's GeneratedType (poker-vm#1939).
4476
+ * cosmjs types its writer as protobufjs's Writer class; ours is @bufbuild's
4477
+ * BinaryWriter, a different class with the same contract. The Registry only
4478
+ * calls fromPartial, encode(...).finish() and decode(bytes), all of which
4479
+ * MessageFns provides, so this is the one place that bridges the two. Both
4480
+ * writer types are classes with private members, so no structural adapter can
4481
+ * satisfy GeneratedType without this cast.
4482
+ */
4483
+ const asGeneratedType = (fns) => fns;
4475
4484
  const msgTypes$u = [
4476
- ["/pokerchain.poker.v1.MsgUpdateParams", MsgUpdateParams$d],
4477
- ["/pokerchain.poker.v1.MsgCreateGame", MsgCreateGame],
4478
- ["/pokerchain.poker.v1.MsgJoinGame", MsgJoinGame],
4479
- ["/pokerchain.poker.v1.MsgLeaveGame", MsgLeaveGame],
4480
- ["/pokerchain.poker.v1.MsgRecordHandEnd", MsgRecordHandEnd],
4481
- ["/pokerchain.poker.v1.MsgDealCards", MsgDealCards],
4482
- ["/pokerchain.poker.v1.MsgPerformAction", MsgPerformAction],
4483
- ["/pokerchain.poker.v1.MsgMint", MsgMint],
4484
- ["/pokerchain.poker.v1.MsgBurn", MsgBurn],
4485
- ["/pokerchain.poker.v1.MsgProcessDeposit", MsgProcessDeposit],
4486
- ["/pokerchain.poker.v1.MsgInitiateWithdrawal", MsgInitiateWithdrawal],
4487
- ["/pokerchain.poker.v1.MsgUpdateEthBlockHeight", MsgUpdateEthBlockHeight],
4488
- ["/pokerchain.poker.v1.MsgTopUp", MsgTopUp],
4489
- ["/pokerchain.poker.v1.MsgDeleteGame", MsgDeleteGame],
4490
- ["/pokerchain.poker.v1.MsgForceCloseGame", MsgForceCloseGame],
4491
- ["/pokerchain.poker.v1.MsgRegisterNftAvatar", MsgRegisterNftAvatar],
4485
+ ["/pokerchain.poker.v1.MsgUpdateParams", asGeneratedType(MsgUpdateParams$d)],
4486
+ ["/pokerchain.poker.v1.MsgCreateGame", asGeneratedType(MsgCreateGame)],
4487
+ ["/pokerchain.poker.v1.MsgJoinGame", asGeneratedType(MsgJoinGame)],
4488
+ ["/pokerchain.poker.v1.MsgLeaveGame", asGeneratedType(MsgLeaveGame)],
4489
+ ["/pokerchain.poker.v1.MsgRecordHandEnd", asGeneratedType(MsgRecordHandEnd)],
4490
+ ["/pokerchain.poker.v1.MsgDealCards", asGeneratedType(MsgDealCards)],
4491
+ ["/pokerchain.poker.v1.MsgPerformAction", asGeneratedType(MsgPerformAction)],
4492
+ ["/pokerchain.poker.v1.MsgMint", asGeneratedType(MsgMint)],
4493
+ ["/pokerchain.poker.v1.MsgBurn", asGeneratedType(MsgBurn)],
4494
+ ["/pokerchain.poker.v1.MsgProcessDeposit", asGeneratedType(MsgProcessDeposit)],
4495
+ ["/pokerchain.poker.v1.MsgInitiateWithdrawal", asGeneratedType(MsgInitiateWithdrawal)],
4496
+ ["/pokerchain.poker.v1.MsgUpdateEthBlockHeight", asGeneratedType(MsgUpdateEthBlockHeight)],
4497
+ ["/pokerchain.poker.v1.MsgTopUp", asGeneratedType(MsgTopUp)],
4498
+ ["/pokerchain.poker.v1.MsgDeleteGame", asGeneratedType(MsgDeleteGame)],
4499
+ ["/pokerchain.poker.v1.MsgForceCloseGame", asGeneratedType(MsgForceCloseGame)],
4500
+ ["/pokerchain.poker.v1.MsgRegisterNftAvatar", asGeneratedType(MsgRegisterNftAvatar)],
4492
4501
  ];
4493
4502
 
4494
4503
  /**
@@ -56650,7 +56659,8 @@ const isValidPlayerAddress = (address) => {
56650
56659
  * start: 25/50
56651
56660
  * duration: 5m
56652
56661
  * progression: double | linear 25 | percentage 1.5
56653
- * round: 25 percentage only (the engine's roundTo)
56662
+ * round: 25 percentage: the engine's roundTo
56663
+ * round: blinds double / linear: round levels of 1,000+ (roundBlinds)
56654
56664
  * ante: bb | bb * 0.1 | level >= 4 ? bb * 0.1 : 0
56655
56665
  * cap: 15
56656
56666
  * }
@@ -56866,6 +56876,15 @@ function parseTable(body) {
56866
56876
  out.maxLevel = parseInteger("cap", body.fields.get("cap").join(" "));
56867
56877
  return out;
56868
56878
  }
56879
+ /** `round: blinds` on double / linear turns on roundBlinds (poker-vm#2738); no other value is accepted there. */
56880
+ function parseRoundBlinds(f) {
56881
+ if (!f.has("round"))
56882
+ return {};
56883
+ const value = f.get("round").join(" ");
56884
+ if (value !== "blinds")
56885
+ fail(`double and linear take "round: blinds" (round levels of 1,000+), got "round: ${value}"`);
56886
+ return { roundBlinds: true };
56887
+ }
56869
56888
  function parseAlgorithmic(body) {
56870
56889
  const f = body.fields;
56871
56890
  for (const key of f.keys()) {
@@ -56894,16 +56913,16 @@ function parseAlgorithmic(body) {
56894
56913
  const [kind, ...rest] = f.get("progression");
56895
56914
  switch (kind) {
56896
56915
  case "double":
56897
- if (rest.length !== 0 || f.has("round"))
56898
- fail("double takes no argument and no round");
56899
- return { progression: "double", ...base };
56916
+ if (rest.length !== 0)
56917
+ fail("double takes no argument");
56918
+ return { progression: "double", ...base, ...parseRoundBlinds(f) };
56900
56919
  case "linear": {
56901
- if (rest.length !== 1 || f.has("round"))
56902
- fail('linear needs one step, e.g. "linear 25", and no round');
56920
+ if (rest.length !== 1)
56921
+ fail('linear needs one step, e.g. "linear 25"');
56903
56922
  const step = parseAmount("linear step", rest[0]);
56904
56923
  if (BigInt(step) <= 0n)
56905
56924
  fail("linear step must be positive");
56906
- return { progression: "linear", ...base, step };
56925
+ return { progression: "linear", ...base, step, ...parseRoundBlinds(f) };
56907
56926
  }
56908
56927
  case "percentage": {
56909
56928
  if (rest.length !== 1)
@@ -56976,9 +56995,13 @@ function formatBlindStructure(structure, name = "custom") {
56976
56995
  switch (structure.progression) {
56977
56996
  case "double":
56978
56997
  lines.push(" progression: double");
56998
+ if (structure.roundBlinds)
56999
+ lines.push(" round: blinds");
56979
57000
  break;
56980
57001
  case "linear":
56981
57002
  lines.push(` progression: linear ${structure.step}`);
57003
+ if (structure.roundBlinds)
57004
+ lines.push(" round: blinds");
56982
57005
  break;
56983
57006
  case "percentage":
56984
57007
  lines.push(` progression: percentage ${formatBps(structure.factorBps)}`);
@@ -57005,8 +57028,8 @@ function formatBlindStructure(structure, name = "custom") {
57005
57028
  * levels can be previewed before the table exists.
57006
57029
  */
57007
57030
  const BLIND_PRESET_STRUCTURES = {
57008
- turbo: { progression: "double", startSmallBlind: "25", startBigBlind: "50", durationMinutes: 5, ante: { startLevel: 4, bps: 1000 } },
57009
- standard: { progression: "double", startSmallBlind: "25", startBigBlind: "50", durationMinutes: 10, ante: { startLevel: 5, bps: 1000 } },
57031
+ turbo: { progression: "double", startSmallBlind: "25", startBigBlind: "50", durationMinutes: 5, roundBlinds: true, ante: { startLevel: 4, bps: 1000 } },
57032
+ standard: { progression: "double", startSmallBlind: "25", startBigBlind: "50", durationMinutes: 10, roundBlinds: true, ante: { startLevel: 5, bps: 1000 } },
57010
57033
  deep_stack: {
57011
57034
  progression: "percentage",
57012
57035
  startSmallBlind: "25",
@@ -57016,7 +57039,7 @@ const BLIND_PRESET_STRUCTURES = {
57016
57039
  durationMinutes: 15,
57017
57040
  ante: { startLevel: 6, bps: 1250 }
57018
57041
  },
57019
- hyper_turbo: { progression: "double", startSmallBlind: "50", startBigBlind: "100", durationMinutes: 3, ante: { startLevel: 3, bps: 1000 } }
57042
+ hyper_turbo: { progression: "double", startSmallBlind: "50", startBigBlind: "100", durationMinutes: 3, roundBlinds: true, ante: { startLevel: 3, bps: 1000 } }
57020
57043
  };
57021
57044
  /** Replaces a preset with its concrete structure (a deep copy); anything else is returned as is. */
57022
57045
  function resolveBlindPreset(structure) {
@@ -57027,6 +57050,17 @@ function resolveBlindPreset(structure) {
57027
57050
  fail(`"${structure.preset}" is not a preset (${BLIND_PRESETS.join(", ")})`);
57028
57051
  return JSON.parse(JSON.stringify(preset));
57029
57052
  }
57053
+ /**
57054
+ * The engine's roundBlind (poker-vm#2738): a big blind of 1,000 or more rounded
57055
+ * up to two significant figures (1,280 → 1,300; 10,240 → 11,000). The unit is
57056
+ * then at least 100, so the result stays even. Below 1,000 it is returned as is.
57057
+ */
57058
+ function roundBlind(bigBlind) {
57059
+ if (bigBlind < 1000n)
57060
+ return bigBlind;
57061
+ const unit = 10n ** BigInt(bigBlind.toString().length - 2);
57062
+ return ((bigBlind + unit - 1n) / unit) * unit;
57063
+ }
57030
57064
  function algorithmicSmallBlind(structure, n) {
57031
57065
  const sb0 = BigInt(structure.startSmallBlind);
57032
57066
  switch (structure.progression) {
@@ -57075,8 +57109,13 @@ function expandBlindLevel(structure, n) {
57075
57109
  row.durationMinutes = n >= rows.length ? rows[rows.length - 1].durationMinutes : rows[n].durationMinutes;
57076
57110
  return row;
57077
57111
  }
57078
- const sb = algorithmicSmallBlind(structure, m);
57079
- const bb = sb * 2n;
57112
+ let sb = algorithmicSmallBlind(structure, m);
57113
+ let bb = sb * 2n;
57114
+ // Level 0 is the creator's opening blinds and is never rounded.
57115
+ if (structure.progression !== "percentage" && structure.roundBlinds && m > 0) {
57116
+ bb = roundBlind(bb);
57117
+ sb = bb / 2n;
57118
+ }
57080
57119
  let ante = 0n;
57081
57120
  if (structure.ante && n >= structure.ante.startLevel)
57082
57121
  ante = (bb * BigInt(structure.ante.bps)) / BPS;
@@ -58567,10 +58606,10 @@ class CosmosClient {
58567
58606
  async getGameState(gameId) {
58568
58607
  try {
58569
58608
  const response = await this.restClient.get(`/block52/pokerchain/poker/v1/game_state/${gameId}`);
58570
- if (response.data) {
58571
- return response.data;
58609
+ if (!response.data) {
58610
+ throw new Error(`Empty game state response for ${gameId}`);
58572
58611
  }
58573
- return {};
58612
+ return response.data;
58574
58613
  }
58575
58614
  catch (error) {
58576
58615
  console.error("Error fetching game state:", error);
@@ -58583,10 +58622,10 @@ class CosmosClient {
58583
58622
  async getGame(gameId) {
58584
58623
  try {
58585
58624
  const response = await this.restClient.get(`/block52/pokerchain/poker/v1/game/${gameId}`);
58586
- if (response.data) {
58587
- return response.data;
58625
+ if (!response.data) {
58626
+ throw new Error(`Empty game response for ${gameId}`);
58588
58627
  }
58589
- return {};
58628
+ return response.data;
58590
58629
  }
58591
58630
  catch (error) {
58592
58631
  console.error("Error fetching game:", error);
@@ -58633,9 +58672,11 @@ class CosmosClient {
58633
58672
  }
58634
58673
  catch (error) {
58635
58674
  console.error("❌ [CosmosClient] Error listing games:");
58636
- console.error(" Message:", error.message);
58637
- console.error(" Response status:", error.response?.status);
58638
- console.error(" Response data:", error.response?.data);
58675
+ if (axios.isAxiosError(error)) {
58676
+ console.error(" Message:", error.message);
58677
+ console.error(" Response status:", error.response?.status);
58678
+ console.error(" Response data:", error.response?.data);
58679
+ }
58639
58680
  console.error(" Full error:", error);
58640
58681
  throw error;
58641
58682
  }
@@ -58741,9 +58782,10 @@ class CosmosClient {
58741
58782
  */
58742
58783
  async listWithdrawalRequests(cosmosAddress) {
58743
58784
  try {
58785
+ // The chain serves withdrawal_requests; list_withdrawal_requests is a 501 (poker-vm#1939).
58744
58786
  const url = cosmosAddress
58745
- ? `/block52/pokerchain/poker/v1/list_withdrawal_requests?cosmos_address=${cosmosAddress}`
58746
- : `/block52/pokerchain/poker/v1/list_withdrawal_requests`;
58787
+ ? `/block52/pokerchain/poker/v1/withdrawal_requests?cosmos_address=${encodeURIComponent(cosmosAddress)}`
58788
+ : `/block52/pokerchain/poker/v1/withdrawal_requests`;
58747
58789
  const response = await this.restClient.get(url);
58748
58790
  return response.data.withdrawal_requests || [];
58749
58791
  }
@@ -71776,7 +71818,7 @@ class SigningCosmosClient extends CosmosClient {
71776
71818
  if (!denom) {
71777
71819
  denom = this.config.denom;
71778
71820
  }
71779
- const coins = [{ denom: denom, amount: amount.toString() }];
71821
+ const coins = [{ denom, amount: amount.toString() }];
71780
71822
  const fee = gaslessFee();
71781
71823
  const result = await this.signingClient.sendTokens(fromAddress, toAddress, coins, fee, memo || "");
71782
71824
  assertExecuted("send tokens", result);
@@ -72628,84 +72670,28 @@ class SigningCosmosClient extends CosmosClient {
72628
72670
  }
72629
72671
  }
72630
72672
  /**
72631
- * Get next action index for a game - matches original client pattern
72632
- * Checks previousActions array first, falls back to actionCount + 1
72633
- */
72634
- async getNextActionIndex(gameId) {
72635
- try {
72636
- const gameState = await this.queryGameState(gameId);
72637
- if (!gameState) {
72638
- throw new Error("Game state not found");
72639
- }
72640
- let nextIndex;
72641
- // Match original client logic exactly
72642
- if (!gameState.previousActions || gameState.previousActions.length === 0) {
72643
- nextIndex = gameState.actionCount + 1;
72644
- console.log("📊 Action Index Calculation:", {
72645
- gameId: gameId.substring(0, 20) + "...",
72646
- method: "actionCount + 1",
72647
- actionCount: gameState.actionCount,
72648
- nextIndex,
72649
- previousActionsLength: 0
72650
- });
72651
- }
72652
- else {
72653
- const lastAction = gameState.previousActions[gameState.previousActions.length - 1];
72654
- nextIndex = lastAction.index + 1;
72655
- console.log("📊 Action Index Calculation:", {
72656
- gameId: gameId.substring(0, 20) + "...",
72657
- method: "lastAction.index + 1",
72658
- lastActionIndex: lastAction.index,
72659
- nextIndex,
72660
- previousActionsLength: gameState.previousActions.length,
72661
- lastAction: {
72662
- action: lastAction.action,
72663
- player: lastAction.playerId?.substring(0, 10) + "...",
72664
- round: lastAction.round
72665
- }
72666
- });
72667
- }
72668
- return nextIndex;
72669
- }
72670
- catch (error) {
72671
- console.error(`Error getting next action index: ${error.message}`);
72672
- throw error; // Rethrow to be handled by caller
72673
- }
72674
- }
72675
- /**
72676
- * Query all games from the blockchain
72673
+ * Query all games from the blockchain.
72674
+ * Same as listGames(); the old /pokerchain/poker/v1/games path is a 501 (poker-vm#1939).
72677
72675
  */
72678
72676
  async queryGames() {
72679
- try {
72680
- const response = await fetch(`${this.config.restEndpoint}/pokerchain/poker/v1/games`);
72681
- if (!response.ok) {
72682
- throw new Error(`Failed to query games: ${response.statusText}`);
72683
- }
72684
- const data = await response.json();
72685
- // The response has games as a JSON string, need to parse it
72686
- if (data.games) {
72687
- return JSON.parse(data.games);
72688
- }
72689
- return [];
72690
- }
72691
- catch (error) {
72692
- console.error("❌ queryGames() failed:", error);
72693
- throw error;
72694
- }
72677
+ return this.listGames();
72695
72678
  }
72696
72679
  /**
72697
- * Query game state for a specific game
72680
+ * Query the public game state for a game (hole cards masked), or null when the
72681
+ * chain has none. Uses game_state_public: the game_state query needs a signed
72682
+ * player address (poker-vm#1939).
72698
72683
  */
72699
72684
  async queryGameState(gameId) {
72700
72685
  try {
72701
- const response = await fetch(`${this.config.restEndpoint}/block52/pokerchain/poker/v1/game_state/${encodeURIComponent(gameId)}`);
72686
+ const response = await fetch(`${this.config.restEndpoint}/block52/pokerchain/poker/v1/game_state_public/${encodeURIComponent(gameId)}`);
72702
72687
  if (!response.ok) {
72703
72688
  throw new Error(`Failed to query game state: ${response.statusText}`);
72704
72689
  }
72705
72690
  const data = await response.json();
72706
72691
  // The response has game_state as a JSON string, need to parse it
72707
72692
  if (data.game_state) {
72708
- return JSON.parse(data.game_state);
72693
+ const state = JSON.parse(data.game_state);
72694
+ return state;
72709
72695
  }
72710
72696
  return null;
72711
72697
  }
@@ -72819,5 +72805,5 @@ const registry = new Registry([
72819
72805
  ...msgTypes,
72820
72806
  ]);
72821
72807
 
72822
- export { AllPlayerActions, BLIND_PRESETS, BLIND_PRESET_STRUCTURES, BLIND_PROGRESSIONS, BLOCK52_HD_PATH, BettingLimit, Board, COSMOS_CONSTANTS, Client, CosmosClient, Deck, GAME_NAME_MICRO_PER_CHAR, GameFormat, GameStatus, GameVariant, HandType, KEYS, MAX_GAME_NAME_LENGTH, MSG_CREATE_VALIDATOR_TYPE_URL, MissingWalletError, NonPlayerActionType, Params$c as Params, PlayerActionType, PlayerStatus, PokerGameIntegration, PokerSolver, RPCMethods, SIT_IN_METHOD_NEXT_BB, SIT_IN_METHOD_POST_NOW, SIT_OUT_METHOD_NEXT_BB, SIT_OUT_METHOD_NEXT_HAND, SUIT, SigningCosmosClient, TexasHoldemRound, TxExecutionError, ValidatorBond, WithdrawalRequest, assertCreatableBettingLimit, assertExecuted, buildMsgCreateValidator, computeGameNameFee, createSigningClientFromMnemonic, createWalletFromMnemonic, decToAtomics, expandBlindLevel, formatBlindStructure, formatGameFormatDisplay, formatGameVariantDisplay, generateWallet, getActionByType, getAddressFromMnemonic, getBettingLimit, getDefaultCosmosConfig, getGameFormat, getGameFormatForCosmos, getGameFormatFromObject, getGameVariant, hasAction, holeCardsPerPlayer, isCashFormat, isEmptyAddress, isLateRegistrationOpen, isPotLimit, isSitAndGoFormat, isTournamentFormat, isValidMnemonic, isValidPlayerAddress, lateRegistrationClosesAt, parseBlindStructure, parseGameFormat, parseGameVariant, registry, resolveBlindPreset, toValoperAddress, txFailureHash, txFailurePhase };
72808
+ export { AllPlayerActions, BLIND_PRESETS, BLIND_PRESET_STRUCTURES, BLIND_PROGRESSIONS, BLOCK52_HD_PATH, BettingLimit, Board, COSMOS_CONSTANTS, Client, CosmosClient, Deck, GAME_NAME_MICRO_PER_CHAR, GameFormat, GameStatus, GameVariant, HandType, KEYS, MAX_GAME_NAME_LENGTH, MSG_CREATE_VALIDATOR_TYPE_URL, MissingWalletError, NonPlayerActionType, Params$c as Params, PlayerActionType, PlayerStatus, PokerGameIntegration, PokerSolver, RPCMethods, SIT_IN_METHOD_NEXT_BB, SIT_IN_METHOD_POST_NOW, SIT_OUT_METHOD_NEXT_BB, SIT_OUT_METHOD_NEXT_HAND, SUIT, SigningCosmosClient, TexasHoldemRound, TxExecutionError, ValidatorBond, WithdrawalRequest, assertCreatableBettingLimit, assertExecuted, buildMsgCreateValidator, computeGameNameFee, createSigningClientFromMnemonic, createWalletFromMnemonic, decToAtomics, expandBlindLevel, formatBlindStructure, formatGameFormatDisplay, formatGameVariantDisplay, generateWallet, getActionByType, getAddressFromMnemonic, getBettingLimit, getDefaultCosmosConfig, getGameFormat, getGameFormatForCosmos, getGameFormatFromObject, getGameVariant, hasAction, holeCardsPerPlayer, isCashFormat, isEmptyAddress, isLateRegistrationOpen, isPotLimit, isSitAndGoFormat, isTournamentFormat, isValidMnemonic, isValidPlayerAddress, lateRegistrationClosesAt, parseBlindStructure, parseGameFormat, parseGameVariant, registry, resolveBlindPreset, roundBlind, toValoperAddress, txFailureHash, txFailurePhase };
72823
72809
  //# sourceMappingURL=index.esm.js.map