@suigar/sdk 2.0.0-beta.7 → 2.0.0-beta.9

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/utils.cjs CHANGED
@@ -146,36 +146,28 @@ var GAME_DETAILS_SCHEMA = {
146
146
  };
147
147
 
148
148
  // src/utils/parser.ts
149
- var bcsU8 = bcs.bcs.u8();
150
- var bcsU64 = bcs.bcs.u64();
151
- var bcsBool = bcs.bcs.bool();
152
- var bcsString = bcs.bcs.string();
153
149
  var textDecoder = new TextDecoder();
154
150
  var GAME_DETAIL_BCS = {
155
- u8: bcsU8,
156
- u64: bcsU64,
157
- bool: bcsBool,
151
+ u8: bcs.bcs.U8,
152
+ u64: bcs.bcs.U64,
153
+ bool: bcs.bcs.Bool,
158
154
  float: Float,
159
- string: bcsString
155
+ string: bcs.bcs.String
160
156
  };
161
157
  function fromMoveI64(i64) {
162
158
  try {
163
- const value = BigInt(i64.bits ?? 0);
164
- const maxPositive = 1n << 63n;
165
- const twoPow64 = 1n << 64n;
166
- const signed = value >= maxPositive ? value - twoPow64 : value;
167
- return Number(signed);
159
+ return Number(BigInt.asIntN(64, BigInt(i64.bits ?? 0)));
168
160
  } catch {
169
161
  return 0;
170
162
  }
171
163
  }
172
164
  function fromMoveFloat(float) {
173
- const mantissa = BigInt(float.mant);
165
+ const mantissa = BigInt(float.mant ?? 0);
174
166
  if (mantissa === 0n) {
175
167
  return 0;
176
168
  }
177
169
  const exponent = fromMoveI64(float.exp) - 52;
178
- const magnitude = Number(mantissa) * Math.pow(2, exponent);
170
+ const magnitude = Number(mantissa) * 2 ** exponent;
179
171
  return float.is_negative ? -magnitude : magnitude;
180
172
  }
