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

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
@@ -3,6 +3,7 @@
3
3
  var utils = require('@mysten/sui/utils');
4
4
  var bcs = require('@mysten/sui/bcs');
5
5
  var transactions = require('@mysten/sui/transactions');
6
+ var client = require('@mysten/sui/client');
6
7
 
7
8
  // src/client.ts
8
9
  var MOVE_STDLIB_ADDRESS = utils.normalizeSuiAddress("0x1");
@@ -239,6 +240,12 @@ function VecMap2(...typeParameters) {
239
240
 
240
241
  // src/contracts/pvp-coinflip/pvp_coinflip.ts
241
242
  var $moduleName9 = "0xb43cf6583c0c15315c7e66f173af4be79ac40c38aad1fd92ec08638ab2026202::pvp_coinflip";
243
+ var PvpCoinflipSettingsKey = new MoveStruct({
244
+ name: `${$moduleName9}::PvpCoinflipSettingsKey`,
245
+ fields: {
246
+ dummy_field: bcs.bcs.bool()
247
+ }
248
+ });
242
249
  var Game = new MoveStruct({
243
250
  name: `${$moduleName9}::Game<phantom T0>`,
244
251
  fields: {
@@ -295,6 +302,14 @@ var GameCancelledEvent = new MoveStruct({
295
302
  coin_type: TypeName2
296
303
  }
297
304
  });
305
+ var Parameters = new MoveStruct({
306
+ name: `${$moduleName9}::Parameters<phantom T0>`,
307
+ fields: {
308
+ id: bcs.bcs.Address,
309
+ house_edge_bps: bcs.bcs.u64(),
310
+ min_stake: bcs.bcs.u64()
311
+ }
312
+ });
298
313
  function createGame(options) {
299
314
  const packageAddress = options.package ?? "0xb43cf6583c0c15315c7e66f173af4be79ac40c38aad1fd92ec08638ab2026202";
300
315
  const argumentsTypes = [
@@ -416,6 +431,7 @@ var REGISTRY_IDS = {
416
431
  };
417
432
 
418
433
  // src/helpers/config.ts
434
+ var DEFAULT_CACHE_TTL_MS = 30 * 60 * 1e3;
419
435
  function resolveSuigarConfig(network) {
420
436
  const packageIds = PACKAGE_IDS[network];
421
437
  const registryIds = REGISTRY_IDS[network];
@@ -469,7 +485,7 @@ function resolvePriceInfoObjectId(config, coinType) {
469
485
  function resolveSupportedCoin(config, coinType) {
470
486
  const [supportedCoin] = Object.entries(config.coinTypes).find(([_, value]) => value === coinType) ?? [];
471
487
  if (!supportedCoin) {
472
- throw new Error(
488
+ throw new RangeError(
473
489
  `Unsupported coin type ${coinType}. Supported coin types: ${Object.values(
474
490
  config.coinTypes
475
491
  ).join(", ")}`
@@ -477,6 +493,22 @@ function resolveSupportedCoin(config, coinType) {
477
493
  }
478
494
  return supportedCoin;
479
495
  }
496
+ function replaceStructTagAddress(structName, address) {
497
+ return utils.normalizeStructTag({
498
+ ...utils.parseStructTag(structName),
499
+ address
500
+ });
501
+ }
502
+ function resolveGameSettingsKeyType(structName, packageId) {
503
+ return replaceStructTagAddress(structName, packageId);
504
+ }
505
+ function resolveCoinTypeNameForTypeNameKey(structName) {
506
+ const { address } = utils.parseStructTag(structName);
507
+ return replaceStructTagAddress(
508
+ structName,
509
+ utils.normalizeSuiAddress(address).replace(/^0x/, "")
510
+ );
511
+ }
480
512
  var PARTNER_METADATA_KEY = "partner";
481
513
  var RESERVED_METADATA_KEYS = /* @__PURE__ */ new Set([PARTNER_METADATA_KEY, "referrer"]);
482
514
  var textEncoder = new TextEncoder();
@@ -521,8 +553,22 @@ function encodeBetMetadata(metadata, partner) {
521
553
  values
522
554
  };
523
555
  }
524
-
525
- // src/contracts/coinflip/coinflip.ts
556
+ var $moduleName10 = "0xb35c5f286c443752afc8ccb40125a578a4f32df35617170ccfa17fe180ab80ea::coinflip";
557
+ var CoinFlipSettingsKey = new MoveStruct({
558
+ name: `${$moduleName10}::CoinFlipSettingsKey`,
559
+ fields: {
560
+ dummy_field: bcs.bcs.bool()
561
+ }
562
+ });
563
+ var Parameters2 = new MoveStruct({
564
+ name: `${$moduleName10}::Parameters<phantom T0>`,
565
+ fields: {
566
+ id: bcs.bcs.Address,
567
+ house_edge: bcs.bcs.u64(),
568
+ min_stake: bcs.bcs.u64(),
569
+ max_stake: bcs.bcs.u64()
570
+ }
571
+ });
526
572
  function play(options) {
527
573
  const packageAddress = options.package ?? "0xb35c5f286c443752afc8ccb40125a578a4f32df35617170ccfa17fe180ab80ea";
528
574
  const argumentsTypes = [
@@ -550,36 +596,45 @@ var DEFAULT_RANGE_SCALE = 1e6;
550
596
  var DEFAULT_LIMBO_MULTIPLIER_SCALE = 100;
551
597
 
552
598
  // 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}`);
599
+ function assertFiniteNumber(value, errorMessage) {
600
+ if (typeof value !== "number" || !Number.isFinite(value)) {
601
+ throw new TypeError(`${errorMessage}: ${String(value)}`);
559
602
  }
560
603
  }
561
604
  function toBigInt(value) {
562
- if (typeof value === "bigint") {
563
- if (value < 0n) {
564
- throw new Error(`Value must be non-negative: ${value}`);
605
+ let result;
606
+ try {
607
+ if (typeof value === "bigint" || typeof value === "string" || typeof value === "boolean") {
608
+ result = BigInt(value);
609
+ } else {
610
+ assertFiniteNumber(
611
+ value,
612
+ "Value must be a bigint, number, integer string, or boolean"
613
+ );
614
+ result = BigInt(Math.trunc(value));
565
615
  }
566
- return value;
616
+ } catch {
617
+ throw new TypeError(
618
+ `Value must be a bigint, number, integer string, or boolean: ${value}`
619
+ );
567
620
  }
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}`);
621
+ if (result < 0n) {
622
+ throw new RangeError(`Value must be non-negative: ${value}`);
571
623
  }
572
- return BigInt(Math.trunc(value));
624
+ return result;
573
625
  }
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}`);
626
+ function toBoundedInt(value, max, typeName) {
627
+ const num = typeof value === "string" && value.trim() === "" ? NaN : Number(value);
628
+ assertFiniteNumber(num, "Value must be a finite number or integer string");
629
+ if (typeof value === "boolean" || value == null || !Number.isInteger(num) || num < 0 || num > max) {
630
+ throw new RangeError(
631
+ `Value must be a ${typeName} integer (0-${max}): ${value}`
632
+ );
581
633
  }
582
- return value;
634
+ return num;
635
+ }
636
+ function toU8(value) {
637
+ return toBoundedInt(value, 255, "u8");
583
638
  }
584
639
 
585
640
  // src/types/network.type.ts
@@ -599,7 +654,7 @@ new TextDecoder();
599
654
  function parseCoinType(type) {
600
655
  const coinType = utils.parseStructTag(type).typeParams[0];
601
656
  if (!coinType) {
602
- throw new Error(`Unable to parse coin type from ${type}`);
657
+ throw new TypeError(`Unable to parse coin type from ${type}`);
603
658
  }
604
659
  return utils.normalizeStructTag(coinType);
605
660
  }
@@ -697,8 +752,47 @@ function buildCoinflipTransaction(options) {
697
752
  })(tx)
698
753
  });
699
754
  }
755
+ var $moduleName11 = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::i64";
756
+ var I642 = new MoveStruct({
757
+ name: `${$moduleName11}::I64`,
758
+ fields: {
759
+ bits: bcs.bcs.u64()
760
+ }
761
+ });
762
+
763
+ // src/contracts/limbo/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.ts
764
+ var $moduleName12 = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::float";
765
+ var Float2 = new MoveStruct({
766
+ name: `${$moduleName12}::Float`,
767
+ fields: {
768
+ is_negative: bcs.bcs.bool(),
769
+ exp: I642,
770
+ mant: bcs.bcs.u64()
771
+ }
772
+ });
700
773
 
701
774
  // src/contracts/limbo/limbo.ts
775
+ var $moduleName13 = "0x96c7841b9b32c59a219760fd656f1c3aceb53cc74a68ec9844a3a696374309f4::limbo";
776
+ var LimboSettingsKey = new MoveStruct({
777
+ name: `${$moduleName13}::LimboSettingsKey`,
778
+ fields: {
779
+ dummy_field: bcs.bcs.bool()
780
+ }
781
+ });
782
+ var Parameters3 = new MoveStruct({
783
+ name: `${$moduleName13}::Parameters<phantom T0>`,
784
+ fields: {
785
+ id: bcs.bcs.Address,
786
+ min_stake: bcs.bcs.u64(),
787
+ max_stake: bcs.bcs.u64(),
788
+ max_payout: bcs.bcs.u64(),
789
+ min_target_multiplier: Float2,
790
+ max_target_multiplier: Float2,
791
+ max_number_of_games: bcs.bcs.u64(),
792
+ min_rtp: Float2,
793
+ max_rtp: Float2
794
+ }
795
+ });
702
796
  function play2(options) {
703
797
  const packageAddress = options.package ?? "0x96c7841b9b32c59a219760fd656f1c3aceb53cc74a68ec9844a3a696374309f4";
704
798
  const argumentsTypes = [
@@ -756,8 +850,71 @@ function buildLimboTransaction(options) {
756
850
  })(tx)
757
851
  });
758
852
  }
853
+ var $moduleName14 = "0x2::vec_map";
854
+ function Entry3(...typeParameters) {
855
+ return new MoveStruct({
856
+ name: `${$moduleName14}::Entry<${typeParameters[0].name}, ${typeParameters[1].name}>`,
857
+ fields: {
858
+ key: typeParameters[0],
859
+ value: typeParameters[1]
860
+ }
861
+ });
862
+ }
863
+ function VecMap3(...typeParameters) {
864
+ return new MoveStruct({
865
+ name: `${$moduleName14}::VecMap<${typeParameters[0].name}, ${typeParameters[1].name}>`,
866
+ fields: {
867
+ contents: bcs.bcs.vector(Entry3(typeParameters[0], typeParameters[1]))
868
+ }
869
+ });
870
+ }
871
+ var $moduleName15 = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::i64";
872
+ var I643 = new MoveStruct({
873
+ name: `${$moduleName15}::I64`,
874
+ fields: {
875
+ bits: bcs.bcs.u64()
876
+ }
877
+ });
878
+
879
+ // src/contracts/plinko/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.ts
880
+ var $moduleName16 = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::float";
881
+ var Float3 = new MoveStruct({
882
+ name: `${$moduleName16}::Float`,
883
+ fields: {
884
+ is_negative: bcs.bcs.bool(),
885
+ exp: I643,
886
+ mant: bcs.bcs.u64()
887
+ }
888
+ });
759
889
 
760
890
  // src/contracts/plinko/plinko.ts
891
+ var $moduleName17 = "0xd3dd2200883af10811724f0bed97591ad155a02efd6332d471ff8b346030dfb7::plinko";
892
+ var PlinkoSettingsKey = new MoveStruct({
893
+ name: `${$moduleName17}::PlinkoSettingsKey`,
894
+ fields: {
895
+ dummy_field: bcs.bcs.bool()
896
+ }
897
+ });
898
+ var PlinkoConfig = new MoveStruct({
899
+ name: `${$moduleName17}::PlinkoConfig`,
900
+ fields: {
901
+ num_rows: bcs.bcs.u8(),
902
+ multipliers: bcs.bcs.vector(Float3),
903
+ min_stake: bcs.bcs.u64(),
904
+ max_stake: bcs.bcs.u64(),
905
+ is_playable: bcs.bcs.bool()
906
+ }
907
+ });
908
+ var Parameters4 = new MoveStruct({
909
+ name: `${$moduleName17}::Parameters<phantom T0>`,
910
+ fields: {
911
+ id: bcs.bcs.Address,
912
+ min_stake: bcs.bcs.u64(),
913
+ max_stake: bcs.bcs.u64(),
914
+ max_number_of_balls: bcs.bcs.u64(),
915
+ configs: VecMap3(bcs.bcs.u8(), PlinkoConfig)
916
+ }
917
+ });
761
918
  function play3(options) {
762
919
  const packageAddress = options.package ?? "0xd3dd2200883af10811724f0bed97591ad155a02efd6332d471ff8b346030dfb7";
763
920
  const argumentsTypes = [
@@ -881,11 +1038,49 @@ function buildPvPCoinflipTransaction(action, options) {
881
1038
  return tx;
882
1039
  }
883
1040
  default:
884
- throw new Error(`Unsupported PvP coinflip action: ${action}`);
1041
+ throw new RangeError(`Unsupported PvP coinflip action: ${action}`);
885
1042
  }
886
1043
  }
1044
+ var $moduleName18 = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::i64";
1045
+ var I644 = new MoveStruct({
1046
+ name: `${$moduleName18}::I64`,
1047
+ fields: {
1048
+ bits: bcs.bcs.u64()
1049
+ }
1050
+ });
1051
+
1052
+ // src/contracts/range/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.ts
1053
+ var $moduleName19 = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::float";
1054
+ var Float4 = new MoveStruct({
1055
+ name: `${$moduleName19}::Float`,
1056
+ fields: {
1057
+ is_negative: bcs.bcs.bool(),
1058
+ exp: I644,
1059
+ mant: bcs.bcs.u64()
1060
+ }
1061
+ });
887
1062
 
888
1063
  // src/contracts/range/range.ts
1064
+ var $moduleName20 = "0x096a4cf18b3661e76b2c62b90785418345d52f45b272448794f123a4cb6b6416::range";
1065
+ var RangeSettingsKey = new MoveStruct({
1066
+ name: `${$moduleName20}::RangeSettingsKey`,
1067
+ fields: {
1068
+ dummy_field: bcs.bcs.bool()
1069
+ }
1070
+ });
1071
+ var Parameters5 = new MoveStruct({
1072
+ name: `${$moduleName20}::Parameters<phantom T0>`,
1073
+ fields: {
1074
+ id: bcs.bcs.Address,
1075
+ min_stake: bcs.bcs.u64(),
1076
+ max_stake: bcs.bcs.u64(),
1077
+ min_zone_size: bcs.bcs.u64(),
1078
+ max_zone_size: bcs.bcs.u64(),
1079
+ max_number_of_games: bcs.bcs.u64(),
1080
+ min_rtp: Float4,
1081
+ max_rtp: Float4
1082
+ }
1083
+ });
889
1084
  function play4(options) {
890
1085
  const packageAddress = options.package ?? "0x096a4cf18b3661e76b2c62b90785418345d52f45b272448794f123a4cb6b6416";
891
1086
  const argumentsTypes = [
@@ -946,8 +1141,71 @@ function buildRangeTransaction(options) {
946
1141
  })(tx)
947
1142
  });
948
1143
  }
1144
+ var $moduleName21 = "0x2::vec_map";
1145
+ function Entry4(...typeParameters) {
1146
+ return new MoveStruct({
1147
+ name: `${$moduleName21}::Entry<${typeParameters[0].name}, ${typeParameters[1].name}>`,
1148
+ fields: {
1149
+ key: typeParameters[0],
1150
+ value: typeParameters[1]
1151
+ }
1152
+ });
1153
+ }
1154
+ function VecMap4(...typeParameters) {
1155
+ return new MoveStruct({
1156
+ name: `${$moduleName21}::VecMap<${typeParameters[0].name}, ${typeParameters[1].name}>`,
1157
+ fields: {
1158
+ contents: bcs.bcs.vector(Entry4(typeParameters[0], typeParameters[1]))
1159
+ }
1160
+ });
1161
+ }
1162
+ var $moduleName22 = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::i64";
1163
+ var I645 = new MoveStruct({
1164
+ name: `${$moduleName22}::I64`,
1165
+ fields: {
1166
+ bits: bcs.bcs.u64()
1167
+ }
1168
+ });
1169
+
1170
+ // src/contracts/wheel/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.ts
1171
+ var $moduleName23 = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::float";
1172
+ var Float5 = new MoveStruct({
1173
+ name: `${$moduleName23}::Float`,
1174
+ fields: {
1175
+ is_negative: bcs.bcs.bool(),
1176
+ exp: I645,
1177
+ mant: bcs.bcs.u64()
1178
+ }
1179
+ });
949
1180
 
950
1181
  // src/contracts/wheel/wheel.ts
1182
+ var $moduleName24 = "0x0997852ded7e13301c42317004bc49704a893aa82997c5706cebee59053a31b7::wheel";
1183
+ var WheelSettingsKey = new MoveStruct({
1184
+ name: `${$moduleName24}::WheelSettingsKey`,
1185
+ fields: {
1186
+ dummy_field: bcs.bcs.bool()
1187
+ }
1188
+ });
1189
+ var WheelConfig = new MoveStruct({
1190
+ name: `${$moduleName24}::WheelConfig`,
1191
+ fields: {
1192
+ num_cases: bcs.bcs.u8(),
1193
+ multipliers: bcs.bcs.vector(Float5),
1194
+ min_stake: bcs.bcs.u64(),
1195
+ max_stake: bcs.bcs.u64(),
1196
+ is_playable: bcs.bcs.bool()
1197
+ }
1198
+ });
1199
+ var Parameters6 = new MoveStruct({
1200
+ name: `${$moduleName24}::Parameters<phantom T0>`,
1201
+ fields: {
1202
+ id: bcs.bcs.Address,
1203
+ min_stake: bcs.bcs.u64(),
1204
+ max_stake: bcs.bcs.u64(),
1205
+ max_number_of_spins: bcs.bcs.u64(),
1206
+ configs: VecMap4(bcs.bcs.u8(), WheelConfig)
1207
+ }
1208
+ });
951
1209
  function play5(options) {
952
1210
  const packageAddress = options.package ?? "0x0997852ded7e13301c42317004bc49704a893aa82997c5706cebee59053a31b7";
953
1211
  const argumentsTypes = [
@@ -1002,16 +1260,127 @@ function buildWheelTransaction(options) {
1002
1260
  })(tx)
1003
1261
  });
1004
1262
  }
1263
+ var TtlClientCache = class extends client.ClientCache {
1264
+ #ttlMs;
1265
+ constructor({ ttlMs, ...options }) {
1266
+ super({
1267
+ ...options,
1268
+ prefix: options.prefix ?? ["ttl"]
1269
+ });
1270
+ this.#ttlMs = ttlMs;
1271
+ }
1272
+ read(key, load, options) {
1273
+ if (options?.ignoreCache) {
1274
+ super.clear(key);
1275
+ }
1276
+ if (this.#ttlMs <= 0) {
1277
+ return load();
1278
+ }
1279
+ const cached = super.read(
1280
+ key,
1281
+ () => this.#loadEntry(key, load)
1282
+ );
1283
+ if (cached && cached.expiresAt > Date.now()) {
1284
+ return cached.value;
1285
+ }
1286
+ super.clear(key);
1287
+ return super.read(
1288
+ key,
1289
+ () => this.#loadEntry(key, load)
1290
+ ).value;
1291
+ }
1292
+ readSync(key, load, options) {
1293
+ if (options?.ignoreCache) {
1294
+ super.clear(key);
1295
+ }
1296
+ if (this.#ttlMs <= 0) {
1297
+ return load();
1298
+ }
1299
+ const cached = super.readSync(
1300
+ key,
1301
+ () => this.#loadSyncEntry(load)
1302
+ );
1303
+ if (cached.expiresAt > Date.now()) {
1304
+ return cached.value;
1305
+ }
1306
+ super.clear(key);
1307
+ return super.readSync(key, () => this.#loadSyncEntry(load)).value;
1308
+ }
1309
+ #loadEntry(key, load) {
1310
+ const value = load();
1311
+ const entry = {
1312
+ value,
1313
+ expiresAt: Date.now() + this.#ttlMs
1314
+ };
1315
+ if (isPromiseLike(value)) {
1316
+ entry.value = Promise.resolve(value).then((resolved) => {
1317
+ super.clear(key);
1318
+ super.read(key, () => ({
1319
+ value: resolved,
1320
+ expiresAt: Date.now() + this.#ttlMs
1321
+ }));
1322
+ return resolved;
1323
+ }).catch((error) => {
1324
+ super.clear(key);
1325
+ throw error;
1326
+ });
1327
+ }
1328
+ return entry;
1329
+ }
1330
+ #loadSyncEntry(load) {
1331
+ return {
1332
+ value: load(),
1333
+ expiresAt: Date.now() + this.#ttlMs
1334
+ };
1335
+ }
1336
+ };
1337
+ function isPromiseLike(value) {
1338
+ return (typeof value === "object" || typeof value === "function") && value !== null && "then" in value;
1339
+ }
1340
+
1341
+ // src/types/game-settings.type.ts
1342
+ var GAME_SETTINGS = {
1343
+ coinflip: {
1344
+ settingsKey: CoinFlipSettingsKey,
1345
+ parameters: Parameters2
1346
+ },
1347
+ limbo: {
1348
+ settingsKey: LimboSettingsKey,
1349
+ parameters: Parameters3
1350
+ },
1351
+ plinko: {
1352
+ settingsKey: PlinkoSettingsKey,
1353
+ parameters: Parameters4
1354
+ },
1355
+ "pvp-coinflip": {
1356
+ settingsKey: PvpCoinflipSettingsKey,
1357
+ parameters: Parameters
1358
+ },
1359
+ range: {
1360
+ settingsKey: RangeSettingsKey,
1361
+ parameters: Parameters5
1362
+ },
1363
+ wheel: {
1364
+ settingsKey: WheelSettingsKey,
1365
+ parameters: Parameters6
1366
+ }
1367
+ };
1005
1368
 
1006
1369
  // src/client.ts
1007
1370
  function suigar({
1008
1371
  name = "suigar",
1009
- partner
1372
+ partner,
1373
+ cacheTtl
1010
1374
  } = {}) {
1011
1375
  return {
1012
1376
  name,
1013
1377
  register: (client) => {
1014
- return new SuigarClient({ client, partner });
1378
+ return new SuigarClient({
1379
+ client,
1380
+ name: String(name),
1381
+ partner,
1382
+ cacheTtl
1383
+ });
1015
1384
  }
1016
1385
  };
1017
1386
  }
@@ -1019,15 +1388,23 @@ var SuigarClient = class {
1019
1388
  #client;
1020
1389
  #config;
1021
1390
  #partner;
1391
+ #cache;
1022
1392
  constructor({
1023
1393
  client,
1024
- partner
1394
+ name,
1395
+ partner,
1396
+ cacheTtl
1025
1397
  }) {
1026
1398
  this.#client = client;
1027
1399
  this.#partner = partner;
1400
+ this.#cache = client.cache.scope("@suigar/sdk").readSync([name, "ttl-cache"], () => {
1401
+ return new TtlClientCache({
1402
+ ttlMs: cacheTtl ?? DEFAULT_CACHE_TTL_MS
1403
+ });
1404
+ });
1028
1405
  const network = this.#client.network;
1029
1406
  if (!SUPPORTED_SUI_NETWORKS.includes(network)) {
1030
- throw new Error(`Unsupported network: ${network}`);
1407
+ throw new RangeError(`Unsupported network: ${network}`);
1031
1408
  }
1032
1409
  this.#config = resolveSuigarConfig(network);
1033
1410
  }
