@mysten/kiosk 0.3.0 → 0.3.2

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.
@@ -5,9 +5,10 @@ import { TransactionArgument, TransactionBlock } from '@mysten/sui.js';
5
5
  import { getRulePackageAddress, objArg } from '../utils';
6
6
  import { lock } from './kiosk';
7
7
  import {
8
- ObjectArgument,
9
- RulesEnvironmentParam,
10
- TRANSFER_POLICY_MODULE,
8
+ ObjectArgument,
9
+ RulesEnvironmentParam,
10
+ TRANSFER_POLICY_MODULE,
11
+ TRANSFER_POLICY_TYPE,
11
12
  } from '../types';
12
13
 
13
14
  /**
@@ -15,47 +16,47 @@ import {
15
16
  * Returns `transferPolicyCap`
16
17
  */
17
18
  export function createTransferPolicy(
18
- tx: TransactionBlock,
19
- itemType: string,
20
- publisher: ObjectArgument,
19
+ tx: TransactionBlock,
20
+ itemType: string,
21
+ publisher: ObjectArgument,
21
22
  ): TransactionArgument {
22
- let [transferPolicy, transferPolicyCap] = tx.moveCall({
23
- target: `${TRANSFER_POLICY_MODULE}::new`,
24
- typeArguments: [itemType],
25
- arguments: [objArg(tx, publisher)],
26
- });
23
+ let [transferPolicy, transferPolicyCap] = tx.moveCall({
24
+ target: `${TRANSFER_POLICY_MODULE}::new`,
25
+ typeArguments: [itemType],
26
+ arguments: [objArg(tx, publisher)],
27
+ });
27
28
 
28
- tx.moveCall({
29
- target: `0x2::transfer::public_share_object`,
30
- typeArguments: [itemType],
31
- arguments: [transferPolicy],
32
- });
29
+ tx.moveCall({
30
+ target: `0x2::transfer::public_share_object`,
31
+ typeArguments: [`${TRANSFER_POLICY_TYPE}<${itemType}>`],
32
+ arguments: [transferPolicy],
33
+ });
33
34
 
34
- return transferPolicyCap;
35
+ return transferPolicyCap;
35
36
  }
36
37
 
37
38
  /**
38
39
  * Call the `transfer_policy::withdraw` function to withdraw profits from a transfer policy.
39
40
  */
40
41
  export function withdrawFromPolicy(
41
- tx: TransactionBlock,
42
- itemType: string,
43
- policy: ObjectArgument,
44
- policyCap: ObjectArgument,
45
- amount: string | bigint | null,
42
+ tx: TransactionBlock,
43
+ itemType: string,
44
+ policy: ObjectArgument,
45
+ policyCap: ObjectArgument,
46
+ amount: string | bigint | null,
46
47
  ): TransactionArgument {
47
- let amountArg =
48
- amount !== null
49
- ? tx.pure({ Some: amount }, 'Option<u64>')
50
- : tx.pure({ None: true }, 'Option<u64>');
48
+ let amountArg =
49
+ amount !== null
50
+ ? tx.pure({ Some: amount }, 'Option<u64>')
51
+ : tx.pure({ None: true }, 'Option<u64>');
51
52
 
52
- let [profits] = tx.moveCall({
53
- target: `${TRANSFER_POLICY_MODULE}::withdraw`,
54
- typeArguments: [itemType],
55
- arguments: [objArg(tx, policy), objArg(tx, policyCap), amountArg],
56
- });
53
+ let [profits] = tx.moveCall({
54
+ target: `${TRANSFER_POLICY_MODULE}::withdraw`,
55
+ typeArguments: [itemType],
56
+ arguments: [objArg(tx, policy), objArg(tx, policyCap), amountArg],
57
+ });
57
58
 
58
- return profits;
59
+ return profits;
59
60
  }
60
61
 
61
62
  /**
@@ -63,34 +64,34 @@ export function withdrawFromPolicy(
63
64
  * transaction.
64
65
  */
