@mysten/kiosk 0.0.0-experimental-20230615203750 → 0.0.0-experimental-20230618180151

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,10 +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,
11
- TRANSFER_POLICY_TYPE,
8
+ ObjectArgument,
9
+ RulesEnvironmentParam,
10
+ TRANSFER_POLICY_MODULE,
11
+ TRANSFER_POLICY_TYPE,
12
12
  } from '../types';
13
13
 
14
14
  /**
@@ -16,47 +16,47 @@ import {
16
16
  * Returns `transferPolicyCap`
17
17
  */
18
18
  export function createTransferPolicy(
19
- tx: TransactionBlock,
20
- itemType: string,
21
- publisher: ObjectArgument,
19
+ tx: TransactionBlock,
20
+ itemType: string,
21
+ publisher: ObjectArgument,
22
22
  ): TransactionArgument {
23
- let [transferPolicy, transferPolicyCap] = tx.moveCall({
24
- target: `${TRANSFER_POLICY_MODULE}::new`,
25
- typeArguments: [itemType],
26
- arguments: [objArg(tx, publisher)],
27
- });
23
+ let [transferPolicy, transferPolicyCap] = tx.moveCall({
24
+ target: `${TRANSFER_POLICY_MODULE}::new`,
25
+ typeArguments: [itemType],
26
+ arguments: [objArg(tx, publisher)],
27
+ });
28
28
 
29
- tx.moveCall({
30
- target: `0x2::transfer::public_share_object`,
31
- typeArguments: [`${TRANSFER_POLICY_TYPE}<${itemType}>`],
32
- arguments: [transferPolicy],
33
- });
29
+ tx.moveCall({
30
+ target: `0x2::transfer::public_share_object`,
31
+ typeArguments: [`${TRANSFER_POLICY_TYPE}<${itemType}>`],
32
+ arguments: [transferPolicy],
33
+ });
34
34
 
35
- return transferPolicyCap;
35
+ return transferPolicyCap;
36
36
  }
37
37
 
38
38
  /**
39
39
  * Call the `transfer_policy::withdraw` function to withdraw profits from a transfer policy.
40
40
  */
41
41
  export function withdrawFromPolicy(
42
- tx: TransactionBlock,
43
- itemType: string,
44
- policy: ObjectArgument,
45
- policyCap: ObjectArgument,
46
- amount: string | bigint | null,
42
+ tx: TransactionBlock,
43
+ itemType: string,
44
+ policy: ObjectArgument,
45
+ policyCap: ObjectArgument,
46
+ amount: string | bigint | null,
47
47
  ): TransactionArgument {
48
- let amountArg =
49
- amount !== null
50
- ? tx.pure({ Some: amount }, 'Option<u64>')
51
- : 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>');
52
52
 
53
- let [profits] = tx.moveCall({
54
- target: `${TRANSFER_POLICY_MODULE}::withdraw`,
55
- typeArguments: [itemType],
56
- arguments: [objArg(tx, policy), objArg(tx, policyCap), amountArg],
57
- });
53
+ let [profits] = tx.moveCall({
54
+ target: `${TRANSFER_POLICY_MODULE}::withdraw`,
55
+ typeArguments: [itemType],
56
+ arguments: [objArg(tx, policy), objArg(tx, policyCap), amountArg],
57
+ });
58
58
 
59
- return profits;
59
+ return profits;
60
60
  }
61
61
 
62
62
  /**
@@ -64,34 +64,34 @@ export function withdrawFromPolicy(
64
64
  * transaction.
65
65
  */
66
66
  export function confirmRequest(
67
- tx: TransactionBlock,
68
- itemType: string,
69
- policy: ObjectArgument,
70
- request: TransactionArgument,
67
+ tx: TransactionBlock,
68
+ itemType: string,
69
+ policy: ObjectArgument,
70
+ request: TransactionArgument,
71
71
  ): void {
72
- tx.moveCall({
73
- target: `${TRANSFER_POLICY_MODULE}::confirm_request`,
74
- typeArguments: [itemType],
75
- arguments: [objArg(tx, policy), request],
76
- });
72
+ tx.moveCall({
73
+ target: `${TRANSFER_POLICY_MODULE}::confirm_request`,
74
+ typeArguments: [itemType],
75
+ arguments: [objArg(tx, policy), request],
76
+ });
77
77
  }
