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

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
@@ -4,152 +4,7 @@ var utils = require('@mysten/sui/utils');
4
4
  var bcs = require('@mysten/sui/bcs');
5
5
  var transactions = require('@mysten/sui/transactions');
6
6
 
7
- // src/utils/config.ts
8
-
9
- // src/configs/package-id.ts
10
- var DEFAULT_SWEETHOUSE_PACKAGE_ID = "0xb7f64e5a273aba1ede00caa0a6f8027cc7490c279d17eab12e7100ed20660603";
11
- var DEFAULT_GAMES_PACKAGE_ID = {
12
- coinflip: "0xb35c5f286c443752afc8ccb40125a578a4f32df35617170ccfa17fe180ab80ea",
13
- limbo: "0x96c7841b9b32c59a219760fd656f1c3aceb53cc74a68ec9844a3a696374309f4",
14
- plinko: "0xd3dd2200883af10811724f0bed97591ad155a02efd6332d471ff8b346030dfb7",
15
- pvp_coinflip: "0xb43cf6583c0c15315c7e66f173af4be79ac40c38aad1fd92ec08638ab2026202",
16
- range: "0x096a4cf18b3661e76b2c62b90785418345d52f45b272448794f123a4cb6b6416",
17
- wheel: "0x0997852ded7e13301c42317004bc49704a893aa82997c5706cebee59053a31b7"
18
- };
19
-
20
- // src/configs/usdc-coin-type.ts
21
- var DEFAULT_USDC_COIN_TYPE = "0xdba34672e30cb065b1f93e3a0e89fd79d1f22e12e55e88edbbcbac48609f4af0::usdc::USDC";
22
- var DEFAULT_USDC_FLOWX_COIN_TYPE = "0xbde4ba4c7f1193c4f1f5b9e8a9c1cdec42c6f3f3a73cf40e1f4cb12cc7e6a4c0::usdc::USDC";
23
-
24
- // src/utils/config.ts
25
- var trim = (value) => value?.trim() ?? "";
26
- function resolveSuigarConfig(options) {
27
- const suiCoinType = utils.normalizeStructTag(
28
- options.coinTypes?.sui ?? utils.SUI_TYPE_ARG
29
- );
30
- const usdcCoinType = utils.normalizeStructTag(
31
- options.coinTypes?.usdc ?? DEFAULT_USDC_COIN_TYPE
32
- );
33
- const usdcFlowxCoinType = utils.normalizeStructTag(
34
- options.coinTypes?.usdcFlowx ?? DEFAULT_USDC_FLOWX_COIN_TYPE
35
- );
36
- const explicitPriceInfoObjectIds = Object.fromEntries(
37
- Object.entries(options.pyth?.priceInfoObjectIds ?? {}).map(
38
- ([coinType, objectId]) => [utils.normalizeStructTag(coinType), objectId]
39
- )
40
- );
41
- return {
42
- sweetHousePackageId: trim(options.sweetHousePackageId) || trim(DEFAULT_SWEETHOUSE_PACKAGE_ID),
43
- coinTypes: {
44
- sui: suiCoinType,
45
- usdc: usdcCoinType,
46
- usdcFlowx: usdcFlowxCoinType
47
- },
48
- gamesPackageId: {
49
- coinflip: trim(options.gamesPackageId?.coinflip) || DEFAULT_GAMES_PACKAGE_ID.coinflip,
50
- limbo: trim(options.gamesPackageId?.limbo) || DEFAULT_GAMES_PACKAGE_ID.limbo,
51
- plinko: trim(options.gamesPackageId?.plinko) || DEFAULT_GAMES_PACKAGE_ID.plinko,
52
- "pvp-coinflip": trim(options.gamesPackageId?.["pvp-coinflip"]) || DEFAULT_GAMES_PACKAGE_ID.pvp_coinflip,
53
- range: trim(options.gamesPackageId?.range) || DEFAULT_GAMES_PACKAGE_ID.range,
54
- wheel: trim(options.gamesPackageId?.wheel) || DEFAULT_GAMES_PACKAGE_ID.wheel
55
- },
56
- pyth: {
57
- packageId: trim(options.pyth?.packageId) || void 0,
58
- suiPriceInfoObjectId: trim(options.pyth?.suiPriceInfoObjectId),
59
- usdcPriceInfoObjectId: trim(options.pyth?.usdcPriceInfoObjectId),
60
- priceInfoObjectIds: explicitPriceInfoObjectIds
61
- }
62
- };
63
- }
64
- function resolvePythPriceInfoObjectId(config, coinType) {
65
- const normalizedCoinType = utils.normalizeStructTag(coinType);
66
- const explicitObjectId = config.pyth.priceInfoObjectIds[normalizedCoinType];
67
- if (explicitObjectId) {
68
- return explicitObjectId;
69
- }
70
- if (normalizedCoinType === config.coinTypes.sui && config.pyth.suiPriceInfoObjectId) {
71
- return config.pyth.suiPriceInfoObjectId;
72
- }
73
- if ((normalizedCoinType === config.coinTypes.usdc || normalizedCoinType === config.coinTypes.usdcFlowx) && config.pyth.usdcPriceInfoObjectId) {
74
- return config.pyth.usdcPriceInfoObjectId;
75
- }
76
- throw new Error(
77
- `Missing Pyth price object configuration for coin type ${coinType}`
78
- );
79
- }
80
- function assertConfiguredBetGame(config, game) {
81
- if (!config.gamesPackageId[game]) {
82
- throw new Error(
83
- `Missing required config for ${game}: gamesPackageId.${game}`
84
- );
85
- }
86
- }
87
- var ADDRESS_METADATA_KEYS = /* @__PURE__ */ new Set(["referrer", "partner"]);
88
- var textEncoder = new TextEncoder();
89
- var parseHexAddress = (value) => {
90
- const trimmed = value.trim();
91
- if (!trimmed) return null;
92
- try {
93
- const normalized = utils.normalizeSuiAddress(trimmed).slice(2);
94
- const bytes = new Uint8Array(normalized.length / 2);
95
- for (let index = 0; index < normalized.length; index += 2) {
96
- bytes[index / 2] = Number.parseInt(
97
- normalized.slice(index, index + 2),
98
- 16
99
- );
100
- }
101
- return bytes;
102
- } catch {
103
- return null;
104
- }
105
- };
106
- function encodeBetMetadata(metadata) {
107
- const keys = [];
108
- const values = [];
109
- for (const [key, value] of Object.entries(metadata ?? {})) {
110
- if (value === void 0 || value === null) {
111
- continue;
112
- }
113
- let encodedValue;
114
- if (value instanceof Uint8Array) {
115
- encodedValue = Array.from(value);
116
- } else if (Array.isArray(value)) {
117
- encodedValue = value;
118
- } else if (typeof value === "string" && ADDRESS_METADATA_KEYS.has(key)) {
119
- encodedValue = Array.from(
120
- parseHexAddress(value) ?? textEncoder.encode(value)
121
- );
122
- } else {
123
- encodedValue = Array.from(textEncoder.encode(String(value)));
124
- }
125
- keys.push(key);
126
- values.push(encodedValue);
127
- }
128
- return { keys, values };
129
- }
130
-
131
- // src/utils/shared.ts
132
- var DEFAULT_GAS_BUDGET_MIST = 5e7;
133
- var RANGE_FIXED_POINT_SCALE = 1e6;
134
- var LIMBO_MULTIPLIER_SCALE = 100;
135
- function toBigIntAmount(value, fieldName) {
136
- if (typeof value === "bigint") {
137
- if (value < 0n) {
138
- throw new Error(`${fieldName} must be non-negative`);
139
- }
140
- return value;
141
- }
142
- if (!Number.isFinite(value) || value < 0) {
143
- throw new Error(`${fieldName} must be a finite non-negative number`);
144
- }
145
- return BigInt(Math.trunc(value));
146
- }
147
- function toU8Number(value, fieldName) {
148
- if (!Number.isInteger(value) || value < 0 || value > 255) {
149
- throw new Error(`${fieldName} must be an integer between 0 and 255`);
150
- }
151
- return value;
152
- }
7
+ // src/client.ts
153
8
  var MOVE_STDLIB_ADDRESS = utils.normalizeSuiAddress("0x1");
