@mysten/kiosk 0.7.12 → 0.8.0

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