78
78
 
79
79
  /**
80
80
  * Calls the `transfer_policy::remove_rule` function to remove a Rule from the transfer policy's ruleset.
81
81
  */
82
82
  export function removeTransferPolicyRule(
83
- tx: TransactionBlock,
84
- itemType: string,
85
- ruleType: string,
86
- configType: string,
87
- policy: ObjectArgument,
88
- policyCap: TransactionArgument,
83
+ tx: TransactionBlock,
84
+ itemType: string,
85
+ ruleType: string,
86
+ configType: string,
87
+ policy: ObjectArgument,
88
+ policyCap: TransactionArgument,
89
89
  ): void {
90
- tx.moveCall({
91
- target: `${TRANSFER_POLICY_MODULE}::remove_rule`,
92
- typeArguments: [itemType, ruleType, configType],
93
- arguments: [objArg(tx, policy), policyCap],
94
- });
90
+ tx.moveCall({
91
+ target: `${TRANSFER_POLICY_MODULE}::remove_rule`,
92
+ typeArguments: [itemType, ruleType, configType],
93
+ arguments: [objArg(tx, policy), policyCap],
94
+ });
95
95
  }
96
96
 
97
97
  /**
@@ -100,30 +100,30 @@ export function removeTransferPolicyRule(
100
100
  * then calls the `royalty_rule::pay` function to resolve the royalty rule.
101
101
  */
102
102
  export function resolveRoyaltyRule(
103
- tx: TransactionBlock,
104
- itemType: string,
105
- price: string,
106
- policyId: ObjectArgument,
107
- transferRequest: TransactionArgument,
108
- environment: RulesEnvironmentParam,
103
+ tx: TransactionBlock,
104
+ itemType: string,
105
+ price: string,
106
+ policyId: ObjectArgument,
107
+ transferRequest: TransactionArgument,
108
+ environment: RulesEnvironmentParam,
109
109
  ) {
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
- });
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
+ });
117
117
 
118
- // splits the coin.
119
- const feeCoin = tx.splitCoins(tx.gas, [amount]);
118
+ // splits the coin.
119
+ const feeCoin = tx.splitCoins(tx.gas, [amount]);
120
120
 
121
- // pays the policy
122
- tx.moveCall({
123
- target: `${getRulePackageAddress(environment)}::royalty_rule::pay`,
124
- typeArguments: [itemType],
125
- arguments: [policyObj, transferRequest, feeCoin],
126
- });
121
+ // pays the policy
122
+ tx.moveCall({
123
+ target: `${getRulePackageAddress(environment)}::royalty_rule::pay`,
124
+ typeArguments: [itemType],
125
+ arguments: [policyObj, transferRequest, feeCoin],
126
+ });
127
127
  }
128
128
 
129
129
  /**
@@ -132,22 +132,22 @@ export function resolveRoyaltyRule(
132
132
  * by calling the `kiosk_lock_rule::prove` function to resolve it.
133
133
  */
134
134
  export function resolveKioskLockRule(
135
- tx: TransactionBlock,
136
- itemType: string,
137
- item: TransactionArgument,
138
- kiosk: ObjectArgument,
139
- kioskCap: ObjectArgument,
140
- policyId: ObjectArgument,
141
- transferRequest: TransactionArgument,
142
- 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,
143
143
  ) {
144
- // lock item in the kiosk.
145
- lock(tx, itemType, kiosk, kioskCap, policyId, item);
144
+ // lock item in the kiosk.
145
+ lock(tx, itemType, kiosk, kioskCap, policyId, item);
146
146
 
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
- });
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
+ });
153
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;
@@ -2,11 +2,11 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import {
5
- ObjectDigest,
6
- ObjectId,
7
- ObjectType,
8
- PaginatedObjectsResponse,
9
- TransactionArgument,
5
+ ObjectDigest,
6
+ ObjectId,
7
+ ObjectType,
8
+ PaginatedObjectsResponse,
9
+ TransactionArgument,
10
10
  } from '@mysten/sui.js';