154
9
  var SUI_FRAMEWORK_ADDRESS = utils.normalizeSuiAddress("0x2");
155
10
  function getPureBcsSchema(typeTag) {
@@ -181,7 +36,8 @@ function getPureBcsSchema(typeTag) {
181
36
  return bcs.bcs.String;
182
37
  }
183
38
  if (structTag.module === "option" && structTag.name === "Option") {
184
- const type = getPureBcsSchema(structTag.typeParams[0]);
39
+ const inner = structTag.typeParams[0];
40
+ const type = inner ? getPureBcsSchema(inner) : null;
185
41
  return type ? bcs.bcs.option(type) : null;
186
42
  }
187
43
  }
@@ -195,7 +51,7 @@ function normalizeMoveArguments(args, argTypes, parameterNames) {
195
51
  Array.isArray(args) ? args.length : Object.keys(args).length;
196
52
  const normalizedArgs = [];
197
53
  let index = 0;
198
- for (const [i, argType] of argTypes.entries()) {
54
+ for (const argType of argTypes) {
199
55
  if (argType === "0x2::clock::Clock") {
200
56
  normalizedArgs.push((tx) => tx.object.clock());
201
57
  continue;
@@ -230,8 +86,7 @@ function normalizeMoveArguments(args, argTypes, parameterNames) {
230
86
  normalizedArgs.push(arg);
231
87
  continue;
232
88
  }
233
- const type = argTypes[i];
234
- const bcsType = type === null ? null : getPureBcsSchema(type);
89
+ const bcsType = argType === null ? null : getPureBcsSchema(argType);
235
90
  if (bcsType) {
236
91
  const bytes = bcsType.serialize(arg);
237
92
  normalizedArgs.push((tx) => tx.pure(bytes));
@@ -241,7 +96,7 @@ function normalizeMoveArguments(args, argTypes, parameterNames) {
241
96
  normalizedArgs.push((tx) => tx.object(arg));
242
97
  continue;
243
98
  }
244
- throw new Error(`Invalid argument ${stringify(arg)} for type ${type}`);
99
+ throw new Error(`Invalid argument ${stringify(arg)} for type ${argType}`);
245
100
  }
246
101
  return normalizedArgs;
247
102
  }
@@ -254,6 +109,9 @@ var MoveStruct = class extends bcs.BcsStruct {
254
109
  ...options,
255
110
  objectIds: [objectId]
256
111
  });
112
+ if (!res) {
113
+ throw new Error(`No object found for id ${objectId}`);
114
+ }
257
115
  return res;
258
116
  }
259
117
  async getMany({
@@ -287,6 +145,382 @@ function stringify(val) {
287
145
  }
288
146
  return val;
289
147
  }
148
+ var $moduleName = "0x0000000000000000000000000000000000000000000000000000000000000001::type_name";
149
+ var TypeName = new MoveStruct({
150
+ name: `${$moduleName}::TypeName`,
151
+ fields: {
152
+ name: bcs.bcs.string()
153
+ }
154
+ });
155
+ var $moduleName2 = "0x2::vec_map";
156
+ function Entry(...typeParameters) {
157
+ return new MoveStruct({
158
+ name: `${$moduleName2}::Entry<${typeParameters[0].name}, ${typeParameters[1].name}>`,
159
+ fields: {
160
+ key: typeParameters[0],
161
+ value: typeParameters[1]
162
+ }
163
+ });
164
+ }
165
+ function VecMap(...typeParameters) {
166
+ return new MoveStruct({
167
+ name: `${$moduleName2}::VecMap<${typeParameters[0].name}, ${typeParameters[1].name}>`,
168
+ fields: {
169
+ contents: bcs.bcs.vector(Entry(typeParameters[0], typeParameters[1]))
170
+ }
171
+ });
172
+ }
173
+ var $moduleName3 = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::i64";
174
+ var I64 = new MoveStruct({
175
+ name: `${$moduleName3}::I64`,
176
+ fields: {
177
+ bits: bcs.bcs.u64()
178
+ }
179
+ });
180
+
181
+ // src/contracts/core/float.ts
182
+ var $moduleName4 = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::float";
183
+ var Float = new MoveStruct({
184
+ name: `${$moduleName4}::Float`,
185
+ fields: {
186
+ is_negative: bcs.bcs.bool(),
187
+ exp: I64,
188
+ mant: bcs.bcs.u64()
189
+ }
190
+ });
191
+
192
+ // src/contracts/core/core.ts
193
+ var $moduleName5 = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::core";
194
+ var BetResultEvent = new MoveStruct({
195
+ name: `${$moduleName5}::BetResultEvent<phantom T0>`,
196
+ fields: {
197
+ player: bcs.bcs.Address,
198
+ coin_type: TypeName,
199
+ stake_amount: bcs.bcs.u64(),
200
+ unsafe_oracle_usd_coin_price: Float,
201
+ adjusted_oracle_usd_coin_price: Float,
202
+ outcome_amount: bcs.bcs.u64(),
203
+ game_details: VecMap(bcs.bcs.string(), bcs.bcs.vector(bcs.bcs.u8())),
204
+ metadata: VecMap(bcs.bcs.string(), bcs.bcs.vector(bcs.bcs.u8()))
205
+ }
206
+ });
207
+ var $moduleName6 = "0x0000000000000000000000000000000000000000000000000000000000000001::type_name";
208
+ var TypeName2 = new MoveStruct({
209
+ name: `${$moduleName6}::TypeName`,
210
+ fields: {
211
+ name: bcs.bcs.string()
212
+ }
213
+ });
214
+ var $moduleName7 = "0x2::balance";
215
+ var Balance = new MoveStruct({
216
+ name: `${$moduleName7}::Balance<phantom T0>`,
217
+ fields: {
218
+ value: bcs.bcs.u64()
219
+ }
220
+ });
221
+ var $moduleName8 = "0x2::vec_map";
222
+ function Entry2(...typeParameters) {
223
+ return new MoveStruct({
224
+ name: `${$moduleName8}::Entry<${typeParameters[0].name}, ${typeParameters[1].name}>`,
225
+ fields: {
226
+ key: typeParameters[0],
227
+ value: typeParameters[1]
228
+ }
229
+ });
230
+ }
231
+ function VecMap2(...typeParameters) {
232
+ return new MoveStruct({
233
+ name: `${$moduleName8}::VecMap<${typeParameters[0].name}, ${typeParameters[1].name}>`,
234
+ fields: {
235
+ contents: bcs.bcs.vector(Entry2(typeParameters[0], typeParameters[1]))
236
+ }
237
+ });
238
+ }
239
+
240
+ // src/contracts/pvp-coinflip/pvp_coinflip.ts
241
+ var $moduleName9 = "0xb43cf6583c0c15315c7e66f173af4be79ac40c38aad1fd92ec08638ab2026202::pvp_coinflip";
242
+ var Game = new MoveStruct({
243
+ name: `${$moduleName9}::Game<phantom T0>`,
244
+ fields: {
245
+ id: bcs.bcs.Address,
246
+ creator: bcs.bcs.Address,
247
+ creator_is_tails: bcs.bcs.bool(),
248
+ is_private: bcs.bcs.bool(),
249
+ creator_metadata: VecMap2(bcs.bcs.string(), bcs.bcs.vector(bcs.bcs.u8())),
250
+ joiner: bcs.bcs.Address,
251
+ winner: bcs.bcs.Address,
252
+ stake_per_player: bcs.bcs.u64(),
253
+ house_edge_bps: bcs.bcs.u64(),
254
+ stake_pot: Balance
255
+ }
256
+ });
257
+ var GameCreatedEvent = new MoveStruct({
258
+ name: `${$moduleName9}::GameCreatedEvent<phantom T0>`,
259
+ fields: {
260
+ game_id: bcs.bcs.Address,
261
+ creator: bcs.bcs.Address,
262
+ creator_is_tails: bcs.bcs.bool(),
263
+ is_private: bcs.bcs.bool(),
264
+ joiner_is_tails: bcs.bcs.bool(),
265
+ stake_per_player: bcs.bcs.u64(),
266
+ house_edge_bps: bcs.bcs.u64(),
267
+ coin_type: TypeName2
268
+ }
269
+ });
270
+ var GameResolvedEvent = new MoveStruct({
271
+ name: `${$moduleName9}::GameResolvedEvent<phantom T0>`,
272
+ fields: {
273
+ game_id: bcs.bcs.Address,
274
+ creator: bcs.bcs.Address,
275
+ joiner: bcs.bcs.Address,
276
+ winner: bcs.bcs.Address,
277
+ creator_is_tails: bcs.bcs.bool(),
278
+ is_private: bcs.bcs.bool(),
279
+ joiner_is_tails: bcs.bcs.bool(),
280
+ stake_per_player: bcs.bcs.u64(),
281
+ total_pot: bcs.bcs.u64(),
282
+ house_edge_amount: bcs.bcs.u64(),
283
+ payout_amount: bcs.bcs.u64(),
284
+ coin_type: TypeName2
285
+ }
286
+ });
287
+ var GameCancelledEvent = new MoveStruct({
288
+ name: `${$moduleName9}::GameCancelledEvent<phantom T0>`,
289
+ fields: {
290
+ game_id: bcs.bcs.Address,
291
+ creator: bcs.bcs.Address,
292
+ creator_is_tails: bcs.bcs.bool(),
293
+ is_private: bcs.bcs.bool(),
294
+ stake_per_player: bcs.bcs.u64(),
295
+ coin_type: TypeName2
296
+ }
297
+ });
298
+ function createGame(options) {
299
+ const packageAddress = options.package ?? "0xb43cf6583c0c15315c7e66f173af4be79ac40c38aad1fd92ec08638ab2026202";
300
+ const argumentsTypes = [
301
+ null,
302
+ null,
303
+ "bool",
304
+ "bool",
305
+ "vector<0x1::string::String>",
306
+ "vector<vector<u8>>"
307
+ ];
308
+ return (tx) => tx.moveCall({
309
+ package: packageAddress,
310
+ module: "pvp_coinflip",
311
+ function: "create_game",
312
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
313
+ typeArguments: options.typeArguments
314
+ });
315
+ }
316
+ function joinGame(options) {
317
+ const packageAddress = options.package ?? "0xb43cf6583c0c15315c7e66f173af4be79ac40c38aad1fd92ec08638ab2026202";
318
+ const argumentsTypes = [
319
+ "0x2::object::ID",
320
+ null,
321
+ null,
322
+ "vector<0x1::string::String>",
323
+ "vector<vector<u8>>",
324
+ null,
325
+ "0x2::clock::Clock",
326
+ "0x2::random::Random"
327
+ ];
328
+ return (tx) => tx.moveCall({
329
+ package: packageAddress,
330
+ module: "pvp_coinflip",
331
+ function: "join_game",
332
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
333
+ typeArguments: options.typeArguments
334
+ });
335
+ }
336
+ function cancelGame(options) {
337
+ const packageAddress = options.package ?? "0xb43cf6583c0c15315c7e66f173af4be79ac40c38aad1fd92ec08638ab2026202";
338
+ const argumentsTypes = ["0x2::object::ID", null];
339
+ return (tx) => tx.moveCall({
340
+ package: packageAddress,
341
+ module: "pvp_coinflip",
342
+ function: "cancel_game",
343
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
344
+ typeArguments: options.typeArguments
345
+ });
346
+ }
347
+
348
+ // src/configs/package.mainnet.ts
349
+ var MAINNET_PACKAGE_IDS = {
350
+ sweetHouse: "0xa1549d73230118716bc08865b8d62454f360ddaf40eee2158e458e52125d4ef1",
351
+ core: "0xcbb0929f21450013ebe5e86e7139f2409da2e3ed212c51126a7e6448b795a43f",
352
+ coinflip: "0xca96885371150f55653f7fab9e9b146f5a19698b1002bdff42159ea9d2ba7d7e",
353
+ limbo: "0x89db6a55ad4e650cad641b6f9fd90b391b22b1d9adbb2cabbfeb94a9eeda7026",
354
+ plinko: "0x74a73daff11c11ed05299c93ed770c62ec4dc6756fa99e271e251c2399f49fef",
355
+ pvpCoinflip: "0x29162faf01a8135630e0a32bbe4ce47f69607b24dbb1edea3800861f91d0030a",
356
+ range: "0xd19e32b0f2a5e541fbd345b4602f8a93a2eee25c16029595b6fef0b1e0461a54",
357
+ wheel: "0x6791eac73fe7bf463b7f3b1ea391df265fbc1b96201270664a5a11e2441e9955"
358
+ };
359
+ var MAINNET_COIN_TYPES = {
360
+ sui: "0x2::sui::SUI",
361
+ usdc: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC"
362
+ };
363
+ var MAINNET_PRICE_INFO_OBJECT_IDS = {
364
+ sui: "0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37",
365
+ usdc: "0x5dec622733a204ca27f5a90d8c2fad453cc6665186fd5dff13a83d0b6c9027ab"
366
+ };
367
+
368
+ // src/configs/package.testnet.ts
369
+ var TESTNET_PACKAGE_IDS = {
370
+ sweetHouse: "0xb7f64e5a273aba1ede00caa0a6f8027cc7490c279d17eab12e7100ed20660603",
371
+ core: "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc",
372
+ coinflip: "0xb35c5f286c443752afc8ccb40125a578a4f32df35617170ccfa17fe180ab80ea",
373
+ limbo: "0x96c7841b9b32c59a219760fd656f1c3aceb53cc74a68ec9844a3a696374309f4",
374
+ plinko: "0xd3dd2200883af10811724f0bed97591ad155a02efd6332d471ff8b346030dfb7",
375
+ pvpCoinflip: "0xb43cf6583c0c15315c7e66f173af4be79ac40c38aad1fd92ec08638ab2026202",
376
+ range: "0x096a4cf18b3661e76b2c62b90785418345d52f45b272448794f123a4cb6b6416",
377
+ wheel: "0x0997852ded7e13301c42317004bc49704a893aa82997c5706cebee59053a31b7"
378
+ };
379
+ var TESTNET_COIN_TYPES = {
380
+ sui: "0x47c67b9594069c32caa7a6e875ddf31d7fa52602dd22ccb9ebd8d3482aed76dc::test_sui::TEST_SUI",
381
+ usdc: "0x47c67b9594069c32caa7a6e875ddf31d7fa52602dd22ccb9ebd8d3482aed76dc::test_usdc::TEST_USDC"
382
+ };
383
+ var TESTNET_PRICE_INFO_OBJECT_IDS = {
384
+ sui: "0x1ebb295c789cc42b3b2a1606482cd1c7124076a0f5676718501fda8c7fd075a0",
385
+ usdc: "0x9c4dd4008297ffa5e480684b8100ec21cc934405ed9a25d4e4d7b6259aad9c81"
386
+ };
387
+
388
+ // src/configs/package.ts
389
+ var PACKAGE_IDS = {
390
+ mainnet: { ...MAINNET_PACKAGE_IDS },
391
+ testnet: { ...TESTNET_PACKAGE_IDS }
392
+ };
393
+ var COIN_TYPES = {
394
+ mainnet: { ...MAINNET_COIN_TYPES },
395
+ testnet: { ...TESTNET_COIN_TYPES }
396
+ };
397
+ var PRICE_INFO_OBJECT_IDS = {
398
+ mainnet: { ...MAINNET_PRICE_INFO_OBJECT_IDS },
399
+ testnet: { ...TESTNET_PRICE_INFO_OBJECT_IDS }
400
+ };
401
+
402
+ // src/configs/registry.mainnet.ts
403
+ var PVP_COINFLIP_REGISTRY_ID = "0x3d73568546c539c1da3eb2b8fe917faef3c0acdbec78a67fe6d52800a0729349";
404
+
405
+ // src/configs/registry.testnet.ts
406
+ var PVP_COINFLIP_REGISTRY_ID2 = "0x99f20d8e4be012ea14a681144ae72ac349d0a1a1585205880183eb167f075bad";
407
+
408
+ // src/configs/registry.ts
409
+ var REGISTRY_IDS = {
410
+ mainnet: {
411
+ pvpCoinflip: PVP_COINFLIP_REGISTRY_ID
412
+ },
413
+ testnet: {
414
+ pvpCoinflip: PVP_COINFLIP_REGISTRY_ID2
415
+ }
416
+ };
417
+
418
+ // src/helpers/config.ts
419
+ function resolveSuigarConfig(network) {
420
+ const packageIds = PACKAGE_IDS[network];
421
+ const registryIds = REGISTRY_IDS[network];
422
+ const coinTypes = COIN_TYPES[network];
423
+ const priceInfoObjectIds = PRICE_INFO_OBJECT_IDS[network];
424
+ return {
425
+ packageIds: { ...packageIds },
426
+ registryIds: { ...registryIds },
427
+ coinTypes: {
428
+ sui: utils.normalizeStructTag(coinTypes.sui),
429
+ usdc: utils.normalizeStructTag(coinTypes.usdc)
430
+ },
431
+ priceInfoObjectIds: {
432
+ sui: priceInfoObjectIds.sui,
433
+ usdc: priceInfoObjectIds.usdc
434
+ }
435
+ };
436
+ }
437
+ function assertConfiguredBetGame(config, game) {
438
+ if (!resolveGamePackageId(config, game)) {
439
+ throw new Error(`Missing required config for ${game}: packageIds.${game}`);
440
+ }
441
+ }
442
+ function resolveGamePackageId(config, game) {
443
+ switch (game) {
444
+ case "coinflip":
445
+ return config.packageIds.coinflip;
446
+ case "limbo":
447
+ return config.packageIds.limbo;
448
+ case "plinko":
449
+ return config.packageIds.plinko;
450
+ case "pvp-coinflip":
451
+ return config.packageIds.pvpCoinflip;
452
+ case "range":
453
+ return config.packageIds.range;
454
+ case "wheel":
455
+ return config.packageIds.wheel;
456
+ }
457
+ }
458
+ function resolvePriceInfoObjectId(config, coinType) {
459
+ const normalizedCoinType = utils.normalizeStructTag(coinType);
460
+ const supportedCoin = resolveSupportedCoin(config, normalizedCoinType);
461
+ const objectId = config.priceInfoObjectIds[supportedCoin];
462
+ if (!objectId) {
463
+ throw new Error(
464
+ `Missing price info object configuration for coin type ${coinType}`
465
+ );
466
+ }
467
+ return objectId;
468
+ }
469
+ function resolveSupportedCoin(config, coinType) {
470
+ const [supportedCoin] = Object.entries(config.coinTypes).find(([_, value]) => value === coinType) ?? [];
471
+ if (!supportedCoin) {
472
+ throw new Error(
473
+ `Unsupported coin type ${coinType}. Supported coin types: ${Object.values(
474
+ config.coinTypes
475
+ ).join(", ")}`
476
+ );
477
+ }
478
+ return supportedCoin;
479
+ }
480
+ var PARTNER_METADATA_KEY = "partner";
481
+ var RESERVED_METADATA_KEYS = /* @__PURE__ */ new Set([PARTNER_METADATA_KEY, "referrer"]);
482
+ var textEncoder = new TextEncoder();
483
+ function encodeString(value) {
484
+ try {
485
+ return utils.fromHex(value);
486
+ } catch {
487
+ return textEncoder.encode(value);
488
+ }
489
+ }
490
+ function encodeMetadataValue(value) {
491
+ if (value instanceof Uint8Array) {
492
+ return Array.from(value);
493
+ }
494
+ if (Array.isArray(value)) {
495
+ return value;
496
+ }
497
+ return Array.from(encodeString(String(value)));
498
+ }
499
+ function encodeBetMetadata(metadata, partner) {
500
+ const keys = [];
501
+ const values = [];
502
+ for (const [key, value] of Object.entries(metadata ?? {})) {
503
+ if (RESERVED_METADATA_KEYS.has(key)) {
504
+ console.warn(
505
+ `Metadata key "${key}" is reserved and will be ignored when parsing metadata.`
506
+ );
507
+ continue;
508
+ }
509
+ if (value == null) {
510
+ continue;
511
+ }
512
+ keys.push(key);
513
+ values.push(encodeMetadataValue(value));
514
+ }
515
+ if (partner?.trim()) {
516
+ keys.unshift(PARTNER_METADATA_KEY);
517
+ values.unshift(encodeMetadataValue(partner));
518
+ }
519
+ return {
520
+ keys,
521
+ values
522
+ };
523
+ }
290
524
 
291
525
  // src/contracts/coinflip/coinflip.ts
292
526
  function play(options) {
@@ -311,39 +545,98 @@ function play(options) {
311
545
  typeArguments: options.typeArguments
312
546
  });
313
547
  }
548
+ var DEFAULT_GAS_BUDGET_MIST = utils.parseToMist("0.05");
549
+ var DEFAULT_RANGE_SCALE = 1e6;
550
+ var DEFAULT_LIMBO_MULTIPLIER_SCALE = 100;
551
+
552
+ // src/utils/numeric.ts
553
+ function isFiniteNumber(value, message) {
554
+ if (typeof value !== "number") {
555
+ throw new Error(`${message}: ${String(value)}`);
556
+ }
557
+ if (!Number.isFinite(value)) {
558
+ throw new Error(`Value must be a finite number: ${value}`);
559
+ }
560
+ }
561
+ function toBigInt(value) {
562
+ if (typeof value === "bigint") {
563
+ if (value < 0n) {
564
+ throw new Error(`Value must be non-negative: ${value}`);
565
+ }
566
+ return value;
567
+ }
568
+ isFiniteNumber(value, "Value must be a bigint or number");
569
+ if (value < 0) {
570
+ throw new Error(`Value must be a finite non-negative number: ${value}`);
571
+ }
572
+ return BigInt(Math.trunc(value));
573
+ }
574
+ function toU8(value) {
575
+ isFiniteNumber(value, "Value must be a number");
576
+ if (!Number.isInteger(value)) {
577
+ throw new Error(`Value must be an integer: ${value}`);
578
+ }
579
+ if (value < 0 || value > 255) {
580
+ throw new Error(`Value must be an integer between 0 and 255: ${value}`);
581
+ }
582
+ return value;
583
+ }
584
+
585
+ // src/types/network.type.ts
586
+ var SUPPORTED_SUI_NETWORKS = [
587
+ "mainnet",
588
+ "testnet"
589
+ ];
590
+
591
+ // src/utils/parser.ts
592
+ new TextDecoder();
593
+ ({
594
+ u8: bcs.bcs.U8,
595
+ u64: bcs.bcs.U64,
596
+ bool: bcs.bcs.Bool,
597
+ string: bcs.bcs.String
598
+ });
599
+ function parseCoinType(type) {
600
+ const coinType = utils.parseStructTag(type).typeParams[0];
601
+ if (!coinType) {
602
+ throw new Error(`Unable to parse coin type from ${type}`);
603
+ }
604
+ return utils.normalizeStructTag(coinType);
605
+ }
606
+
607
+ // src/transactions/shared.ts
314
608
  function createBaseGameTransaction({
315
609
  config,
316
610
  game,
317
- owner,
318
- sender,
611
+ playerAddress,
319
612
  gasBudget
320
613
  }) {
321
614
  assertConfiguredBetGame(config, game);
322
615
  const tx = new transactions.Transaction();
323
- tx.setSenderIfNotSet(utils.normalizeSuiAddress(sender ?? owner));
616
+ tx.setSenderIfNotSet(utils.normalizeSuiAddress(playerAddress));
324
617
  tx.setGasBudgetIfNotSet(gasBudget ?? DEFAULT_GAS_BUDGET_MIST);
325
618
  return tx;
326
619
  }
327
620
  function buildSharedStandardGameBetCall({
328
621
  config,
329
- owner,
330
- sender,
622
+ playerAddress,
331
623
  coinType,
332
624
  stake,
333
625
  cashStake,
334
626
  betCount,
335
627
  metadata,
628
+ partner,
336
629
  allowGasCoinShortcut = true,
337
630
  buildRewardCoin
338
631
  }) {
339
632
  return (tx) => {
340
- const normalizedOwner = utils.normalizeSuiAddress(sender ?? owner);
633
+ const normalizedPlayerAddress = utils.normalizeSuiAddress(playerAddress);
341
634
  const normalizedCoinType = utils.normalizeStructTag(coinType);
342
- const resolvedStake = toBigIntAmount(stake, "stake");
343
- const resolvedCashStake = toBigIntAmount(cashStake ?? stake, "cashStake");
344
- const resolvedBetCount = toBigIntAmount(betCount ?? 1, "betCount");
345
- const encodedMetadata = encodeBetMetadata(metadata);
346
- const pythPriceInfoObjectId = resolvePythPriceInfoObjectId(
635
+ const resolvedStake = toBigInt(stake);
636
+ const resolvedCashStake = toBigInt(cashStake ?? stake);
637
+ const resolvedBetCount = toBigInt(betCount ?? 1);
638
+ const encodedMetadata = encodeBetMetadata(metadata, partner);
639
+ const priceInfoObjectId = resolvePriceInfoObjectId(
347
640
  config,
348
641
  normalizedCoinType
349
642
  );
@@ -355,16 +648,16 @@ function buildSharedStandardGameBetCall({
355
648
  const rewardCoin = buildRewardCoin({
356
649
  tx,
357
650
  config,
358
- owner: normalizedOwner,
651
+ playerAddress: normalizedPlayerAddress,
359
652
  coinType: normalizedCoinType,
360
653
  stake: resolvedStake,
361
654
  cashStake: resolvedCashStake,
362
655
  betCount: resolvedBetCount,
363
656
  metadata: encodedMetadata,
364
- pythPriceInfoObjectId,
657
+ priceInfoObjectId,
365
658
  betCoin
366
659
  });
367
- tx.transferObjects([rewardCoin], tx.pure.address(normalizedOwner));
660
+ tx.transferObjects([rewardCoin], tx.pure.address(normalizedPlayerAddress));
368
661
  return rewardCoin;
369
662
  };
370
663
  }
@@ -386,20 +679,20 @@ function buildCoinflipTransaction(options) {
386
679
  stake,
387
680
  betCount,
388
681
  metadata,
389
- pythPriceInfoObjectId,
682
+ priceInfoObjectId,
390
683
  betCoin
391
684
  }) => play({
392
- package: config.gamesPackageId.coinflip,
685
+ package: config.packageIds.coinflip,
393
686
  typeArguments: [coinType],
394
687
  arguments: [
395
- config.sweetHousePackageId,
688
+ config.packageIds.sweetHouse,
396
689
  stake,
397
690
  betCoin,
398
691
  betCount,
399
692
  options.side === "tails",
400
693
  metadata.keys,
401
694
  metadata.values,
402
- pythPriceInfoObjectId
695
+ priceInfoObjectId
403
696
  ]
404
697
  })(tx)
405
698
  });
@@ -432,7 +725,7 @@ function play2(options) {
432
725
 
433
726
  // src/transactions/limbo.ts
434
727
  function buildLimboTransaction(options) {
435
- const scale = options.scale ?? LIMBO_MULTIPLIER_SCALE;
728
+ const scale = options.scale ?? DEFAULT_LIMBO_MULTIPLIER_SCALE;
436
729
  const numerator = Math.round(options.targetMultiplier * scale);
437
730
  return buildSharedStandardGameBetTransaction({
438
731
  ...options,
@@ -444,13 +737,13 @@ function buildLimboTransaction(options) {
444
737
  stake,
445
738
  betCount,
446
739
  metadata,
447
- pythPriceInfoObjectId,
740
+ priceInfoObjectId,
448
741
  betCoin
449
742
  }) => play2({
450
- package: config.gamesPackageId.limbo,
743
+ package: config.packageIds.limbo,
451
744
  typeArguments: [coinType],
452
745
  arguments: [
453
- config.sweetHousePackageId,
746
+ config.packageIds.sweetHouse,
454
747
  stake,
455
748
  betCoin,
456
749
  betCount,
@@ -458,7 +751,7 @@ function buildLimboTransaction(options) {
458
751
  BigInt(scale),
459
752
  metadata.keys,
460
753
  metadata.values,
461
- pythPriceInfoObjectId
754
+ priceInfoObjectId
462
755
  ]
463
756
  })(tx)
464
757
  });
@@ -490,7 +783,7 @@ function play3(options) {
490
783
 
491
784
  // src/transactions/plinko.ts
492
785
  function buildPlinkoTransaction(options) {
493
- const configId = toU8Number(options.configId, "configId");
786
+ const configId = toU8(options.configId);
494
787
  return buildSharedStandardGameBetTransaction({
495
788
  ...options,
496
789
  game: "plinko",
@@ -501,134 +794,35 @@ function buildPlinkoTransaction(options) {
501
794
  stake,
502
795
  betCount,
503
796
  metadata,
504
- pythPriceInfoObjectId,
797
+ priceInfoObjectId,
505
798
  betCoin
506
799
  }) => play3({
507
- package: config.gamesPackageId.plinko,
800
+ package: config.packageIds.plinko,
508
801
  typeArguments: [coinType],
509
802
  arguments: [
510
- config.sweetHousePackageId,
803
+ config.packageIds.sweetHouse,
511
804
  stake,
512
805
  betCoin,
513
806
  betCount,
514
807
  configId,
515
808
  metadata.keys,
516
809
  metadata.values,
517
- pythPriceInfoObjectId
810
+ priceInfoObjectId
518
811
  ]
519
812
  })(tx)
520
813
  });
521
814
  }
522
- var $moduleName = "0x0000000000000000000000000000000000000000000000000000000000000001::type_name";
523
- var TypeName = new MoveStruct({ name: `${$moduleName}::TypeName`, fields: {
524
- name: bcs.bcs.string()
525
- } });
526
-
527
- // src/contracts/pvp-coinflip/pvp_coinflip.ts
528
- var $moduleName2 = "0xb43cf6583c0c15315c7e66f173af4be79ac40c38aad1fd92ec08638ab2026202::pvp_coinflip";
529
- function GameCreatedEvent(...typeParameters) {
530
- return new MoveStruct({ name: `${$moduleName2}::GameCreatedEvent<${typeParameters[0].name}>`, fields: {
531
- game_id: bcs.bcs.Address,
532
- creator: bcs.bcs.Address,
533
- creator_is_tails: bcs.bcs.bool(),
534
- is_private: bcs.bcs.bool(),
535
- joiner_is_tails: bcs.bcs.bool(),
536
- stake_per_player: bcs.bcs.u64(),
537
- house_edge_bps: bcs.bcs.u64(),
538
- coin_type: TypeName
539
- } });
540
- }
541
- function GameResolvedEvent(...typeParameters) {
542
- return new MoveStruct({ name: `${$moduleName2}::GameResolvedEvent<${typeParameters[0].name}>`, fields: {
543
- game_id: bcs.bcs.Address,
544
- creator: bcs.bcs.Address,
545
- joiner: bcs.bcs.Address,
546
- winner: bcs.bcs.Address,
547
- creator_is_tails: bcs.bcs.bool(),
548
- is_private: bcs.bcs.bool(),
549
- joiner_is_tails: bcs.bcs.bool(),
550
- stake_per_player: bcs.bcs.u64(),
551
- total_pot: bcs.bcs.u64(),
552
- house_edge_amount: bcs.bcs.u64(),
553
- payout_amount: bcs.bcs.u64(),
554
- coin_type: TypeName
555
- } });
556
- }
557
- function GameCancelledEvent(...typeParameters) {
558
- return new MoveStruct({ name: `${$moduleName2}::GameCancelledEvent<${typeParameters[0].name}>`, fields: {
559
- game_id: bcs.bcs.Address,
560
- creator: bcs.bcs.Address,
561
- creator_is_tails: bcs.bcs.bool(),
562
- is_private: bcs.bcs.bool(),
563
- stake_per_player: bcs.bcs.u64(),
564
- coin_type: TypeName
565
- } });
566
- }
567
- function createGame(options) {
568
- const packageAddress = options.package ?? "0xb43cf6583c0c15315c7e66f173af4be79ac40c38aad1fd92ec08638ab2026202";
569
- const argumentsTypes = [
570
- null,
571
- null,
572
- "bool",
573
- "bool",
574
- "vector<0x1::string::String>",
575
- "vector<vector<u8>>"
576
- ];
577
- return (tx) => tx.moveCall({
578
- package: packageAddress,
579
- module: "pvp_coinflip",
580
- function: "create_game",
581
- arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
582
- typeArguments: options.typeArguments
583
- });
584
- }
585
- function joinGame(options) {
586
- const packageAddress = options.package ?? "0xb43cf6583c0c15315c7e66f173af4be79ac40c38aad1fd92ec08638ab2026202";
587
- const argumentsTypes = [
588
- "0x2::object::ID",
589
- null,
590
- null,
591
- "vector<0x1::string::String>",
592
- "vector<vector<u8>>",
593
- null,
594
- "0x2::clock::Clock",
595
- "0x2::random::Random"
596
- ];
597
- return (tx) => tx.moveCall({
598
- package: packageAddress,
599
- module: "pvp_coinflip",
600
- function: "join_game",
601
- arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
602
- typeArguments: options.typeArguments
603
- });
604
- }
605
- function cancelGame(options) {
606
- const packageAddress = options.package ?? "0xb43cf6583c0c15315c7e66f173af4be79ac40c38aad1fd92ec08638ab2026202";
607
- const argumentsTypes = [
608
- "0x2::object::ID",
609
- null
610
- ];
611
- return (tx) => tx.moveCall({
612
- package: packageAddress,
613
- module: "pvp_coinflip",
614
- function: "cancel_game",
615
- arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
616
- typeArguments: options.typeArguments
617
- });
618
- }
619
-
620
- // src/transactions/pvp-coinflip.ts
621
815
  function buildPvPCoinflipTransaction(action, options) {
622
816
  const tx = createBaseGameTransaction({
623
817
  ...options,
624
818
  game: "pvp-coinflip"
625
819
  });
626
820
  const normalizedCoinType = utils.normalizeStructTag(options.coinType);
627
- const encodedMetadata = encodeBetMetadata(options.metadata);
821
+ const encodedMetadata = encodeBetMetadata(options.metadata, options.partner);
628
822
  switch (action) {
629
823
  case "create": {
630
824
  const createOptions = options;
631
- const stake = toBigIntAmount(createOptions.stake, "stake");
825
+ const stake = toBigInt(createOptions.stake);
632
826
  const betCoin = tx.coin({
633
827
  type: normalizedCoinType,
634
828
  balance: stake,
@@ -636,10 +830,10 @@ function buildPvPCoinflipTransaction(action, options) {
636
830
  });
637
831
  tx.add(
638
832
  createGame({
639
- package: createOptions.config.gamesPackageId["pvp-coinflip"],
833
+ package: createOptions.config.packageIds.pvpCoinflip,
640
834
  typeArguments: [normalizedCoinType],
641
835
  arguments: [
642
- createOptions.config.sweetHousePackageId,
836
+ createOptions.config.packageIds.sweetHouse,
643
837
  betCoin,
644
838
  createOptions.side === "tails",
645
839
  Boolean(createOptions.isPrivate),
@@ -652,23 +846,21 @@ function buildPvPCoinflipTransaction(action, options) {
652
846
  }
653
847
  case "join": {
654
848
  const joinOptions = options;
655
- const stake = toBigIntAmount(joinOptions.stake, "stake");
656
- const betCoin = tx.coin({
657
- type: normalizedCoinType,
658
- balance: stake,
659
- useGasCoin: joinOptions.allowGasCoinShortcut
660
- });
849
+ const priceInfoObjectId = resolvePriceInfoObjectId(
850
+ joinOptions.config,
851
+ normalizedCoinType
852
+ );
661
853
  tx.add(
662
854
  joinGame({
663
- package: joinOptions.config.gamesPackageId["pvp-coinflip"],
855
+ package: joinOptions.config.packageIds.pvpCoinflip,
664
856
  typeArguments: [normalizedCoinType],
665
857
  arguments: [
666
858
  joinOptions.gameId,
667
- joinOptions.config.sweetHousePackageId,
668
- betCoin,
859
+ joinOptions.config.packageIds.sweetHouse,
860
+ tx.add(joinOptions.betCoin),
669
861
  encodedMetadata.keys,
670
862
  encodedMetadata.values,
671
- joinOptions.extraObjectId
863
+ priceInfoObjectId
672
864
  ]
673
865
  })
674
866
  );
@@ -678,11 +870,11 @@ function buildPvPCoinflipTransaction(action, options) {
678
870
  const cancelOptions = options;
679
871
  tx.add(
680
872
  cancelGame({
681
- package: cancelOptions.config.gamesPackageId["pvp-coinflip"],
873
+ package: cancelOptions.config.packageIds.pvpCoinflip,
682
874
  typeArguments: [normalizedCoinType],
683
875
  arguments: [
684
876
  cancelOptions.gameId,
685
- cancelOptions.config.sweetHousePackageId
877
+ cancelOptions.config.packageIds.sweetHouse
686
878
  ]
687
879
  })
688
880
  );
@@ -721,7 +913,7 @@ function play4(options) {
721
913
 
722
914
  // src/transactions/range.ts
723
915
  function buildRangeTransaction(options) {
724
- const scale = options.scale ?? RANGE_FIXED_POINT_SCALE;
916
+ const scale = options.scale ?? DEFAULT_RANGE_SCALE;
725
917
  const leftPoint = Math.round(options.leftPoint * scale);
726
918
  const rightPoint = Math.round(options.rightPoint * scale);
727
919
  return buildSharedStandardGameBetTransaction({
@@ -734,13 +926,13 @@ function buildRangeTransaction(options) {
734
926
  stake,
735
927
  betCount,
736
928
  metadata,
737
- pythPriceInfoObjectId,
929
+ priceInfoObjectId,
738
930
  betCoin
739
931
  }) => play4({
740
- package: config.gamesPackageId.range,
932
+ package: config.packageIds.range,
741
933
  typeArguments: [coinType],
742
934
  arguments: [
743
- config.sweetHousePackageId,
935
+ config.packageIds.sweetHouse,
744
936
  stake,
745
937
  betCoin,
746
938
  betCount,
@@ -749,7 +941,7 @@ function buildRangeTransaction(options) {
749
941
  Boolean(options.outOfRange),
750
942
  metadata.keys,
751
943
  metadata.values,
752
- pythPriceInfoObjectId
944
+ priceInfoObjectId
753
945
  ]
754
946
  })(tx)
755
947
  });
@@ -781,7 +973,7 @@ function play5(options) {
781
973
 
782
974
  // src/transactions/wheel.ts
783
975
  function buildWheelTransaction(options) {
784
- const configId = toU8Number(options.configId, "configId");
976
+ const configId = toU8(options.configId);
785
977
  return buildSharedStandardGameBetTransaction({
786
978
  ...options,
787
979
  game: "wheel",
@@ -792,87 +984,64 @@ function buildWheelTransaction(options) {
792
984
  stake,
793
985
  betCount,
794
986
  metadata,
795
- pythPriceInfoObjectId,
987
+ priceInfoObjectId,
796
988
  betCoin
797
989
  }) => play5({
798
- package: config.gamesPackageId.wheel,
990
+ package: config.packageIds.wheel,
799
991
  typeArguments: [coinType],
800
992
  arguments: [
801
- config.sweetHousePackageId,
993
+ config.packageIds.sweetHouse,
802
994
  stake,
803
995
  betCoin,
804
996
  betCount,
805
997
  configId,
806
998
  metadata.keys,
807
999
  metadata.values,
808
- pythPriceInfoObjectId
1000
+ priceInfoObjectId
809
1001
  ]
810
1002
  })(tx)
811
1003
  });
812
1004
  }
813
- var $moduleName3 = "0x0000000000000000000000000000000000000000000000000000000000000001::type_name";
814
- var TypeName2 = new MoveStruct({ name: `${$moduleName3}::TypeName`, fields: {
815
- name: bcs.bcs.string()
816
- } });
817
- var $moduleName4 = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::i64";
818
- var I64 = new MoveStruct({ name: `${$moduleName4}::I64`, fields: {
819
- bits: bcs.bcs.u64()
820
- } });
821
1005
 
822
- // src/contracts/core/float.ts
823
- var $moduleName5 = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::float";
824
- var Float = new MoveStruct({ name: `${$moduleName5}::Float`, fields: {
825
- is_negative: bcs.bcs.bool(),
826
- exp: I64,
827
- mant: bcs.bcs.u64()
828
- } });
829
- var $moduleName6 = "0x2::vec_map";
830
- function Entry(...typeParameters) {
831
- return new MoveStruct({ name: `${$moduleName6}::Entry<${typeParameters[0].name}, ${typeParameters[1].name}>`, fields: {
832
- key: typeParameters[0],
833
- value: typeParameters[1]
834
- } });
835
- }
836
- function VecMap(...typeParameters) {
837
- return new MoveStruct({ name: `${$moduleName6}::VecMap<${typeParameters[0].name}, ${typeParameters[1].name}>`, fields: {
838
- contents: bcs.bcs.vector(Entry(typeParameters[0], typeParameters[1]))
839
- } });
840
- }
841
-
842
- // src/contracts/core/core.ts
843
- var $moduleName7 = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::core";
844
- function BetResultEvent(...typeParameters) {
845
- return new MoveStruct({ name: `${$moduleName7}::BetResultEvent<${typeParameters[0].name}>`, fields: {
846
- player: bcs.bcs.Address,
847
- coin_type: TypeName2,
848
- stake_amount: bcs.bcs.u64(),
849
- unsafe_oracle_usd_coin_price: Float,
850
- adjusted_oracle_usd_coin_price: Float,
851
- outcome_amount: bcs.bcs.u64(),
852
- game_details: VecMap(bcs.bcs.string(), bcs.bcs.vector(bcs.bcs.u8())),
853
- metadata: VecMap(bcs.bcs.string(), bcs.bcs.vector(bcs.bcs.u8()))
854
- } });
855
- }
1006
+ // src/client.ts
856
1007
  function suigar({
857
1008
  name = "suigar",
858
- ...options
1009
+ partner
859
1010
  } = {}) {
860
1011
  return {
861
1012
  name,
862
1013
  register: (client) => {
863
- return new SuigarClient({ client, options });
1014
+ return new SuigarClient({ client, partner });
864
1015
  }
865
1016
  };
866
1017
  }
867
1018
  var SuigarClient = class {
868
1019
  #client;
869
1020
  #config;
1021
+ #partner;
870
1022
  constructor({
871
1023
  client,
872
- options
1024
+ partner
873
1025
  }) {
874
1026
  this.#client = client;
875
- this.#config = resolveSuigarConfig(options);
1027
+ this.#partner = partner;
1028
+ const network = this.#client.network;
1029
+ if (!SUPPORTED_SUI_NETWORKS.includes(network)) {
1030
+ throw new Error(`Unsupported network: ${network}`);
1031
+ }
1032
+ this.#config = resolveSuigarConfig(network);
1033
+ }
1034
+ /**
1035
+ * Returns the resolved SDK configuration for the connected network.
1036
+ *
1037
+ * This is primarily useful for debugging or inspecting which package ids,
1038
+ * supported coin types, and price info object ids the SDK resolved for the
1039
+ * current client network.
1040
+ *
1041
+ * @returns Network-resolved Suigar configuration.
1042
+ */
1043
+ getConfig() {
1044
+ return this.#config;
876
1045
  }
877
1046
  /**
878
1047
  * Builds a transaction with the configured Sui client and encodes the resulting BCS bytes as base64.
@@ -890,9 +1059,86 @@ var SuigarClient = class {
890
1059
  return utils.toBase64(bytes);
891
1060
  }
892
1061
  /**
893
- * BCS struct constructors for decoding Suigar events emitted on-chain.
1062
+ * Lists unresolved PvP coinflip games from the configured registry and resolves
1063
+ * each entry into parsed onchain game state.
1064
+ *
1065
+ * This fetches dynamic fields from the PvP coinflip registry object, then bulk
1066
+ * loads the referenced game objects through `client.core.getObjects()`. Registry
1067
+ * membership is the unresolved-state signal: when a game is joined and resolved,
1068
+ * the Move flow removes it from the registry and deletes the live `Game` object.
1069
+ * Use this when a product needs the current set of open PvP coinflip matches for
1070
+ * browsing or lobby views.
1071
+ *
1072
+ * @param options Optional dynamic field pagination forwarded to `listDynamicFields()`, excluding `parentId`.
1073
+ * Supported options such as `limit`, `cursor`, and `signal` are forwarded to the
1074
+ * underlying lookup calls. Pass `throwOnError: true` to fail the whole lookup
1075
+ * when any referenced game object cannot be fetched or parsed. By default,
1076
+ * failed per-object lookups are skipped and only successfully parsed unresolved
1077
+ * games are returned.
1078
+ * @returns Parsed unresolved PvP coinflip game objects for the requested
1079
+ * registry page. When `throwOnError` is `false`, entries that fail object fetch
1080
+ * or parse are omitted from the returned array.
1081
+ */
1082
+ async getPvPCoinflipGames(options = {
1083
+ limit: 50
1084
+ }) {
1085
+ const { throwOnError = false, ...listOptions } = options;
1086
+ const { dynamicFields } = await this.#client.core.listDynamicFields({
1087
+ ...listOptions,
1088
+ parentId: this.#config.registryIds.pvpCoinflip
1089
+ });
1090
+ const { objects } = await this.#client.core.getObjects({
1091
+ objectIds: dynamicFields.map(({ childId }) => childId),
1092
+ signal: listOptions.signal,
1093
+ include: {
1094
+ content: true
1095
+ }
1096
+ });
1097
+ const resolvedGames = objects.map((object) => {
1098
+ try {
1099
+ if (object instanceof Error) {
1100
+ throw object;
1101
+ }
1102
+ if (!object.content) {
1103
+ throw new Error(
1104
+ "Unable to resolve PvP coinflip game from retrieved object"
1105
+ );
1106
+ }
1107
+ return {
1108
+ ...Game.parse(object.content),
1109
+ coinType: parseCoinType(object.type)
1110
+ };
1111
+ } catch (error) {
1112
+ return error instanceof Error ? error : new Error(String(error));
1113
+ }
1114
+ });
1115
+ if (throwOnError) {
1116
+ const firstError = resolvedGames.find((game) => game instanceof Error);
1117
+ if (firstError) {
1118
+ throw firstError;
1119
+ }
1120
+ }
1121
+ return resolvedGames.flatMap(
1122
+ (game) => game instanceof Error ? [] : [game]
1123
+ );
1124
+ }
1125
+ /**
1126
+ * BCS struct constructors for decoding on-chain objects and events related to Suigar games.
1127
+ *
1128
+ * These can be used to parse the `content` field of on-chain objects and events into structured data with the
1129
+ * expected types. For example, use `client.suigar.bcs.PvPCoinflipGame.parse(object.content)` to decode a PvP
1130
+ * coinflip game object.
1131
+ *
1132
+ * Note that these constructors are not meant for encoding transaction arguments, as the SDK's transaction
1133
+ * builders handle argument serialization internally. Use these primarily for decoding and parsing on-chain data.
894
1134
  */
895
1135
  bcs = {
1136
+ // Objects
1137
+ /**
1138
+ * Object representing the state of a PvP coinflip game, as stored on-chain.
1139
+ */
1140
+ PvPCoinflipGame: Game,
1141
+ // Events
896
1142
  /**
897
1143
  * Event emitted at the end of a standard game (e.g., Coinflip, Limbo), containing the result and payout information.
898
1144
  */
@@ -900,15 +1146,15 @@ var SuigarClient = class {
900
1146
  /**
901
1147
  * Event emitted when a PvP Coinflip game is created, containing the game configuration and initial state.
902
1148
  */
903
- PvPCoinflipGameCreated: GameCreatedEvent,
1149
+ PvPCoinflipGameCreatedEvent: GameCreatedEvent,
904
1150
  /**
905
1151
  * Event emitted when a PvP Coinflip game is resolved, containing the final outcome.
906
1152
  */
907
- PvPCoinflipGameResolved: GameResolvedEvent,
1153
+ PvPCoinflipGameResolvedEvent: GameResolvedEvent,
908
1154
  /**
909
1155
  * Event emitted when a PvP Coinflip game is cancelled.
910
1156
  */
911
- PvPCoinflipGameCancelled: GameCancelledEvent
1157
+ PvPCoinflipGameCancelledEvent: GameCancelledEvent
912
1158
  };
913
1159
  /**
914
1160
  * Transaction builders for Suigar games.
@@ -926,27 +1172,32 @@ var SuigarClient = class {
926
1172
  case "coinflip":
927
1173
  return buildCoinflipTransaction({
928
1174
  ...options,
929
- config: this.#config
1175
+ config: this.#config,
1176
+ partner: this.#partner
930
1177
  });
931
1178
  case "limbo":
932
1179
  return buildLimboTransaction({
933
1180
  ...options,
934
- config: this.#config
1181
+ config: this.#config,
1182
+ partner: this.#partner
935
1183
  });
936
1184
  case "plinko":
937
1185
  return buildPlinkoTransaction({
938
1186
  ...options,
939
- config: this.#config
1187
+ config: this.#config,
1188
+ partner: this.#partner
940
1189
  });
941
1190
  case "range":
942
1191
  return buildRangeTransaction({
943
1192
  ...options,
944
- config: this.#config
1193
+ config: this.#config,
1194
+ partner: this.#partner
945
1195
  });
946
1196
  case "wheel":
947
1197
  return buildWheelTransaction({
948
1198
  ...options,
949
- config: this.#config
1199
+ config: this.#config,
1200
+ partner: this.#partner
950
1201
  });
951
1202
  default:
952
1203
  throw new Error(`Unsupported game: ${gameId}`);
@@ -960,12 +1211,47 @@ var SuigarClient = class {
960
1211
  * @returns Prepared PvP coinflip transaction.
961
1212
  */
962
1213
  createPvPCoinflipTransaction: (action, options) => {
963
- return buildPvPCoinflipTransaction(action, {
964
- ...options,
965
- config: this.#config
966
- });
1214
+ switch (action) {
1215
+ case "create":
1216
+ return buildPvPCoinflipTransaction("create", {
1217
+ ...options,
1218
+ config: this.#config,
1219
+ partner: this.#partner
1220
+ });
1221
+ case "join": {
1222
+ const joinOptions = options;
1223
+ return buildPvPCoinflipTransaction("join", {
1224
+ ...joinOptions,
1225
+ betCoin: this.#createPvPCoinflipBetCoin(joinOptions),
1226
+ config: this.#config,
1227
+ partner: this.#partner
1228
+ });
1229
+ }
1230
+ case "cancel":
1231
+ return buildPvPCoinflipTransaction("cancel", {
1232
+ ...options,
1233
+ config: this.#config,
1234
+ partner: this.#partner
1235
+ });
1236
+ default:
1237
+ throw new Error(`Unsupported PvP coinflip action: ${action}`);
1238
+ }
967
1239
  }
968
1240
  };
1241
+ #createPvPCoinflipBetCoin(options) {
1242
+ return async (tx) => {
1243
+ const { json } = await Game.get({
1244
+ client: this.#client,
1245
+ objectId: options.gameId
1246
+ });
1247
+ return tx.coin({
1248
+ type: options.coinType,
1249
+ balance: BigInt(json.stake_per_player),
1250
+ useGasCoin: options.allowGasCoinShortcut
1251
+ });
1252
+ };
1253
+ }
969
1254
  };
970
1255
 
1256
+ exports.SuigarClient = SuigarClient;
971
1257
  exports.suigar = suigar;