@suigar/sdk 2.0.0-beta.6 → 2.0.0-beta.8

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.cjs CHANGED
@@ -367,21 +367,34 @@ var DEFAULT_RANGE_SCALE = 1e6;
367
367
  var DEFAULT_LIMBO_MULTIPLIER_SCALE = 100;
368
368
 
369
369
  // src/utils/numeric.ts
370
- function toBigIntAmount(value, fieldName) {
370
+ function isFiniteNumber(value, message) {
371
+ if (typeof value !== "number") {
372
+ throw new Error(`${message}: ${String(value)}`);
373
+ }
374
+ if (!Number.isFinite(value)) {
375
+ throw new Error(`Value must be a finite number: ${value}`);
376
+ }
377
+ }
378
+ function toBigInt(value) {
371
379
  if (typeof value === "bigint") {
372
380
  if (value < 0n) {
373
- throw new Error(`${fieldName} must be non-negative`);
381
+ throw new Error(`Value must be non-negative: ${value}`);
374
382
  }
375
383
  return value;
376
384
  }
377
- if (!Number.isFinite(value) || value < 0) {
378
- throw new Error(`${fieldName} must be a finite non-negative number`);
385
+ isFiniteNumber(value, "Value must be a bigint or number");
386
+ if (value < 0) {
387
+ throw new Error(`Value must be a finite non-negative number: ${value}`);
379
388
  }
380
389
  return BigInt(Math.trunc(value));
381
390
  }
382
- function toU8Number(value, fieldName) {
383
- if (!Number.isInteger(value) || value < 0 || value > 255) {
384
- throw new Error(`${fieldName} must be an integer between 0 and 255`);
391
+ function toU8(value) {
392
+ isFiniteNumber(value, "Value must be a number");
393
+ if (!Number.isInteger(value)) {
394
+ throw new Error(`Value must be an integer: ${value}`);
395
+ }
396
+ if (value < 0 || value > 255) {
397
+ throw new Error(`Value must be an integer between 0 and 255: ${value}`);
385
398
  }
386
399
  return value;
387
400
  }
@@ -400,20 +413,18 @@ var Float = new MoveStruct({ name: `${$moduleName2}::Float`, fields: {
400
413
  function createBaseGameTransaction({
401
414
  config,
402
415
  game,
403
- owner,
404
- sender,
416
+ playerAddress,
405
417
  gasBudget
406
418
  }) {
407
419
  assertConfiguredBetGame(config, game);
408
420
  const tx = new transactions.Transaction();
409
- tx.setSenderIfNotSet(utils.normalizeSuiAddress(sender ?? owner));
421
+ tx.setSenderIfNotSet(utils.normalizeSuiAddress(playerAddress));
410
422
  tx.setGasBudgetIfNotSet(gasBudget ?? DEFAULT_GAS_BUDGET_MIST);
411
423
  return tx;
412
424
  }
413
425
  function buildSharedStandardGameBetCall({
414
426
  config,
415
- owner,
416
- sender,
427
+ playerAddress,
417
428
  coinType,
418
429
  stake,
419
430
  cashStake,
@@ -424,11 +435,11 @@ function buildSharedStandardGameBetCall({
424
435
  buildRewardCoin
425
436
  }) {
426
437
  return (tx) => {
427
- const normalizedOwner = utils.normalizeSuiAddress(sender ?? owner);
438
+ const normalizedPlayerAddress = utils.normalizeSuiAddress(playerAddress);
428
439
  const normalizedCoinType = utils.normalizeStructTag(coinType);
429
- const resolvedStake = toBigIntAmount(stake, "stake");
430
- const resolvedCashStake = toBigIntAmount(cashStake ?? stake, "cashStake");
431
- const resolvedBetCount = toBigIntAmount(betCount ?? 1, "betCount");
440
+ const resolvedStake = toBigInt(stake);
441
+ const resolvedCashStake = toBigInt(cashStake ?? stake);
442
+ const resolvedBetCount = toBigInt(betCount ?? 1);
432
443
  const encodedMetadata = encodeBetMetadata(metadata, partner);
433
444
  const priceInfoObjectId = resolvePriceInfoObjectId(
434
445
  config,
@@ -442,7 +453,7 @@ function buildSharedStandardGameBetCall({
442
453
  const rewardCoin = buildRewardCoin({
443
454
  tx,
444
455
  config,
445
- owner: normalizedOwner,
456
+ playerAddress: normalizedPlayerAddress,
446
457
  coinType: normalizedCoinType,
447
458
  stake: resolvedStake,
448
459
  cashStake: resolvedCashStake,
@@ -451,7 +462,7 @@ function buildSharedStandardGameBetCall({
451
462
  priceInfoObjectId,
452
463
  betCoin
453
464
  });
454
- tx.transferObjects([rewardCoin], tx.pure.address(normalizedOwner));
465
+ tx.transferObjects([rewardCoin], tx.pure.address(normalizedPlayerAddress));
455
466
  return rewardCoin;
456
467
  };
457
468
  }
@@ -577,7 +588,7 @@ function play3(options) {
577
588
 
578
589
  // src/transactions/plinko.ts
579
590
  function buildPlinkoTransaction(options) {
580
- const configId = toU8Number(options.configId, "configId");
591
+ const configId = toU8(options.configId);
581
592
  return buildSharedStandardGameBetTransaction({
582
593
  ...options,
583
594
  game: "plinko",
@@ -737,7 +748,7 @@ function buildPvPCoinflipTransaction(action, options) {
737
748
  switch (action) {
738
749
  case "create": {
739
750
  const createOptions = options;
740
- const stake = toBigIntAmount(createOptions.stake, "stake");
751
+ const stake = toBigInt(createOptions.stake);
741
752
  const betCoin = tx.coin({
742
753
  type: normalizedCoinType,
743
754
  balance: stake,
@@ -888,7 +899,7 @@ function play5(options) {
888
899
 
889
900
  // src/transactions/wheel.ts
890
901
  function buildWheelTransaction(options) {
891
- const configId = toU8Number(options.configId, "configId");
902
+ const configId = toU8(options.configId);
892
903
  return buildSharedStandardGameBetTransaction({
893
904
  ...options,
894
905
  game: "wheel",
@@ -1006,39 +1017,53 @@ var SuigarClient = class {
1006
1017
  * Lists unresolved PvP coinflip games from the configured registry and resolves
1007
1018
  * each entry into parsed onchain game state.
1008
1019
  *
1009
- * This fetches dynamic fields from the PvP coinflip registry object, then loads
1010
- * each referenced game object through `resolvePvPConflipGame()`. Registry
1020
+ * This fetches dynamic fields from the PvP coinflip registry object, then bulk
1021
+ * loads the referenced game objects through `client.core.getObjects()`. Registry
1011
1022
  * membership is the unresolved-state signal: when a game is joined and resolved,
1012
1023
  * the Move flow removes it from the registry and deletes the live `Game` object.
1013
1024
  * Use this when a product needs the current set of open PvP coinflip matches for
1014
1025
  * browsing or lobby views.
1015
1026
  *
1016
1027
  * @param options Optional dynamic field pagination forwarded to `listDynamicFields()`, excluding `parentId`.
1017
- * Pass `throwOnError: true` to fail the whole lookup when any referenced game
1018
- * cannot be resolved. By default, failed game resolutions are skipped and only
1019
- * successfully parsed unresolved games are returned.
1028
+ * Supported options such as `limit`, `cursor`, and `signal` are forwarded to the
1029
+ * underlying lookup calls. Pass `throwOnError: true` to fail the whole lookup
1030
+ * when any referenced game object cannot be fetched or parsed. By default,
1031
+ * failed per-object lookups are skipped and only successfully parsed unresolved
1032
+ * games are returned.
1020
1033
  * @returns Parsed unresolved PvP coinflip game objects for the requested
1021
- * registry page. When `throwOnError` is `false`, entries that fail
1022
- * `resolvePvPConflipGame()` are omitted from the returned array.
1034
+ * registry page. When `throwOnError` is `false`, entries that fail object fetch
1035
+ * or parse are omitted from the returned array.
1023
1036
  */
1024
1037
  async getPvPCoinflipGames(options = {
1025
1038
  limit: 50
1026
1039
  }) {
1027
1040
  const { throwOnError = false, ...listOptions } = options;
1028
1041
  const { dynamicFields } = await this.#client.core.listDynamicFields({
1029
- parentId: this.#config.registryIds.pvpCoinflip,
1030
- ...listOptions
1042
+ ...listOptions,
1043
+ parentId: this.#config.registryIds.pvpCoinflip
1044
+ });
1045
+ const { objects } = await this.#client.core.getObjects({
1046
+ objectIds: dynamicFields.map(({ childId }) => childId),
1047
+ signal: listOptions.signal,
1048
+ include: {
1049
+ content: true
1050
+ }
1051
+ });
1052
+ const resolvedGames = objects.map((object) => {
1053
+ try {
1054
+ return this.#resolvePvPCoinflipGameObject(object);
1055
+ } catch (error) {
1056
+ return error instanceof Error ? error : new Error(String(error));
1057
+ }
1031
1058
  });
1032
1059
  if (throwOnError) {
1033
- return Promise.all(
1034
- dynamicFields.map(({ childId }) => this.resolvePvPConflipGame(childId))
1035
- );
1060
+ const firstError = resolvedGames.find((game) => game instanceof Error);
1061
+ if (firstError) {
1062
+ throw firstError;
1063
+ }
1036
1064
  }
1037
- const settledGames = await Promise.allSettled(
1038
- dynamicFields.map(({ childId }) => this.resolvePvPConflipGame(childId))
1039
- );
1040
- return settledGames.flatMap(
1041
- (result) => result.status === "fulfilled" ? [result.value] : []
1065
+ return resolvedGames.flatMap(
1066
+ (game) => game instanceof Error ? [] : [game]
1042
1067
  );
1043
1068
  }
1044
1069
  /**
@@ -1052,21 +1077,19 @@ var SuigarClient = class {
1052
1077
  * of a specific PvP coinflip match before rendering join, cancel, or result UI.
1053
1078
  *
1054
1079
  * @param gameId On-chain object id of the PvP coinflip game.
1080
+ * @param options Optional `getObject()` options forwarded to the underlying
1081
+ * client lookup, excluding `objectId` and `include`. Supported options include
1082
+ * `signal`.
1055
1083
  * @returns Parsed PvP coinflip game state with a normalized `coinType`.
1056
1084
  * @throws Error If the object cannot be decoded because no content was returned.
1057
1085
  */
1058
- async resolvePvPConflipGame(gameId) {
1086
+ async resolvePvPConflipGame(gameId, options = {}) {
1059
1087
  const { object } = await this.#client.core.getObject({
1088
+ ...options,
1060
1089
  objectId: gameId,
1061
1090
  include: { content: true }
1062
1091
  });
1063
- if (!object.content) {
1064
- throw new Error("Unable to resolve PvP coinflip from game object");
1065
- }
1066
- return {
1067
- ...Game.parse(object.content),
1068
- coinType: utils.normalizeStructTag(utils.parseStructTag(object.type).typeParams[0])
1069
- };
1092
+ return this.#resolvePvPCoinflipGameObject(object);
1070
1093
  }
1071
1094
  /**
1072
1095
  * BCS struct constructors for decoding on-chain objects and events related to Suigar games.
@@ -1092,15 +1115,15 @@ var SuigarClient = class {
1092
1115
  /**
1093
1116
  * Event emitted when a PvP Coinflip game is created, containing the game configuration and initial state.
1094
1117
  */
1095
- PvPCoinflipGameCreated: GameCreatedEvent,
1118
+ PvPCoinflipGameCreatedEvent: GameCreatedEvent,
1096
1119
  /**
1097
1120
  * Event emitted when a PvP Coinflip game is resolved, containing the final outcome.
1098
1121
  */
1099
- PvPCoinflipGameResolved: GameResolvedEvent,
1122
+ PvPCoinflipGameResolvedEvent: GameResolvedEvent,
1100
1123
  /**
1101
1124
  * Event emitted when a PvP Coinflip game is cancelled.
1102
1125
  */
1103
- PvPCoinflipGameCancelled: GameCancelledEvent
1126
+ PvPCoinflipGameCancelledEvent: GameCancelledEvent
1104
1127
  };
1105
1128
  /**
1106
1129
  * Transaction builders for Suigar games.
@@ -1196,6 +1219,20 @@ var SuigarClient = class {
1196
1219
  });
1197
1220
  };
1198
1221
  }
1222
+ #resolvePvPCoinflipGameObject(object) {
1223
+ if (object instanceof Error) {
1224
+ throw object;
1225
+ }
1226
+ if (!object.content) {
1227
+ throw new Error(
1228
+ "Unable to resolve PvP coinflip game from retrieved object"
1229
+ );
1230
+ }
1231
+ return {
1232
+ ...Game.parse(object.content),
1233
+ coinType: utils.normalizeStructTag(utils.parseStructTag(object.type).typeParams[0])
1234
+ };
1235
+ }
1199
1236
  };
1200
1237
 
1201
1238
  exports.SuigarClient = SuigarClient;
package/dist/index.d.cts CHANGED
@@ -2,7 +2,7 @@ import { M as MoveStruct } from './index-jwSXA8q3.cjs';
2
2
  import * as _mysten_bcs from '@mysten/bcs';
3
3
  import { ClientWithCoreApi, SuiClientTypes } from '@mysten/sui/client';
4
4
  import { Transaction, BuildTransactionOptions } from '@mysten/sui/transactions';
5
- import { S as StandardGame, B as BuildCoinflipTransactionOptions, a as BuildWheelTransactionOptions, b as BuildLimboTransactionOptions, c as BuildPlinkoTransactionOptions, d as BuildRangeTransactionOptions, e as SuigarConfig, W as WithThrowOnError, P as PvPCoinflipAction, f as BuildPvPCoinflipTransactionOptions, g as SuigarExtensionOptions } from './games--Haw_z7M.cjs';
5
+ import { S as StandardGame, B as BuildCoinflipTransactionOptions, a as BuildWheelTransactionOptions, b as BuildLimboTransactionOptions, c as BuildPlinkoTransactionOptions, d as BuildRangeTransactionOptions, e as SuigarConfig, W as WithThrowOnError, P as PvPCoinflipAction, f as BuildPvPCoinflipTransactionOptions, g as SuigarExtensionOptions } from './games-BccpPyWd.cjs';
6
6
  import '@mysten/sui/bcs';
7
7
 
8
8
  type WithoutConfig<T> = Omit<T, 'config'>;
@@ -44,20 +44,22 @@ declare class SuigarClient {
44
44
  * Lists unresolved PvP coinflip games from the configured registry and resolves
45
45
  * each entry into parsed onchain game state.
46
46
  *
47
- * This fetches dynamic fields from the PvP coinflip registry object, then loads
48
- * each referenced game object through `resolvePvPConflipGame()`. Registry
47
+ * This fetches dynamic fields from the PvP coinflip registry object, then bulk
48
+ * loads the referenced game objects through `client.core.getObjects()`. Registry
49
49
  * membership is the unresolved-state signal: when a game is joined and resolved,
50
50
  * the Move flow removes it from the registry and deletes the live `Game` object.
51
51
  * Use this when a product needs the current set of open PvP coinflip matches for
52
52
  * browsing or lobby views.
53
53
  *
54
54
  * @param options Optional dynamic field pagination forwarded to `listDynamicFields()`, excluding `parentId`.
55
- * Pass `throwOnError: true` to fail the whole lookup when any referenced game
56
- * cannot be resolved. By default, failed game resolutions are skipped and only
57
- * successfully parsed unresolved games are returned.
55
+ * Supported options such as `limit`, `cursor`, and `signal` are forwarded to the
56
+ * underlying lookup calls. Pass `throwOnError: true` to fail the whole lookup
57
+ * when any referenced game object cannot be fetched or parsed. By default,
58
+ * failed per-object lookups are skipped and only successfully parsed unresolved
59
+ * games are returned.
58
60
  * @returns Parsed unresolved PvP coinflip game objects for the requested
59
- * registry page. When `throwOnError` is `false`, entries that fail
60
- * `resolvePvPConflipGame()` are omitted from the returned array.
61
+ * registry page. When `throwOnError` is `false`, entries that fail object fetch
62
+ * or parse are omitted from the returned array.
61
63
  */
62
64
  getPvPCoinflipGames(options?: WithThrowOnError<Omit<SuiClientTypes.ListDynamicFieldsOptions, 'parentId'>>): Promise<{
63
65
  coinType: string;
@@ -90,10 +92,13 @@ declare class SuigarClient {
90
92
  * of a specific PvP coinflip match before rendering join, cancel, or result UI.
91
93
  *
92
94
  * @param gameId On-chain object id of the PvP coinflip game.
95
+ * @param options Optional `getObject()` options forwarded to the underlying
96
+ * client lookup, excluding `objectId` and `include`. Supported options include
97
+ * `signal`.
93
98
  * @returns Parsed PvP coinflip game state with a normalized `coinType`.
94
99
  * @throws Error If the object cannot be decoded because no content was returned.
95
100
  */
96
- resolvePvPConflipGame(gameId: string): Promise<{
101
+ resolvePvPConflipGame(gameId: string, options?: Omit<SuiClientTypes.GetObjectOptions, 'objectId' | 'include'>): Promise<{
97
102
  coinType: string;
98
103
  id: string;
99
104
  creator: string;
@@ -207,7 +212,7 @@ declare class SuigarClient {
207
212
  /**
208
213
  * Event emitted when a PvP Coinflip game is created, containing the game configuration and initial state.
209
214
  */
210
- PvPCoinflipGameCreated: MoveStruct<{
215
+ PvPCoinflipGameCreatedEvent: MoveStruct<{
211
216
  game_id: _mysten_bcs.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
212
217
  creator: _mysten_bcs.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
213
218
  creator_is_tails: _mysten_bcs.BcsType<boolean, boolean, "bool">;
@@ -222,7 +227,7 @@ declare class SuigarClient {
222
227
  /**
223
228
  * Event emitted when a PvP Coinflip game is resolved, containing the final outcome.
224
229
  */
225
- PvPCoinflipGameResolved: MoveStruct<{
230
+ PvPCoinflipGameResolvedEvent: MoveStruct<{
226
231
  game_id: _mysten_bcs.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
227
232
  creator: _mysten_bcs.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
228
233
  joiner: _mysten_bcs.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
@@ -241,7 +246,7 @@ declare class SuigarClient {
241
246
  /**
242
247
  * Event emitted when a PvP Coinflip game is cancelled.
243
248
  */
244
- PvPCoinflipGameCancelled: MoveStruct<{
249
+ PvPCoinflipGameCancelledEvent: MoveStruct<{
245
250
  game_id: _mysten_bcs.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
246
251
  creator: _mysten_bcs.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
247
252
  creator_is_tails: _mysten_bcs.BcsType<boolean, boolean, "bool">;
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import { M as MoveStruct } from './index-jwSXA8q3.js';
2
2
  import * as _mysten_bcs from '@mysten/bcs';
3
3
  import { ClientWithCoreApi, SuiClientTypes } from '@mysten/sui/client';
4
4
  import { Transaction, BuildTransactionOptions } from '@mysten/sui/transactions';
5
- import { S as StandardGame, B as BuildCoinflipTransactionOptions, a as BuildWheelTransactionOptions, b as BuildLimboTransactionOptions, c as BuildPlinkoTransactionOptions, d as BuildRangeTransactionOptions, e as SuigarConfig, W as WithThrowOnError, P as PvPCoinflipAction, f as BuildPvPCoinflipTransactionOptions, g as SuigarExtensionOptions } from './games--Haw_z7M.js';
5
+ import { S as StandardGame, B as BuildCoinflipTransactionOptions, a as BuildWheelTransactionOptions, b as BuildLimboTransactionOptions, c as BuildPlinkoTransactionOptions, d as BuildRangeTransactionOptions, e as SuigarConfig, W as WithThrowOnError, P as PvPCoinflipAction, f as BuildPvPCoinflipTransactionOptions, g as SuigarExtensionOptions } from './games-BccpPyWd.js';
6
6
  import '@mysten/sui/bcs';
7
7
 
8
8
  type WithoutConfig<T> = Omit<T, 'config'>;
@@ -44,20 +44,22 @@ declare class SuigarClient {
44
44
  * Lists unresolved PvP coinflip games from the configured registry and resolves
45
45
  * each entry into parsed onchain game state.
46
46
  *
47
- * This fetches dynamic fields from the PvP coinflip registry object, then loads
48
- * each referenced game object through `resolvePvPConflipGame()`. Registry
47
+ * This fetches dynamic fields from the PvP coinflip registry object, then bulk
48
+ * loads the referenced game objects through `client.core.getObjects()`. Registry
49
49
  * membership is the unresolved-state signal: when a game is joined and resolved,
50
50
  * the Move flow removes it from the registry and deletes the live `Game` object.
51
51
  * Use this when a product needs the current set of open PvP coinflip matches for
52
52
  * browsing or lobby views.
53
53
  *
54
54
  * @param options Optional dynamic field pagination forwarded to `listDynamicFields()`, excluding `parentId`.
55
- * Pass `throwOnError: true` to fail the whole lookup when any referenced game
56
- * cannot be resolved. By default, failed game resolutions are skipped and only
57
- * successfully parsed unresolved games are returned.
55
+ * Supported options such as `limit`, `cursor`, and `signal` are forwarded to the
56
+ * underlying lookup calls. Pass `throwOnError: true` to fail the whole lookup
57
+ * when any referenced game object cannot be fetched or parsed. By default,
58
+ * failed per-object lookups are skipped and only successfully parsed unresolved
59
+ * games are returned.
58
60
  * @returns Parsed unresolved PvP coinflip game objects for the requested
59
- * registry page. When `throwOnError` is `false`, entries that fail
60
- * `resolvePvPConflipGame()` are omitted from the returned array.
61
+ * registry page. When `throwOnError` is `false`, entries that fail object fetch
62
+ * or parse are omitted from the returned array.
61
63
  */
62
64
  getPvPCoinflipGames(options?: WithThrowOnError<Omit<SuiClientTypes.ListDynamicFieldsOptions, 'parentId'>>): Promise<{
63
65
  coinType: string;
@@ -90,10 +92,13 @@ declare class SuigarClient {
90
92
  * of a specific PvP coinflip match before rendering join, cancel, or result UI.
91
93
  *
92
94
  * @param gameId On-chain object id of the PvP coinflip game.
95
+ * @param options Optional `getObject()` options forwarded to the underlying
96
+ * client lookup, excluding `objectId` and `include`. Supported options include
97
+ * `signal`.
93
98
  * @returns Parsed PvP coinflip game state with a normalized `coinType`.
94
99
  * @throws Error If the object cannot be decoded because no content was returned.
95
100
  */
96
- resolvePvPConflipGame(gameId: string): Promise<{
101
+ resolvePvPConflipGame(gameId: string, options?: Omit<SuiClientTypes.GetObjectOptions, 'objectId' | 'include'>): Promise<{
97
102
  coinType: string;
98
103
  id: string;
99
104
  creator: string;
@@ -207,7 +212,7 @@ declare class SuigarClient {
207
212
  /**
208
213
  * Event emitted when a PvP Coinflip game is created, containing the game configuration and initial state.
209
214
  */
210
- PvPCoinflipGameCreated: MoveStruct<{
215
+ PvPCoinflipGameCreatedEvent: MoveStruct<{
211
216
  game_id: _mysten_bcs.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
212
217
  creator: _mysten_bcs.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
213
218
  creator_is_tails: _mysten_bcs.BcsType<boolean, boolean, "bool">;
@@ -222,7 +227,7 @@ declare class SuigarClient {
222
227
  /**
223
228
  * Event emitted when a PvP Coinflip game is resolved, containing the final outcome.
224
229
  */
225
- PvPCoinflipGameResolved: MoveStruct<{
230
+ PvPCoinflipGameResolvedEvent: MoveStruct<{
226
231
  game_id: _mysten_bcs.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
227
232
  creator: _mysten_bcs.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
228
233
  joiner: _mysten_bcs.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
@@ -241,7 +246,7 @@ declare class SuigarClient {
241
246
  /**
242
247
  * Event emitted when a PvP Coinflip game is cancelled.
243
248
  */
244
- PvPCoinflipGameCancelled: MoveStruct<{
249
+ PvPCoinflipGameCancelledEvent: MoveStruct<{
245
250
  game_id: _mysten_bcs.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
246
251
  creator: _mysten_bcs.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
247
252
  creator_is_tails: _mysten_bcs.BcsType<boolean, boolean, "bool">;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { MoveStruct, Float, toBigIntAmount, toU8Number, DEFAULT_GAS_BUDGET_MIST, normalizeMoveArguments, DEFAULT_LIMBO_MULTIPLIER_SCALE, DEFAULT_RANGE_SCALE } from './chunk-W3WZ2BHO.js';
1
+ import { MoveStruct, Float, toBigInt, toU8, DEFAULT_GAS_BUDGET_MIST, normalizeMoveArguments, DEFAULT_LIMBO_MULTIPLIER_SCALE, DEFAULT_RANGE_SCALE } from './chunk-YGYMLRE4.js';
2
2
  import { toBase64, normalizeStructTag, parseStructTag, normalizeSuiAddress, isValidSuiAddress } from '@mysten/sui/utils';
3
3
  import { Transaction } from '@mysten/sui/transactions';
4
4
  import { bcs } from '@mysten/sui/bcs';
@@ -225,20 +225,18 @@ function play(options) {
225
225
  function createBaseGameTransaction({
226
226
  config,
227
227
  game,
228
- owner,
229
- sender,
228
+ playerAddress,
230
229
  gasBudget
231
230
  }) {
232
231
  assertConfiguredBetGame(config, game);
233
232
  const tx = new Transaction();
234
- tx.setSenderIfNotSet(normalizeSuiAddress(sender ?? owner));
233
+ tx.setSenderIfNotSet(normalizeSuiAddress(playerAddress));
235
234
  tx.setGasBudgetIfNotSet(gasBudget ?? DEFAULT_GAS_BUDGET_MIST);
236
235
  return tx;
237
236
  }
238
237
  function buildSharedStandardGameBetCall({
239
238
  config,
240
- owner,
241
- sender,
239
+ playerAddress,
242
240
  coinType,
243
241
  stake,
244
242
  cashStake,
@@ -249,11 +247,11 @@ function buildSharedStandardGameBetCall({
249
247
  buildRewardCoin
250
248
  }) {
251
249
  return (tx) => {
252
- const normalizedOwner = normalizeSuiAddress(sender ?? owner);
250
+ const normalizedPlayerAddress = normalizeSuiAddress(playerAddress);
253
251
  const normalizedCoinType = normalizeStructTag(coinType);
254
- const resolvedStake = toBigIntAmount(stake, "stake");
255
- const resolvedCashStake = toBigIntAmount(cashStake ?? stake, "cashStake");
256
- const resolvedBetCount = toBigIntAmount(betCount ?? 1, "betCount");
252
+ const resolvedStake = toBigInt(stake);
253
+ const resolvedCashStake = toBigInt(cashStake ?? stake);
254
+ const resolvedBetCount = toBigInt(betCount ?? 1);
257
255
  const encodedMetadata = encodeBetMetadata(metadata, partner);
258
256
  const priceInfoObjectId = resolvePriceInfoObjectId(
259
257
  config,
@@ -267,7 +265,7 @@ function buildSharedStandardGameBetCall({
267
265
  const rewardCoin = buildRewardCoin({
268
266
  tx,
269
267
  config,
270
- owner: normalizedOwner,
268
+ playerAddress: normalizedPlayerAddress,
271
269
  coinType: normalizedCoinType,
272
270
  stake: resolvedStake,
273
271
  cashStake: resolvedCashStake,
@@ -276,7 +274,7 @@ function buildSharedStandardGameBetCall({
276
274
  priceInfoObjectId,
277
275
  betCoin
278
276
  });
279
- tx.transferObjects([rewardCoin], tx.pure.address(normalizedOwner));
277
+ tx.transferObjects([rewardCoin], tx.pure.address(normalizedPlayerAddress));
280
278
  return rewardCoin;
281
279
  };
282
280
  }
@@ -402,7 +400,7 @@ function play3(options) {
402
400
 
403
401
  // src/transactions/plinko.ts
404
402
  function buildPlinkoTransaction(options) {
405
- const configId = toU8Number(options.configId, "configId");
403
+ const configId = toU8(options.configId);
406
404
  return buildSharedStandardGameBetTransaction({
407
405
  ...options,
408
406
  game: "plinko",
@@ -562,7 +560,7 @@ function buildPvPCoinflipTransaction(action, options) {
562
560
  switch (action) {
563
561
  case "create": {
564
562
  const createOptions = options;
565
- const stake = toBigIntAmount(createOptions.stake, "stake");
563
+ const stake = toBigInt(createOptions.stake);
566
564
  const betCoin = tx.coin({
567
565
  type: normalizedCoinType,
568
566
  balance: stake,
@@ -713,7 +711,7 @@ function play5(options) {
713
711
 
714
712
  // src/transactions/wheel.ts
715
713
  function buildWheelTransaction(options) {
716
- const configId = toU8Number(options.configId, "configId");
714
+ const configId = toU8(options.configId);
717
715
  return buildSharedStandardGameBetTransaction({
718
716
  ...options,
719
717
  game: "wheel",
@@ -831,39 +829,53 @@ var SuigarClient = class {
831
829
  * Lists unresolved PvP coinflip games from the configured registry and resolves
832
830
  * each entry into parsed onchain game state.
833
831
  *
834
- * This fetches dynamic fields from the PvP coinflip registry object, then loads
835
- * each referenced game object through `resolvePvPConflipGame()`. Registry
832
+ * This fetches dynamic fields from the PvP coinflip registry object, then bulk
833
+ * loads the referenced game objects through `client.core.getObjects()`. Registry
836
834
  * membership is the unresolved-state signal: when a game is joined and resolved,
837
835
  * the Move flow removes it from the registry and deletes the live `Game` object.
838
836
  * Use this when a product needs the current set of open PvP coinflip matches for
839
837
  * browsing or lobby views.
840
838
  *
841
839
  * @param options Optional dynamic field pagination forwarded to `listDynamicFields()`, excluding `parentId`.
842
- * Pass `throwOnError: true` to fail the whole lookup when any referenced game
843
- * cannot be resolved. By default, failed game resolutions are skipped and only
844
- * successfully parsed unresolved games are returned.
840
+ * Supported options such as `limit`, `cursor`, and `signal` are forwarded to the
841
+ * underlying lookup calls. Pass `throwOnError: true` to fail the whole lookup
842
+ * when any referenced game object cannot be fetched or parsed. By default,
843
+ * failed per-object lookups are skipped and only successfully parsed unresolved
844
+ * games are returned.
845
845
  * @returns Parsed unresolved PvP coinflip game objects for the requested
846
- * registry page. When `throwOnError` is `false`, entries that fail
847
- * `resolvePvPConflipGame()` are omitted from the returned array.
846
+ * registry page. When `throwOnError` is `false`, entries that fail object fetch
847
+ * or parse are omitted from the returned array.
848
848
  */
849
849
  async getPvPCoinflipGames(options = {
850
850
  limit: 50
851
851
  }) {
852
852
  const { throwOnError = false, ...listOptions } = options;
853
853
  const { dynamicFields } = await this.#client.core.listDynamicFields({
854
- parentId: this.#config.registryIds.pvpCoinflip,
855
- ...listOptions
854
+ ...listOptions,
855
+ parentId: this.#config.registryIds.pvpCoinflip
856
+ });
857
+ const { objects } = await this.#client.core.getObjects({
858
+ objectIds: dynamicFields.map(({ childId }) => childId),
859
+ signal: listOptions.signal,
860
+ include: {
861
+ content: true
862
+ }
863
+ });
864
+ const resolvedGames = objects.map((object) => {
865
+ try {
866
+ return this.#resolvePvPCoinflipGameObject(object);
867
+ } catch (error) {
868
+ return error instanceof Error ? error : new Error(String(error));
869
+ }
856
870
  });
857
871
  if (throwOnError) {
858
- return Promise.all(
859
- dynamicFields.map(({ childId }) => this.resolvePvPConflipGame(childId))
860
- );
872
+ const firstError = resolvedGames.find((game) => game instanceof Error);
873
+ if (firstError) {
874
+ throw firstError;
875
+ }
861
876
  }
862
- const settledGames = await Promise.allSettled(
863
- dynamicFields.map(({ childId }) => this.resolvePvPConflipGame(childId))
864
- );
865
- return settledGames.flatMap(
866
- (result) => result.status === "fulfilled" ? [result.value] : []
877
+ return resolvedGames.flatMap(
878
+ (game) => game instanceof Error ? [] : [game]
867
879
  );
868
880
  }
869
881
  /**
@@ -877,21 +889,19 @@ var SuigarClient = class {
877
889
  * of a specific PvP coinflip match before rendering join, cancel, or result UI.
878
890
  *
879
891
  * @param gameId On-chain object id of the PvP coinflip game.
892
+ * @param options Optional `getObject()` options forwarded to the underlying
893
+ * client lookup, excluding `objectId` and `include`. Supported options include
894
+ * `signal`.
880
895
  * @returns Parsed PvP coinflip game state with a normalized `coinType`.
881
896
  * @throws Error If the object cannot be decoded because no content was returned.
882
897
  */
883
- async resolvePvPConflipGame(gameId) {
898
+ async resolvePvPConflipGame(gameId, options = {}) {
884
899
  const { object } = await this.#client.core.getObject({
900
+ ...options,
885
901
  objectId: gameId,
886
902
  include: { content: true }
887
903
  });
888
- if (!object.content) {
889
- throw new Error("Unable to resolve PvP coinflip from game object");
890
- }
891
- return {
892
- ...Game.parse(object.content),
893
- coinType: normalizeStructTag(parseStructTag(object.type).typeParams[0])
894
- };
904
+ return this.#resolvePvPCoinflipGameObject(object);
895
905
  }
896
906
  /**
897
907
  * BCS struct constructors for decoding on-chain objects and events related to Suigar games.
@@ -917,15 +927,15 @@ var SuigarClient = class {
917
927
  /**
918
928
  * Event emitted when a PvP Coinflip game is created, containing the game configuration and initial state.
919
929
  */
920
- PvPCoinflipGameCreated: GameCreatedEvent,
930
+ PvPCoinflipGameCreatedEvent: GameCreatedEvent,
921
931
  /**
922
932
  * Event emitted when a PvP Coinflip game is resolved, containing the final outcome.
923
933
  */
924
- PvPCoinflipGameResolved: GameResolvedEvent,
934
+ PvPCoinflipGameResolvedEvent: GameResolvedEvent,
925
935
  /**
926
936
  * Event emitted when a PvP Coinflip game is cancelled.
927
937
  */
928
- PvPCoinflipGameCancelled: GameCancelledEvent
938
+ PvPCoinflipGameCancelledEvent: GameCancelledEvent
929
939
  };
930
940
  /**
931
941
  * Transaction builders for Suigar games.
@@ -1021,6 +1031,20 @@ var SuigarClient = class {
1021
1031
  });
1022
1032
  };
1023
1033
  }
1034
+ #resolvePvPCoinflipGameObject(object) {
1035
+ if (object instanceof Error) {
1036
+ throw object;
1037
+ }
1038
+ if (!object.content) {
1039
+ throw new Error(
1040
+ "Unable to resolve PvP coinflip game from retrieved object"
1041
+ );
1042
+ }
1043
+ return {
1044
+ ...Game.parse(object.content),
1045
+ coinType: normalizeStructTag(parseStructTag(object.type).typeParams[0])
1046
+ };
1047
+ }
1024
1048
  };
1025
1049
 
1026
1050
  export { SuigarClient, suigar };