@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/utils.cjs
CHANGED
|
@@ -11,21 +11,34 @@ var RANGE_POINT_LIMIT = DEFAULT_RANGE_SCALE * 100;
|
|
|
11
11
|
var DEFAULT_LIMBO_MULTIPLIER_SCALE = 100;
|
|
12
12
|
|
|
13
13
|
// src/utils/numeric.ts
|
|
14
|
-
function
|
|
14
|
+
function isFiniteNumber(value, message) {
|
|
15
|
+
if (typeof value !== "number") {
|
|
16
|
+
throw new Error(`${message}: ${String(value)}`);
|
|
17
|
+
}
|
|
18
|
+
if (!Number.isFinite(value)) {
|
|
19
|
+
throw new Error(`Value must be a finite number: ${value}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function toBigInt(value) {
|
|
15
23
|
if (typeof value === "bigint") {
|
|
16
24
|
if (value < 0n) {
|
|
17
|
-
throw new Error(
|
|
25
|
+
throw new Error(`Value must be non-negative: ${value}`);
|
|
18
26
|
}
|
|
19
27
|
return value;
|
|
20
28
|
}
|
|
21
|
-
|
|
22
|
-
|
|
29
|
+
isFiniteNumber(value, "Value must be a bigint or number");
|
|
30
|
+
if (value < 0) {
|
|
31
|
+
throw new Error(`Value must be a finite non-negative number: ${value}`);
|
|
23
32
|
}
|
|
24
33
|
return BigInt(Math.trunc(value));
|
|
25
34
|
}
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
-
|
|
35
|
+
function toU8(value) {
|
|
36
|
+
isFiniteNumber(value, "Value must be a number");
|
|
37
|
+
if (!Number.isInteger(value)) {
|
|
38
|
+
throw new Error(`Value must be an integer: ${value}`);
|
|
39
|
+
}
|
|
40
|
+
if (value < 0 || value > 255) {
|
|
41
|
+
throw new Error(`Value must be an integer between 0 and 255: ${value}`);
|
|
29
42
|
}
|
|
30
43
|
return value;
|
|
31
44
|
}
|
|
@@ -145,7 +158,7 @@ var GAME_DETAIL_BCS = {
|
|
|
145
158
|
float: Float,
|
|
146
159
|
string: bcsString
|
|
147
160
|
};
|
|
148
|
-
function
|
|
161
|
+
function fromMoveI64(i64) {
|
|
149
162
|
try {
|
|
150
163
|
const value = BigInt(i64.bits ?? 0);
|
|
151
164
|
const maxPositive = 1n << 63n;
|
|
@@ -156,18 +169,18 @@ function parseI64(i64) {
|
|
|
156
169
|
return 0;
|
|
157
170
|
}
|
|
158
171
|
}
|
|
159
|
-
function
|
|
172
|
+
function fromMoveFloat(float) {
|
|
160
173
|
const mantissa = BigInt(float.mant);
|
|
161
174
|
if (mantissa === 0n) {
|
|
162
175
|
return 0;
|
|
163
176
|
}
|
|
164
|
-
const exponent =
|
|
177
|
+
const exponent = fromMoveI64(float.exp) - 52;
|
|
165
178
|
const magnitude = Number(mantissa) * Math.pow(2, exponent);
|
|
166
179
|
return float.is_negative ? -magnitude : magnitude;
|
|
167
180
|
}
|
|
168
181
|
function normalizeGameDetailValue(valueType, parsed) {
|
|
169
182
|
if (valueType === "float") {
|
|
170
|
-
return
|
|
183
|
+
return fromMoveFloat(parsed);
|
|
171
184
|
}
|
|
172
185
|
if (valueType === "u64") {
|
|
173
186
|
return Number(parsed);
|
|
@@ -201,8 +214,8 @@ exports.DEFAULT_GAS_BUDGET_MIST = DEFAULT_GAS_BUDGET_MIST;
|
|
|
201
214
|
exports.DEFAULT_LIMBO_MULTIPLIER_SCALE = DEFAULT_LIMBO_MULTIPLIER_SCALE;
|
|
202
215
|
exports.DEFAULT_RANGE_SCALE = DEFAULT_RANGE_SCALE;
|
|
203
216
|
exports.RANGE_POINT_LIMIT = RANGE_POINT_LIMIT;
|
|
204
|
-
exports.
|
|
217
|
+
exports.fromMoveFloat = fromMoveFloat;
|
|
218
|
+
exports.fromMoveI64 = fromMoveI64;
|
|
205
219
|
exports.parseGameDetails = parseGameDetails;
|
|
206
|
-
exports.
|
|
207
|
-
exports.
|
|
208
|
-
exports.toU8Number = toU8Number;
|
|
220
|
+
exports.toBigInt = toBigInt;
|
|
221
|
+
exports.toU8 = toU8;
|
package/dist/utils.d.cts
CHANGED
|
@@ -61,8 +61,31 @@ 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
|
-
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
88
|
+
declare function toU8(value: unknown): number;
|
|
66
89
|
|
|
67
90
|
declare const Float: MoveStruct<{
|
|
68
91
|
is_negative: _mysten_bcs.BcsType<boolean, boolean, "bool">;
|
|
@@ -72,8 +95,21 @@ declare const Float: MoveStruct<{
|
|
|
72
95
|
mant: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
|
|
73
96
|
}, "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::float::Float">;
|
|
74
97
|
|
|
75
|
-
|
|
76
|
-
declare function
|
|
98
|
+
type MoveFloat = ReturnType<(typeof Float)['parse']>;
|
|
99
|
+
declare function fromMoveI64(i64: MoveFloat['exp']): number;
|
|
100
|
+
declare function fromMoveFloat(float: MoveFloat): number;
|
|
101
|
+
/**
|
|
102
|
+
* Decodes `BetResultEvent.game_details` into plain application values.
|
|
103
|
+
*
|
|
104
|
+
* Suigar stores game detail entries as `VecMap<string, vector<u8>>`, so raw BCS
|
|
105
|
+
* decoding leaves each value as bytes. This helper looks up the known schema for
|
|
106
|
+
* each key, parses the bytes into the expected runtime type, and preserves the
|
|
107
|
+
* original onchain keys in the returned object. Unknown keys fall back to
|
|
108
|
+
* string decoding so newer detail fields remain readable by default.
|
|
109
|
+
*
|
|
110
|
+
* @param gameDetails Raw `game_details` map from a decoded bet result event.
|
|
111
|
+
* @returns A plain object with the same keys and decoded string, number, or boolean values.
|
|
112
|
+
*/
|
|
77
113
|
declare function parseGameDetails(gameDetails: BetResultGameDetails): ParsedGameDetails;
|
|
78
114
|
|
|
79
|
-
export { DEFAULT_GAS_BUDGET_MIST, DEFAULT_LIMBO_MULTIPLIER_SCALE, DEFAULT_RANGE_SCALE, RANGE_POINT_LIMIT,
|
|
115
|
+
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
|
@@ -61,8 +61,31 @@ 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
|
-
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
88
|
+
declare function toU8(value: unknown): number;
|
|
66
89
|
|
|
67
90
|
declare const Float: MoveStruct<{
|
|
68
91
|
is_negative: _mysten_bcs.BcsType<boolean, boolean, "bool">;
|
|
@@ -72,8 +95,21 @@ declare const Float: MoveStruct<{
|
|
|
72
95
|
mant: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
|
|
73
96
|
}, "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::float::Float">;
|
|
74
97
|
|
|
75
|
-
|
|
76
|
-
declare function
|
|
98
|
+
type MoveFloat = ReturnType<(typeof Float)['parse']>;
|
|
99
|
+
declare function fromMoveI64(i64: MoveFloat['exp']): number;
|
|
100
|
+
declare function fromMoveFloat(float: MoveFloat): number;
|
|
101
|
+
/**
|
|
102
|
+
* Decodes `BetResultEvent.game_details` into plain application values.
|
|
103
|
+
*
|
|
104
|
+
* Suigar stores game detail entries as `VecMap<string, vector<u8>>`, so raw BCS
|
|
105
|
+
* decoding leaves each value as bytes. This helper looks up the known schema for
|
|
106
|
+
* each key, parses the bytes into the expected runtime type, and preserves the
|
|
107
|
+
* original onchain keys in the returned object. Unknown keys fall back to
|
|
108
|
+
* string decoding so newer detail fields remain readable by default.
|
|
109
|
+
*
|
|
110
|
+
* @param gameDetails Raw `game_details` map from a decoded bet result event.
|
|
111
|
+
* @returns A plain object with the same keys and decoded string, number, or boolean values.
|
|
112
|
+
*/
|
|
77
113
|
declare function parseGameDetails(gameDetails: BetResultGameDetails): ParsedGameDetails;
|
|
78
114
|
|
|
79
|
-
export { DEFAULT_GAS_BUDGET_MIST, DEFAULT_LIMBO_MULTIPLIER_SCALE, DEFAULT_RANGE_SCALE, RANGE_POINT_LIMIT,
|
|
115
|
+
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,
|
|
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';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@suigar/sdk",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.8",
|
|
4
4
|
"description": "TypeScript SDK for Suigar v2 Move contracts on Sui.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"suigar",
|
|
@@ -91,20 +91,5 @@
|
|
|
91
91
|
"typescript": "^5.9.3",
|
|
92
92
|
"typescript-eslint": "^8.59.0",
|
|
93
93
|
"vitest": "^4.1.5"
|
|
94
|
-
},
|
|
95
|
-
"lint-staged": {
|
|
96
|
-
"{src,test,scripts}/**/*.{ts,tsx,js,mjs,cjs}": [
|
|
97
|
-
"eslint --fix",
|
|
98
|
-
"prettier --write"
|
|
99
|
-
],
|
|
100
|
-
"./*.{ts,tsx,js,mjs,cjs}": [
|
|
101
|
-
"eslint --fix",
|
|
102
|
-
"prettier --write"
|
|
103
|
-
],
|
|
104
|
-
"examples/game-integration/**/*.{ts,tsx,js,mjs,cjs}": [
|
|
105
|
-
"npm --prefix examples/game-integration exec eslint -- --fix",
|
|
106
|
-
"prettier --write"
|
|
107
|
-
],
|
|
108
|
-
"*.{json,md,yml,yaml}": "prettier --write"
|
|
109
94
|
}
|
|
110
95
|
}
|