65
66
  export function confirmRequest(
66
- tx: TransactionBlock,
67
- itemType: string,
68
- policy: ObjectArgument,
69
- request: TransactionArgument,
67
+ tx: TransactionBlock,
68
+ itemType: string,
69
+ policy: ObjectArgument,
70
+ request: TransactionArgument,
70
71
  ): void {
71
- tx.moveCall({
72
- target: `${TRANSFER_POLICY_MODULE}::confirm_request`,
73
- typeArguments: [itemType],
74
- arguments: [objArg(tx, policy), request],
75
- });
72
+ tx.moveCall({
73
+ target: `${TRANSFER_POLICY_MODULE}::confirm_request`,
74
+ typeArguments: [itemType],
75
+ arguments: [objArg(tx, policy), request],
76
+ });
76
77
  }
77
78
 
78
79
  /**
79
80
  * Calls the `transfer_policy::remove_rule` function to remove a Rule from the transfer policy's ruleset.
80
81
  */
81
82
  export function removeTransferPolicyRule(
82
- tx: TransactionBlock,
83
- itemType: string,
84
- ruleType: string,
85
- configType: string,
86
- policy: ObjectArgument,
87
- policyCap: TransactionArgument,
83
+ tx: TransactionBlock,
84
+ itemType: string,
85
+ ruleType: string,
86
+ configType: string,
87
+ policy: ObjectArgument,
88
+ policyCap: TransactionArgument,
88
89
  ): void {
89
- tx.moveCall({
90
- target: `${TRANSFER_POLICY_MODULE}::remove_rule`,
91
- typeArguments: [itemType, ruleType, configType],
92
- arguments: [objArg(tx, policy), policyCap],
93
- });
90
+ tx.moveCall({
91
+ target: `${TRANSFER_POLICY_MODULE}::remove_rule`,
92
+ typeArguments: [itemType, ruleType, configType],
93
+ arguments: [objArg(tx, policy), policyCap],
94
+ });
94
95
  }
95
96
 
96
97
  /**
@@ -99,30 +100,30 @@ export function removeTransferPolicyRule(
99
100
  * then calls the `royalty_rule::pay` function to resolve the royalty rule.
100
101
  */
101
102
  export function resolveRoyaltyRule(
102
- tx: TransactionBlock,
103
- itemType: string,
104
- price: string,
105
- policyId: ObjectArgument,
106
- transferRequest: TransactionArgument,
107
- environment: RulesEnvironmentParam,
103
+ tx: TransactionBlock,
104
+ itemType: string,
105
+ price: string,
106
+ policyId: ObjectArgument,
107
+ transferRequest: TransactionArgument,
108
+ environment: RulesEnvironmentParam,
108
109
  ) {
109
- const policyObj = objArg(tx, policyId);
110
- // calculates the amount
111
- const [amount] = tx.moveCall({
112
- target: `${getRulePackageAddress(environment)}::royalty_rule::fee_amount`,
113
- typeArguments: [itemType],
114
- arguments: [policyObj, objArg(tx, price)],
115
- });
110
+ const policyObj = objArg(tx, policyId);
111
+ // calculates the amount
112
+ const [amount] = tx.moveCall({
113
+ target: `${getRulePackageAddress(environment)}::royalty_rule::fee_amount`,
114
+ typeArguments: [itemType],
115
+ arguments: [policyObj, objArg(tx, price)],
116
+ });
116
117
 
117
- // splits the coin.
118
- const feeCoin = tx.splitCoins(tx.gas, [amount]);
118
+ // splits the coin.
119
+ const feeCoin = tx.splitCoins(tx.gas, [amount]);
119
120
 
120
- // pays the policy
121
- tx.moveCall({
122
- target: `${getRulePackageAddress(environment)}::royalty_rule::pay`,
123
- typeArguments: [itemType],
124
- arguments: [policyObj, transferRequest, feeCoin],
125
- });
121
+ // pays the policy
122
+ tx.moveCall({
123
+ target: `${getRulePackageAddress(environment)}::royalty_rule::pay`,
124
+ typeArguments: [itemType],
125
+ arguments: [policyObj, transferRequest, feeCoin],
126
+ });
126
127
  }
127
128
 
128
129
  /**
@@ -131,22 +132,22 @@ export function resolveRoyaltyRule(
131
132
  * by calling the `kiosk_lock_rule::prove` function to resolve it.
132
133
  */
