@suigar/sdk 2.0.0-beta.14 → 2.0.0-beta.16

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.
Files changed (160) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +22 -8
  3. package/dist/client.d.mts +258 -0
  4. package/dist/client.d.mts.map +1 -0
  5. package/dist/client.mjs +291 -0
  6. package/dist/client.mjs.map +1 -0
  7. package/dist/configs/package.mainnet.mjs +23 -0
  8. package/dist/configs/package.mainnet.mjs.map +1 -0
  9. package/dist/configs/package.mjs +19 -0
  10. package/dist/configs/package.mjs.map +1 -0
  11. package/dist/configs/package.testnet.mjs +23 -0
  12. package/dist/configs/package.testnet.mjs.map +1 -0
  13. package/dist/configs/registry.mainnet.mjs +6 -0
  14. package/dist/configs/registry.mainnet.mjs.map +1 -0
  15. package/dist/configs/registry.mjs +11 -0
  16. package/dist/configs/registry.mjs.map +1 -0
  17. package/dist/configs/registry.testnet.mjs +6 -0
  18. package/dist/configs/registry.testnet.mjs.map +1 -0
  19. package/dist/contracts/coinflip/coinflip.mjs +46 -0
  20. package/dist/contracts/coinflip/coinflip.mjs.map +1 -0
  21. package/dist/contracts/core/core.d.mts +55 -0
  22. package/dist/contracts/core/core.d.mts.map +1 -0
  23. package/dist/contracts/core/core.mjs +22 -0
  24. package/dist/contracts/core/core.mjs.map +1 -0
  25. package/dist/contracts/core/deps/0x0000000000000000000000000000000000000000000000000000000000000001/type_name.mjs +10 -0
  26. package/dist/contracts/core/deps/0x0000000000000000000000000000000000000000000000000000000000000001/type_name.mjs.map +1 -0
  27. package/dist/contracts/core/deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.mjs +26 -0
  28. package/dist/contracts/core/deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.mjs.map +1 -0
  29. package/dist/contracts/core/float.d.mts +14 -0
  30. package/dist/contracts/core/float.d.mts.map +1 -0
  31. package/dist/contracts/core/float.mjs +15 -0
  32. package/dist/contracts/core/float.mjs.map +1 -0
  33. package/dist/contracts/core/i64.mjs +10 -0
  34. package/dist/contracts/core/i64.mjs.map +1 -0
  35. package/dist/contracts/limbo/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.mjs +15 -0
  36. package/dist/contracts/limbo/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.mjs.map +1 -0
  37. package/dist/contracts/limbo/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/i64.mjs +10 -0
  38. package/dist/contracts/limbo/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/i64.mjs.map +1 -0
  39. package/dist/contracts/limbo/limbo.mjs +53 -0
  40. package/dist/contracts/limbo/limbo.mjs.map +1 -0
  41. package/dist/contracts/plinko/deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.mjs +26 -0
  42. package/dist/contracts/plinko/deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.mjs.map +1 -0
  43. package/dist/contracts/plinko/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.mjs +15 -0
  44. package/dist/contracts/plinko/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.mjs.map +1 -0
  45. package/dist/contracts/plinko/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/i64.mjs +10 -0
  46. package/dist/contracts/plinko/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/i64.mjs.map +1 -0
  47. package/dist/contracts/plinko/plinko.mjs +59 -0
  48. package/dist/contracts/plinko/plinko.mjs.map +1 -0
  49. package/dist/contracts/pvp-coinflip/deps/0x0000000000000000000000000000000000000000000000000000000000000001/type_name.mjs +10 -0
  50. package/dist/contracts/pvp-coinflip/deps/0x0000000000000000000000000000000000000000000000000000000000000001/type_name.mjs.map +1 -0
  51. package/dist/contracts/pvp-coinflip/deps/0x0000000000000000000000000000000000000000000000000000000000000002/balance.mjs +10 -0
  52. package/dist/contracts/pvp-coinflip/deps/0x0000000000000000000000000000000000000000000000000000000000000002/balance.mjs.map +1 -0
  53. package/dist/contracts/pvp-coinflip/deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.mjs +26 -0
  54. package/dist/contracts/pvp-coinflip/deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.mjs.map +1 -0
  55. package/dist/contracts/pvp-coinflip/pvp_coinflip.d.mts +34 -0
  56. package/dist/contracts/pvp-coinflip/pvp_coinflip.d.mts.map +1 -0
  57. package/dist/contracts/pvp-coinflip/pvp_coinflip.mjs +131 -0
  58. package/dist/contracts/pvp-coinflip/pvp_coinflip.mjs.map +1 -0
  59. package/dist/contracts/range/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.mjs +15 -0
  60. package/dist/contracts/range/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.mjs.map +1 -0
  61. package/dist/contracts/range/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/i64.mjs +10 -0
  62. package/dist/contracts/range/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/i64.mjs.map +1 -0
  63. package/dist/contracts/range/range.mjs +53 -0
  64. package/dist/contracts/range/range.mjs.map +1 -0
  65. package/dist/contracts/utils/index.d.mts +33 -0
  66. package/dist/contracts/utils/index.d.mts.map +1 -0
  67. package/dist/contracts/utils/index.mjs +119 -0
  68. package/dist/contracts/utils/index.mjs.map +1 -0
  69. package/dist/contracts/wheel/deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.mjs +26 -0
  70. package/dist/contracts/wheel/deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.mjs.map +1 -0
  71. package/dist/contracts/wheel/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.mjs +15 -0
  72. package/dist/contracts/wheel/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.mjs.map +1 -0
  73. package/dist/contracts/wheel/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/i64.mjs +10 -0
  74. package/dist/contracts/wheel/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/i64.mjs.map +1 -0
  75. package/dist/contracts/wheel/wheel.mjs +59 -0
  76. package/dist/contracts/wheel/wheel.mjs.map +1 -0
  77. package/dist/games.d.mts +3 -0
  78. package/dist/games.mjs +1 -0
  79. package/dist/helpers/config.mjs +51 -0
  80. package/dist/helpers/config.mjs.map +1 -0
  81. package/dist/helpers/game-settings.mjs +19 -0
  82. package/dist/helpers/game-settings.mjs.map +1 -0
  83. package/dist/helpers/metadata.mjs +42 -0
  84. package/dist/helpers/metadata.mjs.map +1 -0
  85. package/dist/index.d.mts +2 -0
  86. package/dist/index.mjs +2 -0
  87. package/dist/transactions/coinflip.mjs +27 -0
  88. package/dist/transactions/coinflip.mjs.map +1 -0
  89. package/dist/transactions/limbo.mjs +31 -0
  90. package/dist/transactions/limbo.mjs.map +1 -0
  91. package/dist/transactions/plinko.mjs +29 -0
  92. package/dist/transactions/plinko.mjs.map +1 -0
  93. package/dist/transactions/pvp-coinflip.mjs +70 -0
  94. package/dist/transactions/pvp-coinflip.mjs.map +1 -0
  95. package/dist/transactions/range.mjs +33 -0
  96. package/dist/transactions/range.mjs.map +1 -0
  97. package/dist/transactions/shared.mjs +49 -0
  98. package/dist/transactions/shared.mjs.map +1 -0
  99. package/dist/transactions/wheel.mjs +29 -0
  100. package/dist/transactions/wheel.mjs.map +1 -0
  101. package/dist/ttl-cache.mjs +60 -0
  102. package/dist/ttl-cache.mjs.map +1 -0
  103. package/dist/types/bet-metadata.type.d.mts +7 -0
  104. package/dist/types/bet-metadata.type.d.mts.map +1 -0
  105. package/dist/types/build-game-transaction-options.type.d.mts +9 -0
  106. package/dist/types/build-game-transaction-options.type.d.mts.map +1 -0
  107. package/dist/types/game-details.type.d.mts +73 -0
  108. package/dist/types/game-details.type.d.mts.map +1 -0
  109. package/dist/types/game-details.type.mjs +59 -0
  110. package/dist/types/game-details.type.mjs.map +1 -0
  111. package/dist/types/game-settings.type.d.mts +201 -0
  112. package/dist/types/game-settings.type.d.mts.map +1 -0
  113. package/dist/types/game-settings.type.mjs +37 -0
  114. package/dist/types/game-settings.type.mjs.map +1 -0
  115. package/dist/types/game.type.d.mts +15 -0
  116. package/dist/types/game.type.d.mts.map +1 -0
  117. package/dist/types/game.type.mjs +19 -0
  118. package/dist/types/game.type.mjs.map +1 -0
  119. package/dist/types/index.d.mts +7 -0
  120. package/dist/types/move-float.type.d.mts +7 -0
  121. package/dist/types/move-float.type.d.mts.map +1 -0
  122. package/dist/types/network.type.d.mts +1 -0
  123. package/dist/types/network.type.mjs +6 -0
  124. package/dist/types/network.type.mjs.map +1 -0
  125. package/dist/types/suigar-config.type.d.mts +33 -0
  126. package/dist/types/suigar-config.type.d.mts.map +1 -0
  127. package/dist/types/transaction-options.type.d.mts +63 -0
  128. package/dist/types/transaction-options.type.d.mts.map +1 -0
  129. package/dist/utils/constants.d.mts +8 -0
  130. package/dist/utils/constants.d.mts.map +1 -0
  131. package/dist/utils/constants.mjs +10 -0
  132. package/dist/utils/constants.mjs.map +1 -0
  133. package/dist/utils/numeric.d.mts +86 -0
  134. package/dist/utils/numeric.d.mts.map +1 -0
  135. package/dist/utils/numeric.mjs +148 -0
  136. package/dist/utils/numeric.mjs.map +1 -0
  137. package/dist/utils/parser.d.mts +54 -0
  138. package/dist/utils/parser.d.mts.map +1 -0
  139. package/dist/utils/parser.mjs +94 -0
  140. package/dist/utils/parser.mjs.map +1 -0
  141. package/dist/utils.d.mts +4 -0
  142. package/dist/utils.mjs +4 -0
  143. package/package.json +21 -22
  144. package/dist/chunk-7N55D2TV.js +0 -343
  145. package/dist/games-Da2uZvVJ.d.cts +0 -98
  146. package/dist/games-Da2uZvVJ.d.ts +0 -98
  147. package/dist/games.cjs +0 -2
  148. package/dist/games.d.cts +0 -2
  149. package/dist/games.d.ts +0 -2
  150. package/dist/games.js +0 -1
  151. package/dist/index-3P_LBbDM.d.cts +0 -25
  152. package/dist/index-3P_LBbDM.d.ts +0 -25
  153. package/dist/index.cjs +0 -1692
  154. package/dist/index.d.cts +0 -467
  155. package/dist/index.d.ts +0 -467
  156. package/dist/index.js +0 -1470
  157. package/dist/utils.cjs +0 -243
  158. package/dist/utils.d.cts +0 -180
  159. package/dist/utils.d.ts +0 -180
  160. package/dist/utils.js +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @suigar/sdk
