@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/CHANGELOG.md +20 -0
- package/README.md +41 -32
- package/dist/{chunk-W3WZ2BHO.js → chunk-YGYMLRE4.js} +25 -12
- package/dist/{games--Haw_z7M.d.cts → games-BccpPyWd.d.cts} +19 -20
- package/dist/{games--Haw_z7M.d.ts → games-BccpPyWd.d.ts} +19 -20
- package/dist/games.d.cts +2 -1
- package/dist/games.d.ts +2 -1
- package/dist/index.cjs +86 -49
- package/dist/index.d.cts +17 -12
- package/dist/index.d.ts +17 -12
- package/dist/index.js +67 -43
- package/dist/utils.cjs +28 -15
- package/dist/utils.d.cts +41 -5
- package/dist/utils.d.ts +41 -5
- package/dist/utils.js +1 -1
- package/package.json +1 -16
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
|
|
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(
|
|
381
|
+
throw new Error(`Value must be non-negative: ${value}`);
|
|
374
382
|
}
|
|
375
383
|
return value;
|
|
376
384
|
}
|
|
377
|
-
|
|
378
|
-
|
|
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
|
|
383
|
-
|
|
384
|
-
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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
|
|
438
|
+
const normalizedPlayerAddress = utils.normalizeSuiAddress(playerAddress);
|
|
428
439
|
const normalizedCoinType = utils.normalizeStructTag(coinType);
|
|
429
|
-
const resolvedStake =
|
|
430
|
-
const resolvedCashStake =
|
|
431
|
-
const resolvedBetCount =
|
|
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
|
-
|
|
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(
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
|
1010
|
-
*
|
|
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
|
-
*
|
|
1018
|
-
*
|
|
1019
|
-
*
|
|
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
|
-
*
|
|
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
|
-
|
|
1030
|
-
|
|
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
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1060
|
+
const firstError = resolvedGames.find((game) => game instanceof Error);
|
|
1061
|
+
if (firstError) {
|
|
1062
|
+
throw firstError;
|
|
1063
|
+
}
|
|
1036
1064
|
}
|
|
1037
|
-
|
|
1038
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1118
|
+
PvPCoinflipGameCreatedEvent: GameCreatedEvent,
|
|
1096
1119
|
/**
|
|
1097
1120
|
* Event emitted when a PvP Coinflip game is resolved, containing the final outcome.
|
|
1098
1121
|
*/
|
|
1099
|
-
|
|
1122
|
+
PvPCoinflipGameResolvedEvent: GameResolvedEvent,
|
|
1100
1123
|
/**
|
|
1101
1124
|
* Event emitted when a PvP Coinflip game is cancelled.
|
|
1102
1125
|
*/
|
|
1103
|
-
|
|
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
|
|
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
|
|
48
|
-
*
|
|
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
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
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
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
48
|
-
*
|
|
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
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
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
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,
|
|
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
|
-
|
|
229
|
-
sender,
|
|
228
|
+
playerAddress,
|
|
230
229
|
gasBudget
|
|
231
230
|
}) {
|
|
232
231
|
assertConfiguredBetGame(config, game);
|
|
233
232
|
const tx = new Transaction();
|
|
234
|
-
tx.setSenderIfNotSet(normalizeSuiAddress(
|
|
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
|
-
|
|
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
|
|
250
|
+
const normalizedPlayerAddress = normalizeSuiAddress(playerAddress);
|
|
253
251
|
const normalizedCoinType = normalizeStructTag(coinType);
|
|
254
|
-
const resolvedStake =
|
|
255
|
-
const resolvedCashStake =
|
|
256
|
-
const resolvedBetCount =
|
|
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
|
-
|
|
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(
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
|
835
|
-
*
|
|
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
|
-
*
|
|
843
|
-
*
|
|
844
|
-
*
|
|
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
|
-
*
|
|
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
|
-
|
|
855
|
-
|
|
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
|
-
|
|
859
|
-
|
|
860
|
-
|
|
872
|
+
const firstError = resolvedGames.find((game) => game instanceof Error);
|
|
873
|
+
if (firstError) {
|
|
874
|
+
throw firstError;
|
|
875
|
+
}
|
|
861
876
|
}
|
|
862
|
-
|
|
863
|
-
|
|
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
|
-
|
|
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
|
-
|
|
930
|
+
PvPCoinflipGameCreatedEvent: GameCreatedEvent,
|
|
921
931
|
/**
|
|
922
932
|
* Event emitted when a PvP Coinflip game is resolved, containing the final outcome.
|
|
923
933
|
*/
|
|
924
|
-
|
|
934
|
+
PvPCoinflipGameResolvedEvent: GameResolvedEvent,
|
|
925
935
|
/**
|
|
926
936
|
* Event emitted when a PvP Coinflip game is cancelled.
|
|
927
937
|
*/
|
|
928
|
-
|
|
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 };
|