@mysten/kiosk 0.3.3 → 0.4.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 +31 -0
- package/README.md +15 -14
- package/dist/bcs.d.ts +1 -1
- package/dist/index.js +29 -28
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +21 -25
- package/dist/index.mjs.map +1 -1
- package/dist/query/kiosk.d.ts +3 -3
- package/dist/query/transfer-policy.d.ts +2 -2
- package/dist/tx/kiosk.d.ts +9 -9
- package/dist/tx/transfer-policy.d.ts +1 -1
- package/dist/types/env.d.ts +2 -3
- package/dist/types/index.d.ts +3 -1
- package/dist/types/kiosk.d.ts +13 -12
- package/dist/types/transfer-policy.d.ts +1 -1
- package/dist/utils.d.ts +8 -16
- package/package.json +4 -4
- package/src/bcs.ts +1 -1
- package/src/query/kiosk.ts +16 -20
- package/src/query/transfer-policy.ts +4 -4
- package/src/tx/kiosk.ts +9 -9
- package/src/tx/transfer-policy.ts +1 -1
- package/src/types/env.ts +2 -4
- package/src/types/index.ts +3 -1
- package/src/types/kiosk.ts +13 -18
- package/src/types/transfer-policy.ts +1 -1
- package/src/utils.ts +22 -27
package/src/tx/kiosk.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { TransactionBlock, TransactionArgument } from '@mysten/sui.js/transactions';
|
|
5
5
|
|
|
6
6
|
import { getTypeWithoutPackageAddress, objArg } from '../utils';
|
|
7
7
|
import { confirmRequest, resolveKioskLockRule, resolveRoyaltyRule } from './transfer-policy';
|
|
@@ -96,7 +96,7 @@ export function take(
|
|
|
96
96
|
itemType: string,
|
|
97
97
|
kiosk: ObjectArgument,
|
|
98
98
|
kioskCap: ObjectArgument,
|
|
99
|
-
itemId:
|
|
99
|
+
itemId: string,
|
|
100
100
|
): TransactionArgument {
|
|
101
101
|
let [item] = tx.moveCall({
|
|
102
102
|
target: `${KIOSK_MODULE}::take`,
|
|
@@ -116,7 +116,7 @@ export function list(
|
|
|
116
116
|
itemType: string,
|
|
117
117
|
kiosk: ObjectArgument,
|
|
118
118
|
kioskCap: ObjectArgument,
|
|
119
|
-
itemId:
|
|
119
|
+
itemId: string,
|
|
120
120
|
price: string | bigint,
|
|
121
121
|
): void {
|
|
122
122
|
tx.moveCall({
|
|
@@ -140,7 +140,7 @@ export function delist(
|
|
|
140
140
|
itemType: string,
|
|
141
141
|
kiosk: ObjectArgument,
|
|
142
142
|
kioskCap: ObjectArgument,
|
|
143
|
-
itemId:
|
|
143
|
+
itemId: string,
|
|
144
144
|
): void {
|
|
145
145
|
tx.moveCall({
|
|
146
146
|
target: `${KIOSK_MODULE}::delist`,
|
|
@@ -176,7 +176,7 @@ export function purchase(
|
|
|
176
176
|
tx: TransactionBlock,
|
|
177
177
|
itemType: string,
|
|
178
178
|
kiosk: ObjectArgument,
|
|
179
|
-
itemId:
|
|
179
|
+
itemId: string,
|
|
180
180
|
payment: ObjectArgument,
|
|
181
181
|
): [TransactionArgument, TransactionArgument] {
|
|
182
182
|
let [item, transferRequest] = tx.moveCall({
|
|
@@ -225,7 +225,7 @@ export function borrow(
|
|
|
225
225
|
itemType: string,
|
|
226
226
|
kiosk: ObjectArgument,
|
|
227
227
|
kioskCap: ObjectArgument,
|
|
228
|
-
itemId:
|
|
228
|
+
itemId: string,
|
|
229
229
|
): TransactionArgument {
|
|
230
230
|
let [item] = tx.moveCall({
|
|
231
231
|
target: `${KIOSK_MODULE}::borrow`,
|
|
@@ -245,7 +245,7 @@ export function borrowMut(
|
|
|
245
245
|
itemType: string,
|
|
246
246
|
kiosk: ObjectArgument,
|
|
247
247
|
kioskCap: ObjectArgument,
|
|
248
|
-
itemId:
|
|
248
|
+
itemId: string,
|
|
249
249
|
): TransactionArgument {
|
|
250
250
|
let [item] = tx.moveCall({
|
|
251
251
|
target: `${KIOSK_MODULE}::borrow_mut`,
|
|
@@ -267,7 +267,7 @@ export function borrowValue(
|
|
|
267
267
|
itemType: string,
|
|
268
268
|
kiosk: ObjectArgument,
|
|
269
269
|
kioskCap: ObjectArgument,
|
|
270
|
-
itemId:
|
|
270
|
+
itemId: string,
|
|
271
271
|
): [TransactionArgument, TransactionArgument] {
|
|
272
272
|
let [item, promise] = tx.moveCall({
|
|
273
273
|
target: `${KIOSK_MODULE}::borrow_val`,
|
|
@@ -310,7 +310,7 @@ export function purchaseAndResolvePolicies(
|
|
|
310
310
|
itemType: string,
|
|
311
311
|
price: string,
|
|
312
312
|
kiosk: ObjectArgument,
|
|
313
|
-
itemId:
|
|
313
|
+
itemId: string,
|
|
314
314
|
policy: TransferPolicy,
|
|
315
315
|
environment: RulesEnvironmentParam,
|
|
316
316
|
extraParams?: PurchaseOptionalParams,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { TransactionBlock, TransactionArgument } from '@mysten/sui.js/transactions';
|
|
5
5
|
import { getRulePackageAddress, objArg } from '../utils';
|
|
6
6
|
import { lock } from './kiosk';
|
|
7
7
|
import {
|
package/src/types/env.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { SuiAddress } from '@mysten/sui.js';
|
|
5
|
-
|
|
6
4
|
/* A list of environments. */
|
|
7
5
|
export type Environment = 'mainnet' | 'testnet' | 'devnet' | 'custom';
|
|
8
6
|
|
|
9
|
-
/** A Parameter to support
|
|
10
|
-
export type RulesEnvironmentParam = { env: Environment; address?:
|
|
7
|
+
/** A Parameter to support environments for rules. */
|
|
8
|
+
export type RulesEnvironmentParam = { env: Environment; address?: string };
|
|
11
9
|
|
|
12
10
|
/** A default Testnet Environment object */
|
|
13
11
|
export const testnetEnvironment: RulesEnvironmentParam = { env: 'testnet' };
|
package/src/types/index.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { SharedObjectRef
|
|
4
|
+
import { SharedObjectRef } from '@mysten/sui.js/bcs';
|
|
5
|
+
import { SuiObjectRef } from '@mysten/sui.js/client';
|
|
6
|
+
import { TransactionArgument } from '@mysten/sui.js/transactions';
|
|
5
7
|
|
|
6
8
|
export * from './kiosk';
|
|
7
9
|
export * from './transfer-policy';
|
package/src/types/kiosk.ts
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
ObjectId,
|
|
7
|
-
ObjectType,
|
|
8
|
-
PaginatedObjectsResponse,
|
|
9
|
-
TransactionArgument,
|
|
10
|
-
} from '@mysten/sui.js';
|
|
4
|
+
import { PaginatedObjectsResponse } from '@mysten/sui.js/client';
|
|
5
|
+
import { TransactionArgument } from '@mysten/sui.js/transactions';
|
|
11
6
|
import { ObjectArgument } from '.';
|
|
12
7
|
|
|
13
8
|
/** The Kiosk module. */
|
|
@@ -77,7 +72,7 @@ export type PurchaseOptionalParams = {
|
|
|
77
72
|
*/
|
|
78
73
|
export type KioskListing = {
|
|
79
74
|
/** The ID of the Item */
|
|
80
|
-
objectId:
|
|
75
|
+
objectId: string;
|
|
81
76
|
/**
|
|
82
77
|
* Whether or not there's a `PurchaseCap` issued. `true` means that
|
|
83
78
|
* the listing is controlled by some logic and can't be purchased directly.
|
|
@@ -86,7 +81,7 @@ export type KioskListing = {
|
|
|
86
81
|
*/
|
|
87
82
|
isExclusive: boolean;
|
|
88
83
|
/** The ID of the listing */
|
|
89
|
-
listingId:
|
|
84
|
+
listingId: string;
|
|
90
85
|
price?: string;
|
|
91
86
|
};
|
|
92
87
|
|
|
@@ -96,9 +91,9 @@ export type KioskListing = {
|
|
|
96
91
|
*/
|
|
97
92
|
export type KioskItem = {
|
|
98
93
|
/** The ID of the Item */
|
|
99
|
-
objectId:
|
|
94
|
+
objectId: string;
|
|
100
95
|
/** The type of the Item */
|
|
101
|
-
type:
|
|
96
|
+
type: string;
|
|
102
97
|
/** Whether the item is Locked (there must be a `Lock` Dynamic Field) */
|
|
103
98
|
isLocked: boolean;
|
|
104
99
|
/** Optional listing */
|
|
@@ -109,15 +104,15 @@ export type KioskItem = {
|
|
|
109
104
|
*/
|
|
110
105
|
export type KioskData = {
|
|
111
106
|
items: KioskItem[];
|
|
112
|
-
itemIds:
|
|
113
|
-
listingIds:
|
|
107
|
+
itemIds: string[];
|
|
108
|
+
listingIds: string[];
|
|
114
109
|
kiosk?: Kiosk;
|
|
115
110
|
extensions: any[]; // type will be defined on later versions of the SDK.
|
|
116
111
|
};
|
|
117
112
|
|
|
118
113
|
export type PagedKioskData = {
|
|
119
114
|
data: KioskData;
|
|
120
|
-
nextCursor: string | null;
|
|
115
|
+
nextCursor: string | null | undefined;
|
|
121
116
|
hasNextPage: boolean;
|
|
122
117
|
};
|
|
123
118
|
|
|
@@ -128,12 +123,12 @@ export type FetchKioskOptions = {
|
|
|
128
123
|
|
|
129
124
|
export type OwnedKiosks = {
|
|
130
125
|
kioskOwnerCaps: KioskOwnerCap[];
|
|
131
|
-
kioskIds:
|
|
126
|
+
kioskIds: string[];
|
|
132
127
|
} & Omit<PaginatedObjectsResponse, 'data'>;
|
|
133
128
|
|
|
134
129
|
export type KioskOwnerCap = {
|
|
135
|
-
objectId:
|
|
136
|
-
kioskId:
|
|
137
|
-
digest:
|
|
130
|
+
objectId: string;
|
|
131
|
+
kioskId: string;
|
|
132
|
+
digest: string;
|
|
138
133
|
version: string;
|
|
139
134
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { ObjectOwner } from '@mysten/sui.js';
|
|
4
|
+
import { ObjectOwner } from '@mysten/sui.js/client';
|
|
5
5
|
|
|
6
6
|
/** The Transfer Policy module. */
|
|
7
7
|
export const TRANSFER_POLICY_MODULE = '0x2::transfer_policy';
|
package/src/utils.ts
CHANGED
|
@@ -1,21 +1,14 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
SharedObjectRef,
|
|
9
|
-
SuiObjectRef,
|
|
10
|
-
SuiObjectResponse,
|
|
11
|
-
TransactionArgument,
|
|
12
|
-
TransactionBlock,
|
|
13
|
-
getObjectFields,
|
|
14
|
-
} from '@mysten/sui.js';
|
|
15
|
-
import { type DynamicFieldInfo } from '@mysten/sui.js';
|
|
4
|
+
import { SharedObjectRef } from '@mysten/sui.js/bcs';
|
|
5
|
+
import { SuiObjectRef, SuiObjectResponse } from '@mysten/sui.js/client';
|
|
6
|
+
import { TransactionBlock, TransactionArgument } from '@mysten/sui.js/transactions';
|
|
7
|
+
import { type DynamicFieldInfo } from '@mysten/sui.js/client';
|
|
16
8
|
import { bcs } from './bcs';
|
|
17
9
|
import { KIOSK_TYPE, Kiosk, KioskData, KioskListing, RulesEnvironmentParam } from './types';
|
|
18
10
|
import { MAINNET_RULES_PACKAGE_ADDRESS, TESTNET_RULES_PACKAGE_ADDRESS } from './constants';
|
|
11
|
+
import { SuiClient, PaginationArguments } from '@mysten/sui.js/client';
|
|
19
12
|
|
|
20
13
|
/* A simple map to the rule package addresses */
|
|
21
14
|
// TODO: Supply the mainnet and devnet addresses.
|
|
@@ -56,8 +49,8 @@ export function objArg(
|
|
|
56
49
|
throw new Error('Invalid argument type');
|
|
57
50
|
}
|
|
58
51
|
|
|
59
|
-
export async function getKioskObject(
|
|
60
|
-
const queryRes = await
|
|
52
|
+
export async function getKioskObject(client: SuiClient, id: string): Promise<Kiosk> {
|
|
53
|
+
const queryRes = await client.getObject({ id, options: { showBcs: true } });
|
|
61
54
|
|
|
62
55
|
if (!queryRes || queryRes.error || !queryRes.data) {
|
|
63
56
|
throw new Error(`Kiosk ${id} not found; ${queryRes.error}`);
|
|
@@ -92,13 +85,13 @@ export function extractKioskData(
|
|
|
92
85
|
case 'kiosk::Listing':
|
|
93
86
|
acc.listingIds.push(val.objectId);
|
|
94
87
|
listings.push({
|
|
95
|
-
objectId: val.name.value.id,
|
|
88
|
+
objectId: (val.name.value as { id: string }).id,
|
|
96
89
|
listingId: val.objectId,
|
|
97
|
-
isExclusive: val.name.value.is_exclusive,
|
|
90
|
+
isExclusive: (val.name.value as { is_exclusive: boolean }).is_exclusive,
|
|
98
91
|
});
|
|
99
92
|
break;
|
|
100
93
|
case 'kiosk::Lock':
|
|
101
|
-
lockedItemIds?.push(val.name.value.id);
|
|
94
|
+
lockedItemIds?.push((val.name.value as { id: string }).id);
|
|
102
95
|
break;
|
|
103
96
|
}
|
|
104
97
|
return acc;
|
|
@@ -122,18 +115,20 @@ export function attachListingsAndPrices(
|
|
|
122
115
|
) {
|
|
123
116
|
// map item listings as {item_id: KioskListing}
|
|
124
117
|
// for easier mapping on the nex
|
|
125
|
-
const itemListings = listings.reduce<Record<
|
|
126
|
-
(acc: Record<
|
|
118
|
+
const itemListings = listings.reduce<Record<string, KioskListing>>(
|
|
119
|
+
(acc: Record<string, KioskListing>, item, idx) => {
|
|
127
120
|
acc[item.objectId] = { ...item };
|
|
128
121
|
|
|
129
122
|
// return in case we don't have any listing objects.
|
|
130
123
|
// that's the case when we don't have the `listingPrices` included.
|
|
131
124
|
if (listingObjects.length === 0) return acc;
|
|
132
125
|
|
|
133
|
-
const
|
|
126
|
+
const content = listingObjects[idx].data?.content;
|
|
127
|
+
const data = content?.dataType === 'moveObject' ? content?.fields : null;
|
|
128
|
+
|
|
134
129
|
if (!data) return acc;
|
|
135
130
|
|
|
136
|
-
acc[item.objectId].price = data.value;
|
|
131
|
+
acc[item.objectId].price = (data as { value: string }).value;
|
|
137
132
|
return acc;
|
|
138
133
|
},
|
|
139
134
|
{},
|
|
@@ -147,10 +142,10 @@ export function attachListingsAndPrices(
|
|
|
147
142
|
/**
|
|
148
143
|
* A Helper to attach locked state to items in Kiosk Data.
|
|
149
144
|
*/
|
|
150
|
-
export function attachLockedItems(kioskData: KioskData, lockedItemIds:
|
|
145
|
+
export function attachLockedItems(kioskData: KioskData, lockedItemIds: string[]) {
|
|
151
146
|
// map lock status in an array of type { item_id: true }
|
|
152
|
-
const lockedStatuses = lockedItemIds.reduce<Record<
|
|
153
|
-
(acc: Record<
|
|
147
|
+
const lockedStatuses = lockedItemIds.reduce<Record<string, boolean>>(
|
|
148
|
+
(acc: Record<string, boolean>, item: string) => {
|
|
154
149
|
acc[item] = true;
|
|
155
150
|
return acc;
|
|
156
151
|
},
|
|
@@ -182,8 +177,8 @@ export function getRulePackageAddress(environment: RulesEnvironmentParam): strin
|
|
|
182
177
|
* RPC calls that allow filtering of Type / batch fetching of spec
|
|
183
178
|
*/
|
|
184
179
|
export async function getAllDynamicFields(
|
|
185
|
-
|
|
186
|
-
parentId:
|
|
180
|
+
client: SuiClient,
|
|
181
|
+
parentId: string,
|
|
187
182
|
pagination: PaginationArguments<string>,
|
|
188
183
|
) {
|
|
189
184
|
let hasNextPage = true;
|
|
@@ -191,7 +186,7 @@ export async function getAllDynamicFields(
|
|
|
191
186
|
const data: DynamicFieldInfo[] = [];
|
|
192
187
|
|
|
193
188
|
while (hasNextPage) {
|
|
194
|
-
const result = await
|
|
189
|
+
const result = await client.getDynamicFields({
|
|
195
190
|
parentId,
|
|
196
191
|
limit: pagination.limit || undefined,
|
|
197
192
|
cursor,
|