2
2
 
3
+ ## 2.0.0-beta.16
4
+
5
+ ### Patch Changes
6
+
7
+ - 4463bbf: Update `@mysten/*` dependencies to latest patch versions
8
+
9
+ ## 2.0.0-beta.15
10
+
11
+ ### Patch Changes
12
+
13
+ - 67a8b5b: Add `parseGameEvent` to `@suigar/sdk/utils` for extracting a normalized Suigar game id plus raw Move event name for supported Suigar events in `GAME_EVENTS`, including standard `BetResultEvent` and PvP coinflip events.
14
+
15
+ Change `parseGameDetails` to accept `gameId` first so TypeScript can narrow the returned detail keys and value types per game.
16
+
3
17
  ## 2.0.0-beta.14
4
18
 
5
19
  ### Patch Changes
package/README.md CHANGED
@@ -10,7 +10,7 @@ npm install --save @suigar/sdk @mysten/sui @mysten/bcs
10
10
 
11
11
  Runtime requirements:
12
12
 
13
- - Node.js `>=22`
13
+ - Node.js `^22.18.0 || >=24`
14
14
  - ESM project configuration (`"type": "module"`)
15
15
  - `@mysten/sui` v2
16
16
  - `@mysten/bcs` v2
@@ -71,7 +71,7 @@ Numeric helper behavior:
71
71
  JavaScript `number`
