@mysten/kiosk 0.7.13 → 0.8.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 (130) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/cjs/bcs.js +47 -0
  3. package/dist/cjs/bcs.js.map +7 -0
  4. package/dist/{client → cjs/client}/kiosk-client.d.ts +8 -7
  5. package/dist/cjs/client/kiosk-client.js +126 -0
  6. package/dist/cjs/client/kiosk-client.js.map +7 -0
  7. package/dist/{client → cjs/client}/kiosk-transaction.d.ts +3 -3
  8. package/dist/cjs/client/kiosk-transaction.js +489 -0
  9. package/dist/cjs/client/kiosk-transaction.js.map +7 -0
  10. package/dist/{client → cjs/client}/tp-transaction.d.ts +3 -3
  11. package/dist/cjs/client/tp-transaction.js +317 -0
  12. package/dist/cjs/client/tp-transaction.js.map +7 -0
  13. package/dist/{constants.d.ts → cjs/constants.d.ts} +2 -1
  14. package/dist/cjs/constants.js +102 -0
  15. package/dist/cjs/constants.js.map +7 -0
  16. package/dist/cjs/index.d.ts +6 -0
  17. package/dist/cjs/index.js +24 -0
  18. package/dist/cjs/index.js.map +7 -0
  19. package/dist/cjs/package.json +5 -0
  20. package/dist/{query → cjs/query}/kiosk.d.ts +2 -2
  21. package/dist/cjs/query/kiosk.js +124 -0
  22. package/dist/cjs/query/kiosk.js.map +7 -0
  23. package/dist/{query → cjs/query}/transfer-policy.d.ts +2 -2
  24. package/dist/cjs/query/transfer-policy.js +94 -0
  25. package/dist/cjs/query/transfer-policy.js.map +7 -0
  26. package/dist/{tx → cjs/tx}/kiosk.d.ts +2 -2
  27. package/dist/cjs/tx/kiosk.js +130 -0
  28. package/dist/cjs/tx/kiosk.js.map +7 -0
  29. package/dist/{tx → cjs/tx}/personal-kiosk.d.ts +2 -2
  30. package/dist/cjs/tx/personal-kiosk.js +38 -0
  31. package/dist/cjs/tx/personal-kiosk.js.map +7 -0
  32. package/dist/{tx → cjs/tx}/rules/attach.d.ts +2 -2
  33. package/dist/cjs/tx/rules/attach.js +62 -0
  34. package/dist/cjs/tx/rules/attach.js.map +7 -0
  35. package/dist/{tx → cjs/tx}/rules/resolve.d.ts +1 -1
  36. package/dist/cjs/tx/rules/resolve.js +81 -0
  37. package/dist/cjs/tx/rules/resolve.js.map +7 -0
  38. package/dist/{tx → cjs/tx}/transfer-policy.d.ts +2 -2
  39. package/dist/cjs/tx/transfer-policy.js +78 -0
  40. package/dist/cjs/tx/transfer-policy.js.map +7 -0
  41. package/dist/{types → cjs/types}/index.d.ts +5 -5
  42. package/dist/cjs/types/index.js +33 -0
  43. package/dist/cjs/types/index.js.map +7 -0
  44. package/dist/{types → cjs/types}/kiosk.d.ts +3 -3
  45. package/dist/cjs/types/kiosk.js +37 -0
  46. package/dist/cjs/types/kiosk.js.map +7 -0
  47. package/dist/{types → cjs/types}/transfer-policy.d.ts +3 -3
  48. package/dist/cjs/types/transfer-policy.js +35 -0
  49. package/dist/cjs/types/transfer-policy.js.map +7 -0
  50. package/dist/{utils.d.ts → cjs/utils.d.ts} +2 -2
  51. package/dist/cjs/utils.js +203 -0
  52. package/dist/cjs/utils.js.map +7 -0
  53. package/dist/esm/bcs.d.ts +2 -0
  54. package/dist/esm/bcs.js +32 -0
  55. package/dist/esm/bcs.js.map +7 -0
  56. package/dist/esm/client/kiosk-client.d.ts +74 -0
  57. package/dist/esm/client/kiosk-client.js +117 -0
  58. package/dist/esm/client/kiosk-client.js.map +7 -0
  59. package/dist/esm/client/kiosk-transaction.d.ts +182 -0
  60. package/dist/esm/client/kiosk-transaction.js +459 -0
  61. package/dist/esm/client/kiosk-transaction.js.map +7 -0
  62. package/dist/esm/client/tp-transaction.d.ts +112 -0
  63. package/dist/esm/client/tp-transaction.js +308 -0
  64. package/dist/esm/client/tp-transaction.js.map +7 -0
  65. package/dist/esm/constants.d.ts +31 -0
  66. package/dist/esm/constants.js +87 -0
  67. package/dist/esm/constants.js.map +7 -0
  68. package/dist/esm/index.d.ts +6 -0
  69. package/dist/esm/index.js +7 -0
  70. package/dist/esm/index.js.map +7 -0
  71. package/dist/esm/package.json +5 -0
  72. package/dist/esm/query/kiosk.d.ts +14 -0
  73. package/dist/esm/query/kiosk.js +112 -0
  74. package/dist/esm/query/kiosk.js.map +7 -0
  75. package/dist/esm/query/transfer-policy.d.ts +28 -0
  76. package/dist/esm/query/transfer-policy.js +78 -0
  77. package/dist/esm/query/transfer-policy.js.map +7 -0
  78. package/dist/esm/tx/kiosk.d.ts +71 -0
  79. package/dist/esm/tx/kiosk.js +110 -0
  80. package/dist/esm/tx/kiosk.js.map +7 -0
  81. package/dist/esm/tx/personal-kiosk.d.ts +7 -0
  82. package/dist/esm/tx/personal-kiosk.js +18 -0
  83. package/dist/esm/tx/personal-kiosk.js.map +7 -0
  84. package/dist/esm/tx/rules/attach.d.ts +7 -0
  85. package/dist/esm/tx/rules/attach.js +42 -0
  86. package/dist/esm/tx/rules/attach.js.map +7 -0
  87. package/dist/esm/tx/rules/resolve.d.ts +15 -0
  88. package/dist/esm/tx/rules/resolve.js +61 -0
  89. package/dist/esm/tx/rules/resolve.js.map +7 -0
  90. package/dist/esm/tx/transfer-policy.d.ts +29 -0
  91. package/dist/esm/tx/transfer-policy.js +58 -0
  92. package/dist/esm/tx/transfer-policy.js.map +7 -0
  93. package/dist/esm/types/index.d.ts +27 -0
  94. package/dist/esm/types/index.js +12 -0
  95. package/dist/esm/types/index.js.map +7 -0
  96. package/dist/esm/types/kiosk.d.ts +160 -0
  97. package/dist/esm/types/kiosk.js +17 -0
  98. package/dist/esm/types/kiosk.js.map +7 -0
  99. package/dist/esm/types/transfer-policy.d.ts +49 -0
  100. package/dist/esm/types/transfer-policy.js +15 -0
  101. package/dist/esm/types/transfer-policy.js.map +7 -0
  102. package/dist/esm/utils.d.ts +51 -0
  103. package/dist/esm/utils.js +183 -0
  104. package/dist/esm/utils.js.map +7 -0
  105. package/dist/tsconfig.esm.tsbuildinfo +1 -0
  106. package/dist/tsconfig.tsbuildinfo +1 -0
  107. package/package.json +17 -19
  108. package/src/bcs.ts +1 -1
  109. package/src/client/kiosk-client.ts +12 -13
  110. package/src/client/kiosk-transaction.ts +10 -10
  111. package/src/client/tp-transaction.ts +5 -5
  112. package/src/constants.ts +4 -2
  113. package/src/index.ts +6 -6
  114. package/src/query/kiosk.ts +5 -5
  115. package/src/query/transfer-policy.ts +5 -6
  116. package/src/tx/kiosk.ts +3 -2
  117. package/src/tx/personal-kiosk.ts +2 -2
  118. package/src/tx/rules/attach.ts +2 -2
  119. package/src/tx/rules/resolve.ts +2 -2
  120. package/src/tx/transfer-policy.ts +3 -2
  121. package/src/types/index.ts +5 -5
  122. package/src/types/kiosk.ts +3 -3
  123. package/src/types/transfer-policy.ts +3 -3
  124. package/src/utils.ts +5 -11
  125. package/dist/index.d.ts +0 -6
  126. package/dist/index.js +0 -1643
  127. package/dist/index.js.map +0 -1
  128. package/dist/index.mjs +0 -1582
  129. package/dist/index.mjs.map +0 -1
  130. /package/dist/{bcs.d.ts → cjs/bcs.d.ts} +0 -0