133
134
  export function resolveKioskLockRule(
134
- tx: TransactionBlock,
135
- itemType: string,
136
- item: TransactionArgument,
137
- kiosk: ObjectArgument,
138
- kioskCap: ObjectArgument,
139
- policyId: ObjectArgument,
140
- transferRequest: TransactionArgument,
141
- environment: RulesEnvironmentParam,
135
+ tx: TransactionBlock,
136
+ itemType: string,
137
+ item: TransactionArgument,
138
+ kiosk: ObjectArgument,
139
+ kioskCap: ObjectArgument,
140
+ policyId: ObjectArgument,
141
+ transferRequest: TransactionArgument,
142
+ environment: RulesEnvironmentParam,
142
143
  ) {
143
- // lock item in the kiosk.
144
- lock(tx, itemType, kiosk, kioskCap, policyId, item);
144
+ // lock item in the kiosk.
145
+ lock(tx, itemType, kiosk, kioskCap, policyId, item);
145
146
 
146
- // proves that the item is locked in the kiosk to the TP.
147
- tx.moveCall({
148
- target: `${getRulePackageAddress(environment)}::kiosk_lock_rule::prove`,
149
- typeArguments: [itemType],
150
- arguments: [transferRequest, objArg(tx, kiosk)],
151
- });
147
+ // proves that the item is locked in the kiosk to the TP.
148
+ tx.moveCall({
149
+ target: `${getRulePackageAddress(environment)}::kiosk_lock_rule::prove`,
150
+ typeArguments: [itemType],
151
+ arguments: [transferRequest, objArg(tx, kiosk)],
152
+ });
152
153
  }
package/src/types/env.ts CHANGED
@@ -17,6 +17,6 @@ export const mainnetEnvironment: RulesEnvironmentParam = { env: 'mainnet' };
17
17
 
18
18
  /** A helper to easily export a custom environment */
19
19
  export const customEnvironment = (address: string): RulesEnvironmentParam => ({
20
- env: 'custom',
21
- address,
20
+ env: 'custom',
21
+ address,
22
22
  });
@@ -1,11 +1,7 @@
1
1
  // Copyright (c) Mysten Labs, Inc.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import {
5
- SharedObjectRef,
6
- SuiObjectRef,
7
- TransactionArgument,
8
- } from '@mysten/sui.js';
4
+ import { SharedObjectRef, SuiObjectRef, TransactionArgument } from '@mysten/sui.js';
9
5
 
10
6
  export * from './kiosk';
11
7
  export * from './transfer-policy';
@@ -14,8 +10,4 @@ export * from './env';
14
10
  /**
15
11
  * A valid argument for any of the Kiosk functions.
16
12
  */
17
- export type ObjectArgument =
18
- | string
19
- | TransactionArgument
20
- | SharedObjectRef
21
- | SuiObjectRef;
13
+ export type ObjectArgument = string | TransactionArgument | SharedObjectRef | SuiObjectRef;
@@ -1,7 +1,13 @@
1
1
  // Copyright (c) Mysten Labs, Inc.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { TransactionArgument } from '@mysten/sui.js';
4
+ import {
5
+ ObjectDigest,
6
+ ObjectId,
7
+ ObjectType,
8
+ PaginatedObjectsResponse,
9
+ TransactionArgument,
10
+ } from '@mysten/sui.js';
5
11
  import { ObjectArgument } from '.';
6
12
 
7
13
  /** The Kiosk module. */
@@ -29,21 +35,21 @@ export const KIOSK_PURCHASE_CAP = `${KIOSK_MODULE}::PurchaseCap`;
29
35
  * The Kiosk object fields (for BCS queries).
30
36
  */
31
37
  export type Kiosk = {
32
- id: string;
33
- profits: string;
34
- owner: string;
35
- itemCount: number;
36
- allowExtensions: boolean;
38
+ id: string;
39
+ profits: string;
40
+ owner: string;
41
+ itemCount: number;
42
+ allowExtensions: boolean;
37
43
  };
38
44
 
39
45
  /**
40
46
  * PurchaseCap object fields (for BCS queries).
41
47
  */
