@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
@@ -2,8 +2,17 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { SuiClient } from '@mysten/sui.js/client';
5
+ import { isValidSuiAddress } from '@mysten/sui.js/utils';
6
+
5
7
  import { bcs } from '../bcs';
6
- import { TRANSFER_POLICY_CREATED_EVENT, TRANSFER_POLICY_TYPE, TransferPolicy } from '../types';
8
+ import {
9
+ TRANSFER_POLICY_CAP_TYPE,
10
+ TRANSFER_POLICY_CREATED_EVENT,
11
+ TRANSFER_POLICY_TYPE,
12
+ TransferPolicy,
13
+ TransferPolicyCap,
14
+ } from '../types';
15
+ import { getAllOwnedObjects, parseTransferPolicyCapObject } from '../utils';
7
16
 
8
17
  /**
9
18
  * Searches the `TransferPolicy`-s for the given type. The seach is performed via
@@ -40,7 +49,7 @@ export async function queryTransferPolicy(
40
49
  throw new Error(`Invalid policy: ${policy?.objectId}, expected object, got package`);
41
50
  }
42
51
 
43
- let parsed = bcs.de(TRANSFER_POLICY_TYPE, policy.bcs.bcsBytes, 'base64');
52
+ const parsed = bcs.de(TRANSFER_POLICY_TYPE, policy.bcs.bcsBytes, 'base64');
44
53
 
45
54
  return {
46
55
  id: policy?.objectId,
@@ -51,3 +60,74 @@ export async function queryTransferPolicy(
51
60
  } as TransferPolicy;
52
61
  });
53
62
  }
63
+
64
+ /**
65
+ * A function to fetch all the user's kiosk Caps
66
+ * And a list of the kiosk address ids.
67
+ * Returns a list of `kioskOwnerCapIds` and `kioskIds`.
68
+ * Extra options allow pagination.
69
+ * @returns TransferPolicyCap Object ID | undefined if not found.
70
+ */
71
+ export async function queryTransferPolicyCapsByType(
72
+ client: SuiClient,
73
+ address: string,
74
+ type: string,
75
+ ): Promise<TransferPolicyCap[]> {
76
+ if (!isValidSuiAddress(address)) return [];
77
+
78
+ const filter = {
79
+ MatchAll: [
80
+ {
81
+ StructType: `${TRANSFER_POLICY_CAP_TYPE}<${type}>`,
82
+ },
83
+ ],
84
+ };
85
+
86
+ // fetch owned kiosk caps, paginated.
87
+ const data = await getAllOwnedObjects({
88
+ client,
89
+ filter,
90
+ owner: address,
91
+ });
92
+
93
+ return data
94
+ .map((item) => parseTransferPolicyCapObject(item))
95
+ .filter((item) => !!item) as TransferPolicyCap[];
96
+ }
97
+
98
+ /**
99
+ * A function to fetch all the user's kiosk Caps
100
+ * And a list of the kiosk address ids.
101
+ * Returns a list of `kioskOwnerCapIds` and `kioskIds`.
102
+ * Extra options allow pagination.
103
+ * @returns TransferPolicyCap Object ID | undefined if not found.
104
+ */
105
+ export async function queryOwnedTransferPolicies(
106
+ client: SuiClient,
107
+ address: string,
108
+ ): Promise<TransferPolicyCap[] | undefined> {
109
+ if (!isValidSuiAddress(address)) return;
110
+
111
+ const filter = {
112
+ MatchAll: [
113
+ {
114
+ MoveModule: {
115
+ module: 'transfer_policy',
116
+ package: '0x2',
117
+ },
118
+ },
119
+ ],
120
+ };
121
+
122
+ // fetch all owned kiosk caps, paginated.
123
+ const data = await getAllOwnedObjects({ client, owner: address, filter });
124
+
125
+ const policies: TransferPolicyCap[] = [];
126
+
127
+ for (const item of data) {
128
+ const data = parseTransferPolicyCapObject(item);
129
+ if (data) policies.push(data);
130
+ }
131
+
132
+ return policies;
133
+ }
package/src/tx/kiosk.ts CHANGED
@@ -1,27 +1,23 @@
1
1
  // Copyright (c) Mysten Labs, Inc.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { TransactionBlock, TransactionArgument } from '@mysten/sui.js/transactions';