72
72
  - `parseCoinType(type)` extracts the normalized first generic coin type from a
73
73
  Move object type string and throws `TypeError` when no coin type can be parsed
74
- - `parseGameDetails(gameDetails)` decodes standard `BetResultEvent.game_details`
74
+ - `parseGameDetails(gameId, gameDetails)` decodes standard `BetResultEvent.game_details`
75
75
  byte arrays into the expected string, number, and boolean values while
76
76
  preserving the original on-chain keys
77
77
 
@@ -267,6 +267,9 @@ By default, per-object fetch or parse failures are skipped so one broken or
267
267
  already-deleted registry entry does not reject the full lookup. Pass
268
268
  `throwOnError: true` if you want the call to reject instead.
269
269
 
270
+ Each returned entry includes the parsed game fields plus a derived
271
+ `coin_type` string from the underlying Move object type.
272
+
270
273
  Any supported `listDynamicFields()` options such as `limit`, `cursor`, or
271
274
  `signal` can be passed through `options`.
272
275
 
@@ -275,7 +278,7 @@ const games = await client.suigar.getPvPCoinflipGames({ limit: 20 });
275
278
 
276
279
  for (const game of games) {
277
280
  console.log(game.id);
278
- console.log(game.coinType);
281
+ console.log(game.coin_type);
279
282
  }
280
283
  ```
281
284
 
@@ -460,7 +463,7 @@ These are generated Move event decoders. Use them to parse Suigar event payloads
460
463
  - `fromMoveFloat(float)` converts a generated Move `Float` struct to a JavaScript number
461
464
  - `parseCoinType(type)` extracts the normalized coin type from generic Move object type strings such as PvP coinflip `Game<T>`
462
465
  and throws `TypeError` when the type string does not include a first generic coin type
463
- - `parseGameDetails(game_details)` decodes `BetResultEvent.game_details` entries into the expected string, number, and boolean values
466
+ - `parseGameDetails(gameId, game_details)` decodes `BetResultEvent.game_details` entries into the expected string, number, and boolean values
464
467
 
465
468
  ### Parse PvP Coinflip Game Object Data
466
469
 
@@ -525,17 +528,28 @@ Parsed fields include:
525
528
  - `game_details`
526
529
  - `metadata`
527
530
 
528
- `game_details` and `metadata` decode as `VecMap<string, vector<u8>>`-shaped data, so values come back as byte arrays. Use `parseGameDetails` from `@suigar/sdk/utils` to decode `game_details` with the SDK's known game-detail schemas.
531
+ `game_details` and `metadata` decode as `VecMap<string, vector<u8>>`-shaped data, so values come back as byte arrays. Use `parseGameEvent(event)` from `@suigar/sdk/utils` to retrieve the normalized `gameId` and `eventName`, then pass that `gameId` to `parseGameDetails(gameId, decoded.game_details)` for game-specific key and value typing.
529
532
 
530
533
  ```ts
531
- import { parseGameDetails } from '@suigar/sdk/utils';
534
+ import { parseGameDetails, parseGameEvent } from '@suigar/sdk/utils';
532
535
 
536
+ const { gameId, eventName } = parseGameEvent(event)!;
533
537
  const decoded = client.suigar.bcs.BetResultEvent.parse(event.bcs);
