@mysten/kiosk 0.14.6 → 1.0.1

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 (267) hide show
  1. package/CHANGELOG.md +114 -2
  2. package/dist/client/kiosk-client.d.mts +126 -0
  3. package/dist/client/kiosk-client.d.mts.map +1 -0
  4. package/dist/client/kiosk-client.mjs +124 -0
  5. package/dist/client/kiosk-client.mjs.map +1 -0
  6. package/dist/client/kiosk-transaction.d.mts +236 -0
  7. package/dist/client/kiosk-transaction.d.mts.map +1 -0
  8. package/dist/client/kiosk-transaction.mjs +472 -0
  9. package/dist/client/kiosk-transaction.mjs.map +1 -0
  10. package/dist/client/tp-transaction.d.mts +139 -0
  11. package/dist/client/tp-transaction.d.mts.map +1 -0
  12. package/dist/client/tp-transaction.mjs +273 -0
  13. package/dist/client/tp-transaction.mjs.map +1 -0
  14. package/dist/constants.d.mts +42 -0
  15. package/dist/constants.d.mts.map +1 -0
  16. package/dist/constants.mjs +62 -0
  17. package/dist/constants.mjs.map +1 -0
  18. package/dist/contracts/0x2/bag.mjs +19 -0
  19. package/dist/contracts/0x2/bag.mjs.map +1 -0
  20. package/dist/contracts/0x2/balance.mjs +20 -0
  21. package/dist/contracts/0x2/balance.mjs.map +1 -0
  22. package/dist/contracts/0x2/deps/0x0000000000000000000000000000000000000000000000000000000000000001/type_name.mjs +16 -0
  23. package/dist/contracts/0x2/deps/0x0000000000000000000000000000000000000000000000000000000000000001/type_name.mjs.map +1 -0
  24. package/dist/contracts/0x2/kiosk.mjs +244 -0
  25. package/dist/contracts/0x2/kiosk.mjs.map +1 -0
  26. package/dist/contracts/0x2/kiosk_extension.mjs +25 -0
  27. package/dist/contracts/0x2/kiosk_extension.mjs.map +1 -0
  28. package/dist/contracts/0x2/transfer_policy.mjs +99 -0
  29. package/dist/contracts/0x2/transfer_policy.mjs.map +1 -0
  30. package/dist/contracts/0x2/vec_set.mjs +18 -0
  31. package/dist/contracts/0x2/vec_set.mjs.map +1 -0
  32. package/dist/contracts/kiosk/deps/sui/kiosk.mjs +98 -0
  33. package/dist/contracts/kiosk/deps/sui/kiosk.mjs.map +1 -0
  34. package/dist/contracts/kiosk/floor_price_rule.mjs +70 -0
  35. package/dist/contracts/kiosk/floor_price_rule.mjs.map +1 -0
  36. package/dist/contracts/kiosk/kiosk_lock_rule.mjs +72 -0
  37. package/dist/contracts/kiosk/kiosk_lock_rule.mjs.map +1 -0
  38. package/dist/contracts/kiosk/personal_kiosk.mjs +102 -0
  39. package/dist/contracts/kiosk/personal_kiosk.mjs.map +1 -0
  40. package/dist/contracts/kiosk/personal_kiosk_rule.mjs +66 -0
  41. package/dist/contracts/kiosk/personal_kiosk_rule.mjs.map +1 -0
  42. package/dist/contracts/kiosk/royalty_rule.mjs +115 -0
  43. package/dist/contracts/kiosk/royalty_rule.mjs.map +1 -0
  44. package/dist/contracts/utils/index.mjs +118 -0
  45. package/dist/contracts/utils/index.mjs.map +1 -0
  46. package/dist/index.d.mts +9 -0
  47. package/dist/index.mjs +9 -0
  48. package/dist/query/client-utils.mjs +30 -0
  49. package/dist/query/client-utils.mjs.map +1 -0
  50. package/dist/query/kiosk.mjs +154 -0
  51. package/dist/query/kiosk.mjs.map +1 -0
  52. package/dist/query/transfer-policy.mjs +110 -0
  53. package/dist/query/transfer-policy.mjs.map +1 -0
  54. package/dist/tx/kiosk.mjs +20 -0
  55. package/dist/tx/kiosk.mjs.map +1 -0
  56. package/dist/tx/rules/resolve.mjs +114 -0
  57. package/dist/tx/rules/resolve.mjs.map +1 -0
  58. package/dist/tx/transfer-policy.mjs +38 -0
  59. package/dist/tx/transfer-policy.mjs.map +1 -0
  60. package/dist/types/index.d.mts +23 -0
  61. package/dist/types/index.d.mts.map +1 -0
  62. package/dist/types/kiosk.d.mts +165 -0
  63. package/dist/types/kiosk.d.mts.map +1 -0
  64. package/dist/types/kiosk.mjs +21 -0
  65. package/dist/types/kiosk.mjs.map +1 -0
  66. package/dist/types/transfer-policy.d.mts +56 -0
  67. package/dist/types/transfer-policy.d.mts.map +1 -0
  68. package/dist/types/transfer-policy.mjs +19 -0
  69. package/dist/types/transfer-policy.mjs.map +1 -0
  70. package/dist/utils.d.mts +45 -0
  71. package/dist/utils.d.mts.map +1 -0
  72. package/dist/utils.mjs +156 -0
  73. package/dist/utils.mjs.map +1 -0
  74. package/package.json +31 -20
  75. package/src/client/kiosk-client.ts +42 -5
  76. package/src/client/kiosk-transaction.ts +144 -65
  77. package/src/client/tp-transaction.ts +149 -95
  78. package/src/constants.ts +19 -24
  79. package/src/contracts/0x2/accumulator.ts +24 -0
  80. package/src/contracts/0x2/accumulator_metadata.ts +38 -0
  81. package/src/contracts/0x2/accumulator_settlement.ts +14 -0
  82. package/src/contracts/0x2/address.ts +145 -0
  83. package/src/contracts/0x2/address_alias.ts +92 -0
  84. package/src/contracts/0x2/authenticator_state.ts +44 -0
  85. package/src/contracts/0x2/bag.ts +192 -0
  86. package/src/contracts/0x2/balance.ts +269 -0
  87. package/src/contracts/0x2/bcs.ts +495 -0
  88. package/src/contracts/0x2/bls12381.ts +717 -0
  89. package/src/contracts/0x2/borrow.ts +99 -0
  90. package/src/contracts/0x2/clock.ts +30 -0
  91. package/src/contracts/0x2/coin.ts +977 -0
  92. package/src/contracts/0x2/coin_registry.ts +874 -0
  93. package/src/contracts/0x2/config.ts +30 -0
  94. package/src/contracts/0x2/deny_list.ts +55 -0
  95. package/src/contracts/0x2/deps/0x0000000000000000000000000000000000000000000000000000000000000001/type_name.ts +12 -0
  96. package/src/contracts/0x2/derived_object.ts +95 -0
  97. package/src/contracts/0x2/display.ts +258 -0
  98. package/src/contracts/0x2/dynamic_field.ts +171 -0
  99. package/src/contracts/0x2/dynamic_object_field.ts +167 -0
  100. package/src/contracts/0x2/ecdsa_k1.ts +65 -0
  101. package/src/contracts/0x2/ecdsa_r1.ts +49 -0
  102. package/src/contracts/0x2/ecvrf.ts +29 -0
  103. package/src/contracts/0x2/ed25519.ts +25 -0
  104. package/src/contracts/0x2/event.ts +42 -0
  105. package/src/contracts/0x2/funds_accumulator.ts +86 -0
  106. package/src/contracts/0x2/groth16.ts +171 -0
  107. package/src/contracts/0x2/group_ops.ts +49 -0
  108. package/src/contracts/0x2/hash.ts +37 -0
  109. package/src/contracts/0x2/hex.ts +37 -0
  110. package/src/contracts/0x2/hmac.ts +21 -0
  111. package/src/contracts/0x2/kiosk.ts +797 -0
  112. package/src/contracts/0x2/kiosk_extension.ts +270 -0
  113. package/src/contracts/0x2/linked_table.ts +354 -0
  114. package/src/contracts/0x2/math.ts +117 -0
  115. package/src/contracts/0x2/nitro_attestation.ts +186 -0
  116. package/src/contracts/0x2/object.ts +249 -0
  117. package/src/contracts/0x2/object_bag.ts +210 -0
  118. package/src/contracts/0x2/object_table.ts +200 -0
  119. package/src/contracts/0x2/package.ts +414 -0
  120. package/src/contracts/0x2/party.ts +37 -0
  121. package/src/contracts/0x2/pay.ts +153 -0
  122. package/src/contracts/0x2/poseidon.ts +21 -0
  123. package/src/contracts/0x2/priority_queue.ts +139 -0
  124. package/src/contracts/0x2/random.ts +294 -0
  125. package/src/contracts/0x2/sui.ts +29 -0
  126. package/src/contracts/0x2/table.ts +200 -0
  127. package/src/contracts/0x2/table_vec.ts +232 -0
  128. package/src/contracts/0x2/token.ts +873 -0
  129. package/src/contracts/0x2/transfer.ts +216 -0
  130. package/src/contracts/0x2/transfer_policy.ts +400 -0
  131. package/src/contracts/0x2/tx_context.ts +129 -0
  132. package/src/contracts/0x2/types.ts +24 -0
  133. package/src/contracts/0x2/url.ts +77 -0
  134. package/src/contracts/0x2/vdf.ts +45 -0
  135. package/src/contracts/0x2/vec_map.ts +401 -0
  136. package/src/contracts/0x2/vec_set.ts +211 -0
  137. package/src/contracts/0x2/versioned.ts +153 -0
  138. package/src/contracts/0x2/zklogin_verified_id.ts +172 -0
  139. package/src/contracts/0x2/zklogin_verified_issuer.ts +99 -0
  140. package/src/contracts/kiosk/deps/sui/kiosk.ts +94 -0
  141. package/src/contracts/kiosk/deps/sui/object.ts +15 -0
  142. package/src/contracts/kiosk/floor_price_rule.ts +92 -0
  143. package/src/contracts/kiosk/kiosk_lock_rule.ts +97 -0
  144. package/src/contracts/kiosk/personal_kiosk.ts +295 -0
  145. package/src/contracts/kiosk/personal_kiosk_rule.ts +89 -0
  146. package/src/contracts/kiosk/royalty_rule.ts +144 -0
  147. package/src/contracts/kiosk/witness_rule.ts +92 -0
  148. package/src/contracts/utils/index.ts +234 -0
  149. package/src/query/client-utils.ts +51 -0
  150. package/src/query/kiosk.ts +128 -100
  151. package/src/query/transfer-policy.ts +112 -78
  152. package/src/tx/kiosk.ts +7 -231
  153. package/src/tx/rules/resolve.ts +97 -48
  154. package/src/tx/transfer-policy.ts +25 -86
  155. package/src/types/index.ts +3 -14
  156. package/src/types/kiosk.ts +10 -12
  157. package/src/types/transfer-policy.ts +4 -4
  158. package/src/utils.ts +90 -128
  159. package/dist/cjs/bcs.d.ts +0 -23
  160. package/dist/cjs/bcs.js +0 -50
  161. package/dist/cjs/bcs.js.map +0 -7
  162. package/dist/cjs/client/kiosk-client.d.ts +0 -76
  163. package/dist/cjs/client/kiosk-client.js +0 -123
  164. package/dist/cjs/client/kiosk-client.js.map +0 -7
  165. package/dist/cjs/client/kiosk-transaction.d.ts +0 -186
  166. package/dist/cjs/client/kiosk-transaction.js +0 -462
  167. package/dist/cjs/client/kiosk-transaction.js.map +0 -7
  168. package/dist/cjs/client/tp-transaction.d.ts +0 -114
  169. package/dist/cjs/client/tp-transaction.js +0 -307
  170. package/dist/cjs/client/tp-transaction.js.map +0 -7
  171. package/dist/cjs/constants.d.ts +0 -31
  172. package/dist/cjs/constants.js +0 -102
  173. package/dist/cjs/constants.js.map +0 -7
  174. package/dist/cjs/index.d.ts +0 -6
  175. package/dist/cjs/index.js +0 -24
  176. package/dist/cjs/index.js.map +0 -7
  177. package/dist/cjs/package.json +0 -5
  178. package/dist/cjs/query/kiosk.d.ts +0 -8
  179. package/dist/cjs/query/kiosk.js +0 -181
  180. package/dist/cjs/query/kiosk.js.map +0 -7
  181. package/dist/cjs/query/transfer-policy.d.ts +0 -29
  182. package/dist/cjs/query/transfer-policy.js +0 -92
  183. package/dist/cjs/query/transfer-policy.js.map +0 -7
  184. package/dist/cjs/tx/kiosk.d.ts +0 -71
  185. package/dist/cjs/tx/kiosk.js +0 -130
  186. package/dist/cjs/tx/kiosk.js.map +0 -7
  187. package/dist/cjs/tx/personal-kiosk.d.ts +0 -7
  188. package/dist/cjs/tx/personal-kiosk.js +0 -38
  189. package/dist/cjs/tx/personal-kiosk.js.map +0 -7
  190. package/dist/cjs/tx/rules/attach.d.ts +0 -7
  191. package/dist/cjs/tx/rules/attach.js +0 -62
  192. package/dist/cjs/tx/rules/attach.js.map +0 -7
  193. package/dist/cjs/tx/rules/resolve.d.ts +0 -15
  194. package/dist/cjs/tx/rules/resolve.js +0 -109
  195. package/dist/cjs/tx/rules/resolve.js.map +0 -7
  196. package/dist/cjs/tx/transfer-policy.d.ts +0 -29
  197. package/dist/cjs/tx/transfer-policy.js +0 -78
  198. package/dist/cjs/tx/transfer-policy.js.map +0 -7
  199. package/dist/cjs/types/index.d.ts +0 -27
  200. package/dist/cjs/types/index.js +0 -33
  201. package/dist/cjs/types/index.js.map +0 -7
  202. package/dist/cjs/types/kiosk.d.ts +0 -160
  203. package/dist/cjs/types/kiosk.js +0 -37
  204. package/dist/cjs/types/kiosk.js.map +0 -7
  205. package/dist/cjs/types/transfer-policy.d.ts +0 -53
  206. package/dist/cjs/types/transfer-policy.js +0 -35
  207. package/dist/cjs/types/transfer-policy.js.map +0 -7
  208. package/dist/cjs/utils.d.ts +0 -51
  209. package/dist/cjs/utils.js +0 -198
  210. package/dist/cjs/utils.js.map +0 -7
  211. package/dist/esm/bcs.d.ts +0 -23
  212. package/dist/esm/bcs.js +0 -35
  213. package/dist/esm/bcs.js.map +0 -7
  214. package/dist/esm/client/kiosk-client.d.ts +0 -76
  215. package/dist/esm/client/kiosk-client.js +0 -114
  216. package/dist/esm/client/kiosk-client.js.map +0 -7
  217. package/dist/esm/client/kiosk-transaction.d.ts +0 -186
  218. package/dist/esm/client/kiosk-transaction.js +0 -432
  219. package/dist/esm/client/kiosk-transaction.js.map +0 -7
  220. package/dist/esm/client/tp-transaction.d.ts +0 -114
  221. package/dist/esm/client/tp-transaction.js +0 -298
  222. package/dist/esm/client/tp-transaction.js.map +0 -7
  223. package/dist/esm/constants.d.ts +0 -31
  224. package/dist/esm/constants.js +0 -87
  225. package/dist/esm/constants.js.map +0 -7
  226. package/dist/esm/index.d.ts +0 -6
  227. package/dist/esm/index.js +0 -7
  228. package/dist/esm/index.js.map +0 -7
  229. package/dist/esm/package.json +0 -5
  230. package/dist/esm/query/kiosk.d.ts +0 -8
  231. package/dist/esm/query/kiosk.js +0 -169
  232. package/dist/esm/query/kiosk.js.map +0 -7
  233. package/dist/esm/query/transfer-policy.d.ts +0 -29
  234. package/dist/esm/query/transfer-policy.js +0 -76
  235. package/dist/esm/query/transfer-policy.js.map +0 -7
  236. package/dist/esm/tx/kiosk.d.ts +0 -71
  237. package/dist/esm/tx/kiosk.js +0 -110
  238. package/dist/esm/tx/kiosk.js.map +0 -7
  239. package/dist/esm/tx/personal-kiosk.d.ts +0 -7
  240. package/dist/esm/tx/personal-kiosk.js +0 -18
  241. package/dist/esm/tx/personal-kiosk.js.map +0 -7
  242. package/dist/esm/tx/rules/attach.d.ts +0 -7
  243. package/dist/esm/tx/rules/attach.js +0 -42
  244. package/dist/esm/tx/rules/attach.js.map +0 -7
  245. package/dist/esm/tx/rules/resolve.d.ts +0 -15
  246. package/dist/esm/tx/rules/resolve.js +0 -89
  247. package/dist/esm/tx/rules/resolve.js.map +0 -7
  248. package/dist/esm/tx/transfer-policy.d.ts +0 -29
  249. package/dist/esm/tx/transfer-policy.js +0 -58
  250. package/dist/esm/tx/transfer-policy.js.map +0 -7
  251. package/dist/esm/types/index.d.ts +0 -27
  252. package/dist/esm/types/index.js +0 -12
  253. package/dist/esm/types/index.js.map +0 -7
  254. package/dist/esm/types/kiosk.d.ts +0 -160
  255. package/dist/esm/types/kiosk.js +0 -17
  256. package/dist/esm/types/kiosk.js.map +0 -7
  257. package/dist/esm/types/transfer-policy.d.ts +0 -53
  258. package/dist/esm/types/transfer-policy.js +0 -15
  259. package/dist/esm/types/transfer-policy.js.map +0 -7
  260. package/dist/esm/utils.d.ts +0 -51
  261. package/dist/esm/utils.js +0 -183
  262. package/dist/esm/utils.js.map +0 -7
  263. package/dist/tsconfig.esm.tsbuildinfo +0 -1
  264. package/dist/tsconfig.tsbuildinfo +0 -1
  265. package/src/bcs.ts +0 -39
  266. package/src/tx/personal-kiosk.ts +0 -34
  267. package/src/tx/rules/attach.ts +0 -73