42
48
  export type PurchaseCap = {
43
- id: string;
44
- kioskId: string;
45
- itemId: string;
46
- minPrice: string;
49
+ id: string;
50
+ kioskId: string;
51
+ itemId: string;
52
+ minPrice: string;
47
53
  };
48
54
 
49
55
  /**
@@ -51,8 +57,8 @@ export type PurchaseCap = {
51
57
  * Returns the item, and a `canTransfer` param.
52
58
  */
53
59
  export type PurchaseAndResolvePoliciesResponse = {
54
- item: TransactionArgument;
55
- canTransfer: boolean;
60
+ item: TransactionArgument;
61
+ canTransfer: boolean;
56
62
  };
57
63
 
58
64
  /**
@@ -61,6 +67,73 @@ export type PurchaseAndResolvePoliciesResponse = {
61
67
  * without introducing more breaking changes.
62
68
  */
63
69
  export type PurchaseOptionalParams = {
64
- ownedKiosk?: ObjectArgument;
65
- ownedKioskCap?: ObjectArgument;
70
+ ownedKiosk?: ObjectArgument;
71
+ ownedKioskCap?: ObjectArgument;
72
+ };
73
+
74
+ /**
75
+ * A dynamic field `Listing { ID, isExclusive }` attached to the Kiosk.
76
+ * Holds a `u64` value - the price of the item.
77
+ */
78
+ export type KioskListing = {
79
+ /** The ID of the Item */
80
+ objectId: ObjectId;
81
+ /**
82
+ * Whether or not there's a `PurchaseCap` issued. `true` means that
83
+ * the listing is controlled by some logic and can't be purchased directly.
84
+ *
85
+ * TODO: consider renaming the field for better indication.
86
+ */
87
+ isExclusive: boolean;
88
+ /** The ID of the listing */
89
+ listingId: ObjectId;
90
+ price?: string;
91
+ };
92
+
93
+ /**
94
+ * A dynamic field `Item { ID }` attached to the Kiosk.
95
+ * Holds an Item `T`. The type of the item is known upfront.
96
+ */
97
+ export type KioskItem = {
98
+ /** The ID of the Item */
99
+ objectId: ObjectId;
100
+ /** The type of the Item */
101
+ type: ObjectType;
102
+ /** Whether the item is Locked (there must be a `Lock` Dynamic Field) */
103
+ isLocked: boolean;
104
+ /** Optional listing */
105
+ listing?: KioskListing;
106
+ };
107
+ /**
108
+ * Aggregated data from the Kiosk.
109
+ */
110
+ export type KioskData = {
111
+ items: KioskItem[];
112
+ itemIds: ObjectId[];
113
+ listingIds: ObjectId[];
114
+ kiosk?: Kiosk;
115
+ extensions: any[]; // type will be defined on later versions of the SDK.
116
+ };
117
+
118
+ export type PagedKioskData = {
119
+ data: KioskData;
120
+ nextCursor: string | null;
121
+ hasNextPage: boolean;
122
+ };
123
+
124
+ export type FetchKioskOptions = {
125
+ withKioskFields?: boolean;
126
+ withListingPrices?: boolean;
127
+ };
128
+
129
+ export type OwnedKiosks = {
130
+ kioskOwnerCaps: KioskOwnerCap[];
131
+ kioskIds: ObjectId[];
132
+ } & Omit<PaginatedObjectsResponse, 'data'>;
133
+
134
+ export type KioskOwnerCap = {
135
+ objectId: ObjectId;
136
+ kioskId: ObjectId;
137
+ digest: ObjectDigest;
138
+ version: string;
66
139
  };
@@ -20,14 +20,14 @@ export const ROYALTY_RULE = 'royalty_rule::Rule';
20
20
 
21
21
  /** The `TransferPolicy` object */
22
22
  export type TransferPolicy = {
23
- id: string;
24
- type: string;
25
- balance: string;
26
- rules: string[];
27
- owner: ObjectOwner;
23
+ id: string;
24
+ type: string;
25
+ balance: string;
26
+ rules: string[];
27
+ owner: ObjectOwner;
28
28
  };
29
29
 
30
30
  /** Event emitted when a TransferPolicy is created. */
31
31
  export type TransferPolicyCreated = {
32
- id: string;
32
+ id: string;
33
33
  };