11
11
  import { ObjectArgument } from '.';
12
12
 
@@ -35,21 +35,21 @@ export const KIOSK_PURCHASE_CAP = `${KIOSK_MODULE}::PurchaseCap`;
35
35
  * The Kiosk object fields (for BCS queries).
36
36
  */
37
37
  export type Kiosk = {
38
- id: string;
39
- profits: string;
40
- owner: string;
41
- itemCount: number;
42
- allowExtensions: boolean;
38
+ id: string;
39
+ profits: string;
40
+ owner: string;
41
+ itemCount: number;
42
+ allowExtensions: boolean;
43
43
  };
44
44
 
45
45
  /**
46
46
  * PurchaseCap object fields (for BCS queries).
47
47
  */
48
48
  export type PurchaseCap = {
49
- id: string;
50
- kioskId: string;
51
- itemId: string;
52
- minPrice: string;
49
+ id: string;
50
+ kioskId: string;
51
+ itemId: string;
52
+ minPrice: string;
53
53
  };
54
54
 
55
55
  /**
@@ -57,8 +57,8 @@ export type PurchaseCap = {
57
57
  * Returns the item, and a `canTransfer` param.
58
58
  */
59
59
  export type PurchaseAndResolvePoliciesResponse = {
60
- item: TransactionArgument;
61
- canTransfer: boolean;
60
+ item: TransactionArgument;
61
+ canTransfer: boolean;
62
62
  };
63
63
 
64
64
  /**
@@ -67,8 +67,8 @@ export type PurchaseAndResolvePoliciesResponse = {
67
67
  * without introducing more breaking changes.
68
68
  */
69
69
  export type PurchaseOptionalParams = {
70
- ownedKiosk?: ObjectArgument;
71
- ownedKioskCap?: ObjectArgument;
70
+ ownedKiosk?: ObjectArgument;
71
+ ownedKioskCap?: ObjectArgument;
72
72
  };
73
73
 
74
74
  /**
@@ -76,18 +76,18 @@ export type PurchaseOptionalParams = {
76
76
  * Holds a `u64` value - the price of the item.
77
77
  */
78
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;
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
91
  };
92
92
 
93
93
  /**
@@ -95,45 +95,45 @@ export type KioskListing = {
95
95
  * Holds an Item `T`. The type of the item is known upfront.
96
96
  */
97
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;
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
106
  };
107
107
  /**
108
108
  * Aggregated data from the Kiosk.
109
109
  */
110
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.
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
116
  };
117
117
 
118
118
  export type PagedKioskData = {
119
- data: KioskData;
120
- nextCursor: string | null;
121
- hasNextPage: boolean;
119
+ data: KioskData;
120
+ nextCursor: string | null;
121
+ hasNextPage: boolean;
122
122
  };
123
123
 
124
124
  export type FetchKioskOptions = {
125
- withKioskFields?: boolean;
126
- withListingPrices?: boolean;
125
+ withKioskFields?: boolean;
126
+ withListingPrices?: boolean;
127
127
  };
128
128
 
129
129
  export type OwnedKiosks = {
130
- kioskOwnerCaps: KioskOwnerCap[];
131
- kioskIds: ObjectId[];
130
+ kioskOwnerCaps: KioskOwnerCap[];
131
+ kioskIds: ObjectId[];
132
132
  } & Omit<PaginatedObjectsResponse, 'data'>;
133
133
 
134
134
  export type KioskOwnerCap = {
135
- objectId: ObjectId;
136
- kioskId: ObjectId;
137
- digest: ObjectDigest;
138
- version: string;
135
+ objectId: ObjectId;
136
+ kioskId: ObjectId;
137
+ digest: ObjectDigest;
138
+ version: string;
139
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
  };