181
173
  function normalizeGameDetailValue(valueType, parsed) {
@@ -190,7 +182,7 @@ function normalizeGameDetailValue(valueType, parsed) {
190
182
  function parseStringGameDetail(value) {
191
183
  const bytes = Uint8Array.from(value);
192
184
  try {
193
- return bcsString.parse(bytes);
185
+ return bcs.bcs.String.parse(bytes);
194
186
  } catch {
195
187
  return textDecoder.decode(bytes);
196
188
  }
package/dist/utils.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _mysten_bcs from '@mysten/bcs';
2
- import { M as MoveStruct } from './index-jwSXA8q3.cjs';
2
+ import { M as MoveStruct } from './index-3P_LBbDM.cjs';
3
3
  import '@mysten/sui/bcs';
4
4
  import '@mysten/sui/client';
5
5
 
@@ -61,7 +61,30 @@ declare const DEFAULT_RANGE_SCALE = 1000000;
61
61
  declare const RANGE_POINT_LIMIT: number;
62
62
  declare const DEFAULT_LIMBO_MULTIPLIER_SCALE = 100;
63
63
 
64
+ /**
65
+ * Normalizes a numeric input into a non-negative `bigint`.
66
+ *
67
+ * This helper accepts the two number shapes the SDK commonly sees from app
68
+ * code: plain JavaScript numbers and already-normalized `bigint` values.
69
+ * Number inputs are truncated toward zero before conversion, so UI-friendly
70
+ * values like `5.9` become `5n`.
71
+ *
72
+ * @param value Value to coerce into a `bigint`.
73
+ * @returns The normalized non-negative `bigint`.
74
+ * @throws When `value` is not a finite number or bigint, or when it is negative.
75
+ */
64
76
  declare function toBigInt(value: unknown): bigint;
77
+ /**
78
+ * Validates that a value can be safely used as a Move `u8`.
79
+ *
80
+ * Use this for config ids and other small integer fields that must stay inside
81
+ * the `0..255` range. Unlike `toBigInt`, this does not coerce fractional
82
+ * values: the input must already be an integer.
83
+ *
84
+ * @param value Value to validate.
85
+ * @returns The original number once it has been confirmed to be a valid `u8`.
86
+ * @throws When `value` is not a finite integer between `0` and `255`.
87
+ */
65
88
  declare function toU8(value: unknown): number;
66
89
 
67
90
  declare const Float: MoveStruct<{
@@ -73,8 +96,42 @@ declare const Float: MoveStruct<{
73
96
  }, "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::float::Float">;
74
97
 
75
98
  type MoveFloat = ReturnType<(typeof Float)['parse']>;
99
+ /**
100
+ * Converts a generated Move `i64` wrapper into a JavaScript number.
101
+ *
102
+ * The generated bindings expose signed 64-bit integers through a `{ bits }`
103
+ * field that stores the raw two's-complement bit pattern. This helper
104
+ * reinterprets those bits as a signed `i64` and returns a plain JS number.
105
+ * Invalid or missing input falls back to `0`.
106
+ *
107
+ * @param i64 Generated Move `i64` value, typically used for float exponents.
108
+ * @returns The signed 64-bit value as a JavaScript number.
109
+ */
76
110
  declare function fromMoveI64(i64: MoveFloat['exp']): number;
111
+ /**
112
+ * Converts a generated Move `Float` struct into a JavaScript number.
113
+ *
114
+ * Suigar float values are represented as a sign flag, an unsigned mantissa,
115
+ * and a Move `i64` exponent. This helper rebuilds the numeric value using the
116
+ * same normalization expected by the onchain format and applies the sign at
117
+ * the end. Missing mantissas are treated as `0`, and a zero mantissa returns `0`.
118
+ *
119
+ * @param float Generated Move float value with `mant`, `exp`, and `is_negative`.
120
+ * @returns The decoded floating-point value as a JavaScript number.
121
+ */
77
122
  declare function fromMoveFloat(float: MoveFloat): number;
123
+ /**
124
+ * Decodes `BetResultEvent.game_details` into plain application values.
125
+ *
126
+ * Suigar stores game detail entries as `VecMap<string, vector<u8>>`, so raw BCS
127
+ * decoding leaves each value as bytes. This helper looks up the known schema for
128
+ * each key, parses the bytes into the expected runtime type, and preserves the
129
+ * original onchain keys in the returned object. Unknown keys fall back to
130
+ * string decoding so newer detail fields remain readable by default.
131
+ *
132
+ * @param gameDetails Raw `game_details` map from a decoded bet result event.
133
+ * @returns A plain object with the same keys and decoded string, number, or boolean values.
134
+ */
78
135
  declare function parseGameDetails(gameDetails: BetResultGameDetails): ParsedGameDetails;
79
136
 
80
137
  export { DEFAULT_GAS_BUDGET_MIST, DEFAULT_LIMBO_MULTIPLIER_SCALE, DEFAULT_RANGE_SCALE, RANGE_POINT_LIMIT, fromMoveFloat, fromMoveI64, parseGameDetails, toBigInt, toU8 };
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _mysten_bcs from '@mysten/bcs';
2
- import { M as MoveStruct } from './index-jwSXA8q3.js';
2
+ import { M as MoveStruct } from './index-3P_LBbDM.js';
3
3
  import '@mysten/sui/bcs';
4
4
  import '@mysten/sui/client';
5
5
 
@@ -61,7 +61,30 @@ declare const DEFAULT_RANGE_SCALE = 1000000;
61
61
  declare const RANGE_POINT_LIMIT: number;
62
62
  declare const DEFAULT_LIMBO_MULTIPLIER_SCALE = 100;
63
63
 
64
+ /**
65
+ * Normalizes a numeric input into a non-negative `bigint`.
66
+ *
67
+ * This helper accepts the two number shapes the SDK commonly sees from app
68
+ * code: plain JavaScript numbers and already-normalized `bigint` values.
69
+ * Number inputs are truncated toward zero before conversion, so UI-friendly
70
+ * values like `5.9` become `5n`.
71
+ *
72
+ * @param value Value to coerce into a `bigint`.
73
+ * @returns The normalized non-negative `bigint`.
74
+ * @throws When `value` is not a finite number or bigint, or when it is negative.
75
+ */
64
76
  declare function toBigInt(value: unknown): bigint;
77
+ /**
78
+ * Validates that a value can be safely used as a Move `u8`.
79
+ *
80
+ * Use this for config ids and other small integer fields that must stay inside
81
+ * the `0..255` range. Unlike `toBigInt`, this does not coerce fractional
82
+ * values: the input must already be an integer.
83
+ *
84
+ * @param value Value to validate.
85
+ * @returns The original number once it has been confirmed to be a valid `u8`.
86
+ * @throws When `value` is not a finite integer between `0` and `255`.
87
+ */
65
88
  declare function toU8(value: unknown): number;
66
89
 
67
90
  declare const Float: MoveStruct<{
@@ -73,8 +96,42 @@ declare const Float: MoveStruct<{
73
96
  }, "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::float::Float">;
74
97
 
75
98
  type MoveFloat = ReturnType<(typeof Float)['parse']>;
99
+ /**
100
+ * Converts a generated Move `i64` wrapper into a JavaScript number.
101
+ *
102
+ * The generated bindings expose signed 64-bit integers through a `{ bits }`
103
+ * field that stores the raw two's-complement bit pattern. This helper
104
+ * reinterprets those bits as a signed `i64` and returns a plain JS number.
105
+ * Invalid or missing input falls back to `0`.
106
+ *
107
+ * @param i64 Generated Move `i64` value, typically used for float exponents.
108
+ * @returns The signed 64-bit value as a JavaScript number.
109
+ */
76
110
  declare function fromMoveI64(i64: MoveFloat['exp']): number;
111
+ /**
112
+ * Converts a generated Move `Float` struct into a JavaScript number.
113
+ *
114
+ * Suigar float values are represented as a sign flag, an unsigned mantissa,
115
+ * and a Move `i64` exponent. This helper rebuilds the numeric value using the
116
+ * same normalization expected by the onchain format and applies the sign at
117
+ * the end. Missing mantissas are treated as `0`, and a zero mantissa returns `0`.
118
+ *
119
+ * @param float Generated Move float value with `mant`, `exp`, and `is_negative`.
120
+ * @returns The decoded floating-point value as a JavaScript number.
121
+ */
77
122
  declare function fromMoveFloat(float: MoveFloat): number;
123
+ /**
124
+ * Decodes `BetResultEvent.game_details` into plain application values.
125
+ *
126
+ * Suigar stores game detail entries as `VecMap<string, vector<u8>>`, so raw BCS
127
+ * decoding leaves each value as bytes. This helper looks up the known schema for
128
+ * each key, parses the bytes into the expected runtime type, and preserves the
129
+ * original onchain keys in the returned object. Unknown keys fall back to
130
+ * string decoding so newer detail fields remain readable by default.
131
+ *
132
+ * @param gameDetails Raw `game_details` map from a decoded bet result event.
133
+ * @returns A plain object with the same keys and decoded string, number, or boolean values.
134
+ */
78
135
  declare function parseGameDetails(gameDetails: BetResultGameDetails): ParsedGameDetails;
79
136
 
80
137
  export { DEFAULT_GAS_BUDGET_MIST, DEFAULT_LIMBO_MULTIPLIER_SCALE, DEFAULT_RANGE_SCALE, RANGE_POINT_LIMIT, fromMoveFloat, fromMoveI64, parseGameDetails, toBigInt, toU8 };
package/dist/utils.js CHANGED
@@ -1 +1 @@
1
- export { DEFAULT_GAS_BUDGET_MIST, DEFAULT_LIMBO_MULTIPLIER_SCALE, DEFAULT_RANGE_SCALE, RANGE_POINT_LIMIT, fromMoveFloat, fromMoveI64, parseGameDetails, toBigInt, toU8 } from './chunk-YGYMLRE4.js';
1
+ export { DEFAULT_GAS_BUDGET_MIST, DEFAULT_LIMBO_MULTIPLIER_SCALE, DEFAULT_RANGE_SCALE, RANGE_POINT_LIMIT, fromMoveFloat, fromMoveI64, parseGameDetails, toBigInt, toU8 } from './chunk-FEQY5O43.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suigar/sdk",
3
- "version": "2.0.0-beta.7",
3
+ "version": "2.0.0-beta.9",
4
4
  "description": "TypeScript SDK for Suigar v2 Move contracts on Sui.",
5
5
  "keywords": [
6
6
  "suigar",
@@ -46,18 +46,17 @@
46
46
  "build": "npm run clean && npm run codegen && tsup",
47
47
  "build:ci": "rm -rf dist && tsup",
48
48
  "clean": "rm -rf dist src/contracts .vitest-cache",
49
- "codegen": "sui-ts-codegen generate",
49
+ "codegen": "node ./scripts/update-package-configs.mjs && sui-ts-codegen generate",
50
50
  "changeset": "changeset",
51
51
  "changeset:beta:enter": "changeset pre enter beta",
52
52
  "changeset:beta:exit": "changeset pre exit",
53
+ "changeset:version": "changeset version",
53
54
  "format": "prettier --write .",
54
55
  "lint": "eslint . --fix && npm run format",
55
56
  "prepare": "husky",
56
57
  "release": "changeset publish",
57
58
  "test": "vitest run",
58
- "typecheck": "tsc --noEmit",
59
- "update:package-configs": "node ./scripts/update-package-configs.mjs",
60
- "version-packages": "changeset version"
59
+ "typecheck": "tsc --noEmit"
61
60
  },
62
61
  "repository": {
63
62
  "type": "git",
@@ -78,7 +77,7 @@
78
77
  "@changesets/cli": "^2.31.0",
79
78
  "@eslint/js": "^10.0.1",
80
79
  "@mysten/bcs": "^2.0.3",
81
- "@mysten/codegen": "^0.9.0",
80
+ "@mysten/codegen": "^0.10.0",
82
81
  "@mysten/sui": "^2.16.0",
83
82
  "@types/node": "^24.0.0",
84
83
  "eslint": "^10.2.1",
@@ -89,7 +88,7 @@
89
88
  "tsup": "^8.5.1",
90
89
  "tsx": "^4.21.0",
91
90
  "typescript": "^5.9.3",
92
- "typescript-eslint": "^8.59.0",
91
+ "typescript-eslint": "^8.59.1",
93
92
  "vitest": "^4.1.5"
94
93
  }
95
94
  }