5
-
6
- import { getTypeWithoutPackageAddress, objArg } from '../utils';
7
- import { confirmRequest, resolveKioskLockRule, resolveRoyaltyRule } from './transfer-policy';
4
+ import { bcs } from '@mysten/sui.js/bcs';
8
5
  import {
9
- KIOSK_LOCK_RULE,
10
- KIOSK_MODULE,
11
- KIOSK_TYPE,
12
- ObjectArgument,
13
- PurchaseAndResolvePoliciesResponse,
14
- PurchaseOptionalParams,
15
- ROYALTY_RULE,
16
- RulesEnvironmentParam,
17
- TransferPolicy,
18
- } from '../types';
6
+ TransactionArgument,
7
+ TransactionBlock,
8
+ TransactionObjectArgument,
9
+ } from '@mysten/sui.js/transactions';
10
+
11
+ import { KIOSK_MODULE, KIOSK_TYPE, ObjectArgument } from '../types';
12
+ import { objArg } from '../utils';
19
13
 
20
14
  /**
21
15
  * Create a new shared Kiosk and returns the [kiosk, kioskOwnerCap] tuple.
22
16
  */
23
- export function createKiosk(tx: TransactionBlock): [TransactionArgument, TransactionArgument] {
24
- let [kiosk, kioskOwnerCap] = tx.moveCall({
17
+ export function createKiosk(
18
+ tx: TransactionBlock,
19
+ ): [TransactionObjectArgument, TransactionObjectArgument] {
20
+ const [kiosk, kioskOwnerCap] = tx.moveCall({
25
21
  target: `${KIOSK_MODULE}::new`,
26
22
  });
27
23
 
@@ -32,18 +28,21 @@ export function createKiosk(tx: TransactionBlock): [TransactionArgument, Transac
32
28
  * Calls the `kiosk::new()` function and shares the kiosk.
33
29
  * Returns the `kioskOwnerCap` object.
34
30
  */
35
- export function createKioskAndShare(tx: TransactionBlock): TransactionArgument {
36
- let [kiosk, kioskOwnerCap] = tx.moveCall({
37
- target: `${KIOSK_MODULE}::new`,
38
- });
31
+ export function createKioskAndShare(tx: TransactionBlock): TransactionObjectArgument {
32
+ const [kiosk, kioskOwnerCap] = createKiosk(tx);
33
+ shareKiosk(tx, kiosk);
34
+ return kioskOwnerCap;
35
+ }
39
36
 
37
+ /**
38
+ * Converts Transfer Policy to a shared object.
39
+ */
40
+ export function shareKiosk(tx: TransactionBlock, kiosk: TransactionArgument) {
40
41
  tx.moveCall({
41
42
  target: `0x2::transfer::public_share_object`,
42
43
  typeArguments: [KIOSK_TYPE],
43
44
  arguments: [kiosk],
44
45
  });
45
-
46
- return kioskOwnerCap;
47
46
  }
48
47
 
49
48
  /**
@@ -97,11 +96,11 @@ export function take(
97
96
  kiosk: ObjectArgument,
98
97
  kioskCap: ObjectArgument,
99
98
  itemId: string,
100
- ): TransactionArgument {
101
- let [item] = tx.moveCall({
99
+ ): TransactionObjectArgument {
100
+ const [item] = tx.moveCall({
102
101
  target: `${KIOSK_MODULE}::take`,
103
102
  typeArguments: [itemType],
104
- arguments: [objArg(tx, kiosk), objArg(tx, kioskCap), tx.pure(itemId, 'address')],
103
+ arguments: [objArg(tx, kiosk), objArg(tx, kioskCap), tx.pure.address(itemId)],
105
104
  });
106
105
 
107
106
  return item;
@@ -125,8 +124,8 @@ export function list(
125
124
  arguments: [
126
125
  objArg(tx, kiosk),
127
126
  objArg(tx, kioskCap),
128
- tx.pure(itemId, 'address'),
129
- tx.pure(price, 'u64'),
127
+ tx.pure.address(itemId),
128
+ tx.pure.u64(price),
130
129
  ],
131
130
  });
132
131
  }
@@ -145,7 +144,7 @@ export function delist(
145
144
  tx.moveCall({
146
145
  target: `${KIOSK_MODULE}::delist`,
147
146
  typeArguments: [itemType],
148
- arguments: [objArg(tx, kiosk), objArg(tx, kioskCap), tx.pure(itemId, 'address')],
147
+ arguments: [objArg(tx, kiosk), objArg(tx, kioskCap), tx.pure.address(itemId)],
149
148
  });
150
149
  }
151
150
 
@@ -164,7 +163,7 @@ export function placeAndList(
164
163
  tx.moveCall({
165
164
  target: `${KIOSK_MODULE}::place_and_list`,
166
165
  typeArguments: [itemType],
167
- arguments: [objArg(tx, kiosk), objArg(tx, kioskCap), objArg(tx, item), tx.pure(price, 'u64')],
166
+ arguments: [objArg(tx, kiosk), objArg(tx, kioskCap), objArg(tx, item), tx.pure.u64(price)],
168
167
  });
169
168
  }
170
169
 
@@ -178,11 +177,11 @@ export function purchase(
178
177
  kiosk: ObjectArgument,
179
178
  itemId: string,
180
179
  payment: ObjectArgument,
181
- ): [TransactionArgument, TransactionArgument] {
182
- let [item, transferRequest] = tx.moveCall({
180
+ ): [TransactionObjectArgument, TransactionObjectArgument] {
181
+ const [item, transferRequest] = tx.moveCall({
183
182
  target: `${KIOSK_MODULE}::purchase`,
184
183
  typeArguments: [itemType],
185
- arguments: [objArg(tx, kiosk), tx.pure(itemId, 'address'), objArg(tx, payment)],
184
+ arguments: [objArg(tx, kiosk), tx.pure.address(itemId), objArg(tx, payment)],
186
185
  });
187
186
 
188
187
  return [item, transferRequest];
@@ -196,19 +195,11 @@ export function withdrawFromKiosk(
196
195
  tx: TransactionBlock,
197
196
  kiosk: ObjectArgument,
198
197
  kioskCap: ObjectArgument,
199
- amount: string | bigint | null,
200
- ): TransactionArgument {
201
- let amountArg =
202
- amount !== null
203
- ? tx.pure(
204
- {
205
- Some: amount,
206
- },
207
- 'Option<u64>',
208
- )
209
- : tx.pure({ None: true }, 'Option<u64>');
198
+ amount?: string | bigint | number,
199
+ ): TransactionObjectArgument {
200
+ const amountArg = bcs.option(bcs.u64()).serialize(amount);
210
201
 
211
- let [coin] = tx.moveCall({
202
+ const [coin] = tx.moveCall({
212
203
  target: `${KIOSK_MODULE}::withdraw`,
213
204
  arguments: [objArg(tx, kiosk), objArg(tx, kioskCap), amountArg],
214
205
  });
@@ -216,46 +207,6 @@ export function withdrawFromKiosk(
216
207
  return coin;
217
208
  }
218
209
 
219
- /**
220
- * Call the `kiosk::borrow<T>(Kiosk, KioskOwnerCap, ID): &T` function.
221
- * Immutably borrow an item from the Kiosk.
222
- */
223
- export function borrow(
224
- tx: TransactionBlock,
225
- itemType: string,
226
- kiosk: ObjectArgument,
227
- kioskCap: ObjectArgument,
228
- itemId: string,
229
- ): TransactionArgument {
230
- let [item] = tx.moveCall({
231
- target: `${KIOSK_MODULE}::borrow`,
232
- typeArguments: [itemType],
233
- arguments: [objArg(tx, kiosk), objArg(tx, kioskCap), tx.pure(itemId, 'address')],
234
- });
235
-
236
- return item;
237
- }
238
-
239
- /**
240
- * Call the `kiosk::borrow_mut<T>(Kiosk, KioskOwnerCap, ID): &mut T` function.
241
- * Mutably borrow an item from the Kiosk.
242
- */
243
- export function borrowMut(
244
- tx: TransactionBlock,
245
- itemType: string,
246
- kiosk: ObjectArgument,
247
- kioskCap: ObjectArgument,
248
- itemId: string,
249
- ): TransactionArgument {
250
- let [item] = tx.moveCall({
251
- target: `${KIOSK_MODULE}::borrow_mut`,
252
- typeArguments: [itemType],
253
- arguments: [objArg(tx, kiosk), objArg(tx, kioskCap), tx.pure(itemId, 'address')],
254
- });
255
-
256
- return item;
257
- }
258
-
259
210
  /**
260
211
  * Call the `kiosk::borrow_value<T>(Kiosk, KioskOwnerCap, ID): T` function.
261
212
  * Immutably borrow an item from the Kiosk and return it in the end.
@@ -269,10 +220,10 @@ export function borrowValue(
269
220
  kioskCap: ObjectArgument,
270
221
  itemId: string,
271
222
  ): [TransactionArgument, TransactionArgument] {
272
- let [item, promise] = tx.moveCall({
223
+ const [item, promise] = tx.moveCall({
273
224
  target: `${KIOSK_MODULE}::borrow_val`,
274
225
  typeArguments: [itemType],
275
- arguments: [objArg(tx, kiosk), objArg(tx, kioskCap), tx.pure(itemId, 'address')],
226
+ arguments: [objArg(tx, kiosk), objArg(tx, kioskCap), tx.pure.address(itemId)],
276
227
  });
277
228
 
278
229
  return [item, promise];
@@ -295,75 +246,3 @@ export function returnValue(
295
246
  arguments: [objArg(tx, kiosk), item, promise],
296
247
  });
297
248
  }
298
-
299
- /**
300
- * Completes the full purchase flow that includes:
301
- * 1. Purchasing the item.
302
- * 2. Resolving all the transfer policies (if any).
303
- * 3. Returns the item and whether the user can transfer it or not.
304
- *
305
- * If the item can be transferred, there's an extra transaction required by the user
306
- * to transfer it to an address or place it in their kiosk.
307
- */
308
- export function purchaseAndResolvePolicies(
309
- tx: TransactionBlock,
310
- itemType: string,
311
- price: string,
312
- kiosk: ObjectArgument,
313
- itemId: string,
314
- policy: TransferPolicy,
315
- environment: RulesEnvironmentParam,
316
- extraParams?: PurchaseOptionalParams,
317
- ): PurchaseAndResolvePoliciesResponse {
318
- // if we don't pass the listing or the listing doens't have a price, return.
319
- if (price === undefined || typeof price !== 'string')
320
- throw new Error(`Price of the listing is not supplied.`);
321
-
322
- // Split the coin for the amount of the listing.
323
- const coin = tx.splitCoins(tx.gas, [tx.pure(price, 'u64')]);
324
-
325
- // initialize the purchase `kiosk::purchase`
326
- const [purchasedItem, transferRequest] = purchase(tx, itemType, kiosk, itemId, coin);
327
-
328
- // Start resolving rules.
329
- // Right now we support `kiosk_lock_rule` and `royalty_rule`.
330
- // They can also be supplied in parallel (supports combination).
331
- let hasKioskLockRule = false;
332
-
333
- for (let rule of policy.rules) {
334
- const ruleWithoutAddr = getTypeWithoutPackageAddress(rule);
335
-
336
- switch (ruleWithoutAddr) {
337
- case ROYALTY_RULE:
338
- resolveRoyaltyRule(tx, itemType, price, policy.id, transferRequest, environment);
339
- break;
340
- case KIOSK_LOCK_RULE:
341
- if (!extraParams?.ownedKiosk || !extraParams?.ownedKioskCap)
342
- throw new Error(
343
- `This item type ${itemType} has a 'kiosk_lock_rule', but function call is missing user's kiosk and kioskCap params`,
344
- );
345
- hasKioskLockRule = true;
346
- resolveKioskLockRule(
347
- tx,
348
- itemType,
349
- purchasedItem,
350
- extraParams.ownedKiosk,
351
- extraParams.ownedKioskCap,
352
- policy.id,
353
- transferRequest,
354
- environment,
355
- );
356
- break;
357
- default:
358
- break;
359
- }
360
- }
361
-
362
- // confirm the Transfer Policy request.
363
- confirmRequest(tx, itemType, policy.id, transferRequest);
364
-
365
- return {
366
- item: purchasedItem,
367
- canTransfer: !hasKioskLockRule,
368
- };
369
- }
@@ -0,0 +1,35 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { TransactionBlock, TransactionObjectArgument } from '@mysten/sui.js/transactions';
5
+
6
+ import { ObjectArgument } from '../types';
7
+ import { objArg } from '../utils';
8
+
9
+ export function convertToPersonalTx(
10
+ tx: TransactionBlock,
11
+ kiosk: ObjectArgument,
12
+ kioskOwnerCap: ObjectArgument,
13
+ packageId: string,
14
+ ): TransactionObjectArgument {
15
+ const personalKioskCap = tx.moveCall({
16
+ target: `${packageId}::personal_kiosk::new`,
17
+ arguments: [objArg(tx, kiosk), objArg(tx, kioskOwnerCap)],
18
+ });
19
+
20
+ return personalKioskCap;
21
+ }
22
+
23
+ /**
24
+ * Transfers the personal kiosk Cap to the sender.
25
+ */
26
+ export function transferPersonalCapTx(
27
+ tx: TransactionBlock,
28
+ personalKioskCap: TransactionObjectArgument,
29
+ packageId: string,
30
+ ) {
31
+ tx.moveCall({
32
+ target: `${packageId}::personal_kiosk::transfer_to_sender`,
33
+ arguments: [personalKioskCap],
34
+ });
35
+ }
@@ -0,0 +1,74 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { type TransactionBlock } from '@mysten/sui.js/transactions';
5
+
6
+ import { type ObjectArgument } from '../../types';
7
+ import { objArg } from '../../utils';
8
+
9
+ export function attachKioskLockRuleTx(
10
+ tx: TransactionBlock,
11
+ type: string,
12
+ policy: ObjectArgument,
13
+ policyCap: ObjectArgument,
14
+ packageId: string,
15
+ ) {
16
+ tx.moveCall({
17
+ target: `${packageId}::kiosk_lock_rule::add`,
18
+ typeArguments: [type],
19
+ arguments: [objArg(tx, policy), objArg(tx, policyCap)],
20
+ });
21
+ }
22
+
23
+ export function attachRoyaltyRuleTx(
24
+ tx: TransactionBlock,
25
+ type: string,
26
+ policy: ObjectArgument,
27
+ policyCap: ObjectArgument,
28
+ percentageBps: number | string, // this is in basis points.
29
+ minAmount: number | string,
30
+ packageId: string,
31
+ ) {
32
+ if (Number(percentageBps) < 0 || Number(percentageBps) > 10_000)
33
+ throw new Error('Invalid basis point percentage. Use a value between [0,10000].');
34
+
35
+ tx.moveCall({
36
+ target: `${packageId}::royalty_rule::add`,
37
+ typeArguments: [type],
38
+ arguments: [
39
+ objArg(tx, policy),
40
+ objArg(tx, policyCap),
41
+ tx.pure.u16(Number(percentageBps)),
42
+ tx.pure.u64(minAmount),
43
+ ],
44
+ });
45
+ }
46
+
47
+ export function attachPersonalKioskRuleTx(
48
+ tx: TransactionBlock,
49
+ type: string,
50
+ policy: ObjectArgument,
51
+ policyCap: ObjectArgument,
52
+ packageId: string,
53
+ ) {
54
+ tx.moveCall({
55
+ target: `${packageId}::personal_kiosk_rule::add`,
56
+ typeArguments: [type],
57
+ arguments: [objArg(tx, policy), objArg(tx, policyCap)],
58
+ });
59
+ }
60
+
61
+ export function attachFloorPriceRuleTx(
62
+ tx: TransactionBlock,
63
+ type: string,
64
+ policy: ObjectArgument,
65
+ policyCap: ObjectArgument,
66
+ minPrice: string | bigint,
67
+ packageId: string,
68
+ ) {
69
+ tx.moveCall({
70
+ target: `${packageId}::floor_price_rule::add`,
71
+ typeArguments: [type],
72
+ arguments: [objArg(tx, policy), objArg(tx, policyCap), tx.pure.u64(minPrice)],
73
+ });
74
+ }
@@ -0,0 +1,87 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { type RuleResolvingParams } from '../../types';
5
+ import { objArg } from '../../utils';
6
+ import { lock } from '../kiosk';
7
+
8
+ /**
9
+ * A helper to resolve the royalty rule.
10
+ */
11
+ export function resolveRoyaltyRule(params: RuleResolvingParams) {
12
+ const { transactionBlock: txb, itemType, price, packageId, transferRequest, policyId } = params;
13
+
14
+ const policyObj = objArg(txb, policyId);
15
+
16
+ // calculates the amount
17
+ const [amount] = txb.moveCall({
18
+ target: `${packageId}::royalty_rule::fee_amount`,
19
+ typeArguments: [itemType],
20
+ arguments: [policyObj, objArg(txb, price ?? '')],
21
+ });
22
+
23
+ // splits the coin.
24
+ const feeCoin = txb.splitCoins(txb.gas, [amount]);
25
+
26
+ // pays the policy
27
+ txb.moveCall({
28
+ target: `${packageId}::royalty_rule::pay`,
29
+ typeArguments: [itemType],
30
+ arguments: [policyObj, transferRequest, feeCoin],
31
+ });
32
+ }
33
+
34
+ export function resolveKioskLockRule(params: RuleResolvingParams) {
35
+ const {
36
+ transactionBlock: txb,
37
+ packageId,
38
+ itemType,
39
+ kiosk,
40
+ kioskCap,
41
+ policyId,
42
+ purchasedItem,
43
+ transferRequest,
44
+ } = params;
45
+
46
+ if (!kiosk || !kioskCap) throw new Error('Missing Owned Kiosk or Owned Kiosk Cap');
47
+
48
+ lock(txb, itemType, kiosk, kioskCap, policyId, purchasedItem);
49
+
50
+ // proves that the item is locked in the kiosk to the TP.
51
+ txb.moveCall({
52
+ target: `${packageId}::kiosk_lock_rule::prove`,
53
+ typeArguments: [itemType],
54
+ arguments: [transferRequest, objArg(txb, kiosk)],
55
+ });
56
+ }
57
+
58
+ /**
59
+ * A helper to resolve the personalKioskRule.
60
+ * @param params
61
+ */
62
+ export function resolvePersonalKioskRule(params: RuleResolvingParams) {
63
+ const { transactionBlock: txb, packageId, itemType, kiosk, transferRequest } = params;
64
+
65
+ if (!kiosk) throw new Error('Missing owned Kiosk.');
66
+
67
+ // proves that the destination kiosk is personal.
68
+ txb.moveCall({
69
+ target: `${packageId}::personal_kiosk_rule::prove`,
70
+ typeArguments: [itemType],
71
+ arguments: [objArg(txb, kiosk), transferRequest],
72
+ });
73
+ }
74
+
75
+ /**
76
+ * Resolves the floor price rule.
77
+ */
78
+ export function resolveFloorPriceRule(params: RuleResolvingParams) {
79
+ const { transactionBlock: txb, packageId, itemType, policyId, transferRequest } = params;
80
+
81
+ // proves that the destination kiosk is personal
82
+ txb.moveCall({
83
+ target: `${packageId}::floor_price_rule::prove`,
84
+ typeArguments: [itemType],
85
+ arguments: [objArg(txb, policyId), transferRequest],
86
+ });
87
+ }