534
- const gameDetails = parseGameDetails(decoded.game_details);
538
+ const gameDetails = parseGameDetails(gameId, decoded.game_details);
535
539
  ```
536
540
 
537
541
  `parseGameDetails` preserves the on-chain keys and only changes the value representation. For example, coinflip details keep keys such as `player_bet` and `coin_outcome`; range details keep keys such as `roll_value`, `win`, and `payout_multiplier`.
538
542
 
543
+ `parseGameDetails(gameId, decoded.game_details)` narrows based on the parsed event game id. For example, when `gameId === 'coinflip'` it narrows to:
544
+
545
+ - `{ player_bet: string; coin_outcome: string }`
546
+
547
+ `parseGameEvent(event)` returns the normalized game id and raw Move event name for every supported Suigar event in `GAME_EVENTS`:
548
+
549
+ - `{ gameId: 'coinflip' | 'limbo' | 'plinko' | 'range' | 'wheel', eventName: 'BetResultEvent' }` for standard bet result events
550
+ - `{ gameId: 'pvp-coinflip', eventName: 'GameCreatedEvent' | 'GameResolvedEvent' | 'GameCancelledEvent' }` for PvP coinflip events
551
+ - `null` for unsupported event names or non-Suigar event payloads
552
+
539
553
  When the extension is configured with `partner`, decoded event `metadata` will
540
554
  contain that partner wallet address under the `partner` entry.
541
555
 
@@ -545,7 +559,7 @@ contain that partner wallet address under the `partner` entry.
545
559
  > - unwrap the core API union with `result.$kind`, `result.Transaction`, and `result.FailedTransaction`
546
560
  > - parse emitted events from the unwrapped transaction result
547
561
  > - use `event.bcs` for consistent decoding across transports
548
- > - use `parseGameDetails(decoded.game_details)` instead of hand-decoding standard game detail byte arrays
562
+ > - use `const { gameId } = parseGameEvent(event)!` and then `parseGameDetails(gameId, decoded.game_details)` instead of hand-decoding standard game detail byte arrays
549
563
 
550
564
  > **Tip:**
551
565
  >
@@ -0,0 +1,258 @@
1
+ import { Game, StandardGame } from "./types/game.type.mjs";
2
+ import { SuigarConfig, SuigarExtensionOptions } from "./types/suigar-config.type.mjs";
3
+ import { BuildPvPCoinflipTransactionOptions, PvPCoinflipAction, WithThrowOnError } from "./types/transaction-options.type.mjs";
4
+ import { MoveStruct } from "./contracts/utils/index.mjs";
5
+ import { Game as Game$1 } from "./contracts/pvp-coinflip/pvp_coinflip.mjs";
6
+ import { BuildGameOptions } from "./types/build-game-transaction-options.type.mjs";
7
+ import { GameParameters, GetGameParametersOptions } from "./types/game-settings.type.mjs";
8
+ import { BuildTransactionOptions, Transaction } from "@mysten/sui/transactions";
9
+ import { ClientWithCoreApi, SuiClientTypes } from "@mysten/sui/client";
10
+ import * as _$_mysten_bcs0 from "@mysten/bcs";
11
+ import { InferBcsType } from "@mysten/bcs";
12
+
13
+ //#region src/client.d.ts
14
+ declare function suigar<const Name = 'suigar'>({
15
+ name,
16
+ partner,
17
+ cacheTtl
18
+ }?: SuigarExtensionOptions<Name>): {
19
+ name: Name;
20
+ register: (client: ClientWithCoreApi) => SuigarClient;
21
+ };
22
+ declare class SuigarClient {
23
+ #private;
24
+ constructor({
25
+ client,
26
+ name,
27
+ partner,
28
+ cacheTtl
29
+ }: {
30
+ client: ClientWithCoreApi;
31
+ name: string;
32
+ partner?: string;
33
+ cacheTtl?: number;
34
+ });
35
+ /**
36
+ * Returns the resolved SDK configuration for the connected network.
37
+ *
38
+ * This is primarily useful for debugging or inspecting which package ids,
39
+ * registry ids, supported coin types, and price info object ids the SDK
40
+ * resolved for the current client network.
41
+ *
42
+ * @returns Network-resolved Suigar configuration.
43
+ */
44
+ getConfig(): SuigarConfig;
45
+ /**
46
+ * Builds a transaction with the configured Sui client and encodes the resulting BCS bytes as base64.
47
+ *
48
+ * Use this when an external wallet, API, or transport expects the built transaction payload as a base64 string
49
+ * instead of raw bytes. The SDK always injects the configured Sui client, so `options` accepts the standard
50
+ * transaction build options except for `client`.
51
+ *
52
+ * @param transaction Transaction to build and serialize.
53
+ * @param options Optional transaction build options forwarded to `transaction.build()`, excluding `client`.
54
+ * @returns Base64-encoded transaction bytes ready to send over the wire.
55
+ */
56
+ serializeTransactionToBase64(transaction: Transaction, options?: Omit<BuildTransactionOptions, 'client'>): Promise<string>;
57
+ /**
58
+ * Reads on-chain game parameters for the requested game.
59
+ *
60
+ * The SDK first reads the selected game's settings object from SweetHouse,
61
+ * then reads that game's coin-specific `Parameters<T>` object. Results are
62
+ * cached according to the extension `cacheTtl` option. Pass
63
+ * `ignoreCache: true` to refresh the on-chain read and replace the cached
64
+ * value.
65
+ *
66
+ * @param game Game whose parameters should be loaded.
67
+ * @param options Optional coin type, cache override, and abort signal.
68
+ * @returns Parsed game parameters typed for the requested game.
69
+ */
70
+ getGameParameters<TGame extends Game>(game: TGame, options?: GetGameParametersOptions): Promise<GameParameters<TGame>>;
71
+ /**
72
+ * Lists unresolved PvP coinflip games from the configured registry and resolves
73
+ * each entry into parsed on-chain game state.
74
+ *
75
+ * This fetches dynamic fields from the PvP coinflip registry object, then bulk
76
+ * loads the referenced game objects through `client.core.getObjects()`. Registry
77
+ * membership is the unresolved-state signal: when a game is joined and resolved,
78
+ * the Move flow removes it from the registry and deletes the live `Game` object.
79
+ * Use this when a product needs the current set of open PvP coinflip matches for
80
+ * browsing or lobby views.
81
+ *
82
+ * @param options Optional dynamic field pagination forwarded to `listDynamicFields()`, excluding `parentId`.
83
+ * Supported options such as `limit`, `cursor`, and `signal` are forwarded to the
84
+ * underlying lookup calls. Pass `throwOnError: true` to fail the whole lookup
85
+ * when any referenced game object cannot be fetched or parsed. By default,
86
+ * failed per-object lookups are skipped and only successfully parsed unresolved
87
+ * games are returned.
88
+ * @returns Parsed unresolved PvP coinflip game objects for the requested
89
+ * registry page. When `throwOnError` is `false`, entries that fail object fetch
90
+ * or parse are omitted from the returned array.
91
+ */
92
+ getPvPCoinflipGames(options?: WithThrowOnError<Omit<SuiClientTypes.ListDynamicFieldsOptions, 'parentId'>>): Promise<(InferBcsType<typeof Game$1> & {
93
+ coin_type: string;
94
+ })[]>;
95
+ /**
96
+ * BCS struct constructors for decoding on-chain objects and events related to Suigar games.
97
+ *
98
+ * These can be used to parse the `content` field of on-chain objects and events into structured data with the
99
+ * expected types. For example, use `client.suigar.bcs.PvPCoinflipGame.parse(object.content)` to decode a PvP
100
+ * coinflip game object.
101
+ *
102
+ * Note that these constructors are not meant for encoding transaction arguments, as the SDK's transaction
103
+ * builders handle argument serialization internally. Use these primarily for decoding and parsing on-chain data.
104
+ */
105
+ bcs: {
106
+ /**
107
+ * Object representing the state of a PvP coinflip game, as stored on-chain.
108
+ */
109
+ PvPCoinflipGame: MoveStruct<{
110
+ id: _$_mysten_bcs0.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
111
+ creator: _$_mysten_bcs0.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
112
+ creator_is_tails: _$_mysten_bcs0.BcsType<boolean, boolean, "bool">;
113
+ is_private: _$_mysten_bcs0.BcsType<boolean, boolean, "bool">;
114
+ creator_metadata: MoveStruct<{
115
+ contents: _$_mysten_bcs0.BcsType<{
116
+ key: string;
117
+ value: number[];
118
+ }[], Iterable<{
119
+ key: string;
120
+ value: Iterable<number> & {
121
+ length: number;
122
+ };
123
+ }> & {
124
+ length: number;
125
+ }, string>;
126
+ }, "0x2::vec_map::VecMap<string, vector<u8>>">;
127
+ joiner: _$_mysten_bcs0.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
128
+ winner: _$_mysten_bcs0.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
129
+ stake_per_player: _$_mysten_bcs0.BcsType<string, string | number | bigint, "u64">;
130
+ house_edge_bps: _$_mysten_bcs0.BcsType<string, string | number | bigint, "u64">;
131
+ stake_pot: MoveStruct<{
132
+ value: _$_mysten_bcs0.BcsType<string, string | number | bigint, "u64">;
133
+ }, "0x2::balance::Balance<phantom T0>">;
134
+ }, "0xb43cf6583c0c15315c7e66f173af4be79ac40c38aad1fd92ec08638ab2026202::pvp_coinflip::Game<phantom T0>">;
135
+ /**
136
+ * Event emitted at the end of a standard game (e.g., Coinflip, Limbo), containing the result and payout information.
137
+ */
138
+ BetResultEvent: MoveStruct<{
139
+ player: _$_mysten_bcs0.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
140
+ coin_type: MoveStruct<{
141
+ name: _$_mysten_bcs0.BcsType<string, string, "string">;
142
+ }, "0x0000000000000000000000000000000000000000000000000000000000000001::type_name::TypeName">;
143
+ stake_amount: _$_mysten_bcs0.BcsType<string, string | number | bigint, "u64">;
144
+ unsafe_oracle_usd_coin_price: MoveStruct<{
145
+ is_negative: _$_mysten_bcs0.BcsType<boolean, boolean, "bool">;
146
+ exp: MoveStruct<{
147
+ bits: _$_mysten_bcs0.BcsType<string, string | number | bigint, "u64">;
148
+ }, "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::i64::I64">;
149
+ mant: _$_mysten_bcs0.BcsType<string, string | number | bigint, "u64">;
150
+ }, "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::float::Float">;
151
+ adjusted_oracle_usd_coin_price: MoveStruct<{
152
+ is_negative: _$_mysten_bcs0.BcsType<boolean, boolean, "bool">;
153
+ exp: MoveStruct<{
154
+ bits: _$_mysten_bcs0.BcsType<string, string | number | bigint, "u64">;
155
+ }, "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::i64::I64">;
156
+ mant: _$_mysten_bcs0.BcsType<string, string | number | bigint, "u64">;
157
+ }, "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::float::Float">;
158
+ outcome_amount: _$_mysten_bcs0.BcsType<string, string | number | bigint, "u64">;
159
+ game_details: MoveStruct<{
160
+ contents: _$_mysten_bcs0.BcsType<{
161
+ key: string;
162
+ value: number[];
163
+ }[], Iterable<{
164
+ key: string;
165
+ value: Iterable<number> & {
166
+ length: number;
167
+ };
168
+ }> & {
169
+ length: number;
170
+ }, string>;
171
+ }, "0x2::vec_map::VecMap<string, vector<u8>>">;
172
+ metadata: MoveStruct<{
173
+ contents: _$_mysten_bcs0.BcsType<{
174
+ key: string;
175
+ value: number[];
176
+ }[], Iterable<{
177
+ key: string;
178
+ value: Iterable<number> & {
179
+ length: number;
180
+ };
181
+ }> & {
182
+ length: number;
183
+ }, string>;
184
+ }, "0x2::vec_map::VecMap<string, vector<u8>>">;
185
+ }, "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::core::BetResultEvent<phantom T0>">;
186
+ /**
187
+ * Event emitted when a PvP Coinflip game is created, containing the game configuration and initial state.
188
+ */
189
+ PvPCoinflipGameCreatedEvent: MoveStruct<{
190
+ game_id: _$_mysten_bcs0.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
191
+ creator: _$_mysten_bcs0.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
192
+ creator_is_tails: _$_mysten_bcs0.BcsType<boolean, boolean, "bool">;
193
+ is_private: _$_mysten_bcs0.BcsType<boolean, boolean, "bool">;
194
+ joiner_is_tails: _$_mysten_bcs0.BcsType<boolean, boolean, "bool">;
195
+ stake_per_player: _$_mysten_bcs0.BcsType<string, string | number | bigint, "u64">;
196
+ house_edge_bps: _$_mysten_bcs0.BcsType<string, string | number | bigint, "u64">;
197
+ coin_type: MoveStruct<{
198
+ name: _$_mysten_bcs0.BcsType<string, string, "string">;
199
+ }, "0x0000000000000000000000000000000000000000000000000000000000000001::type_name::TypeName">;
200
+ }, "0xb43cf6583c0c15315c7e66f173af4be79ac40c38aad1fd92ec08638ab2026202::pvp_coinflip::GameCreatedEvent<phantom T0>">;
201
+ /**
202
+ * Event emitted when a PvP Coinflip game is resolved, containing the final outcome.
203
+ */
204
+ PvPCoinflipGameResolvedEvent: MoveStruct<{
205
+ game_id: _$_mysten_bcs0.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
206
+ creator: _$_mysten_bcs0.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
207
+ joiner: _$_mysten_bcs0.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
208
+ winner: _$_mysten_bcs0.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
209
+ creator_is_tails: _$_mysten_bcs0.BcsType<boolean, boolean, "bool">;
210
+ is_private: _$_mysten_bcs0.BcsType<boolean, boolean, "bool">;
211
+ joiner_is_tails: _$_mysten_bcs0.BcsType<boolean, boolean, "bool">;
212
+ stake_per_player: _$_mysten_bcs0.BcsType<string, string | number | bigint, "u64">;
213
+ total_pot: _$_mysten_bcs0.BcsType<string, string | number | bigint, "u64">;
214
+ house_edge_amount: _$_mysten_bcs0.BcsType<string, string | number | bigint, "u64">;
215
+ payout_amount: _$_mysten_bcs0.BcsType<string, string | number | bigint, "u64">;
216
+ coin_type: MoveStruct<{
217
+ name: _$_mysten_bcs0.BcsType<string, string, "string">;
218
+ }, "0x0000000000000000000000000000000000000000000000000000000000000001::type_name::TypeName">;
219
+ }, "0xb43cf6583c0c15315c7e66f173af4be79ac40c38aad1fd92ec08638ab2026202::pvp_coinflip::GameResolvedEvent<phantom T0>">;
220
+ /**
221
+ * Event emitted when a PvP Coinflip game is cancelled.
222
+ */
223
+ PvPCoinflipGameCancelledEvent: MoveStruct<{
224
+ game_id: _$_mysten_bcs0.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
225
+ creator: _$_mysten_bcs0.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
226
+ creator_is_tails: _$_mysten_bcs0.BcsType<boolean, boolean, "bool">;
227
+ is_private: _$_mysten_bcs0.BcsType<boolean, boolean, "bool">;
228
+ stake_per_player: _$_mysten_bcs0.BcsType<string, string | number | bigint, "u64">;
229
+ coin_type: MoveStruct<{
230
+ name: _$_mysten_bcs0.BcsType<string, string, "string">;
231
+ }, "0x0000000000000000000000000000000000000000000000000000000000000001::type_name::TypeName">;
232
+ }, "0xb43cf6583c0c15315c7e66f173af4be79ac40c38aad1fd92ec08638ab2026202::pvp_coinflip::GameCancelledEvent<phantom T0>">;
233
+ };
234
+ /**
235
+ * Transaction builders for Suigar games.
236
+ */
237
+ tx: {
238
+ /**
239
+ * Creates a standard game transaction for the provided game id.
240
+ *
241
+ * @param gameId Supported standard game identifier.
242
+ * @param options Transaction builder options for the selected game.
243
+ * @returns Prepared transaction for the selected game.
244
+ */
245
+ createBetTransaction: <GameId extends StandardGame>(gameId: GameId, options: BuildGameOptions<GameId>) => Transaction;
246
+ /**
247
+ * Creates a PvP coinflip transaction for the requested action.
248
+ *
249
+ * @param action PvP coinflip action to perform.
250
+ * @param options Transaction builder options for the selected action.
251
+ * @returns Prepared PvP coinflip transaction.
252
+ */
253
+ createPvPCoinflipTransaction: <Action extends PvPCoinflipAction>(action: Action, options: BuildPvPCoinflipTransactionOptions<Action>) => Transaction;
254
+ };
255
+ }
256
+ //#endregion
257
+ export { SuigarClient, suigar };
258
+ //# sourceMappingURL=client.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.mts","names":[],"sources":["../src/client.ts"],"mappings":";;;;;;;;;;;;;iBA+DgB,MAAA,uBAAA,CAAA;EACf,IAAA;EACA,OAAA;EACA;AAAA,IACE,sBAAA,CAAuB,IAAA;;qBAGL,iBAAA,KAAoB,YAAA;AAAA;AAAA,cAW5B,YAAA;EAAA;;IAUX,MAAA;IACA,IAAA;IACA,OAAA;IACA;EAAA;IAEA,MAAA,EAAQ,iBAAA;IACR,IAAA;IACA,OAAA;IACA,QAAA;EAAA;EAlCD;;;;;;;;;EA+DA,SAAA,CAAA,GAAa,YAAA;EAhEb;;;;;;;;;;;EA+EM,4BAAA,CACL,WAAA,EAAa,WAAA,EACb,OAAA,GAAU,IAAA,CAAK,uBAAA,cACb,OAAA;;;;;AAjEJ;;;;;;;;;EAmFO,iBAAA,eAAgC,IAAA,CAAA,CACrC,IAAA,EAAM,KAAA,EACN,OAAA,GAAS,wBAAA,GACP,OAAA,CAAQ,cAAA,CAAe,KAAA;EAtBV;;;;;;;;;;;;;;;;;;;;;EAsDV,mBAAA,CACL,OAAA,GAAS,gBAAA,CACR,IAAA,CAAK,cAAA,CAAe,wBAAA,iBAInB,OAAA,EAAS,YAAA,QAAoB,MAAA;IAAqB,SAAA;EAAA;;;;;;;;;;;EA4DrD,GAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAsCW;;;;;;;;;;;;;;;IAlNV;;;;;;;;;;;;;;;;;;;IAuEuB;;;;;;;;;;;;;;EAoCvB;;;EA6FD,EAAA;IAxFqD;;;;;;;0CAgGd,YAAA,EAAY,MAAA,EACzC,MAAA,EAAM,OAAA,EACL,gBAAA,CAAiB,MAAA,MACxB,WAAA;;;;;;;;kDA2C2C,iBAAA,EAAiB,MAAA,EACtD,MAAA,EAAM,OAAA,EACL,kCAAA,CAAmC,MAAA,MAC1C,WAAA;EAAA;AAAA"}
@@ -0,0 +1,291 @@
1
+ import { TypeName } from "./contracts/core/deps/0x0000000000000000000000000000000000000000000000000000000000000001/type_name.mjs";
2
+ import { BetResultEvent } from "./contracts/core/core.mjs";
3
+ import { Game, GameCancelledEvent, GameCreatedEvent, GameResolvedEvent } from "./contracts/pvp-coinflip/pvp_coinflip.mjs";
4
+ import { resolveGamePackageId, resolveSuigarConfig } from "./helpers/config.mjs";
5
+ import { resolveCoinTypeNameForTypeNameKey, resolveGameSettingsKeyType } from "./helpers/game-settings.mjs";
6
+ import { SUPPORTED_SUI_NETWORKS } from "./types/network.type.mjs";
7
+ import { parseCoinType } from "./utils/parser.mjs";
8
+ import { buildCoinflipTransaction } from "./transactions/coinflip.mjs";
9
+ import { buildLimboTransaction } from "./transactions/limbo.mjs";
10
+ import { buildPlinkoTransaction } from "./transactions/plinko.mjs";
11
+ import { buildPvPCoinflipTransaction } from "./transactions/pvp-coinflip.mjs";
12
+ import { buildRangeTransaction } from "./transactions/range.mjs";
13
+ import { buildWheelTransaction } from "./transactions/wheel.mjs";
14
+ import { TtlClientCache } from "./ttl-cache.mjs";
15
+ import { GAME_SETTINGS } from "./types/game-settings.type.mjs";
16
+ import { normalizeStructTag, toBase64 } from "@mysten/sui/utils";
17
+ //#region src/client.ts
18
+ function suigar({ name = "suigar", partner, cacheTtl } = {}) {
19
+ return {
20
+ name,
21
+ register: (client) => {
22
+ return new SuigarClient({
23
+ client,
24
+ name: String(name),
25
+ partner,
26
+ cacheTtl
27
+ });
28
+ }
29
+ };
30
+ }
31
+ var SuigarClient = class {
32
+ #client;
33
+ #config;
34
+ #partner;
35
+ #cache;
36
+ constructor({ client, name, partner, cacheTtl }) {
37
+ this.#client = client;
38
+ this.#partner = partner;
39
+ this.#cache = client.cache.scope("@suigar/sdk").readSync([name, "ttl-cache"], () => {
40
+ return new TtlClientCache({ ttlMs: cacheTtl ?? 18e5 });
41
+ });
42
+ const network = this.#client.network;
43
+ if (!SUPPORTED_SUI_NETWORKS.includes(network)) throw new RangeError(`Unsupported network: ${network}`);
44
+ this.#config = resolveSuigarConfig(network);
45
+ }
46
+ /**
47
+ * Returns the resolved SDK configuration for the connected network.
48
+ *
49
+ * This is primarily useful for debugging or inspecting which package ids,
50
+ * registry ids, supported coin types, and price info object ids the SDK
51
+ * resolved for the current client network.
52
+ *
53
+ * @returns Network-resolved Suigar configuration.
54
+ */
55
+ getConfig() {
56
+ return this.#config;
57
+ }
58
+ /**
59
+ * Builds a transaction with the configured Sui client and encodes the resulting BCS bytes as base64.
60
+ *
61
+ * Use this when an external wallet, API, or transport expects the built transaction payload as a base64 string
62
+ * instead of raw bytes. The SDK always injects the configured Sui client, so `options` accepts the standard
63
+ * transaction build options except for `client`.
64
+ *
65
+ * @param transaction Transaction to build and serialize.
66
+ * @param options Optional transaction build options forwarded to `transaction.build()`, excluding `client`.
67
+ * @returns Base64-encoded transaction bytes ready to send over the wire.
68
+ */
69
+ async serializeTransactionToBase64(transaction, options) {
70
+ return toBase64(await transaction.build({
71
+ ...options,
72
+ client: this.#client
73
+ }));
74
+ }
75
+ /**
76
+ * Reads on-chain game parameters for the requested game.
77
+ *
78
+ * The SDK first reads the selected game's settings object from SweetHouse,
79
+ * then reads that game's coin-specific `Parameters<T>` object. Results are
80
+ * cached according to the extension `cacheTtl` option. Pass
81
+ * `ignoreCache: true` to refresh the on-chain read and replace the cached
82
+ * value.
83
+ *
84
+ * @param game Game whose parameters should be loaded.
85
+ * @param options Optional coin type, cache override, and abort signal.
86
+ * @returns Parsed game parameters typed for the requested game.
87
+ */
88
+ async getGameParameters(game, options = {}) {
89
+ const coinType = normalizeStructTag(options.coinType ?? this.#config.coinTypes.sui);
90
+ return this.#cache.read([
91
+ "parameters",
92
+ this.#client.network,
93
+ game,
94
+ coinType
95
+ ], () => this.#fetchGameParameters(game, coinType, options.signal), { ignoreCache: options.ignoreCache });
96
+ }
97
+ /**
98
+ * Lists unresolved PvP coinflip games from the configured registry and resolves
99
+ * each entry into parsed on-chain game state.
100
+ *
101
+ * This fetches dynamic fields from the PvP coinflip registry object, then bulk
102
+ * loads the referenced game objects through `client.core.getObjects()`. Registry
103
+ * membership is the unresolved-state signal: when a game is joined and resolved,
104
+ * the Move flow removes it from the registry and deletes the live `Game` object.
105
+ * Use this when a product needs the current set of open PvP coinflip matches for
106
+ * browsing or lobby views.
107
+ *
108
+ * @param options Optional dynamic field pagination forwarded to `listDynamicFields()`, excluding `parentId`.
109
+ * Supported options such as `limit`, `cursor`, and `signal` are forwarded to the
110
+ * underlying lookup calls. Pass `throwOnError: true` to fail the whole lookup
111
+ * when any referenced game object cannot be fetched or parsed. By default,
112
+ * failed per-object lookups are skipped and only successfully parsed unresolved
113
+ * games are returned.
114
+ * @returns Parsed unresolved PvP coinflip game objects for the requested
115
+ * registry page. When `throwOnError` is `false`, entries that fail object fetch
116
+ * or parse are omitted from the returned array.
117
+ */
118
+ async getPvPCoinflipGames(options = { limit: 50 }) {
119
+ const { throwOnError = false, ...listOptions } = options;
120
+ const { dynamicFields } = await this.#client.core.listDynamicFields({
121
+ ...listOptions,
122
+ parentId: this.#config.registryIds.pvpCoinflip
123
+ });
124
+ const { objects } = await this.#client.core.getObjects({
125
+ objectIds: dynamicFields.map(({ childId }) => childId),
126
+ signal: listOptions.signal,
127
+ include: { content: true }
128
+ });
129
+ const resolvedGames = objects.map((object) => {
130
+ try {
131
+ if (object instanceof Error) throw object;
132
+ if (!object.content) throw new Error("Unable to resolve PvP coinflip game from retrieved object");
133
+ return {
134
+ ...Game.parse(object.content),
135
+ coin_type: parseCoinType(object.type)
136
+ };
137
+ } catch (error) {
138
+ return error instanceof Error ? error : new Error(String(error));
139
+ }
140
+ });
141
+ if (throwOnError) {
142
+ const firstError = resolvedGames.find((game) => game instanceof Error);
143
+ if (firstError) throw firstError;
144
+ }
145
+ return resolvedGames.flatMap((game) => game instanceof Error ? [] : [game]);
146
+ }
147
+ /**
148
+ * BCS struct constructors for decoding on-chain objects and events related to Suigar games.
149
+ *
150
+ * These can be used to parse the `content` field of on-chain objects and events into structured data with the
151
+ * expected types. For example, use `client.suigar.bcs.PvPCoinflipGame.parse(object.content)` to decode a PvP
152
+ * coinflip game object.
153
+ *
154
+ * Note that these constructors are not meant for encoding transaction arguments, as the SDK's transaction
155
+ * builders handle argument serialization internally. Use these primarily for decoding and parsing on-chain data.
156
+ */
157
+ bcs = {
158
+ /**
159
+ * Object representing the state of a PvP coinflip game, as stored on-chain.
160
+ */
161
+ PvPCoinflipGame: Game,
162
+ /**
163
+ * Event emitted at the end of a standard game (e.g., Coinflip, Limbo), containing the result and payout information.
164
+ */
165
+ BetResultEvent,
166
+ /**
167
+ * Event emitted when a PvP Coinflip game is created, containing the game configuration and initial state.
168
+ */
169
+ PvPCoinflipGameCreatedEvent: GameCreatedEvent,
170
+ /**
171
+ * Event emitted when a PvP Coinflip game is resolved, containing the final outcome.
172
+ */
173
+ PvPCoinflipGameResolvedEvent: GameResolvedEvent,
174
+ /**
175
+ * Event emitted when a PvP Coinflip game is cancelled.
176
+ */
177
+ PvPCoinflipGameCancelledEvent: GameCancelledEvent
178
+ };
179
+ /**
180
+ * Transaction builders for Suigar games.
181
+ */
182
+ tx = {
183
+ /**
184
+ * Creates a standard game transaction for the provided game id.
185
+ *
186
+ * @param gameId Supported standard game identifier.
187
+ * @param options Transaction builder options for the selected game.
188
+ * @returns Prepared transaction for the selected game.
189
+ */
190
+ createBetTransaction: (gameId, options) => {
191
+ switch (gameId) {
192
+ case "coinflip": return buildCoinflipTransaction({
193
+ ...options,
194
+ config: this.#config,
195
+ partner: this.#partner
196
+ });
197
+ case "limbo": return buildLimboTransaction({
198
+ ...options,
199
+ config: this.#config,
200
+ partner: this.#partner
201
+ });
202
+ case "plinko": return buildPlinkoTransaction({
203
+ ...options,
204
+ config: this.#config,
205
+ partner: this.#partner
206
+ });
207
+ case "range": return buildRangeTransaction({
208
+ ...options,
209
+ config: this.#config,
210
+ partner: this.#partner
211
+ });
212
+ case "wheel": return buildWheelTransaction({
213
+ ...options,
214
+ config: this.#config,
215
+ partner: this.#partner
216
+ });
217
+ default: throw new RangeError(`Unsupported game: ${gameId}`);
218
+ }
219
+ },
220
+ /**
221
+ * Creates a PvP coinflip transaction for the requested action.
222
+ *
223
+ * @param action PvP coinflip action to perform.
224
+ * @param options Transaction builder options for the selected action.
225
+ * @returns Prepared PvP coinflip transaction.
226
+ */
227
+ createPvPCoinflipTransaction: (action, options) => {
228
+ switch (action) {
229
+ case "create": return buildPvPCoinflipTransaction("create", {
230
+ ...options,
231
+ config: this.#config,
232
+ partner: this.#partner
233
+ });
234
+ case "join": {
235
+ const joinOptions = options;
236
+ return buildPvPCoinflipTransaction("join", {
237
+ ...joinOptions,
238
+ betCoin: this.#createPvPCoinflipBetCoin(joinOptions),
239
+ config: this.#config,
240
+ partner: this.#partner
241
+ });
242
+ }
243
+ case "cancel": return buildPvPCoinflipTransaction("cancel", {
244
+ ...options,
245
+ config: this.#config,
246
+ partner: this.#partner
247
+ });
248
+ default: throw new RangeError(`Unsupported PvP coinflip action: ${action}`);
249
+ }
250
+ }
251
+ };
252
+ #createPvPCoinflipBetCoin(options) {
253
+ return async (tx) => {
254
+ const { json } = await Game.get({
255
+ client: this.#client,
256
+ objectId: options.gameId
257
+ });
258
+ return tx.coin({
259
+ type: options.coinType,
260
+ balance: BigInt(json.stake_per_player),
261
+ useGasCoin: options.allowGasCoinShortcut
262
+ });
263
+ };
264
+ }
265
+ async #fetchGameParameters(game, coinType, signal) {
266
+ const gameDefinition = GAME_SETTINGS[game];
267
+ const { object: settingsObject } = await this.#client.core.getDynamicObjectField({
268
+ parentId: this.#config.packageIds.sweetHouse,
269
+ name: {
270
+ type: resolveGameSettingsKeyType(gameDefinition.settingsKey.name, resolveGamePackageId(this.#config, game)),
271
+ bcs: gameDefinition.settingsKey.serialize({ dummy_field: false }).toBytes()
272
+ },
273
+ signal
274
+ });
275
+ const { object } = await this.#client.core.getDynamicObjectField({
276
+ parentId: settingsObject.objectId,
277
+ name: {
278
+ type: TypeName.name,
279
+ bcs: TypeName.serialize({ name: resolveCoinTypeNameForTypeNameKey(coinType) }).toBytes()
280
+ },
281
+ include: { content: true },
282
+ signal
283
+ });
284
+ if (!object?.content) throw new Error(`Missing parameters object content for ${game} and coin type ${coinType}`);
285
+ return gameDefinition.parameters.parse(object.content);
286
+ }
287
+ };
288
+ //#endregion
289
+ export { SuigarClient, suigar };
290
+
291
+ //# sourceMappingURL=client.mjs.map