@mysten/kiosk 1.3.13 → 1.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 +13 -0
- package/dist/client/kiosk-client.d.mts +5 -6
- package/dist/client/kiosk-client.d.mts.map +1 -1
- package/dist/client/kiosk-client.mjs +3 -3
- package/dist/client/kiosk-client.mjs.map +1 -1
- package/dist/contracts/utils/index.mjs +5 -1
- package/dist/contracts/utils/index.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/query/client-utils.mjs +32 -200
- package/dist/query/client-utils.mjs.map +1 -1
- package/dist/query/kiosk.mjs.map +1 -1
- package/dist/query/transfer-policy.mjs +1 -5
- package/dist/query/transfer-policy.mjs.map +1 -1
- package/dist/types/index.d.mts +7 -5
- package/dist/types/index.d.mts.map +1 -1
- package/dist/utils.d.mts +2 -3
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs.map +1 -1
- package/docs/advanced-examples.md +3 -3
- package/docs/from-v1.md +9 -9
- package/docs/index.md +6 -3
- package/docs/kiosk-client/introduction.md +10 -7
- package/docs/llms-index.md +4 -4
- package/package.json +4 -5
- package/src/client/kiosk-client.ts +5 -5
- package/src/contracts/utils/index.ts +49 -2
- package/src/query/client-utils.ts +51 -273
- package/src/query/kiosk.ts +3 -3
- package/src/query/transfer-policy.ts +1 -5
- package/src/types/index.ts +7 -4
- package/src/utils.ts +8 -3
|
@@ -2,66 +2,13 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import type { SuiClientTypes } from '@mysten/sui/client';
|
|
5
|
-
import { graphql } from '@mysten/sui/graphql/schema';
|
|
6
5
|
import { isSuiGraphQLClient } from '@mysten/sui/graphql';
|
|
7
|
-
import { isSuiJsonRpcClient } from '@mysten/sui/jsonRpc';
|
|
8
|
-
import { normalizeStructTag } from '@mysten/sui/utils';
|
|
9
|
-
import { chunk, fromBase64 } from '@mysten/utils';
|
|
10
6
|
|
|
11
|
-
import type {
|
|
7
|
+
import type { ObjectWithDisplay } from '../types/kiosk.js';
|
|
12
8
|
import type { KioskCompatibleClient } from '../types/index.js';
|
|
13
9
|
|
|
14
10
|
const DEFAULT_QUERY_LIMIT = 50;
|
|
15
|
-
|
|
16
|
-
const FetchObjectsWithDisplayQuery = graphql(`
|
|
17
|
-
query FetchObjectsWithDisplay($objectKeys: [ObjectKey!]!) {
|
|
18
|
-
multiGetObjects(keys: $objectKeys) {
|
|
19
|
-
address
|
|
20
|
-
digest
|
|
21
|
-
version
|
|
22
|
-
asMoveObject {
|
|
23
|
-
contents {
|
|
24
|
-
bcs
|
|
25
|
-
type {
|
|
26
|
-
repr
|
|
27
|
-
}
|
|
28
|
-
display {
|
|
29
|
-
output
|
|
30
|
-
errors
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
asMovePackage {
|
|
35
|
-
__typename
|
|
36
|
-
}
|
|
37
|
-
owner {
|
|
38
|
-
__typename
|
|
39
|
-
... on AddressOwner {
|
|
40
|
-
address {
|
|
41
|
-
address
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
... on ObjectOwner {
|
|
45
|
-
address {
|
|
46
|
-
address
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
... on Shared {
|
|
50
|
-
initialSharedVersion
|
|
51
|
-
}
|
|
52
|
-
... on ConsensusAddressOwner {
|
|
53
|
-
startVersion
|
|
54
|
-
address {
|
|
55
|
-
address
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
previousTransaction {
|
|
60
|
-
digest
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
`);
|
|
11
|
+
const MAX_EVENT_QUERY_PAGES = 10;
|
|
65
12
|
|
|
66
13
|
export async function getAllObjects(
|
|
67
14
|
client: KioskCompatibleClient,
|
|
@@ -69,234 +16,65 @@ export async function getAllObjects(
|
|
|
69
16
|
): Promise<ObjectWithDisplay[]> {
|
|
70
17
|
if (ids.length === 0) return [];
|
|
71
18
|
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
19
|
+
const { objects } = await client.core.getObjects({
|
|
20
|
+
objectIds: ids,
|
|
21
|
+
include: {
|
|
22
|
+
content: true,
|
|
23
|
+
previousTransaction: true,
|
|
24
|
+
display: true,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
return objects
|
|
29
|
+
.filter(
|
|
30
|
+
(
|
|
31
|
+
object,
|
|
32
|
+
): object is SuiClientTypes.Object<{
|
|
33
|
+
content: true;
|
|
34
|
+
previousTransaction: true;
|
|
35
|
+
display: true;
|
|
36
|
+
}> => !(object instanceof Error),
|
|
37
|
+
)
|
|
38
|
+
.map((object) => ({
|
|
39
|
+
...object,
|
|
40
|
+
previousTransaction: object.previousTransaction ?? null,
|
|
41
|
+
display: object.display
|
|
42
|
+
? {
|
|
43
|
+
data: object.display.output,
|
|
44
|
+
error: object.display.errors ? JSON.stringify(object.display.errors) : null,
|
|
95
45
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
? fromBase64(obj.asMoveObject.contents.bcs)
|
|
99
|
-
: undefined;
|
|
100
|
-
|
|
101
|
-
const displayData = obj.asMoveObject?.contents?.display;
|
|
102
|
-
const display: KioskDisplay | undefined = displayData
|
|
103
|
-
? {
|
|
104
|
-
data: (displayData.output as Record<string, unknown> | null) ?? null,
|
|
105
|
-
error: displayData.errors ? JSON.stringify(displayData.errors) : null,
|
|
106
|
-
}
|
|
107
|
-
: undefined;
|
|
108
|
-
|
|
109
|
-
results.push({
|
|
110
|
-
objectId: obj.address,
|
|
111
|
-
version: obj.version?.toString()!,
|
|
112
|
-
digest: obj.digest!,
|
|
113
|
-
type,
|
|
114
|
-
content: bcsContent!,
|
|
115
|
-
owner: mapGraphQLOwner(obj.owner!),
|
|
116
|
-
previousTransaction: (obj.previousTransaction?.digest ?? null)!,
|
|
117
|
-
objectBcs: undefined,
|
|
118
|
-
json: undefined,
|
|
119
|
-
display,
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return results;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (isSuiJsonRpcClient(client)) {
|
|
129
|
-
for (const batch of chunks) {
|
|
130
|
-
const responses = await client.multiGetObjects({
|
|
131
|
-
ids: batch,
|
|
132
|
-
options: {
|
|
133
|
-
showDisplay: true,
|
|
134
|
-
showBcs: true,
|
|
135
|
-
showType: true,
|
|
136
|
-
showOwner: true,
|
|
137
|
-
showPreviousTransaction: true,
|
|
138
|
-
},
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
for (const resp of responses) {
|
|
142
|
-
if (!resp.data) continue;
|
|
143
|
-
const obj = resp.data;
|
|
144
|
-
|
|
145
|
-
const bcsContent =
|
|
146
|
-
obj.bcs?.dataType === 'moveObject' ? fromBase64(obj.bcs.bcsBytes) : undefined;
|
|
147
|
-
|
|
148
|
-
const type =
|
|
149
|
-
obj.type && obj.type.includes('::') ? normalizeStructTag(obj.type) : (obj.type ?? '');
|
|
150
|
-
|
|
151
|
-
const display: KioskDisplay | undefined = obj.display
|
|
152
|
-
? {
|
|
153
|
-
data: obj.display.data ?? null,
|
|
154
|
-
error: obj.display.error ? JSON.stringify(obj.display.error) : null,
|
|
155
|
-
}
|
|
156
|
-
: undefined;
|
|
157
|
-
|
|
158
|
-
results.push({
|
|
159
|
-
objectId: obj.objectId,
|
|
160
|
-
version: obj.version,
|
|
161
|
-
digest: obj.digest,
|
|
162
|
-
type,
|
|
163
|
-
content: bcsContent!,
|
|
164
|
-
owner: parseJsonRpcOwner(obj.owner!),
|
|
165
|
-
previousTransaction: (obj.previousTransaction ?? null)!,
|
|
166
|
-
objectBcs: undefined,
|
|
167
|
-
json: undefined,
|
|
168
|
-
display,
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return results;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
throw new Error(
|
|
177
|
-
'Object fetching requires a JSON-RPC or GraphQL client. ' +
|
|
178
|
-
'gRPC clients are not supported by the kiosk SDK.',
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
function parseJsonRpcOwner(owner: NonNullable<unknown>): SuiClientTypes.ObjectOwner {
|
|
183
|
-
if (owner === 'Immutable') {
|
|
184
|
-
return { $kind: 'Immutable', Immutable: true } as SuiClientTypes.ObjectOwner;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
const ownerObj = owner as Record<string, any>;
|
|
188
|
-
|
|
189
|
-
if ('ConsensusAddressOwner' in ownerObj) {
|
|
190
|
-
return {
|
|
191
|
-
$kind: 'ConsensusAddressOwner',
|
|
192
|
-
ConsensusAddressOwner: {
|
|
193
|
-
owner: ownerObj.ConsensusAddressOwner.owner,
|
|
194
|
-
startVersion: ownerObj.ConsensusAddressOwner.start_version,
|
|
195
|
-
},
|
|
196
|
-
} as SuiClientTypes.ObjectOwner;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
if ('AddressOwner' in ownerObj) {
|
|
200
|
-
return {
|
|
201
|
-
$kind: 'AddressOwner',
|
|
202
|
-
AddressOwner: ownerObj.AddressOwner,
|
|
203
|
-
} as SuiClientTypes.ObjectOwner;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
if ('ObjectOwner' in ownerObj) {
|
|
207
|
-
return {
|
|
208
|
-
$kind: 'ObjectOwner',
|
|
209
|
-
ObjectOwner: ownerObj.ObjectOwner,
|
|
210
|
-
} as SuiClientTypes.ObjectOwner;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
if ('Shared' in ownerObj) {
|
|
214
|
-
return {
|
|
215
|
-
$kind: 'Shared',
|
|
216
|
-
Shared: {
|
|
217
|
-
initialSharedVersion: ownerObj.Shared.initial_shared_version,
|
|
218
|
-
},
|
|
219
|
-
} as SuiClientTypes.ObjectOwner;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
throw new Error(`Unknown owner type: ${JSON.stringify(owner)}`);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
function mapGraphQLOwner(
|
|
226
|
-
owner: NonNullable<unknown> & { __typename?: string },
|
|
227
|
-
): SuiClientTypes.ObjectOwner {
|
|
228
|
-
const o = owner as Record<string, any>;
|
|
229
|
-
switch (o.__typename) {
|
|
230
|
-
case 'AddressOwner':
|
|
231
|
-
return {
|
|
232
|
-
$kind: 'AddressOwner',
|
|
233
|
-
AddressOwner: o.address?.address!,
|
|
234
|
-
} as SuiClientTypes.ObjectOwner;
|
|
235
|
-
case 'ObjectOwner':
|
|
236
|
-
return {
|
|
237
|
-
$kind: 'ObjectOwner',
|
|
238
|
-
ObjectOwner: o.address?.address!,
|
|
239
|
-
} as SuiClientTypes.ObjectOwner;
|
|
240
|
-
case 'Immutable':
|
|
241
|
-
return { $kind: 'Immutable', Immutable: true } as SuiClientTypes.ObjectOwner;
|
|
242
|
-
case 'Shared':
|
|
243
|
-
return {
|
|
244
|
-
$kind: 'Shared',
|
|
245
|
-
Shared: { initialSharedVersion: String(o.initialSharedVersion) },
|
|
246
|
-
} as SuiClientTypes.ObjectOwner;
|
|
247
|
-
case 'ConsensusAddressOwner':
|
|
248
|
-
return {
|
|
249
|
-
$kind: 'ConsensusAddressOwner',
|
|
250
|
-
ConsensusAddressOwner: {
|
|
251
|
-
owner: o.address?.address!,
|
|
252
|
-
startVersion: String(o.startVersion),
|
|
253
|
-
},
|
|
254
|
-
} as SuiClientTypes.ObjectOwner;
|
|
255
|
-
default:
|
|
256
|
-
throw new Error(`Unknown GraphQL owner type: ${o.__typename}`);
|
|
257
|
-
}
|
|
46
|
+
: undefined,
|
|
47
|
+
}));
|
|
258
48
|
}
|
|
259
49
|
|
|
260
50
|
export async function queryEvents(
|
|
261
51
|
client: KioskCompatibleClient,
|
|
262
52
|
eventType: string,
|
|
263
53
|
): Promise<{ json: unknown }[]> {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
query,
|
|
279
|
-
variables: { eventType },
|
|
54
|
+
// Preserve the windows returned by the previously transport-specific implementations.
|
|
55
|
+
const order = isSuiGraphQLClient(client) ? 'ascending' : 'descending';
|
|
56
|
+
const events: SuiClientTypes.EventEntry[] = [];
|
|
57
|
+
let cursor: string | null = null;
|
|
58
|
+
|
|
59
|
+
// gRPC can return empty scan-limited pages. Continue through a bounded number of those pages
|
|
60
|
+
// while preserving the 50-event window returned by the previous transport-specific queries.
|
|
61
|
+
for (let pageCount = 0; pageCount < MAX_EVENT_QUERY_PAGES; pageCount++) {
|
|
62
|
+
const remaining = DEFAULT_QUERY_LIMIT - events.length;
|
|
63
|
+
const page = await client.core.listEvents({
|
|
64
|
+
filter: { eventType },
|
|
65
|
+
limit: remaining,
|
|
66
|
+
order,
|
|
67
|
+
...(cursor ? (order === 'descending' ? { before: cursor } : { after: cursor }) : {}),
|
|
280
68
|
});
|
|
281
69
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
json: event.contents?.json,
|
|
285
|
-
})) ?? []
|
|
286
|
-
);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
if (isSuiJsonRpcClient(client)) {
|
|
290
|
-
const events = await client.queryEvents({
|
|
291
|
-
query: { MoveEventType: eventType },
|
|
292
|
-
});
|
|
70
|
+
events.push(...page.events.slice(0, remaining));
|
|
71
|
+
if (!page.hasNextPage || events.length === DEFAULT_QUERY_LIMIT) break;
|
|
293
72
|
|
|
294
|
-
|
|
73
|
+
if (!page.endCursor || page.endCursor === cursor) {
|
|
74
|
+
throw new Error('Event query did not return a cursor for the next page');
|
|
75
|
+
}
|
|
76
|
+
cursor = page.endCursor;
|
|
295
77
|
}
|
|
296
78
|
|
|
297
|
-
|
|
298
|
-
'Event querying is not supported by this client type. ' +
|
|
299
|
-
'JSON-RPC and GraphQL clients support event querying, but gRPC does not. ' +
|
|
300
|
-
'Please use a JSON-RPC or GraphQL client, or provide the required IDs directly.',
|
|
301
|
-
);
|
|
79
|
+
return events.map((event) => ({ json: event.json }));
|
|
302
80
|
}
|
package/src/query/kiosk.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import type { PaginationArguments } from '@mysten/sui/jsonRpc';
|
|
5
4
|
import type { ClientWithCoreApi, SuiClientTypes } from '@mysten/sui/client';
|
|
6
5
|
import { isValidSuiAddress } from '@mysten/sui/utils';
|
|
7
6
|
|
|
@@ -11,6 +10,7 @@ import type {
|
|
|
11
10
|
KioskCompatibleClient,
|
|
12
11
|
KioskExtension,
|
|
13
12
|
KioskListing,
|
|
13
|
+
KioskPaginationArguments,
|
|
14
14
|
OwnedKiosks,
|
|
15
15
|
PagedKioskData,
|
|
16
16
|
} from '../types/index.js';
|
|
@@ -29,7 +29,7 @@ import { PersonalKioskCap } from '../contracts/kiosk/personal_kiosk.js';
|
|
|
29
29
|
export async function fetchKiosk(
|
|
30
30
|
client: KioskCompatibleClient,
|
|
31
31
|
kioskId: string,
|
|
32
|
-
pagination:
|
|
32
|
+
pagination: KioskPaginationArguments,
|
|
33
33
|
options: FetchKioskOptions,
|
|
34
34
|
): Promise<PagedKioskData> {
|
|
35
35
|
// TODO: Replace the `getAllDynamicFields` with a paginated
|
|
@@ -83,7 +83,7 @@ export async function getOwnedKiosks(
|
|
|
83
83
|
client: ClientWithCoreApi,
|
|
84
84
|
address: string,
|
|
85
85
|
options?: {
|
|
86
|
-
pagination?:
|
|
86
|
+
pagination?: KioskPaginationArguments;
|
|
87
87
|
personalKioskType: string;
|
|
88
88
|
},
|
|
89
89
|
): Promise<OwnedKiosks> {
|
|
@@ -21,12 +21,8 @@ import { queryEvents } from './client-utils.js';
|
|
|
21
21
|
* and the caller needs to filter the results accordingly (ie single owner can not
|
|
22
22
|
* be accessed by anyone but the owner).
|
|
23
23
|
*
|
|
24
|
-
*
|
|
25
|
-
* gRPC clients do not support event querying and will throw an error.
|
|
26
|
-
*
|
|
27
|
-
* @param client - The Sui client (must support event querying)
|
|
24
|
+
* @param client - A Sui client with the Core API
|
|
28
25
|
* @param type - The type of the asset (e.g., "0x123::nft::NFT")
|
|
29
|
-
* @throws Error if the client doesn't support event querying
|
|
30
26
|
*/
|
|
31
27
|
export async function queryTransferPolicy(
|
|
32
28
|
client: KioskCompatibleClient,
|
package/src/types/index.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import type { SuiClientTypes } from '@mysten/sui/client';
|
|
4
|
+
import type { ClientWithCoreApi, SuiClientTypes } from '@mysten/sui/client';
|
|
5
5
|
import type { TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
6
6
|
|
|
7
7
|
import type { BaseRulePackageIds } from '../constants.js';
|
|
8
|
-
import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
|
|
9
|
-
import { SuiGraphQLClient } from '@mysten/sui/graphql';
|
|
10
8
|
|
|
11
9
|
export * from './kiosk.js';
|
|
12
10
|
export * from './transfer-policy.js';
|
|
@@ -25,4 +23,9 @@ export type KioskClientOptions = {
|
|
|
25
23
|
packageIds?: BaseRulePackageIds;
|
|
26
24
|
};
|
|
27
25
|
|
|
28
|
-
export type KioskCompatibleClient =
|
|
26
|
+
export type KioskCompatibleClient = ClientWithCoreApi;
|
|
27
|
+
|
|
28
|
+
export type KioskPaginationArguments = {
|
|
29
|
+
cursor?: string | null;
|
|
30
|
+
limit?: number | null;
|
|
31
|
+
};
|
package/src/utils.ts
CHANGED
|
@@ -2,12 +2,17 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { bcs } from '@mysten/sui/bcs';
|
|
5
|
-
import { PaginationArguments } from '@mysten/sui/jsonRpc';
|
|
6
5
|
import type { ClientWithCoreApi, SuiClientTypes } from '@mysten/sui/client';
|
|
7
6
|
import { normalizeStructTag, normalizeSuiAddress, parseStructTag } from '@mysten/sui/utils';
|
|
8
7
|
|
|
9
8
|
import { Item, Listing, Lock, Kiosk as KioskStruct } from './contracts/0x2/kiosk.js';
|
|
10
|
-
import type {
|
|
9
|
+
import type {
|
|
10
|
+
Kiosk,
|
|
11
|
+
KioskData,
|
|
12
|
+
KioskListing,
|
|
13
|
+
KioskPaginationArguments,
|
|
14
|
+
ObjectWithDisplay,
|
|
15
|
+
} from './types/index.js';
|
|
11
16
|
|
|
12
17
|
export type DynamicFieldInfo = SuiClientTypes.ListDynamicFieldsResponse['dynamicFields'][number];
|
|
13
18
|
|
|
@@ -176,7 +181,7 @@ export function attachLockedItems(kioskData: KioskData, lockedItemIds: string[])
|
|
|
176
181
|
export async function getAllDynamicFields(
|
|
177
182
|
client: ClientWithCoreApi,
|
|
178
183
|
parentId: string,
|
|
179
|
-
pagination:
|
|
184
|
+
pagination: KioskPaginationArguments,
|
|
180
185
|
): Promise<DynamicFieldInfo[]> {
|
|
181
186
|
let hasNextPage = true;
|
|
182
187
|
let cursor: string | null = null;
|