package/src/tx/kiosk.ts CHANGED
@@ -1,243 +1,19 @@
1
1
  // Copyright (c) Mysten Labs, Inc.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { bcs } from '@mysten/sui/bcs';
5
- import type {
6
- Transaction,
7
- TransactionArgument,
8
- TransactionObjectArgument,
9
- } from '@mysten/sui/transactions';
10
-
11
- import type { ObjectArgument } from '../types/index.js';
12
- import { KIOSK_MODULE, KIOSK_TYPE } from '../types/index.js';
13
-
14
- /**
15
- * Create a new shared Kiosk and returns the [kiosk, kioskOwnerCap] tuple.
16
- */
17
- export function createKiosk(
18
- tx: Transaction,
19
- ): [TransactionObjectArgument, TransactionObjectArgument] {
20
- const [kiosk, kioskOwnerCap] = tx.moveCall({
21
- target: `${KIOSK_MODULE}::new`,
22
- });
23
-
24
- return [kiosk, kioskOwnerCap];
25
- }
4
+ import type { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
5
+ import * as kiosk from '../contracts/0x2/kiosk.js';
26
6
 
27
7
  /**
28
8
  * Calls the `kiosk::new()` function and shares the kiosk.
29
9
  * Returns the `kioskOwnerCap` object.
30
10
  */
31
11
  export function createKioskAndShare(tx: Transaction): TransactionObjectArgument {
32
- const [kiosk, kioskOwnerCap] = createKiosk(tx);
33
- shareKiosk(tx, kiosk);
34
- return kioskOwnerCap;
35
- }
36
-
37
- /**
38
- * Converts Transfer Policy to a shared object.
39
- */
40
- export function shareKiosk(tx: Transaction, kiosk: TransactionArgument) {
41
- tx.moveCall({
42
- target: `0x2::transfer::public_share_object`,
43
- typeArguments: [KIOSK_TYPE],
44
- arguments: [kiosk],
45
- });
46
- }
47
-
48
- /**
49
- * Call the `kiosk::place<T>(Kiosk, KioskOwnerCap, Item)` function.
50
- * Place an item to the Kiosk.
51
- */
52
- export function place(
53
- tx: Transaction,
54
- itemType: string,
55
- kiosk: ObjectArgument,
56
- kioskCap: ObjectArgument,
57
- item: ObjectArgument,
58
- ): void {
59
- tx.moveCall({
60
- target: `${KIOSK_MODULE}::place`,
61
- typeArguments: [itemType],
62
- arguments: [tx.object(kiosk), tx.object(kioskCap), tx.object(item)],
63
- });
64
- }
65
-
66
- /**
67
- * Call the `kiosk::lock<T>(Kiosk, KioskOwnerCap, TransferPolicy, Item)`
68
- * function. Lock an item in the Kiosk.
69
- *
70
- * Unlike `place` this function requires a `TransferPolicy` to exist
71
- * and be passed in. This is done to make sure the item does not get
72
- * locked without an option to take it out.
73
- */
74
- export function lock(
75
- tx: Transaction,
76
- itemType: string,
77
- kiosk: ObjectArgument,
78
- kioskCap: ObjectArgument,
79
- policy: ObjectArgument,
80
- item: ObjectArgument,
81
- ): void {
82
- tx.moveCall({
83
- target: `${KIOSK_MODULE}::lock`,
84
- typeArguments: [itemType],
85
- arguments: [tx.object(kiosk), tx.object(kioskCap), tx.object(policy), tx.object(item)],
86
- });
87
- }
88
-
89
- /**
90
- * Call the `kiosk::take<T>(Kiosk, KioskOwnerCap, ID)` function.
91
- * Take an item from the Kiosk.
92
- */
93
- export function take(
94
- tx: Transaction,
95
- itemType: string,
96
- kiosk: ObjectArgument,
97
- kioskCap: ObjectArgument,
98
- itemId: string,
99
- ): TransactionObjectArgument {
100
- const [item] = tx.moveCall({
101
- target: `${KIOSK_MODULE}::take`,
102
- typeArguments: [itemType],
103
- arguments: [tx.object(kiosk), tx.object(kioskCap), tx.pure.id(itemId)],
104
- });
105
-
106
- return item;
107
- }
108
-
109
- /**
110
- * Call the `kiosk::list<T>(Kiosk, KioskOwnerCap, ID, u64)` function.
111
- * List an item for sale.
112
- */
113
- export function list(
114
- tx: Transaction,
115
- itemType: string,
116
- kiosk: ObjectArgument,
117
- kioskCap: ObjectArgument,
118
- itemId: string,
119
- price: string | bigint,
120
- ): void {
121
- tx.moveCall({
122
- target: `${KIOSK_MODULE}::list`,
123
- typeArguments: [itemType],
124
- arguments: [tx.object(kiosk), tx.object(kioskCap), tx.pure.id(itemId), tx.pure.u64(price)],
125
- });
126
- }
127
-
128
- /**
129
- * Call the `kiosk::list<T>(Kiosk, KioskOwnerCap, ID, u64)` function.
130
- * List an item for sale.
131
- */
132
- export function delist(
133
- tx: Transaction,
134
- itemType: string,
135
- kiosk: ObjectArgument,
136
- kioskCap: ObjectArgument,
137
- itemId: string,
138
- ): void {
12
+ const [kioskObj, kioskOwnerCap] = tx.add(kiosk._new({}));
139
13
  tx.moveCall({
140
- target: `${KIOSK_MODULE}::delist`,
141
- typeArguments: [itemType],
142
- arguments: [tx.object(kiosk), tx.object(kioskCap), tx.pure.id(itemId)],
143
- });
144
- }
145
-
146
- /**
147
- * Call the `kiosk::place_and_list<T>(Kiosk, KioskOwnerCap, Item, u64)` function.
148
- * Place an item to the Kiosk and list it for sale.
149
- */
150
- export function placeAndList(
151
- tx: Transaction,
152
- itemType: string,
153
- kiosk: ObjectArgument,
154
- kioskCap: ObjectArgument,
155
- item: ObjectArgument,
156
- price: string | bigint,
157
- ): void {
158
- tx.moveCall({
159
- target: `${KIOSK_MODULE}::place_and_list`,
160
- typeArguments: [itemType],
161
- arguments: [tx.object(kiosk), tx.object(kioskCap), tx.object(item), tx.pure.u64(price)],
162
- });
163
- }
164
-
165
- /**
166
- * Call the `kiosk::purchase<T>(Kiosk, ID, Coin<SUI>)` function and receive an Item and
167
- * a TransferRequest which needs to be dealt with (via a matching TransferPolicy).
168
- */
169
- export function purchase(
170
- tx: Transaction,
171
- itemType: string,
172
- kiosk: ObjectArgument,
173
- itemId: string,
174
- payment: ObjectArgument,
175
- ): [TransactionObjectArgument, TransactionObjectArgument] {
176
- const [item, transferRequest] = tx.moveCall({
177
- target: `${KIOSK_MODULE}::purchase`,
178
- typeArguments: [itemType],
179
- arguments: [tx.object(kiosk), tx.pure.id(itemId), tx.object(payment)],
180
- });
181
-
182
- return [item, transferRequest];
183
- }
184
-
185
- /**
186
- * Call the `kiosk::withdraw(Kiosk, KioskOwnerCap, Option<u64>)` function and receive a Coin<SUI>.
187
- * If the amount is null, then the entire balance will be withdrawn.
188
- */
189
- export function withdrawFromKiosk(
190
- tx: Transaction,
191
- kiosk: ObjectArgument,
192
- kioskCap: ObjectArgument,
193
- amount?: string | bigint | number,
194
- ): TransactionObjectArgument {
195
- const amountArg = bcs.option(bcs.u64()).serialize(amount);
196
-
197
- const [coin] = tx.moveCall({
198
- target: `${KIOSK_MODULE}::withdraw`,
199
- arguments: [tx.object(kiosk), tx.object(kioskCap), amountArg],
200
- });
201
-
202
- return coin;
203
- }
204
-
205
- /**
206
- * Call the `kiosk::borrow_value<T>(Kiosk, KioskOwnerCap, ID): T` function.
207
- * Immutably borrow an item from the Kiosk and return it in the end.
208
- *
209
- * Requires calling `returnValue` to return the item.
210
- */
211
- export function borrowValue(
212
- tx: Transaction,
213
- itemType: string,
214
- kiosk: ObjectArgument,
215
- kioskCap: ObjectArgument,
216
- itemId: string,
217
- ): [TransactionArgument, TransactionArgument] {
218
- const [item, promise] = tx.moveCall({
219
- target: `${KIOSK_MODULE}::borrow_val`,
220
- typeArguments: [itemType],
221
- arguments: [tx.object(kiosk), tx.object(kioskCap), tx.pure.id(itemId)],
222
- });
223
-
224
- return [item, promise];
225
- }
226
-
227
- /**
228
- * Call the `kiosk::return_value<T>(Kiosk, Item, Borrow)` function.
229
- * Return an item to the Kiosk after it was `borrowValue`-d.
230
- */
231
- export function returnValue(
232
- tx: Transaction,
233
- itemType: string,
234
- kiosk: ObjectArgument,
235
- item: TransactionArgument,
236
- promise: TransactionArgument,
237
- ): void {
238
- tx.moveCall({
239
- target: `${KIOSK_MODULE}::return_val`,
240
- typeArguments: [itemType],
241
- arguments: [tx.object(kiosk), item, promise],
14
+ target: '0x2::transfer::public_share_object',
15
+ arguments: [kioskObj],
16
+ typeArguments: ['0x2::kiosk::Kiosk'],
242
17
  });
18
+ return kioskOwnerCap;
243
19
  }
@@ -1,26 +1,29 @@
1
1
  // Copyright (c) Mysten Labs, Inc.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { bcs } from '@mysten/sui/bcs';
5
4
  import type { TransactionArgument } from '@mysten/sui/transactions';
6
5
  import { Transaction } from '@mysten/sui/transactions';
6
+ import { bcs } from '@mysten/sui/bcs';
7
7
  import { normalizeSuiAddress } from '@mysten/sui/utils';
8
8
 
9
9
  import type { RuleResolvingParams } from '../../types/index.js';
10
- import { lock } from '../kiosk.js';
11
-
10
+ import * as kiosk from '../../contracts/0x2/kiosk.js';
11
+ import * as royaltyRule from '../../contracts/kiosk/royalty_rule.js';
12
+ import * as kioskLockRule from '../../contracts/kiosk/kiosk_lock_rule.js';
13
+ import * as personalKioskRule from '../../contracts/kiosk/personal_kiosk_rule.js';
14
+ import * as floorPriceRule from '../../contracts/kiosk/floor_price_rule.js';
12
15
  /**
13
16
  * A helper to resolve the royalty rule.
14
17
  */
15
18
  export async function resolveRoyaltyRule(params: RuleResolvingParams) {
16
19
  const {
17
- kioskClient,
18
20
  transaction: tx,
19
21
  itemType,
20
22
  price,
21
23
  packageId,
22
24
  transferRequest,
23
25
  policyId,
26
+ kioskClient,
24
27
  } = params;
25
28
 
26
29
  // We attempt to resolve the fee amount outside of the PTB so that the split amount is known before the transaction is sent.
@@ -29,45 +32,69 @@ export async function resolveRoyaltyRule(params: RuleResolvingParams) {
29
32
  const feeTx = new Transaction();
30
33
 
31
34
  // calculates the amount
32
- feeTx.moveCall({
33
- target: `${packageId}::royalty_rule::fee_amount`,
34
- typeArguments: [itemType],
35
- arguments: [feeTx.object(policyId), feeTx.pure.u64(price || '0')],
36
- });
35
+ feeTx.add(
36
+ royaltyRule.feeAmount({
37
+ package: packageId,
38
+ arguments: {
39
+ policy: feeTx.object(policyId),
40
+ paid: BigInt(price || '0'),
41
+ },
42
+ typeArguments: [itemType],
43
+ }),
44
+ );
37
45
 
38
46
  const policyObj = tx.object(policyId);
39
47
 
40
- const { results } = await kioskClient.client.devInspectTransactionBlock({
41
- sender: tx.getData().sender || normalizeSuiAddress('0x0'),
42
- transactionBlock: feeTx,
43
- });
44
-
45
48
  let amount: TransactionArgument | bigint | null = null;
46
- if (results) {
47
- const returnedAmount = results?.[0].returnValues?.[0]?.[0];
48
- if (returnedAmount) {
49
- amount = BigInt(bcs.U64.parse(new Uint8Array(returnedAmount as number[])));
49
+
50
+ try {
51
+ feeTx.setSender(tx.getData().sender || normalizeSuiAddress('0x0'));
52
+ const txBytes = await feeTx.build({ client: kioskClient.client });
53
+
54
+ const result = await kioskClient.client.core.simulateTransaction({
55
+ transaction: txBytes,
56
+ include: { commandResults: true },
57
+ });
58
+
59
+ if (result.commandResults && result.commandResults.length > 0) {
60
+ const returnedAmount = result.commandResults[0]?.returnValues?.[0]?.bcs;
61
+ if (returnedAmount) {
62
+ amount = BigInt(bcs.U64.parse(returnedAmount));
63
+ }
50
64
  }
65
+ } catch {
66
+ // If simulate fails, fall back to resolving within the PTB
51
67
  }
52
68
 
53
69
  // We were not able to calculate the amount outside of the transaction, so fall back to resolving it within the PTB
54
70
  if (!amount) {
55
- [amount] = tx.moveCall({
56
- target: `${packageId}::royalty_rule::fee_amount`,
57
- typeArguments: [itemType],
58
- arguments: [policyObj, tx.pure.u64(price || '0')],
59
- });
71
+ [amount] = tx.add(
72
+ royaltyRule.feeAmount({
73
+ package: packageId,
74
+ arguments: {
75
+ policy: policyObj,
76
+ paid: BigInt(price || '0'),
77
+ },
78
+ typeArguments: [itemType],
79
+ }),
80
+ );
60
81
  }
61
82
 
62
83
  // splits the coin.
63
84
  const feeCoin = tx.splitCoins(tx.gas, [amount]);
64
85
 
65
86
  // pays the policy
66
- tx.moveCall({
67
- target: `${packageId}::royalty_rule::pay`,
68
- typeArguments: [itemType],
69
- arguments: [policyObj, transferRequest, feeCoin],
70
- });
87
+ tx.add(
88
+ royaltyRule.pay({
89
+ package: packageId,
90
+ arguments: {
91
+ policy: policyObj,
92
+ request: transferRequest,
93
+ payment: feeCoin,
94
+ },
95
+ typeArguments: [itemType],
96
+ }),
97
+ );
71
98
  }
72
99
 
73
100
  export function resolveKioskLockRule(params: RuleResolvingParams) {
@@ -75,23 +102,33 @@ export function resolveKioskLockRule(params: RuleResolvingParams) {
75
102
  transaction: tx,
76
103
  packageId,
77
104
  itemType,
78
- kiosk,
105
+ kiosk: kioskId,
79
106
  kioskCap,
80
107
  policyId,
81
108
  purchasedItem,
82
109
  transferRequest,
83
110
  } = params;
84
111
 
85
- if (!kiosk || !kioskCap) throw new Error('Missing Owned Kiosk or Owned Kiosk Cap');
112
+ if (!kioskId || !kioskCap) throw new Error('Missing Owned Kiosk or Owned Kiosk Cap');
86
113
 
87
- lock(tx, itemType, kiosk, kioskCap, policyId, purchasedItem);
114
+ tx.add(
115
+ kiosk.lock({
116
+ arguments: [kioskId, kioskCap, policyId, purchasedItem],
117
+ typeArguments: [itemType],
118
+ }),
119
+ );
88
120
 
89
121
  // proves that the item is locked in the kiosk to the TP.
90
- tx.moveCall({
91
- target: `${packageId}::kiosk_lock_rule::prove`,
92
- typeArguments: [itemType],
93
- arguments: [transferRequest, tx.object(kiosk)],
94
- });
122
+ tx.add(
123
+ kioskLockRule.prove({
124
+ package: packageId,
125
+ arguments: {
126
+ request: transferRequest,
127
+ kiosk: tx.object(kioskId),
128
+ },
129
+ typeArguments: [itemType],
130
+ }),
131
+ );
95
132
  }
96
133
 
97
134
  /**
@@ -104,23 +141,35 @@ export function resolvePersonalKioskRule(params: RuleResolvingParams) {
104
141
  if (!kiosk) throw new Error('Missing owned Kiosk.');
105
142
 
106
143
  // proves that the destination kiosk is personal.
107
- tx.moveCall({
108
- target: `${packageId}::personal_kiosk_rule::prove`,
109
- typeArguments: [itemType],
110
- arguments: [tx.object(kiosk), transferRequest],
111
- });
144
+ tx.add(
145
+ personalKioskRule.prove({
146
+ package: packageId,
147
+ arguments: {
148
+ kiosk: tx.object(kiosk),
149
+ request: transferRequest,
150
+ },
151
+ typeArguments: [itemType],
152
+ }),
153
+ );
112
154
  }
113
155
 
114
156
  /**
115
- * Resolves the floor price rule.
157
+ * A helper to resolve the floor price rule.
158
+ * The floor price rule verifies that the paid amount meets the minimum price.
159
+ * @param params
116
160
  */
117
161
  export function resolveFloorPriceRule(params: RuleResolvingParams) {
118
162
  const { transaction: tx, packageId, itemType, policyId, transferRequest } = params;
119
163
 
120
- // proves that the destination kiosk is personal
121
- tx.moveCall({
122
- target: `${packageId}::floor_price_rule::prove`,
123
- typeArguments: [itemType],
124
- arguments: [tx.object(policyId), transferRequest],
125
- });
164
+ // proves that the paid amount meets the floor price requirement
165
+ tx.add(
166
+ floorPriceRule.prove({
167
+ package: packageId,
168
+ arguments: {
169
+ policy: tx.object(policyId),
170
+ request: transferRequest,
171
+ },
172
+ typeArguments: [itemType],
173
+ }),
174
+ );
126
175
  }
@@ -1,15 +1,10 @@
1
1
  // Copyright (c) Mysten Labs, Inc.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { bcs } from '@mysten/sui/bcs';
5
- import type {
6
- Transaction,
7
- TransactionArgument,
8
- TransactionObjectArgument,
9
- } from '@mysten/sui/transactions';
4
+ import type { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
10
5
 
11
6
  import type { ObjectArgument } from '../types/index.js';
12
- import { TRANSFER_POLICY_MODULE, TRANSFER_POLICY_TYPE } from '../types/index.js';
7
+ import * as transferPolicy from '../contracts/0x2/transfer_policy.js';
13
8
 
14
9
  /**
15
10
  * Call the `transfer_policy::new` function to create a new transfer policy.
@@ -20,47 +15,20 @@ export function createTransferPolicy(
20
15
  itemType: string,
21
16
  publisher: ObjectArgument,
22
17
  ): TransactionObjectArgument {
23
- const [transferPolicy, transferPolicyCap] = createTransferPolicyWithoutSharing(
24
- tx,
25
- itemType,
26
- publisher,
18
+ const [policy, policyCap] = tx.add(
19
+ transferPolicy._new({
20
+ arguments: [publisher],
21
+ typeArguments: [itemType],
22
+ }),
27
23
  );
28
24
 
29
- shareTransferPolicy(tx, itemType, transferPolicy);
30
-
31
- return transferPolicyCap;
32
- }
33
-
34
- /**
35
- * Creates a transfer Policy and returns both the Policy and the Cap.
36
- * Used if we want to use the policy before making it a shared object.
37
- */
38
- export function createTransferPolicyWithoutSharing(
39
- tx: Transaction,
40
- itemType: string,
41
- publisher: ObjectArgument,
42
- ): [TransactionObjectArgument, TransactionObjectArgument] {
43
- const [transferPolicy, transferPolicyCap] = tx.moveCall({
44
- target: `${TRANSFER_POLICY_MODULE}::new`,
45
- typeArguments: [itemType],
46
- arguments: [tx.object(publisher)],
47
- });
48
-
49
- return [transferPolicy, transferPolicyCap];
50
- }
51
- /**
52
- * Converts Transfer Policy to a shared object.
53
- */
54
- export function shareTransferPolicy(
55
- tx: Transaction,
56
- itemType: string,
57
- transferPolicy: TransactionObjectArgument,
58
- ) {
59
25
  tx.moveCall({
60
- target: `0x2::transfer::public_share_object`,
61
- typeArguments: [`${TRANSFER_POLICY_TYPE}<${itemType}>`],
62
- arguments: [transferPolicy],
26
+ target: '0x2::transfer::public_share_object',
27
+ arguments: [policy],
28
+ typeArguments: [`0x2::transfer_policy::TransferPolicy<${itemType}>`],
63
29
  });
30
+
31
+ return policyCap;
64
32
  }
65
33
 
66
34
  /**
@@ -73,48 +41,19 @@ export function withdrawFromPolicy(
73
41
  policyCap: ObjectArgument,
74
42
  amount?: string | bigint | null,
75
43
  ): TransactionObjectArgument {
76
- const amountArg = bcs.option(bcs.u64()).serialize(amount);
77
-
78
- const [profits] = tx.moveCall({
79
- target: `${TRANSFER_POLICY_MODULE}::withdraw`,
80
- typeArguments: [itemType],
81
- arguments: [tx.object(policy), tx.object(policyCap), amountArg],
82
- });
44
+ // Convert string to bigint if needed for the generated function
45
+ const amountArg: bigint | null = amount
46
+ ? typeof amount === 'string'
47
+ ? BigInt(amount)
48
+ : amount
49
+ : null;
50
+
51
+ const [profits] = tx.add(
52
+ transferPolicy.withdraw({
53
+ arguments: [policy, policyCap, amountArg],
54
+ typeArguments: [itemType],
55
+ }),
56
+ );
83
57
 
84
58
  return profits;
85
59
  }
86
-
87
- /**
88
- * Call the `transfer_policy::confirm_request` function to unblock the
89
- * transaction.
90
- */
91
- export function confirmRequest(
92
- tx: Transaction,
93
- itemType: string,
94
- policy: ObjectArgument,
95
- request: TransactionArgument,
96
- ): void {
97
- tx.moveCall({
98
- target: `${TRANSFER_POLICY_MODULE}::confirm_request`,
99
- typeArguments: [itemType],
100
- arguments: [tx.object(policy), request],
101
- });
102
- }
103
-
104
- /**
105
- * Calls the `transfer_policy::remove_rule` function to remove a Rule from the transfer policy's ruleset.
106
- */
107
- export function removeTransferPolicyRule(
108
- tx: Transaction,
109
- itemType: string,
110
- ruleType: string,
111
- configType: string,
112
- policy: ObjectArgument,
113
- policyCap: ObjectArgument,
114
- ): void {
115
- tx.moveCall({
116
- target: `${TRANSFER_POLICY_MODULE}::remove_rule`,
117
- typeArguments: [itemType, ruleType, configType],
118
- arguments: [tx.object(policy), tx.object(policyCap)],
119
- });
120
- }
@@ -1,7 +1,7 @@
1
1
  // Copyright (c) Mysten Labs, Inc.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import type { SuiClient } from '@mysten/sui/client';
4
+ import type { ClientWithCoreApi, SuiClientTypes } from '@mysten/sui/client';
5
5
  import type { TransactionObjectArgument } from '@mysten/sui/transactions';
6
6
 
7
7
  import type { BaseRulePackageIds } from '../constants.js';
@@ -14,22 +14,11 @@ export * from './transfer-policy.js';
14
14
  */
15
15
  export type ObjectArgument = string | TransactionObjectArgument;
16
16
 
17
- /**
18
- * A Network selector.
19
- * Kiosk SDK supports mainnet & testnet.
20
- * Pass `custom` for any other network (devnet, localnet).
21
- */
22
- export enum Network {
23
- MAINNET = 'mainnet',
24
- TESTNET = 'testnet',
25
- CUSTOM = 'custom',
26
- }
27
-
28
17
  /**
29
18
  * The Client Options for Both KioskClient & TransferPolicyManager.
30
19
  */
31
20
  export type KioskClientOptions = {
32
- client: SuiClient;
33
- network: Network;
21
+ client: ClientWithCoreApi;
22
+ network: SuiClientTypes.Network;
34
23
  packageIds?: BaseRulePackageIds;
35
24
  };
@@ -1,17 +1,15 @@
1
1
  // Copyright (c) Mysten Labs, Inc.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import type {
5
- PaginatedObjectsResponse,
6
- SuiObjectData,
7
- SuiObjectDataOptions,
8
- } from '@mysten/sui/client';
9
4
  import type { TransactionArgument } from '@mysten/sui/transactions';
5
+ import { SuiClientTypes } from '@mysten/sui/client';
10
6
 
11
7
  import type { ObjectArgument } from './index.js';
12
8
 
9
+ import { SUI_FRAMEWORK_ADDRESS } from '@mysten/sui/utils';
10
+
13
11
  /** The Kiosk module. */
14
- export const KIOSK_MODULE = '0x2::kiosk';
12
+ export const KIOSK_MODULE = `${SUI_FRAMEWORK_ADDRESS}::kiosk`;
15
13
 
16
14
  /** The Kiosk type. */
17
15
  export const KIOSK_TYPE = `${KIOSK_MODULE}::Kiosk`;
@@ -105,8 +103,8 @@ export type KioskItem = {
105
103
  listing?: KioskListing;
106
104
  /** The ID of the kiosk the item is placed in */
107
105
  kioskId: string;
108
- /** Optional Kiosk Data */
109
- data?: SuiObjectData;
106
+ /** Optional Kiosk Data (core API object) */
107
+ data?: SuiClientTypes.Object;
110
108
  };
111
109
 
112
110
  /** The overview type returned from `getKiosk` */
@@ -149,16 +147,16 @@ export type FetchKioskOptions = {
149
147
  withKioskFields?: boolean;
150
148
  /** Include the listing prices. */
151
149
  withListingPrices?: boolean;
152
- /** Include the objects for the Items in the kiosk. Defaults to `display` only. */
150
+ /** Include the objects for the Items in the kiosk. */
153
151
  withObjects?: boolean;
154
- /** Pass the data options for the objects, when fetching, in case you want to query other details. */
155
- objectOptions?: SuiObjectDataOptions;
156
152
  };
157
153
 
158
154
  export type OwnedKiosks = {
159
155
  kioskOwnerCaps: KioskOwnerCap[];
160
156
  kioskIds: string[];
161
- } & Omit<PaginatedObjectsResponse, 'data'>;
157
+ nextCursor: string | null;
158
+ hasNextPage: boolean;
159
+ };
162
160
 
163
161
  export type KioskOwnerCap = {
164
162
  isPersonal?: boolean;