@suigar/sdk 2.0.0-beta.10 → 2.0.0-beta.11

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,5 +1,15 @@
1
1
  # @suigar/sdk
2
2
 
3
+ ## 2.0.0-beta.11
4
+
5
+ ### Patch Changes
6
+
7
+ - c7685d2: Add `client.suigar.getGameParameters(game, options?)` for reading live onchain game parameter objects, such as min/max stake and game-specific config bounds, directly from SweetHouse settings.
8
+
9
+ The lookup first reads the selected game's settings object from SweetHouse, then reads that game's coin-specific `Parameters<T>` object, parses it with the correct return type for the requested game, and caches the result for SDK integrations that need to display or validate current game limits without repeatedly querying the same onchain objects.
10
+
11
+ This update also broadens the public numeric helpers in `@suigar/sdk/utils`: `toBigInt()` accepts booleans and non-negative integer strings in addition to numbers and `bigint`, `toU8()` accepts plain integer strings such as `'1'` for parsed config ids and other `u8` values, and `toU16()` provides the same validation pattern for `u16` values.
12
+
3
13
  ## 2.0.0-beta.10
4
14
 
5
15
  ### Patch Changes
package/README.md CHANGED
@@ -48,9 +48,26 @@ import {
48
48
  RANGE_POINT_LIMIT,
49
49
  toBigInt,
50
50
  toU8,
51
+ toU16,
51
52
  } from '@suigar/sdk/utils';
52
53
  ```
53
54
 
55
+ Numeric helper behavior:
56
+
57
+ - `toBigInt(value)` accepts `bigint`, finite `number`, non-negative integer
58
+ `string`, and `boolean` inputs and returns a normalized non-negative `bigint`
59
+ - `toU8(value)` accepts a finite integer `number` or plain integer `string` in
60
+ the inclusive `0..255` range and rejects booleans or fractional values
61
+ - `toU16(value)` accepts a finite integer `number` or plain integer `string`
62
+ in the inclusive `0..65535` range and rejects booleans or fractional values
63
+ - `fromMoveI64(value)` converts a generated Move `i64` wrapper into a
64
+ JavaScript `number`
65
+ - `fromMoveFloat(value)` converts a generated Move float struct into a
66
+ JavaScript `number`
67
+ - `parseGameDetails(gameDetails)` decodes standard `BetResultEvent.game_details`
68
+ byte arrays into the expected string, number, and boolean values while
69
+ preserving the original onchain keys
70
+
54
71
  Game-specific type exports are available from the dedicated `games` subpath:
55
72
 
56
73
  ```ts
@@ -147,17 +164,22 @@ Supported override areas:
147
164
 
148
165
  - `name`
149
166
  - `partner`
167
+ - `cacheTtl`
150
168
 
151
169
  If `partner` is configured, the SDK automatically writes that partner wallet
152
170
  address into the onchain metadata vec-map. Transaction builder options may also
153
171
  include `metadata`, but reserved keys such as `partner` and `referrer` are
154
172
  ignored with a warning when provided manually.
155
173
 
174
+ `cacheTtl` controls the SDK cache for onchain reads such as parsed game
175
+ parameters. It is expressed in milliseconds and defaults to 30 minutes.
176
+
156
177
  ## Runtime Surface
157
178
 
158
179
  The registered extension instance exposes the main runtime surface:
159
180
 
160
181
  - `getConfig()`
182
+ - `getGameParameters(game, options?)`
161
183
  - `serializeTransactionToBase64(transaction, options?)`
162
184
  - `getPvPCoinflipGames(options?)`
163
185
  - `bcs`
@@ -182,6 +204,32 @@ const config = client.suigar.getConfig();
182
204
  console.log(config.packageIds);
