@suigar/sdk 2.0.0-beta.13 → 2.0.0-beta.15

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.
Files changed (160) hide show
  1. package/CHANGELOG.md +23 -4
  2. package/README.md +22 -8
  3. package/dist/client.d.mts +258 -0
  4. package/dist/client.d.mts.map +1 -0
  5. package/dist/client.mjs +291 -0
  6. package/dist/client.mjs.map +1 -0
  7. package/dist/configs/package.mainnet.mjs +23 -0
  8. package/dist/configs/package.mainnet.mjs.map +1 -0
  9. package/dist/configs/package.mjs +19 -0
  10. package/dist/configs/package.mjs.map +1 -0
  11. package/dist/configs/package.testnet.mjs +23 -0
  12. package/dist/configs/package.testnet.mjs.map +1 -0
  13. package/dist/configs/registry.mainnet.mjs +6 -0
  14. package/dist/configs/registry.mainnet.mjs.map +1 -0
  15. package/dist/configs/registry.mjs +11 -0
  16. package/dist/configs/registry.mjs.map +1 -0
  17. package/dist/configs/registry.testnet.mjs +6 -0
  18. package/dist/configs/registry.testnet.mjs.map +1 -0
  19. package/dist/contracts/coinflip/coinflip.mjs +46 -0
  20. package/dist/contracts/coinflip/coinflip.mjs.map +1 -0
  21. package/dist/contracts/core/core.d.mts +55 -0
  22. package/dist/contracts/core/core.d.mts.map +1 -0
  23. package/dist/contracts/core/core.mjs +22 -0
  24. package/dist/contracts/core/core.mjs.map +1 -0
  25. package/dist/contracts/core/deps/0x0000000000000000000000000000000000000000000000000000000000000001/type_name.mjs +10 -0
  26. package/dist/contracts/core/deps/0x0000000000000000000000000000000000000000000000000000000000000001/type_name.mjs.map +1 -0
  27. package/dist/contracts/core/deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.mjs +26 -0
  28. package/dist/contracts/core/deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.mjs.map +1 -0
  29. package/dist/contracts/core/float.d.mts +14 -0
  30. package/dist/contracts/core/float.d.mts.map +1 -0
  31. package/dist/contracts/core/float.mjs +15 -0
  32. package/dist/contracts/core/float.mjs.map +1 -0
  33. package/dist/contracts/core/i64.mjs +10 -0
  34. package/dist/contracts/core/i64.mjs.map +1 -0
  35. package/dist/contracts/limbo/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.mjs +15 -0
  36. package/dist/contracts/limbo/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.mjs.map +1 -0
  37. package/dist/contracts/limbo/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/i64.mjs +10 -0
  38. package/dist/contracts/limbo/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/i64.mjs.map +1 -0
  39. package/dist/contracts/limbo/limbo.mjs +53 -0
  40. package/dist/contracts/limbo/limbo.mjs.map +1 -0
  41. package/dist/contracts/plinko/deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.mjs +26 -0
  42. package/dist/contracts/plinko/deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.mjs.map +1 -0
  43. package/dist/contracts/plinko/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.mjs +15 -0
  44. package/dist/contracts/plinko/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.mjs.map +1 -0
  45. package/dist/contracts/plinko/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/i64.mjs +10 -0
  46. package/dist/contracts/plinko/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/i64.mjs.map +1 -0
  47. package/dist/contracts/plinko/plinko.mjs +59 -0
  48. package/dist/contracts/plinko/plinko.mjs.map +1 -0
  49. package/dist/contracts/pvp-coinflip/deps/0x0000000000000000000000000000000000000000000000000000000000000001/type_name.mjs +10 -0
  50. package/dist/contracts/pvp-coinflip/deps/0x0000000000000000000000000000000000000000000000000000000000000001/type_name.mjs.map +1 -0
  51. package/dist/contracts/pvp-coinflip/deps/0x0000000000000000000000000000000000000000000000000000000000000002/balance.mjs +10 -0
  52. package/dist/contracts/pvp-coinflip/deps/0x0000000000000000000000000000000000000000000000000000000000000002/balance.mjs.map +1 -0
  53. package/dist/contracts/pvp-coinflip/deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.mjs +26 -0
  54. package/dist/contracts/pvp-coinflip/deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.mjs.map +1 -0
  55. package/dist/contracts/pvp-coinflip/pvp_coinflip.d.mts +34 -0
  56. package/dist/contracts/pvp-coinflip/pvp_coinflip.d.mts.map +1 -0
  57. package/dist/contracts/pvp-coinflip/pvp_coinflip.mjs +131 -0
  58. package/dist/contracts/pvp-coinflip/pvp_coinflip.mjs.map +1 -0
  59. package/dist/contracts/range/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.mjs +15 -0
  60. package/dist/contracts/range/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.mjs.map +1 -0
  61. package/dist/contracts/range/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/i64.mjs +10 -0
  62. package/dist/contracts/range/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/i64.mjs.map +1 -0
  63. package/dist/contracts/range/range.mjs +53 -0
  64. package/dist/contracts/range/range.mjs.map +1 -0
  65. package/dist/contracts/utils/index.d.mts +33 -0
  66. package/dist/contracts/utils/index.d.mts.map +1 -0
  67. package/dist/contracts/utils/index.mjs +119 -0
  68. package/dist/contracts/utils/index.mjs.map +1 -0
  69. package/dist/contracts/wheel/deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.mjs +26 -0
  70. package/dist/contracts/wheel/deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.mjs.map +1 -0
  71. package/dist/contracts/wheel/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.mjs +15 -0
  72. package/dist/contracts/wheel/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.mjs.map +1 -0
  73. package/dist/contracts/wheel/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/i64.mjs +10 -0
  74. package/dist/contracts/wheel/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/i64.mjs.map +1 -0
  75. package/dist/contracts/wheel/wheel.mjs +59 -0
  76. package/dist/contracts/wheel/wheel.mjs.map +1 -0
  77. package/dist/games.d.mts +3 -0
  78. package/dist/games.mjs +1 -0
  79. package/dist/helpers/config.mjs +51 -0
  80. package/dist/helpers/config.mjs.map +1 -0
  81. package/dist/helpers/game-settings.mjs +19 -0
  82. package/dist/helpers/game-settings.mjs.map +1 -0
  83. package/dist/helpers/metadata.mjs +42 -0
  84. package/dist/helpers/metadata.mjs.map +1 -0
  85. package/dist/index.d.mts +2 -0
  86. package/dist/index.mjs +2 -0
  87. package/dist/transactions/coinflip.mjs +27 -0
  88. package/dist/transactions/coinflip.mjs.map +1 -0
  89. package/dist/transactions/limbo.mjs +31 -0
  90. package/dist/transactions/limbo.mjs.map +1 -0
  91. package/dist/transactions/plinko.mjs +29 -0
  92. package/dist/transactions/plinko.mjs.map +1 -0
  93. package/dist/transactions/pvp-coinflip.mjs +70 -0
  94. package/dist/transactions/pvp-coinflip.mjs.map +1 -0
  95. package/dist/transactions/range.mjs +33 -0
  96. package/dist/transactions/range.mjs.map +1 -0
  97. package/dist/transactions/shared.mjs +49 -0
  98. package/dist/transactions/shared.mjs.map +1 -0
  99. package/dist/transactions/wheel.mjs +29 -0
  100. package/dist/transactions/wheel.mjs.map +1 -0
  101. package/dist/ttl-cache.mjs +60 -0
  102. package/dist/ttl-cache.mjs.map +1 -0
  103. package/dist/types/bet-metadata.type.d.mts +7 -0
  104. package/dist/types/bet-metadata.type.d.mts.map +1 -0
  105. package/dist/types/build-game-transaction-options.type.d.mts +9 -0
  106. package/dist/types/build-game-transaction-options.type.d.mts.map +1 -0
  107. package/dist/types/game-details.type.d.mts +73 -0
  108. package/dist/types/game-details.type.d.mts.map +1 -0
  109. package/dist/types/game-details.type.mjs +59 -0
  110. package/dist/types/game-details.type.mjs.map +1 -0
  111. package/dist/types/game-settings.type.d.mts +201 -0
  112. package/dist/types/game-settings.type.d.mts.map +1 -0
  113. package/dist/types/game-settings.type.mjs +37 -0
  114. package/dist/types/game-settings.type.mjs.map +1 -0
  115. package/dist/types/game.type.d.mts +15 -0
  116. package/dist/types/game.type.d.mts.map +1 -0
  117. package/dist/types/game.type.mjs +19 -0
  118. package/dist/types/game.type.mjs.map +1 -0
  119. package/dist/types/index.d.mts +7 -0
  120. package/dist/types/move-float.type.d.mts +7 -0
  121. package/dist/types/move-float.type.d.mts.map +1 -0
  122. package/dist/types/network.type.d.mts +1 -0
  123. package/dist/types/network.type.mjs +6 -0
  124. package/dist/types/network.type.mjs.map +1 -0
  125. package/dist/types/suigar-config.type.d.mts +33 -0
  126. package/dist/types/suigar-config.type.d.mts.map +1 -0
  127. package/dist/types/transaction-options.type.d.mts +63 -0
  128. package/dist/types/transaction-options.type.d.mts.map +1 -0
  129. package/dist/utils/constants.d.mts +8 -0
  130. package/dist/utils/constants.d.mts.map +1 -0
  131. package/dist/utils/constants.mjs +10 -0
  132. package/dist/utils/constants.mjs.map +1 -0
  133. package/dist/utils/numeric.d.mts +86 -0
  134. package/dist/utils/numeric.d.mts.map +1 -0
  135. package/dist/utils/numeric.mjs +148 -0
  136. package/dist/utils/numeric.mjs.map +1 -0
  137. package/dist/utils/parser.d.mts +54 -0
  138. package/dist/utils/parser.d.mts.map +1 -0
  139. package/dist/utils/parser.mjs +94 -0
  140. package/dist/utils/parser.mjs.map +1 -0
  141. package/dist/utils.d.mts +4 -0
  142. package/dist/utils.mjs +4 -0
  143. package/package.json +16 -17
  144. package/dist/chunk-7N55D2TV.js +0 -343
  145. package/dist/games-BHYRg31e.d.cts +0 -98
  146. package/dist/games-BHYRg31e.d.ts +0 -98
  147. package/dist/games.cjs +0 -2
  148. package/dist/games.d.cts +0 -2
  149. package/dist/games.d.ts +0 -2
  150. package/dist/games.js +0 -1
  151. package/dist/index-3P_LBbDM.d.cts +0 -25
  152. package/dist/index-3P_LBbDM.d.ts +0 -25
  153. package/dist/index.cjs +0 -1692
  154. package/dist/index.d.cts +0 -457
  155. package/dist/index.d.ts +0 -457
  156. package/dist/index.js +0 -1470
  157. package/dist/utils.cjs +0 -243
  158. package/dist/utils.d.cts +0 -180
  159. package/dist/utils.d.ts +0 -180
  160. package/dist/utils.js +0 -1
