@suigar/sdk 2.0.0-beta.11 → 2.0.0-beta.13
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 +20 -5
- package/README.md +32 -10
- package/dist/{chunk-TBJ5TYYE.js → chunk-7N55D2TV.js} +4 -2
- package/dist/index.cjs +46 -44
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +43 -43
- package/dist/utils.cjs +4 -2
- package/dist/utils.d.cts +2 -2
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,27 @@
|
|
|
1
1
|
# @suigar/sdk
|
|
2
2
|
|
|
3
|
+
## 2.0.0-beta.13
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 667d7c4: Normalize authored repository wording to use `on-chain` consistently.
|
|
8
|
+
|
|
9
|
+
## 2.0.0-beta.12
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 85ae057: Refine public validation failures to use `RangeError` and `TypeError` instead
|
|
14
|
+
of generic `Error` for unsupported networks, unsupported game or PvP action
|
|
15
|
+
inputs, unsupported configured coin types, bounded integer helpers, and
|
|
16
|
+
`parseCoinType()` parsing failures.
|
|
17
|
+
|
|
3
18
|
## 2.0.0-beta.11
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
6
21
|
|
|
7
|
-
- c7685d2: Add `client.suigar.getGameParameters(game, options?)` for reading live
|
|
22
|
+
- c7685d2: Add `client.suigar.getGameParameters(game, options?)` for reading live on-chain game parameter objects, such as min/max stake and game-specific config bounds, directly from SweetHouse settings.
|
|
8
23
|
|
|
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
|
|
24
|
+
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 on-chain objects.
|
|
10
25
|
|
|
11
26
|
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
27
|
|
|
@@ -14,7 +29,7 @@
|
|
|
14
29
|
|
|
15
30
|
### Patch Changes
|
|
16
31
|
|
|
17
|
-
- 4b59c7b: Remove the `client.suigar.
|
|
32
|
+
- 4b59c7b: Remove the `client.suigar.resolvePvPCoinflipGame()` client method. Use the exported generated helper `client.suigar.bcs.PvPCoinflipGame.get({ client, objectId })` for one specific live PvP coinflip game object instead.
|
|
18
33
|
|
|
19
34
|
Add `parseCoinType` to `@suigar/sdk/utils` for extracting normalized coin types from generic Move object type strings.
|
|
20
35
|
|
|
@@ -40,7 +55,7 @@
|
|
|
40
55
|
- a2aa324: Update PvP coinflip lookup helpers to use bulk object reads for unresolved lobby discovery and support forwarded lookup options.
|
|
41
56
|
- Make `getPvPCoinflipGames()` parse bulk `client.core.getObjects()` results instead of resolving each game individually.
|
|
42
57
|
- Skip per-object fetch or parse failures by default and continue supporting strict rejection with `throwOnError: true`.
|
|
43
|
-
- Forward supported lookup options such as `signal` through `getPvPCoinflipGames()` and `
|
|
58
|
+
- Forward supported lookup options such as `signal` through `getPvPCoinflipGames()` and `resolvePvPCoinflipGame(gameId, options?)`.
|
|
44
59
|
- Update tests, README guidance, and repo-local PvP skill documentation to match the current client behavior.
|
|
45
60
|
|
|
46
61
|
## 2.0.0-beta.7
|
|
@@ -85,7 +100,7 @@
|
|
|
85
100
|
|
|
86
101
|
Document the PvP coinflip runtime helpers more clearly by describing
|
|
87
102
|
registry-backed unresolved game discovery through `getPvPCoinflipGames()` and
|
|
88
|
-
the normalized live-game lookup behavior of `
|
|
103
|
+
the normalized live-game lookup behavior of `resolvePvPCoinflipGame()`.
|
|
89
104
|
|
|
90
105
|
- 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.
|
|
91
106
|
|
package/README.md
CHANGED
|
@@ -56,17 +56,24 @@ Numeric helper behavior:
|
|
|
56
56
|
|
|
57
57
|
- `toBigInt(value)` accepts `bigint`, finite `number`, non-negative integer
|
|
58
58
|
`string`, and `boolean` inputs and returns a normalized non-negative `bigint`
|
|
59
|
+
while throwing `TypeError` for invalid input shapes and `RangeError` for
|
|
60
|
+
negative values
|
|
59
61
|
- `toU8(value)` accepts a finite integer `number` or plain integer `string` in
|
|
60
|
-
the inclusive `0..255` range
|
|
62
|
+
the inclusive `0..255` range, throwing `TypeError` for non-numeric input and
|
|
63
|
+
`RangeError` for booleans, fractional values, or out-of-range integers
|
|
61
64
|
- `toU16(value)` accepts a finite integer `number` or plain integer `string`
|
|
62
|
-
in the inclusive `0..65535` range
|
|
65
|
+
in the inclusive `0..65535` range, throwing `TypeError` for non-numeric
|
|
66
|
+
input and `RangeError` for booleans, fractional values, or out-of-range
|
|
67
|
+
integers
|
|
63
68
|
- `fromMoveI64(value)` converts a generated Move `i64` wrapper into a
|
|
64
69
|
JavaScript `number`
|
|
65
70
|
- `fromMoveFloat(value)` converts a generated Move float struct into a
|
|
66
71
|
JavaScript `number`
|
|
72
|
+
- `parseCoinType(type)` extracts the normalized first generic coin type from a
|
|
73
|
+
Move object type string and throws `TypeError` when no coin type can be parsed
|
|
67
74
|
- `parseGameDetails(gameDetails)` decodes standard `BetResultEvent.game_details`
|
|
68
75
|
byte arrays into the expected string, number, and boolean values while
|
|
69
|
-
preserving the original
|
|
76
|
+
preserving the original on-chain keys
|
|
70
77
|
|
|
71
78
|
Game-specific type exports are available from the dedicated `games` subpath:
|
|
72
79
|
|
|
@@ -122,6 +129,9 @@ const base64 = await client.suigar.serializeTransactionToBase64(tx);
|
|
|
122
129
|
|
|
123
130
|
Creates a named Sui client extension. By default, it registers under `client.suigar`.
|
|
124
131
|
|
|
132
|
+
The extension constructor throws `RangeError` when the connected client network
|
|
133
|
+
is not one of the SDK's supported Sui networks.
|
|
134
|
+
|
|
125
135
|
### Partner Setup
|
|
126
136
|
|
|
127
137
|
> **Important:** `partner` is the partner wallet address. Configure it once
|
|
@@ -137,7 +147,7 @@ client.suigar;
|
|
|
137
147
|
```
|
|
138
148
|
|
|
139
149
|
Do not pass a partner slug, label, or display name here. Use the wallet
|
|
140
|
-
address that should receive partner attribution
|
|
150
|
+
address that should receive partner attribution on-chain.
|
|
141
151
|
|
|
142
152
|
You can rename the extension:
|
|
143
153
|
|
|
@@ -167,11 +177,11 @@ Supported override areas:
|
|
|
167
177
|
- `cacheTtl`
|
|
168
178
|
|
|
169
179
|
If `partner` is configured, the SDK automatically writes that partner wallet
|
|
170
|
-
address into the
|
|
180
|
+
address into the on-chain metadata vec-map. Transaction builder options may also
|
|
171
181
|
include `metadata`, but reserved keys such as `partner` and `referrer` are
|
|
172
182
|
ignored with a warning when provided manually.
|
|
173
183
|
|
|
174
|
-
`cacheTtl` controls the SDK cache for
|
|
184
|
+
`cacheTtl` controls the SDK cache for on-chain reads such as parsed game
|
|
175
185
|
parameters. It is expressed in milliseconds and defaults to 30 minutes.
|
|
176
186
|
|
|
177
187
|
## Runtime Surface
|
|
@@ -206,7 +216,7 @@ console.log(config.packageIds);
|
|
|
206
216
|
|
|
207
217
|
### `getGameParameters(game, options?)`
|
|
208
218
|
|
|
209
|
-
Returns the
|
|
219
|
+
Returns the on-chain `Parameters<T>` object for any supported game and coin type.
|
|
210
220
|
The return type is inferred from `game`.
|
|
211
221
|
|
|
212
222
|
The SDK first reads the selected game's settings object from the configured
|
|
@@ -227,7 +237,7 @@ const parameters = await client.suigar.getGameParameters('coinflip', {
|
|
|
227
237
|
console.log(parameters.min_stake);
|
|
228
238
|
```
|
|
229
239
|
|
|
230
|
-
Pass `ignoreCache: true` to refresh the
|
|
240
|
+
Pass `ignoreCache: true` to refresh the on-chain read and replace the cached
|
|
231
241
|
value.
|
|
232
242
|
|
|
233
243
|
### `serializeTransactionToBase64(transaction, options?)`
|
|
@@ -321,6 +331,12 @@ Shared behavior:
|
|
|
321
331
|
- the SDK resolves the price info object from the configured supported-coin mapping
|
|
322
332
|
- the reward object is transferred back to `playerAddress`
|
|
323
333
|
|
|
334
|
+
Error behavior:
|
|
335
|
+
|
|
336
|
+
- `RangeError` when `gameId` is unsupported
|
|
337
|
+
- `RangeError` when `coinType` is not in the resolved supported-coin config for the active network
|
|
338
|
+
- `RangeError` from bounded numeric helpers such as `toU8()` when `plinko` or `wheel` `configId` is out of range or not an integer
|
|
339
|
+
|
|
324
340
|
Per-game options:
|
|
325
341
|
|
|
326
342
|
- `coinflip`: `side: 'heads' | 'tails'`
|
|
@@ -352,7 +368,7 @@ const rangeTx = client.suigar.tx.createBetTransaction('range', {
|
|
|
352
368
|
> **Note:**
|
|
353
369
|
>
|
|
354
370
|
> - limbo converts `targetMultiplier` with `Math.round(targetMultiplier * scale)`
|
|
355
|
-
> - with the default limbo scale `100`, exposed as `DEFAULT_LIMBO_MULTIPLIER_SCALE`, a target multiplier of `2.5` becomes `250`
|
|
371
|
+
> - with the default limbo scale `100`, exposed as `DEFAULT_LIMBO_MULTIPLIER_SCALE`, a target multiplier of `2.5` becomes `250` on-chain
|
|
356
372
|
> - range converts each point with `Math.round(value * scale)`
|
|
357
373
|
> - range points are bounded by the contract limit exposed as `RANGE_POINT_LIMIT`
|
|
358
374
|
> - with the default range scale `1_000_000`, exposed as `DEFAULT_RANGE_SCALE`, valid UI values are `0` to `100`
|
|
@@ -420,6 +436,11 @@ Action-specific options:
|
|
|
420
436
|
- `join`: `gameId`
|
|
421
437
|
- `cancel`: `gameId`
|
|
422
438
|
|
|
439
|
+
Error behavior:
|
|
440
|
+
|
|
441
|
+
- `RangeError` when `action` is unsupported
|
|
442
|
+
- `RangeError` when `coinType` is not in the resolved supported-coin config for the active network
|
|
443
|
+
|
|
423
444
|
## `bcs`
|
|
424
445
|
|
|
425
446
|
BCS helpers live under `client.suigar.bcs`.
|
|
@@ -438,6 +459,7 @@ These are generated Move event decoders. Use them to parse Suigar event payloads
|
|
|
438
459
|
- `fromMoveI64(float.exp)` converts a generated Move `i64` exponent to a JavaScript number
|
|
439
460
|
- `fromMoveFloat(float)` converts a generated Move `Float` struct to a JavaScript number
|
|
440
461
|
- `parseCoinType(type)` extracts the normalized coin type from generic Move object type strings such as PvP coinflip `Game<T>`
|
|
462
|
+
and throws `TypeError` when the type string does not include a first generic coin type
|
|
441
463
|
- `parseGameDetails(game_details)` decodes `BetResultEvent.game_details` entries into the expected string, number, and boolean values
|
|
442
464
|
|
|
443
465
|
### Parse PvP Coinflip Game Object Data
|
|
@@ -512,7 +534,7 @@ const decoded = client.suigar.bcs.BetResultEvent.parse(event.bcs);
|
|
|
512
534
|
const gameDetails = parseGameDetails(decoded.game_details);
|
|
513
535
|
```
|
|
514
536
|
|
|
515
|
-
`parseGameDetails` preserves the
|
|
537
|
+
`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`.
|
|
516
538
|
|
|
517
539
|
When the extension is configured with `partner`, decoded event `metadata` will
|
|
518
540
|
contain that partner wallet address under the `partner` entry.
|
|
@@ -40,7 +40,9 @@ function toBoundedInt(value, max, typeName) {
|
|
|
40
40
|
const num = typeof value === "string" && value.trim() === "" ? NaN : Number(value);
|
|
41
41
|
assertFiniteNumber(num, "Value must be a finite number or integer string");
|
|
42
42
|
if (typeof value === "boolean" || value == null || !Number.isInteger(num) || num < 0 || num > max) {
|
|
43
|
-
throw new
|
|
43
|
+
throw new RangeError(
|
|
44
|
+
`Value must be a ${typeName} integer (0-${max}): ${value}`
|
|
45
|
+
);
|
|
44
46
|
}
|
|
45
47
|
return num;
|
|
46
48
|
}
|
|
@@ -302,7 +304,7 @@ function fromMoveFloat(float) {
|
|
|
302
304
|
function parseCoinType(type) {
|
|
303
305
|
const coinType = parseStructTag(type).typeParams[0];
|
|
304
306
|
if (!coinType) {
|
|
305
|
-
throw new
|
|
307
|
+
throw new TypeError(`Unable to parse coin type from ${type}`);
|
|
306
308
|
}
|
|
307
309
|
return normalizeStructTag(coinType);
|
|
308
310
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -485,7 +485,7 @@ function resolvePriceInfoObjectId(config, coinType) {
|
|
|
485
485
|
function resolveSupportedCoin(config, coinType) {
|
|
486
486
|
const [supportedCoin] = Object.entries(config.coinTypes).find(([_, value]) => value === coinType) ?? [];
|
|
487
487
|
if (!supportedCoin) {
|
|
488
|
-
throw new
|
|
488
|
+
throw new RangeError(
|
|
489
489
|
`Unsupported coin type ${coinType}. Supported coin types: ${Object.values(
|
|
490
490
|
config.coinTypes
|
|
491
491
|
).join(", ")}`
|
|
@@ -627,7 +627,9 @@ function toBoundedInt(value, max, typeName) {
|
|
|
627
627
|
const num = typeof value === "string" && value.trim() === "" ? NaN : Number(value);
|
|
628
628
|
assertFiniteNumber(num, "Value must be a finite number or integer string");
|
|
629
629
|
if (typeof value === "boolean" || value == null || !Number.isInteger(num) || num < 0 || num > max) {
|
|
630
|
-
throw new
|
|
630
|
+
throw new RangeError(
|
|
631
|
+
`Value must be a ${typeName} integer (0-${max}): ${value}`
|
|
632
|
+
);
|
|
631
633
|
}
|
|
632
634
|
return num;
|
|
633
635
|
}
|
|
@@ -652,7 +654,7 @@ new TextDecoder();
|
|
|
652
654
|
function parseCoinType(type) {
|
|
653
655
|
const coinType = utils.parseStructTag(type).typeParams[0];
|
|
654
656
|
if (!coinType) {
|
|
655
|
-
throw new
|
|
657
|
+
throw new TypeError(`Unable to parse coin type from ${type}`);
|
|
656
658
|
}
|
|
657
659
|
return utils.normalizeStructTag(coinType);
|
|
658
660
|
}
|
|
@@ -1036,7 +1038,7 @@ function buildPvPCoinflipTransaction(action, options) {
|
|
|
1036
1038
|
return tx;
|
|
1037
1039
|
}
|
|
1038
1040
|
default:
|
|
1039
|
-
throw new
|
|
1041
|
+
throw new RangeError(`Unsupported PvP coinflip action: ${action}`);
|
|
1040
1042
|
}
|
|
1041
1043
|
}
|
|
1042
1044
|
var $moduleName18 = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::i64";
|
|
@@ -1402,7 +1404,7 @@ var SuigarClient = class {
|
|
|
1402
1404
|
});
|
|
1403
1405
|
const network = this.#client.network;
|
|
1404
1406
|
if (!SUPPORTED_SUI_NETWORKS.includes(network)) {
|
|
1405
|
-
throw new
|
|
1407
|
+
throw new RangeError(`Unsupported network: ${network}`);
|
|
1406
1408
|
}
|
|
1407
1409
|
this.#config = resolveSuigarConfig(network);
|
|
1408
1410
|
}
|
|
@@ -1439,7 +1441,7 @@ var SuigarClient = class {
|
|
|
1439
1441
|
* The SDK first reads the selected game's settings object from SweetHouse,
|
|
1440
1442
|
* then reads that game's coin-specific `Parameters<T>` object. Results are
|
|
1441
1443
|
* cached according to the extension `cacheTtl` option. Pass
|
|
1442
|
-
* `ignoreCache: true` to refresh the
|
|
1444
|
+
* `ignoreCache: true` to refresh the on-chain read and replace the cached
|
|
1443
1445
|
* value.
|
|
1444
1446
|
*
|
|
1445
1447
|
* @param game Game whose parameters should be loaded.
|
|
@@ -1458,7 +1460,7 @@ var SuigarClient = class {
|
|
|
1458
1460
|
}
|
|
1459
1461
|
/**
|
|
1460
1462
|
* Lists unresolved PvP coinflip games from the configured registry and resolves
|
|
1461
|
-
* each entry into parsed
|
|
1463
|
+
* each entry into parsed on-chain game state.
|
|
1462
1464
|
*
|
|
1463
1465
|
* This fetches dynamic fields from the PvP coinflip registry object, then bulk
|
|
1464
1466
|
* loads the referenced game objects through `client.core.getObjects()`. Registry
|
|
@@ -1520,41 +1522,6 @@ var SuigarClient = class {
|
|
|
1520
1522
|
(game) => game instanceof Error ? [] : [game]
|
|
1521
1523
|
);
|
|
1522
1524
|
}
|
|
1523
|
-
async #fetchGameParameters(game, coinType, signal) {
|
|
1524
|
-
const gameDefinition = GAME_SETTINGS[game];
|
|
1525
|
-
const { object: settingsObject } = await this.#client.core.getDynamicObjectField({
|
|
1526
|
-
parentId: this.#config.packageIds.sweetHouse,
|
|
1527
|
-
name: {
|
|
1528
|
-
type: resolveGameSettingsKeyType(
|
|
1529
|
-
gameDefinition.settingsKey.name,
|
|
1530
|
-
resolveGamePackageId(this.#config, game)
|
|
1531
|
-
),
|
|
1532
|
-
bcs: gameDefinition.settingsKey.serialize({ dummy_field: false }).toBytes()
|
|
1533
|
-
},
|
|
1534
|
-
signal
|
|
1535
|
-
});
|
|
1536
|
-
const { object } = await this.#client.core.getDynamicObjectField({
|
|
1537
|
-
parentId: settingsObject.objectId,
|
|
1538
|
-
name: {
|
|
1539
|
-
type: TypeName.name,
|
|
1540
|
-
bcs: TypeName.serialize({
|
|
1541
|
-
name: resolveCoinTypeNameForTypeNameKey(coinType)
|
|
1542
|
-
}).toBytes()
|
|
1543
|
-
},
|
|
1544
|
-
include: {
|
|
1545
|
-
content: true
|
|
1546
|
-
},
|
|
1547
|
-
signal
|
|
1548
|
-
});
|
|
1549
|
-
if (!object?.content) {
|
|
1550
|
-
throw new Error(
|
|
1551
|
-
`Missing parameters object content for ${game} and coin type ${coinType}`
|
|
1552
|
-
);
|
|
1553
|
-
}
|
|
1554
|
-
return gameDefinition.parameters.parse(
|
|
1555
|
-
object.content
|
|
1556
|
-
);
|
|
1557
|
-
}
|
|
1558
1525
|
/**
|
|
1559
1526
|
* BCS struct constructors for decoding on-chain objects and events related to Suigar games.
|
|
1560
1527
|
*
|
|
@@ -1633,7 +1600,7 @@ var SuigarClient = class {
|
|
|
1633
1600
|
partner: this.#partner
|
|
1634
1601
|
});
|
|
1635
1602
|
default:
|
|
1636
|
-
throw new
|
|
1603
|
+
throw new RangeError(`Unsupported game: ${gameId}`);
|
|
1637
1604
|
}
|
|
1638
1605
|
},
|
|
1639
1606
|
/**
|
|
@@ -1667,7 +1634,7 @@ var SuigarClient = class {
|
|
|
1667
1634
|
partner: this.#partner
|
|
1668
1635
|
});
|
|
1669
1636
|
default:
|
|
1670
|
-
throw new
|
|
1637
|
+
throw new RangeError(`Unsupported PvP coinflip action: ${action}`);
|
|
1671
1638
|
}
|
|
1672
1639
|
}
|
|
1673
1640
|
};
|
|
@@ -1684,6 +1651,41 @@ var SuigarClient = class {
|
|
|
1684
1651
|
});
|
|
1685
1652
|
};
|
|
1686
1653
|
}
|
|
1654
|
+
async #fetchGameParameters(game, coinType, signal) {
|
|
1655
|
+
const gameDefinition = GAME_SETTINGS[game];
|
|
1656
|
+
const { object: settingsObject } = await this.#client.core.getDynamicObjectField({
|
|
1657
|
+
parentId: this.#config.packageIds.sweetHouse,
|
|
1658
|
+
name: {
|
|
1659
|
+
type: resolveGameSettingsKeyType(
|
|
1660
|
+
gameDefinition.settingsKey.name,
|
|
1661
|
+
resolveGamePackageId(this.#config, game)
|
|
1662
|
+
),
|
|
1663
|
+
bcs: gameDefinition.settingsKey.serialize({ dummy_field: false }).toBytes()
|
|
1664
|
+
},
|
|
1665
|
+
signal
|
|
1666
|
+
});
|
|
1667
|
+
const { object } = await this.#client.core.getDynamicObjectField({
|
|
1668
|
+
parentId: settingsObject.objectId,
|
|
1669
|
+
name: {
|
|
1670
|
+
type: TypeName.name,
|
|
1671
|
+
bcs: TypeName.serialize({
|
|
1672
|
+
name: resolveCoinTypeNameForTypeNameKey(coinType)
|
|
1673
|
+
}).toBytes()
|
|
1674
|
+
},
|
|
1675
|
+
include: {
|
|
1676
|
+
content: true
|
|
1677
|
+
},
|
|
1678
|
+
signal
|
|
1679
|
+
});
|
|
1680
|
+
if (!object?.content) {
|
|
1681
|
+
throw new Error(
|
|
1682
|
+
`Missing parameters object content for ${game} and coin type ${coinType}`
|
|
1683
|
+
);
|
|
1684
|
+
}
|
|
1685
|
+
return gameDefinition.parameters.parse(
|
|
1686
|
+
object.content
|
|
1687
|
+
);
|
|
1688
|
+
}
|
|
1687
1689
|
};
|
|
1688
1690
|
|
|
1689
1691
|
exports.SuigarClient = SuigarClient;
|
package/dist/index.d.cts
CHANGED
|
@@ -243,7 +243,7 @@ declare class SuigarClient {
|
|
|
243
243
|
* The SDK first reads the selected game's settings object from SweetHouse,
|
|
244
244
|
* then reads that game's coin-specific `Parameters<T>` object. Results are
|
|
245
245
|
* cached according to the extension `cacheTtl` option. Pass
|
|
246
|
-
* `ignoreCache: true` to refresh the
|
|
246
|
+
* `ignoreCache: true` to refresh the on-chain read and replace the cached
|
|
247
247
|
* value.
|
|
248
248
|
*
|
|
249
249
|
* @param game Game whose parameters should be loaded.
|
|
@@ -253,7 +253,7 @@ declare class SuigarClient {
|
|
|
253
253
|
getGameParameters<TGame extends Game>(game: TGame, options?: GetGameParametersOptions): Promise<GameParameters<TGame>>;
|
|
254
254
|
/**
|
|
255
255
|
* Lists unresolved PvP coinflip games from the configured registry and resolves
|
|
256
|
-
* each entry into parsed
|
|
256
|
+
* each entry into parsed on-chain game state.
|
|
257
257
|
*
|
|
258
258
|
* This fetches dynamic fields from the PvP coinflip registry object, then bulk
|
|
259
259
|
* loads the referenced game objects through `client.core.getObjects()`. Registry
|
package/dist/index.d.ts
CHANGED
|
@@ -243,7 +243,7 @@ declare class SuigarClient {
|
|
|
243
243
|
* The SDK first reads the selected game's settings object from SweetHouse,
|
|
244
244
|
* then reads that game's coin-specific `Parameters<T>` object. Results are
|
|
245
245
|
* cached according to the extension `cacheTtl` option. Pass
|
|
246
|
-
* `ignoreCache: true` to refresh the
|
|
246
|
+
* `ignoreCache: true` to refresh the on-chain read and replace the cached
|
|
247
247
|
* value.
|
|
248
248
|
*
|
|
249
249
|
* @param game Game whose parameters should be loaded.
|
|
@@ -253,7 +253,7 @@ declare class SuigarClient {
|
|
|
253
253
|
getGameParameters<TGame extends Game>(game: TGame, options?: GetGameParametersOptions): Promise<GameParameters<TGame>>;
|
|
254
254
|
/**
|
|
255
255
|
* Lists unresolved PvP coinflip games from the configured registry and resolves
|
|
256
|
-
* each entry into parsed
|
|
256
|
+
* each entry into parsed on-chain game state.
|
|
257
257
|
*
|
|
258
258
|
* This fetches dynamic fields from the PvP coinflip registry object, then bulk
|
|
259
259
|
* loads the referenced game objects through `client.core.getObjects()`. Registry
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MoveStruct, Float, parseCoinType, toBigInt, toU8, DEFAULT_GAS_BUDGET_MIST, normalizeMoveArguments, DEFAULT_LIMBO_MULTIPLIER_SCALE, DEFAULT_RANGE_SCALE } from './chunk-
|
|
1
|
+
import { MoveStruct, Float, parseCoinType, toBigInt, toU8, DEFAULT_GAS_BUDGET_MIST, normalizeMoveArguments, DEFAULT_LIMBO_MULTIPLIER_SCALE, DEFAULT_RANGE_SCALE } from './chunk-7N55D2TV.js';
|
|
2
2
|
import { toBase64, normalizeStructTag, parseStructTag, normalizeSuiAddress, fromHex } from '@mysten/sui/utils';
|
|
3
3
|
import { bcs } from '@mysten/sui/bcs';
|
|
4
4
|
import { Transaction } from '@mysten/sui/transactions';
|
|
@@ -325,7 +325,7 @@ function resolvePriceInfoObjectId(config, coinType) {
|
|
|
325
325
|
function resolveSupportedCoin(config, coinType) {
|
|
326
326
|
const [supportedCoin] = Object.entries(config.coinTypes).find(([_, value]) => value === coinType) ?? [];
|
|
327
327
|
if (!supportedCoin) {
|
|
328
|
-
throw new
|
|
328
|
+
throw new RangeError(
|
|
329
329
|
`Unsupported coin type ${coinType}. Supported coin types: ${Object.values(
|
|
330
330
|
config.coinTypes
|
|
331
331
|
).join(", ")}`
|
|
@@ -817,7 +817,7 @@ function buildPvPCoinflipTransaction(action, options) {
|
|
|
817
817
|
return tx;
|
|
818
818
|
}
|
|
819
819
|
default:
|
|
820
|
-
throw new
|
|
820
|
+
throw new RangeError(`Unsupported PvP coinflip action: ${action}`);
|
|
821
821
|
}
|
|
822
822
|
}
|
|
823
823
|
var $moduleName16 = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::i64";
|
|
@@ -1183,7 +1183,7 @@ var SuigarClient = class {
|
|
|
1183
1183
|
});
|
|
1184
1184
|
const network = this.#client.network;
|
|
1185
1185
|
if (!SUPPORTED_SUI_NETWORKS.includes(network)) {
|
|
1186
|
-
throw new
|
|
1186
|
+
throw new RangeError(`Unsupported network: ${network}`);
|
|
1187
1187
|
}
|
|
1188
1188
|
this.#config = resolveSuigarConfig(network);
|
|
1189
1189
|
}
|
|
@@ -1220,7 +1220,7 @@ var SuigarClient = class {
|
|
|
1220
1220
|
* The SDK first reads the selected game's settings object from SweetHouse,
|
|
1221
1221
|
* then reads that game's coin-specific `Parameters<T>` object. Results are
|
|
1222
1222
|
* cached according to the extension `cacheTtl` option. Pass
|
|
1223
|
-
* `ignoreCache: true` to refresh the
|
|
1223
|
+
* `ignoreCache: true` to refresh the on-chain read and replace the cached
|
|
1224
1224
|
* value.
|
|
1225
1225
|
*
|
|
1226
1226
|
* @param game Game whose parameters should be loaded.
|
|
@@ -1239,7 +1239,7 @@ var SuigarClient = class {
|
|
|
1239
1239
|
}
|
|
1240
1240
|
/**
|
|
1241
1241
|
* Lists unresolved PvP coinflip games from the configured registry and resolves
|
|
1242
|
-
* each entry into parsed
|
|
1242
|
+
* each entry into parsed on-chain game state.
|
|
1243
1243
|
*
|
|
1244
1244
|
* This fetches dynamic fields from the PvP coinflip registry object, then bulk
|
|
1245
1245
|
* loads the referenced game objects through `client.core.getObjects()`. Registry
|
|
@@ -1301,41 +1301,6 @@ var SuigarClient = class {
|
|
|
1301
1301
|
(game) => game instanceof Error ? [] : [game]
|
|
1302
1302
|
);
|
|
1303
1303
|
}
|
|
1304
|
-
async #fetchGameParameters(game, coinType, signal) {
|
|
1305
|
-
const gameDefinition = GAME_SETTINGS[game];
|
|
1306
|
-
const { object: settingsObject } = await this.#client.core.getDynamicObjectField({
|
|
1307
|
-
parentId: this.#config.packageIds.sweetHouse,
|
|
1308
|
-
name: {
|
|
1309
|
-
type: resolveGameSettingsKeyType(
|
|
1310
|
-
gameDefinition.settingsKey.name,
|
|
1311
|
-
resolveGamePackageId(this.#config, game)
|
|
1312
|
-
),
|
|
1313
|
-
bcs: gameDefinition.settingsKey.serialize({ dummy_field: false }).toBytes()
|
|
1314
|
-
},
|
|
1315
|
-
signal
|
|
1316
|
-
});
|
|
1317
|
-
const { object } = await this.#client.core.getDynamicObjectField({
|
|
1318
|
-
parentId: settingsObject.objectId,
|
|
1319
|
-
name: {
|
|
1320
|
-
type: TypeName.name,
|
|
1321
|
-
bcs: TypeName.serialize({
|
|
1322
|
-
name: resolveCoinTypeNameForTypeNameKey(coinType)
|
|
1323
|
-
}).toBytes()
|
|
1324
|
-
},
|
|
1325
|
-
include: {
|
|
1326
|
-
content: true
|
|
1327
|
-
},
|
|
1328
|
-
signal
|
|
1329
|
-
});
|
|
1330
|
-
if (!object?.content) {
|
|
1331
|
-
throw new Error(
|
|
1332
|
-
`Missing parameters object content for ${game} and coin type ${coinType}`
|
|
1333
|
-
);
|
|
1334
|
-
}
|
|
1335
|
-
return gameDefinition.parameters.parse(
|
|
1336
|
-
object.content
|
|
1337
|
-
);
|
|
1338
|
-
}
|
|
1339
1304
|
/**
|
|
1340
1305
|
* BCS struct constructors for decoding on-chain objects and events related to Suigar games.
|
|
1341
1306
|
*
|
|
@@ -1414,7 +1379,7 @@ var SuigarClient = class {
|
|
|
1414
1379
|
partner: this.#partner
|
|
1415
1380
|
});
|
|
1416
1381
|
default:
|
|
1417
|
-
throw new
|
|
1382
|
+
throw new RangeError(`Unsupported game: ${gameId}`);
|
|
1418
1383
|
}
|
|
1419
1384
|
},
|
|
1420
1385
|
/**
|
|
@@ -1448,7 +1413,7 @@ var SuigarClient = class {
|
|
|
1448
1413
|
partner: this.#partner
|
|
1449
1414
|
});
|
|
1450
1415
|
default:
|
|
1451
|
-
throw new
|
|
1416
|
+
throw new RangeError(`Unsupported PvP coinflip action: ${action}`);
|
|
1452
1417
|
}
|
|
1453
1418
|
}
|
|
1454
1419
|
};
|
|
@@ -1465,6 +1430,41 @@ var SuigarClient = class {
|
|
|
1465
1430
|
});
|
|
1466
1431
|
};
|
|
1467
1432
|
}
|
|
1433
|
+
async #fetchGameParameters(game, coinType, signal) {
|
|
1434
|
+
const gameDefinition = GAME_SETTINGS[game];
|
|
1435
|
+
const { object: settingsObject } = await this.#client.core.getDynamicObjectField({
|
|
1436
|
+
parentId: this.#config.packageIds.sweetHouse,
|
|
1437
|
+
name: {
|
|
1438
|
+
type: resolveGameSettingsKeyType(
|
|
1439
|
+
gameDefinition.settingsKey.name,
|
|
1440
|
+
resolveGamePackageId(this.#config, game)
|
|
1441
|
+
),
|
|
1442
|
+
bcs: gameDefinition.settingsKey.serialize({ dummy_field: false }).toBytes()
|
|
1443
|
+
},
|
|
1444
|
+
signal
|
|
1445
|
+
});
|
|
1446
|
+
const { object } = await this.#client.core.getDynamicObjectField({
|
|
1447
|
+
parentId: settingsObject.objectId,
|
|
1448
|
+
name: {
|
|
1449
|
+
type: TypeName.name,
|
|
1450
|
+
bcs: TypeName.serialize({
|
|
1451
|
+
name: resolveCoinTypeNameForTypeNameKey(coinType)
|
|
1452
|
+
}).toBytes()
|
|
1453
|
+
},
|
|
1454
|
+
include: {
|
|
1455
|
+
content: true
|
|
1456
|
+
},
|
|
1457
|
+
signal
|
|
1458
|
+
});
|
|
1459
|
+
if (!object?.content) {
|
|
1460
|
+
throw new Error(
|
|
1461
|
+
`Missing parameters object content for ${game} and coin type ${coinType}`
|
|
1462
|
+
);
|
|
1463
|
+
}
|
|
1464
|
+
return gameDefinition.parameters.parse(
|
|
1465
|
+
object.content
|
|
1466
|
+
);
|
|
1467
|
+
}
|
|
1468
1468
|
};
|
|
1469
1469
|
|
|
1470
1470
|
export { SuigarClient, suigar };
|
package/dist/utils.cjs
CHANGED
|
@@ -42,7 +42,9 @@ function toBoundedInt(value, max, typeName) {
|
|
|
42
42
|
const num = typeof value === "string" && value.trim() === "" ? NaN : Number(value);
|
|
43
43
|
assertFiniteNumber(num, "Value must be a finite number or integer string");
|
|
44
44
|
if (typeof value === "boolean" || value == null || !Number.isInteger(num) || num < 0 || num > max) {
|
|
45
|
-
throw new
|
|
45
|
+
throw new RangeError(
|
|
46
|
+
`Value must be a ${typeName} integer (0-${max}): ${value}`
|
|
47
|
+
);
|
|
46
48
|
}
|
|
47
49
|
return num;
|
|
48
50
|
}
|
|
@@ -192,7 +194,7 @@ function fromMoveFloat(float) {
|
|
|
192
194
|
function parseCoinType(type) {
|
|
193
195
|
const coinType = utils.parseStructTag(type).typeParams[0];
|
|
194
196
|
if (!coinType) {
|
|
195
|
-
throw new
|
|
197
|
+
throw new TypeError(`Unable to parse coin type from ${type}`);
|
|
196
198
|
}
|
|
197
199
|
return utils.normalizeStructTag(coinType);
|
|
198
200
|
}
|
package/dist/utils.d.cts
CHANGED
|
@@ -145,7 +145,7 @@ declare function fromMoveI64(i64: MoveFloat['exp']): number;
|
|
|
145
145
|
*
|
|
146
146
|
* Suigar float values are represented as a sign flag, an unsigned mantissa,
|
|
147
147
|
* and a Move `i64` exponent. This helper rebuilds the numeric value using the
|
|
148
|
-
* same normalization expected by the
|
|
148
|
+
* same normalization expected by the on-chain format and applies the sign at
|
|
149
149
|
* the end. Missing mantissas are treated as `0`, and a zero mantissa returns `0`.
|
|
150
150
|
*
|
|
151
151
|
* @param float Generated Move float value with `mant`, `exp`, and `is_negative`.
|
|
@@ -169,7 +169,7 @@ declare function parseCoinType(type: string): string;
|
|
|
169
169
|
* Suigar stores game detail entries as `VecMap<string, vector<u8>>`, so raw BCS
|
|
170
170
|
* decoding leaves each value as bytes. This helper looks up the known schema for
|
|
171
171
|
* each key, parses the bytes into the expected runtime type, and preserves the
|
|
172
|
-
* original
|
|
172
|
+
* original on-chain keys in the returned object. Unknown keys fall back to
|
|
173
173
|
* string decoding so newer detail fields remain readable by default.
|
|
174
174
|
*
|
|
175
175
|
* @param gameDetails Raw `game_details` map from a decoded bet result event.
|
package/dist/utils.d.ts
CHANGED
|
@@ -145,7 +145,7 @@ declare function fromMoveI64(i64: MoveFloat['exp']): number;
|
|
|
145
145
|
*
|
|
146
146
|
* Suigar float values are represented as a sign flag, an unsigned mantissa,
|
|
147
147
|
* and a Move `i64` exponent. This helper rebuilds the numeric value using the
|
|
148
|
-
* same normalization expected by the
|
|
148
|
+
* same normalization expected by the on-chain format and applies the sign at
|
|
149
149
|
* the end. Missing mantissas are treated as `0`, and a zero mantissa returns `0`.
|
|
150
150
|
*
|
|
151
151
|
* @param float Generated Move float value with `mant`, `exp`, and `is_negative`.
|
|
@@ -169,7 +169,7 @@ declare function parseCoinType(type: string): string;
|
|
|
169
169
|
* Suigar stores game detail entries as `VecMap<string, vector<u8>>`, so raw BCS
|
|
170
170
|
* decoding leaves each value as bytes. This helper looks up the known schema for
|
|
171
171
|
* each key, parses the bytes into the expected runtime type, and preserves the
|
|
172
|
-
* original
|
|
172
|
+
* original on-chain keys in the returned object. Unknown keys fall back to
|
|
173
173
|
* string decoding so newer detail fields remain readable by default.
|
|
174
174
|
*
|
|
175
175
|
* @param gameDetails Raw `game_details` map from a decoded bet result event.
|
package/dist/utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { DEFAULT_GAS_BUDGET_MIST, DEFAULT_LIMBO_MULTIPLIER_SCALE, DEFAULT_RANGE_SCALE, RANGE_POINT_LIMIT, fromMoveFloat, fromMoveI64, parseCoinType, parseGameDetails, toBigInt, toU16, toU8 } from './chunk-
|
|
1
|
+
export { DEFAULT_GAS_BUDGET_MIST, DEFAULT_LIMBO_MULTIPLIER_SCALE, DEFAULT_RANGE_SCALE, RANGE_POINT_LIMIT, fromMoveFloat, fromMoveI64, parseCoinType, parseGameDetails, toBigInt, toU16, toU8 } from './chunk-7N55D2TV.js';
|