@suigar/sdk 2.0.0-beta.3 → 2.0.0-beta.4

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 ADDED
@@ -0,0 +1,208 @@
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 toBigIntAmount(value, fieldName) {
15
+ if (typeof value === "bigint") {
16
+ if (value < 0n) {
17
+ throw new Error(`${fieldName} must be non-negative`);
18
+ }
19
+ return value;
20
+ }
21
+ if (!Number.isFinite(value) || value < 0) {
22
+ throw new Error(`${fieldName} must be a finite non-negative number`);
23
+ }
24
+ return BigInt(Math.trunc(value));
25
+ }
26
+ function toU8Number(value, fieldName) {
27
+ if (!Number.isInteger(value) || value < 0 || value > 255) {
28
+ throw new Error(`${fieldName} must be an integer between 0 and 255`);
29
+ }
30
+ return value;
31
+ }
32
+ utils.normalizeSuiAddress("0x1");
33
+ utils.normalizeSuiAddress("0x2");
34
+ var MoveStruct = class extends bcs.BcsStruct {
35
+ async get({
36
+ objectId,
37
+ ...options
38
+ }) {
39
+ const [res] = await this.getMany({
40
+ ...options,
41
+ objectIds: [objectId]
42
+ });
43
+ return res;
44
+ }
45
+ async getMany({
46
+ client,
47
+ ...options
48
+ }) {
49
+ const response = await client.core.getObjects({
50
+ ...options,
51
+ include: {
52
+ ...options.include,
53
+ content: true
54
+ }
55
+ });
56
+ return response.objects.map((obj) => {
57
+ if (obj instanceof Error) {
58
+ throw obj;
59
+ }
60
+ return {
61
+ ...obj,
62
+ json: this.parse(obj.content)
63
+ };
64
+ });
65
+ }
66
+ };
67
+ var $moduleName = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::i64";
68
+ var I64 = new MoveStruct({ name: `${$moduleName}::I64`, fields: {
69
+ bits: bcs.bcs.u64()
70
+ } });
71
+
72
+ // src/contracts/core/float.ts
73
+ var $moduleName2 = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::float";
74
+ var Float = new MoveStruct({ name: `${$moduleName2}::Float`, fields: {
75
+ is_negative: bcs.bcs.bool(),
76
+ exp: I64,
77
+ mant: bcs.bcs.u64()
78
+ } });
79
+
80
+ // src/types/game-details.type.ts
81
+ var COINFLIP_GAME_DETAILS_SCHEMA = {
82
+ player_bet: "string",
83
+ coin_outcome: "string"
84
+ };
85
+ var PVP_COINFLIP_GAME_DETAILS_SCHEMA = {
86
+ pvp_result: "string"
87
+ };
88
+ var LIMBO_GAME_DETAILS_SCHEMA = {
89
+ payout_amount: "u64",
90
+ win: "bool",
91
+ roll_multiplier: "float",
92
+ payout_multiplier: "float",
93
+ target_multiplier: "float",
94
+ actual_rtp: "float"
95
+ };
96
+ var RANGE_GAME_DETAILS_SCHEMA = {
97
+ roll_value: "u64",
98
+ win: "bool",
99
+ payout_amount: "u64",
100
+ payout_multiplier: "float",
101
+ left_point: "u64",
102
+ right_point: "u64",
103
+ zone_size: "u64",
104
+ winning_zone_size: "u64",
105
+ is_out_range: "bool",
106
+ bet_threshold: "u64",
107
+ roll_under: "bool",
108
+ range_mode: "u8",
109
+ win_probability: "float",
110
+ win_multiplier: "float",
111
+ actual_rtp: "float"
112
+ };
113
+ var PLINKO_GAME_DETAILS_SCHEMA = {
114
+ slot_index: "u8",
115
+ multiplier: "float",
116
+ payout_amount: "u64",
117
+ plinko_config: "u8"
118
+ };
119
+ var WHEEL_GAME_DETAILS_SCHEMA = {
120
+ case_index: "u8",
121
+ multiplier: "float",
122
+ payout_amount: "u64",
123
+ wheel_config: "u8",
124
+ spin_value: "u64"
125
+ };
126
+ var GAME_DETAILS_SCHEMA = {
127
+ ...COINFLIP_GAME_DETAILS_SCHEMA,
128
+ ...PVP_COINFLIP_GAME_DETAILS_SCHEMA,
129
+ ...LIMBO_GAME_DETAILS_SCHEMA,
130
+ ...RANGE_GAME_DETAILS_SCHEMA,
131
+ ...PLINKO_GAME_DETAILS_SCHEMA,
132
+ ...WHEEL_GAME_DETAILS_SCHEMA
133
+ };
134
+
135
+ // src/utils/parser.ts
136
+ var bcsU8 = bcs.bcs.u8();
137
+ var bcsU64 = bcs.bcs.u64();
138
+ var bcsBool = bcs.bcs.bool();
139
+ var bcsString = bcs.bcs.string();
140
+ var textDecoder = new TextDecoder();
141
+ var GAME_DETAIL_BCS = {
142
+ u8: bcsU8,
143
+ u64: bcsU64,
144
+ bool: bcsBool,
145
+ float: Float,
146
+ string: bcsString
147
+ };
148
+ function parseI64(i64) {
149
+ try {
150
+ const value = BigInt(i64.bits ?? 0);
151
+ const maxPositive = 1n << 63n;
152
+ const twoPow64 = 1n << 64n;
153
+ const signed = value >= maxPositive ? value - twoPow64 : value;
154
+ return Number(signed);
155
+ } catch {
156
+ return 0;
157
+ }
158
+ }
159
+ function parseFloat(float) {
160
+ const mantissa = BigInt(float.mant);
161
+ if (mantissa === 0n) {
162
+ return 0;
163
+ }
164
+ const exponent = parseI64(float.exp) - 52;
165
+ const magnitude = Number(mantissa) * Math.pow(2, exponent);
166
+ return float.is_negative ? -magnitude : magnitude;
167
+ }
168
+ function normalizeGameDetailValue(valueType, parsed) {
169
+ if (valueType === "float") {
170
+ return parseFloat(parsed);
171
+ }
172
+ if (valueType === "u64") {
173
+ return Number(parsed);
174
+ }
175
+ return parsed;
176
+ }
177
+ function parseStringGameDetail(value) {
178
+ const bytes = Uint8Array.from(value);
179
+ try {
180
+ return bcsString.parse(bytes);
181
+ } catch {
182
+ return textDecoder.decode(bytes);
183
+ }
184
+ }
185
+ function parseGameDetail(valueType, value) {
186
+ if (valueType === "string") {
187
+ return parseStringGameDetail(value);
188
+ }
189
+ const parsed = GAME_DETAIL_BCS[valueType].parse(Uint8Array.from(value));
190
+ return normalizeGameDetailValue(valueType, parsed);
191
+ }
192
+ function parseGameDetails(gameDetails) {
193
+ return gameDetails.contents.reduce((details, entry) => {
194
+ const valueType = GAME_DETAILS_SCHEMA[entry.key] ?? "string";
195
+ details[entry.key] = parseGameDetail(valueType, entry.value);
196
+ return details;
197
+ }, {});
198
+ }
199
+
200
+ exports.DEFAULT_GAS_BUDGET_MIST = DEFAULT_GAS_BUDGET_MIST;
201
+ exports.DEFAULT_LIMBO_MULTIPLIER_SCALE = DEFAULT_LIMBO_MULTIPLIER_SCALE;
202
+ exports.DEFAULT_RANGE_SCALE = DEFAULT_RANGE_SCALE;
203
+ exports.RANGE_POINT_LIMIT = RANGE_POINT_LIMIT;
204
+ exports.parseFloat = parseFloat;
205
+ exports.parseGameDetails = parseGameDetails;
206
+ exports.parseI64 = parseI64;
207
+ exports.toBigIntAmount = toBigIntAmount;
208
+ exports.toU8Number = toU8Number;
@@ -0,0 +1,79 @@
1
+ import * as _mysten_bcs from '@mysten/bcs';
2
+ import { M as MoveStruct } from './index-jwSXA8q3.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
+ declare function toBigIntAmount(value: bigint | number, fieldName: string): bigint;
65
+ declare function toU8Number(value: number, fieldName: string): number;
66
+
67
+ declare const Float: MoveStruct<{
68
+ is_negative: _mysten_bcs.BcsType<boolean, boolean, "bool">;
69
+ exp: MoveStruct<{
70
+ bits: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
71
+ }, "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::i64::I64">;
72
+ mant: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
73
+ }, "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::float::Float">;
74
+
75
+ declare function parseI64(i64: ReturnType<(typeof Float)['parse']>['exp']): number;
76
+ declare function parseFloat(float: ReturnType<(typeof Float)['parse']>): number;
77
+ declare function parseGameDetails(gameDetails: BetResultGameDetails): ParsedGameDetails;
78
+
79
+ export { DEFAULT_GAS_BUDGET_MIST, DEFAULT_LIMBO_MULTIPLIER_SCALE, DEFAULT_RANGE_SCALE, RANGE_POINT_LIMIT, parseFloat, parseGameDetails, parseI64, toBigIntAmount, toU8Number };
@@ -0,0 +1,79 @@
1
+ import * as _mysten_bcs from '@mysten/bcs';
2
+ import { M as MoveStruct } from './index-jwSXA8q3.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
+ declare function toBigIntAmount(value: bigint | number, fieldName: string): bigint;
65
+ declare function toU8Number(value: number, fieldName: string): number;
66
+
67
+ declare const Float: MoveStruct<{
68
+ is_negative: _mysten_bcs.BcsType<boolean, boolean, "bool">;
69
+ exp: MoveStruct<{
70
+ bits: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
71
+ }, "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::i64::I64">;
72
+ mant: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
73
+ }, "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::float::Float">;
74
+
75
+ declare function parseI64(i64: ReturnType<(typeof Float)['parse']>['exp']): number;
76
+ declare function parseFloat(float: ReturnType<(typeof Float)['parse']>): number;
77
+ declare function parseGameDetails(gameDetails: BetResultGameDetails): ParsedGameDetails;
78
+
79
+ export { DEFAULT_GAS_BUDGET_MIST, DEFAULT_LIMBO_MULTIPLIER_SCALE, DEFAULT_RANGE_SCALE, RANGE_POINT_LIMIT, parseFloat, parseGameDetails, parseI64, toBigIntAmount, toU8Number };
package/dist/utils.js ADDED
@@ -0,0 +1 @@
1
+ export { DEFAULT_GAS_BUDGET_MIST, DEFAULT_LIMBO_MULTIPLIER_SCALE, DEFAULT_RANGE_SCALE, RANGE_POINT_LIMIT, parseFloat, parseGameDetails, parseI64, toBigIntAmount, toU8Number } from './chunk-W3WZ2BHO.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suigar/sdk",
3
- "version": "2.0.0-beta.3",
3
+ "version": "2.0.0-beta.4",
4
4
  "description": "TypeScript SDK for Suigar v2 Move contracts on Sui.",
5
5
  "keywords": [
6
6
  "suigar",
@@ -27,6 +27,16 @@
27
27
  "types": "./dist/index.d.ts",
28
28
  "import": "./dist/index.js",
29
29
  "require": "./dist/index.cjs"
30
+ },
31
+ "./games": {
32
+ "types": "./dist/games.d.ts",
33
+ "import": "./dist/games.js",
34
+ "require": "./dist/games.cjs"
35
+ },
36
+ "./utils": {
37
+ "types": "./dist/utils.d.ts",
38
+ "import": "./dist/utils.js",
39
+ "require": "./dist/utils.cjs"
30
40
  }
31
41
  },
32
42
  "engines": {
@@ -83,10 +93,18 @@
83
93
  "vitest": "^4.1.5"
84
94
  },
85
95
  "lint-staged": {
86
- "*.{ts,tsx,js,mjs,cjs}": [
96
+ "{src,test,scripts}/**/*.{ts,tsx,js,mjs,cjs}": [
87
97
  "eslint --fix",
88
98
  "prettier --write"
89
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
+ ],
90
108
  "*.{json,md,yml,yaml}": "prettier --write"
91
109
  }
92
110
  }