183
205
  ```
184
206
 
207
+ ### `getGameParameters(game, options?)`
208
+
209
+ Returns the onchain `Parameters<T>` object for any supported game and coin type.
210
+ The return type is inferred from `game`.
211
+
212
+ The SDK first reads the selected game's settings object from the configured
213
+ SweetHouse object, then reads that game's coin-specific `Parameters<T>` object.
214
+ This is useful for displaying or validating current limits such as min/max
215
+ stake, house edge, or game-specific config bounds. The parsed result is cached
216
+ using the extension `cacheTtl`.
217
+
218
+ When a parameter field is a generated Move float struct, such as
219
+ `min_target_multiplier`, `max_target_multiplier`, `min_rtp`, or `max_rtp`, use
220
+ `fromMoveFloat()` before treating it as a normal JavaScript number.
221
+
222
+ ```ts
223
+ const parameters = await client.suigar.getGameParameters('coinflip', {
224
+ coinType: '0x2::sui::SUI',
225
+ });
226
+
227
+ console.log(parameters.min_stake);
228
+ ```
229
+
230
+ Pass `ignoreCache: true` to refresh the onchain read and replace the cached
231
+ value.
232
+
185
233
  ### `serializeTransactionToBase64(transaction, options?)`
186
234
 
187
235
  Builds a transaction with the configured Sui client and returns base64-encoded transaction bytes.
@@ -9,36 +9,46 @@ var RANGE_POINT_LIMIT = DEFAULT_RANGE_SCALE * 100;
9
9
  var DEFAULT_LIMBO_MULTIPLIER_SCALE = 100;
10
10
 
11
11
  // src/utils/numeric.ts
12
- function isFiniteNumber(value, message) {
13
- if (typeof value !== "number") {
14
- throw new Error(`${message}: ${String(value)}`);
15
- }
16
- if (!Number.isFinite(value)) {
17
- throw new Error(`Value must be a finite number: ${value}`);
12
+ function assertFiniteNumber(value, errorMessage) {
13
+ if (typeof value !== "number" || !Number.isFinite(value)) {
14
+ throw new TypeError(`${errorMessage}: ${String(value)}`);
18
15
  }
19
16
  }
20
17
  function toBigInt(value) {
21
- if (typeof value === "bigint") {
22
- if (value < 0n) {
23
- throw new Error(`Value must be non-negative: ${value}`);
18
+ let result;
19
+ try {
20
+ if (typeof value === "bigint" || typeof value === "string" || typeof value === "boolean") {
21
+ result = BigInt(value);
22
+ } else {
23
+ assertFiniteNumber(
24
+ value,
25
+ "Value must be a bigint, number, integer string, or boolean"
26
+ );
27
+ result = BigInt(Math.trunc(value));
24
28
  }
25
- return value;
29
+ } catch {
30
+ throw new TypeError(
31
+ `Value must be a bigint, number, integer string, or boolean: ${value}`
32
+ );
26
33
  }
27
- isFiniteNumber(value, "Value must be a bigint or number");
28
- if (value < 0) {
29
- throw new Error(`Value must be a finite non-negative number: ${value}`);
34
+ if (result < 0n) {
35
+ throw new RangeError(`Value must be non-negative: ${value}`);
30
36
  }
31
- return BigInt(Math.trunc(value));
37
+ return result;
32
38
  }
33
- function toU8(value) {
34
- isFiniteNumber(value, "Value must be a number");
35
- if (!Number.isInteger(value)) {
36
- throw new Error(`Value must be an integer: ${value}`);
37
- }
38
- if (value < 0 || value > 255) {
39
- throw new Error(`Value must be an integer between 0 and 255: ${value}`);
39
+ function toBoundedInt(value, max, typeName) {
40
+ const num = typeof value === "string" && value.trim() === "" ? NaN : Number(value);
41
+ assertFiniteNumber(num, "Value must be a finite number or integer string");
42
+ if (typeof value === "boolean" || value == null || !Number.isInteger(num) || num < 0 || num > max) {
43
+ throw new Error(`Value must be a ${typeName} integer (0-${max}): ${value}`);
40
44
  }
41
- return value;
45
+ return num;
46
+ }
47
+ function toU8(value) {
48
+ return toBoundedInt(value, 255, "u8");
49
+ }
50
+ function toU16(value) {
51
+ return toBoundedInt(value, 65535, "u16");
42
52
  }
43
53
  var MOVE_STDLIB_ADDRESS = normalizeSuiAddress("0x1");
44
54
  var SUI_FRAMEWORK_ADDRESS = normalizeSuiAddress("0x2");
@@ -328,4 +338,4 @@ function parseGameDetails(gameDetails) {
328
338
  }, {});
329
339
  }
330
340
 
331
- export { DEFAULT_GAS_BUDGET_MIST, DEFAULT_LIMBO_MULTIPLIER_SCALE, DEFAULT_RANGE_SCALE, Float, MoveStruct, RANGE_POINT_LIMIT, fromMoveFloat, fromMoveI64, normalizeMoveArguments, parseCoinType, parseGameDetails, toBigInt, toU8 };
341
+ export { DEFAULT_GAS_BUDGET_MIST, DEFAULT_LIMBO_MULTIPLIER_SCALE, DEFAULT_RANGE_SCALE, Float, MoveStruct, RANGE_POINT_LIMIT, fromMoveFloat, fromMoveI64, normalizeMoveArguments, parseCoinType, parseGameDetails, toBigInt, toU16, toU8 };
@@ -12,7 +12,19 @@ type BetMetadataInput = Record<string, BetMetadataValue | null | undefined>;
12
12
 
13
13
  interface SuigarExtensionOptions<Name = 'suigar'> {
14
14
  name?: Name;
15
+ /**
16
+ * Partner wallet address injected into bet metadata for attribution.
17
+ *
18
+ * Configure this once when registering the `suigar()` client extension
19
+ * instead of passing partner data through per-transaction metadata.
20
+ */
15
21
  partner?: string;
22
+ /**
23
+ * Cache TTL in milliseconds for SDK-managed on-chain config lookups.
24
+ *
25
+ * Defaults to 30 minutes.
26
+ */
27
+ cacheTtl?: number;
16
28
  }
17
29
  type SuigarCoin = 'sui' | 'usdc';
18
30
  type SuigarCoinTypes = Record<SuigarCoin, string>;
@@ -83,4 +95,4 @@ type BuildCancelPvPCoinflipTransactionOptions = SharedPvPCoinflipTransactionOpti
83
95
  };
84
96
  type BuildPvPCoinflipTransactionOptions<Action extends PvPCoinflipAction = PvPCoinflipAction> = Action extends 'create' ? BuildCreatePvPCoinflipTransactionOptions : Action extends 'join' ? BuildJoinPvPCoinflipTransactionOptions : Action extends 'cancel' ? BuildCancelPvPCoinflipTransactionOptions : never;
85
97
 
86
- export type { BuildCoinflipTransactionOptions as B, CoinSide as C, PvPCoinflipAction as P, StandardGame as S, WithThrowOnError as W, BuildWheelTransactionOptions as a, BuildLimboTransactionOptions as b, BuildPlinkoTransactionOptions as c, BuildRangeTransactionOptions as d, SuigarConfig as e, BuildPvPCoinflipTransactionOptions as f, SuigarExtensionOptions as g, BuildCancelPvPCoinflipTransactionOptions as h, BuildCreatePvPCoinflipTransactionOptions as i, BuildJoinPvPCoinflipTransactionOptions as j };
98
+ export type { BuildCoinflipTransactionOptions as B, CoinSide as C, Game as G, PvPCoinflipAction as P, StandardGame as S, WithThrowOnError as W, BuildWheelTransactionOptions as a, BuildLimboTransactionOptions as b, BuildPlinkoTransactionOptions as c, BuildRangeTransactionOptions as d, SuigarConfig as e, BuildPvPCoinflipTransactionOptions as f, SuigarExtensionOptions as g, BuildCancelPvPCoinflipTransactionOptions as h, BuildCreatePvPCoinflipTransactionOptions as i, BuildJoinPvPCoinflipTransactionOptions as j };
@@ -12,7 +12,19 @@ type BetMetadataInput = Record<string, BetMetadataValue | null | undefined>;
12
12
 
13
13
  interface SuigarExtensionOptions<Name = 'suigar'> {
14
14
  name?: Name;
15
+ /**
16
+ * Partner wallet address injected into bet metadata for attribution.
17
+ *
18
+ * Configure this once when registering the `suigar()` client extension
19
+ * instead of passing partner data through per-transaction metadata.
20
+ */
15
21
  partner?: string;
22
+ /**
23
+ * Cache TTL in milliseconds for SDK-managed on-chain config lookups.
24
+ *
25
+ * Defaults to 30 minutes.
26
+ */
27
+ cacheTtl?: number;
16
28
  }
17
29
  type SuigarCoin = 'sui' | 'usdc';
18
30
  type SuigarCoinTypes = Record<SuigarCoin, string>;
@@ -83,4 +95,4 @@ type BuildCancelPvPCoinflipTransactionOptions = SharedPvPCoinflipTransactionOpti
83
95
  };
84
96
  type BuildPvPCoinflipTransactionOptions<Action extends PvPCoinflipAction = PvPCoinflipAction> = Action extends 'create' ? BuildCreatePvPCoinflipTransactionOptions : Action extends 'join' ? BuildJoinPvPCoinflipTransactionOptions : Action extends 'cancel' ? BuildCancelPvPCoinflipTransactionOptions : never;
85
97
 
86
- export type { BuildCoinflipTransactionOptions as B, CoinSide as C, PvPCoinflipAction as P, StandardGame as S, WithThrowOnError as W, BuildWheelTransactionOptions as a, BuildLimboTransactionOptions as b, BuildPlinkoTransactionOptions as c, BuildRangeTransactionOptions as d, SuigarConfig as e, BuildPvPCoinflipTransactionOptions as f, SuigarExtensionOptions as g, BuildCancelPvPCoinflipTransactionOptions as h, BuildCreatePvPCoinflipTransactionOptions as i, BuildJoinPvPCoinflipTransactionOptions as j };
98
+ export type { BuildCoinflipTransactionOptions as B, CoinSide as C, Game as G, PvPCoinflipAction as P, StandardGame as S, WithThrowOnError as W, BuildWheelTransactionOptions as a, BuildLimboTransactionOptions as b, BuildPlinkoTransactionOptions as c, BuildRangeTransactionOptions as d, SuigarConfig as e, BuildPvPCoinflipTransactionOptions as f, SuigarExtensionOptions as g, BuildCancelPvPCoinflipTransactionOptions as h, BuildCreatePvPCoinflipTransactionOptions as i, BuildJoinPvPCoinflipTransactionOptions as j };
package/dist/games.d.cts CHANGED
@@ -1,2 +1,2 @@
1
- export { h as BuildCancelPvPCoinflipTransactionOptions, B as BuildCoinflipTransactionOptions, i as BuildCreatePvPCoinflipTransactionOptions, j as BuildJoinPvPCoinflipTransactionOptions, b as BuildLimboTransactionOptions, c as BuildPlinkoTransactionOptions, d as BuildRangeTransactionOptions, a as BuildWheelTransactionOptions, C as CoinSide, P as PvPCoinflipAction } from './games-BccpPyWd.cjs';
1
+ export { h as BuildCancelPvPCoinflipTransactionOptions, B as BuildCoinflipTransactionOptions, i as BuildCreatePvPCoinflipTransactionOptions, j as BuildJoinPvPCoinflipTransactionOptions, b as BuildLimboTransactionOptions, c as BuildPlinkoTransactionOptions, d as BuildRangeTransactionOptions, a as BuildWheelTransactionOptions, C as CoinSide, P as PvPCoinflipAction } from './games-BHYRg31e.cjs';
2
2
  import '@mysten/sui/transactions';
package/dist/games.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { h as BuildCancelPvPCoinflipTransactionOptions, B as BuildCoinflipTransactionOptions, i as BuildCreatePvPCoinflipTransactionOptions, j as BuildJoinPvPCoinflipTransactionOptions, b as BuildLimboTransactionOptions, c as BuildPlinkoTransactionOptions, d as BuildRangeTransactionOptions, a as BuildWheelTransactionOptions, C as CoinSide, P as PvPCoinflipAction } from './games-BccpPyWd.js';
1
+ export { h as BuildCancelPvPCoinflipTransactionOptions, B as BuildCoinflipTransactionOptions, i as BuildCreatePvPCoinflipTransactionOptions, j as BuildJoinPvPCoinflipTransactionOptions, b as BuildLimboTransactionOptions, c as BuildPlinkoTransactionOptions, d as BuildRangeTransactionOptions, a as BuildWheelTransactionOptions, C as CoinSide, P as PvPCoinflipAction } from './games-BHYRg31e.js';
2
2
  import '@mysten/sui/transactions';