@mysten/kiosk 0.6.0 → 0.7.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 (44) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +2 -287
  3. package/dist/client/kiosk-client.d.ts +64 -0
  4. package/dist/client/kiosk-transaction.d.ts +182 -0
  5. package/dist/client/tp-transaction.d.ts +112 -0
  6. package/dist/constants.d.ts +30 -4
  7. package/dist/index.d.ts +3 -6
  8. package/dist/index.js +1256 -264
  9. package/dist/index.js.map +1 -1
  10. package/dist/index.mjs +1239 -230
  11. package/dist/index.mjs.map +1 -1
  12. package/dist/query/kiosk.d.ts +2 -1
  13. package/dist/query/transfer-policy.d.ts +17 -1
  14. package/dist/tx/kiosk.d.ts +11 -27
  15. package/dist/tx/personal-kiosk.d.ts +7 -0
  16. package/dist/tx/rules/attach.d.ts +7 -0
  17. package/dist/tx/rules/resolve.d.ts +15 -0
  18. package/dist/tx/transfer-policy.d.ts +14 -17
  19. package/dist/types/index.d.ts +23 -5
  20. package/dist/types/kiosk.d.ts +30 -1
  21. package/dist/types/transfer-policy.d.ts +27 -1
  22. package/dist/utils.d.ts +32 -18
  23. package/package.json +12 -4
  24. package/src/bcs.ts +1 -0
  25. package/src/client/kiosk-client.ts +156 -0
  26. package/src/client/kiosk-transaction.ts +519 -0
  27. package/src/client/tp-transaction.ts +350 -0
  28. package/src/constants.ts +113 -6
  29. package/src/index.ts +3 -6
  30. package/src/query/kiosk.ts +51 -18
  31. package/src/query/transfer-policy.ts +82 -2
  32. package/src/tx/kiosk.ts +37 -158
  33. package/src/tx/personal-kiosk.ts +35 -0
  34. package/src/tx/rules/attach.ts +74 -0
  35. package/src/tx/rules/resolve.ts +87 -0
  36. package/src/tx/transfer-policy.ts +46 -79
  37. package/src/types/index.ts +26 -5
  38. package/src/types/kiosk.ts +26 -1
  39. package/src/types/transfer-policy.ts +35 -1
  40. package/src/utils.ts +143 -35
  41. package/dist/tx/rules.d.ts +0 -19
  42. package/dist/types/env.d.ts +0 -12
  43. package/src/tx/rules.ts +0 -58
  44. package/src/types/env.ts +0 -20
package/dist/index.mjs CHANGED
@@ -1,3 +1,29 @@
1
+ var __accessCheck = (obj, member, msg) => {
2
+ if (!member.has(obj))
3
+ throw TypeError("Cannot " + msg);
4
+ };
5
+ var __privateGet = (obj, member, getter) => {
6
+ __accessCheck(obj, member, "read from private field");
7
+ return getter ? getter.call(obj) : member.get(obj);
8
+ };
9
+ var __privateAdd = (obj, member, value) => {
10
+ if (member.has(obj))
11
+ throw TypeError("Cannot add the same private member more than once");
12
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
13
+ };
14
+ var __privateSet = (obj, member, value, setter) => {
15
+ __accessCheck(obj, member, "write to private field");
16
+ setter ? setter.call(obj, value) : member.set(obj, value);
17
+ return value;
18
+ };
19
+ var __privateMethod = (obj, member, method) => {
20
+ __accessCheck(obj, member, "access private method");
21
+ return method;
22
+ };
23
+
24
+ // src/utils.ts
25
+ import { normalizeSuiAddress } from "@mysten/sui.js/utils";
26
+
1
27
  // src/bcs.ts
2
28
  import { bcs } from "@mysten/sui.js/bcs";
3
29
 
@@ -14,16 +40,17 @@ var KIOSK_PURCHASE_CAP = `${KIOSK_MODULE}::PurchaseCap`;
14
40
  var TRANSFER_POLICY_MODULE = "0x2::transfer_policy";
15
41
  var TRANSFER_POLICY_CREATED_EVENT = `${TRANSFER_POLICY_MODULE}::TransferPolicyCreated`;
16
42
  var TRANSFER_POLICY_TYPE = `${TRANSFER_POLICY_MODULE}::TransferPolicy`;
43
+ var TRANSFER_POLICY_CAP_TYPE = `${TRANSFER_POLICY_MODULE}::TransferPolicyCap`;
17
44
  var KIOSK_LOCK_RULE = "kiosk_lock_rule::Rule";
18
45
  var ROYALTY_RULE = "royalty_rule::Rule";
19
46
 
20
- // src/types/env.ts
21
- var testnetEnvironment = { env: "testnet" };
22
- var mainnetEnvironment = { env: "mainnet" };
23
- var customEnvironment = (address) => ({
24
- env: "custom",
25
- address
26
- });
47
+ // src/types/index.ts
48
+ var Network = /* @__PURE__ */ ((Network2) => {
49
+ Network2["MAINNET"] = "mainnet";
50
+ Network2["TESTNET"] = "testnet";
51
+ Network2["CUSTOM"] = "custom";
52
+ return Network2;
53
+ })(Network || {});
27
54
 
28
55
  // src/bcs.ts
