@suigar/sdk 2.0.0-beta.3 → 2.0.0-beta.4

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/CHANGELOG.md CHANGED
@@ -1,17 +1,42 @@
1
1
  # @suigar/sdk
2
2
 
3
+ ## 2.0.0-beta.4
4
+
5
+ ### Patch Changes
6
+
7
+ - 6daa819: Add BCS parser helpers and a Next.js game integration example app.
8
+ - expose parser helpers through `@suigar/sdk/utils`
9
+ - add `parseGameDetails` for decoding `BetResultEvent.game_details`
10
+ - document generated BCS event decoding and game detail parsing guidance
11
+ - add a testnet-only `examples/game-integration` app for standard and PvP Suigar transactions
12
+ - integrate Mysten dApp Kit wallet connection, signing, and execution
13
+ - add live transaction code previews and shared decoded event logging with SDK parser helpers
14
+ - add Suigar-themed responsive UI, supported coin selection, and human-readable stake handling
15
+ - update PvP coinflip join so callers only provide `gameId` and the SDK derives the join stake while using the configured price info object id
16
+
17
+ - b89d0b4: Add a public `@suigar/sdk/games` export subpath for shared game option types, and export `SuigarClient` from the package root.
18
+ - bf1f71b: Add `registryIds` to `SuigarConfig` and resolve it from the network config registry map.
19
+
20
+ Document the PvP coinflip runtime helpers more clearly by describing
21
+ registry-backed unresolved game discovery through `getPvPCoinflipGames()` and
22
+ the normalized live-game lookup behavior of `resolvePvPConflipGame()`.
23
+
24
+ - 4861f55: Add public utility exports for shared scaling constants in `@suigar/sdk/utils`, including `RANGE_POINT_LIMIT` and `DEFAULT_RANGE_SCALE`. Update the SDK example app and documentation to use the exported constants and document limbo/range scaling behavior more clearly.
25
+
3
26
  ## 2.0.0-beta.3
4
27
 
5
28
  ### Patch Changes
6
29
 
7
- - e1cdedc: - Fix exported transaction option types so `BuildGameOptions` and `BuildPvPGameOptions` no longer require the internal `config` field
30
+ - e1cdedc: Improve public transaction builder typings and refresh Sui 2.0+ integration guidance around the gRPC client.
31
+ - Fix exported transaction option types so `BuildGameOptions` and `BuildPvPGameOptions` no longer require the internal `config` field
8
32
  - Update installation and integration documentation for Sui 2.0+ by switching examples to `SuiGrpcClient`, clarifying required peer dependencies, and aligning transaction-result examples with the current client API.
9
33
 
10
34
  ## 2.0.0-beta.2
11
35
 
12
36
  ### Patch Changes
13
37
 
14
- - 128cb6c: - `suigar()` now only accepts the extension `name`.
38
+ - 128cb6c: Make SDK configuration network-resolved and expose runtime config inspection through the client extension.
39
+ - `suigar()` now only accepts the extension `name`.
15
40
  - The SDK now validates the connected client network and supports `mainnet` and `testnet`.
16
41
  - Added `client.suigar.getConfig()` to inspect the resolved network config at runtime.
17
42
  - Exported the `SuiNetwork` type and `resolveGamePackageId()` helper.