@@ -1035,8 +1412,8 @@ var SuigarClient = class {
1035
1412
  * Returns the resolved SDK configuration for the connected network.
1036
1413
  *
1037
1414
  * 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.
1415
+ * registry ids, supported coin types, and price info object ids the SDK
1416
+ * resolved for the current client network.
1040
1417
  *
1041
1418
  * @returns Network-resolved Suigar configuration.
1042
1419
  */
@@ -1058,6 +1435,29 @@ var SuigarClient = class {
1058
1435
  const bytes = await transaction.build({ ...options, client: this.#client });
1059
1436
  return utils.toBase64(bytes);
1060
1437
  }
1438
+ /**
1439
+ * Reads on-chain game parameters for the requested game.
1440
+ *
1441
+ * The SDK first reads the selected game's settings object from SweetHouse,
1442
+ * then reads that game's coin-specific `Parameters<T>` object. Results are
1443
+ * cached according to the extension `cacheTtl` option. Pass
1444
+ * `ignoreCache: true` to refresh the onchain read and replace the cached
1445
+ * value.
1446
+ *
1447
+ * @param game Game whose parameters should be loaded.
1448
+ * @param options Optional coin type, cache override, and abort signal.
1449
+ * @returns Parsed game parameters typed for the requested game.
1450
+ */
1451
+ async getGameParameters(game, options = {}) {
1452
+ const coinType = utils.normalizeStructTag(
1453
+ options.coinType ?? this.#config.coinTypes.sui
1454
+ );
1455
+ return this.#cache.read(
1456
+ ["parameters", this.#client.network, game, coinType],
1457
+ () => this.#fetchGameParameters(game, coinType, options.signal),
1458
+ { ignoreCache: options.ignoreCache }
1459
+ );
1460
+ }
1061
1461
  /**
1062
1462
  * Lists unresolved PvP coinflip games from the configured registry and resolves
1063
1463
  * each entry into parsed onchain game state.
@@ -1200,7 +1600,7 @@ var SuigarClient = class {
1200
1600
  partner: this.#partner
1201
1601
  });
1202
1602
  default:
1203
- throw new Error(`Unsupported game: ${gameId}`);
1603
+ throw new RangeError(`Unsupported game: ${gameId}`);
1204
1604
  }
1205
1605
  },
1206
1606
  /**
@@ -1234,7 +1634,7 @@ var SuigarClient = class {
1234
1634
  partner: this.#partner
1235
1635
  });
1236
1636
  default:
1237
- throw new Error(`Unsupported PvP coinflip action: ${action}`);
1637
+ throw new RangeError(`Unsupported PvP coinflip action: ${action}`);
1238
1638
  }
1239
1639
  }
1240
1640
  };
@@ -1251,6 +1651,41 @@ var SuigarClient = class {
1251
1651
  });
1252
1652
  };
1253
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
+ }
1254
1689
  };
1255
1690
 
1256
1691
  exports.SuigarClient = SuigarClient;