@mysten/kiosk 0.2.0 → 0.3.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.
- package/CHANGELOG.md +26 -2
- package/README.md +31 -19
- package/dist/bcs.d.ts +1 -32
- package/dist/constants.d.ts +4 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +192 -45
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +178 -44
- package/dist/index.mjs.map +1 -1
- package/dist/query/kiosk.d.ts +10 -52
- package/dist/query/transfer-policy.d.ts +1 -3
- package/dist/tx/kiosk.d.ts +6 -11
- package/dist/tx/transfer-policy.d.ts +8 -6
- package/dist/types/env.d.ts +13 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/kiosk.d.ts +113 -0
- package/dist/types/transfer-policy.d.ts +23 -0
- package/dist/utils.d.ts +32 -10
- package/package.json +2 -2
- package/src/bcs.ts +11 -40
- package/src/constants.ts +10 -0
- package/src/index.ts +2 -0
- package/src/query/kiosk.ts +72 -61
- package/src/query/transfer-policy.ts +8 -10
- package/src/tx/kiosk.ts +65 -28
- package/src/tx/transfer-policy.ts +40 -14
- package/src/types/env.ts +22 -0
- package/src/types/index.ts +21 -0
- package/src/types/kiosk.ts +139 -0
- package/src/types/transfer-policy.ts +33 -0
- package/src/utils.ts +74 -20
package/src/constants.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/** The Transer Policy Rules package address on testnet */
|
|
5
|
+
export const TESTNET_RULES_PACKAGE_ADDRESS =
|
|
6
|
+
'bd8fc1947cf119350184107a3087e2dc27efefa0dd82e25a1f699069fe81a585';
|
|
7
|
+
|
|
8
|
+
/** The transfer policy rules package address on mainnet */
|
|
9
|
+
export const MAINNET_RULES_PACKAGE_ADDRESS =
|
|
10
|
+
'0x434b5bd8f6a7b05fede0ff46c6e511d71ea326ed38056e3bcd681d2d7c2a7879';
|
package/src/index.ts
CHANGED
package/src/query/kiosk.ts
CHANGED
|
@@ -4,72 +4,27 @@
|
|
|
4
4
|
import {
|
|
5
5
|
JsonRpcProvider,
|
|
6
6
|
ObjectId,
|
|
7
|
-
ObjectType,
|
|
8
7
|
PaginationArguments,
|
|
9
8
|
SuiAddress,
|
|
9
|
+
SuiObjectData,
|
|
10
|
+
SuiObjectResponse,
|
|
11
|
+
getObjectFields,
|
|
12
|
+
isValidSuiAddress,
|
|
10
13
|
} from '@mysten/sui.js';
|
|
11
14
|
import {
|
|
12
15
|
attachListingsAndPrices,
|
|
13
16
|
attachLockedItems,
|
|
14
17
|
extractKioskData,
|
|
18
|
+
getAllDynamicFields,
|
|
15
19
|
getKioskObject,
|
|
16
20
|
} from '../utils';
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
/** The ID of the Item */
|
|
25
|
-
objectId: ObjectId;
|
|
26
|
-
/**
|
|
27
|
-
* Whether or not there's a `PurchaseCap` issued. `true` means that
|
|
28
|
-
* the listing is controlled by some logic and can't be purchased directly.
|
|
29
|
-
*
|
|
30
|
-
* TODO: consider renaming the field for better indication.
|
|
31
|
-
*/
|
|
32
|
-
isExclusive: boolean;
|
|
33
|
-
/** The ID of the listing */
|
|
34
|
-
listingId: ObjectId;
|
|
35
|
-
price?: string;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* A dynamic field `Item { ID }` attached to the Kiosk.
|
|
40
|
-
* Holds an Item `T`. The type of the item is known upfront.
|
|
41
|
-
*/
|
|
42
|
-
export type KioskItem = {
|
|
43
|
-
/** The ID of the Item */
|
|
44
|
-
objectId: ObjectId;
|
|
45
|
-
/** The type of the Item */
|
|
46
|
-
type: ObjectType;
|
|
47
|
-
/** Whether the item is Locked (there must be a `Lock` Dynamic Field) */
|
|
48
|
-
isLocked: boolean;
|
|
49
|
-
/** Optional listing */
|
|
50
|
-
listing?: KioskListing;
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Aggregated data from the Kiosk.
|
|
54
|
-
*/
|
|
55
|
-
export type KioskData = {
|
|
56
|
-
items: KioskItem[];
|
|
57
|
-
itemIds: ObjectId[];
|
|
58
|
-
listingIds: ObjectId[];
|
|
59
|
-
kiosk?: Kiosk;
|
|
60
|
-
extensions: any[]; // type will be defined on later versions of the SDK.
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export type PagedKioskData = {
|
|
64
|
-
data: KioskData;
|
|
65
|
-
nextCursor: string | null;
|
|
66
|
-
hasNextPage: boolean;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export type FetchKioskOptions = {
|
|
70
|
-
withKioskFields?: boolean;
|
|
71
|
-
withListingPrices?: boolean;
|
|
72
|
-
};
|
|
21
|
+
import {
|
|
22
|
+
FetchKioskOptions,
|
|
23
|
+
KIOSK_OWNER_CAP,
|
|
24
|
+
KioskListing,
|
|
25
|
+
OwnedKiosks,
|
|
26
|
+
PagedKioskData,
|
|
27
|
+
} from '../types';
|
|
73
28
|
|
|
74
29
|
export async function fetchKiosk(
|
|
75
30
|
provider: JsonRpcProvider,
|
|
@@ -77,10 +32,11 @@ export async function fetchKiosk(
|
|
|
77
32
|
pagination: PaginationArguments<string>,
|
|
78
33
|
options: FetchKioskOptions,
|
|
79
34
|
): Promise<PagedKioskData> {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
35
|
+
// TODO: Replace the `getAllDynamicFields` with a paginated
|
|
36
|
+
// response, once we have better RPC support for
|
|
37
|
+
// type filtering & batch fetching.
|
|
38
|
+
// This can't work with pagination currently.
|
|
39
|
+
const data = await getAllDynamicFields(provider, kioskId, pagination);
|
|
84
40
|
|
|
85
41
|
const listings: KioskListing[] = [];
|
|
86
42
|
const lockedItemIds: ObjectId[] = [];
|
|
@@ -113,7 +69,62 @@ export async function fetchKiosk(
|
|
|
113
69
|
|
|
114
70
|
return {
|
|
115
71
|
data: kioskData,
|
|
72
|
+
nextCursor: null,
|
|
73
|
+
hasNextPage: false,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* A function to fetch all the user's kiosk Caps
|
|
79
|
+
* And a list of the kiosk address ids.
|
|
80
|
+
* Returns a list of `kioskOwnerCapIds` and `kioskIds`.
|
|
81
|
+
* Extra options allow pagination.
|
|
82
|
+
*/
|
|
83
|
+
export async function getOwnedKiosks(
|
|
84
|
+
provider: JsonRpcProvider,
|
|
85
|
+
address: SuiAddress,
|
|
86
|
+
options?: {
|
|
87
|
+
pagination?: PaginationArguments<string>;
|
|
88
|
+
},
|
|
89
|
+
): Promise<OwnedKiosks> {
|
|
90
|
+
if (!isValidSuiAddress(address))
|
|
91
|
+
return {
|
|
92
|
+
nextCursor: null,
|
|
93
|
+
hasNextPage: false,
|
|
94
|
+
kioskOwnerCaps: [],
|
|
95
|
+
kioskIds: [],
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// fetch owned kiosk caps, paginated.
|
|
99
|
+
const { data, hasNextPage, nextCursor } = await provider.getOwnedObjects({
|
|
100
|
+
owner: address,
|
|
101
|
+
filter: { StructType: KIOSK_OWNER_CAP },
|
|
102
|
+
options: {
|
|
103
|
+
showContent: true,
|
|
104
|
+
},
|
|
105
|
+
...(options?.pagination || {}),
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// get kioskIds from the OwnerCaps.
|
|
109
|
+
const kioskIdList = data?.map(
|
|
110
|
+
(x: SuiObjectResponse) => getObjectFields(x)?.for,
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
// clean up data that might have an error in them.
|
|
114
|
+
// only return valid objects.
|
|
115
|
+
const filteredData = data
|
|
116
|
+
.filter((x) => 'data' in x)
|
|
117
|
+
.map((x) => x.data) as SuiObjectData[];
|
|
118
|
+
|
|
119
|
+
return {
|
|
116
120
|
nextCursor,
|
|
117
121
|
hasNextPage,
|
|
122
|
+
kioskOwnerCaps: filteredData.map((x, idx) => ({
|
|
123
|
+
digest: x.digest,
|
|
124
|
+
version: x.version,
|
|
125
|
+
objectId: x.objectId,
|
|
126
|
+
kioskId: kioskIdList[idx],
|
|
127
|
+
})),
|
|
128
|
+
kioskIds: kioskIdList,
|
|
118
129
|
};
|
|
119
130
|
}
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { JsonRpcProvider } from '@mysten/sui.js';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
import { bcs } from '../bcs';
|
|
6
|
+
import {
|
|
7
|
+
TRANSFER_POLICY_CREATED_EVENT,
|
|
8
|
+
TRANSFER_POLICY_TYPE,
|
|
9
|
+
TransferPolicy,
|
|
10
|
+
} from '../types';
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
13
|
* Searches the `TransferPolicy`-s for the given type. The seach is performed via
|
|
@@ -44,15 +46,11 @@ export async function queryTransferPolicy(
|
|
|
44
46
|
);
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
let parsed = bcs.de(
|
|
48
|
-
'0x2::transfer_policy::TransferPolicy',
|
|
49
|
-
policy.bcs.bcsBytes,
|
|
50
|
-
'base64',
|
|
51
|
-
);
|
|
49
|
+
let parsed = bcs.de(TRANSFER_POLICY_TYPE, policy.bcs.bcsBytes, 'base64');
|
|
52
50
|
|
|
53
51
|
return {
|
|
54
52
|
id: policy?.objectId,
|
|
55
|
-
type:
|
|
53
|
+
type: `${TRANSFER_POLICY_TYPE}<${type}>`,
|
|
56
54
|
owner: policy?.owner!,
|
|
57
55
|
rules: parsed.rules,
|
|
58
56
|
balance: parsed.balance,
|
package/src/tx/kiosk.ts
CHANGED
|
@@ -7,19 +7,23 @@ import {
|
|
|
7
7
|
TransactionBlock,
|
|
8
8
|
} from '@mysten/sui.js';
|
|
9
9
|
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
10
|
+
import { getTypeWithoutPackageAddress, objArg } from '../utils';
|
|
11
|
+
import {
|
|
12
|
+
confirmRequest,
|
|
13
|
+
resolveKioskLockRule,
|
|
14
|
+
resolveRoyaltyRule,
|
|
15
|
+
} from './transfer-policy';
|
|
16
|
+
import {
|
|
17
|
+
KIOSK_LOCK_RULE,
|
|
18
|
+
KIOSK_MODULE,
|
|
19
|
+
KIOSK_TYPE,
|
|
20
|
+
ObjectArgument,
|
|
21
|
+
PurchaseAndResolvePoliciesResponse,
|
|
22
|
+
PurchaseOptionalParams,
|
|
23
|
+
ROYALTY_RULE,
|
|
24
|
+
RulesEnvironmentParam,
|
|
25
|
+
TransferPolicy,
|
|
26
|
+
} from '../types';
|
|
23
27
|
|
|
24
28
|
/**
|
|
25
29
|
* Create a new shared Kiosk and returns the [kiosk, kioskOwnerCap] tuple.
|
|
@@ -228,7 +232,12 @@ export function withdrawFromKiosk(
|
|
|
228
232
|
): TransactionArgument {
|
|
229
233
|
let amountArg =
|
|
230
234
|
amount !== null
|
|
231
|
-
? tx.pure(
|
|
235
|
+
? tx.pure(
|
|
236
|
+
{
|
|
237
|
+
Some: amount,
|
|
238
|
+
},
|
|
239
|
+
'Option<u64>',
|
|
240
|
+
)
|
|
232
241
|
: tx.pure({ None: true }, 'Option<u64>');
|
|
233
242
|
|
|
234
243
|
let [coin] = tx.moveCall({
|
|
@@ -335,46 +344,71 @@ export function returnValue(
|
|
|
335
344
|
* Completes the full purchase flow that includes:
|
|
336
345
|
* 1. Purchasing the item.
|
|
337
346
|
* 2. Resolving all the transfer policies (if any).
|
|
338
|
-
* 3. Returns the
|
|
347
|
+
* 3. Returns the item and whether the user can transfer it or not.
|
|
348
|
+
*
|
|
349
|
+
* If the item can be transferred, there's an extra transaction required by the user
|
|
350
|
+
* to transfer it to an address or place it in their kiosk.
|
|
339
351
|
*/
|
|
340
352
|
export function purchaseAndResolvePolicies(
|
|
341
353
|
tx: TransactionBlock,
|
|
342
354
|
itemType: string,
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
itemId:
|
|
355
|
+
price: string,
|
|
356
|
+
kiosk: ObjectArgument,
|
|
357
|
+
itemId: SuiAddress,
|
|
346
358
|
policy: TransferPolicy,
|
|
347
|
-
|
|
359
|
+
environment: RulesEnvironmentParam,
|
|
360
|
+
extraParams?: PurchaseOptionalParams,
|
|
361
|
+
): PurchaseAndResolvePoliciesResponse {
|
|
348
362
|
// if we don't pass the listing or the listing doens't have a price, return.
|
|
349
|
-
if (
|
|
363
|
+
if (price === undefined || typeof price !== 'string')
|
|
364
|
+
throw new Error(`Price of the listing is not supplied.`);
|
|
350
365
|
|
|
351
366
|
// Split the coin for the amount of the listing.
|
|
352
|
-
const coin = tx.splitCoins(tx.gas, [tx.pure(
|
|
367
|
+
const coin = tx.splitCoins(tx.gas, [tx.pure(price, 'u64')]);
|
|
353
368
|
|
|
354
369
|
// initialize the purchase `kiosk::purchase`
|
|
355
370
|
const [purchasedItem, transferRequest] = purchase(
|
|
356
371
|
tx,
|
|
357
372
|
itemType,
|
|
358
|
-
|
|
373
|
+
kiosk,
|
|
359
374
|
itemId,
|
|
360
375
|
coin,
|
|
361
376
|
);
|
|
362
377
|
|
|
363
378
|
// Start resolving rules.
|
|
364
|
-
//
|
|
365
|
-
//
|
|
366
|
-
|
|
379
|
+
// Right now we support `kiosk_lock_rule` and `royalty_rule`.
|
|
380
|
+
// They can also be supplied in parallel (supports combination).
|
|
381
|
+
let hasKioskLockRule = false;
|
|
382
|
+
|
|
367
383
|
for (let rule of policy.rules) {
|
|
368
384
|
const ruleWithoutAddr = getTypeWithoutPackageAddress(rule);
|
|
369
385
|
|
|
370
386
|
switch (ruleWithoutAddr) {
|
|
371
|
-
case
|
|
387
|
+
case ROYALTY_RULE:
|
|
372
388
|
resolveRoyaltyRule(
|
|
373
389
|
tx,
|
|
374
390
|
itemType,
|
|
375
|
-
|
|
391
|
+
price,
|
|
392
|
+
policy.id,
|
|
393
|
+
transferRequest,
|
|
394
|
+
environment,
|
|
395
|
+
);
|
|
396
|
+
break;
|
|
397
|
+
case KIOSK_LOCK_RULE:
|
|
398
|
+
if (!extraParams?.ownedKiosk || !extraParams?.ownedKioskCap)
|
|
399
|
+
throw new Error(
|
|
400
|
+
`This item type ${itemType} has a 'kiosk_lock_rule', but function call is missing user's kiosk and kioskCap params`,
|
|
401
|
+
);
|
|
402
|
+
hasKioskLockRule = true;
|
|
403
|
+
resolveKioskLockRule(
|
|
404
|
+
tx,
|
|
405
|
+
itemType,
|
|
406
|
+
purchasedItem,
|
|
407
|
+
extraParams.ownedKiosk,
|
|
408
|
+
extraParams.ownedKioskCap,
|
|
376
409
|
policy.id,
|
|
377
410
|
transferRequest,
|
|
411
|
+
environment,
|
|
378
412
|
);
|
|
379
413
|
break;
|
|
380
414
|
default:
|
|
@@ -385,5 +419,8 @@ export function purchaseAndResolvePolicies(
|
|
|
385
419
|
// confirm the Transfer Policy request.
|
|
386
420
|
confirmRequest(tx, itemType, policy.id, transferRequest);
|
|
387
421
|
|
|
388
|
-
return
|
|
422
|
+
return {
|
|
423
|
+
item: purchasedItem,
|
|
424
|
+
canTransfer: !hasKioskLockRule,
|
|
425
|
+
};
|
|
389
426
|
}
|
|
@@ -2,15 +2,14 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { TransactionArgument, TransactionBlock } from '@mysten/sui.js';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
'bd8fc1947cf119350184107a3087e2dc27efefa0dd82e25a1f699069fe81a585';
|
|
5
|
+
import { getRulePackageAddress, objArg } from '../utils';
|
|
6
|
+
import { lock } from './kiosk';
|
|
7
|
+
import {
|
|
8
|
+
ObjectArgument,
|
|
9
|
+
RulesEnvironmentParam,
|
|
10
|
+
TRANSFER_POLICY_MODULE,
|
|
11
|
+
TRANSFER_POLICY_TYPE,
|
|
12
|
+
} from '../types';
|
|
14
13
|
|
|
15
14
|
/**
|
|
16
15
|
* Call the `transfer_policy::new` function to create a new transfer policy.
|
|
@@ -29,7 +28,7 @@ export function createTransferPolicy(
|
|
|
29
28
|
|
|
30
29
|
tx.moveCall({
|
|
31
30
|
target: `0x2::transfer::public_share_object`,
|
|
32
|
-
typeArguments: [itemType],
|
|
31
|
+
typeArguments: [`${TRANSFER_POLICY_TYPE}<${itemType}>`],
|
|
33
32
|
arguments: [transferPolicy],
|
|
34
33
|
});
|
|
35
34
|
|
|
@@ -48,7 +47,7 @@ export function withdrawFromPolicy(
|
|
|
48
47
|
): TransactionArgument {
|
|
49
48
|
let amountArg =
|
|
50
49
|
amount !== null
|
|
51
|
-
? tx.pure(amount, 'Option<u64>')
|
|
50
|
+
? tx.pure({ Some: amount }, 'Option<u64>')
|
|
52
51
|
: tx.pure({ None: true }, 'Option<u64>');
|
|
53
52
|
|
|
54
53
|
let [profits] = tx.moveCall({
|
|
@@ -104,13 +103,14 @@ export function resolveRoyaltyRule(
|
|
|
104
103
|
tx: TransactionBlock,
|
|
105
104
|
itemType: string,
|
|
106
105
|
price: string,
|
|
107
|
-
policyId:
|
|
106
|
+
policyId: ObjectArgument,
|
|
108
107
|
transferRequest: TransactionArgument,
|
|
108
|
+
environment: RulesEnvironmentParam,
|
|
109
109
|
) {
|
|
110
110
|
const policyObj = objArg(tx, policyId);
|
|
111
111
|
// calculates the amount
|
|
112
112
|
const [amount] = tx.moveCall({
|
|
113
|
-
target: `${
|
|
113
|
+
target: `${getRulePackageAddress(environment)}::royalty_rule::fee_amount`,
|
|
114
114
|
typeArguments: [itemType],
|
|
115
115
|
arguments: [policyObj, objArg(tx, price)],
|
|
116
116
|
});
|
|
@@ -120,8 +120,34 @@ export function resolveRoyaltyRule(
|
|
|
120
120
|
|
|
121
121
|
// pays the policy
|
|
122
122
|
tx.moveCall({
|
|
123
|
-
target: `${
|
|
123
|
+
target: `${getRulePackageAddress(environment)}::royalty_rule::pay`,
|
|
124
124
|
typeArguments: [itemType],
|
|
125
125
|
arguments: [policyObj, transferRequest, feeCoin],
|
|
126
126
|
});
|
|
127
127
|
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Locks the item in the supplied kiosk and
|
|
131
|
+
* proves to the `kiosk_lock` rule that the item was indeed locked,
|
|
132
|
+
* by calling the `kiosk_lock_rule::prove` function to resolve it.
|
|
133
|
+
*/
|
|
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,
|
|
143
|
+
) {
|
|
144
|
+
// lock item in the kiosk.
|
|
145
|
+
lock(tx, itemType, kiosk, kioskCap, policyId, item);
|
|
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
|
+
});
|
|
153
|
+
}
|
package/src/types/env.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { SuiAddress } from '@mysten/sui.js';
|
|
5
|
+
|
|
6
|
+
/* A list of environments. */
|
|
7
|
+
export type Environment = 'mainnet' | 'testnet' | 'devnet' | 'custom';
|
|
8
|
+
|
|
9
|
+
/** A Parameter to support enivronments for rules. */
|
|
10
|
+
export type RulesEnvironmentParam = { env: Environment; address?: SuiAddress };
|
|
11
|
+
|
|
12
|
+
/** A default Testnet Environment object */
|
|
13
|
+
export const testnetEnvironment: RulesEnvironmentParam = { env: 'testnet' };
|
|
14
|
+
|
|
15
|
+
/** A default Mainnet Environment object */
|
|
16
|
+
export const mainnetEnvironment: RulesEnvironmentParam = { env: 'mainnet' };
|
|
17
|
+
|
|
18
|
+
/** A helper to easily export a custom environment */
|
|
19
|
+
export const customEnvironment = (address: string): RulesEnvironmentParam => ({
|
|
20
|
+
env: 'custom',
|
|
21
|
+
address,
|
|
22
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
SharedObjectRef,
|
|
6
|
+
SuiObjectRef,
|
|
7
|
+
TransactionArgument,
|
|
8
|
+
} from '@mysten/sui.js';
|
|
9
|
+
|
|
10
|
+
export * from './kiosk';
|
|
11
|
+
export * from './transfer-policy';
|
|
12
|
+
export * from './env';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A valid argument for any of the Kiosk functions.
|
|
16
|
+
*/
|
|
17
|
+
export type ObjectArgument =
|
|
18
|
+
| string
|
|
19
|
+
| TransactionArgument
|
|
20
|
+
| SharedObjectRef
|
|
21
|
+
| SuiObjectRef;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
ObjectDigest,
|
|
6
|
+
ObjectId,
|
|
7
|
+
ObjectType,
|
|
8
|
+
PaginatedObjectsResponse,
|
|
9
|
+
TransactionArgument,
|
|
10
|
+
} from '@mysten/sui.js';
|
|
11
|
+
import { ObjectArgument } from '.';
|
|
12
|
+
|
|
13
|
+
/** The Kiosk module. */
|
|
14
|
+
export const KIOSK_MODULE = '0x2::kiosk';
|
|
15
|
+
|
|
16
|
+
/** The Kiosk type. */
|
|
17
|
+
export const KIOSK_TYPE = `${KIOSK_MODULE}::Kiosk`;
|
|
18
|
+
|
|
19
|
+
/** The Kiosk Owner Cap Type */
|
|
20
|
+
export const KIOSK_OWNER_CAP = `${KIOSK_MODULE}::KioskOwnerCap`;
|
|
21
|
+
|
|
22
|
+
/** The Kiosk Item Type */
|
|
23
|
+
export const KIOSK_ITEM = `${KIOSK_MODULE}::Item`;
|
|
24
|
+
|
|
25
|
+
/** The Kiosk Listing Type */
|
|
26
|
+
export const KIOSK_LISTING = `${KIOSK_MODULE}::Listing`;
|
|
27
|
+
|
|
28
|
+
/** The Kiosk Lock Type */
|
|
29
|
+
export const KIOSK_LOCK = `${KIOSK_MODULE}::Lock`;
|
|
30
|
+
|
|
31
|
+
/** The Kiosk PurchaseCap type */
|
|
32
|
+
export const KIOSK_PURCHASE_CAP = `${KIOSK_MODULE}::PurchaseCap`;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The Kiosk object fields (for BCS queries).
|
|
36
|
+
*/
|
|
37
|
+
export type Kiosk = {
|
|
38
|
+
id: string;
|
|
39
|
+
profits: string;
|
|
40
|
+
owner: string;
|
|
41
|
+
itemCount: number;
|
|
42
|
+
allowExtensions: boolean;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* PurchaseCap object fields (for BCS queries).
|
|
47
|
+
*/
|
|
48
|
+
export type PurchaseCap = {
|
|
49
|
+
id: string;
|
|
50
|
+
kioskId: string;
|
|
51
|
+
itemId: string;
|
|
52
|
+
minPrice: string;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The response type of a successful purchase flow.
|
|
57
|
+
* Returns the item, and a `canTransfer` param.
|
|
58
|
+
*/
|
|
59
|
+
export type PurchaseAndResolvePoliciesResponse = {
|
|
60
|
+
item: TransactionArgument;
|
|
61
|
+
canTransfer: boolean;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Optional parameters for `purchaseAndResolvePolicies` flow.
|
|
66
|
+
* This gives us the chance to extend the function in further releases
|
|
67
|
+
* without introducing more breaking changes.
|
|
68
|
+
*/
|
|
69
|
+
export type PurchaseOptionalParams = {
|
|
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;
|
|
139
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { ObjectOwner } from '@mysten/sui.js';
|
|
5
|
+
|
|
6
|
+
/** The Transfer Policy module. */
|
|
7
|
+
export const TRANSFER_POLICY_MODULE = '0x2::transfer_policy';
|
|
8
|
+
|
|
9
|
+
/** Name of the event emitted when a TransferPolicy for T is created. */
|
|
10
|
+
export const TRANSFER_POLICY_CREATED_EVENT = `${TRANSFER_POLICY_MODULE}::TransferPolicyCreated`;
|
|
11
|
+
|
|
12
|
+
/** The Transfer Policy Type */
|
|
13
|
+
export const TRANSFER_POLICY_TYPE = `${TRANSFER_POLICY_MODULE}::TransferPolicy`;
|
|
14
|
+
|
|
15
|
+
/** The Kiosk Lock Rule */
|
|
16
|
+
export const KIOSK_LOCK_RULE = 'kiosk_lock_rule::Rule';
|
|
17
|
+
|
|
18
|
+
/** The Royalty rule */
|
|
19
|
+
export const ROYALTY_RULE = 'royalty_rule::Rule';
|
|
20
|
+
|
|
21
|
+
/** The `TransferPolicy` object */
|
|
22
|
+
export type TransferPolicy = {
|
|
23
|
+
id: string;
|
|
24
|
+
type: string;
|
|
25
|
+
balance: string;
|
|
26
|
+
rules: string[];
|
|
27
|
+
owner: ObjectOwner;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/** Event emitted when a TransferPolicy is created. */
|
|
31
|
+
export type TransferPolicyCreated = {
|
|
32
|
+
id: string;
|
|
33
|
+
};
|