package/README.md CHANGED
@@ -19,14 +19,53 @@ This SDK targets Sui TypeScript SDK 2.0+ only. Follow the official [Sui 2.0 migr
19
19
 
20
20
  ## What This Package Exposes
21
21
 
22
- The package root currently exposes the extension factory:
22
+ The package ships three public entrypoints:
23
+
24
+ - `@suigar/sdk` for the extension factory and runtime client class
25
+ - `@suigar/sdk/games` for game-specific public types
26
+ - `@suigar/sdk/utils` for public parser, constants, and numeric helpers
27
+
28
+ The package root exposes the extension factory and client class:
23
29
 
24
30
  ```ts
25
- import { suigar } from '@suigar/sdk';
31
+ import { suigar, SuigarClient } from '@suigar/sdk';
26
32
  ```
27
33
 
28
34
  It does not export the individual transaction builders from the package root.
29
- It also does not export `SuigarClient` as a public root symbol.
35
+ Those stay on the registered extension instance under `client.suigar.tx`.
36
+
37
+ Utility exports are available from the utils subpath:
38
+
39
+ ```ts
40
+ import {
41
+ DEFAULT_GAS_BUDGET_MIST,
42
+ DEFAULT_LIMBO_MULTIPLIER_SCALE,
43
+ DEFAULT_RANGE_SCALE,
44
+ RANGE_POINT_LIMIT,
45
+ parseFloat,
46
+ parseGameDetails,
47
+ parseI64,
48
+ toBigIntAmount,
49
+ toU8Number,
50
+ } from '@suigar/sdk/utils';
51
+ ```
52
+
53
+ Game-specific type exports are available from the dedicated `games` subpath:
54
+
55
+ ```ts
56
+ import type {
57
+ BuildCoinflipTransactionOptions,
58
+ CoinSide,
59
+ } from '@suigar/sdk/games';
60
+ import type {
61
+ BuildCreatePvPCoinflipTransactionOptions,
62
+ PvPCoinflipAction,
63
+ } from '@suigar/sdk/games';
64
+ ```
65
+
66
+ Current game-type subpath exports:
67
+
68
+ - `@suigar/sdk/games`: `CoinSide`, `PvPCoinflipAction`, `BuildCoinflipTransactionOptions`, `BuildLimboTransactionOptions`, `BuildPlinkoTransactionOptions`, `BuildRangeTransactionOptions`, `BuildWheelTransactionOptions`, `BuildCreatePvPCoinflipTransactionOptions`, `BuildJoinPvPCoinflipTransactionOptions`, `BuildCancelPvPCoinflipTransactionOptions`
30
69
 
31
70
  What you actually use at runtime is the registered extension instance:
32
71
 
@@ -35,6 +74,8 @@ const client = new SuiGrpcClient({ baseUrl, network }).$extend(suigar());
35
74
 
36
75
  client.suigar.serializeTransactionToBase64(...);
37
76
  client.suigar.getConfig();
77
+ client.suigar.getPvPCoinflipGames(...);
78
+ client.suigar.resolvePvPConflipGame(...);
38
79
  client.suigar.bcs;
39
80
  client.suigar.tx;
40
81
  ```
@@ -66,12 +107,24 @@ const base64 = await client.suigar.serializeTransactionToBase64(tx);
66
107
 
67
108
  Creates a named Sui client extension. By default, it registers under `client.suigar`.
68
109
 
110
+ ### Partner Setup
111
+
112
+ > [!IMPORTANT]
113
+ > `partner` is the partner wallet address. Configure it once when you
114
+ > register the extension so the SDK can append that wallet address to supported
115
+ > bet metadata automatically.
116
+
69
117
  ```ts
70
- const client = new SuiGrpcClient({ baseUrl, network }).$extend(suigar());
118
+ const client = new SuiGrpcClient({ baseUrl, network }).$extend(
119
+ suigar({ partner: '0xpartner_wallet_address' }),
120
+ );
71
121
 
72
122
  client.suigar;
73
123
  ```
74
124
 
125
+ Do not pass a partner slug, label, or display name here. Use the wallet
126
+ address that should receive partner attribution onchain.
127
+
75
128
  You can rename the extension:
76
129
 
77
130
  ```ts
@@ -96,13 +149,21 @@ client.games.bcs;
96
149
  Supported override areas:
97
150
 
98
151
  - `name`
152
+ - `partner`
153
+
154
+ If `partner` is configured, the SDK automatically writes that partner wallet
155
+ address into the onchain metadata vec-map. Transaction builder options may also
156
+ include `metadata`, but reserved keys such as `partner` and `referrer` are
157
+ ignored with a warning when provided manually.
99
158
 
100
159
  ## Runtime Surface
101
160
 
102
- The registered extension instance exposes three main areas:
161
+ The registered extension instance exposes the main runtime surface:
103
162
 
104
163
  - `getConfig()`
105
164
  - `serializeTransactionToBase64(transaction, options?)`
165
+ - `getPvPCoinflipGames(options?)`
166
+ - `resolvePvPConflipGame(gameId)`
106
167
  - `bcs`
107
168
  - `tx`
108
169
 
@@ -116,6 +177,7 @@ resolved package ids or supported coin mappings for the active client network.
116
177
  It includes:
117
178
 
118
179
  - `packageIds`
180
+ - `registryIds`
119
181
  - `coinTypes`
120
182
  - `priceInfoObjectIds`
121
183
 
@@ -134,6 +196,58 @@ Use this when you need a transport-safe payload for a wallet, API, or external s
134
196
  const base64 = await client.suigar.serializeTransactionToBase64(tx);
135
197
  ```
136
198
 
199
+ ### `getPvPCoinflipGames(options?)`
200
+
201
+ Lists unresolved PvP coinflip games from the configured PvP registry.
202
+
203
+ This reads the registry dynamic fields for the active network and resolves each
204
+ entry into parsed game state through `resolvePvPConflipGame()`. Registry
205
+ membership is the unresolved-state signal: once a match is joined and resolved,
206
+ the Move flow removes it from the registry and deletes the live `Game` object.
207
+
208
+ Use this when a product needs the current set of open PvP coinflip matches for
209
+ browsing or lobby views.
210
+
211
+ ```ts
212
+ const games = await client.suigar.getPvPCoinflipGames({ limit: 20 });
213
+
214
+ for (const game of games) {
215
+ console.log(game.id);
216
+ console.log(game.coinType);
217
+ }
218
+ ```
219
+
220
+ ### `resolvePvPConflipGame(gameId)`
221
+
222
+ Fetches a PvP coinflip game object from chain and parses it into the SDK's
223
+ normalized runtime shape.
224
+
225
+ This requires the object's `content`, decodes it with the generated
226
+ `PvPCoinflipGame` parser, and normalizes the generic coin type into a standard
227
+ struct tag string.
228
+
229
+ Use this when a product needs the live onchain match state for a specific
230
+ pending match before rendering join or cancel actions, or inspecting the stake
231
+ and privacy flag for a game.
232
+
233
+ ```ts
234
+ const game = await client.suigar.resolvePvPConflipGame('0xGAME_ID');
235
+
236
+ console.log(game.creator);
237
+ console.log(game.coinType);
238
+ console.log(game.stake_per_player);
239
+ console.log(game.is_private);
240
+ ```
241
+
242
+ > [!NOTE]
243
+ >
244
+ > - it throws if the object response does not include decodable `content`
245
+ > - the PvP join builder uses this internally to derive the required join stake
246
+ > - after a game is joined and resolved, the live `Game` object is removed from the registry and deleted, so inspect `PvPCoinflipGameResolved` to read the final result
247
+
248
+ > [!TIP]
249
+ > Prefer this helper over manual object parsing when you only need the parsed state for a live PvP game object.
250
+
137
251
  ## `tx`
138
252
 
139
253
  Transaction builders live under `client.suigar.tx`.
@@ -176,6 +290,8 @@ Shared behavior:
176
290
  - `betCount` defaults to `1`
177
291
  - `sender` overrides the transaction sender
178
292
  - `metadata` is encoded into `keys` and `values` byte arrays
293
+ - `partner` configured via `suigar({ partner })` is appended automatically to metadata as the partner wallet address
294
+ - `metadata.partner` and `metadata.referrer` are reserved and ignored with a warning
179
295
  - the SDK resolves the price info object from the configured supported-coin mapping
180
296
  - the reward object is transferred back to `owner`
181
297
 
@@ -201,17 +317,25 @@ const rangeTx = client.suigar.tx.createBetTransaction('range', {
201
317
  owner: '0x123',
202
318
  coinType: '0x2::sui::SUI',
203
319
  stake: 1_000_000_000n,
204
- leftPoint: 0.95,
205
- rightPoint: 1.05,
320
+ leftPoint: 25,
321
+ rightPoint: 75,
206
322
  outOfRange: false,
207
323
  });
208
324
  ```
209
325
 
210
- Notes:
326
+ > [!NOTE]
327
+ >
328
+ > - limbo converts `targetMultiplier` with `Math.round(targetMultiplier * scale)`
329
+ > - with the default limbo scale `100`, exposed as `DEFAULT_LIMBO_MULTIPLIER_SCALE`, a target multiplier of `2.5` becomes `250` onchain
330
+ > - range converts each point with `Math.round(value * scale)`
331
+ > - range points are bounded by the contract limit exposed as `RANGE_POINT_LIMIT`
332
+ > - with the default range scale `1_000_000`, exposed as `DEFAULT_RANGE_SCALE`, valid UI values are `0` to `100`
333
+ > - plinko and wheel `configId` must fit in `u8`
211
334
 
212
- - limbo converts `targetMultiplier` with `Math.round(targetMultiplier * scale)`
213
- - range converts each point with `Math.round(value * scale)`
214
- - plinko and wheel `configId` must fit in `u8`
335
+ > [!TIP]
336
+ >
337
+ > - if you set `scale` to `10_000_000`, valid UI values become `0` to `10`
338
+ > - do not pre-scale range points before passing them to the SDK; pass the human value and let the SDK scale it once
215
339
 
216
340
  ### PvP Coinflip
217
341
 
@@ -240,8 +364,6 @@ const tx = client.suigar.tx.createPvPCoinflipTransaction('join', {
240
364
  owner: '0x123',
241
365
  coinType: '0x2::sui::SUI',
242
366
  gameId: '0xGAME_ID',
243
- extraObjectId: '0xEXTRA_OBJECT_ID',
244
- stake: 1_000_000_000n,
245
367
  });
246
368
  ```
247
369
 
@@ -255,11 +377,14 @@ const tx = client.suigar.tx.createPvPCoinflipTransaction('cancel', {
255
377
  });
256
378
  ```
257
379
 
380
+ Join derives the stake from `gameId` and uses the configured price info object
381
+ id for `coinType`.
382
+
258
383
  PvP shared options:
259
384
 
260
385
  - `owner: string`
261
386
  - `coinType: string`
262
- - `metadata?: ...`
387
+ - `metadata?: Record<string, string | number | boolean | bigint | Uint8Array | number[] | null | undefined>`
263
388
  - `gasBudget?: number | bigint`
264
389
  - `sender?: string`
265
390
  - `allowGasCoinShortcut?: boolean`
@@ -267,7 +392,7 @@ PvP shared options:
267
392
  Action-specific options:
268
393
 
269
394
  - `create`: `stake`, `side`, `isPrivate?`
270
- - `join`: `gameId`, `extraObjectId`, `stake`
395
+ - `join`: `gameId`
271
396
  - `cancel`: `gameId`
272
397
 
273
398
  ## `bcs`
@@ -276,12 +401,41 @@ BCS helpers live under `client.suigar.bcs`.
276
401
 
277
402
  Current exposed helpers:
278
403
 
404
+ - `PvPCoinflipGame`
279
405
  - `BetResultEvent`
280
406
  - `PvPCoinflipGameCreated`
281
407
  - `PvPCoinflipGameResolved`
282
408
  - `PvPCoinflipGameCancelled`
283
409
 
284
- These are generated Move event decoders. Use them to parse Suigar event payloads from transaction results.
410
+ These are generated Move event decoders. Use them to parse Suigar event payloads from transaction results. The `@suigar/sdk/utils` subpath also exposes parser helpers for generated BCS values:
411
+
412
+ - `PvPCoinflipGame` parses a PvP coinflip game object's `content`
413
+ - `parseI64(float.exp)` converts a generated Move `i64` exponent to a JavaScript number
414
+ - `parseFloat(float)` converts a generated Move `Float` struct to a JavaScript number
415
+ - `parseGameDetails(game_details)` decodes `BetResultEvent.game_details` entries into the expected string, number, and boolean values
416
+
417
+ ### Parse PvP Coinflip Game Object Data
418
+
419
+ Use the BCS helper directly when you already fetched the object with `content`:
420
+
421
+ ```ts
422
+ const { object } = await client.core.getObject({
423
+ objectId: '0xGAME_ID',
424
+ include: { content: true },
425
+ });
426
+
427
+ if (!object.content) {
428
+ throw new Error('Missing game content');
429
+ }
430
+
431
+ const parsed = client.suigar.bcs.PvPCoinflipGame.parse(object.content);
432
+ ```
433
+
434
+ If you only need the parsed game object, prefer the convenience method:
435
+
436
+ ```ts
437
+ const parsed = await client.suigar.resolvePvPConflipGame('0xGAME_ID');
438
+ ```
285
439
 
286
440
  ### Parse Standard Bet Result Data
287
441
 
@@ -333,27 +487,32 @@ Parsed fields include:
333
487
  - `game_details`
334
488
  - `metadata`
335
489
 
336
- `game_details` and `metadata` decode as `VecMap<string, vector<u8>>`-shaped data, so values come back as byte arrays.
490
+ `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.
337
491
 
338
492
  ```ts
339
- const textDecoder = new TextDecoder();
493
+ import { parseGameDetails } from '@suigar/sdk/utils';
340
494
 
341
- const metadata = new Map(
342
- decoded.metadata.contents.map(({ key, value }) => [
343
- key,
344
- textDecoder.decode(new Uint8Array(value)),
345
- ]),
346
- );
495
+ const decoded = client.suigar.bcs.BetResultEvent.parse(event.bcs);
496
+ const gameDetails = parseGameDetails(decoded.game_details);
347
497
  ```
348
498
 
349
- Important:
499
+ `parseGameDetails` preserves the onchain 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`.
500
+
501
+ When the extension is configured with `partner`, decoded event `metadata` will
502
+ contain that partner wallet address under the `partner` entry.
503
+
504
+ > [!IMPORTANT]
505
+ >
506
+ > - execute or wait for the transaction with `include: { events: true }`
507
+ > - unwrap the core API union with `result.$kind`, `result.Transaction`, and `result.FailedTransaction`
508
+ > - parse emitted events from the unwrapped transaction result
509
+ > - use `event.bcs` for consistent decoding across transports
510
+ > - use `parseGameDetails(decoded.game_details)` instead of hand-decoding standard game detail byte arrays
350
511
 
351
- - execute or wait for the transaction with `include: { events: true }`
352
- - unwrap the core API union with `result.$kind`, `result.Transaction`, and `result.FailedTransaction`
353
- - parse emitted events from the unwrapped transaction result
354
- - use `event.bcs` for consistent decoding across transports
355
- - `waitForTransaction({ result, include: { effects: true, events: true } })` is useful when you want the finalized transaction result before decoding
356
- - these helpers decode the event payload itself, not a full transaction response
512
+ > [!TIP]
513
+ >
514
+ > - `waitForTransaction({ result, include: { effects: true, events: true } })` is useful when you want the finalized transaction result before decoding
515
+ > - these helpers decode the event payload itself, not a full transaction response
357
516
 
358
517
  ### Parse PvP Coinflip Event Data
359
518
 
@@ -370,3 +529,24 @@ npm run build
370
529
  npm run typecheck
371
530
  npm test
372
531
  ```
532
+
533
+ ## Example App
534
+
535
+ This repository now includes a Next.js integration example in [examples/game-integration](/Users/lucas/Documents/Github/suigar-sdk/examples/game-integration).
536
+
537
+ It demonstrates:
538
+
539
+ - standard game transactions through `client.suigar.tx.createBetTransaction(...)`
540
+ - PvP coinflip create, join, and cancel flows through `client.suigar.tx.createPvPCoinflipTransaction(...)`, exposed in the example through a PvP game selector ready for future PvP games
541
+ - wallet connection and execution with `@mysten/dapp-kit-core` and `@mysten/dapp-kit-react`
542
+ - supported coin selection from `client.suigar.getConfig()`
543
+ - connected-wallet balance display for each supported coin in the example app
544
+ - decoding `BetResultEvent` and PvP events into a persistent event log
545
+ - parsing `BetResultEvent.game_details` with `parseGameDetails`
546
+
547
+ Run it from the repo root with:
548
+
549
+ ```bash
550
+ npm --prefix examples/game-integration install
551
+ npm --prefix examples/game-integration run dev
552
+ ```