@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.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
  /**
@@ -56652,7 +56661,8 @@ const isValidPlayerAddress = (address) => {
56652
56661
  * start: 25/50
56653
56662
  * duration: 5m
56654
56663
  * progression: double | linear 25 | percentage 1.5
56655
- * round: 25 percentage only (the engine's roundTo)
56664
+ * round: 25 percentage: the engine's roundTo
56665
+ * round: blinds double / linear: round levels of 1,000+ (roundBlinds)
56656
56666
  * ante: bb | bb * 0.1 | level >= 4 ? bb * 0.1 : 0
56657
56667
  * cap: 15
56658
56668
  * }
@@ -56868,6 +56878,15 @@ function parseTable(body) {
56868
56878
  out.maxLevel = parseInteger("cap", body.fields.get("cap").join(" "));
56869
56879
  return out;
56870
56880
  }
56881
+ /** `round: blinds` on double / linear turns on roundBlinds (poker-vm#2738); no other value is accepted there. */
56882
+ function parseRoundBlinds(f) {
56883
+ if (!f.has("round"))
56884
+ return {};
56885
+ const value = f.get("round").join(" ");
56886
+ if (value !== "blinds")
56887
+ fail(`double and linear take "round: blinds" (round levels of 1,000+), got "round: ${value}"`);
56888
+ return { roundBlinds: true };
56889
+ }
56871
56890
  function parseAlgorithmic(body) {
56872
56891
  const f = body.fields;
56873
56892
  for (const key of f.keys()) {
@@ -56896,16 +56915,16 @@ function parseAlgorithmic(body) {
56896
56915
  const [kind, ...rest] = f.get("progression");
56897
56916
  switch (kind) {
56898
56917
  case "double":
56899
- if (rest.length !== 0 || f.has("round"))
56900
- fail("double takes no argument and no round");
56901
- return { progression: "double", ...base };
56918
+ if (rest.length !== 0)
56919
+ fail("double takes no argument");
56920
+ return { progression: "double", ...base, ...parseRoundBlinds(f) };
56902
56921
  case "linear": {
56903
- if (rest.length !== 1 || f.has("round"))
56904
- fail('linear needs one step, e.g. "linear 25", and no round');
56922
+ if (rest.length !== 1)
56923
+ fail('linear needs one step, e.g. "linear 25"');
56905
56924
  const step = parseAmount("linear step", rest[0]);
56906
56925
  if (BigInt(step) <= 0n)
56907
56926
  fail("linear step must be positive");
56908
- return { progression: "linear", ...base, step };
56927
+ return { progression: "linear", ...base, step, ...parseRoundBlinds(f) };
56909
56928
  }
56910
56929
  case "percentage": {
56911
56930
  if (rest.length !== 1)
@@ -56978,9 +56997,13 @@ function formatBlindStructure(structure, name = "custom") {
56978
56997
  switch (structure.progression) {
56979
56998
  case "double":
56980
56999
  lines.push(" progression: double");
57000
+ if (structure.roundBlinds)
57001
+ lines.push(" round: blinds");
56981
57002
  break;
56982
57003
  case "linear":
56983
57004
  lines.push(` progression: linear ${structure.step}`);
57005
+ if (structure.roundBlinds)
57006
+ lines.push(" round: blinds");
56984
57007
  break;
56985
57008
  case "percentage":
56986
57009
  lines.push(` progression: percentage ${formatBps(structure.factorBps)}`);
@@ -57007,8 +57030,8 @@ function formatBlindStructure(structure, name = "custom") {
57007
57030
  * levels can be previewed before the table exists.
57008
57031
  */
57009
57032
  const BLIND_PRESET_STRUCTURES = {
57010
- turbo: { progression: "double", startSmallBlind: "25", startBigBlind: "50", durationMinutes: 5, ante: { startLevel: 4, bps: 1000 } },
57011
- standard: { progression: "double", startSmallBlind: "25", startBigBlind: "50", durationMinutes: 10, ante: { startLevel: 5, bps: 1000 } },
57033
+ turbo: { progression: "double", startSmallBlind: "25", startBigBlind: "50", durationMinutes: 5, roundBlinds: true, ante: { startLevel: 4, bps: 1000 } },
57034
+ standard: { progression: "double", startSmallBlind: "25", startBigBlind: "50", durationMinutes: 10, roundBlinds: true, ante: { startLevel: 5, bps: 1000 } },
57012
57035
  deep_stack: {
57013
57036
  progression: "percentage",
57014
57037
  startSmallBlind: "25",
@@ -57018,7 +57041,7 @@ const BLIND_PRESET_STRUCTURES = {
57018
57041
  durationMinutes: 15,
57019
57042
  ante: { startLevel: 6, bps: 1250 }
57020
57043
  },
57021
- hyper_turbo: { progression: "double", startSmallBlind: "50", startBigBlind: "100", durationMinutes: 3, ante: { startLevel: 3, bps: 1000 } }
57044
+ hyper_turbo: { progression: "double", startSmallBlind: "50", startBigBlind: "100", durationMinutes: 3, roundBlinds: true, ante: { startLevel: 3, bps: 1000 } }
57022
57045
  };
57023
57046
  /** Replaces a preset with its concrete structure (a deep copy); anything else is returned as is. */
57024
57047
  function resolveBlindPreset(structure) {
@@ -57029,6 +57052,17 @@ function resolveBlindPreset(structure) {
57029
57052
  fail(`"${structure.preset}" is not a preset (${BLIND_PRESETS.join(", ")})`);
57030
57053
  return JSON.parse(JSON.stringify(preset));
57031
57054
  }
57055
+ /**
57056
+ * The engine's roundBlind (poker-vm#2738): a big blind of 1,000 or more rounded
57057
+ * up to two significant figures (1,280 → 1,300; 10,240 → 11,000). The unit is
57058
+ * then at least 100, so the result stays even. Below 1,000 it is returned as is.
57059
+ */
57060
+ function roundBlind(bigBlind) {
57061
+ if (bigBlind < 1000n)
57062
+ return bigBlind;
57063
+ const unit = 10n ** BigInt(bigBlind.toString().length - 2);
57064
+ return ((bigBlind + unit - 1n) / unit) * unit;
57065
+ }
57032
57066
  function algorithmicSmallBlind(structure, n) {
57033
57067
  const sb0 = BigInt(structure.startSmallBlind);
57034
57068
  switch (structure.progression) {
@@ -57077,8 +57111,13 @@ function expandBlindLevel(structure, n) {
57077
57111
  row.durationMinutes = n >= rows.length ? rows[rows.length - 1].durationMinutes : rows[n].durationMinutes;
57078
57112
  return row;
57079
57113
  }
57080
- const sb = algorithmicSmallBlind(structure, m);
57081
- const bb = sb * 2n;
57114
+ let sb = algorithmicSmallBlind(structure, m);
57115
+ let bb = sb * 2n;
57116
+ // Level 0 is the creator's opening blinds and is never rounded.
57117
+ if (structure.progression !== "percentage" && structure.roundBlinds && m > 0) {
57118
+ bb = roundBlind(bb);
57119
+ sb = bb / 2n;
57120
+ }
57082
57121
  let ante = 0n;
57083
57122
  if (structure.ante && n >= structure.ante.startLevel)
57084
57123
  ante = (bb * BigInt(structure.ante.bps)) / BPS;
@@ -58569,10 +58608,10 @@ class CosmosClient {
58569
58608
  async getGameState(gameId) {
58570
58609
  try {
58571
58610
  const response = await this.restClient.get(`/block52/pokerchain/poker/v1/game_state/${gameId}`);
58572
- if (response.data) {
58573
- return response.data;
58611
+ if (!response.data) {
58612
+ throw new Error(`Empty game state response for ${gameId}`);
58574
58613
  }
58575
- return {};
58614
+ return response.data;
58576
58615
  }
58577
58616
  catch (error) {
58578
58617
  console.error("Error fetching game state:", error);
@@ -58585,10 +58624,10 @@ class CosmosClient {
58585
58624
  async getGame(gameId) {
58586
58625
  try {
58587
58626
  const response = await this.restClient.get(`/block52/pokerchain/poker/v1/game/${gameId}`);
58588
- if (response.data) {
58589
- return response.data;
58627
+ if (!response.data) {
58628
+ throw new Error(`Empty game response for ${gameId}`);
58590
58629
  }
58591
- return {};
58630
+ return response.data;
58592
58631
  }
58593
58632
  catch (error) {
58594
58633
  console.error("Error fetching game:", error);
@@ -58635,9 +58674,11 @@ class CosmosClient {
58635
58674
  }
58636
58675
  catch (error) {
58637
58676
  console.error("❌ [CosmosClient] Error listing games:");
58638
- console.error(" Message:", error.message);
58639
- console.error(" Response status:", error.response?.status);
58640
- console.error(" Response data:", error.response?.data);
58677
+ if (axios.isAxiosError(error)) {
58678
+ console.error(" Message:", error.message);
58679
+ console.error(" Response status:", error.response?.status);
58680
+ console.error(" Response data:", error.response?.data);
58681
+ }
58641
58682
  console.error(" Full error:", error);
58642
58683
  throw error;
58643
58684
  }
@@ -58743,9 +58784,10 @@ class CosmosClient {
58743
58784
  */
58744
58785
  async listWithdrawalRequests(cosmosAddress) {
58745
58786
  try {
58787
+ // The chain serves withdrawal_requests; list_withdrawal_requests is a 501 (poker-vm#1939).
58746
58788
  const url = cosmosAddress
58747
- ? `/block52/pokerchain/poker/v1/list_withdrawal_requests?cosmos_address=${cosmosAddress}`
58748
- : `/block52/pokerchain/poker/v1/list_withdrawal_requests`;
58789
+ ? `/block52/pokerchain/poker/v1/withdrawal_requests?cosmos_address=${encodeURIComponent(cosmosAddress)}`
58790
+ : `/block52/pokerchain/poker/v1/withdrawal_requests`;
58749
58791
  const response = await this.restClient.get(url);
58750
58792
  return response.data.withdrawal_requests || [];
58751
58793
  }
@@ -71778,7 +71820,7 @@ class SigningCosmosClient extends CosmosClient {
71778
71820
  if (!denom) {
71779
71821
  denom = this.config.denom;
71780
71822
  }
71781
- const coins = [{ denom: denom, amount: amount.toString() }];
71823
+ const coins = [{ denom, amount: amount.toString() }];
71782
71824
  const fee = gaslessFee();
71783
71825
  const result = await this.signingClient.sendTokens(fromAddress, toAddress, coins, fee, memo || "");
71784
71826
  assertExecuted("send tokens", result);
@@ -72630,84 +72672,28 @@ class SigningCosmosClient extends CosmosClient {
72630
72672
  }
72631
72673
  }
72632
72674
  /**
72633
- * Get next action index for a game - matches original client pattern
72634
- * Checks previousActions array first, falls back to actionCount + 1
72635
- */
72636
- async getNextActionIndex(gameId) {
72637
- try {
72638
- const gameState = await this.queryGameState(gameId);
72639
- if (!gameState) {
72640
- throw new Error("Game state not found");
72641
- }
72642
- let nextIndex;
72643
- // Match original client logic exactly
72644
- if (!gameState.previousActions || gameState.previousActions.length === 0) {
72645
- nextIndex = gameState.actionCount + 1;
72646
- console.log("📊 Action Index Calculation:", {
72647
- gameId: gameId.substring(0, 20) + "...",
72648
- method: "actionCount + 1",
72649
- actionCount: gameState.actionCount,
72650
- nextIndex,
72651
- previousActionsLength: 0
72652
- });
72653
- }
72654
- else {
72655
- const lastAction = gameState.previousActions[gameState.previousActions.length - 1];
72656
- nextIndex = lastAction.index + 1;
72657
- console.log("📊 Action Index Calculation:", {
72658
- gameId: gameId.substring(0, 20) + "...",
72659
- method: "lastAction.index + 1",
72660
- lastActionIndex: lastAction.index,
72661
- nextIndex,
72662
- previousActionsLength: gameState.previousActions.length,
72663
- lastAction: {
72664
- action: lastAction.action,
72665
- player: lastAction.playerId?.substring(0, 10) + "...",
72666
- round: lastAction.round
72667
- }
72668
- });
72669
- }
72670
- return nextIndex;
72671
- }
72672
- catch (error) {
72673
- console.error(`Error getting next action index: ${error.message}`);
72674
- throw error; // Rethrow to be handled by caller
72675
- }
72676
- }
72677
- /**
72678
- * Query all games from the blockchain
72675
+ * Query all games from the blockchain.
72676
+ * Same as listGames(); the old /pokerchain/poker/v1/games path is a 501 (poker-vm#1939).
72679
72677
  */
72680
72678
  async queryGames() {
72681
- try {
72682
- const response = await fetch(`${this.config.restEndpoint}/pokerchain/poker/v1/games`);
72683
- if (!response.ok) {
72684
- throw new Error(`Failed to query games: ${response.statusText}`);
72685
- }
72686
- const data = await response.json();
72687
- // The response has games as a JSON string, need to parse it
72688
- if (data.games) {
72689
- return JSON.parse(data.games);
72690
- }
72691
- return [];
72692
- }
72693
- catch (error) {
72694
- console.error("❌ queryGames() failed:", error);
72695
- throw error;
72696
- }
72679
+ return this.listGames();
72697
72680
  }
72698
72681
  /**
72699
- * Query game state for a specific game
72682
+ * Query the public game state for a game (hole cards masked), or null when the
72683
+ * chain has none. Uses game_state_public: the game_state query needs a signed
72684
+ * player address (poker-vm#1939).
72700
72685
  */
72701
72686
  async queryGameState(gameId) {
72702
72687
  try {
72703
- const response = await fetch(`${this.config.restEndpoint}/block52/pokerchain/poker/v1/game_state/${encodeURIComponent(gameId)}`);
72688
+ const response = await fetch(`${this.config.restEndpoint}/block52/pokerchain/poker/v1/game_state_public/${encodeURIComponent(gameId)}`);
72704
72689
  if (!response.ok) {
72705
72690
  throw new Error(`Failed to query game state: ${response.statusText}`);
72706
72691
  }
72707
72692
  const data = await response.json();
72708
72693
  // The response has game_state as a JSON string, need to parse it
72709
72694
  if (data.game_state) {
72710
- return JSON.parse(data.game_state);
72695
+ const state = JSON.parse(data.game_state);
72696
+ return state;
72711
72697
  }
72712
72698
  return null;
72713
72699
  }
@@ -72883,6 +72869,7 @@ exports.parseGameFormat = parseGameFormat;
72883
72869
  exports.parseGameVariant = parseGameVariant;
72884
72870
  exports.registry = registry;
72885
72871
  exports.resolveBlindPreset = resolveBlindPreset;
72872
+ exports.roundBlind = roundBlind;
72886
72873
  exports.toValoperAddress = toValoperAddress;
72887
72874
  exports.txFailureHash = txFailureHash;
72888
72875
  exports.txFailurePhase = txFailurePhase;