29
56
  bcs.registerStructType(KIOSK_TYPE, {
@@ -48,26 +75,17 @@ bcs.registerStructType(TRANSFER_POLICY_TYPE, {
48
75
  rules: ["vector", "string"]
49
76
  });
50
77
 
51
- // src/constants.ts
52
- var TESTNET_RULES_PACKAGE_ADDRESS = "bd8fc1947cf119350184107a3087e2dc27efefa0dd82e25a1f699069fe81a585";
53
- var MAINNET_RULES_PACKAGE_ADDRESS = "0x434b5bd8f6a7b05fede0ff46c6e511d71ea326ed38056e3bcd681d2d7c2a7879";
54
-
55
78
  // src/utils.ts
56
- var rulesPackageAddresses = {
57
- mainnet: MAINNET_RULES_PACKAGE_ADDRESS,
58
- testnet: TESTNET_RULES_PACKAGE_ADDRESS,
59
- devnet: "",
60
- custom: null
61
- };
62
- function objArg(tx, arg) {
79
+ var DEFAULT_QUERY_LIMIT = 50;
80
+ function objArg(txb, arg) {
63
81
  if (typeof arg === "string") {
64
- return tx.object(arg);
82
+ return txb.object(arg);
65
83
  }
66
84
  if ("digest" in arg && "version" in arg && "objectId" in arg) {
67
- return tx.objectRef(arg);
85
+ return txb.objectRef(arg);
68
86
  }
69
87
  if ("objectId" in arg && "initialSharedVersion" in arg && "mutable" in arg) {
70
- return tx.sharedObjectRef(arg);
88
+ return txb.sharedObjectRef(arg);
71
89
  }
72
90
  if ("kind" in arg) {
73
91
  return arg;
@@ -84,7 +102,7 @@ async function getKioskObject(client, id) {
84
102
  }
85
103
  return bcs.de(KIOSK_TYPE, queryRes.data.bcs.bcsBytes, "base64");
86
104
  }
87
- function extractKioskData(data, listings, lockedItemIds) {
105
+ function extractKioskData(data, listings, lockedItemIds, kioskId) {
88
106
  return data.reduce(
89
107
  (acc, val) => {
90
108
  const type = getTypeWithoutPackageAddress(val.name.type);
@@ -94,7 +112,8 @@ function extractKioskData(data, listings, lockedItemIds) {
94
112
  acc.items.push({
95
113
  objectId: val.objectId,
96
114
  type: val.objectType,
97
- isLocked: false
115
+ isLocked: false,
116
+ kioskId
98
117
  });
99
118
  break;
100
119
  case "kiosk::Listing":
@@ -136,6 +155,18 @@ function attachListingsAndPrices(kioskData, listings, listingObjects) {
136
155
  item.listing = itemListings[item.objectId] || void 0;
137
156
  });
138
157
  }
158
+ function attachObjects(kioskData, objects) {
159
+ const mapping = objects.reduce(
160
+ (acc, obj) => {
161
+ acc[obj.objectId] = obj;
162
+ return acc;
163
+ },
164
+ {}
165
+ );
166
+ kioskData.items.forEach((item) => {
167
+ item.data = mapping[item.objectId] || void 0;
168
+ });
169
+ }
139
170
  function attachLockedItems(kioskData, lockedItemIds) {
140
171
  const lockedStatuses = lockedItemIds.reduce(
141
172
  (acc, item) => {
@@ -148,14 +179,6 @@ function attachLockedItems(kioskData, lockedItemIds) {
148
179
  item.isLocked = lockedStatuses[item.objectId] || false;
149
180
  });
150
181
  }
151
- function getRulePackageAddress(environment) {
152
- if (environment.env === "custom") {
153
- if (!environment.address)
154
- throw new Error("Please supply the custom package address for rules.");
155
- return environment.address;
156
- }
157
- return rulesPackageAddresses[environment.env];
158
- }
159
182
  async function getAllDynamicFields(client, parentId, pagination) {
160
183
  let hasNextPage = true;
161
184
  let cursor = void 0;
@@ -172,89 +195,87 @@ async function getAllDynamicFields(client, parentId, pagination) {
172
195
  }
173
196
  return data;
174
197
  }
198
+ async function getAllObjects(client, ids, options, limit = DEFAULT_QUERY_LIMIT) {
199
+ const chunks = Array.from(
200
+ { length: Math.ceil(ids.length / limit) },
201
+ (_, index) => ids.slice(index * limit, index * limit + limit)
202
+ );
203
+ const results = await Promise.all(
204
+ chunks.map((chunk) => {
205
+ return client.multiGetObjects({
206
+ ids: chunk,
207
+ options
208
+ });
209
+ })
210
+ );
211
+ return results.flat();
212
+ }
213
+ async function getAllOwnedObjects({
214
+ client,
215
+ owner,
216
+ filter,
217
+ limit = DEFAULT_QUERY_LIMIT,
218
+ options = { showType: true, showContent: true }
219
+ }) {
220
+ let hasNextPage = true;
221
+ let cursor = void 0;
222
+ const data = [];
223
+ while (hasNextPage) {
224
+ const result = await client.getOwnedObjects({
225
+ owner,
226
+ filter,
227
+ limit,
228
+ cursor,
229
+ options
230
+ });
231
+ data.push(...result.data);
232
+ hasNextPage = result.hasNextPage;
233
+ cursor = result.nextCursor;
234
+ }
235
+ return data;
236
+ }
175
237
  function percentageToBasisPoints(percentage) {
176
238
  if (percentage < 0 || percentage > 100)
177
239
  throw new Error("Percentage needs to be in the [0,100] range.");
178
240
  return Math.ceil(percentage * 100);
179
241
  }
180
-
181
- // src/tx/transfer-policy.ts
182
- function createTransferPolicy(tx, itemType, publisher) {
183
- let [transferPolicy, transferPolicyCap] = tx.moveCall({
184
- target: `${TRANSFER_POLICY_MODULE}::new`,
185
- typeArguments: [itemType],
186
- arguments: [objArg(tx, publisher)]
187
- });
188
- tx.moveCall({
189
- target: `0x2::transfer::public_share_object`,
190
- typeArguments: [`${TRANSFER_POLICY_TYPE}<${itemType}>`],
191
- arguments: [transferPolicy]
192
- });
193
- return transferPolicyCap;
194
- }
195
- function withdrawFromPolicy(tx, itemType, policy, policyCap, amount) {
196
- let amountArg = amount !== null ? tx.pure({ Some: amount }, "Option<u64>") : tx.pure({ None: true }, "Option<u64>");
197
- let [profits] = tx.moveCall({
198
- target: `${TRANSFER_POLICY_MODULE}::withdraw`,
199
- typeArguments: [itemType],
200
- arguments: [objArg(tx, policy), objArg(tx, policyCap), amountArg]
201
- });
202
- return profits;
203
- }
204
- function confirmRequest(tx, itemType, policy, request) {
205
- tx.moveCall({
206
- target: `${TRANSFER_POLICY_MODULE}::confirm_request`,
207
- typeArguments: [itemType],
208
- arguments: [objArg(tx, policy), request]
209
- });
210
- }
211
- function removeTransferPolicyRule(tx, itemType, ruleType, configType, policy, policyCap) {
212
- tx.moveCall({
213
- target: `${TRANSFER_POLICY_MODULE}::remove_rule`,
214
- typeArguments: [itemType, ruleType, configType],
215
- arguments: [objArg(tx, policy), policyCap]
216
- });
217
- }
218
- function resolveRoyaltyRule(tx, itemType, price, policyId, transferRequest, environment) {
219
- const policyObj = objArg(tx, policyId);
220
- const [amount] = tx.moveCall({
221
- target: `${getRulePackageAddress(environment)}::royalty_rule::fee_amount`,
222
- typeArguments: [itemType],
223
- arguments: [policyObj, objArg(tx, price)]
224
- });
225
- const feeCoin = tx.splitCoins(tx.gas, [amount]);
226
- tx.moveCall({
227
- target: `${getRulePackageAddress(environment)}::royalty_rule::pay`,
228
- typeArguments: [itemType],
229
- arguments: [policyObj, transferRequest, feeCoin]
230
- });
242
+ function parseTransferPolicyCapObject(item) {
243
+ const type = item?.data?.content?.type;
244
+ const policy = item?.data?.content?.fields?.policy_id;
245
+ if (!type.includes(TRANSFER_POLICY_CAP_TYPE))
246
+ return void 0;
247
+ const objectType = type.replace(TRANSFER_POLICY_CAP_TYPE + "<", "").slice(0, -1);
248
+ return {
249
+ policyId: policy,
250
+ policyCapId: item.data?.objectId,
251
+ type: objectType
252
+ };
231
253
  }
232
- function resolveKioskLockRule(tx, itemType, item, kiosk, kioskCap, policyId, transferRequest, environment) {
233
- lock(tx, itemType, kiosk, kioskCap, policyId, item);
234
- tx.moveCall({
235
- target: `${getRulePackageAddress(environment)}::kiosk_lock_rule::prove`,
236
- typeArguments: [itemType],
237
- arguments: [transferRequest, objArg(tx, kiosk)]
238
- });
254
+ function getNormalizedRuleType(rule) {
255
+ const normalizedRuleAddress = rule.split("::");
256
+ normalizedRuleAddress[0] = normalizeSuiAddress(normalizedRuleAddress[0]);
257
+ return normalizedRuleAddress.join("::");
239
258
  }
240
259
 
241
260
  // src/tx/kiosk.ts
261
+ import { bcs as bcs2 } from "@mysten/sui.js/bcs";
242
262
  function createKiosk(tx) {
243
- let [kiosk, kioskOwnerCap] = tx.moveCall({
263
+ const [kiosk, kioskOwnerCap] = tx.moveCall({
244
264
  target: `${KIOSK_MODULE}::new`
245
265
  });
246
266
  return [kiosk, kioskOwnerCap];
247
267
  }
248
268
  function createKioskAndShare(tx) {
249
- let [kiosk, kioskOwnerCap] = tx.moveCall({
250
- target: `${KIOSK_MODULE}::new`
251
- });
269
+ const [kiosk, kioskOwnerCap] = createKiosk(tx);
270
+ shareKiosk(tx, kiosk);
271
+ return kioskOwnerCap;
272
+ }
273
+ function shareKiosk(tx, kiosk) {
252
274
  tx.moveCall({
253
275
  target: `0x2::transfer::public_share_object`,
254
276
  typeArguments: [KIOSK_TYPE],
255
277
  arguments: [kiosk]
256
278
  });
257
- return kioskOwnerCap;
258
279
  }
259
280
  function place(tx, itemType, kiosk, kioskCap, item) {
260
281
  tx.moveCall({
@@ -271,10 +292,10 @@ function lock(tx, itemType, kiosk, kioskCap, policy, item) {
271
292
  });
272
293
  }
273
294
  function take(tx, itemType, kiosk, kioskCap, itemId) {
274
- let [item] = tx.moveCall({
295
+ const [item] = tx.moveCall({
275
296
  target: `${KIOSK_MODULE}::take`,
276
297
  typeArguments: [itemType],
277
- arguments: [objArg(tx, kiosk), objArg(tx, kioskCap), tx.pure(itemId, "address")]
298
+ arguments: [objArg(tx, kiosk), objArg(tx, kioskCap), tx.pure.address(itemId)]
278
299
  });
279
300
  return item;
280
301
  }
@@ -285,8 +306,8 @@ function list(tx, itemType, kiosk, kioskCap, itemId, price) {
285
306
  arguments: [
286
307
  objArg(tx, kiosk),
287
308
  objArg(tx, kioskCap),
288
- tx.pure(itemId, "address"),
289
- tx.pure(price, "u64")
309
+ tx.pure.address(itemId),
310
+ tx.pure.u64(price)
290
311
  ]
291
312
  });
292
313
  }
@@ -294,58 +315,37 @@ function delist(tx, itemType, kiosk, kioskCap, itemId) {
294
315
  tx.moveCall({
295
316
  target: `${KIOSK_MODULE}::delist`,
296
317
  typeArguments: [itemType],
297
- arguments: [objArg(tx, kiosk), objArg(tx, kioskCap), tx.pure(itemId, "address")]
318
+ arguments: [objArg(tx, kiosk), objArg(tx, kioskCap), tx.pure.address(itemId)]
298
319
  });
299
320
  }
300
321
  function placeAndList(tx, itemType, kiosk, kioskCap, item, price) {
301
322
  tx.moveCall({
302
323
  target: `${KIOSK_MODULE}::place_and_list`,
303
324
  typeArguments: [itemType],
304
- arguments: [objArg(tx, kiosk), objArg(tx, kioskCap), objArg(tx, item), tx.pure(price, "u64")]
325
+ arguments: [objArg(tx, kiosk), objArg(tx, kioskCap), objArg(tx, item), tx.pure.u64(price)]
305
326
  });
306
327
  }
307
328
  function purchase(tx, itemType, kiosk, itemId, payment) {
308
- let [item, transferRequest] = tx.moveCall({
329
+ const [item, transferRequest] = tx.moveCall({
309
330
  target: `${KIOSK_MODULE}::purchase`,
310
331
  typeArguments: [itemType],
311
- arguments: [objArg(tx, kiosk), tx.pure(itemId, "address"), objArg(tx, payment)]
332
+ arguments: [objArg(tx, kiosk), tx.pure.address(itemId), objArg(tx, payment)]
312
333
  });
313
334
  return [item, transferRequest];
314
335
  }
315
336
  function withdrawFromKiosk(tx, kiosk, kioskCap, amount) {
316
- let amountArg = amount !== null ? tx.pure(
317
- {
318
- Some: amount
319
- },
320
- "Option<u64>"
321
- ) : tx.pure({ None: true }, "Option<u64>");
322
- let [coin] = tx.moveCall({
337
+ const amountArg = bcs2.option(bcs2.u64()).serialize(amount);
338
+ const [coin] = tx.moveCall({
323
339
  target: `${KIOSK_MODULE}::withdraw`,
324
340
  arguments: [objArg(tx, kiosk), objArg(tx, kioskCap), amountArg]
325
341
  });
326
342
  return coin;
327
343
  }
328
- function borrow(tx, itemType, kiosk, kioskCap, itemId) {
329
- let [item] = tx.moveCall({
330
- target: `${KIOSK_MODULE}::borrow`,
331
- typeArguments: [itemType],
332
- arguments: [objArg(tx, kiosk), objArg(tx, kioskCap), tx.pure(itemId, "address")]
333
- });
334
- return item;
335
- }
336
- function borrowMut(tx, itemType, kiosk, kioskCap, itemId) {
337
- let [item] = tx.moveCall({
338
- target: `${KIOSK_MODULE}::borrow_mut`,
339
- typeArguments: [itemType],
340
- arguments: [objArg(tx, kiosk), objArg(tx, kioskCap), tx.pure(itemId, "address")]
341
- });
342
- return item;
343
- }
344
344
  function borrowValue(tx, itemType, kiosk, kioskCap, itemId) {
345
- let [item, promise] = tx.moveCall({
345
+ const [item, promise] = tx.moveCall({
346
346
  target: `${KIOSK_MODULE}::borrow_val`,
347
347
  typeArguments: [itemType],
348
- arguments: [objArg(tx, kiosk), objArg(tx, kioskCap), tx.pure(itemId, "address")]
348
+ arguments: [objArg(tx, kiosk), objArg(tx, kioskCap), tx.pure.address(itemId)]
349
349
  });
350
350
  return [item, promise];
351
351
  }
@@ -356,68 +356,132 @@ function returnValue(tx, itemType, kiosk, item, promise) {
356
356
  arguments: [objArg(tx, kiosk), item, promise]
357
357
  });
358
358
  }
359
- function purchaseAndResolvePolicies(tx, itemType, price, kiosk, itemId, policy, environment, extraParams) {
360
- if (price === void 0 || typeof price !== "string")
361
- throw new Error(`Price of the listing is not supplied.`);
362
- const coin = tx.splitCoins(tx.gas, [tx.pure(price, "u64")]);
363
- const [purchasedItem, transferRequest] = purchase(tx, itemType, kiosk, itemId, coin);
364
- let hasKioskLockRule = false;
365
- for (let rule of policy.rules) {
366
- const ruleWithoutAddr = getTypeWithoutPackageAddress(rule);
367
- switch (ruleWithoutAddr) {
368
- case ROYALTY_RULE:
369
- resolveRoyaltyRule(tx, itemType, price, policy.id, transferRequest, environment);
370
- break;
371
- case KIOSK_LOCK_RULE:
372
- if (!extraParams?.ownedKiosk || !extraParams?.ownedKioskCap)
373
- throw new Error(
374
- `This item type ${itemType} has a 'kiosk_lock_rule', but function call is missing user's kiosk and kioskCap params`
375
- );
376
- hasKioskLockRule = true;
377
- resolveKioskLockRule(
378
- tx,
379
- itemType,
380
- purchasedItem,
381
- extraParams.ownedKiosk,
382
- extraParams.ownedKioskCap,
383
- policy.id,
384
- transferRequest,
385
- environment
386
- );
387
- break;
388
- default:
389
- break;
390
- }
391
- }
392
- confirmRequest(tx, itemType, policy.id, transferRequest);
393
- return {
394
- item: purchasedItem,
395
- canTransfer: !hasKioskLockRule
396
- };
397
- }
398
359
 
399
- // src/tx/rules.ts
400
- function attachRoyaltyRule(tx, type, policy, policyCap, percentageBps, minAmount, environment) {
401
- if (Number(percentageBps) < 0 || Number(percentageBps) > 1e4)
402
- throw new Error("Invalid basis point percentage. Use a value between [0,10000].");
403
- tx.moveCall({
404
- target: `${getRulePackageAddress(environment)}::royalty_rule::add`,
405
- typeArguments: [type],
406
- arguments: [
407
- objArg(tx, policy),
408
- objArg(tx, policyCap),
409
- tx.pure(percentageBps, "u16"),
410
- tx.pure(minAmount, "u64")
411
- ]
360
+ // src/tx/rules/resolve.ts
361
+ function resolveRoyaltyRule(params) {
362
+ const { transactionBlock: txb, itemType, price, packageId, transferRequest, policyId } = params;
363
+ const policyObj = objArg(txb, policyId);
364
+ const [amount] = txb.moveCall({
365
+ target: `${packageId}::royalty_rule::fee_amount`,
366
+ typeArguments: [itemType],
367
+ arguments: [policyObj, objArg(txb, price ?? "")]
368
+ });
369
+ const feeCoin = txb.splitCoins(txb.gas, [amount]);
370
+ txb.moveCall({
371
+ target: `${packageId}::royalty_rule::pay`,
372
+ typeArguments: [itemType],
373
+ arguments: [policyObj, transferRequest, feeCoin]
412
374
  });
413
375
  }
414
- function attachKioskLockRule(tx, type, policy, policyCap, environment) {
415
- tx.moveCall({
416
- target: `${getRulePackageAddress(environment)}::kiosk_lock_rule::add`,
417
- typeArguments: [type],
418
- arguments: [objArg(tx, policy), objArg(tx, policyCap)]
376
+ function resolveKioskLockRule(params) {
377
+ const {
378
+ transactionBlock: txb,
379
+ packageId,
380
+ itemType,
381
+ kiosk,
382
+ kioskCap,
383
+ policyId,
384
+ purchasedItem,
385
+ transferRequest
386
+ } = params;
387
+ if (!kiosk || !kioskCap)
388
+ throw new Error("Missing Owned Kiosk or Owned Kiosk Cap");
389
+ lock(txb, itemType, kiosk, kioskCap, policyId, purchasedItem);
390
+ txb.moveCall({
391
+ target: `${packageId}::kiosk_lock_rule::prove`,
392
+ typeArguments: [itemType],
393
+ arguments: [transferRequest, objArg(txb, kiosk)]
394
+ });
395
+ }
396
+ function resolvePersonalKioskRule(params) {
397
+ const { transactionBlock: txb, packageId, itemType, kiosk, transferRequest } = params;
398
+ if (!kiosk)
399
+ throw new Error("Missing owned Kiosk.");
400
+ txb.moveCall({
401
+ target: `${packageId}::personal_kiosk_rule::prove`,
402
+ typeArguments: [itemType],
403
+ arguments: [objArg(txb, kiosk), transferRequest]
419
404
  });
420
405
  }
406
+ function resolveFloorPriceRule(params) {
407
+ const { transactionBlock: txb, packageId, itemType, policyId, transferRequest } = params;
408
+ txb.moveCall({
409
+ target: `${packageId}::floor_price_rule::prove`,
410
+ typeArguments: [itemType],
411
+ arguments: [objArg(txb, policyId), transferRequest]
412
+ });
413
+ }
414
+
415
+ // src/constants.ts
416
+ var ROYALTY_RULE_ADDRESS = {
417
+ ["testnet" /* TESTNET */]: "bd8fc1947cf119350184107a3087e2dc27efefa0dd82e25a1f699069fe81a585",
418
+ ["mainnet" /* MAINNET */]: "0x434b5bd8f6a7b05fede0ff46c6e511d71ea326ed38056e3bcd681d2d7c2a7879",
419
+ ["custom" /* CUSTOM */]: ""
420
+ };
421
+ var KIOSK_LOCK_RULE_ADDRESS = {
422
+ ["testnet" /* TESTNET */]: "bd8fc1947cf119350184107a3087e2dc27efefa0dd82e25a1f699069fe81a585",
423
+ ["mainnet" /* MAINNET */]: "0x434b5bd8f6a7b05fede0ff46c6e511d71ea326ed38056e3bcd681d2d7c2a7879",
424
+ ["custom" /* CUSTOM */]: ""
425
+ };
426
+ var FLOOR_PRICE_RULE_ADDRESS = {
427
+ ["testnet" /* TESTNET */]: "0x06f6bdd3f2e2e759d8a4b9c252f379f7a05e72dfe4c0b9311cdac27b8eb791b1",
428
+ ["mainnet" /* MAINNET */]: "0x34cc6762780f4f6f153c924c0680cfe2a1fb4601e7d33cc28a92297b62de1e0e",
429
+ ["custom" /* CUSTOM */]: ""
430
+ };
431
+ var PERSONAL_KIOSK_RULE_ADDRESS = {
432
+ ["testnet" /* TESTNET */]: "0x06f6bdd3f2e2e759d8a4b9c252f379f7a05e72dfe4c0b9311cdac27b8eb791b1",
433
+ ["mainnet" /* MAINNET */]: "0x0cb4bcc0560340eb1a1b929cabe56b33fc6449820ec8c1980d69bb98b649b802",
434
+ ["custom" /* CUSTOM */]: ""
435
+ };
436
+ function getBaseRules({
437
+ royaltyRulePackageId,
438
+ kioskLockRulePackageId,
439
+ personalKioskRulePackageId,
440
+ floorPriceRulePackageId
441
+ }) {
442
+ const rules2 = [];
443
+ if (royaltyRulePackageId) {
444
+ rules2.push({
445
+ rule: `${royaltyRulePackageId}::royalty_rule::Rule`,
446
+ packageId: royaltyRulePackageId,
447
+ resolveRuleFunction: resolveRoyaltyRule
448
+ });
449
+ }
450
+ if (kioskLockRulePackageId) {
451
+ rules2.push({
452
+ rule: `${kioskLockRulePackageId}::kiosk_lock_rule::Rule`,
453
+ packageId: kioskLockRulePackageId,
454
+ resolveRuleFunction: resolveKioskLockRule,
455
+ hasLockingRule: true
456
+ });
457
+ }
458
+ if (personalKioskRulePackageId) {
459
+ rules2.push({
460
+ rule: `${personalKioskRulePackageId}::personal_kiosk_rule::Rule`,
461
+ packageId: personalKioskRulePackageId,
462
+ resolveRuleFunction: resolvePersonalKioskRule
463
+ });
464
+ }
465
+ if (floorPriceRulePackageId) {
466
+ rules2.push({
467
+ rule: `${floorPriceRulePackageId}::floor_price_rule::Rule`,
468
+ packageId: floorPriceRulePackageId,
469
+ resolveRuleFunction: resolveFloorPriceRule
470
+ });
471
+ }
472
+ return rules2;
473
+ }
474
+ var testnetRules = getBaseRules({
475
+ royaltyRulePackageId: ROYALTY_RULE_ADDRESS["testnet" /* TESTNET */],
476
+ kioskLockRulePackageId: KIOSK_LOCK_RULE_ADDRESS["testnet" /* TESTNET */],
477
+ personalKioskRulePackageId: PERSONAL_KIOSK_RULE_ADDRESS["testnet" /* TESTNET */],
478
+ floorPriceRulePackageId: FLOOR_PRICE_RULE_ADDRESS["testnet" /* TESTNET */]
479
+ });
480
+ var mainnetRules = getBaseRules({
481
+ royaltyRulePackageId: ROYALTY_RULE_ADDRESS["mainnet" /* MAINNET */],
482
+ kioskLockRulePackageId: KIOSK_LOCK_RULE_ADDRESS["mainnet" /* MAINNET */]
483
+ });
484
+ var rules = [...testnetRules, ...mainnetRules];
421
485
 
422
486
  // src/query/kiosk.ts
423
487
  import { isValidSuiAddress } from "@mysten/sui.js/utils";
@@ -425,20 +489,22 @@ async function fetchKiosk(client, kioskId, pagination, options) {
425
489
  const data = await getAllDynamicFields(client, kioskId, pagination);
426
490
  const listings = [];
427
491
  const lockedItemIds = [];
428
- const kioskData = extractKioskData(data, listings, lockedItemIds);
429
- const [kiosk, listingObjects] = await Promise.all([
492
+ const kioskData = extractKioskData(data, listings, lockedItemIds, kioskId);
493
+ const [kiosk, listingObjects, items] = await Promise.all([
430
494
  options.withKioskFields ? getKioskObject(client, kioskId) : Promise.resolve(void 0),
431
- options.withListingPrices ? client.multiGetObjects({
432
- ids: kioskData.listingIds,
433
- options: {
434
- showContent: true
435
- }
436
- }) : Promise.resolve([])
495
+ options.withListingPrices ? getAllObjects(client, kioskData.listingIds, {
496
+ showContent: true
497
+ }) : Promise.resolve([]),
498
+ options.withObjects ? getAllObjects(client, kioskData.itemIds, options.objectOptions || { showDisplay: true }) : Promise.resolve([])
437
499
  ]);
438
500
  if (options.withKioskFields)
439
501
  kioskData.kiosk = kiosk;
440
502
  attachListingsAndPrices(kioskData, listings, listingObjects);
441
503
  attachLockedItems(kioskData, lockedItemIds);
504
+ attachObjects(
505
+ kioskData,
506
+ items.filter((x) => !!x.data).map((x) => x.data)
507
+ );
442
508
  return {
443
509
  data: kioskData,
444
510
  nextCursor: null,
@@ -453,23 +519,37 @@ async function getOwnedKiosks(client, address, options) {
453
519
  kioskOwnerCaps: [],
454
520
  kioskIds: []
455
521
  };
522
+ const filter = {
523
+ MatchAny: [
524
+ {
525
+ StructType: KIOSK_OWNER_CAP
526
+ }
527
+ ]
528
+ };
529
+ if (options?.personalKioskType) {
530
+ filter.MatchAny.push({
531
+ StructType: options.personalKioskType
532
+ });
533
+ }
456
534
  const { data, hasNextPage, nextCursor } = await client.getOwnedObjects({
457
535
  owner: address,
458
- filter: { StructType: KIOSK_OWNER_CAP },
536
+ filter,
459
537
  options: {
460
- showContent: true
538
+ showContent: true,
539
+ showType: true
461
540
  },
462
541
  ...options?.pagination || {}
463
542
  });
464
543
  const kioskIdList = data?.map((x) => {
465
544
  const fields = x.data?.content?.dataType === "moveObject" ? x.data.content.fields : null;
466
- return fields?.for;
545
+ return fields?.cap ? fields?.cap?.fields?.for : fields?.for;
467
546
  });
468
547
  const filteredData = data.filter((x) => "data" in x).map((x) => x.data);
469
548
  return {
470
549
  nextCursor,
471
550
  hasNextPage,
472
551
  kioskOwnerCaps: filteredData.map((x, idx) => ({
552
+ isPersonal: x.type !== KIOSK_OWNER_CAP,
473
553
  digest: x.digest,
474
554
  version: x.version,
475
555
  objectId: x.objectId,
@@ -480,6 +560,7 @@ async function getOwnedKiosks(client, address, options) {
480
560
  }
481
561
 
482
562
  // src/query/transfer-policy.ts
563
+ import { isValidSuiAddress as isValidSuiAddress2 } from "@mysten/sui.js/utils";
483
564
  async function queryTransferPolicy(client, type) {
484
565
  const { data } = await client.queryEvents({
485
566
  query: {
@@ -495,7 +576,7 @@ async function queryTransferPolicy(client, type) {
495
576
  if (!policy || !policy.bcs || !("bcsBytes" in policy.bcs)) {
496
577
  throw new Error(`Invalid policy: ${policy?.objectId}, expected object, got package`);
497
578
  }
498
- let parsed = bcs.de(TRANSFER_POLICY_TYPE, policy.bcs.bcsBytes, "base64");
579
+ const parsed = bcs.de(TRANSFER_POLICY_TYPE, policy.bcs.bcsBytes, "base64");
499
580
  return {
500
581
  id: policy?.objectId,
501
582
  type: `${TRANSFER_POLICY_TYPE}<${type}>`,
@@ -505,60 +586,988 @@ async function queryTransferPolicy(client, type) {
505
586
  };
506
587
  });
507
588
  }
589
+ async function queryTransferPolicyCapsByType(client, address, type) {
590
+ if (!isValidSuiAddress2(address))
591
+ return [];
592
+ const filter = {
593
+ MatchAll: [
594
+ {
595
+ StructType: `${TRANSFER_POLICY_CAP_TYPE}<${type}>`
596
+ }
597
+ ]
598
+ };
599
+ const data = await getAllOwnedObjects({
600
+ client,
601
+ filter,
602
+ owner: address
603
+ });
604
+ return data.map((item) => parseTransferPolicyCapObject(item)).filter((item) => !!item);
605
+ }
606
+ async function queryOwnedTransferPolicies(client, address) {
607
+ if (!isValidSuiAddress2(address))
608
+ return;
609
+ const filter = {
610
+ MatchAll: [
611
+ {
612
+ MoveModule: {
613
+ module: "transfer_policy",
614
+ package: "0x2"
615
+ }
616
+ }
617
+ ]
618
+ };
619
+ const data = await getAllOwnedObjects({ client, owner: address, filter });
620
+ const policies = [];
621
+ for (const item of data) {
622
+ const data2 = parseTransferPolicyCapObject(item);
623
+ if (data2)
624
+ policies.push(data2);
625
+ }
626
+ return policies;
627
+ }
628
+
629
+ // src/client/kiosk-client.ts
630
+ var KioskClient = class {
631
+ constructor(options) {
632
+ this.client = options.client;
633
+ this.network = options.network;
634
+ this.rules = rules;
635
+ this.packageIds = options.packageIds;
636
+ if (options.packageIds)
637
+ this.rules.push(...getBaseRules(options.packageIds));
638
+ }
639
+ /// Querying
640
+ /**
641
+ * Get an addresses's owned kiosks.
642
+ * @param address The address for which we want to retrieve the kiosks.
643
+ * @returns An Object containing all the `kioskOwnerCap` objects as well as the kioskIds.
644
+ */
645
+ async getOwnedKiosks({ address }) {
646
+ const personalPackageId = this.packageIds?.personalKioskRulePackageId || PERSONAL_KIOSK_RULE_ADDRESS[this.network];
647
+ return getOwnedKiosks(this.client, address, {
648
+ personalKioskType: personalPackageId ? `${personalPackageId}::personal_kiosk::PersonalKioskCap` : ""
649
+ });
650
+ }
651
+ /**
652
+ * Fetches the kiosk contents.
653
+ * @param kioskId The ID of the kiosk to fetch.
654
+ * @param options Optioal
655
+ * @returns
656
+ */
657
+ async getKiosk({ id, options }) {
658
+ return (await fetchKiosk(
659
+ this.client,
660
+ id,
661
+ {
662
+ limit: 1e3
663
+ },
664
+ options || {}
665
+ )).data;
666
+ }
667
+ /**
668
+ * Query the Transfer Policy(ies) for type `T`.
669
+ * @param type The Type we're querying for (E.g `0xMyAddress::hero::Hero`)
670
+ */
671
+ async getTransferPolicies({ type }) {
672
+ return queryTransferPolicy(this.client, type);
673
+ }
674
+ /**
675
+ * Query all the owned transfer policies for an address.
676
+ * Returns `TransferPolicyCap` which uncludes `policyId, policyCapId, type`.
677
+ * @param address The address we're searching the owned transfer policies for.
678
+ */
679
+ async getOwnedTransferPolicies({ address }) {
680
+ return queryOwnedTransferPolicies(this.client, address);
681
+ }
682
+ /**
683
+ * Query the Transfer Policy Cap for type `T`, owned by `address`
684
+ * @param type The Type `T` for the object
685
+ * @param address The address that owns the cap.
686
+ */
687
+ async getOwnedTransferPoliciesByType({ type, address }) {
688
+ return queryTransferPolicyCapsByType(this.client, address, type);
689
+ }
690
+ // Someone would just have to create a `kiosk-client.ts` file in their project, initialize a KioskClient
691
+ // and call the `addRuleResolver` function. Each rule has a `resolve` function.
692
+ // The resolve function is automatically called on `purchaseAndResolve` function call.
693
+ addRuleResolver(rule) {
694
+ if (this.rules.find((x) => x.rule === rule.rule))
695
+ throw new Error(`Rule ${rule.rule} resolver already exists.`);
696
+ this.rules.push(rule);
697
+ }
698
+ /**
699
+ * A convenient helper to get the packageIds for our supported ruleset,
700
+ * based on `kioskClient` configuration.
701
+ */
702
+ getRulePackageId(rule) {
703
+ const rules2 = this.packageIds || {};
704
+ const network = this.network;
705
+ if (!rules2[rule] && network !== "mainnet" /* MAINNET */ && network !== "testnet" /* TESTNET */) {
706
+ throw new Error(`Missing packageId for rule ${rule}`);
707
+ }
708
+ switch (rule) {
709
+ case "kioskLockRulePackageId":
710
+ return rules2[rule] || KIOSK_LOCK_RULE_ADDRESS[network];
711
+ case "royaltyRulePackageId":
712
+ return rules2[rule] || ROYALTY_RULE_ADDRESS[network];
713
+ case "personalKioskRulePackageId":
714
+ return rules2[rule] || PERSONAL_KIOSK_RULE_ADDRESS[network];
715
+ case "floorPriceRulePackageId":
716
+ return rules2[rule] || FLOOR_PRICE_RULE_ADDRESS[network];
717
+ }
718
+ }
719
+ };
720
+
721
+ // src/tx/rules/attach.ts
722
+ function attachKioskLockRuleTx(tx, type, policy, policyCap, packageId) {
723
+ tx.moveCall({
724
+ target: `${packageId}::kiosk_lock_rule::add`,
725
+ typeArguments: [type],
726
+ arguments: [objArg(tx, policy), objArg(tx, policyCap)]
727
+ });
728
+ }
729
+ function attachRoyaltyRuleTx(tx, type, policy, policyCap, percentageBps, minAmount, packageId) {
730
+ if (Number(percentageBps) < 0 || Number(percentageBps) > 1e4)
731
+ throw new Error("Invalid basis point percentage. Use a value between [0,10000].");
732
+ tx.moveCall({
733
+ target: `${packageId}::royalty_rule::add`,
734
+ typeArguments: [type],
735
+ arguments: [
736
+ objArg(tx, policy),
737
+ objArg(tx, policyCap),
738
+ tx.pure.u16(Number(percentageBps)),
739
+ tx.pure.u64(minAmount)
740
+ ]
741
+ });
742
+ }
743
+ function attachPersonalKioskRuleTx(tx, type, policy, policyCap, packageId) {
744
+ tx.moveCall({
745
+ target: `${packageId}::personal_kiosk_rule::add`,
746
+ typeArguments: [type],
747
+ arguments: [objArg(tx, policy), objArg(tx, policyCap)]
748
+ });
749
+ }
750
+ function attachFloorPriceRuleTx(tx, type, policy, policyCap, minPrice, packageId) {
751
+ tx.moveCall({
752
+ target: `${packageId}::floor_price_rule::add`,
753
+ typeArguments: [type],
754
+ arguments: [objArg(tx, policy), objArg(tx, policyCap), tx.pure.u64(minPrice)]
755
+ });
756
+ }
757
+
758
+ // src/tx/transfer-policy.ts
759
+ import { bcs as bcs3 } from "@mysten/sui.js/bcs";
760
+ function createTransferPolicy(tx, itemType, publisher) {
761
+ const [transferPolicy, transferPolicyCap] = createTransferPolicyWithoutSharing(
762
+ tx,
763
+ itemType,
764
+ publisher
765
+ );
766
+ shareTransferPolicy(tx, itemType, transferPolicy);
767
+ return transferPolicyCap;
768
+ }
769
+ function createTransferPolicyWithoutSharing(tx, itemType, publisher) {
770
+ const [transferPolicy, transferPolicyCap] = tx.moveCall({
771
+ target: `${TRANSFER_POLICY_MODULE}::new`,
772
+ typeArguments: [itemType],
773
+ arguments: [objArg(tx, publisher)]
774
+ });
775
+ return [transferPolicy, transferPolicyCap];
776
+ }
777
+ function shareTransferPolicy(tx, itemType, transferPolicy) {
778
+ tx.moveCall({
779
+ target: `0x2::transfer::public_share_object`,
780
+ typeArguments: [`${TRANSFER_POLICY_TYPE}<${itemType}>`],
781
+ arguments: [transferPolicy]
782
+ });
783
+ }
784
+ function withdrawFromPolicy(tx, itemType, policy, policyCap, amount) {
785
+ const amountArg = bcs3.option(bcs3.u64()).serialize(amount);
786
+ const [profits] = tx.moveCall({
787
+ target: `${TRANSFER_POLICY_MODULE}::withdraw`,
788
+ typeArguments: [itemType],
789
+ arguments: [objArg(tx, policy), objArg(tx, policyCap), amountArg]
790
+ });
791
+ return profits;
792
+ }
793
+ function confirmRequest(tx, itemType, policy, request) {
794
+ tx.moveCall({
795
+ target: `${TRANSFER_POLICY_MODULE}::confirm_request`,
796
+ typeArguments: [itemType],
797
+ arguments: [objArg(tx, policy), request]
798
+ });
799
+ }
800
+ function removeTransferPolicyRule(tx, itemType, ruleType, configType, policy, policyCap) {
801
+ tx.moveCall({
802
+ target: `${TRANSFER_POLICY_MODULE}::remove_rule`,
803
+ typeArguments: [itemType, ruleType, configType],
804
+ arguments: [objArg(tx, policy), objArg(tx, policyCap)]
805
+ });
806
+ }
807
+
808
+ // src/client/tp-transaction.ts
809
+ var _validateInputs, validateInputs_fn, _setup, setup_fn;
810
+ var TransferPolicyTransaction = class {
811
+ constructor({ kioskClient, transactionBlock, cap }) {
812
+ // Internal function that that the policy's Id + Cap + type have been set.
813
+ __privateAdd(this, _validateInputs);
814
+ /**
815
+ * Setup the state of the TransferPolicyTransaction.
816
+ */
817
+ __privateAdd(this, _setup);
818
+ this.kioskClient = kioskClient;
819
+ this.transactionBlock = transactionBlock;
820
+ if (cap)
821
+ this.setCap(cap);
822
+ }
823
+ /**
824
+ * A function to create a new transfer policy.
825
+ * Checks if there's already an existing transfer policy to prevent
826
+ * double transfer polciy mistakes.
827
+ * There's an optional `skipCheck` flag that will just create the policy
828
+ * without checking
829
+ *
830
+ * @param type The Type (`T`) for which we're creating the transfer policy.
831
+ * @param publisher The Publisher Object Id.
832
+ * @param address Address to save the `TransferPolicyCap` object to.
833
+ * @param skipCheck (Optional) skip checking if a transfer policy already exists
834
+ */
835
+ async createAndShare({
836
+ type,
837
+ publisher,
838
+ address,
839
+ skipCheck
840
+ }) {
841
+ if (!skipCheck) {
842
+ const policies = await this.kioskClient.getTransferPolicies({ type });
843
+ if (policies.length > 0)
844
+ throw new Error("There's already transfer policy for this Type.");
845
+ }
846
+ const cap = createTransferPolicy(this.transactionBlock, type, publisher);
847
+ this.transactionBlock.transferObjects([cap], this.transactionBlock.pure.address(address));
848
+ }
849
+ /**
850
+ * A convenient function to create a Transfer Policy and attach some rules
851
+ * before sharing it (so you can prepare it in a single PTB)
852
+ * @param type The Type (`T`) for which we're creating the transfer policy.
853
+ * @param publisher The Publisher Object Id.
854
+ * @param address Address to save the `TransferPolicyCap` object to.
855
+ * @param skipCheck (Optional) skip checking if a transfer policy already exists
856
+ */
857
+ async create({
858
+ type,
859
+ publisher,
860
+ skipCheck
861
+ }) {
862
+ if (!skipCheck) {
863
+ const policies = await this.kioskClient.getTransferPolicies({ type });
864
+ if (policies.length > 0)
865
+ throw new Error("There's already transfer policy for this Type.");
866
+ }
867
+ const [policy, policyCap] = createTransferPolicyWithoutSharing(
868
+ this.transactionBlock,
869
+ type,
870
+ publisher
871
+ );
872
+ __privateMethod(this, _setup, setup_fn).call(this, policy, policyCap, type);
873
+ return this;
874
+ }
875
+ /**
876
+ * This can be called after calling the `create` function to share the `TransferPolicy`,
877
+ * and transfer the `TransferPolicyCap` to the specified address
878
+ *
879
+ * @param address The address to transfer the `TransferPolicyCap`
880
+ */
881
+ shareAndTransferCap(address) {
882
+ if (!this.type || !this.policyCap || !this.policy)
883
+ throw new Error("This function can only be called after `transferPolicyManager.create`");
884
+ shareTransferPolicy(this.transactionBlock, this.type, this.policy);
885
+ this.transactionBlock.transferObjects(
886
+ [this.policyCap],
887
+ this.transactionBlock.pure.address(address)
888
+ );
889
+ }
890
+ /**
891
+ * Setup the TransferPolicy by passing a `cap` returned from `kioskClient.getOwnedTransferPolicies` or
892
+ * `kioskClient.getOwnedTransferPoliciesByType`.
893
+ * @param policyCapId The `TransferPolicyCap`
894
+ */
895
+ setCap({ policyId, policyCapId, type }) {
896
+ return __privateMethod(this, _setup, setup_fn).call(this, policyId, policyCapId, type);
897
+ }
898
+ /**
899
+ * Withdraw from the transfer policy's profits.
900
+ * @param address Address to transfer the profits to.
901
+ * @param amount (Optional) amount parameter. Will withdraw all profits if the amount is not specified.
902
+ */
903
+ withdraw(address, amount) {
904
+ __privateMethod(this, _validateInputs, validateInputs_fn).call(this);
905
+ const coin = withdrawFromPolicy(
906
+ this.transactionBlock,
907
+ this.type,
908
+ this.policy,
909
+ this.policyCap,
910
+ amount
911
+ );
912
+ this.transactionBlock.transferObjects([coin], this.transactionBlock.pure.address(address));
913
+ return this;
914
+ }
915
+ /**
916
+ * Adds the Kiosk Royalty rule to the Transfer Policy.
917
+ * You can pass the percentage, as well as a minimum amount.
918
+ * The royalty that will be paid is the MAX(percentage, minAmount).
919
+ * You can pass 0 in either value if you want only percentage royalty, or a fixed amount fee.
920
+ * (but you should define at least one of them for the rule to make sense).
921
+ *
922
+ * @param percentageBps The royalty percentage in basis points. Use `percentageToBasisPoints` helper to convert from percentage [0,100].
923
+ * @param minAmount The minimum royalty amount per request in MIST.
924
+ */
925
+ addRoyaltyRule(percentageBps, minAmount) {
926
+ __privateMethod(this, _validateInputs, validateInputs_fn).call(this);
927
+ attachRoyaltyRuleTx(
928
+ this.transactionBlock,
929
+ this.type,
930
+ this.policy,
931
+ this.policyCap,
932
+ percentageBps,
933
+ minAmount,
934
+ this.kioskClient.getRulePackageId("royaltyRulePackageId")
935
+ );
936
+ return this;
937
+ }
938
+ /**
939
+ * Adds the Kiosk Lock Rule to the Transfer Policy.
940
+ * This Rule forces buyer to lock the item in the kiosk, preserving strong royalties.
941
+ */
942
+ addLockRule() {
943
+ __privateMethod(this, _validateInputs, validateInputs_fn).call(this);
944
+ attachKioskLockRuleTx(
945
+ this.transactionBlock,
946
+ this.type,
947
+ this.policy,
948
+ this.policyCap,
949
+ this.kioskClient.getRulePackageId("kioskLockRulePackageId")
950
+ );
951
+ return this;
952
+ }
953
+ /**
954
+ * Attaches the Personal Kiosk Rule, making a purchase valid only for `SoulBound` kiosks.
955
+ */
956
+ addPersonalKioskRule() {
957
+ __privateMethod(this, _validateInputs, validateInputs_fn).call(this);
958
+ attachPersonalKioskRuleTx(
959
+ this.transactionBlock,
960
+ this.type,
961
+ this.policy,
962
+ this.policyCap,
963
+ this.kioskClient.getRulePackageId("personalKioskRulePackageId")
964
+ );
965
+ return this;
966
+ }
967
+ /**
968
+ * A function to add the floor price rule to a transfer policy.
969
+ * @param minPrice The minimum price in MIST.
970
+ */
971
+ addFloorPriceRule(minPrice) {
972
+ __privateMethod(this, _validateInputs, validateInputs_fn).call(this);
973
+ attachFloorPriceRuleTx(
974
+ this.transactionBlock,
975
+ this.type,
976
+ this.policy,
977
+ this.policyCap,
978
+ minPrice,
979
+ this.kioskClient.getRulePackageId("floorPriceRulePackageId")
980
+ );
981
+ return this;
982
+ }
983
+ /**
984
+ * Generic helper to remove a rule, not from the SDK's base ruleset.
985
+ * @param ruleType The Rule Type
986
+ * @param configType The Config Type
987
+ */
988
+ removeRule({ ruleType, configType }) {
989
+ __privateMethod(this, _validateInputs, validateInputs_fn).call(this);
990
+ removeTransferPolicyRule(
991
+ this.transactionBlock,
992
+ this.type,
993
+ ruleType,
994
+ configType,
995
+ this.policy,
996
+ this.policyCap
997
+ );
998
+ }
999
+ /**
1000
+ * Removes the lock rule.
1001
+ */
1002
+ removeLockRule() {
1003
+ __privateMethod(this, _validateInputs, validateInputs_fn).call(this);
1004
+ const packageId = this.kioskClient.getRulePackageId("kioskLockRulePackageId");
1005
+ removeTransferPolicyRule(
1006
+ this.transactionBlock,
1007
+ this.type,
1008
+ `${packageId}::kiosk_lock_rule::Rule`,
1009
+ `${packageId}::kiosk_lock_rule::Config`,
1010
+ this.policy,
1011
+ this.policyCap
1012
+ );
1013
+ return this;
1014
+ }
1015
+ /**
1016
+ * Removes the Royalty rule
1017
+ */
1018
+ removeRoyaltyRule() {
1019
+ __privateMethod(this, _validateInputs, validateInputs_fn).call(this);
1020
+ const packageId = this.kioskClient.getRulePackageId("royaltyRulePackageId");
1021
+ removeTransferPolicyRule(
1022
+ this.transactionBlock,
1023
+ this.type,
1024
+ `${packageId}::royalty_rule::Rule`,
1025
+ `${packageId}::royalty_rule::Config`,
1026
+ this.policy,
1027
+ this.policyCap
1028
+ );
1029
+ return this;
1030
+ }
1031
+ removePersonalKioskRule() {
1032
+ __privateMethod(this, _validateInputs, validateInputs_fn).call(this);
1033
+ const packageId = this.kioskClient.getRulePackageId("personalKioskRulePackageId");
1034
+ removeTransferPolicyRule(
1035
+ this.transactionBlock,
1036
+ this.type,
1037
+ `${packageId}::personal_kiosk_rule::Rule`,
1038
+ `bool`,
1039
+ this.policy,
1040
+ this.policyCap
1041
+ );
1042
+ return this;
1043
+ }
1044
+ removeFloorPriceRule() {
1045
+ __privateMethod(this, _validateInputs, validateInputs_fn).call(this);
1046
+ const packageId = this.kioskClient.getRulePackageId("floorPriceRulePackageId");
1047
+ removeTransferPolicyRule(
1048
+ this.transactionBlock,
1049
+ this.type,
1050
+ `${packageId}::floor_price_rule::Rule`,
1051
+ `${packageId}::floor_price_rule::Config`,
1052
+ this.policy,
1053
+ this.policyCap
1054
+ );
1055
+ return this;
1056
+ }
1057
+ getPolicy() {
1058
+ if (!this.policy)
1059
+ throw new Error("Policy not set.");
1060
+ return this.policy;
1061
+ }
1062
+ getPolicyCap() {
1063
+ if (!this.policyCap)
1064
+ throw new Error("Transfer Policy Cap not set.");
1065
+ return this.policyCap;
1066
+ }
1067
+ };
1068
+ _validateInputs = new WeakSet();
1069
+ validateInputs_fn = function() {
1070
+ const genericErrorMessage = `Please use 'setCap()' to setup the TransferPolicy.`;
1071
+ if (!this.policy)
1072
+ throw new Error(`${genericErrorMessage} Missing: Transfer Policy Object.`);
1073
+ if (!this.policyCap)
1074
+ throw new Error(`${genericErrorMessage} Missing: TransferPolicyCap Object ID`);
1075
+ if (!this.type)
1076
+ throw new Error(
1077
+ `${genericErrorMessage} Missing: Transfer Policy object type (e.g. {packageId}::item::Item)`
1078
+ );
1079
+ };
1080
+ _setup = new WeakSet();
1081
+ setup_fn = function(policyId, policyCap, type) {
1082
+ this.policy = policyId;
1083
+ this.policyCap = policyCap;
1084
+ this.type = type;
1085
+ return this;
1086
+ };
1087
+
1088
+ // src/tx/personal-kiosk.ts
1089
+ function convertToPersonalTx(tx, kiosk, kioskOwnerCap, packageId) {
1090
+ const personalKioskCap = tx.moveCall({
1091
+ target: `${packageId}::personal_kiosk::new`,
1092
+ arguments: [objArg(tx, kiosk), objArg(tx, kioskOwnerCap)]
1093
+ });
1094
+ return personalKioskCap;
1095
+ }
1096
+ function transferPersonalCapTx(tx, personalKioskCap, packageId) {
1097
+ tx.moveCall({
1098
+ target: `${packageId}::personal_kiosk::transfer_to_sender`,
1099
+ arguments: [personalKioskCap]
1100
+ });
1101
+ }
1102
+
1103
+ // src/client/kiosk-transaction.ts
1104
+ var _pendingShare, _pendingTransfer, _promise, _personalCap, _finalized, _borrowFromPersonalCap, borrowFromPersonalCap_fn, _setPendingStatuses, setPendingStatuses_fn, _validateKioskIsSet, validateKioskIsSet_fn, _validateFinalizedStatus, validateFinalizedStatus_fn;
1105
+ var KioskTransaction = class {
1106
+ constructor({ transactionBlock, kioskClient, cap }) {
1107
+ /**
1108
+ * A function to borrow from `personalCap`.
1109
+ */
1110
+ __privateAdd(this, _borrowFromPersonalCap);
1111
+ __privateAdd(this, _setPendingStatuses);
1112
+ __privateAdd(this, _validateKioskIsSet);
1113
+ // Validates that `finalize`
1114
+ __privateAdd(this, _validateFinalizedStatus);
1115
+ // If we're pending `share` of a new kiosk, `finalize()` will share it.
1116
+ __privateAdd(this, _pendingShare, void 0);
1117
+ // If we're pending transferring of the cap, `finalize()` will either error or transfer the cap if it's a new personal.
1118
+ __privateAdd(this, _pendingTransfer, void 0);
1119
+ // The promise that the personalCap will be returned on `finalize()`.
1120
+ __privateAdd(this, _promise, void 0);
1121
+ // The personal kiosk argument.
1122
+ __privateAdd(this, _personalCap, void 0);
1123
+ // A flag that checks whether kiosk TX is finalized.
1124
+ __privateAdd(this, _finalized, false);
1125
+ this.transactionBlock = transactionBlock;
1126
+ this.kioskClient = kioskClient;
1127
+ if (cap)
1128
+ this.setCap(cap);
1129
+ }
1130
+ /**
1131
+ * Creates a kiosk and saves `kiosk` and `kioskOwnerCap` in state.
1132
+ * Helpful if we want to chain some actions before sharing + transferring the cap to the specified address.
1133
+ * @param borrow If true, the `kioskOwnerCap` is borrowed from the `PersonalKioskCap` to be used in next transactions.
1134
+ */
1135
+ create() {
1136
+ __privateMethod(this, _validateFinalizedStatus, validateFinalizedStatus_fn).call(this);
1137
+ __privateMethod(this, _setPendingStatuses, setPendingStatuses_fn).call(this, {
1138
+ share: true,
1139
+ transfer: true
1140
+ });
1141
+ const [kiosk, cap] = createKiosk(this.transactionBlock);
1142
+ this.kiosk = kiosk;
1143
+ this.kioskCap = cap;
1144
+ return this;
1145
+ }
1146
+ /**
1147
+ * Creates a personal kiosk & shares it.
1148
+ * The `PersonalKioskCap` is transferred to the signer.
1149
+ * @param borrow If true, the `kioskOwnerCap` is borrowed from the `PersonalKioskCap` to be used in next transactions.
1150
+ */
1151
+ createPersonal(borrow) {
1152
+ __privateSet(this, _pendingShare, true);
1153
+ return this.create().convertToPersonal(borrow);
1154
+ }
1155
+ /**
1156
+ * Converts a kiosk to a Personal (Soulbound) Kiosk.
1157
+ * Requires initialization by either calling `ktxb.create()` or `ktxb.setCap()`.
1158
+ */
1159
+ convertToPersonal(borrow) {
1160
+ __privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
1161
+ const cap = convertToPersonalTx(
1162
+ this.transactionBlock,
1163
+ this.kiosk,
1164
+ this.kioskCap,
1165
+ this.kioskClient.getRulePackageId("personalKioskRulePackageId")
1166
+ );
1167
+ if (borrow)
1168
+ __privateMethod(this, _borrowFromPersonalCap, borrowFromPersonalCap_fn).call(this, cap);
1169
+ else
1170
+ __privateSet(this, _personalCap, cap);
1171
+ __privateMethod(this, _setPendingStatuses, setPendingStatuses_fn).call(this, { transfer: true });
1172
+ return this;
1173
+ }
1174
+ /**
1175
+ * Single function way to create a kiosk, share it and transfer the cap to the specified address.
1176
+ */
1177
+ createAndShare(address) {
1178
+ __privateMethod(this, _validateFinalizedStatus, validateFinalizedStatus_fn).call(this);
1179
+ const cap = createKioskAndShare(this.transactionBlock);
1180
+ this.transactionBlock.transferObjects([cap], this.transactionBlock.pure.address(address));
1181
+ }
1182
+ /**
1183
+ * Shares the kiosk.
1184
+ */
1185
+ share() {
1186
+ __privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
1187
+ __privateMethod(this, _setPendingStatuses, setPendingStatuses_fn).call(this, { share: false });
1188
+ shareKiosk(this.transactionBlock, this.kiosk);
1189
+ }
1190
+ /**
1191
+ * Should be called only after `create` is called.
1192
+ * It shares the kiosk & transfers the cap to the specified address.
1193
+ */
1194
+ shareAndTransferCap(address) {
1195
+ if (__privateGet(this, _personalCap))
1196
+ throw new Error("You can only call `shareAndTransferCap` on a non-personal kiosk.");
1197
+ __privateMethod(this, _setPendingStatuses, setPendingStatuses_fn).call(this, { transfer: false });
1198
+ this.share();
1199
+ this.transactionBlock.transferObjects(
1200
+ [this.kioskCap],
1201
+ this.transactionBlock.pure.address(address)
1202
+ );
1203
+ }
1204
+ /**
1205
+ * A function to borrow an item from a kiosk & execute any function with it.
1206
+ * Example: You could borrow a Fren out of a kiosk, attach an accessory (or mix), and return it.
1207
+ */
1208
+ borrowTx({ itemType, itemId }, callback) {
1209
+ __privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
1210
+ const [itemObj, promise] = borrowValue(
1211
+ this.transactionBlock,
1212
+ itemType,
1213
+ this.kiosk,
1214
+ this.kioskCap,
1215
+ itemId
1216
+ );
1217
+ callback(itemObj);
1218
+ this.return({ itemType, item: itemObj, promise });
1219
+ }
1220
+ /**
1221
+ * Borrows an item from the kiosk.
1222
+ * This will fail if the item is listed for sale.
1223
+ *
1224
+ * Requires calling `return`.
1225
+ */
1226
+ borrow({ itemType, itemId }) {
1227
+ __privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
1228
+ const [itemObj, promise] = borrowValue(
1229
+ this.transactionBlock,
1230
+ itemType,
1231
+ this.kiosk,
1232
+ this.kioskCap,
1233
+ itemId
1234
+ );
1235
+ return [itemObj, promise];
1236
+ }
1237
+ /**
1238
+ * Returns the item back to the kiosk.
1239
+ * Accepts the parameters returned from the `borrow` function.
1240
+ */
1241
+ return({ itemType, item, promise }) {
1242
+ __privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
1243
+ returnValue(this.transactionBlock, itemType, this.kiosk, item, promise);
1244
+ return this;
1245
+ }
1246
+ /**
1247
+ * A function to withdraw from kiosk
1248
+ * @param address Where to trasnfer the coin.
1249
+ * @param amount The amount we aim to withdraw.
1250
+ */
1251
+ withdraw(address, amount) {
1252
+ __privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
1253
+ const coin = withdrawFromKiosk(
1254
+ this.transactionBlock,
1255
+ this.kiosk,
1256
+ this.kioskCap,
1257
+ amount
1258
+ );
1259
+ this.transactionBlock.transferObjects([coin], this.transactionBlock.pure.address(address));
1260
+ return this;
1261
+ }
1262
+ /**
1263
+ * A function to place an item in the kiosk.
1264
+ * @param itemType The type `T` of the item
1265
+ * @param item The ID or Transaction Argument of the item
1266
+ */
1267
+ place({ itemType, item }) {
1268
+ __privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
1269
+ place(this.transactionBlock, itemType, this.kiosk, this.kioskCap, item);
1270
+ return this;
1271
+ }
1272
+ /**
1273
+ * A function to place an item in the kiosk and list it for sale in one transaction.
1274
+ * @param itemType The type `T` of the item
1275
+ * @param item The ID or Transaction Argument of the item
1276
+ * @param price The price in MIST
1277
+ */
1278
+ placeAndList({ itemType, item, price }) {
1279
+ __privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
1280
+ placeAndList(this.transactionBlock, itemType, this.kiosk, this.kioskCap, item, price);
1281
+ return this;
1282
+ }
1283
+ /**
1284
+ * A function to list an item in the kiosk.
1285
+ * @param itemType The type `T` of the item
1286
+ * @param itemId The ID of the item
1287
+ * @param price The price in MIST
1288
+ */
1289
+ list({ itemType, itemId, price }) {
1290
+ __privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
1291
+ list(this.transactionBlock, itemType, this.kiosk, this.kioskCap, itemId, price);
1292
+ return this;
1293
+ }
1294
+ /**
1295
+ * A function to delist an item from the kiosk.
1296
+ * @param itemType The type `T` of the item
1297
+ * @param itemId The ID of the item
1298
+ */
1299
+ delist({ itemType, itemId }) {
1300
+ __privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
1301
+ delist(this.transactionBlock, itemType, this.kiosk, this.kioskCap, itemId);
1302
+ return this;
1303
+ }
1304
+ /**
1305
+ * A function to take an item from the kiosk. The transaction won't succeed if the item is listed or locked.
1306
+
1307
+ * @param itemType The type `T` of the item
1308
+ * @param itemId The ID of the item
1309
+ */
1310
+ take({ itemType, itemId }) {
1311
+ __privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
1312
+ return take(this.transactionBlock, itemType, this.kiosk, this.kioskCap, itemId);
1313
+ }
1314
+ /**
1315
+ * Transfer a non-locked/non-listed item to an address.
1316
+ *
1317
+ * @param itemType The type `T` of the item
1318
+ * @param itemId The ID of the item
1319
+ * @param address The destination address
1320
+ */
1321
+ transfer({ itemType, itemId, address }) {
1322
+ __privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
1323
+ const item = this.take({ itemType, itemId });
1324
+ this.transactionBlock.transferObjects([item], this.transactionBlock.pure.address(address));
1325
+ return this;
1326
+ }
1327
+ /**
1328
+ * A function to take lock an item in the kiosk.
1329
+
1330
+ * @param itemType The type `T` of the item
1331
+ * @param itemId The ID of the item
1332
+ * @param policy The Policy ID or Transaction Argument for item T
1333
+ */
1334
+ lock({ itemType, itemId, policy }) {
1335
+ __privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
1336
+ lock(this.transactionBlock, itemType, this.kiosk, this.kioskCap, policy, itemId);
1337
+ return this;
1338
+ }
1339
+ /**
1340
+ * Purchase an item from a seller's kiosk.
1341
+ * Returns [item, transferRequest]
1342
+ * Can be called like: `const [item, transferRequest] = kioskTx.purchase({...})`
1343
+ * @param itemType The type `T` of the item
1344
+ * @param itemId The ID of the item
1345
+ * @param price The price in MIST
1346
+ * @param sellerKiosk The kiosk which is selling the item. Can be an id or an object argument.
1347
+ */
1348
+ purchase({
1349
+ itemType,
1350
+ itemId,
1351
+ price,
1352
+ sellerKiosk
1353
+ }) {
1354
+ const coin = this.transactionBlock.splitCoins(this.transactionBlock.gas, [
1355
+ this.transactionBlock.pure.u64(price)
1356
+ ]);
1357
+ return purchase(this.transactionBlock, itemType, sellerKiosk, itemId, coin);
1358
+ }
1359
+ /**
1360
+ * A function to purchase and resolve a transfer policy.
1361
+ * If the transfer policy has the `lock` rule, the item is locked in the kiosk.
1362
+ * Otherwise, the item is placed in the kiosk.
1363
+ * @param itemType The type of the item
1364
+ * @param itemId The id of the item
1365
+ * @param price The price of the specified item
1366
+ * @param sellerKiosk The kiosk which is selling the item. Can be an id or an object argument.
1367
+ * @param extraArgs Used to pass arguments for custom rule resolvers.
1368
+ */
1369
+ async purchaseAndResolve({
1370
+ itemType,
1371
+ itemId,
1372
+ price,
1373
+ sellerKiosk,
1374
+ extraArgs
1375
+ }) {
1376
+ __privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
1377
+ const policies = await this.kioskClient.getTransferPolicies({ type: itemType });
1378
+ if (policies.length === 0) {
1379
+ throw new Error(
1380
+ `The type ${itemType} doesn't have a Transfer Policy so it can't be traded through kiosk.`
1381
+ );
1382
+ }
1383
+ const policy = policies[0];
1384
+ const [purchasedItem, transferRequest] = this.purchase({
1385
+ itemType,
1386
+ itemId,
1387
+ price,
1388
+ sellerKiosk
1389
+ });
1390
+ let canTransferOutsideKiosk = true;
1391
+ for (const rule of policy.rules) {
1392
+ const ruleDefinition = this.kioskClient.rules.find(
1393
+ (x) => getNormalizedRuleType(x.rule) === getNormalizedRuleType(rule)
1394
+ );
1395
+ if (!ruleDefinition)
1396
+ throw new Error(`No resolver for the following rule: ${rule}.`);
1397
+ if (ruleDefinition.hasLockingRule)
1398
+ canTransferOutsideKiosk = false;
1399
+ ruleDefinition.resolveRuleFunction({
1400
+ packageId: ruleDefinition.packageId,
1401
+ transactionBlock: this.transactionBlock,
1402
+ itemType,
1403
+ itemId,
1404
+ price: price.toString(),
1405
+ sellerKiosk,
1406
+ policyId: policy.id,
1407
+ transferRequest,
1408
+ purchasedItem,
1409
+ kiosk: this.kiosk,
1410
+ kioskCap: this.kioskCap,
1411
+ extraArgs: extraArgs || {}
1412
+ });
1413
+ }
1414
+ confirmRequest(this.transactionBlock, itemType, policy.id, transferRequest);
1415
+ if (canTransferOutsideKiosk)
1416
+ this.place({ itemType, item: purchasedItem });
1417
+ return this;
1418
+ }
1419
+ /**
1420
+ * A function to setup the client using an existing `ownerCap`,
1421
+ * as return from the `kioskClient.getOwnedKiosks` function.
1422
+ * @param cap `KioskOwnerCap` object as returned from `getOwnedKiosks` SDK call.
1423
+ */
1424
+ setCap(cap) {
1425
+ __privateMethod(this, _validateFinalizedStatus, validateFinalizedStatus_fn).call(this);
1426
+ this.kiosk = objArg(this.transactionBlock, cap.kioskId);
1427
+ if (!cap.isPersonal) {
1428
+ this.kioskCap = objArg(this.transactionBlock, cap.objectId);
1429
+ return;
1430
+ }
1431
+ return __privateMethod(this, _borrowFromPersonalCap, borrowFromPersonalCap_fn).call(this, cap.objectId);
1432
+ }
1433
+ /**
1434
+ * A function that ends up the kiosk building txb & returns the `kioskOwnerCap` back to the
1435
+ * `PersonalKioskCap`, in case we are operating on a personal kiosk.
1436
+ * It will also share the `kiosk` if it's not shared, and finalize the transfer of the personal cap if it's pending.
1437
+ */
1438
+ finalize() {
1439
+ __privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
1440
+ if (__privateGet(this, _pendingShare))
1441
+ this.share();
1442
+ if (!__privateGet(this, _personalCap)) {
1443
+ if (__privateGet(this, _pendingTransfer))
1444
+ throw new Error(
1445
+ "You need to transfer the `kioskOwnerCap` by calling `shareAndTransferCap()` before wrap"
1446
+ );
1447
+ return;
1448
+ }
1449
+ const packageId = this.kioskClient.getRulePackageId("personalKioskRulePackageId");
1450
+ if (__privateGet(this, _promise)) {
1451
+ this.transactionBlock.moveCall({
1452
+ target: `${packageId}::personal_kiosk::return_val`,
1453
+ arguments: [
1454
+ __privateGet(this, _personalCap),
1455
+ objArg(this.transactionBlock, this.kioskCap),
1456
+ __privateGet(this, _promise)
1457
+ ]
1458
+ });
1459
+ }
1460
+ if (__privateGet(this, _pendingTransfer))
1461
+ transferPersonalCapTx(this.transactionBlock, __privateGet(this, _personalCap), packageId);
1462
+ __privateSet(this, _finalized, true);
1463
+ }
1464
+ // Some setters in case we want custom behavior.
1465
+ setKioskCap(cap) {
1466
+ __privateMethod(this, _validateFinalizedStatus, validateFinalizedStatus_fn).call(this);
1467
+ this.kioskCap = cap;
1468
+ return this;
1469
+ }
1470
+ setKiosk(kiosk) {
1471
+ __privateMethod(this, _validateFinalizedStatus, validateFinalizedStatus_fn).call(this);
1472
+ this.kiosk = kiosk;
1473
+ return this;
1474
+ }
1475
+ // Some getters
1476
+ /*
1477
+ * Returns the active transaction's kiosk, or undefined if `setCap` or `create()` hasn't been called yet.
1478
+ */
1479
+ getKiosk() {
1480
+ __privateMethod(this, _validateFinalizedStatus, validateFinalizedStatus_fn).call(this);
1481
+ if (!this.kiosk)
1482
+ throw new Error("Kiosk is not set.");
1483
+ return this.kiosk;
1484
+ }
1485
+ /*
1486
+ * Returns the active transaction's kioskOwnerCap, or undefined if `setCap` or `create()` hasn't been called yet.
1487
+ */
1488
+ getKioskCap() {
1489
+ __privateMethod(this, _validateFinalizedStatus, validateFinalizedStatus_fn).call(this);
1490
+ if (!this.kioskCap)
1491
+ throw new Error("Kiosk cap is not set");
1492
+ return this.kioskCap;
1493
+ }
1494
+ };
1495
+ _pendingShare = new WeakMap();
1496
+ _pendingTransfer = new WeakMap();
1497
+ _promise = new WeakMap();
1498
+ _personalCap = new WeakMap();
1499
+ _finalized = new WeakMap();
1500
+ _borrowFromPersonalCap = new WeakSet();
1501
+ borrowFromPersonalCap_fn = function(personalCap) {
1502
+ const [kioskCap, promise] = this.transactionBlock.moveCall({
1503
+ target: `${this.kioskClient.getRulePackageId(
1504
+ "personalKioskRulePackageId"
1505
+ )}::personal_kiosk::borrow_val`,
1506
+ arguments: [objArg(this.transactionBlock, personalCap)]
1507
+ });
1508
+ this.kioskCap = kioskCap;
1509
+ __privateSet(this, _personalCap, objArg(this.transactionBlock, personalCap));
1510
+ __privateSet(this, _promise, promise);
1511
+ return this;
1512
+ };
1513
+ _setPendingStatuses = new WeakSet();
1514
+ setPendingStatuses_fn = function({ share, transfer }) {
1515
+ if (transfer !== void 0)
1516
+ __privateSet(this, _pendingTransfer, transfer);
1517
+ if (share !== void 0)
1518
+ __privateSet(this, _pendingShare, share);
1519
+ };
1520
+ _validateKioskIsSet = new WeakSet();
1521
+ validateKioskIsSet_fn = function() {
1522
+ __privateMethod(this, _validateFinalizedStatus, validateFinalizedStatus_fn).call(this);
1523
+ if (!this.kiosk || !this.kioskCap)
1524
+ throw new Error(
1525
+ "You need to initialize the client by either supplying an existing owner cap or by creating a new by calling `.create()`"
1526
+ );
1527
+ };
1528
+ _validateFinalizedStatus = new WeakSet();
1529
+ validateFinalizedStatus_fn = function() {
1530
+ if (__privateGet(this, _finalized))
1531
+ throw new Error("You can't add more transactions to a finalized kiosk transaction block.");
1532
+ };
508
1533
  export {
1534
+ FLOOR_PRICE_RULE_ADDRESS,
509
1535
  KIOSK_ITEM,
510
1536
  KIOSK_LISTING,
511
1537
  KIOSK_LOCK,
512
1538
  KIOSK_LOCK_RULE,
1539
+ KIOSK_LOCK_RULE_ADDRESS,
513
1540
  KIOSK_MODULE,
514
1541
  KIOSK_OWNER_CAP,
515
1542
  KIOSK_PURCHASE_CAP,
516
1543
  KIOSK_TYPE,
517
- MAINNET_RULES_PACKAGE_ADDRESS,
1544
+ KioskClient,
1545
+ KioskTransaction,
1546
+ Network,
1547
+ PERSONAL_KIOSK_RULE_ADDRESS,
518
1548
  ROYALTY_RULE,
519
- TESTNET_RULES_PACKAGE_ADDRESS,
1549
+ ROYALTY_RULE_ADDRESS,
1550
+ TRANSFER_POLICY_CAP_TYPE,
520
1551
  TRANSFER_POLICY_CREATED_EVENT,
521
1552
  TRANSFER_POLICY_MODULE,
522
1553
  TRANSFER_POLICY_TYPE,
523
- attachKioskLockRule,
1554
+ TransferPolicyTransaction,
524
1555
  attachListingsAndPrices,
525
1556
  attachLockedItems,
526
- attachRoyaltyRule,
527
- bcs,
528
- borrow,
529
- borrowMut,
530
- borrowValue,
531
- confirmRequest,
532
- createKiosk,
533
- createKioskAndShare,
534
- createTransferPolicy,
535
- customEnvironment,
536
- delist,
1557
+ attachObjects,
537
1558
  extractKioskData,
538
- fetchKiosk,
539
1559
  getAllDynamicFields,
1560
+ getAllObjects,
1561
+ getAllOwnedObjects,
1562
+ getBaseRules,
540
1563
  getKioskObject,
541
- getOwnedKiosks,
542
- getRulePackageAddress,
1564
+ getNormalizedRuleType,
543
1565
  getTypeWithoutPackageAddress,
544
- list,
545
- lock,
546
- mainnetEnvironment,
1566
+ mainnetRules,
547
1567
  objArg,
1568
+ parseTransferPolicyCapObject,
548
1569
  percentageToBasisPoints,
549
- place,
550
- placeAndList,
551
- purchase,
552
- purchaseAndResolvePolicies,
553
- queryTransferPolicy,
554
- removeTransferPolicyRule,
555
- resolveKioskLockRule,
556
- resolveRoyaltyRule,
557
- returnValue,
558
- rulesPackageAddresses,
559
- take,
560
- testnetEnvironment,
561
- withdrawFromKiosk,
562
- withdrawFromPolicy
1570
+ rules,
1571
+ testnetRules
563
1572
  };
564
1573
  //# sourceMappingURL=index.mjs.map