@suigar/sdk 2.0.0-beta.1 → 2.0.0-beta.11
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 +123 -0
- package/README.md +324 -111
- package/dist/chunk-TBJ5TYYE.js +341 -0
- package/dist/games-BHYRg31e.d.cts +98 -0
- package/dist/games-BHYRg31e.d.ts +98 -0
- package/dist/games.cjs +2 -0
- package/dist/games.d.cts +2 -0
- package/dist/games.d.ts +2 -0
- package/dist/games.js +1 -0
- package/dist/index-3P_LBbDM.d.cts +25 -0
- package/dist/index-3P_LBbDM.d.ts +25 -0
- package/dist/index.cjs +1082 -363
- package/dist/index.d.cts +390 -218
- package/dist/index.d.ts +390 -218
- package/dist/index.js +962 -461
- package/dist/utils.cjs +241 -0
- package/dist/utils.d.cts +180 -0
- package/dist/utils.d.ts +180 -0
- package/dist/utils.js +1 -0
- package/package.json +81 -79
package/dist/utils.cjs
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var utils = require('@mysten/sui/utils');
|
|
4
|
+
var bcs = require('@mysten/sui/bcs');
|
|
5
|
+
require('@mysten/sui/transactions');
|
|
6
|
+
|
|
7
|
+
// src/utils/constants.ts
|
|
8
|
+
var DEFAULT_GAS_BUDGET_MIST = utils.parseToMist("0.05");
|
|
9
|
+
var DEFAULT_RANGE_SCALE = 1e6;
|
|
10
|
+
var RANGE_POINT_LIMIT = DEFAULT_RANGE_SCALE * 100;
|
|
11
|
+
var DEFAULT_LIMBO_MULTIPLIER_SCALE = 100;
|
|
12
|
+
|
|
13
|
+
// src/utils/numeric.ts
|
|
14
|
+
function assertFiniteNumber(value, errorMessage) {
|
|
15
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
16
|
+
throw new TypeError(`${errorMessage}: ${String(value)}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function toBigInt(value) {
|
|
20
|
+
let result;
|
|
21
|
+
try {
|
|
22
|
+
if (typeof value === "bigint" || typeof value === "string" || typeof value === "boolean") {
|
|
23
|
+
result = BigInt(value);
|
|
24
|
+
} else {
|
|
25
|
+
assertFiniteNumber(
|
|
26
|
+
value,
|
|
27
|
+
"Value must be a bigint, number, integer string, or boolean"
|
|
28
|
+
);
|
|
29
|
+
result = BigInt(Math.trunc(value));
|
|
30
|
+
}
|
|
31
|
+
} catch {
|
|
32
|
+
throw new TypeError(
|
|
33
|
+
`Value must be a bigint, number, integer string, or boolean: ${value}`
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
if (result < 0n) {
|
|
37
|
+
throw new RangeError(`Value must be non-negative: ${value}`);
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
function toBoundedInt(value, max, typeName) {
|
|
42
|
+
const num = typeof value === "string" && value.trim() === "" ? NaN : Number(value);
|
|
43
|
+
assertFiniteNumber(num, "Value must be a finite number or integer string");
|
|
44
|
+
if (typeof value === "boolean" || value == null || !Number.isInteger(num) || num < 0 || num > max) {
|
|
45
|
+
throw new Error(`Value must be a ${typeName} integer (0-${max}): ${value}`);
|
|
46
|
+
}
|
|
47
|
+
return num;
|
|
48
|
+
}
|
|
49
|
+
function toU8(value) {
|
|
50
|
+
return toBoundedInt(value, 255, "u8");
|
|
51
|
+
}
|
|
52
|
+
function toU16(value) {
|
|
53
|
+
return toBoundedInt(value, 65535, "u16");
|
|
54
|
+
}
|
|
55
|
+
utils.normalizeSuiAddress("0x1");
|
|
56
|
+
utils.normalizeSuiAddress("0x2");
|
|
57
|
+
var MoveStruct = class extends bcs.BcsStruct {
|
|
58
|
+
async get({
|
|
59
|
+
objectId,
|
|
60
|
+
...options
|
|
61
|
+
}) {
|
|
62
|
+
const [res] = await this.getMany({
|
|
63
|
+
...options,
|
|
64
|
+
objectIds: [objectId]
|
|
65
|
+
});
|
|
66
|
+
if (!res) {
|
|
67
|
+
throw new Error(`No object found for id ${objectId}`);
|
|
68
|
+
}
|
|
69
|
+
return res;
|
|
70
|
+
}
|
|
71
|
+
async getMany({
|
|
72
|
+
client,
|
|
73
|
+
...options
|
|
74
|
+
}) {
|
|
75
|
+
const response = await client.core.getObjects({
|
|
76
|
+
...options,
|
|
77
|
+
include: {
|
|
78
|
+
...options.include,
|
|
79
|
+
content: true
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
return response.objects.map((obj) => {
|
|
83
|
+
if (obj instanceof Error) {
|
|
84
|
+
throw obj;
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
...obj,
|
|
88
|
+
json: this.parse(obj.content)
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
var $moduleName = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::i64";
|
|
94
|
+
var I64 = new MoveStruct({
|
|
95
|
+
name: `${$moduleName}::I64`,
|
|
96
|
+
fields: {
|
|
97
|
+
bits: bcs.bcs.u64()
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// src/contracts/core/float.ts
|
|
102
|
+
var $moduleName2 = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::float";
|
|
103
|
+
var Float = new MoveStruct({
|
|
104
|
+
name: `${$moduleName2}::Float`,
|
|
105
|
+
fields: {
|
|
106
|
+
is_negative: bcs.bcs.bool(),
|
|
107
|
+
exp: I64,
|
|
108
|
+
mant: bcs.bcs.u64()
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// src/types/game-details.type.ts
|
|
113
|
+
var COINFLIP_GAME_DETAILS_SCHEMA = {
|
|
114
|
+
player_bet: "string",
|
|
115
|
+
coin_outcome: "string"
|
|
116
|
+
};
|
|
117
|
+
var PVP_COINFLIP_GAME_DETAILS_SCHEMA = {
|
|
118
|
+
pvp_result: "string"
|
|
119
|
+
};
|
|
120
|
+
var LIMBO_GAME_DETAILS_SCHEMA = {
|
|
121
|
+
payout_amount: "u64",
|
|
122
|
+
win: "bool",
|
|
123
|
+
roll_multiplier: "float",
|
|
124
|
+
payout_multiplier: "float",
|
|
125
|
+
target_multiplier: "float",
|
|
126
|
+
actual_rtp: "float"
|
|
127
|
+
};
|
|
128
|
+
var RANGE_GAME_DETAILS_SCHEMA = {
|
|
129
|
+
roll_value: "u64",
|
|
130
|
+
win: "bool",
|
|
131
|
+
payout_amount: "u64",
|
|
132
|
+
payout_multiplier: "float",
|
|
133
|
+
left_point: "u64",
|
|
134
|
+
right_point: "u64",
|
|
135
|
+
zone_size: "u64",
|
|
136
|
+
winning_zone_size: "u64",
|
|
137
|
+
is_out_range: "bool",
|
|
138
|
+
bet_threshold: "u64",
|
|
139
|
+
roll_under: "bool",
|
|
140
|
+
range_mode: "u8",
|
|
141
|
+
win_probability: "float",
|
|
142
|
+
win_multiplier: "float",
|
|
143
|
+
actual_rtp: "float"
|
|
144
|
+
};
|
|
145
|
+
var PLINKO_GAME_DETAILS_SCHEMA = {
|
|
146
|
+
slot_index: "u8",
|
|
147
|
+
multiplier: "float",
|
|
148
|
+
payout_amount: "u64",
|
|
149
|
+
plinko_config: "u8"
|
|
150
|
+
};
|
|
151
|
+
var WHEEL_GAME_DETAILS_SCHEMA = {
|
|
152
|
+
case_index: "u8",
|
|
153
|
+
multiplier: "float",
|
|
154
|
+
payout_amount: "u64",
|
|
155
|
+
wheel_config: "u8",
|
|
156
|
+
spin_value: "u64"
|
|
157
|
+
};
|
|
158
|
+
var GAME_DETAILS_SCHEMA = {
|
|
159
|
+
...COINFLIP_GAME_DETAILS_SCHEMA,
|
|
160
|
+
...PVP_COINFLIP_GAME_DETAILS_SCHEMA,
|
|
161
|
+
...LIMBO_GAME_DETAILS_SCHEMA,
|
|
162
|
+
...RANGE_GAME_DETAILS_SCHEMA,
|
|
163
|
+
...PLINKO_GAME_DETAILS_SCHEMA,
|
|
164
|
+
...WHEEL_GAME_DETAILS_SCHEMA
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// src/utils/parser.ts
|
|
168
|
+
var textDecoder = new TextDecoder();
|
|
169
|
+
var GAME_DETAIL_BCS = {
|
|
170
|
+
u8: bcs.bcs.U8,
|
|
171
|
+
u64: bcs.bcs.U64,
|
|
172
|
+
bool: bcs.bcs.Bool,
|
|
173
|
+
float: Float,
|
|
174
|
+
string: bcs.bcs.String
|
|
175
|
+
};
|
|
176
|
+
function fromMoveI64(i64) {
|
|
177
|
+
try {
|
|
178
|
+
return Number(BigInt.asIntN(64, BigInt(i64.bits ?? 0)));
|
|
179
|
+
} catch {
|
|
180
|
+
return 0;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function fromMoveFloat(float) {
|
|
184
|
+
const mantissa = BigInt(float.mant ?? 0);
|
|
185
|
+
if (mantissa === 0n) {
|
|
186
|
+
return 0;
|
|
187
|
+
}
|
|
188
|
+
const exponent = fromMoveI64(float.exp) - 52;
|
|
189
|
+
const magnitude = Number(mantissa) * 2 ** exponent;
|
|
190
|
+
return float.is_negative ? -magnitude : magnitude;
|
|
191
|
+
}
|
|
192
|
+
function parseCoinType(type) {
|
|
193
|
+
const coinType = utils.parseStructTag(type).typeParams[0];
|
|
194
|
+
if (!coinType) {
|
|
195
|
+
throw new Error(`Unable to parse coin type from ${type}`);
|
|
196
|
+
}
|
|
197
|
+
return utils.normalizeStructTag(coinType);
|
|
198
|
+
}
|
|
199
|
+
function normalizeGameDetailValue(valueType, parsed) {
|
|
200
|
+
if (valueType === "float") {
|
|
201
|
+
return fromMoveFloat(parsed);
|
|
202
|
+
}
|
|
203
|
+
if (valueType === "u64") {
|
|
204
|
+
return Number(parsed);
|
|
205
|
+
}
|
|
206
|
+
return parsed;
|
|
207
|
+
}
|
|
208
|
+
function parseStringGameDetail(value) {
|
|
209
|
+
const bytes = Uint8Array.from(value);
|
|
210
|
+
try {
|
|
211
|
+
return bcs.bcs.String.parse(bytes);
|
|
212
|
+
} catch {
|
|
213
|
+
return textDecoder.decode(bytes);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
function parseGameDetail(valueType, value) {
|
|
217
|
+
if (valueType === "string") {
|
|
218
|
+
return parseStringGameDetail(value);
|
|
219
|
+
}
|
|
220
|
+
const parsed = GAME_DETAIL_BCS[valueType].parse(Uint8Array.from(value));
|
|
221
|
+
return normalizeGameDetailValue(valueType, parsed);
|
|
222
|
+
}
|
|
223
|
+
function parseGameDetails(gameDetails) {
|
|
224
|
+
return gameDetails.contents.reduce((details, entry) => {
|
|
225
|
+
const valueType = GAME_DETAILS_SCHEMA[entry.key] ?? "string";
|
|
226
|
+
details[entry.key] = parseGameDetail(valueType, entry.value);
|
|
227
|
+
return details;
|
|
228
|
+
}, {});
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
exports.DEFAULT_GAS_BUDGET_MIST = DEFAULT_GAS_BUDGET_MIST;
|
|
232
|
+
exports.DEFAULT_LIMBO_MULTIPLIER_SCALE = DEFAULT_LIMBO_MULTIPLIER_SCALE;
|
|
233
|
+
exports.DEFAULT_RANGE_SCALE = DEFAULT_RANGE_SCALE;
|
|
234
|
+
exports.RANGE_POINT_LIMIT = RANGE_POINT_LIMIT;
|
|
235
|
+
exports.fromMoveFloat = fromMoveFloat;
|
|
236
|
+
exports.fromMoveI64 = fromMoveI64;
|
|
237
|
+
exports.parseCoinType = parseCoinType;
|
|
238
|
+
exports.parseGameDetails = parseGameDetails;
|
|
239
|
+
exports.toBigInt = toBigInt;
|
|
240
|
+
exports.toU16 = toU16;
|
|
241
|
+
exports.toU8 = toU8;
|
package/dist/utils.d.cts
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import * as _mysten_bcs from '@mysten/bcs';
|
|
2
|
+
import { M as MoveStruct } from './index-3P_LBbDM.cjs';
|
|
3
|
+
import '@mysten/sui/bcs';
|
|
4
|
+
import '@mysten/sui/client';
|
|
5
|
+
|
|
6
|
+
declare const BetResultEvent: MoveStruct<{
|
|
7
|
+
player: _mysten_bcs.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
8
|
+
coin_type: MoveStruct<{
|
|
9
|
+
name: _mysten_bcs.BcsType<string, string, "string">;
|
|
10
|
+
}, "0x0000000000000000000000000000000000000000000000000000000000000001::type_name::TypeName">;
|
|
11
|
+
stake_amount: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
|
|
12
|
+
unsafe_oracle_usd_coin_price: MoveStruct<{
|
|
13
|
+
is_negative: _mysten_bcs.BcsType<boolean, boolean, "bool">;
|
|
14
|
+
exp: MoveStruct<{
|
|
15
|
+
bits: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
|
|
16
|
+
}, "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::i64::I64">;
|
|
17
|
+
mant: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
|
|
18
|
+
}, "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::float::Float">;
|
|
19
|
+
adjusted_oracle_usd_coin_price: MoveStruct<{
|
|
20
|
+
is_negative: _mysten_bcs.BcsType<boolean, boolean, "bool">;
|
|
21
|
+
exp: MoveStruct<{
|
|
22
|
+
bits: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
|
|
23
|
+
}, "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::i64::I64">;
|
|
24
|
+
mant: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
|
|
25
|
+
}, "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::float::Float">;
|
|
26
|
+
outcome_amount: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
|
|
27
|
+
game_details: MoveStruct<{
|
|
28
|
+
contents: _mysten_bcs.BcsType<{
|
|
29
|
+
key: string;
|
|
30
|
+
value: number[];
|
|
31
|
+
}[], Iterable<{
|
|
32
|
+
key: string;
|
|
33
|
+
value: Iterable<number> & {
|
|
34
|
+
length: number;
|
|
35
|
+
};
|
|
36
|
+
}> & {
|
|
37
|
+
length: number;
|
|
38
|
+
}, string>;
|
|
39
|
+
}, "0x2::vec_map::VecMap<string, vector<u8>>">;
|
|
40
|
+
metadata: MoveStruct<{
|
|
41
|
+
contents: _mysten_bcs.BcsType<{
|
|
42
|
+
key: string;
|
|
43
|
+
value: number[];
|
|
44
|
+
}[], Iterable<{
|
|
45
|
+
key: string;
|
|
46
|
+
value: Iterable<number> & {
|
|
47
|
+
length: number;
|
|
48
|
+
};
|
|
49
|
+
}> & {
|
|
50
|
+
length: number;
|
|
51
|
+
}, string>;
|
|
52
|
+
}, "0x2::vec_map::VecMap<string, vector<u8>>">;
|
|
53
|
+
}, "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::core::BetResultEvent<phantom T0>">;
|
|
54
|
+
|
|
55
|
+
type BetResultGameDetails = ReturnType<(typeof BetResultEvent)['parse']>['game_details'];
|
|
56
|
+
type ParsedGameDetailValue = string | number | boolean;
|
|
57
|
+
type ParsedGameDetails = Record<string, ParsedGameDetailValue>;
|
|
58
|
+
|
|
59
|
+
declare const DEFAULT_GAS_BUDGET_MIST: bigint;
|
|
60
|
+
declare const DEFAULT_RANGE_SCALE = 1000000;
|
|
61
|
+
declare const RANGE_POINT_LIMIT: number;
|
|
62
|
+
declare const DEFAULT_LIMBO_MULTIPLIER_SCALE = 100;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Normalizes a value into a non-negative `bigint`.
|
|
66
|
+
*
|
|
67
|
+
* Accepted inputs:
|
|
68
|
+
* - `bigint`
|
|
69
|
+
* - finite `number`
|
|
70
|
+
* - base-10 integer `string`
|
|
71
|
+
* - `boolean`
|
|
72
|
+
*
|
|
73
|
+
* Number inputs are truncated toward zero before conversion, so `5.9` becomes
|
|
74
|
+
* `5n`. String and boolean inputs are parsed through the native
|
|
75
|
+
* `BigInt(...)` constructor, so `true` becomes `1n`, `false` becomes `0n`,
|
|
76
|
+
* and only integer strings are accepted.
|
|
77
|
+
*
|
|
78
|
+
* @param value Value to normalize.
|
|
79
|
+
* @returns A non-negative `bigint`.
|
|
80
|
+
* @throws When `value` is not a bigint, finite number, integer string, or
|
|
81
|
+
* boolean.
|
|
82
|
+
* @throws When the normalized value is negative.
|
|
83
|
+
*/
|
|
84
|
+
declare function toBigInt(value: unknown): bigint;
|
|
85
|
+
/**
|
|
86
|
+
* Validates that a value can be safely used as a Move `u8` in the `0..255`
|
|
87
|
+
* range.
|
|
88
|
+
*
|
|
89
|
+
* Accepted inputs:
|
|
90
|
+
* - finite `number`
|
|
91
|
+
* - base-10 integer `string`
|
|
92
|
+
*
|
|
93
|
+
* String inputs are accepted for parsed values such as `'1'`, but only when
|
|
94
|
+
* they are plain non-negative integer strings. This helper does not accept
|
|
95
|
+
* booleans and does not truncate fractional values.
|
|
96
|
+
*
|
|
97
|
+
* @param value Value to validate.
|
|
98
|
+
* @returns The validated `u8` value as a JavaScript `number`.
|
|
99
|
+
* @throws When `value` is not a finite number or integer string.
|
|
100
|
+
* @throws When `value` is not an integer between `0` and `255`.
|
|
101
|
+
*/
|
|
102
|
+
declare function toU8(value: unknown): number;
|
|
103
|
+
/**
|
|
104
|
+
* Validates that a value can be safely used as a Move `u16` in the
|
|
105
|
+
* `0..65535` range.
|
|
106
|
+
*
|
|
107
|
+
* Accepted inputs:
|
|
108
|
+
* - finite `number`
|
|
109
|
+
* - base-10 integer `string`
|
|
110
|
+
*
|
|
111
|
+
* String inputs are accepted for parsed values such as `'1'`, but only when
|
|
112
|
+
* they are plain non-negative integer strings. This helper does not accept
|
|
113
|
+
* booleans and does not truncate fractional values.
|
|
114
|
+
*
|
|
115
|
+
* @param value Value to validate.
|
|
116
|
+
* @returns The validated `u16` value as a JavaScript `number`.
|
|
117
|
+
* @throws When `value` is not a finite number or integer string.
|
|
118
|
+
* @throws When `value` is not an integer between `0` and `65535`.
|
|
119
|
+
*/
|
|
120
|
+
declare function toU16(value: unknown): number;
|
|
121
|
+
|
|
122
|
+
declare const Float: MoveStruct<{
|
|
123
|
+
is_negative: _mysten_bcs.BcsType<boolean, boolean, "bool">;
|
|
124
|
+
exp: MoveStruct<{
|
|
125
|
+
bits: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
|
|
126
|
+
}, "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::i64::I64">;
|
|
127
|
+
mant: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
|
|
128
|
+
}, "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::float::Float">;
|
|
129
|
+
|
|
130
|
+
type MoveFloat = ReturnType<(typeof Float)['parse']>;
|
|
131
|
+
/**
|
|
132
|
+
* Converts a generated Move `i64` wrapper into a JavaScript number.
|
|
133
|
+
*
|
|
134
|
+
* The generated bindings expose signed 64-bit integers through a `{ bits }`
|
|
135
|
+
* field that stores the raw two's-complement bit pattern. This helper
|
|
136
|
+
* reinterprets those bits as a signed `i64` and returns a plain JS number.
|
|
137
|
+
* Invalid or missing input falls back to `0`.
|
|
138
|
+
*
|
|
139
|
+
* @param i64 Generated Move `i64` value, typically used for float exponents.
|
|
140
|
+
* @returns The signed 64-bit value as a JavaScript number.
|
|
141
|
+
*/
|
|
142
|
+
declare function fromMoveI64(i64: MoveFloat['exp']): number;
|
|
143
|
+
/**
|
|
144
|
+
* Converts a generated Move `Float` struct into a JavaScript number.
|
|
145
|
+
*
|
|
146
|
+
* Suigar float values are represented as a sign flag, an unsigned mantissa,
|
|
147
|
+
* and a Move `i64` exponent. This helper rebuilds the numeric value using the
|
|
148
|
+
* same normalization expected by the onchain format and applies the sign at
|
|
149
|
+
* the end. Missing mantissas are treated as `0`, and a zero mantissa returns `0`.
|
|
150
|
+
*
|
|
151
|
+
* @param float Generated Move float value with `mant`, `exp`, and `is_negative`.
|
|
152
|
+
* @returns The decoded floating-point value as a JavaScript number.
|
|
153
|
+
*/
|
|
154
|
+
declare function fromMoveFloat(float: MoveFloat): number;
|
|
155
|
+
/**
|
|
156
|
+
* Extracts and normalizes the first generic coin type from a Move object type.
|
|
157
|
+
*
|
|
158
|
+
* PvP game object types encode the wager coin as their first type parameter,
|
|
159
|
+
* for example `Game<0x2::sui::SUI>`. This helper converts that generic type
|
|
160
|
+
* argument into the SDK's canonical struct tag string.
|
|
161
|
+
*
|
|
162
|
+
* @param type Fully qualified Move object type with the coin type as its first generic argument.
|
|
163
|
+
* @returns Normalized coin type struct tag.
|
|
164
|
+
*/
|
|
165
|
+
declare function parseCoinType(type: string): string;
|
|
166
|
+
/**
|
|
167
|
+
* Decodes `BetResultEvent.game_details` into plain application values.
|
|
168
|
+
*
|
|
169
|
+
* Suigar stores game detail entries as `VecMap<string, vector<u8>>`, so raw BCS
|
|
170
|
+
* decoding leaves each value as bytes. This helper looks up the known schema for
|
|
171
|
+
* each key, parses the bytes into the expected runtime type, and preserves the
|
|
172
|
+
* original onchain keys in the returned object. Unknown keys fall back to
|
|
173
|
+
* string decoding so newer detail fields remain readable by default.
|
|
174
|
+
*
|
|
175
|
+
* @param gameDetails Raw `game_details` map from a decoded bet result event.
|
|
176
|
+
* @returns A plain object with the same keys and decoded string, number, or boolean values.
|
|
177
|
+
*/
|
|
178
|
+
declare function parseGameDetails(gameDetails: BetResultGameDetails): ParsedGameDetails;
|
|
179
|
+
|
|
180
|
+
export { DEFAULT_GAS_BUDGET_MIST, DEFAULT_LIMBO_MULTIPLIER_SCALE, DEFAULT_RANGE_SCALE, RANGE_POINT_LIMIT, fromMoveFloat, fromMoveI64, parseCoinType, parseGameDetails, toBigInt, toU16, toU8 };
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import * as _mysten_bcs from '@mysten/bcs';
|
|
2
|
+
import { M as MoveStruct } from './index-3P_LBbDM.js';
|
|
3
|
+
import '@mysten/sui/bcs';
|
|
4
|
+
import '@mysten/sui/client';
|
|
5
|
+
|
|
6
|
+
declare const BetResultEvent: MoveStruct<{
|
|
7
|
+
player: _mysten_bcs.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
8
|
+
coin_type: MoveStruct<{
|
|
9
|
+
name: _mysten_bcs.BcsType<string, string, "string">;
|
|
10
|
+
}, "0x0000000000000000000000000000000000000000000000000000000000000001::type_name::TypeName">;
|
|
11
|
+
stake_amount: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
|
|
12
|
+
unsafe_oracle_usd_coin_price: MoveStruct<{
|
|
13
|
+
is_negative: _mysten_bcs.BcsType<boolean, boolean, "bool">;
|
|
14
|
+
exp: MoveStruct<{
|
|
15
|
+
bits: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
|
|
16
|
+
}, "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::i64::I64">;
|
|
17
|
+
mant: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
|
|
18
|
+
}, "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::float::Float">;
|
|
19
|
+
adjusted_oracle_usd_coin_price: MoveStruct<{
|
|
20
|
+
is_negative: _mysten_bcs.BcsType<boolean, boolean, "bool">;
|
|
21
|
+
exp: MoveStruct<{
|
|
22
|
+
bits: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
|
|
23
|
+
}, "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::i64::I64">;
|
|
24
|
+
mant: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
|
|
25
|
+
}, "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::float::Float">;
|
|
26
|
+
outcome_amount: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
|
|
27
|
+
game_details: MoveStruct<{
|
|
28
|
+
contents: _mysten_bcs.BcsType<{
|
|
29
|
+
key: string;
|
|
30
|
+
value: number[];
|
|
31
|
+
}[], Iterable<{
|
|
32
|
+
key: string;
|
|
33
|
+
value: Iterable<number> & {
|
|
34
|
+
length: number;
|
|
35
|
+
};
|
|
36
|
+
}> & {
|
|
37
|
+
length: number;
|
|
38
|
+
}, string>;
|
|
39
|
+
}, "0x2::vec_map::VecMap<string, vector<u8>>">;
|
|
40
|
+
metadata: MoveStruct<{
|
|
41
|
+
contents: _mysten_bcs.BcsType<{
|
|
42
|
+
key: string;
|
|
43
|
+
value: number[];
|
|
44
|
+
}[], Iterable<{
|
|
45
|
+
key: string;
|
|
46
|
+
value: Iterable<number> & {
|
|
47
|
+
length: number;
|
|
48
|
+
};
|
|
49
|
+
}> & {
|
|
50
|
+
length: number;
|
|
51
|
+
}, string>;
|
|
52
|
+
}, "0x2::vec_map::VecMap<string, vector<u8>>">;
|
|
53
|
+
}, "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::core::BetResultEvent<phantom T0>">;
|
|
54
|
+
|
|
55
|
+
type BetResultGameDetails = ReturnType<(typeof BetResultEvent)['parse']>['game_details'];
|
|
56
|
+
type ParsedGameDetailValue = string | number | boolean;
|
|
57
|
+
type ParsedGameDetails = Record<string, ParsedGameDetailValue>;
|
|
58
|
+
|
|
59
|
+
declare const DEFAULT_GAS_BUDGET_MIST: bigint;
|
|
60
|
+
declare const DEFAULT_RANGE_SCALE = 1000000;
|
|
61
|
+
declare const RANGE_POINT_LIMIT: number;
|
|
62
|
+
declare const DEFAULT_LIMBO_MULTIPLIER_SCALE = 100;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Normalizes a value into a non-negative `bigint`.
|
|
66
|
+
*
|
|
67
|
+
* Accepted inputs:
|
|
68
|
+
* - `bigint`
|
|
69
|
+
* - finite `number`
|
|
70
|
+
* - base-10 integer `string`
|
|
71
|
+
* - `boolean`
|
|
72
|
+
*
|
|
73
|
+
* Number inputs are truncated toward zero before conversion, so `5.9` becomes
|
|
74
|
+
* `5n`. String and boolean inputs are parsed through the native
|
|
75
|
+
* `BigInt(...)` constructor, so `true` becomes `1n`, `false` becomes `0n`,
|
|
76
|
+
* and only integer strings are accepted.
|
|
77
|
+
*
|
|
78
|
+
* @param value Value to normalize.
|
|
79
|
+
* @returns A non-negative `bigint`.
|
|
80
|
+
* @throws When `value` is not a bigint, finite number, integer string, or
|
|
81
|
+
* boolean.
|
|
82
|
+
* @throws When the normalized value is negative.
|
|
83
|
+
*/
|
|
84
|
+
declare function toBigInt(value: unknown): bigint;
|
|
85
|
+
/**
|
|
86
|
+
* Validates that a value can be safely used as a Move `u8` in the `0..255`
|
|
87
|
+
* range.
|
|
88
|
+
*
|
|
89
|
+
* Accepted inputs:
|
|
90
|
+
* - finite `number`
|
|
91
|
+
* - base-10 integer `string`
|
|
92
|
+
*
|
|
93
|
+
* String inputs are accepted for parsed values such as `'1'`, but only when
|
|
94
|
+
* they are plain non-negative integer strings. This helper does not accept
|
|
95
|
+
* booleans and does not truncate fractional values.
|
|
96
|
+
*
|
|
97
|
+
* @param value Value to validate.
|
|
98
|
+
* @returns The validated `u8` value as a JavaScript `number`.
|
|
99
|
+
* @throws When `value` is not a finite number or integer string.
|
|
100
|
+
* @throws When `value` is not an integer between `0` and `255`.
|
|
101
|
+
*/
|
|
102
|
+
declare function toU8(value: unknown): number;
|
|
103
|
+
/**
|
|
104
|
+
* Validates that a value can be safely used as a Move `u16` in the
|
|
105
|
+
* `0..65535` range.
|
|
106
|
+
*
|
|
107
|
+
* Accepted inputs:
|
|
108
|
+
* - finite `number`
|
|
109
|
+
* - base-10 integer `string`
|
|
110
|
+
*
|
|
111
|
+
* String inputs are accepted for parsed values such as `'1'`, but only when
|
|
112
|
+
* they are plain non-negative integer strings. This helper does not accept
|
|
113
|
+
* booleans and does not truncate fractional values.
|
|
114
|
+
*
|
|
115
|
+
* @param value Value to validate.
|
|
116
|
+
* @returns The validated `u16` value as a JavaScript `number`.
|
|
117
|
+
* @throws When `value` is not a finite number or integer string.
|
|
118
|
+
* @throws When `value` is not an integer between `0` and `65535`.
|
|
119
|
+
*/
|
|
120
|
+
declare function toU16(value: unknown): number;
|
|
121
|
+
|
|
122
|
+
declare const Float: MoveStruct<{
|
|
123
|
+
is_negative: _mysten_bcs.BcsType<boolean, boolean, "bool">;
|
|
124
|
+
exp: MoveStruct<{
|
|
125
|
+
bits: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
|
|
126
|
+
}, "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::i64::I64">;
|
|
127
|
+
mant: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
|
|
128
|
+
}, "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::float::Float">;
|
|
129
|
+
|
|
130
|
+
type MoveFloat = ReturnType<(typeof Float)['parse']>;
|
|
131
|
+
/**
|
|
132
|
+
* Converts a generated Move `i64` wrapper into a JavaScript number.
|
|
133
|
+
*
|
|
134
|
+
* The generated bindings expose signed 64-bit integers through a `{ bits }`
|
|
135
|
+
* field that stores the raw two's-complement bit pattern. This helper
|
|
136
|
+
* reinterprets those bits as a signed `i64` and returns a plain JS number.
|
|
137
|
+
* Invalid or missing input falls back to `0`.
|
|
138
|
+
*
|
|
139
|
+
* @param i64 Generated Move `i64` value, typically used for float exponents.
|
|
140
|
+
* @returns The signed 64-bit value as a JavaScript number.
|
|
141
|
+
*/
|
|
142
|
+
declare function fromMoveI64(i64: MoveFloat['exp']): number;
|
|
143
|
+
/**
|
|
144
|
+
* Converts a generated Move `Float` struct into a JavaScript number.
|
|
145
|
+
*
|
|
146
|
+
* Suigar float values are represented as a sign flag, an unsigned mantissa,
|
|
147
|
+
* and a Move `i64` exponent. This helper rebuilds the numeric value using the
|
|
148
|
+
* same normalization expected by the onchain format and applies the sign at
|
|
149
|
+
* the end. Missing mantissas are treated as `0`, and a zero mantissa returns `0`.
|
|
150
|
+
*
|
|
151
|
+
* @param float Generated Move float value with `mant`, `exp`, and `is_negative`.
|
|
152
|
+
* @returns The decoded floating-point value as a JavaScript number.
|
|
153
|
+
*/
|
|
154
|
+
declare function fromMoveFloat(float: MoveFloat): number;
|
|
155
|
+
/**
|
|
156
|
+
* Extracts and normalizes the first generic coin type from a Move object type.
|
|
157
|
+
*
|
|
158
|
+
* PvP game object types encode the wager coin as their first type parameter,
|
|
159
|
+
* for example `Game<0x2::sui::SUI>`. This helper converts that generic type
|
|
160
|
+
* argument into the SDK's canonical struct tag string.
|
|
161
|
+
*
|
|
162
|
+
* @param type Fully qualified Move object type with the coin type as its first generic argument.
|
|
163
|
+
* @returns Normalized coin type struct tag.
|
|
164
|
+
*/
|
|
165
|
+
declare function parseCoinType(type: string): string;
|
|
166
|
+
/**
|
|
167
|
+
* Decodes `BetResultEvent.game_details` into plain application values.
|
|
168
|
+
*
|
|
169
|
+
* Suigar stores game detail entries as `VecMap<string, vector<u8>>`, so raw BCS
|
|
170
|
+
* decoding leaves each value as bytes. This helper looks up the known schema for
|
|
171
|
+
* each key, parses the bytes into the expected runtime type, and preserves the
|
|
172
|
+
* original onchain keys in the returned object. Unknown keys fall back to
|
|
173
|
+
* string decoding so newer detail fields remain readable by default.
|
|
174
|
+
*
|
|
175
|
+
* @param gameDetails Raw `game_details` map from a decoded bet result event.
|
|
176
|
+
* @returns A plain object with the same keys and decoded string, number, or boolean values.
|
|
177
|
+
*/
|
|
178
|
+
declare function parseGameDetails(gameDetails: BetResultGameDetails): ParsedGameDetails;
|
|
179
|
+
|
|
180
|
+
export { DEFAULT_GAS_BUDGET_MIST, DEFAULT_LIMBO_MULTIPLIER_SCALE, DEFAULT_RANGE_SCALE, RANGE_POINT_LIMIT, fromMoveFloat, fromMoveI64, parseCoinType, parseGameDetails, toBigInt, toU16, toU8 };
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DEFAULT_GAS_BUDGET_MIST, DEFAULT_LIMBO_MULTIPLIER_SCALE, DEFAULT_RANGE_SCALE, RANGE_POINT_LIMIT, fromMoveFloat, fromMoveI64, parseCoinType, parseGameDetails, toBigInt, toU16, toU8 } from './chunk-TBJ5TYYE.js';
|