@suigar/sdk 2.0.0-beta.14 → 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 +8 -0
  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-Da2uZvVJ.d.cts +0 -98
  146. package/dist/games-Da2uZvVJ.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 -467
  155. package/dist/index.d.ts +0 -467
  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.js DELETED
@@ -1,1470 +0,0 @@
1
- import { MoveStruct, Float, parseCoinType, toBigInt, toU8, DEFAULT_GAS_BUDGET_MIST, normalizeMoveArguments, DEFAULT_LIMBO_MULTIPLIER_SCALE, DEFAULT_RANGE_SCALE } from './chunk-7N55D2TV.js';
2
- import { toBase64, normalizeStructTag, parseStructTag, normalizeSuiAddress, fromHex } from '@mysten/sui/utils';
3
- import { bcs } from '@mysten/sui/bcs';
4
- import { Transaction } from '@mysten/sui/transactions';
5
- import { ClientCache } from '@mysten/sui/client';
6
-
7
- var $moduleName = "0x0000000000000000000000000000000000000000000000000000000000000001::type_name";
8
- var TypeName = new MoveStruct({
9
- name: `${$moduleName}::TypeName`,
10
- fields: {
11
- name: bcs.string()
12
- }
13
- });
14
- var $moduleName2 = "0x2::vec_map";
15
- function Entry(...typeParameters) {
16
- return new MoveStruct({
17
- name: `${$moduleName2}::Entry<${typeParameters[0].name}, ${typeParameters[1].name}>`,
18
- fields: {
19
- key: typeParameters[0],
20
- value: typeParameters[1]
21
- }
22
- });
23
- }
24
- function VecMap(...typeParameters) {
25
- return new MoveStruct({
26
- name: `${$moduleName2}::VecMap<${typeParameters[0].name}, ${typeParameters[1].name}>`,
27
- fields: {
28
- contents: bcs.vector(Entry(typeParameters[0], typeParameters[1]))
29
- }
30
- });
31
- }
32
-
33
- // src/contracts/core/core.ts
34
- var $moduleName3 = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::core";
35
- var BetResultEvent = new MoveStruct({
36
- name: `${$moduleName3}::BetResultEvent<phantom T0>`,
37
- fields: {
38
- player: bcs.Address,
39
- coin_type: TypeName,
40
- stake_amount: bcs.u64(),
41
- unsafe_oracle_usd_coin_price: Float,
42
- adjusted_oracle_usd_coin_price: Float,
43
- outcome_amount: bcs.u64(),
44
- game_details: VecMap(bcs.string(), bcs.vector(bcs.u8())),
45
- metadata: VecMap(bcs.string(), bcs.vector(bcs.u8()))
46
- }
47
- });
48
- var $moduleName4 = "0x0000000000000000000000000000000000000000000000000000000000000001::type_name";
49
- var TypeName2 = new MoveStruct({
50
- name: `${$moduleName4}::TypeName`,
51
- fields: {
52
- name: bcs.string()
53
- }
54
- });
55
- var $moduleName5 = "0x2::balance";
56
- var Balance = new MoveStruct({
57
- name: `${$moduleName5}::Balance<phantom T0>`,
58
- fields: {
59
- value: bcs.u64()
60
- }
61
- });
62
- var $moduleName6 = "0x2::vec_map";
63
- function Entry2(...typeParameters) {
64
- return new MoveStruct({
65
- name: `${$moduleName6}::Entry<${typeParameters[0].name}, ${typeParameters[1].name}>`,
66
- fields: {
67
- key: typeParameters[0],
68
- value: typeParameters[1]
69
- }
70
- });
71
- }
72
- function VecMap2(...typeParameters) {
73
- return new MoveStruct({
74
- name: `${$moduleName6}::VecMap<${typeParameters[0].name}, ${typeParameters[1].name}>`,
75
- fields: {
76
- contents: bcs.vector(Entry2(typeParameters[0], typeParameters[1]))
77
- }
78
- });
79
- }
80
-
81
- // src/contracts/pvp-coinflip/pvp_coinflip.ts
82
- var $moduleName7 = "0xb43cf6583c0c15315c7e66f173af4be79ac40c38aad1fd92ec08638ab2026202::pvp_coinflip";
83
- var PvpCoinflipSettingsKey = new MoveStruct({
84
- name: `${$moduleName7}::PvpCoinflipSettingsKey`,
85
- fields: {
86
- dummy_field: bcs.bool()
87
- }
88
- });
89
- var Game = new MoveStruct({
90
- name: `${$moduleName7}::Game<phantom T0>`,
91
- fields: {
92
- id: bcs.Address,
93
- creator: bcs.Address,
94
- creator_is_tails: bcs.bool(),
95
- is_private: bcs.bool(),
96
- creator_metadata: VecMap2(bcs.string(), bcs.vector(bcs.u8())),
97
- joiner: bcs.Address,
98
- winner: bcs.Address,
99
- stake_per_player: bcs.u64(),
100
- house_edge_bps: bcs.u64(),
101
- stake_pot: Balance
102
- }
103
- });
104
- var GameCreatedEvent = new MoveStruct({
105
- name: `${$moduleName7}::GameCreatedEvent<phantom T0>`,
106
- fields: {
107
- game_id: bcs.Address,
108
- creator: bcs.Address,
109
- creator_is_tails: bcs.bool(),
110
- is_private: bcs.bool(),
111
- joiner_is_tails: bcs.bool(),
112
- stake_per_player: bcs.u64(),
113
- house_edge_bps: bcs.u64(),
114
- coin_type: TypeName2
115
- }
116
- });
117
- var GameResolvedEvent = new MoveStruct({
118
- name: `${$moduleName7}::GameResolvedEvent<phantom T0>`,
119
- fields: {
120
- game_id: bcs.Address,
121
- creator: bcs.Address,
122
- joiner: bcs.Address,
123
- winner: bcs.Address,
124
- creator_is_tails: bcs.bool(),
125
- is_private: bcs.bool(),
126
- joiner_is_tails: bcs.bool(),
127
- stake_per_player: bcs.u64(),
128
- total_pot: bcs.u64(),
129
- house_edge_amount: bcs.u64(),
130
- payout_amount: bcs.u64(),
131
- coin_type: TypeName2
132
- }
133
- });
134
- var GameCancelledEvent = new MoveStruct({
135
- name: `${$moduleName7}::GameCancelledEvent<phantom T0>`,
136
- fields: {
137
- game_id: bcs.Address,
138
- creator: bcs.Address,
139
- creator_is_tails: bcs.bool(),
140
- is_private: bcs.bool(),
141
- stake_per_player: bcs.u64(),
142
- coin_type: TypeName2
143
- }
144
- });
145
- var Parameters = new MoveStruct({
146
- name: `${$moduleName7}::Parameters<phantom T0>`,
147
- fields: {
148
- id: bcs.Address,
149
- house_edge_bps: bcs.u64(),
150
- min_stake: bcs.u64()
151
- }
152
- });
153
- function createGame(options) {
154
- const packageAddress = options.package ?? "0xb43cf6583c0c15315c7e66f173af4be79ac40c38aad1fd92ec08638ab2026202";
155
- const argumentsTypes = [
156
- null,
157
- null,
158
- "bool",
159
- "bool",
160
- "vector<0x1::string::String>",
161
- "vector<vector<u8>>"
162
- ];
163
- return (tx) => tx.moveCall({
164
- package: packageAddress,
165
- module: "pvp_coinflip",
166
- function: "create_game",
167
- arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
168
- typeArguments: options.typeArguments
169
- });
170
- }
171
- function joinGame(options) {
172
- const packageAddress = options.package ?? "0xb43cf6583c0c15315c7e66f173af4be79ac40c38aad1fd92ec08638ab2026202";
173
- const argumentsTypes = [
174
- "0x2::object::ID",
175
- null,
176
- null,
177
- "vector<0x1::string::String>",
178
- "vector<vector<u8>>",
179
- null,
180
- "0x2::clock::Clock",
181
- "0x2::random::Random"
182
- ];
183
- return (tx) => tx.moveCall({
184
- package: packageAddress,
185
- module: "pvp_coinflip",
186
- function: "join_game",
187
- arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
188
- typeArguments: options.typeArguments
189
- });
190
- }
191
- function cancelGame(options) {
192
- const packageAddress = options.package ?? "0xb43cf6583c0c15315c7e66f173af4be79ac40c38aad1fd92ec08638ab2026202";
193
- const argumentsTypes = ["0x2::object::ID", null];
194
- return (tx) => tx.moveCall({
195
- package: packageAddress,
196
- module: "pvp_coinflip",
197
- function: "cancel_game",
198
- arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
199
- typeArguments: options.typeArguments
200
- });
201
- }
202
-
203
- // src/configs/package.mainnet.ts
204
- var MAINNET_PACKAGE_IDS = {
205
- sweetHouse: "0xa1549d73230118716bc08865b8d62454f360ddaf40eee2158e458e52125d4ef1",
206
- core: "0xcbb0929f21450013ebe5e86e7139f2409da2e3ed212c51126a7e6448b795a43f",
207
- coinflip: "0xca96885371150f55653f7fab9e9b146f5a19698b1002bdff42159ea9d2ba7d7e",
208
- limbo: "0x89db6a55ad4e650cad641b6f9fd90b391b22b1d9adbb2cabbfeb94a9eeda7026",
209
- plinko: "0x74a73daff11c11ed05299c93ed770c62ec4dc6756fa99e271e251c2399f49fef",
210
- pvpCoinflip: "0x29162faf01a8135630e0a32bbe4ce47f69607b24dbb1edea3800861f91d0030a",
211
- range: "0xd19e32b0f2a5e541fbd345b4602f8a93a2eee25c16029595b6fef0b1e0461a54",
212
- wheel: "0x6791eac73fe7bf463b7f3b1ea391df265fbc1b96201270664a5a11e2441e9955"
213
- };
214
- var MAINNET_COIN_TYPES = {
215
- sui: "0x2::sui::SUI",
216
- usdc: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC"
217
- };
218
- var MAINNET_PRICE_INFO_OBJECT_IDS = {
219
- sui: "0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37",
220
- usdc: "0x5dec622733a204ca27f5a90d8c2fad453cc6665186fd5dff13a83d0b6c9027ab"
221
- };
222
-
223
- // src/configs/package.testnet.ts
224
- var TESTNET_PACKAGE_IDS = {
225
- sweetHouse: "0xb7f64e5a273aba1ede00caa0a6f8027cc7490c279d17eab12e7100ed20660603",
226
- core: "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc",
227
- coinflip: "0xb35c5f286c443752afc8ccb40125a578a4f32df35617170ccfa17fe180ab80ea",
228
- limbo: "0x96c7841b9b32c59a219760fd656f1c3aceb53cc74a68ec9844a3a696374309f4",
229
- plinko: "0xd3dd2200883af10811724f0bed97591ad155a02efd6332d471ff8b346030dfb7",
230
- pvpCoinflip: "0xb43cf6583c0c15315c7e66f173af4be79ac40c38aad1fd92ec08638ab2026202",
231
- range: "0x096a4cf18b3661e76b2c62b90785418345d52f45b272448794f123a4cb6b6416",
232
- wheel: "0x0997852ded7e13301c42317004bc49704a893aa82997c5706cebee59053a31b7"
233
- };
234
- var TESTNET_COIN_TYPES = {
235
- sui: "0x47c67b9594069c32caa7a6e875ddf31d7fa52602dd22ccb9ebd8d3482aed76dc::test_sui::TEST_SUI",
236
- usdc: "0x47c67b9594069c32caa7a6e875ddf31d7fa52602dd22ccb9ebd8d3482aed76dc::test_usdc::TEST_USDC"
237
- };
238
- var TESTNET_PRICE_INFO_OBJECT_IDS = {
239
- sui: "0x1ebb295c789cc42b3b2a1606482cd1c7124076a0f5676718501fda8c7fd075a0",
240
- usdc: "0x9c4dd4008297ffa5e480684b8100ec21cc934405ed9a25d4e4d7b6259aad9c81"
241
- };
242
-
243
- // src/configs/package.ts
244
- var PACKAGE_IDS = {
245
- mainnet: { ...MAINNET_PACKAGE_IDS },
246
- testnet: { ...TESTNET_PACKAGE_IDS }
247
- };
248
- var COIN_TYPES = {
249
- mainnet: { ...MAINNET_COIN_TYPES },
250
- testnet: { ...TESTNET_COIN_TYPES }
251
- };
252
- var PRICE_INFO_OBJECT_IDS = {
253
- mainnet: { ...MAINNET_PRICE_INFO_OBJECT_IDS },
254
- testnet: { ...TESTNET_PRICE_INFO_OBJECT_IDS }
255
- };
256
-
257
- // src/configs/registry.mainnet.ts
258
- var MAINNET_REGISTRY_IDS = {
259
- pvpCoinflip: "0x3d73568546c539c1da3eb2b8fe917faef3c0acdbec78a67fe6d52800a0729349"
260
- };
261
-
262
- // src/configs/registry.testnet.ts
263
- var TESTNET_REGISTRY_IDS = {
264
- pvpCoinflip: "0x99f20d8e4be012ea14a681144ae72ac349d0a1a1585205880183eb167f075bad"
265
- };
266
-
267
- // src/configs/registry.ts
268
- var REGISTRY_IDS = {
269
- mainnet: { ...MAINNET_REGISTRY_IDS },
270
- testnet: { ...TESTNET_REGISTRY_IDS }
271
- };
272
-
273
- // src/helpers/config.ts
274
- var DEFAULT_CACHE_TTL_MS = 30 * 60 * 1e3;
275
- function resolveSuigarConfig(network) {
276
- const packageIds = PACKAGE_IDS[network];
277
- const registryIds = REGISTRY_IDS[network];
278
- const coinTypes = COIN_TYPES[network];
279
- const priceInfoObjectIds = PRICE_INFO_OBJECT_IDS[network];
280
- return {
281
- packageIds: { ...packageIds },
282
- registryIds: { ...registryIds },
283
- coinTypes: {
284
- sui: normalizeStructTag(coinTypes.sui),
285
- usdc: normalizeStructTag(coinTypes.usdc)
286
- },
287
- priceInfoObjectIds: {
288
- sui: priceInfoObjectIds.sui,
289
- usdc: priceInfoObjectIds.usdc
290
- }
291
- };
292
- }
293
- function assertConfiguredBetGame(config, game) {
294
- if (!resolveGamePackageId(config, game)) {
295
- throw new Error(`Missing required config for ${game}: packageIds.${game}`);
296
- }
297
- }
298
- function resolveGamePackageId(config, game) {
299
- switch (game) {
300
- case "coinflip":
301
- return config.packageIds.coinflip;
302
- case "limbo":
303
- return config.packageIds.limbo;
304
- case "plinko":
305
- return config.packageIds.plinko;
306
- case "pvp-coinflip":
307
- return config.packageIds.pvpCoinflip;
308
- case "range":
309
- return config.packageIds.range;
310
- case "wheel":
311
- return config.packageIds.wheel;
312
- }
313
- }
314
- function resolvePriceInfoObjectId(config, coinType) {
315
- const normalizedCoinType = normalizeStructTag(coinType);
316
- const supportedCoin = resolveSupportedCoin(config, normalizedCoinType);
317
- const objectId = config.priceInfoObjectIds[supportedCoin];
318
- if (!objectId) {
319
- throw new Error(
320
- `Missing price info object configuration for coin type ${coinType}`
321
- );
322
- }
323
- return objectId;
324
- }
325
- function resolveSupportedCoin(config, coinType) {
326
- const [supportedCoin] = Object.entries(config.coinTypes).find(([_, value]) => value === coinType) ?? [];
327
- if (!supportedCoin) {
328
- throw new RangeError(
329
- `Unsupported coin type ${coinType}. Supported coin types: ${Object.values(
330
- config.coinTypes
331
- ).join(", ")}`
332
- );
333
- }
334
- return supportedCoin;
335
- }
336
- function replaceStructTagAddress(structName, address) {
337
- return normalizeStructTag({
338
- ...parseStructTag(structName),
339
- address
340
- });
341
- }
342
- function resolveGameSettingsKeyType(structName, packageId) {
343
- return replaceStructTagAddress(structName, packageId);
344
- }
345
- function resolveCoinTypeNameForTypeNameKey(structName) {
346
- const { address } = parseStructTag(structName);
347
- return replaceStructTagAddress(
348
- structName,
349
- normalizeSuiAddress(address).replace(/^0x/, "")
350
- );
351
- }
352
- var PARTNER_METADATA_KEY = "partner";
353
- var RESERVED_METADATA_KEYS = /* @__PURE__ */ new Set([PARTNER_METADATA_KEY, "referrer"]);
354
- var textEncoder = new TextEncoder();
355
- function encodeString(value) {
356
- try {
357
- return fromHex(value);
358
- } catch {
359
- return textEncoder.encode(value);
360
- }
361
- }
362
- function encodeMetadataValue(value) {
363
- if (value instanceof Uint8Array) {
364
- return Array.from(value);
365
- }
366
- if (Array.isArray(value)) {
367
- return value;
368
- }
369
- return Array.from(encodeString(String(value)));
370
- }
371
- function encodeBetMetadata(metadata, partner) {
372
- const keys = [];
373
- const values = [];
374
- for (const [key, value] of Object.entries(metadata ?? {})) {
375
- if (RESERVED_METADATA_KEYS.has(key)) {
376
- console.warn(
377
- `Metadata key "${key}" is reserved and will be ignored when parsing metadata.`
378
- );
379
- continue;
380
- }
381
- if (value == null) {
382
- continue;
383
- }
384
- keys.push(key);
385
- values.push(encodeMetadataValue(value));
386
- }
387
- if (partner?.trim()) {
388
- keys.unshift(PARTNER_METADATA_KEY);
389
- values.unshift(encodeMetadataValue(partner));
390
- }
391
- return {
392
- keys,
393
- values
394
- };
395
- }
396
- var $moduleName8 = "0xb35c5f286c443752afc8ccb40125a578a4f32df35617170ccfa17fe180ab80ea::coinflip";
397
- var CoinFlipSettingsKey = new MoveStruct({
398
- name: `${$moduleName8}::CoinFlipSettingsKey`,
399
- fields: {
400
- dummy_field: bcs.bool()
401
- }
402
- });
403
- var Parameters2 = new MoveStruct({
404
- name: `${$moduleName8}::Parameters<phantom T0>`,
405
- fields: {
406
- id: bcs.Address,
407
- house_edge: bcs.u64(),
408
- min_stake: bcs.u64(),
409
- max_stake: bcs.u64()
410
- }
411
- });
412
- function play(options) {
413
- const packageAddress = options.package ?? "0xb35c5f286c443752afc8ccb40125a578a4f32df35617170ccfa17fe180ab80ea";
414
- const argumentsTypes = [
415
- null,
416
- "u64",
417
- null,
418
- "u64",
419
- "bool",
420
- "vector<0x1::string::String>",
421
- "vector<vector<u8>>",
422
- null,
423
- "0x2::clock::Clock",
424
- "0x2::random::Random"
425
- ];
426
- return (tx) => tx.moveCall({
427
- package: packageAddress,
428
- module: "coinflip",
429
- function: "play",
430
- arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
431
- typeArguments: options.typeArguments
432
- });
433
- }
434
-
435
- // src/types/network.type.ts
436
- var SUPPORTED_SUI_NETWORKS = [
437
- "mainnet",
438
- "testnet"
439
- ];
440
-
441
- // src/transactions/shared.ts
442
- function createBaseGameTransaction({
443
- config,
444
- game,
445
- playerAddress,
446
- gasBudget
447
- }) {
448
- assertConfiguredBetGame(config, game);
449
- const tx = new Transaction();
450
- tx.setSenderIfNotSet(normalizeSuiAddress(playerAddress));
451
- tx.setGasBudgetIfNotSet(gasBudget ?? DEFAULT_GAS_BUDGET_MIST);
452
- return tx;
453
- }
454
- function buildSharedStandardGameBetCall({
455
- config,
456
- playerAddress,
457
- coinType,
458
- stake,
459
- cashStake,
460
- betCount,
461
- metadata,
462
- partner,
463
- allowGasCoinShortcut = true,
464
- buildRewardCoin
465
- }) {
466
- return (tx) => {
467
- const normalizedPlayerAddress = normalizeSuiAddress(playerAddress);
468
- const normalizedCoinType = normalizeStructTag(coinType);
469
- const resolvedStake = toBigInt(stake);
470
- const resolvedCashStake = toBigInt(cashStake ?? stake);
471
- const resolvedBetCount = toBigInt(betCount ?? 1);
472
- const encodedMetadata = encodeBetMetadata(metadata, partner);
473
- const priceInfoObjectId = resolvePriceInfoObjectId(
474
- config,
475
- normalizedCoinType
476
- );
477
- const betCoin = tx.coin({
478
- type: normalizedCoinType,
479
- balance: resolvedCashStake,
480
- useGasCoin: allowGasCoinShortcut
481
- });
482
- const rewardCoin = buildRewardCoin({
483
- tx,
484
- config,
485
- playerAddress: normalizedPlayerAddress,
486
- coinType: normalizedCoinType,
487
- stake: resolvedStake,
488
- cashStake: resolvedCashStake,
489
- betCount: resolvedBetCount,
490
- metadata: encodedMetadata,
491
- priceInfoObjectId,
492
- betCoin
493
- });
494
- tx.transferObjects([rewardCoin], tx.pure.address(normalizedPlayerAddress));
495
- return rewardCoin;
496
- };
497
- }
498
- function buildSharedStandardGameBetTransaction(options) {
499
- const tx = createBaseGameTransaction(options);
500
- tx.add(buildSharedStandardGameBetCall(options));
501
- return tx;
502
- }
503
-
504
- // src/transactions/coinflip.ts
505
- function buildCoinflipTransaction(options) {
506
- return buildSharedStandardGameBetTransaction({
507
- ...options,
508
- game: "coinflip",
509
- buildRewardCoin: ({
510
- tx,
511
- config,
512
- coinType,
513
- stake,
514
- betCount,
515
- metadata,
516
- priceInfoObjectId,
517
- betCoin
518
- }) => play({
519
- package: config.packageIds.coinflip,
520
- typeArguments: [coinType],
521
- arguments: [
522
- config.packageIds.sweetHouse,
523
- stake,
524
- betCoin,
525
- betCount,
526
- options.side === "tails",
527
- metadata.keys,
528
- metadata.values,
529
- priceInfoObjectId
530
- ]
531
- })(tx)
532
- });
533
- }
534
- var $moduleName9 = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::i64";
535
- var I64 = new MoveStruct({
536
- name: `${$moduleName9}::I64`,
537
- fields: {
538
- bits: bcs.u64()
539
- }
540
- });
541
-
542
- // src/contracts/limbo/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.ts
543
- var $moduleName10 = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::float";
544
- var Float2 = new MoveStruct({
545
- name: `${$moduleName10}::Float`,
546
- fields: {
547
- is_negative: bcs.bool(),
548
- exp: I64,
549
- mant: bcs.u64()
550
- }
551
- });
552
-
553
- // src/contracts/limbo/limbo.ts
554
- var $moduleName11 = "0x96c7841b9b32c59a219760fd656f1c3aceb53cc74a68ec9844a3a696374309f4::limbo";
555
- var LimboSettingsKey = new MoveStruct({
556
- name: `${$moduleName11}::LimboSettingsKey`,
557
- fields: {
558
- dummy_field: bcs.bool()
559
- }
560
- });
561
- var Parameters3 = new MoveStruct({
562
- name: `${$moduleName11}::Parameters<phantom T0>`,
563
- fields: {
564
- id: bcs.Address,
565
- min_stake: bcs.u64(),
566
- max_stake: bcs.u64(),
567
- max_payout: bcs.u64(),
568
- min_target_multiplier: Float2,
569
- max_target_multiplier: Float2,
570
- max_number_of_games: bcs.u64(),
571
- min_rtp: Float2,
572
- max_rtp: Float2
573
- }
574
- });
575
- function play2(options) {
576
- const packageAddress = options.package ?? "0x96c7841b9b32c59a219760fd656f1c3aceb53cc74a68ec9844a3a696374309f4";
577
- const argumentsTypes = [
578
- null,
579
- "u64",
580
- null,
581
- "u64",
582
- "u64",
583
- "u64",
584
- "vector<0x1::string::String>",
585
- "vector<vector<u8>>",
586
- null,
587
- "0x2::clock::Clock",
588
- "0x2::random::Random"
589
- ];
590
- return (tx) => tx.moveCall({
591
- package: packageAddress,
592
- module: "limbo",
593
- function: "play",
594
- arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
595
- typeArguments: options.typeArguments
596
- });
597
- }
598
-
599
- // src/transactions/limbo.ts
600
- function buildLimboTransaction(options) {
601
- const scale = options.scale ?? DEFAULT_LIMBO_MULTIPLIER_SCALE;
602
- const numerator = Math.round(options.targetMultiplier * scale);
603
- return buildSharedStandardGameBetTransaction({
604
- ...options,
605
- game: "limbo",
606
- buildRewardCoin: ({
607
- tx,
608
- config,
609
- coinType,
610
- stake,
611
- betCount,
612
- metadata,
613
- priceInfoObjectId,
614
- betCoin
615
- }) => play2({
616
- package: config.packageIds.limbo,
617
- typeArguments: [coinType],
618
- arguments: [
619
- config.packageIds.sweetHouse,
620
- stake,
621
- betCoin,
622
- betCount,
623
- BigInt(numerator),
624
- BigInt(scale),
625
- metadata.keys,
626
- metadata.values,
627
- priceInfoObjectId
628
- ]
629
- })(tx)
630
- });
631
- }
632
- var $moduleName12 = "0x2::vec_map";
633
- function Entry3(...typeParameters) {
634
- return new MoveStruct({
635
- name: `${$moduleName12}::Entry<${typeParameters[0].name}, ${typeParameters[1].name}>`,
636
- fields: {
637
- key: typeParameters[0],
638
- value: typeParameters[1]
639
- }
640
- });
641
- }
642
- function VecMap3(...typeParameters) {
643
- return new MoveStruct({
644
- name: `${$moduleName12}::VecMap<${typeParameters[0].name}, ${typeParameters[1].name}>`,
645
- fields: {
646
- contents: bcs.vector(Entry3(typeParameters[0], typeParameters[1]))
647
- }
648
- });
649
- }
650
- var $moduleName13 = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::i64";
651
- var I642 = new MoveStruct({
652
- name: `${$moduleName13}::I64`,
653
- fields: {
654
- bits: bcs.u64()
655
- }
656
- });
657
-
658
- // src/contracts/plinko/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.ts
659
- var $moduleName14 = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::float";
660
- var Float3 = new MoveStruct({
661
- name: `${$moduleName14}::Float`,
662
- fields: {
663
- is_negative: bcs.bool(),
664
- exp: I642,
665
- mant: bcs.u64()
666
- }
667
- });
668
-
669
- // src/contracts/plinko/plinko.ts
670
- var $moduleName15 = "0xd3dd2200883af10811724f0bed97591ad155a02efd6332d471ff8b346030dfb7::plinko";
671
- var PlinkoSettingsKey = new MoveStruct({
672
- name: `${$moduleName15}::PlinkoSettingsKey`,
673
- fields: {
674
- dummy_field: bcs.bool()
675
- }
676
- });
677
- var PlinkoConfig = new MoveStruct({
678
- name: `${$moduleName15}::PlinkoConfig`,
679
- fields: {
680
- num_rows: bcs.u8(),
681
- multipliers: bcs.vector(Float3),
682
- min_stake: bcs.u64(),
683
- max_stake: bcs.u64(),
684
- is_playable: bcs.bool()
685
- }
686
- });
687
- var Parameters4 = new MoveStruct({
688
- name: `${$moduleName15}::Parameters<phantom T0>`,
689
- fields: {
690
- id: bcs.Address,
691
- min_stake: bcs.u64(),
692
- max_stake: bcs.u64(),
693
- max_number_of_balls: bcs.u64(),
694
- configs: VecMap3(bcs.u8(), PlinkoConfig)
695
- }
696
- });
697
- function play3(options) {
698
- const packageAddress = options.package ?? "0xd3dd2200883af10811724f0bed97591ad155a02efd6332d471ff8b346030dfb7";
699
- const argumentsTypes = [
700
- null,
701
- "u64",
702
- null,
703
- "u64",
704
- "u8",
705
- "vector<0x1::string::String>",
706
- "vector<vector<u8>>",
707
- null,
708
- "0x2::clock::Clock",
709
- "0x2::random::Random"
710
- ];
711
- return (tx) => tx.moveCall({
712
- package: packageAddress,
713
- module: "plinko",
714
- function: "play",
715
- arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
716
- typeArguments: options.typeArguments
717
- });
718
- }
719
-
720
- // src/transactions/plinko.ts
721
- function buildPlinkoTransaction(options) {
722
- const configId = toU8(options.configId);
723
- return buildSharedStandardGameBetTransaction({
724
- ...options,
725
- game: "plinko",
726
- buildRewardCoin: ({
727
- tx,
728
- config,
729
- coinType,
730
- stake,
731
- betCount,
732
- metadata,
733
- priceInfoObjectId,
734
- betCoin
735
- }) => play3({
736
- package: config.packageIds.plinko,
737
- typeArguments: [coinType],
738
- arguments: [
739
- config.packageIds.sweetHouse,
740
- stake,
741
- betCoin,
742
- betCount,
743
- configId,
744
- metadata.keys,
745
- metadata.values,
746
- priceInfoObjectId
747
- ]
748
- })(tx)
749
- });
750
- }
751
- function buildPvPCoinflipTransaction(action, options) {
752
- const tx = createBaseGameTransaction({
753
- ...options,
754
- game: "pvp-coinflip"
755
- });
756
- const normalizedCoinType = normalizeStructTag(options.coinType);
757
- const encodedMetadata = encodeBetMetadata(options.metadata, options.partner);
758
- switch (action) {
759
- case "create": {
760
- const createOptions = options;
761
- const stake = toBigInt(createOptions.stake);
762
- const betCoin = tx.coin({
763
- type: normalizedCoinType,
764
- balance: stake,
765
- useGasCoin: createOptions.allowGasCoinShortcut
766
- });
767
- tx.add(
768
- createGame({
769
- package: createOptions.config.packageIds.pvpCoinflip,
770
- typeArguments: [normalizedCoinType],
771
- arguments: [
772
- createOptions.config.packageIds.sweetHouse,
773
- betCoin,
774
- createOptions.side === "tails",
775
- Boolean(createOptions.isPrivate),
776
- encodedMetadata.keys,
777
- encodedMetadata.values
778
- ]
779
- })
780
- );
781
- return tx;
782
- }
783
- case "join": {
784
- const joinOptions = options;
785
- const priceInfoObjectId = resolvePriceInfoObjectId(
786
- joinOptions.config,
787
- normalizedCoinType
788
- );
789
- tx.add(
790
- joinGame({
791
- package: joinOptions.config.packageIds.pvpCoinflip,
792
- typeArguments: [normalizedCoinType],
793
- arguments: [
794
- joinOptions.gameId,
795
- joinOptions.config.packageIds.sweetHouse,
796
- tx.add(joinOptions.betCoin),
797
- encodedMetadata.keys,
798
- encodedMetadata.values,
799
- priceInfoObjectId
800
- ]
801
- })
802
- );
803
- return tx;
804
- }
805
- case "cancel": {
806
- const cancelOptions = options;
807
- tx.add(
808
- cancelGame({
809
- package: cancelOptions.config.packageIds.pvpCoinflip,
810
- typeArguments: [normalizedCoinType],
811
- arguments: [
812
- cancelOptions.gameId,
813
- cancelOptions.config.packageIds.sweetHouse
814
- ]
815
- })
816
- );
817
- return tx;
818
- }
819
- default:
820
- throw new RangeError(`Unsupported PvP coinflip action: ${action}`);
821
- }
822
- }
823
- var $moduleName16 = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::i64";
824
- var I643 = new MoveStruct({
825
- name: `${$moduleName16}::I64`,
826
- fields: {
827
- bits: bcs.u64()
828
- }
829
- });
830
-
831
- // src/contracts/range/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.ts
832
- var $moduleName17 = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::float";
833
- var Float4 = new MoveStruct({
834
- name: `${$moduleName17}::Float`,
835
- fields: {
836
- is_negative: bcs.bool(),
837
- exp: I643,
838
- mant: bcs.u64()
839
- }
840
- });
841
-
842
- // src/contracts/range/range.ts
843
- var $moduleName18 = "0x096a4cf18b3661e76b2c62b90785418345d52f45b272448794f123a4cb6b6416::range";
844
- var RangeSettingsKey = new MoveStruct({
845
- name: `${$moduleName18}::RangeSettingsKey`,
846
- fields: {
847
- dummy_field: bcs.bool()
848
- }
849
- });
850
- var Parameters5 = new MoveStruct({
851
- name: `${$moduleName18}::Parameters<phantom T0>`,
852
- fields: {
853
- id: bcs.Address,
854
- min_stake: bcs.u64(),
855
- max_stake: bcs.u64(),
856
- min_zone_size: bcs.u64(),
857
- max_zone_size: bcs.u64(),
858
- max_number_of_games: bcs.u64(),
859
- min_rtp: Float4,
860
- max_rtp: Float4
861
- }
862
- });
863
- function play4(options) {
864
- const packageAddress = options.package ?? "0x096a4cf18b3661e76b2c62b90785418345d52f45b272448794f123a4cb6b6416";
865
- const argumentsTypes = [
866
- null,
867
- "u64",
868
- null,
869
- "u64",
870
- "u64",
871
- "u64",
872
- "bool",
873
- "vector<0x1::string::String>",
874
- "vector<vector<u8>>",
875
- null,
876
- "0x2::clock::Clock",
877
- "0x2::random::Random"
878
- ];
879
- return (tx) => tx.moveCall({
880
- package: packageAddress,
881
- module: "range",
882
- function: "play",
883
- arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
884
- typeArguments: options.typeArguments
885
- });
886
- }
887
-
888
- // src/transactions/range.ts
889
- function buildRangeTransaction(options) {
890
- const scale = options.scale ?? DEFAULT_RANGE_SCALE;
891
- const leftPoint = Math.round(options.leftPoint * scale);
892
- const rightPoint = Math.round(options.rightPoint * scale);
893
- return buildSharedStandardGameBetTransaction({
894
- ...options,
895
- game: "range",
896
- buildRewardCoin: ({
897
- tx,
898
- config,
899
- coinType,
900
- stake,
901
- betCount,
902
- metadata,
903
- priceInfoObjectId,
904
- betCoin
905
- }) => play4({
906
- package: config.packageIds.range,
907
- typeArguments: [coinType],
908
- arguments: [
909
- config.packageIds.sweetHouse,
910
- stake,
911
- betCoin,
912
- betCount,
913
- BigInt(leftPoint),
914
- BigInt(rightPoint),
915
- Boolean(options.outOfRange),
916
- metadata.keys,
917
- metadata.values,
918
- priceInfoObjectId
919
- ]
920
- })(tx)
921
- });
922
- }
923
- var $moduleName19 = "0x2::vec_map";
924
- function Entry4(...typeParameters) {
925
- return new MoveStruct({
926
- name: `${$moduleName19}::Entry<${typeParameters[0].name}, ${typeParameters[1].name}>`,
927
- fields: {
928
- key: typeParameters[0],
929
- value: typeParameters[1]
930
- }
931
- });
932
- }
933
- function VecMap4(...typeParameters) {
934
- return new MoveStruct({
935
- name: `${$moduleName19}::VecMap<${typeParameters[0].name}, ${typeParameters[1].name}>`,
936
- fields: {
937
- contents: bcs.vector(Entry4(typeParameters[0], typeParameters[1]))
938
- }
939
- });
940
- }
941
- var $moduleName20 = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::i64";
942
- var I644 = new MoveStruct({
943
- name: `${$moduleName20}::I64`,
944
- fields: {
945
- bits: bcs.u64()
946
- }
947
- });
948
-
949
- // src/contracts/wheel/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.ts
950
- var $moduleName21 = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::float";
951
- var Float5 = new MoveStruct({
952
- name: `${$moduleName21}::Float`,
953
- fields: {
954
- is_negative: bcs.bool(),
955
- exp: I644,
956
- mant: bcs.u64()
957
- }
958
- });
959
-
960
- // src/contracts/wheel/wheel.ts
961
- var $moduleName22 = "0x0997852ded7e13301c42317004bc49704a893aa82997c5706cebee59053a31b7::wheel";
962
- var WheelSettingsKey = new MoveStruct({
963
- name: `${$moduleName22}::WheelSettingsKey`,
964
- fields: {
965
- dummy_field: bcs.bool()
966
- }
967
- });
968
- var WheelConfig = new MoveStruct({
969
- name: `${$moduleName22}::WheelConfig`,
970
- fields: {
971
- num_cases: bcs.u8(),
972
- multipliers: bcs.vector(Float5),
973
- min_stake: bcs.u64(),
974
- max_stake: bcs.u64(),
975
- is_playable: bcs.bool()
976
- }
977
- });
978
- var Parameters6 = new MoveStruct({
979
- name: `${$moduleName22}::Parameters<phantom T0>`,
980
- fields: {
981
- id: bcs.Address,
982
- min_stake: bcs.u64(),
983
- max_stake: bcs.u64(),
984
- max_number_of_spins: bcs.u64(),
985
- configs: VecMap4(bcs.u8(), WheelConfig)
986
- }
987
- });
988
- function play5(options) {
989
- const packageAddress = options.package ?? "0x0997852ded7e13301c42317004bc49704a893aa82997c5706cebee59053a31b7";
990
- const argumentsTypes = [
991
- null,
992
- "u64",
993
- null,
994
- "u64",
995
- "u8",
996
- "vector<0x1::string::String>",
997
- "vector<vector<u8>>",
998
- null,
999
- "0x2::clock::Clock",
1000
- "0x2::random::Random"
1001
- ];
1002
- return (tx) => tx.moveCall({
1003
- package: packageAddress,
1004
- module: "wheel",
1005
- function: "play",
1006
- arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
1007
- typeArguments: options.typeArguments
1008
- });
1009
- }
1010
-
1011
- // src/transactions/wheel.ts
1012
- function buildWheelTransaction(options) {
1013
- const configId = toU8(options.configId);
1014
- return buildSharedStandardGameBetTransaction({
1015
- ...options,
1016
- game: "wheel",
1017
- buildRewardCoin: ({
1018
- tx,
1019
- config,
1020
- coinType,
1021
- stake,
1022
- betCount,
1023
- metadata,
1024
- priceInfoObjectId,
1025
- betCoin
1026
- }) => play5({
1027
- package: config.packageIds.wheel,
1028
- typeArguments: [coinType],
1029
- arguments: [
1030
- config.packageIds.sweetHouse,
1031
- stake,
1032
- betCoin,
1033
- betCount,
1034
- configId,
1035
- metadata.keys,
1036
- metadata.values,
1037
- priceInfoObjectId
1038
- ]
1039
- })(tx)
1040
- });
1041
- }
1042
- var TtlClientCache = class extends ClientCache {
1043
- #ttlMs;
1044
- constructor({ ttlMs, ...options }) {
1045
- super({
1046
- ...options,
1047
- prefix: options.prefix ?? ["ttl"]
1048
- });
1049
- this.#ttlMs = ttlMs;
1050
- }
1051
- read(key, load, options) {
1052
- if (options?.ignoreCache) {
1053
- super.clear(key);
1054
- }
1055
- if (this.#ttlMs <= 0) {
1056
- return load();
1057
- }
1058
- const cached = super.read(
1059
- key,
1060
- () => this.#loadEntry(key, load)
1061
- );
1062
- if (cached && cached.expiresAt > Date.now()) {
1063
- return cached.value;
1064
- }
1065
- super.clear(key);
1066
- return super.read(
1067
- key,
1068
- () => this.#loadEntry(key, load)
1069
- ).value;
1070
- }
1071
- readSync(key, load, options) {
1072
- if (options?.ignoreCache) {
1073
- super.clear(key);
1074
- }
1075
- if (this.#ttlMs <= 0) {
1076
- return load();
1077
- }
1078
- const cached = super.readSync(
1079
- key,
1080
- () => this.#loadSyncEntry(load)
1081
- );
1082
- if (cached.expiresAt > Date.now()) {
1083
- return cached.value;
1084
- }
1085
- super.clear(key);
1086
- return super.readSync(key, () => this.#loadSyncEntry(load)).value;
1087
- }
1088
- #loadEntry(key, load) {
1089
- const value = load();
1090
- const entry = {
1091
- value,
1092
- expiresAt: Date.now() + this.#ttlMs
1093
- };
1094
- if (isPromiseLike(value)) {
1095
- entry.value = Promise.resolve(value).then((resolved) => {
1096
- super.clear(key);
1097
- super.read(key, () => ({
1098
- value: resolved,
1099
- expiresAt: Date.now() + this.#ttlMs
1100
- }));
1101
- return resolved;
1102
- }).catch((error) => {
1103
- super.clear(key);
1104
- throw error;
1105
- });
1106
- }
1107
- return entry;
1108
- }
1109
- #loadSyncEntry(load) {
1110
- return {
1111
- value: load(),
1112
- expiresAt: Date.now() + this.#ttlMs
1113
- };
1114
- }
1115
- };
1116
- function isPromiseLike(value) {
1117
- return (typeof value === "object" || typeof value === "function") && value !== null && "then" in value;
1118
- }
1119
-
1120
- // src/types/game-settings.type.ts
1121
- var GAME_SETTINGS = {
1122
- coinflip: {
1123
- settingsKey: CoinFlipSettingsKey,
1124
- parameters: Parameters2
1125
- },
1126
- limbo: {
1127
- settingsKey: LimboSettingsKey,
1128
- parameters: Parameters3
1129
- },
1130
- plinko: {
1131
- settingsKey: PlinkoSettingsKey,
1132
- parameters: Parameters4
1133
- },
1134
- "pvp-coinflip": {
1135
- settingsKey: PvpCoinflipSettingsKey,
1136
- parameters: Parameters
1137
- },
1138
- range: {
1139
- settingsKey: RangeSettingsKey,
1140
- parameters: Parameters5
1141
- },
1142
- wheel: {
1143
- settingsKey: WheelSettingsKey,
1144
- parameters: Parameters6
1145
- }
1146
- };
1147
-
1148
- // src/client.ts
1149
- function suigar({
1150
- name = "suigar",
1151
- partner,
1152
- cacheTtl
1153
- } = {}) {
1154
- return {
1155
- name,
1156
- register: (client) => {
1157
- return new SuigarClient({
1158
- client,
1159
- name: String(name),
1160
- partner,
1161
- cacheTtl
1162
- });
1163
- }
1164
- };
1165
- }
1166
- var SuigarClient = class {
1167
- #client;
1168
- #config;
1169
- #partner;
1170
- #cache;
1171
- constructor({
1172
- client,
1173
- name,
1174
- partner,
1175
- cacheTtl
1176
- }) {
1177
- this.#client = client;
1178
- this.#partner = partner;
1179
- this.#cache = client.cache.scope("@suigar/sdk").readSync([name, "ttl-cache"], () => {
1180
- return new TtlClientCache({
1181
- ttlMs: cacheTtl ?? DEFAULT_CACHE_TTL_MS
1182
- });
1183
- });
1184
- const network = this.#client.network;
1185
- if (!SUPPORTED_SUI_NETWORKS.includes(network)) {
1186
- throw new RangeError(`Unsupported network: ${network}`);
1187
- }
1188
- this.#config = resolveSuigarConfig(network);
1189
- }
1190
- /**
1191
- * Returns the resolved SDK configuration for the connected network.
1192
- *
1193
- * This is primarily useful for debugging or inspecting which package ids,
1194
- * registry ids, supported coin types, and price info object ids the SDK
1195
- * resolved for the current client network.
1196
- *
1197
- * @returns Network-resolved Suigar configuration.
1198
- */
1199
- getConfig() {
1200
- return this.#config;
1201
- }
1202
- /**
1203
- * Builds a transaction with the configured Sui client and encodes the resulting BCS bytes as base64.
1204
- *
1205
- * Use this when an external wallet, API, or transport expects the built transaction payload as a base64 string
1206
- * instead of raw bytes. The SDK always injects the configured Sui client, so `options` accepts the standard
1207
- * transaction build options except for `client`.
1208
- *
1209
- * @param transaction Transaction to build and serialize.
1210
- * @param options Optional transaction build options forwarded to `transaction.build()`, excluding `client`.
1211
- * @returns Base64-encoded transaction bytes ready to send over the wire.
1212
- */
1213
- async serializeTransactionToBase64(transaction, options) {
1214
- const bytes = await transaction.build({ ...options, client: this.#client });
1215
- return toBase64(bytes);
1216
- }
1217
- /**
1218
- * Reads on-chain game parameters for the requested game.
1219
- *
1220
- * The SDK first reads the selected game's settings object from SweetHouse,
1221
- * then reads that game's coin-specific `Parameters<T>` object. Results are
1222
- * cached according to the extension `cacheTtl` option. Pass
1223
- * `ignoreCache: true` to refresh the on-chain read and replace the cached
1224
- * value.
1225
- *
1226
- * @param game Game whose parameters should be loaded.
1227
- * @param options Optional coin type, cache override, and abort signal.
1228
- * @returns Parsed game parameters typed for the requested game.
1229
- */
1230
- async getGameParameters(game, options = {}) {
1231
- const coinType = normalizeStructTag(
1232
- options.coinType ?? this.#config.coinTypes.sui
1233
- );
1234
- return this.#cache.read(
1235
- ["parameters", this.#client.network, game, coinType],
1236
- () => this.#fetchGameParameters(game, coinType, options.signal),
1237
- { ignoreCache: options.ignoreCache }
1238
- );
1239
- }
1240
- /**
1241
- * Lists unresolved PvP coinflip games from the configured registry and resolves
1242
- * each entry into parsed on-chain game state.
1243
- *
1244
- * This fetches dynamic fields from the PvP coinflip registry object, then bulk
1245
- * loads the referenced game objects through `client.core.getObjects()`. Registry
1246
- * membership is the unresolved-state signal: when a game is joined and resolved,
1247
- * the Move flow removes it from the registry and deletes the live `Game` object.
1248
- * Use this when a product needs the current set of open PvP coinflip matches for
1249
- * browsing or lobby views.
1250
- *
1251
- * @param options Optional dynamic field pagination forwarded to `listDynamicFields()`, excluding `parentId`.
1252
- * Supported options such as `limit`, `cursor`, and `signal` are forwarded to the
1253
- * underlying lookup calls. Pass `throwOnError: true` to fail the whole lookup
1254
- * when any referenced game object cannot be fetched or parsed. By default,
1255
- * failed per-object lookups are skipped and only successfully parsed unresolved
1256
- * games are returned.
1257
- * @returns Parsed unresolved PvP coinflip game objects for the requested
1258
- * registry page. When `throwOnError` is `false`, entries that fail object fetch
1259
- * or parse are omitted from the returned array.
1260
- */
1261
- async getPvPCoinflipGames(options = {
1262
- limit: 50
1263
- }) {
1264
- const { throwOnError = false, ...listOptions } = options;
1265
- const { dynamicFields } = await this.#client.core.listDynamicFields({
1266
- ...listOptions,
1267
- parentId: this.#config.registryIds.pvpCoinflip
1268
- });
1269
- const { objects } = await this.#client.core.getObjects({
1270
- objectIds: dynamicFields.map(({ childId }) => childId),
1271
- signal: listOptions.signal,
1272
- include: {
1273
- content: true
1274
- }
1275
- });
1276
- const resolvedGames = objects.map((object) => {
1277
- try {
1278
- if (object instanceof Error) {
1279
- throw object;
1280
- }
1281
- if (!object.content) {
1282
- throw new Error(
1283
- "Unable to resolve PvP coinflip game from retrieved object"
1284
- );
1285
- }
1286
- return {
1287
- ...Game.parse(object.content),
1288
- coinType: parseCoinType(object.type)
1289
- };
1290
- } catch (error) {
1291
- return error instanceof Error ? error : new Error(String(error));
1292
- }
1293
- });
1294
- if (throwOnError) {
1295
- const firstError = resolvedGames.find((game) => game instanceof Error);
1296
- if (firstError) {
1297
- throw firstError;
1298
- }
1299
- }
1300
- return resolvedGames.flatMap(
1301
- (game) => game instanceof Error ? [] : [game]
1302
- );
1303
- }
1304
- /**
1305
- * BCS struct constructors for decoding on-chain objects and events related to Suigar games.
1306
- *
1307
- * These can be used to parse the `content` field of on-chain objects and events into structured data with the
1308
- * expected types. For example, use `client.suigar.bcs.PvPCoinflipGame.parse(object.content)` to decode a PvP
1309
- * coinflip game object.
1310
- *
1311
- * Note that these constructors are not meant for encoding transaction arguments, as the SDK's transaction
1312
- * builders handle argument serialization internally. Use these primarily for decoding and parsing on-chain data.
1313
- */
1314
- bcs = {
1315
- // Objects
1316
- /**
1317
- * Object representing the state of a PvP coinflip game, as stored on-chain.
1318
- */
1319
- PvPCoinflipGame: Game,
1320
- // Events
1321
- /**
1322
- * Event emitted at the end of a standard game (e.g., Coinflip, Limbo), containing the result and payout information.
1323
- */
1324
- BetResultEvent,
1325
- /**
1326
- * Event emitted when a PvP Coinflip game is created, containing the game configuration and initial state.
1327
- */
1328
- PvPCoinflipGameCreatedEvent: GameCreatedEvent,
1329
- /**
1330
- * Event emitted when a PvP Coinflip game is resolved, containing the final outcome.
1331
- */
1332
- PvPCoinflipGameResolvedEvent: GameResolvedEvent,
1333
- /**
1334
- * Event emitted when a PvP Coinflip game is cancelled.
1335
- */
1336
- PvPCoinflipGameCancelledEvent: GameCancelledEvent
1337
- };
1338
- /**
1339
- * Transaction builders for Suigar games.
1340
- */
1341
- tx = {
1342
- /**
1343
- * Creates a standard game transaction for the provided game id.
1344
- *
1345
- * @param gameId Supported standard game identifier.
1346
- * @param options Transaction builder options for the selected game.
1347
- * @returns Prepared transaction for the selected game.
1348
- */
1349
- createBetTransaction: (gameId, options) => {
1350
- switch (gameId) {
1351
- case "coinflip":
1352
- return buildCoinflipTransaction({
1353
- ...options,
1354
- config: this.#config,
1355
- partner: this.#partner
1356
- });
1357
- case "limbo":
1358
- return buildLimboTransaction({
1359
- ...options,
1360
- config: this.#config,
1361
- partner: this.#partner
1362
- });
1363
- case "plinko":
1364
- return buildPlinkoTransaction({
1365
- ...options,
1366
- config: this.#config,
1367
- partner: this.#partner
1368
- });
1369
- case "range":
1370
- return buildRangeTransaction({
1371
- ...options,
1372
- config: this.#config,
1373
- partner: this.#partner
1374
- });
1375
- case "wheel":
1376
- return buildWheelTransaction({
1377
- ...options,
1378
- config: this.#config,
1379
- partner: this.#partner
1380
- });
1381
- default:
1382
- throw new RangeError(`Unsupported game: ${gameId}`);
1383
- }
1384
- },
1385
- /**
1386
- * Creates a PvP coinflip transaction for the requested action.
1387
- *
1388
- * @param action PvP coinflip action to perform.
1389
- * @param options Transaction builder options for the selected action.
1390
- * @returns Prepared PvP coinflip transaction.
1391
- */
1392
- createPvPCoinflipTransaction: (action, options) => {
1393
- switch (action) {
1394
- case "create":
1395
- return buildPvPCoinflipTransaction("create", {
1396
- ...options,
1397
- config: this.#config,
1398
- partner: this.#partner
1399
- });
1400
- case "join": {
1401
- const joinOptions = options;
1402
- return buildPvPCoinflipTransaction("join", {
1403
- ...joinOptions,
1404
- betCoin: this.#createPvPCoinflipBetCoin(joinOptions),
1405
- config: this.#config,
1406
- partner: this.#partner
1407
- });
1408
- }
1409
- case "cancel":
1410
- return buildPvPCoinflipTransaction("cancel", {
1411
- ...options,
1412
- config: this.#config,
1413
- partner: this.#partner
1414
- });
1415
- default:
1416
- throw new RangeError(`Unsupported PvP coinflip action: ${action}`);
1417
- }
1418
- }
1419
- };
1420
- #createPvPCoinflipBetCoin(options) {
1421
- return async (tx) => {
1422
- const { json } = await Game.get({
1423
- client: this.#client,
1424
- objectId: options.gameId
1425
- });
1426
- return tx.coin({
1427
- type: options.coinType,
1428
- balance: BigInt(json.stake_per_player),
1429
- useGasCoin: options.allowGasCoinShortcut
1430
- });
1431
- };
1432
- }
1433
- async #fetchGameParameters(game, coinType, signal) {
1434
- const gameDefinition = GAME_SETTINGS[game];
1435
- const { object: settingsObject } = await this.#client.core.getDynamicObjectField({
1436
- parentId: this.#config.packageIds.sweetHouse,
1437
- name: {
1438
- type: resolveGameSettingsKeyType(
1439
- gameDefinition.settingsKey.name,
1440
- resolveGamePackageId(this.#config, game)
1441
- ),
1442
- bcs: gameDefinition.settingsKey.serialize({ dummy_field: false }).toBytes()
1443
- },
1444
- signal
1445
- });
1446
- const { object } = await this.#client.core.getDynamicObjectField({
1447
- parentId: settingsObject.objectId,
1448
- name: {
1449
- type: TypeName.name,
1450
- bcs: TypeName.serialize({
1451
- name: resolveCoinTypeNameForTypeNameKey(coinType)
1452
- }).toBytes()
1453
- },
1454
- include: {
1455
- content: true
1456
- },
1457
- signal
1458
- });
1459
- if (!object?.content) {
1460
- throw new Error(
1461
- `Missing parameters object content for ${game} and coin type ${coinType}`
1462
- );
1463
- }
1464
- return gameDefinition.parameters.parse(
1465
- object.content
1466
- );
1467
- }
1468
- };
1469
-
1470
- export { SuigarClient, suigar };