@@ -0,0 +1,489 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var __accessCheck = (obj, member, msg) => {
30
+ if (!member.has(obj))
31
+ throw TypeError("Cannot " + msg);
32
+ };
33
+ var __privateGet = (obj, member, getter) => {
34
+ __accessCheck(obj, member, "read from private field");
35
+ return getter ? getter.call(obj) : member.get(obj);
36
+ };
37
+ var __privateAdd = (obj, member, value) => {
38
+ if (member.has(obj))
39
+ throw TypeError("Cannot add the same private member more than once");
40
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
41
+ };
42
+ var __privateSet = (obj, member, value, setter) => {
43
+ __accessCheck(obj, member, "write to private field");
44
+ setter ? setter.call(obj, value) : member.set(obj, value);
45
+ return value;
46
+ };
47
+ var __privateMethod = (obj, member, method) => {
48
+ __accessCheck(obj, member, "access private method");
49
+ return method;
50
+ };
51
+ var kiosk_transaction_exports = {};
52
+ __export(kiosk_transaction_exports, {
53
+ KioskTransaction: () => KioskTransaction
54
+ });
55
+ module.exports = __toCommonJS(kiosk_transaction_exports);
56
+ var kioskTx = __toESM(require("../tx/kiosk.js"));
57
+ var import_personal_kiosk = require("../tx/personal-kiosk.js");
58
+ var import_transfer_policy = require("../tx/transfer-policy.js");
59
+ var import_utils = require("../utils.js");
60
+ var _pendingShare, _pendingTransfer, _promise, _personalCap, _finalized, _borrowFromPersonalCap, borrowFromPersonalCap_fn, _setPendingStatuses, setPendingStatuses_fn, _validateKioskIsSet, validateKioskIsSet_fn, _validateFinalizedStatus, validateFinalizedStatus_fn;
61
+ class KioskTransaction {
62
+ constructor({ transactionBlock, kioskClient, cap }) {
63
+ /**
64
+ * A function to borrow from `personalCap`.
65
+ */
66
+ __privateAdd(this, _borrowFromPersonalCap);
67
+ __privateAdd(this, _setPendingStatuses);
68
+ __privateAdd(this, _validateKioskIsSet);
69
+ // Validates that `finalize`
70
+ __privateAdd(this, _validateFinalizedStatus);
71
+ // If we're pending `share` of a new kiosk, `finalize()` will share it.
72
+ __privateAdd(this, _pendingShare, void 0);
73
+ // If we're pending transferring of the cap, `finalize()` will either error or transfer the cap if it's a new personal.
74
+ __privateAdd(this, _pendingTransfer, void 0);
75
+ // The promise that the personalCap will be returned on `finalize()`.
76
+ __privateAdd(this, _promise, void 0);
77
+ // The personal kiosk argument.
78
+ __privateAdd(this, _personalCap, void 0);
79
+ // A flag that checks whether kiosk TX is finalized.
80
+ __privateAdd(this, _finalized, false);
81
+ this.transactionBlock = transactionBlock;
82
+ this.kioskClient = kioskClient;
83
+ if (cap)
84
+ this.setCap(cap);
85
+ }
86
+ /**
87
+ * Creates a kiosk and saves `kiosk` and `kioskOwnerCap` in state.
88
+ * Helpful if we want to chain some actions before sharing + transferring the cap to the specified address.
89
+ * @param borrow If true, the `kioskOwnerCap` is borrowed from the `PersonalKioskCap` to be used in next transactions.
90
+ */
91
+ create() {
92
+ __privateMethod(this, _validateFinalizedStatus, validateFinalizedStatus_fn).call(this);
93
+ __privateMethod(this, _setPendingStatuses, setPendingStatuses_fn).call(this, {
94
+ share: true,
95
+ transfer: true
96
+ });
97
+ const [kiosk, cap] = kioskTx.createKiosk(this.transactionBlock);
98
+ this.kiosk = kiosk;
99
+ this.kioskCap = cap;
100
+ return this;
101
+ }
102
+ /**
103
+ * Creates a personal kiosk & shares it.
104
+ * The `PersonalKioskCap` is transferred to the signer.
105
+ * @param borrow If true, the `kioskOwnerCap` is borrowed from the `PersonalKioskCap` to be used in next transactions.
106
+ */
107
+ createPersonal(borrow) {
108
+ __privateSet(this, _pendingShare, true);
109
+ return this.create().convertToPersonal(borrow);
110
+ }
111
+ /**
112
+ * Converts a kiosk to a Personal (Soulbound) Kiosk.
113
+ * Requires initialization by either calling `ktxb.create()` or `ktxb.setCap()`.
114
+ */
115
+ convertToPersonal(borrow) {
116
+ __privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
117
+ const cap = (0, import_personal_kiosk.convertToPersonalTx)(
118
+ this.transactionBlock,
119
+ this.kiosk,
120
+ this.kioskCap,
121
+ this.kioskClient.getRulePackageId("personalKioskRulePackageId")
122
+ );
123
+ if (borrow)
124
+ __privateMethod(this, _borrowFromPersonalCap, borrowFromPersonalCap_fn).call(this, cap);
125
+ else
126
+ __privateSet(this, _personalCap, cap);
127
+ __privateMethod(this, _setPendingStatuses, setPendingStatuses_fn).call(this, { transfer: true });
128
+ return this;
129
+ }
130
+ /**
131
+ * Single function way to create a kiosk, share it and transfer the cap to the specified address.
132
+ */
133
+ createAndShare(address) {
134
+ __privateMethod(this, _validateFinalizedStatus, validateFinalizedStatus_fn).call(this);
135
+ const cap = kioskTx.createKioskAndShare(this.transactionBlock);
136
+ this.transactionBlock.transferObjects([cap], this.transactionBlock.pure.address(address));
137
+ }
138
+ /**
139
+ * Shares the kiosk.
140
+ */
141
+ share() {
142
+ __privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
143
+ __privateMethod(this, _setPendingStatuses, setPendingStatuses_fn).call(this, { share: false });
144
+ kioskTx.shareKiosk(this.transactionBlock, this.kiosk);
145
+ }
146
+ /**
147
+ * Should be called only after `create` is called.
148
+ * It shares the kiosk & transfers the cap to the specified address.
149
+ */
150
+ shareAndTransferCap(address) {
151
+ if (__privateGet(this, _personalCap))
152
+ throw new Error("You can only call `shareAndTransferCap` on a non-personal kiosk.");
153
+ __privateMethod(this, _setPendingStatuses, setPendingStatuses_fn).call(this, { transfer: false });
154
+ this.share();
155
+ this.transactionBlock.transferObjects(
156
+ [this.kioskCap],
157
+ this.transactionBlock.pure.address(address)
158
+ );
159
+ }
160
+ /**
161
+ * A function to borrow an item from a kiosk & execute any function with it.
162
+ * Example: You could borrow a Fren out of a kiosk, attach an accessory (or mix), and return it.
163
+ */
164
+ borrowTx({ itemType, itemId }, callback) {
165
+ __privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
166
+ const [itemObj, promise] = kioskTx.borrowValue(
167
+ this.transactionBlock,
168
+ itemType,
169
+ this.kiosk,
170
+ this.kioskCap,
171
+ itemId
172
+ );
173
+ callback(itemObj);
174
+ this.return({ itemType, item: itemObj, promise });
175
+ }
176
+ /**
177
+ * Borrows an item from the kiosk.
178
+ * This will fail if the item is listed for sale.
179
+ *
180
+ * Requires calling `return`.
181
+ */
182
+ borrow({ itemType, itemId }) {
183
+ __privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
184
+ const [itemObj, promise] = kioskTx.borrowValue(
185
+ this.transactionBlock,
186
+ itemType,
187
+ this.kiosk,
188
+ this.kioskCap,
189
+ itemId
190
+ );
191
+ return [itemObj, promise];
192
+ }
193
+ /**
194
+ * Returns the item back to the kiosk.
195
+ * Accepts the parameters returned from the `borrow` function.
196
+ */
197
+ return({ itemType, item, promise }) {
198
+ __privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
199
+ kioskTx.returnValue(this.transactionBlock, itemType, this.kiosk, item, promise);
200
+ return this;
201
+ }
202
+ /**
203
+ * A function to withdraw from kiosk
204
+ * @param address Where to trasnfer the coin.
205
+ * @param amount The amount we aim to withdraw.
206
+ */
207
+ withdraw(address, amount) {
208
+ __privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
209
+ const coin = kioskTx.withdrawFromKiosk(
210
+ this.transactionBlock,
211
+ this.kiosk,
212
+ this.kioskCap,
213
+ amount
214
+ );
215
+ this.transactionBlock.transferObjects([coin], this.transactionBlock.pure.address(address));
216
+ return this;
217
+ }
218
+ /**
219
+ * A function to place an item in the kiosk.
220
+ * @param itemType The type `T` of the item
221
+ * @param item The ID or Transaction Argument of the item
222
+ */
223
+ place({ itemType, item }) {
224
+ __privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
225
+ kioskTx.place(this.transactionBlock, itemType, this.kiosk, this.kioskCap, item);
226
+ return this;
227
+ }
228
+ /**
229
+ * A function to place an item in the kiosk and list it for sale in one transaction.
230
+ * @param itemType The type `T` of the item
231
+ * @param item The ID or Transaction Argument of the item
232
+ * @param price The price in MIST
233
+ */
234
+ placeAndList({ itemType, item, price }) {
235
+ __privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
236
+ kioskTx.placeAndList(this.transactionBlock, itemType, this.kiosk, this.kioskCap, item, price);
237
+ return this;
238
+ }
239
+ /**
240
+ * A function to list an item in the kiosk.
241
+ * @param itemType The type `T` of the item
242
+ * @param itemId The ID of the item
243
+ * @param price The price in MIST
244
+ */
245
+ list({ itemType, itemId, price }) {
246
+ __privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
247
+ kioskTx.list(this.transactionBlock, itemType, this.kiosk, this.kioskCap, itemId, price);
248
+ return this;
249
+ }
250
+ /**
251
+ * A function to delist an item from the kiosk.
252
+ * @param itemType The type `T` of the item
253
+ * @param itemId The ID of the item
254
+ */
255
+ delist({ itemType, itemId }) {
256
+ __privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
257
+ kioskTx.delist(this.transactionBlock, itemType, this.kiosk, this.kioskCap, itemId);
258
+ return this;
259
+ }
260
+ /**
261
+ * A function to take an item from the kiosk. The transaction won't succeed if the item is listed or locked.
262
+
263
+ * @param itemType The type `T` of the item
264
+ * @param itemId The ID of the item
265
+ */
266
+ take({ itemType, itemId }) {
267
+ __privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
268
+ return kioskTx.take(this.transactionBlock, itemType, this.kiosk, this.kioskCap, itemId);
269
+ }
270
+ /**
271
+ * Transfer a non-locked/non-listed item to an address.
272
+ *
273
+ * @param itemType The type `T` of the item
274
+ * @param itemId The ID of the item
275
+ * @param address The destination address
276
+ */
277
+ transfer({ itemType, itemId, address }) {
278
+ __privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
279
+ const item = this.take({ itemType, itemId });
280
+ this.transactionBlock.transferObjects([item], this.transactionBlock.pure.address(address));
281
+ return this;
282
+ }
283
+ /**
284
+ * A function to take lock an item in the kiosk.
285
+
286
+ * @param itemType The type `T` of the item
287
+ * @param itemId The ID of the item
288
+ * @param policy The Policy ID or Transaction Argument for item T
289
+ */
290
+ lock({ itemType, itemId, policy }) {
291
+ __privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
292
+ kioskTx.lock(this.transactionBlock, itemType, this.kiosk, this.kioskCap, policy, itemId);
293
+ return this;
294
+ }
295
+ /**
296
+ * Purchase an item from a seller's kiosk.
297
+ * Returns [item, transferRequest]
298
+ * Can be called like: `const [item, transferRequest] = kioskTx.purchase({...})`
299
+ * @param itemType The type `T` of the item
300
+ * @param itemId The ID of the item
301
+ * @param price The price in MIST
302
+ * @param sellerKiosk The kiosk which is selling the item. Can be an id or an object argument.
303
+ */
304
+ purchase({
305
+ itemType,
306
+ itemId,
307
+ price,
308
+ sellerKiosk
309
+ }) {
310
+ const coin = this.transactionBlock.splitCoins(this.transactionBlock.gas, [
311
+ this.transactionBlock.pure.u64(price)
312
+ ]);
313
+ return kioskTx.purchase(this.transactionBlock, itemType, sellerKiosk, itemId, coin);
314
+ }
315
+ /**
316
+ * A function to purchase and resolve a transfer policy.
317
+ * If the transfer policy has the `lock` rule, the item is locked in the kiosk.
318
+ * Otherwise, the item is placed in the kiosk.
319
+ * @param itemType The type of the item
320
+ * @param itemId The id of the item
321
+ * @param price The price of the specified item
322
+ * @param sellerKiosk The kiosk which is selling the item. Can be an id or an object argument.
323
+ * @param extraArgs Used to pass arguments for custom rule resolvers.
324
+ */
325
+ async purchaseAndResolve({
326
+ itemType,
327
+ itemId,
328
+ price,
329
+ sellerKiosk,
330
+ extraArgs
331
+ }) {
332
+ __privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
333
+ const policies = await this.kioskClient.getTransferPolicies({ type: itemType });
334
+ if (policies.length === 0) {
335
+ throw new Error(
336
+ `The type ${itemType} doesn't have a Transfer Policy so it can't be traded through kiosk.`
337
+ );
338
+ }
339
+ const policy = policies[0];
340
+ const [purchasedItem, transferRequest] = this.purchase({
341
+ itemType,
342
+ itemId,
343
+ price,
344
+ sellerKiosk
345
+ });
346
+ let canTransferOutsideKiosk = true;
347
+ for (const rule of policy.rules) {
348
+ const ruleDefinition = this.kioskClient.rules.find(
349
+ (x) => (0, import_utils.getNormalizedRuleType)(x.rule) === (0, import_utils.getNormalizedRuleType)(rule)
350
+ );
351
+ if (!ruleDefinition)
352
+ throw new Error(`No resolver for the following rule: ${rule}.`);
353
+ if (ruleDefinition.hasLockingRule)
354
+ canTransferOutsideKiosk = false;
355
+ ruleDefinition.resolveRuleFunction({
356
+ packageId: ruleDefinition.packageId,
357
+ transactionBlock: this.transactionBlock,
358
+ itemType,
359
+ itemId,
360
+ price: price.toString(),
361
+ sellerKiosk,
362
+ policyId: policy.id,
363
+ transferRequest,
364
+ purchasedItem,
365
+ kiosk: this.kiosk,
366
+ kioskCap: this.kioskCap,
367
+ extraArgs: extraArgs || {}
368
+ });
369
+ }
370
+ (0, import_transfer_policy.confirmRequest)(this.transactionBlock, itemType, policy.id, transferRequest);
371
+ if (canTransferOutsideKiosk)
372
+ this.place({ itemType, item: purchasedItem });
373
+ return this;
374
+ }
375
+ /**
376
+ * A function to setup the client using an existing `ownerCap`,
377
+ * as return from the `kioskClient.getOwnedKiosks` function.
378
+ * @param cap `KioskOwnerCap` object as returned from `getOwnedKiosks` SDK call.
379
+ */
380
+ setCap(cap) {
381
+ __privateMethod(this, _validateFinalizedStatus, validateFinalizedStatus_fn).call(this);
382
+ this.kiosk = this.transactionBlock.object(cap.kioskId);
383
+ if (!cap.isPersonal) {
384
+ this.kioskCap = this.transactionBlock.object(cap.objectId);
385
+ return;
386
+ }
387
+ return __privateMethod(this, _borrowFromPersonalCap, borrowFromPersonalCap_fn).call(this, cap.objectId);
388
+ }
389
+ /**
390
+ * A function that ends up the kiosk building txb & returns the `kioskOwnerCap` back to the
391
+ * `PersonalKioskCap`, in case we are operating on a personal kiosk.
392
+ * It will also share the `kiosk` if it's not shared, and finalize the transfer of the personal cap if it's pending.
393
+ */
394
+ finalize() {
395
+ __privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
396
+ if (__privateGet(this, _pendingShare))
397
+ this.share();
398
+ if (!__privateGet(this, _personalCap)) {
399
+ if (__privateGet(this, _pendingTransfer))
400
+ throw new Error(
401
+ "You need to transfer the `kioskOwnerCap` by calling `shareAndTransferCap()` before wrap"
402
+ );
403
+ return;
404
+ }
405
+ const packageId = this.kioskClient.getRulePackageId("personalKioskRulePackageId");
406
+ if (__privateGet(this, _promise)) {
407
+ this.transactionBlock.moveCall({
408
+ target: `${packageId}::personal_kiosk::return_val`,
409
+ arguments: [
410
+ __privateGet(this, _personalCap),
411
+ this.transactionBlock.object(this.kioskCap),
412
+ __privateGet(this, _promise)
413
+ ]
414
+ });
415
+ }
416
+ if (__privateGet(this, _pendingTransfer))
417
+ (0, import_personal_kiosk.transferPersonalCapTx)(this.transactionBlock, __privateGet(this, _personalCap), packageId);
418
+ __privateSet(this, _finalized, true);
419
+ }
420
+ // Some setters in case we want custom behavior.
421
+ setKioskCap(cap) {
422
+ __privateMethod(this, _validateFinalizedStatus, validateFinalizedStatus_fn).call(this);
423
+ this.kioskCap = cap;
424
+ return this;
425
+ }
426
+ setKiosk(kiosk) {
427
+ __privateMethod(this, _validateFinalizedStatus, validateFinalizedStatus_fn).call(this);
428
+ this.kiosk = kiosk;
429
+ return this;
430
+ }
431
+ // Some getters
432
+ /*
433
+ * Returns the active transaction's kiosk, or undefined if `setCap` or `create()` hasn't been called yet.
434
+ */
435
+ getKiosk() {
436
+ __privateMethod(this, _validateFinalizedStatus, validateFinalizedStatus_fn).call(this);
437
+ if (!this.kiosk)
438
+ throw new Error("Kiosk is not set.");
439
+ return this.kiosk;
440
+ }
441
+ /*
442
+ * Returns the active transaction's kioskOwnerCap, or undefined if `setCap` or `create()` hasn't been called yet.
443
+ */
444
+ getKioskCap() {
445
+ __privateMethod(this, _validateFinalizedStatus, validateFinalizedStatus_fn).call(this);
446
+ if (!this.kioskCap)
447
+ throw new Error("Kiosk cap is not set");
448
+ return this.kioskCap;
449
+ }
450
+ }
451
+ _pendingShare = new WeakMap();
452
+ _pendingTransfer = new WeakMap();
453
+ _promise = new WeakMap();
454
+ _personalCap = new WeakMap();
455
+ _finalized = new WeakMap();
456
+ _borrowFromPersonalCap = new WeakSet();
457
+ borrowFromPersonalCap_fn = function(personalCap) {
458
+ const [kioskCap, promise] = this.transactionBlock.moveCall({
459
+ target: `${this.kioskClient.getRulePackageId(
460
+ "personalKioskRulePackageId"
461
+ )}::personal_kiosk::borrow_val`,
462
+ arguments: [this.transactionBlock.object(personalCap)]
463
+ });
464
+ this.kioskCap = kioskCap;
465
+ __privateSet(this, _personalCap, this.transactionBlock.object(personalCap));
466
+ __privateSet(this, _promise, promise);
467
+ return this;
468
+ };
469
+ _setPendingStatuses = new WeakSet();
470
+ setPendingStatuses_fn = function({ share, transfer }) {
471
+ if (transfer !== void 0)
472
+ __privateSet(this, _pendingTransfer, transfer);
473
+ if (share !== void 0)
474
+ __privateSet(this, _pendingShare, share);
475
+ };
476
+ _validateKioskIsSet = new WeakSet();
477
+ validateKioskIsSet_fn = function() {
478
+ __privateMethod(this, _validateFinalizedStatus, validateFinalizedStatus_fn).call(this);
479
+ if (!this.kiosk || !this.kioskCap)
480
+ throw new Error(
481
+ "You need to initialize the client by either supplying an existing owner cap or by creating a new by calling `.create()`"
482
+ );
483
+ };
484
+ _validateFinalizedStatus = new WeakSet();
485
+ validateFinalizedStatus_fn = function() {
486
+ if (__privateGet(this, _finalized))
487
+ throw new Error("You can't add more transactions to a finalized kiosk transaction block.");
488
+ };
489
+ //# sourceMappingURL=kiosk-transaction.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/client/kiosk-transaction.ts"],
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type {\n\tTransactionArgument,\n\tTransactionBlock,\n\tTransactionObjectArgument,\n} from '@mysten/sui.js/transactions';\n\nimport * as kioskTx from '../tx/kiosk.js';\nimport { convertToPersonalTx, transferPersonalCapTx } from '../tx/personal-kiosk.js';\nimport { confirmRequest } from '../tx/transfer-policy.js';\nimport type {\n\tItemId,\n\tItemReference,\n\tItemValue,\n\tKioskOwnerCap,\n\tObjectArgument,\n\tPrice,\n\tPurchaseOptions,\n} from '../types/index.js';\nimport { getNormalizedRuleType } from '../utils.js';\nimport type { KioskClient } from './kiosk-client.js';\n\nexport type KioskTransactionParams = {\n\t/** The TransactionBlock for this run */\n\ttransactionBlock: TransactionBlock;\n\t/**\n\t * You can create a new KioskClient by calling `new KioskClient()`\n\t */\n\tkioskClient: KioskClient;\n\t/**\n\t * You can optionally pass in the `cap` as returned\n\t * from `kioskClient.getOwnedKiosks` when initializing the client\n\t * Otherwise, you can set it by calling `kioskTransaction.setCap()`\n\t */\n\tcap?: KioskOwnerCap;\n};\n\n/**\n * A helper for building transactions that involve kiosk.\n */\nexport class KioskTransaction {\n\ttransactionBlock: TransactionBlock;\n\tkioskClient: KioskClient;\n\tkiosk?: TransactionObjectArgument;\n\tkioskCap?: TransactionObjectArgument;\n\t// If we're pending `share` of a new kiosk, `finalize()` will share it.\n\t#pendingShare?: boolean;\n\t// If we're pending transferring of the cap, `finalize()` will either error or transfer the cap if it's a new personal.\n\t#pendingTransfer?: boolean;\n\t// The promise that the personalCap will be returned on `finalize()`.\n\t#promise?: TransactionArgument | undefined;\n\t// The personal kiosk argument.\n\t#personalCap?: TransactionObjectArgument;\n\t// A flag that checks whether kiosk TX is finalized.\n\t#finalized: boolean = false;\n\n\tconstructor({ transactionBlock, kioskClient, cap }: KioskTransactionParams) {\n\t\tthis.transactionBlock = transactionBlock;\n\t\tthis.kioskClient = kioskClient;\n\n\t\tif (cap) this.setCap(cap);\n\t}\n\n\t/**\n\t * Creates a kiosk and saves `kiosk` and `kioskOwnerCap` in state.\n\t * Helpful if we want to chain some actions before sharing + transferring the cap to the specified address.\n\t * @param borrow If true, the `kioskOwnerCap` is borrowed from the `PersonalKioskCap` to be used in next transactions.\n\t */\n\tcreate() {\n\t\tthis.#validateFinalizedStatus();\n\t\tthis.#setPendingStatuses({\n\t\t\tshare: true,\n\t\t\ttransfer: true,\n\t\t});\n\t\tconst [kiosk, cap] = kioskTx.createKiosk(this.transactionBlock);\n\t\tthis.kiosk = kiosk;\n\t\tthis.kioskCap = cap;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Creates a personal kiosk & shares it.\n\t * The `PersonalKioskCap` is transferred to the signer.\n\t * @param borrow If true, the `kioskOwnerCap` is borrowed from the `PersonalKioskCap` to be used in next transactions.\n\t */\n\tcreatePersonal(borrow?: boolean) {\n\t\tthis.#pendingShare = true;\n\t\treturn this.create().convertToPersonal(borrow);\n\t}\n\n\t/**\n\t * Converts a kiosk to a Personal (Soulbound) Kiosk.\n\t * Requires initialization by either calling `ktxb.create()` or `ktxb.setCap()`.\n\t */\n\tconvertToPersonal(borrow?: boolean) {\n\t\tthis.#validateKioskIsSet();\n\n\t\tconst cap = convertToPersonalTx(\n\t\t\tthis.transactionBlock,\n\t\t\tthis.kiosk!,\n\t\t\tthis.kioskCap!,\n\t\t\tthis.kioskClient.getRulePackageId('personalKioskRulePackageId'),\n\t\t);\n\n\t\t// if we enable `borrow`, we borrow the kioskCap from the cap.\n\t\tif (borrow) this.#borrowFromPersonalCap(cap);\n\t\telse this.#personalCap = cap;\n\n\t\tthis.#setPendingStatuses({ transfer: true });\n\t\treturn this;\n\t}\n\n\t/**\n\t * Single function way to create a kiosk, share it and transfer the cap to the specified address.\n\t */\n\tcreateAndShare(address: string) {\n\t\tthis.#validateFinalizedStatus();\n\t\tconst cap = kioskTx.createKioskAndShare(this.transactionBlock);\n\t\tthis.transactionBlock.transferObjects([cap], this.transactionBlock.pure.address(address));\n\t}\n\n\t/**\n\t * Shares the kiosk.\n\t */\n\tshare() {\n\t\tthis.#validateKioskIsSet();\n\t\tthis.#setPendingStatuses({ share: false });\n\t\tkioskTx.shareKiosk(this.transactionBlock, this.kiosk!);\n\t}\n\n\t/**\n\t * Should be called only after `create` is called.\n\t * It shares the kiosk & transfers the cap to the specified address.\n\t */\n\tshareAndTransferCap(address: string) {\n\t\tif (this.#personalCap)\n\t\t\tthrow new Error('You can only call `shareAndTransferCap` on a non-personal kiosk.');\n\t\tthis.#setPendingStatuses({ transfer: false });\n\t\tthis.share();\n\t\tthis.transactionBlock.transferObjects(\n\t\t\t[this.kioskCap!],\n\t\t\tthis.transactionBlock.pure.address(address),\n\t\t);\n\t}\n\n\t/**\n\t * A function to borrow an item from a kiosk & execute any function with it.\n\t * Example: You could borrow a Fren out of a kiosk, attach an accessory (or mix), and return it.\n\t */\n\tborrowTx({ itemType, itemId }: ItemId, callback: (item: TransactionArgument) => void) {\n\t\tthis.#validateKioskIsSet();\n\t\tconst [itemObj, promise] = kioskTx.borrowValue(\n\t\t\tthis.transactionBlock,\n\t\t\titemType,\n\t\t\tthis.kiosk!,\n\t\t\tthis.kioskCap!,\n\t\t\titemId,\n\t\t);\n\n\t\tcallback(itemObj);\n\n\t\tthis.return({ itemType, item: itemObj, promise });\n\t}\n\n\t/**\n\t * Borrows an item from the kiosk.\n\t * This will fail if the item is listed for sale.\n\t *\n\t * Requires calling `return`.\n\t */\n\tborrow({ itemType, itemId }: ItemId): [TransactionArgument, TransactionArgument] {\n\t\tthis.#validateKioskIsSet();\n\t\tconst [itemObj, promise] = kioskTx.borrowValue(\n\t\t\tthis.transactionBlock,\n\t\t\titemType,\n\t\t\tthis.kiosk!,\n\t\t\tthis.kioskCap!,\n\t\t\titemId,\n\t\t);\n\n\t\treturn [itemObj, promise];\n\t}\n\n\t/**\n\t * Returns the item back to the kiosk.\n\t * Accepts the parameters returned from the `borrow` function.\n\t */\n\treturn({ itemType, item, promise }: ItemValue & { promise: TransactionArgument }) {\n\t\tthis.#validateKioskIsSet();\n\t\tkioskTx.returnValue(this.transactionBlock, itemType, this.kiosk!, item, promise);\n\t\treturn this;\n\t}\n\n\t/**\n\t * A function to withdraw from kiosk\n\t * @param address Where to trasnfer the coin.\n\t * @param amount The amount we aim to withdraw.\n\t */\n\twithdraw(address: string, amount?: string | bigint | number) {\n\t\tthis.#validateKioskIsSet();\n\t\tconst coin = kioskTx.withdrawFromKiosk(\n\t\t\tthis.transactionBlock,\n\t\t\tthis.kiosk!,\n\t\t\tthis.kioskCap!,\n\t\t\tamount,\n\t\t);\n\t\tthis.transactionBlock.transferObjects([coin], this.transactionBlock.pure.address(address));\n\t\treturn this;\n\t}\n\n\t/**\n\t * A function to place an item in the kiosk.\n\t * @param itemType The type `T` of the item\n\t * @param item The ID or Transaction Argument of the item\n\t */\n\tplace({ itemType, item }: ItemReference) {\n\t\tthis.#validateKioskIsSet();\n\t\tkioskTx.place(this.transactionBlock, itemType, this.kiosk!, this.kioskCap!, item);\n\t\treturn this;\n\t}\n\n\t/**\n\t * A function to place an item in the kiosk and list it for sale in one transaction.\n\t * @param itemType The type `T` of the item\n\t * @param item The ID or Transaction Argument of the item\n\t * @param price The price in MIST\n\t */\n\tplaceAndList({ itemType, item, price }: ItemReference & Price) {\n\t\tthis.#validateKioskIsSet();\n\t\tkioskTx.placeAndList(this.transactionBlock, itemType, this.kiosk!, this.kioskCap!, item, price);\n\t\treturn this;\n\t}\n\n\t/**\n\t * A function to list an item in the kiosk.\n\t * @param itemType The type `T` of the item\n\t * @param itemId The ID of the item\n\t * @param price The price in MIST\n\t */\n\tlist({ itemType, itemId, price }: ItemId & { price: string | bigint }) {\n\t\tthis.#validateKioskIsSet();\n\t\tkioskTx.list(this.transactionBlock, itemType, this.kiosk!, this.kioskCap!, itemId, price);\n\t\treturn this;\n\t}\n\n\t/**\n\t * A function to delist an item from the kiosk.\n\t * @param itemType The type `T` of the item\n\t * @param itemId The ID of the item\n\t */\n\tdelist({ itemType, itemId }: ItemId) {\n\t\tthis.#validateKioskIsSet();\n\t\tkioskTx.delist(this.transactionBlock, itemType, this.kiosk!, this.kioskCap!, itemId);\n\t\treturn this;\n\t}\n\n\t/**\n\t * A function to take an item from the kiosk. The transaction won't succeed if the item is listed or locked.\n\n\t * @param itemType The type `T` of the item\n\t * @param itemId The ID of the item\n\t */\n\ttake({ itemType, itemId }: ItemId): TransactionObjectArgument {\n\t\tthis.#validateKioskIsSet();\n\t\treturn kioskTx.take(this.transactionBlock, itemType, this.kiosk!, this.kioskCap!, itemId);\n\t}\n\n\t/**\n\t * Transfer a non-locked/non-listed item to an address.\n\t *\n\t * @param itemType The type `T` of the item\n\t * @param itemId The ID of the item\n\t * @param address The destination address\n\t */\n\ttransfer({ itemType, itemId, address }: ItemId & { address: string }) {\n\t\tthis.#validateKioskIsSet();\n\t\tconst item = this.take({ itemType, itemId });\n\t\tthis.transactionBlock.transferObjects([item], this.transactionBlock.pure.address(address));\n\t\treturn this;\n\t}\n\n\t/**\n\t * A function to take lock an item in the kiosk.\n\n\t * @param itemType The type `T` of the item\n\t * @param itemId The ID of the item\n\t * @param policy The Policy ID or Transaction Argument for item T\n\t */\n\tlock({ itemType, itemId, policy }: ItemId & { policy: ObjectArgument }) {\n\t\tthis.#validateKioskIsSet();\n\t\tkioskTx.lock(this.transactionBlock, itemType, this.kiosk!, this.kioskCap!, policy, itemId);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Purchase an item from a seller's kiosk.\n\t * Returns [item, transferRequest]\n\t * Can be called like: `const [item, transferRequest] = kioskTx.purchase({...})`\n\t * @param itemType The type `T` of the item\n\t * @param itemId The ID of the item\n\t * @param price The price in MIST\n\t * @param sellerKiosk The kiosk which is selling the item. Can be an id or an object argument.\n\t */\n\tpurchase({\n\t\titemType,\n\t\titemId,\n\t\tprice,\n\t\tsellerKiosk,\n\t}: ItemId & Price & { sellerKiosk: ObjectArgument }): [\n\t\tTransactionObjectArgument,\n\t\tTransactionObjectArgument,\n\t] {\n\t\t// Split the coin for the amount of the listing.\n\t\tconst coin = this.transactionBlock.splitCoins(this.transactionBlock.gas, [\n\t\t\tthis.transactionBlock.pure.u64(price),\n\t\t]);\n\t\treturn kioskTx.purchase(this.transactionBlock, itemType, sellerKiosk, itemId, coin);\n\t}\n\n\t/**\n\t * A function to purchase and resolve a transfer policy.\n\t * If the transfer policy has the `lock` rule, the item is locked in the kiosk.\n\t * Otherwise, the item is placed in the kiosk.\n\t * @param itemType The type of the item\n\t * @param itemId The id of the item\n\t * @param price The price of the specified item\n\t * @param sellerKiosk The kiosk which is selling the item. Can be an id or an object argument.\n\t * @param extraArgs Used to pass arguments for custom rule resolvers.\n\t */\n\tasync purchaseAndResolve({\n\t\titemType,\n\t\titemId,\n\t\tprice,\n\t\tsellerKiosk,\n\t\textraArgs,\n\t}: ItemId & Price & { sellerKiosk: ObjectArgument } & PurchaseOptions) {\n\t\tthis.#validateKioskIsSet();\n\t\t// Get a list of the transfer policies.\n\t\tconst policies = await this.kioskClient.getTransferPolicies({ type: itemType });\n\n\t\tif (policies.length === 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`The type ${itemType} doesn't have a Transfer Policy so it can't be traded through kiosk.`,\n\t\t\t);\n\t\t}\n\n\t\tconst policy = policies[0]; // we now pick the first one. We need to add an option to define which one.\n\n\t\t// initialize the purchase `kiosk::purchase`\n\t\tconst [purchasedItem, transferRequest] = this.purchase({\n\t\t\titemType,\n\t\t\titemId,\n\t\t\tprice,\n\t\t\tsellerKiosk,\n\t\t});\n\n\t\tlet canTransferOutsideKiosk = true;\n\n\t\tfor (const rule of policy.rules) {\n\t\t\tconst ruleDefinition = this.kioskClient.rules.find(\n\t\t\t\t(x) => getNormalizedRuleType(x.rule) === getNormalizedRuleType(rule),\n\t\t\t);\n\t\t\tif (!ruleDefinition) throw new Error(`No resolver for the following rule: ${rule}.`);\n\n\t\t\tif (ruleDefinition.hasLockingRule) canTransferOutsideKiosk = false;\n\n\t\t\truleDefinition.resolveRuleFunction({\n\t\t\t\tpackageId: ruleDefinition.packageId,\n\t\t\t\ttransactionBlock: this.transactionBlock,\n\t\t\t\titemType,\n\t\t\t\titemId,\n\t\t\t\tprice: price.toString(),\n\t\t\t\tsellerKiosk,\n\t\t\t\tpolicyId: policy.id,\n\t\t\t\ttransferRequest,\n\t\t\t\tpurchasedItem,\n\t\t\t\tkiosk: this.kiosk!,\n\t\t\t\tkioskCap: this.kioskCap!,\n\t\t\t\textraArgs: extraArgs || {},\n\t\t\t});\n\t\t}\n\n\t\tconfirmRequest(this.transactionBlock, itemType, policy.id, transferRequest);\n\n\t\tif (canTransferOutsideKiosk) this.place({ itemType, item: purchasedItem });\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * A function to setup the client using an existing `ownerCap`,\n\t * as return from the `kioskClient.getOwnedKiosks` function.\n\t * @param cap `KioskOwnerCap` object as returned from `getOwnedKiosks` SDK call.\n\t */\n\tsetCap(cap: KioskOwnerCap) {\n\t\tthis.#validateFinalizedStatus();\n\t\tthis.kiosk = this.transactionBlock.object(cap.kioskId);\n\t\tif (!cap.isPersonal) {\n\t\t\tthis.kioskCap = this.transactionBlock.object(cap.objectId);\n\t\t\treturn;\n\t\t}\n\n\t\treturn this.#borrowFromPersonalCap(cap.objectId);\n\t}\n\n\t/**\n\t *\tA function that ends up the kiosk building txb & returns the `kioskOwnerCap` back to the\n\t * `PersonalKioskCap`, in case we are operating on a personal kiosk.\n\t * \tIt will also share the `kiosk` if it's not shared, and finalize the transfer of the personal cap if it's pending.\n\t */\n\tfinalize() {\n\t\tthis.#validateKioskIsSet();\n\t\t// If we're pending the sharing of the new kiosk, share it.\n\t\tif (this.#pendingShare) this.share();\n\n\t\t// If we're operating on a non-personal kiosk, we don't need to do anything else.\n\t\tif (!this.#personalCap) {\n\t\t\t// If we're pending transfer though, we inform user to call `shareAndTransferCap()`.\n\t\t\tif (this.#pendingTransfer)\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'You need to transfer the `kioskOwnerCap` by calling `shareAndTransferCap()` before wrap',\n\t\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst packageId = this.kioskClient.getRulePackageId('personalKioskRulePackageId');\n\n\t\t// if we have a promise, return the `ownerCap` back to the personal cap.\n\t\tif (this.#promise) {\n\t\t\tthis.transactionBlock.moveCall({\n\t\t\t\ttarget: `${packageId}::personal_kiosk::return_val`,\n\t\t\t\targuments: [\n\t\t\t\t\tthis.#personalCap,\n\t\t\t\t\tthis.transactionBlock.object(this.kioskCap!),\n\t\t\t\t\tthis.#promise!,\n\t\t\t\t],\n\t\t\t});\n\t\t}\n\n\t\t// If we are pending transferring the personalCap, we do it here.\n\t\tif (this.#pendingTransfer)\n\t\t\ttransferPersonalCapTx(this.transactionBlock, this.#personalCap, packageId);\n\n\t\t// Mark the transaction block as finalized, so no other functions can be called.\n\t\tthis.#finalized = true;\n\t}\n\n\t// Some setters in case we want custom behavior.\n\tsetKioskCap(cap: TransactionObjectArgument) {\n\t\tthis.#validateFinalizedStatus();\n\t\tthis.kioskCap = cap;\n\t\treturn this;\n\t}\n\n\tsetKiosk(kiosk: TransactionObjectArgument) {\n\t\tthis.#validateFinalizedStatus();\n\t\tthis.kiosk = kiosk;\n\t\treturn this;\n\t}\n\n\t// Some getters\n\t/*\n\t * Returns the active transaction's kiosk, or undefined if `setCap` or `create()` hasn't been called yet.\n\t */\n\tgetKiosk() {\n\t\tthis.#validateFinalizedStatus();\n\t\tif (!this.kiosk) throw new Error('Kiosk is not set.');\n\t\treturn this.kiosk;\n\t}\n\n\t/*\n\t * Returns the active transaction's kioskOwnerCap, or undefined if `setCap` or `create()` hasn't been called yet.\n\t */\n\tgetKioskCap() {\n\t\tthis.#validateFinalizedStatus();\n\t\tif (!this.kioskCap) throw new Error('Kiosk cap is not set');\n\t\treturn this.kioskCap;\n\t}\n\n\t/**\n\t * A function to borrow from `personalCap`.\n\t */\n\t#borrowFromPersonalCap(personalCap: ObjectArgument) {\n\t\tconst [kioskCap, promise] = this.transactionBlock.moveCall({\n\t\t\ttarget: `${this.kioskClient.getRulePackageId(\n\t\t\t\t'personalKioskRulePackageId',\n\t\t\t)}::personal_kiosk::borrow_val`,\n\t\t\targuments: [this.transactionBlock.object(personalCap)],\n\t\t});\n\n\t\tthis.kioskCap = kioskCap;\n\t\tthis.#personalCap = this.transactionBlock.object(personalCap);\n\t\tthis.#promise = promise;\n\n\t\treturn this;\n\t}\n\n\t#setPendingStatuses({ share, transfer }: { share?: boolean; transfer?: boolean }) {\n\t\tif (transfer !== undefined) this.#pendingTransfer = transfer;\n\t\tif (share !== undefined) this.#pendingShare = share;\n\t}\n\n\t#validateKioskIsSet() {\n\t\tthis.#validateFinalizedStatus();\n\n\t\tif (!this.kiosk || !this.kioskCap)\n\t\t\tthrow new Error(\n\t\t\t\t'You need to initialize the client by either supplying an existing owner cap or by creating a new by calling `.create()`',\n\t\t\t);\n\t}\n\n\t// Validates that `finalize`\n\t#validateFinalizedStatus() {\n\t\tif (this.#finalized)\n\t\t\tthrow new Error(\"You can't add more transactions to a finalized kiosk transaction block.\");\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,cAAyB;AACzB,4BAA2D;AAC3D,6BAA+B;AAU/B,mBAAsC;AArBtC;AA0CO,MAAM,iBAAiB;AAAA,EAgB7B,YAAY,EAAE,kBAAkB,aAAa,IAAI,GAA2B;AA0a5E;AAAA;AAAA;AAAA;AAeA;AAKA;AAUA;AAAA;AAldA;AAAA;AAEA;AAAA;AAEA;AAAA;AAEA;AAAA;AAEA;AAAA,mCAAsB;AAGrB,SAAK,mBAAmB;AACxB,SAAK,cAAc;AAEnB,QAAI;AAAK,WAAK,OAAO,GAAG;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,SAAS;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[]
7
+ }
@@ -1,6 +1,6 @@
1
- import { type TransactionBlock } from '@mysten/sui.js/transactions';
2
- import { TransferPolicyCap, type ObjectArgument } from '../types';
3
- import { KioskClient } from './kiosk-client';
1
+ import type { TransactionBlock } from '@mysten/sui.js/transactions';
2
+ import type { ObjectArgument, TransferPolicyCap } from '../types/index.js';
3
+ import type { KioskClient } from './kiosk-client.js';
4
4
  export type TransferPolicyBaseParams = {
5
5
  type: string;
6
6
  publisher: ObjectArgument;