package/dist/index.cjs DELETED
@@ -1,1692 +0,0 @@
1
- 'use strict';
2
-
3
- var utils = require('@mysten/sui/utils');
4
- var bcs = require('@mysten/sui/bcs');
5
- var transactions = require('@mysten/sui/transactions');
6
- var client = require('@mysten/sui/client');
7
-
8
- // src/client.ts
9
- var MOVE_STDLIB_ADDRESS = utils.normalizeSuiAddress("0x1");
10
- var SUI_FRAMEWORK_ADDRESS = utils.normalizeSuiAddress("0x2");
11
- function getPureBcsSchema(typeTag) {
12
- const parsedTag = typeof typeTag === "string" ? bcs.TypeTagSerializer.parseFromStr(typeTag) : typeTag;
13
- if ("u8" in parsedTag) {
14
- return bcs.bcs.U8;
15
- } else if ("u16" in parsedTag) {
16
- return bcs.bcs.U16;
17
- } else if ("u32" in parsedTag) {
18
- return bcs.bcs.U32;
19
- } else if ("u64" in parsedTag) {
20
- return bcs.bcs.U64;
21
- } else if ("u128" in parsedTag) {
22
- return bcs.bcs.U128;
23
- } else if ("u256" in parsedTag) {
24
- return bcs.bcs.U256;
25
- } else if ("address" in parsedTag) {
26
- return bcs.bcs.Address;
27
- } else if ("bool" in parsedTag) {
28
- return bcs.bcs.Bool;
29
- } else if ("vector" in parsedTag) {
30
- const type = getPureBcsSchema(parsedTag.vector);
31
- return type ? bcs.bcs.vector(type) : null;
32
- } else if ("struct" in parsedTag) {
33
- const structTag = parsedTag.struct;
34
- const pkg = utils.normalizeSuiAddress(structTag.address);
35
- if (pkg === MOVE_STDLIB_ADDRESS) {
36
- if ((structTag.module === "ascii" || structTag.module === "string") && structTag.name === "String") {
37
- return bcs.bcs.String;
38
- }
39
- if (structTag.module === "option" && structTag.name === "Option") {
40
- const inner = structTag.typeParams[0];
41
- const type = inner ? getPureBcsSchema(inner) : null;
42
- return type ? bcs.bcs.option(type) : null;
43
- }
44
- }
45
- if (pkg === SUI_FRAMEWORK_ADDRESS && structTag.module === "object" && (structTag.name === "ID" || structTag.name === "UID")) {
46
- return bcs.bcs.Address;
47
- }
48
- }
49
- return null;
50
- }
51
- function normalizeMoveArguments(args, argTypes, parameterNames) {
52
- Array.isArray(args) ? args.length : Object.keys(args).length;
53
- const normalizedArgs = [];
54
- let index = 0;
55
- for (const argType of argTypes) {
56
- if (argType === "0x2::clock::Clock") {
57
- normalizedArgs.push((tx) => tx.object.clock());
58
- continue;
59
- }
60
- if (argType === "0x2::random::Random") {
61
- normalizedArgs.push((tx) => tx.object.random());
62
- continue;
63
- }
64
- if (argType === "0x2::deny_list::DenyList") {
65
- normalizedArgs.push((tx) => tx.object.denyList());
66
- continue;
67
- }
68
- if (argType === "0x3::sui_system::SuiSystemState") {
69
- normalizedArgs.push((tx) => tx.object.system());
70
- continue;
71
- }
72
- let arg;
73
- if (Array.isArray(args)) {
74
- if (index >= args.length) {
75
- throw new Error(
76
- `Invalid number of arguments, expected at least ${index + 1}, got ${args.length}`
77
- );
78
- }
79
- arg = args[index];
80
- } else {
81
- {
82
- throw new Error(`Expected arguments to be passed as an array`);
83
- }
84
- }
85
- index += 1;
86
- if (typeof arg === "function" || transactions.isArgument(arg)) {
87
- normalizedArgs.push(arg);
88
- continue;
89
- }
90
- const bcsType = argType === null ? null : getPureBcsSchema(argType);
91
- if (bcsType) {
92
- const bytes = bcsType.serialize(arg);
93
- normalizedArgs.push((tx) => tx.pure(bytes));
94
- continue;
95
- }
96
- if (typeof arg === "string") {
97
- normalizedArgs.push((tx) => tx.object(arg));
98
- continue;
99
- }
100
- throw new Error(`Invalid argument ${stringify(arg)} for type ${argType}`);
101
- }
102
- return normalizedArgs;
103
- }
104
- var MoveStruct = class extends bcs.BcsStruct {
105
- async get({
106
- objectId,
107
- ...options
108
- }) {
109
- const [res] = await this.getMany({
110
- ...options,
111
- objectIds: [objectId]
112
- });
113
- if (!res) {
114
- throw new Error(`No object found for id ${objectId}`);
115
- }
116
- return res;
117
- }
118
- async getMany({
119
- client,
120
- ...options
121
- }) {
122
- const response = await client.core.getObjects({
123
- ...options,
124
- include: {
125
- ...options.include,
126
- content: true
127
- }
128
- });
129
- return response.objects.map((obj) => {
130
- if (obj instanceof Error) {
131
- throw obj;
132
- }
133
- return {
134
- ...obj,
135
- json: this.parse(obj.content)
136
- };
137
- });
138
- }
139
- };
140
- function stringify(val) {
141
- if (typeof val === "object") {
142
- return JSON.stringify(val, (val2) => val2);
143
- }
144
- if (typeof val === "bigint") {
145
- return val.toString();
146
- }
147
- return val;
148
- }
149
- var $moduleName = "0x0000000000000000000000000000000000000000000000000000000000000001::type_name";
150
- var TypeName = new MoveStruct({
151
- name: `${$moduleName}::TypeName`,
152
- fields: {
153
- name: bcs.bcs.string()
154
- }
155
- });
156
- var $moduleName2 = "0x2::vec_map";
157
- function Entry(...typeParameters) {
158
- return new MoveStruct({
159
- name: `${$moduleName2}::Entry<${typeParameters[0].name}, ${typeParameters[1].name}>`,
160
- fields: {
161
- key: typeParameters[0],
162
- value: typeParameters[1]
163
- }
164
- });
165
- }
166
- function VecMap(...typeParameters) {
167
- return new MoveStruct({
168
- name: `${$moduleName2}::VecMap<${typeParameters[0].name}, ${typeParameters[1].name}>`,
169
- fields: {
170
- contents: bcs.bcs.vector(Entry(typeParameters[0], typeParameters[1]))
171
- }
172
- });
173
- }
174
- var $moduleName3 = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::i64";
175
- var I64 = new MoveStruct({
176
- name: `${$moduleName3}::I64`,
177
- fields: {
178
- bits: bcs.bcs.u64()
179
- }
180
- });
181
-
182
- // src/contracts/core/float.ts
183
- var $moduleName4 = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::float";
184
- var Float = new MoveStruct({
185
- name: `${$moduleName4}::Float`,
186
- fields: {
187
- is_negative: bcs.bcs.bool(),
188
- exp: I64,
189
- mant: bcs.bcs.u64()
190
- }
191
- });
192
-
193
- // src/contracts/core/core.ts
194
- var $moduleName5 = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::core";
195
- var BetResultEvent = new MoveStruct({
196
- name: `${$moduleName5}::BetResultEvent<phantom T0>`,
197
- fields: {
198
- player: bcs.bcs.Address,
199
- coin_type: TypeName,
200
- stake_amount: bcs.bcs.u64(),
201
- unsafe_oracle_usd_coin_price: Float,
202
- adjusted_oracle_usd_coin_price: Float,
203
- outcome_amount: bcs.bcs.u64(),
204
- game_details: VecMap(bcs.bcs.string(), bcs.bcs.vector(bcs.bcs.u8())),
205
- metadata: VecMap(bcs.bcs.string(), bcs.bcs.vector(bcs.bcs.u8()))
206
- }
207
- });
208
- var $moduleName6 = "0x0000000000000000000000000000000000000000000000000000000000000001::type_name";
209
- var TypeName2 = new MoveStruct({
210
- name: `${$moduleName6}::TypeName`,
211
- fields: {
212
- name: bcs.bcs.string()
213
- }
214
- });
215
- var $moduleName7 = "0x2::balance";
216
- var Balance = new MoveStruct({
217
- name: `${$moduleName7}::Balance<phantom T0>`,
218
- fields: {
219
- value: bcs.bcs.u64()
220
- }
221
- });
222
- var $moduleName8 = "0x2::vec_map";
223
- function Entry2(...typeParameters) {
224
- return new MoveStruct({
225
- name: `${$moduleName8}::Entry<${typeParameters[0].name}, ${typeParameters[1].name}>`,
226
- fields: {
227
- key: typeParameters[0],
228
- value: typeParameters[1]
229
- }
230
- });
231
- }
232
- function VecMap2(...typeParameters) {
233
- return new MoveStruct({
234
- name: `${$moduleName8}::VecMap<${typeParameters[0].name}, ${typeParameters[1].name}>`,
235
- fields: {
236
- contents: bcs.bcs.vector(Entry2(typeParameters[0], typeParameters[1]))
237
- }
238
- });
239
- }
240
-
241
- // src/contracts/pvp-coinflip/pvp_coinflip.ts
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
- });
249
- var Game = new MoveStruct({
250
- name: `${$moduleName9}::Game<phantom T0>`,
251
- fields: {
252
- id: bcs.bcs.Address,
253
- creator: bcs.bcs.Address,
254
- creator_is_tails: bcs.bcs.bool(),
255
- is_private: bcs.bcs.bool(),
256
- creator_metadata: VecMap2(bcs.bcs.string(), bcs.bcs.vector(bcs.bcs.u8())),
257
- joiner: bcs.bcs.Address,
258
- winner: bcs.bcs.Address,
259
- stake_per_player: bcs.bcs.u64(),
260
- house_edge_bps: bcs.bcs.u64(),
261
- stake_pot: Balance
262
- }
263
- });
264
- var GameCreatedEvent = new MoveStruct({
265
- name: `${$moduleName9}::GameCreatedEvent<phantom T0>`,
266
- fields: {
267
- game_id: bcs.bcs.Address,
268
- creator: bcs.bcs.Address,
269
- creator_is_tails: bcs.bcs.bool(),
270
- is_private: bcs.bcs.bool(),
271
- joiner_is_tails: bcs.bcs.bool(),
272
- stake_per_player: bcs.bcs.u64(),
273
- house_edge_bps: bcs.bcs.u64(),
274
- coin_type: TypeName2
275
- }
276
- });
277
- var GameResolvedEvent = new MoveStruct({
278
- name: `${$moduleName9}::GameResolvedEvent<phantom T0>`,
279
- fields: {
280
- game_id: bcs.bcs.Address,
281
- creator: bcs.bcs.Address,
282
- joiner: bcs.bcs.Address,
283
- winner: bcs.bcs.Address,
284
- creator_is_tails: bcs.bcs.bool(),
285
- is_private: bcs.bcs.bool(),
286
- joiner_is_tails: bcs.bcs.bool(),
287
- stake_per_player: bcs.bcs.u64(),
288
- total_pot: bcs.bcs.u64(),
289
- house_edge_amount: bcs.bcs.u64(),
290
- payout_amount: bcs.bcs.u64(),
291
- coin_type: TypeName2
292
- }
293
- });
294
- var GameCancelledEvent = new MoveStruct({
295
- name: `${$moduleName9}::GameCancelledEvent<phantom T0>`,
296
- fields: {
297
- game_id: bcs.bcs.Address,
298
- creator: bcs.bcs.Address,
299
- creator_is_tails: bcs.bcs.bool(),
300
- is_private: bcs.bcs.bool(),
301
- stake_per_player: bcs.bcs.u64(),
302
- coin_type: TypeName2
303
- }
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
- });
313
- function createGame(options) {
314
- const packageAddress = options.package ?? "0xb43cf6583c0c15315c7e66f173af4be79ac40c38aad1fd92ec08638ab2026202";
315
- const argumentsTypes = [
316
- null,
317
- null,
318
- "bool",
319
- "bool",
320
- "vector<0x1::string::String>",
321
- "vector<vector<u8>>"
322
- ];
323
- return (tx) => tx.moveCall({
324
- package: packageAddress,
325
- module: "pvp_coinflip",
326
- function: "create_game",
327
- arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
328
- typeArguments: options.typeArguments
329
- });
330
- }
331
- function joinGame(options) {
332
- const packageAddress = options.package ?? "0xb43cf6583c0c15315c7e66f173af4be79ac40c38aad1fd92ec08638ab2026202";
333
- const argumentsTypes = [
334
- "0x2::object::ID",
335
- null,
336
- null,
337
- "vector<0x1::string::String>",
338
- "vector<vector<u8>>",
339
- null,
340
- "0x2::clock::Clock",
341
- "0x2::random::Random"
342
- ];
343
- return (tx) => tx.moveCall({
344
- package: packageAddress,
345
- module: "pvp_coinflip",
346
- function: "join_game",
347
- arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
348
- typeArguments: options.typeArguments
349
- });
350
- }
351
- function cancelGame(options) {
352
- const packageAddress = options.package ?? "0xb43cf6583c0c15315c7e66f173af4be79ac40c38aad1fd92ec08638ab2026202";
353
- const argumentsTypes = ["0x2::object::ID", null];
354
- return (tx) => tx.moveCall({
355
- package: packageAddress,
356
- module: "pvp_coinflip",
357
- function: "cancel_game",
358
- arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
359
- typeArguments: options.typeArguments
360
- });
361
- }
362
-
363
- // src/configs/package.mainnet.ts
364
- var MAINNET_PACKAGE_IDS = {
365
- sweetHouse: "0xa1549d73230118716bc08865b8d62454f360ddaf40eee2158e458e52125d4ef1",
366
- core: "0xcbb0929f21450013ebe5e86e7139f2409da2e3ed212c51126a7e6448b795a43f",
367
- coinflip: "0xca96885371150f55653f7fab9e9b146f5a19698b1002bdff42159ea9d2ba7d7e",
368
- limbo: "0x89db6a55ad4e650cad641b6f9fd90b391b22b1d9adbb2cabbfeb94a9eeda7026",
369
- plinko: "0x74a73daff11c11ed05299c93ed770c62ec4dc6756fa99e271e251c2399f49fef",
370
- pvpCoinflip: "0x29162faf01a8135630e0a32bbe4ce47f69607b24dbb1edea3800861f91d0030a",
371
- range: "0xd19e32b0f2a5e541fbd345b4602f8a93a2eee25c16029595b6fef0b1e0461a54",
372
- wheel: "0x6791eac73fe7bf463b7f3b1ea391df265fbc1b96201270664a5a11e2441e9955"
373
- };
374
- var MAINNET_COIN_TYPES = {
375
- sui: "0x2::sui::SUI",
376
- usdc: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC"
377
- };
378
- var MAINNET_PRICE_INFO_OBJECT_IDS = {
379
- sui: "0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37",
380
- usdc: "0x5dec622733a204ca27f5a90d8c2fad453cc6665186fd5dff13a83d0b6c9027ab"
381
- };
382
-
383
- // src/configs/package.testnet.ts
384
- var TESTNET_PACKAGE_IDS = {
385
- sweetHouse: "0xb7f64e5a273aba1ede00caa0a6f8027cc7490c279d17eab12e7100ed20660603",
386
- core: "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc",
387
- coinflip: "0xb35c5f286c443752afc8ccb40125a578a4f32df35617170ccfa17fe180ab80ea",
388
- limbo: "0x96c7841b9b32c59a219760fd656f1c3aceb53cc74a68ec9844a3a696374309f4",
389
- plinko: "0xd3dd2200883af10811724f0bed97591ad155a02efd6332d471ff8b346030dfb7",
390
- pvpCoinflip: "0xb43cf6583c0c15315c7e66f173af4be79ac40c38aad1fd92ec08638ab2026202",
391
- range: "0x096a4cf18b3661e76b2c62b90785418345d52f45b272448794f123a4cb6b6416",
392
- wheel: "0x0997852ded7e13301c42317004bc49704a893aa82997c5706cebee59053a31b7"
393
- };
394
- var TESTNET_COIN_TYPES = {
395
- sui: "0x47c67b9594069c32caa7a6e875ddf31d7fa52602dd22ccb9ebd8d3482aed76dc::test_sui::TEST_SUI",
396
- usdc: "0x47c67b9594069c32caa7a6e875ddf31d7fa52602dd22ccb9ebd8d3482aed76dc::test_usdc::TEST_USDC"
397
- };
398
- var TESTNET_PRICE_INFO_OBJECT_IDS = {
399
- sui: "0x1ebb295c789cc42b3b2a1606482cd1c7124076a0f5676718501fda8c7fd075a0",
400
- usdc: "0x9c4dd4008297ffa5e480684b8100ec21cc934405ed9a25d4e4d7b6259aad9c81"
401
- };
402
-
403
- // src/configs/package.ts
404
- var PACKAGE_IDS = {
405
- mainnet: { ...MAINNET_PACKAGE_IDS },
406
- testnet: { ...TESTNET_PACKAGE_IDS }
407
- };
408
- var COIN_TYPES = {
409
- mainnet: { ...MAINNET_COIN_TYPES },
410
- testnet: { ...TESTNET_COIN_TYPES }
411
- };
412
- var PRICE_INFO_OBJECT_IDS = {
413
- mainnet: { ...MAINNET_PRICE_INFO_OBJECT_IDS },
414
- testnet: { ...TESTNET_PRICE_INFO_OBJECT_IDS }
415
- };
416
-
417
- // src/configs/registry.mainnet.ts
418
- var PVP_COINFLIP_REGISTRY_ID = "0x3d73568546c539c1da3eb2b8fe917faef3c0acdbec78a67fe6d52800a0729349";
419
-
420
- // src/configs/registry.testnet.ts
421
- var PVP_COINFLIP_REGISTRY_ID2 = "0x99f20d8e4be012ea14a681144ae72ac349d0a1a1585205880183eb167f075bad";
422
-
423
- // src/configs/registry.ts
424
- var REGISTRY_IDS = {
425
- mainnet: {
426
- pvpCoinflip: PVP_COINFLIP_REGISTRY_ID
427
- },
428
- testnet: {
429
- pvpCoinflip: PVP_COINFLIP_REGISTRY_ID2
430
- }
431
- };
432
-
433
- // src/helpers/config.ts
434
- var DEFAULT_CACHE_TTL_MS = 30 * 60 * 1e3;
435
- function resolveSuigarConfig(network) {
436
- const packageIds = PACKAGE_IDS[network];
437
- const registryIds = REGISTRY_IDS[network];
438
- const coinTypes = COIN_TYPES[network];
439
- const priceInfoObjectIds = PRICE_INFO_OBJECT_IDS[network];
440
- return {
441
- packageIds: { ...packageIds },
442
- registryIds: { ...registryIds },
443
- coinTypes: {
444
- sui: utils.normalizeStructTag(coinTypes.sui),
445
- usdc: utils.normalizeStructTag(coinTypes.usdc)
446
- },
447
- priceInfoObjectIds: {
448
- sui: priceInfoObjectIds.sui,
449
- usdc: priceInfoObjectIds.usdc
450
- }
451
- };
452
- }
453
- function assertConfiguredBetGame(config, game) {
454
- if (!resolveGamePackageId(config, game)) {
455
- throw new Error(`Missing required config for ${game}: packageIds.${game}`);
456
- }
457
- }
458
- function resolveGamePackageId(config, game) {
459
- switch (game) {
460
- case "coinflip":
461
- return config.packageIds.coinflip;
462
- case "limbo":
463
- return config.packageIds.limbo;
464
- case "plinko":
465
- return config.packageIds.plinko;
466
- case "pvp-coinflip":
467
- return config.packageIds.pvpCoinflip;
468
- case "range":
469
- return config.packageIds.range;
470
- case "wheel":
471
- return config.packageIds.wheel;
472
- }
473
- }
474
- function resolvePriceInfoObjectId(config, coinType) {
475
- const normalizedCoinType = utils.normalizeStructTag(coinType);
476
- const supportedCoin = resolveSupportedCoin(config, normalizedCoinType);
477
- const objectId = config.priceInfoObjectIds[supportedCoin];
478
- if (!objectId) {
479
- throw new Error(
480
- `Missing price info object configuration for coin type ${coinType}`
481
- );
482
- }
483
- return objectId;
484
- }
485
- function resolveSupportedCoin(config, coinType) {
486
- const [supportedCoin] = Object.entries(config.coinTypes).find(([_, value]) => value === coinType) ?? [];
487
- if (!supportedCoin) {
488
- throw new RangeError(
489
- `Unsupported coin type ${coinType}. Supported coin types: ${Object.values(
490
- config.coinTypes
491
- ).join(", ")}`
492
- );
493
- }
494
- return supportedCoin;
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
- }
512
- var PARTNER_METADATA_KEY = "partner";
513
- var RESERVED_METADATA_KEYS = /* @__PURE__ */ new Set([PARTNER_METADATA_KEY, "referrer"]);
514
- var textEncoder = new TextEncoder();
515
- function encodeString(value) {
516
- try {
517
- return utils.fromHex(value);
518
- } catch {
519
- return textEncoder.encode(value);
520
- }
521
- }
522
- function encodeMetadataValue(value) {
523
- if (value instanceof Uint8Array) {
524
- return Array.from(value);
525
- }
526
- if (Array.isArray(value)) {
527
- return value;
528
- }
529
- return Array.from(encodeString(String(value)));
530
- }
531
- function encodeBetMetadata(metadata, partner) {
532
- const keys = [];
533
- const values = [];
534
- for (const [key, value] of Object.entries(metadata ?? {})) {
535
- if (RESERVED_METADATA_KEYS.has(key)) {
536
- console.warn(
537
- `Metadata key "${key}" is reserved and will be ignored when parsing metadata.`
538
- );
539
- continue;
540
- }
541
- if (value == null) {
542
- continue;
543
- }
544
- keys.push(key);
545
- values.push(encodeMetadataValue(value));
546
- }
547
- if (partner?.trim()) {
548
- keys.unshift(PARTNER_METADATA_KEY);
549
- values.unshift(encodeMetadataValue(partner));
550
- }
551
- return {
552
- keys,
553
- values
554
- };
555
- }
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
- });
572
- function play(options) {
573
- const packageAddress = options.package ?? "0xb35c5f286c443752afc8ccb40125a578a4f32df35617170ccfa17fe180ab80ea";
574
- const argumentsTypes = [
575
- null,
576
- "u64",
577
- null,
578
- "u64",
579
- "bool",
580
- "vector<0x1::string::String>",
581
- "vector<vector<u8>>",
582
- null,
583
- "0x2::clock::Clock",
584
- "0x2::random::Random"
585
- ];
586
- return (tx) => tx.moveCall({
587
- package: packageAddress,
588
- module: "coinflip",
589
- function: "play",
590
- arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
591
- typeArguments: options.typeArguments
592
- });
593
- }
594
- var DEFAULT_GAS_BUDGET_MIST = utils.parseToMist("0.05");
595
- var DEFAULT_RANGE_SCALE = 1e6;
596
- var DEFAULT_LIMBO_MULTIPLIER_SCALE = 100;
597
-
598
- // src/utils/numeric.ts
599
- function assertFiniteNumber(value, errorMessage) {
600
- if (typeof value !== "number" || !Number.isFinite(value)) {
601
- throw new TypeError(`${errorMessage}: ${String(value)}`);
602
- }
603
- }
604
- function toBigInt(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));
615
- }
616
- } catch {
617
- throw new TypeError(
618
- `Value must be a bigint, number, integer string, or boolean: ${value}`
619
- );
620
- }
621
- if (result < 0n) {
622
- throw new RangeError(`Value must be non-negative: ${value}`);
623
- }
624
- return result;
625
- }
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
- );
633
- }
634
- return num;
635
- }
636
- function toU8(value) {
637
- return toBoundedInt(value, 255, "u8");
638
- }
639
-
640
- // src/types/network.type.ts
641
- var SUPPORTED_SUI_NETWORKS = [
642
- "mainnet",
643
- "testnet"
644
- ];
645
-
646
- // src/utils/parser.ts
647
- new TextDecoder();
648
- ({
649
- u8: bcs.bcs.U8,
650
- u64: bcs.bcs.U64,
651
- bool: bcs.bcs.Bool,
652
- string: bcs.bcs.String
653
- });
654
- function parseCoinType(type) {
655
- const coinType = utils.parseStructTag(type).typeParams[0];
656
- if (!coinType) {
657
- throw new TypeError(`Unable to parse coin type from ${type}`);
658
- }
659
- return utils.normalizeStructTag(coinType);
660
- }
661
-
662
- // src/transactions/shared.ts
663
- function createBaseGameTransaction({
664
- config,
665
- game,
666
- playerAddress,
667
- gasBudget
668
- }) {
669
- assertConfiguredBetGame(config, game);
670
- const tx = new transactions.Transaction();
671
- tx.setSenderIfNotSet(utils.normalizeSuiAddress(playerAddress));
672
- tx.setGasBudgetIfNotSet(gasBudget ?? DEFAULT_GAS_BUDGET_MIST);
673
- return tx;
674
- }
675
- function buildSharedStandardGameBetCall({
676
- config,
677
- playerAddress,
678
- coinType,
679
- stake,
680
- cashStake,
681
- betCount,
682
- metadata,
683
- partner,
684
- allowGasCoinShortcut = true,
685
- buildRewardCoin
686
- }) {
687
- return (tx) => {
688
- const normalizedPlayerAddress = utils.normalizeSuiAddress(playerAddress);
689
- const normalizedCoinType = utils.normalizeStructTag(coinType);
690
- const resolvedStake = toBigInt(stake);
691
- const resolvedCashStake = toBigInt(cashStake ?? stake);
692
- const resolvedBetCount = toBigInt(betCount ?? 1);
693
- const encodedMetadata = encodeBetMetadata(metadata, partner);
694
- const priceInfoObjectId = resolvePriceInfoObjectId(
695
- config,
696
- normalizedCoinType
697
- );
698
- const betCoin = tx.coin({
699
- type: normalizedCoinType,
700
- balance: resolvedCashStake,
701
- useGasCoin: allowGasCoinShortcut
702
- });
703
- const rewardCoin = buildRewardCoin({
704
- tx,
705
- config,
706
- playerAddress: normalizedPlayerAddress,
707
- coinType: normalizedCoinType,
708
- stake: resolvedStake,
709
- cashStake: resolvedCashStake,
710
- betCount: resolvedBetCount,
711
- metadata: encodedMetadata,
712
- priceInfoObjectId,
713
- betCoin
714
- });
715
- tx.transferObjects([rewardCoin], tx.pure.address(normalizedPlayerAddress));
716
- return rewardCoin;
717
- };
718
- }
719
- function buildSharedStandardGameBetTransaction(options) {
720
- const tx = createBaseGameTransaction(options);
721
- tx.add(buildSharedStandardGameBetCall(options));
722
- return tx;
723
- }
724
-
725
- // src/transactions/coinflip.ts
726
- function buildCoinflipTransaction(options) {
727
- return buildSharedStandardGameBetTransaction({
728
- ...options,
729
- game: "coinflip",
730
- buildRewardCoin: ({
731
- tx,
732
- config,
733
- coinType,
734
- stake,
735
- betCount,
736
- metadata,
737
- priceInfoObjectId,
738
- betCoin
739
- }) => play({
740
- package: config.packageIds.coinflip,
741
- typeArguments: [coinType],
742
- arguments: [
743
- config.packageIds.sweetHouse,
744
- stake,
745
- betCoin,
746
- betCount,
747
- options.side === "tails",
748
- metadata.keys,
749
- metadata.values,
750
- priceInfoObjectId
751
- ]
752
- })(tx)
753
- });
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
- });
773
-
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
- });
796
- function play2(options) {
797
- const packageAddress = options.package ?? "0x96c7841b9b32c59a219760fd656f1c3aceb53cc74a68ec9844a3a696374309f4";
798
- const argumentsTypes = [
799
- null,
800
- "u64",
801
- null,
802
- "u64",
803
- "u64",
804
- "u64",
805
- "vector<0x1::string::String>",
806
- "vector<vector<u8>>",
807
- null,
808
- "0x2::clock::Clock",
809
- "0x2::random::Random"
810
- ];
811
- return (tx) => tx.moveCall({
812
- package: packageAddress,
813
- module: "limbo",
814
- function: "play",
815
- arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
816
- typeArguments: options.typeArguments
817
- });
818
- }
819
-
820
- // src/transactions/limbo.ts
821
- function buildLimboTransaction(options) {
822
- const scale = options.scale ?? DEFAULT_LIMBO_MULTIPLIER_SCALE;
823
- const numerator = Math.round(options.targetMultiplier * scale);
824
- return buildSharedStandardGameBetTransaction({
825
- ...options,
826
- game: "limbo",
827
- buildRewardCoin: ({
828
- tx,
829
- config,
830
- coinType,
831
- stake,
832
- betCount,
833
- metadata,
834
- priceInfoObjectId,
835
- betCoin
836
- }) => play2({
837
- package: config.packageIds.limbo,
838
- typeArguments: [coinType],
839
- arguments: [
840
- config.packageIds.sweetHouse,
841
- stake,
842
- betCoin,
843
- betCount,
844
- BigInt(numerator),
845
- BigInt(scale),
846
- metadata.keys,
847
- metadata.values,
848
- priceInfoObjectId
849
- ]
850
- })(tx)
851
- });
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
- });
889
-
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
- });
918
- function play3(options) {
919
- const packageAddress = options.package ?? "0xd3dd2200883af10811724f0bed97591ad155a02efd6332d471ff8b346030dfb7";
920
- const argumentsTypes = [
921
- null,
922
- "u64",
923
- null,
924
- "u64",
925
- "u8",
926
- "vector<0x1::string::String>",
927
- "vector<vector<u8>>",
928
- null,
929
- "0x2::clock::Clock",
930
- "0x2::random::Random"
931
- ];
932
- return (tx) => tx.moveCall({
933
- package: packageAddress,
934
- module: "plinko",
935
- function: "play",
936
- arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
937
- typeArguments: options.typeArguments
938
- });
939
- }
940
-
941
- // src/transactions/plinko.ts
942
- function buildPlinkoTransaction(options) {
943
- const configId = toU8(options.configId);
944
- return buildSharedStandardGameBetTransaction({
945
- ...options,
946
- game: "plinko",
947
- buildRewardCoin: ({
948
- tx,
949
- config,
950
- coinType,
951
- stake,
952
- betCount,
953
- metadata,
954
- priceInfoObjectId,
955
- betCoin
956
- }) => play3({
957
- package: config.packageIds.plinko,
958
- typeArguments: [coinType],
959
- arguments: [
960
- config.packageIds.sweetHouse,
961
- stake,
962
- betCoin,
963
- betCount,
964
- configId,
965
- metadata.keys,
966
- metadata.values,
967
- priceInfoObjectId
968
- ]
969
- })(tx)
970
- });
971
- }
972
- function buildPvPCoinflipTransaction(action, options) {
973
- const tx = createBaseGameTransaction({
974
- ...options,
975
- game: "pvp-coinflip"
976
- });
977
- const normalizedCoinType = utils.normalizeStructTag(options.coinType);
978
- const encodedMetadata = encodeBetMetadata(options.metadata, options.partner);
979
- switch (action) {
980
- case "create": {
981
- const createOptions = options;
982
- const stake = toBigInt(createOptions.stake);
983
- const betCoin = tx.coin({
984
- type: normalizedCoinType,
985
- balance: stake,
986
- useGasCoin: createOptions.allowGasCoinShortcut
987
- });
988
- tx.add(
989
- createGame({
990
- package: createOptions.config.packageIds.pvpCoinflip,
991
- typeArguments: [normalizedCoinType],
992
- arguments: [
993
- createOptions.config.packageIds.sweetHouse,
994
- betCoin,
995
- createOptions.side === "tails",
996
- Boolean(createOptions.isPrivate),
997
- encodedMetadata.keys,
998
- encodedMetadata.values
999
- ]
1000
- })
1001
- );
1002
- return tx;
1003
- }
1004
- case "join": {
1005
- const joinOptions = options;
1006
- const priceInfoObjectId = resolvePriceInfoObjectId(
1007
- joinOptions.config,
1008
- normalizedCoinType
1009
- );
1010
- tx.add(
1011
- joinGame({
1012
- package: joinOptions.config.packageIds.pvpCoinflip,
1013
- typeArguments: [normalizedCoinType],
1014
- arguments: [
1015
- joinOptions.gameId,
1016
- joinOptions.config.packageIds.sweetHouse,
1017
- tx.add(joinOptions.betCoin),
1018
- encodedMetadata.keys,
1019
- encodedMetadata.values,
1020
- priceInfoObjectId
1021
- ]
1022
- })
1023
- );
1024
- return tx;
1025
- }
1026
- case "cancel": {
1027
- const cancelOptions = options;
1028
- tx.add(
1029
- cancelGame({
1030
- package: cancelOptions.config.packageIds.pvpCoinflip,
1031
- typeArguments: [normalizedCoinType],
1032
- arguments: [
1033
- cancelOptions.gameId,
1034
- cancelOptions.config.packageIds.sweetHouse
1035
- ]
1036
- })
1037
- );
1038
- return tx;
1039
- }
1040
- default:
1041
- throw new RangeError(`Unsupported PvP coinflip action: ${action}`);
1042
- }
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
- });
1062
-
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
- });
1084
- function play4(options) {
1085
- const packageAddress = options.package ?? "0x096a4cf18b3661e76b2c62b90785418345d52f45b272448794f123a4cb6b6416";
1086
- const argumentsTypes = [
1087
- null,
1088
- "u64",
1089
- null,
1090
- "u64",
1091
- "u64",
1092
- "u64",
1093
- "bool",
1094
- "vector<0x1::string::String>",
1095
- "vector<vector<u8>>",
1096
- null,
1097
- "0x2::clock::Clock",
1098
- "0x2::random::Random"
1099
- ];
1100
- return (tx) => tx.moveCall({
1101
- package: packageAddress,
1102
- module: "range",
1103
- function: "play",
1104
- arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
1105
- typeArguments: options.typeArguments
1106
- });
1107
- }
1108
-
1109
- // src/transactions/range.ts
1110
- function buildRangeTransaction(options) {
1111
- const scale = options.scale ?? DEFAULT_RANGE_SCALE;
1112
- const leftPoint = Math.round(options.leftPoint * scale);
1113
- const rightPoint = Math.round(options.rightPoint * scale);
1114
- return buildSharedStandardGameBetTransaction({
1115
- ...options,
1116
- game: "range",
1117
- buildRewardCoin: ({
1118
- tx,
1119
- config,
1120
- coinType,
1121
- stake,
1122
- betCount,
1123
- metadata,
1124
- priceInfoObjectId,
1125
- betCoin
1126
- }) => play4({
1127
- package: config.packageIds.range,
1128
- typeArguments: [coinType],
1129
- arguments: [
1130
- config.packageIds.sweetHouse,
1131
- stake,
1132
- betCoin,
1133
- betCount,
1134
- BigInt(leftPoint),
1135
- BigInt(rightPoint),
1136
- Boolean(options.outOfRange),
1137
- metadata.keys,
1138
- metadata.values,
1139
- priceInfoObjectId
1140
- ]
1141
- })(tx)
1142
- });
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
- });
1180
-
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
- });
1209
- function play5(options) {
1210
- const packageAddress = options.package ?? "0x0997852ded7e13301c42317004bc49704a893aa82997c5706cebee59053a31b7";
1211
- const argumentsTypes = [
1212
- null,
1213
- "u64",
1214
- null,
1215
- "u64",
1216
- "u8",
1217
- "vector<0x1::string::String>",
1218
- "vector<vector<u8>>",
1219
- null,
1220
- "0x2::clock::Clock",
1221
- "0x2::random::Random"
1222
- ];
1223
- return (tx) => tx.moveCall({
1224
- package: packageAddress,
1225
- module: "wheel",
1226
- function: "play",
1227
- arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
1228
- typeArguments: options.typeArguments
1229
- });
1230
- }
1231
-
1232
- // src/transactions/wheel.ts
1233
- function buildWheelTransaction(options) {
1234
- const configId = toU8(options.configId);
1235
- return buildSharedStandardGameBetTransaction({
1236
- ...options,
1237
- game: "wheel",
1238
- buildRewardCoin: ({
1239
- tx,
1240
- config,
1241
- coinType,
1242
- stake,
1243
- betCount,
1244
- metadata,
1245
- priceInfoObjectId,
1246
- betCoin
1247
- }) => play5({
1248
- package: config.packageIds.wheel,
1249
- typeArguments: [coinType],
1250
- arguments: [
1251
- config.packageIds.sweetHouse,
1252
- stake,
1253
- betCoin,
1254
- betCount,
1255
- configId,
1256
- metadata.keys,
1257
- metadata.values,
1258
- priceInfoObjectId
1259
- ]
1260
- })(tx)
1261
- });
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
- };
1368
-
1369
- // src/client.ts
1370
- function suigar({
1371
- name = "suigar",
1372
- partner,
1373
- cacheTtl
1374
- } = {}) {
1375
- return {
1376
- name,
1377
- register: (client) => {
1378
- return new SuigarClient({
1379
- client,
1380
- name: String(name),
1381
- partner,
1382
- cacheTtl
1383
- });
1384
- }
1385
- };
1386
- }
1387
- var SuigarClient = class {
1388
- #client;
1389
- #config;
1390
- #partner;
1391
- #cache;
1392
- constructor({
1393
- client,
1394
- name,
1395
- partner,
1396
- cacheTtl
1397
- }) {
1398
- this.#client = client;
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
- });
1405
- const network = this.#client.network;
1406
- if (!SUPPORTED_SUI_NETWORKS.includes(network)) {
1407
- throw new RangeError(`Unsupported network: ${network}`);
1408
- }
1409
- this.#config = resolveSuigarConfig(network);
1410
- }
1411
- /**
1412
- * Returns the resolved SDK configuration for the connected network.
1413
- *
1414
- * This is primarily useful for debugging or inspecting which package ids,
1415
- * registry ids, supported coin types, and price info object ids the SDK
1416
- * resolved for the current client network.
1417
- *
1418
- * @returns Network-resolved Suigar configuration.
1419
- */
1420
- getConfig() {
1421
- return this.#config;
1422
- }
1423
- /**
1424
- * Builds a transaction with the configured Sui client and encodes the resulting BCS bytes as base64.
1425
- *
1426
- * Use this when an external wallet, API, or transport expects the built transaction payload as a base64 string
1427
- * instead of raw bytes. The SDK always injects the configured Sui client, so `options` accepts the standard
1428
- * transaction build options except for `client`.
1429
- *
1430
- * @param transaction Transaction to build and serialize.
1431
- * @param options Optional transaction build options forwarded to `transaction.build()`, excluding `client`.
1432
- * @returns Base64-encoded transaction bytes ready to send over the wire.
1433
- */
1434
- async serializeTransactionToBase64(transaction, options) {
1435
- const bytes = await transaction.build({ ...options, client: this.#client });
1436
- return utils.toBase64(bytes);
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 on-chain 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
- }
1461
- /**
1462
- * Lists unresolved PvP coinflip games from the configured registry and resolves
1463
- * each entry into parsed on-chain game state.
1464
- *
1465
- * This fetches dynamic fields from the PvP coinflip registry object, then bulk
1466
- * loads the referenced game objects through `client.core.getObjects()`. Registry
1467
- * membership is the unresolved-state signal: when a game is joined and resolved,
1468
- * the Move flow removes it from the registry and deletes the live `Game` object.
1469
- * Use this when a product needs the current set of open PvP coinflip matches for
1470
- * browsing or lobby views.
1471
- *
1472
- * @param options Optional dynamic field pagination forwarded to `listDynamicFields()`, excluding `parentId`.
1473
- * Supported options such as `limit`, `cursor`, and `signal` are forwarded to the
1474
- * underlying lookup calls. Pass `throwOnError: true` to fail the whole lookup
1475
- * when any referenced game object cannot be fetched or parsed. By default,
1476
- * failed per-object lookups are skipped and only successfully parsed unresolved
1477
- * games are returned.
1478
- * @returns Parsed unresolved PvP coinflip game objects for the requested
1479
- * registry page. When `throwOnError` is `false`, entries that fail object fetch
1480
- * or parse are omitted from the returned array.
1481
- */
1482
- async getPvPCoinflipGames(options = {
1483
- limit: 50
1484
- }) {
1485
- const { throwOnError = false, ...listOptions } = options;
1486
- const { dynamicFields } = await this.#client.core.listDynamicFields({
1487
- ...listOptions,
1488
- parentId: this.#config.registryIds.pvpCoinflip
1489
- });
1490
- const { objects } = await this.#client.core.getObjects({
1491
- objectIds: dynamicFields.map(({ childId }) => childId),
1492
- signal: listOptions.signal,
1493
- include: {
1494
- content: true
1495
- }
1496
- });
1497
- const resolvedGames = objects.map((object) => {
1498
- try {
1499
- if (object instanceof Error) {
1500
- throw object;
1501
- }
1502
- if (!object.content) {
1503
- throw new Error(
1504
- "Unable to resolve PvP coinflip game from retrieved object"
1505
- );
1506
- }
1507
- return {
1508
- ...Game.parse(object.content),
1509
- coinType: parseCoinType(object.type)
1510
- };
1511
- } catch (error) {
1512
- return error instanceof Error ? error : new Error(String(error));
1513
- }
1514
- });
1515
- if (throwOnError) {
1516
- const firstError = resolvedGames.find((game) => game instanceof Error);
1517
- if (firstError) {
1518
- throw firstError;
1519
- }
1520
- }
1521
- return resolvedGames.flatMap(
1522
- (game) => game instanceof Error ? [] : [game]
1523
- );
1524
- }
1525
- /**
1526
- * BCS struct constructors for decoding on-chain objects and events related to Suigar games.
1527
- *
1528
- * These can be used to parse the `content` field of on-chain objects and events into structured data with the
1529
- * expected types. For example, use `client.suigar.bcs.PvPCoinflipGame.parse(object.content)` to decode a PvP
1530
- * coinflip game object.
1531
- *
1532
- * Note that these constructors are not meant for encoding transaction arguments, as the SDK's transaction
1533
- * builders handle argument serialization internally. Use these primarily for decoding and parsing on-chain data.
1534
- */
1535
- bcs = {
1536
- // Objects
1537
- /**
1538
- * Object representing the state of a PvP coinflip game, as stored on-chain.
1539
- */
1540
- PvPCoinflipGame: Game,
1541
- // Events
1542
- /**
1543
- * Event emitted at the end of a standard game (e.g., Coinflip, Limbo), containing the result and payout information.
1544
- */
1545
- BetResultEvent,
1546
- /**
1547
- * Event emitted when a PvP Coinflip game is created, containing the game configuration and initial state.
1548
- */
1549
- PvPCoinflipGameCreatedEvent: GameCreatedEvent,
1550
- /**
1551
- * Event emitted when a PvP Coinflip game is resolved, containing the final outcome.
1552
- */
1553
- PvPCoinflipGameResolvedEvent: GameResolvedEvent,
1554
- /**
1555
- * Event emitted when a PvP Coinflip game is cancelled.
1556
- */
1557
- PvPCoinflipGameCancelledEvent: GameCancelledEvent
1558
- };
1559
- /**
1560
- * Transaction builders for Suigar games.
1561
- */
1562
- tx = {
1563
- /**
1564
- * Creates a standard game transaction for the provided game id.
1565
- *
1566
- * @param gameId Supported standard game identifier.
1567
- * @param options Transaction builder options for the selected game.
1568
- * @returns Prepared transaction for the selected game.
1569
- */
1570
- createBetTransaction: (gameId, options) => {
1571
- switch (gameId) {
1572
- case "coinflip":
1573
- return buildCoinflipTransaction({
1574
- ...options,
1575
- config: this.#config,
1576
- partner: this.#partner
1577
- });
1578
- case "limbo":
1579
- return buildLimboTransaction({
1580
- ...options,
1581
- config: this.#config,
1582
- partner: this.#partner
1583
- });
1584
- case "plinko":
1585
- return buildPlinkoTransaction({
1586
- ...options,
1587
- config: this.#config,
1588
- partner: this.#partner
1589
- });
1590
- case "range":
1591
- return buildRangeTransaction({
1592
- ...options,
1593
- config: this.#config,
1594
- partner: this.#partner
1595
- });
1596
- case "wheel":
1597
- return buildWheelTransaction({
1598
- ...options,
1599
- config: this.#config,
1600
- partner: this.#partner
1601
- });
1602
- default:
1603
- throw new RangeError(`Unsupported game: ${gameId}`);
1604
- }
1605
- },
1606
- /**
1607
- * Creates a PvP coinflip transaction for the requested action.
1608
- *
1609
- * @param action PvP coinflip action to perform.
1610
- * @param options Transaction builder options for the selected action.
1611
- * @returns Prepared PvP coinflip transaction.
1612
- */
1613
- createPvPCoinflipTransaction: (action, options) => {
1614
- switch (action) {
1615
- case "create":
1616
- return buildPvPCoinflipTransaction("create", {
1617
- ...options,
1618
- config: this.#config,
1619
- partner: this.#partner
1620
- });
1621
- case "join": {
1622
- const joinOptions = options;
1623
- return buildPvPCoinflipTransaction("join", {
1624
- ...joinOptions,
1625
- betCoin: this.#createPvPCoinflipBetCoin(joinOptions),
1626
- config: this.#config,
1627
- partner: this.#partner
1628
- });
1629
- }
1630
- case "cancel":
1631
- return buildPvPCoinflipTransaction("cancel", {
1632
- ...options,
1633
- config: this.#config,
1634
- partner: this.#partner
1635
- });
1636
- default:
1637
- throw new RangeError(`Unsupported PvP coinflip action: ${action}`);
1638
- }
1639
- }
1640
- };
1641
- #createPvPCoinflipBetCoin(options) {
1642
- return async (tx) => {
1643
- const { json } = await Game.get({
1644
- client: this.#client,
1645
- objectId: options.gameId
1646
- });
1647
- return tx.coin({
1648
- type: options.coinType,
1649
- balance: BigInt(json.stake_per_player),
1650
- useGasCoin: options.allowGasCoinShortcut
1651
- });
1652
- };
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
- }
1689
- };
1690
-
1691
- exports.SuigarClient = SuigarClient;
1692
- exports.suigar = suigar;