@mysten/kiosk 1.3.13 → 1.4.0
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 +7 -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/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/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
package/dist/utils.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","names":["KioskStruct"],"sources":["../src/utils.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { bcs } from '@mysten/sui/bcs';\nimport
|
|
1
|
+
{"version":3,"file":"utils.mjs","names":["KioskStruct"],"sources":["../src/utils.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { bcs } from '@mysten/sui/bcs';\nimport type { ClientWithCoreApi, SuiClientTypes } from '@mysten/sui/client';\nimport { normalizeStructTag, normalizeSuiAddress, parseStructTag } from '@mysten/sui/utils';\n\nimport { Item, Listing, Lock, Kiosk as KioskStruct } from './contracts/0x2/kiosk.js';\nimport type {\n\tKiosk,\n\tKioskData,\n\tKioskListing,\n\tKioskPaginationArguments,\n\tObjectWithDisplay,\n} from './types/index.js';\n\nexport type DynamicFieldInfo = SuiClientTypes.ListDynamicFieldsResponse['dynamicFields'][number];\n\nexport async function getKioskObject(client: ClientWithCoreApi, id: string): Promise<Kiosk> {\n\tconst { object } = await client.core.getObject({\n\t\tobjectId: id,\n\t\tinclude: { content: true },\n\t});\n\n\tif (!object.content) {\n\t\tthrow new Error(`Kiosk ${id} not found or has no content`);\n\t}\n\n\tconst parsed = KioskStruct.parse(object.content);\n\n\treturn {\n\t\tid: parsed.id,\n\t\tprofits: parsed.profits.value.toString(),\n\t\towner: parsed.owner,\n\t\titemCount: parsed.item_count,\n\t\tallowExtensions: parsed.allow_extensions,\n\t};\n}\n\n// helper to extract kiosk data from dynamic fields.\nexport function extractKioskData(\n\tdata: DynamicFieldInfo[],\n\tlistings: KioskListing[],\n\tlockedItemIds: string[],\n\tkioskId: string,\n): KioskData {\n\treturn data.reduce<KioskData>(\n\t\t(acc: KioskData, val: DynamicFieldInfo) => {\n\t\t\tconst type = val.name.type;\n\n\t\t\tconst parsedType = parseStructTag(type);\n\t\t\tconst baseType = `${normalizeSuiAddress(parsedType.address)}::${parsedType.module}::${parsedType.name}`;\n\n\t\t\tif (\n\t\t\t\tbaseType ===\n\t\t\t\t'0x0000000000000000000000000000000000000000000000000000000000000002::kiosk::Item'\n\t\t\t) {\n\t\t\t\tconst parsed = Item.parse(val.name.bcs);\n\t\t\t\tacc.itemIds.push(parsed.id);\n\t\t\t\tacc.items.push({\n\t\t\t\t\tobjectId: parsed.id,\n\t\t\t\t\ttype: val.valueType,\n\t\t\t\t\tisLocked: false,\n\t\t\t\t\tkioskId,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tbaseType ===\n\t\t\t\t'0x0000000000000000000000000000000000000000000000000000000000000002::kiosk::Listing'\n\t\t\t) {\n\t\t\t\tconst parsed = Listing.parse(val.name.bcs);\n\n\t\t\t\tacc.listingIds.push(val.fieldId);\n\t\t\t\tlistings.push({\n\t\t\t\t\tobjectId: parsed.id,\n\t\t\t\t\tlistingId: val.fieldId,\n\t\t\t\t\tisExclusive: parsed.is_exclusive,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tbaseType ===\n\t\t\t\t'0x0000000000000000000000000000000000000000000000000000000000000002::kiosk::Lock'\n\t\t\t) {\n\t\t\t\tlockedItemIds?.push(Lock.parse(val.name.bcs).id);\n\t\t\t}\n\n\t\t\t// Check for ExtensionKey type\n\t\t\tif (\n\t\t\t\tbaseType ===\n\t\t\t\t'0x0000000000000000000000000000000000000000000000000000000000000002::kiosk_extension::ExtensionKey'\n\t\t\t) {\n\t\t\t\tacc.extensions.push({\n\t\t\t\t\tobjectId: val.fieldId,\n\t\t\t\t\ttype: normalizeStructTag(parsedType.typeParams[0]),\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn acc;\n\t\t},\n\t\t{ items: [], itemIds: [], listingIds: [], extensions: [] },\n\t);\n}\n\n/**\n * A helper that attaches the listing prices to kiosk listings.\n */\nexport function attachListingsAndPrices(\n\tkioskData: KioskData,\n\tlistings: KioskListing[],\n\tlistingObjects: ObjectWithDisplay[],\n) {\n\tconst itemListings = listings.reduce<Record<string, KioskListing>>(\n\t\t(acc: Record<string, KioskListing>, item, idx) => {\n\t\t\tacc[item.objectId] = { ...item };\n\n\t\t\t// return in case we don't have any listing objects.\n\t\t\t// that's the case when we don't have the `listingPrices` included.\n\t\t\tif (listingObjects.length === 0) return acc;\n\n\t\t\tconst obj = listingObjects[idx];\n\n\t\t\t// Parse BCS content to extract the price (u64 value)\n\t\t\tif (obj.content) {\n\t\t\t\tacc[item.objectId].price = bcs.u64().parse(obj.content).toString();\n\t\t\t}\n\n\t\t\treturn acc;\n\t\t},\n\t\t{},\n\t);\n\n\tkioskData.items.forEach((item) => {\n\t\titem.listing = itemListings[item.objectId] || undefined;\n\t});\n}\n\n/**\n * A helper that attaches object data to kiosk items.\n * Works with core API objects that contain BCS content.\n */\nexport function attachObjects(kioskData: KioskData, objects: ObjectWithDisplay[]) {\n\tconst mapping = objects.reduce<Record<string, ObjectWithDisplay>>(\n\t\t(acc: Record<string, ObjectWithDisplay>, obj) => {\n\t\t\tacc[obj.objectId] = obj;\n\t\t\treturn acc;\n\t\t},\n\t\t{},\n\t);\n\n\tkioskData.items.forEach((item) => {\n\t\titem.data = mapping[item.objectId] || undefined;\n\t});\n}\n\n/**\n * A Helper to attach locked state to items in Kiosk Data.\n */\nexport function attachLockedItems(kioskData: KioskData, lockedItemIds: string[]) {\n\t// map lock status in an array of type { item_id: true }\n\tconst lockedStatuses = lockedItemIds.reduce<Record<string, boolean>>(\n\t\t(acc: Record<string, boolean>, item: string) => {\n\t\t\tacc[item] = true;\n\t\t\treturn acc;\n\t\t},\n\t\t{},\n\t);\n\n\t// parse lockedItemIds and attach their locked status.\n\tkioskData.items.forEach((item) => {\n\t\titem.isLocked = lockedStatuses[item.objectId] || false;\n\t});\n}\n\n/**\n * A helper to fetch all dynamic field pages.\n * We need that to fetch the kiosk DFs consistently, until we have\n * RPC calls that allow filtering of Type / batch fetching of spec\n */\nexport async function getAllDynamicFields(\n\tclient: ClientWithCoreApi,\n\tparentId: string,\n\tpagination: KioskPaginationArguments,\n): Promise<DynamicFieldInfo[]> {\n\tlet hasNextPage = true;\n\tlet cursor: string | null = null;\n\tconst data: DynamicFieldInfo[] = [];\n\n\twhile (hasNextPage) {\n\t\tconst result = await client.core.listDynamicFields({\n\t\t\tparentId,\n\t\t\tlimit: pagination.limit || undefined,\n\t\t\tcursor,\n\t\t});\n\n\t\tdata.push(...result.dynamicFields);\n\n\t\thasNextPage = result.hasNextPage;\n\t\tcursor = result.cursor;\n\t}\n\n\treturn data;\n}\n\n/**\n * Converts a number to basis points.\n * Supports up to 2 decimal points.\n * E.g 9.95 -> 995\n * @param percentage A percentage amount in the range [0, 100] including decimals.\n */\nexport function percentageToBasisPoints(percentage: number) {\n\tif (percentage < 0 || percentage > 100)\n\t\tthrow new Error('Percentage needs to be in the [0,100] range.');\n\treturn Math.ceil(percentage * 100);\n}\n\n// Normalizes the packageId part of a rule's type.\nexport function getNormalizedRuleType(rule: string) {\n\tconst normalizedRuleAddress = rule.split('::');\n\tnormalizedRuleAddress[0] = normalizeSuiAddress(normalizedRuleAddress[0]);\n\treturn normalizedRuleAddress.join('::');\n}\n"],"mappings":";;;;;AAkBA,eAAsB,eAAe,QAA2B,IAA4B;CAC3F,MAAM,EAAE,WAAW,MAAM,OAAO,KAAK,UAAU;EAC9C,UAAU;EACV,SAAS,EAAE,SAAS,MAAM;EAC1B,CAAC;AAEF,KAAI,CAAC,OAAO,QACX,OAAM,IAAI,MAAM,SAAS,GAAG,8BAA8B;CAG3D,MAAM,SAASA,MAAY,MAAM,OAAO,QAAQ;AAEhD,QAAO;EACN,IAAI,OAAO;EACX,SAAS,OAAO,QAAQ,MAAM,UAAU;EACxC,OAAO,OAAO;EACd,WAAW,OAAO;EAClB,iBAAiB,OAAO;EACxB;;AAIF,SAAgB,iBACf,MACA,UACA,eACA,SACY;AACZ,QAAO,KAAK,QACV,KAAgB,QAA0B;EAC1C,MAAM,OAAO,IAAI,KAAK;EAEtB,MAAM,aAAa,eAAe,KAAK;EACvC,MAAM,WAAW,GAAG,oBAAoB,WAAW,QAAQ,CAAC,IAAI,WAAW,OAAO,IAAI,WAAW;AAEjG,MACC,aACA,mFACC;GACD,MAAM,SAAS,KAAK,MAAM,IAAI,KAAK,IAAI;AACvC,OAAI,QAAQ,KAAK,OAAO,GAAG;AAC3B,OAAI,MAAM,KAAK;IACd,UAAU,OAAO;IACjB,MAAM,IAAI;IACV,UAAU;IACV;IACA,CAAC;;AAGH,MACC,aACA,sFACC;GACD,MAAM,SAAS,QAAQ,MAAM,IAAI,KAAK,IAAI;AAE1C,OAAI,WAAW,KAAK,IAAI,QAAQ;AAChC,YAAS,KAAK;IACb,UAAU,OAAO;IACjB,WAAW,IAAI;IACf,aAAa,OAAO;IACpB,CAAC;;AAGH,MACC,aACA,kFAEA,gBAAe,KAAK,KAAK,MAAM,IAAI,KAAK,IAAI,CAAC,GAAG;AAIjD,MACC,aACA,oGAEA,KAAI,WAAW,KAAK;GACnB,UAAU,IAAI;GACd,MAAM,mBAAmB,WAAW,WAAW,GAAG;GAClD,CAAC;AAGH,SAAO;IAER;EAAE,OAAO,EAAE;EAAE,SAAS,EAAE;EAAE,YAAY,EAAE;EAAE,YAAY,EAAE;EAAE,CAC1D;;;;;AAMF,SAAgB,wBACf,WACA,UACA,gBACC;CACD,MAAM,eAAe,SAAS,QAC5B,KAAmC,MAAM,QAAQ;AACjD,MAAI,KAAK,YAAY,EAAE,GAAG,MAAM;AAIhC,MAAI,eAAe,WAAW,EAAG,QAAO;EAExC,MAAM,MAAM,eAAe;AAG3B,MAAI,IAAI,QACP,KAAI,KAAK,UAAU,QAAQ,IAAI,KAAK,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU;AAGnE,SAAO;IAER,EAAE,CACF;AAED,WAAU,MAAM,SAAS,SAAS;AACjC,OAAK,UAAU,aAAa,KAAK,aAAa;GAC7C;;;;;;AAOH,SAAgB,cAAc,WAAsB,SAA8B;CACjF,MAAM,UAAU,QAAQ,QACtB,KAAwC,QAAQ;AAChD,MAAI,IAAI,YAAY;AACpB,SAAO;IAER,EAAE,CACF;AAED,WAAU,MAAM,SAAS,SAAS;AACjC,OAAK,OAAO,QAAQ,KAAK,aAAa;GACrC;;;;;AAMH,SAAgB,kBAAkB,WAAsB,eAAyB;CAEhF,MAAM,iBAAiB,cAAc,QACnC,KAA8B,SAAiB;AAC/C,MAAI,QAAQ;AACZ,SAAO;IAER,EAAE,CACF;AAGD,WAAU,MAAM,SAAS,SAAS;AACjC,OAAK,WAAW,eAAe,KAAK,aAAa;GAChD;;;;;;;AAQH,eAAsB,oBACrB,QACA,UACA,YAC8B;CAC9B,IAAI,cAAc;CAClB,IAAI,SAAwB;CAC5B,MAAM,OAA2B,EAAE;AAEnC,QAAO,aAAa;EACnB,MAAM,SAAS,MAAM,OAAO,KAAK,kBAAkB;GAClD;GACA,OAAO,WAAW,SAAS;GAC3B;GACA,CAAC;AAEF,OAAK,KAAK,GAAG,OAAO,cAAc;AAElC,gBAAc,OAAO;AACrB,WAAS,OAAO;;AAGjB,QAAO;;;;;;;;AASR,SAAgB,wBAAwB,YAAoB;AAC3D,KAAI,aAAa,KAAK,aAAa,IAClC,OAAM,IAAI,MAAM,+CAA+C;AAChE,QAAO,KAAK,KAAK,aAAa,IAAI;;AAInC,SAAgB,sBAAsB,MAAc;CACnD,MAAM,wBAAwB,KAAK,MAAM,KAAK;AAC9C,uBAAsB,KAAK,oBAAoB,sBAAsB,GAAG;AACxE,QAAO,sBAAsB,KAAK,KAAK"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Advanced Examples
|
|
2
2
|
|
|
3
|
-
> Advanced Kiosk SDK usage patterns and code examples for complex scenarios
|
|
3
|
+
> Advanced Kiosk SDK usage patterns and code examples for complex scenarios
|
|
4
4
|
|
|
5
5
|
# Some extended examples
|
|
6
6
|
|
|
@@ -14,8 +14,8 @@ const bullsharkType = `${packageId}::suifrens::SuiFren<${packageId}::bullshark::
|
|
|
14
14
|
const capyType = `${packageId}::suifrens::SuiFren<${packageId}::capy::Capy>`;
|
|
15
15
|
|
|
16
16
|
// initialize the client with the kiosk extension.
|
|
17
|
-
const client = new
|
|
18
|
-
|
|
17
|
+
const client = new SuiGrpcClient({
|
|
18
|
+
baseUrl: 'https://fullnode.mainnet.sui.io:443',
|
|
19
19
|
network: 'mainnet',
|
|
20
20
|
}).$extend(kiosk());
|
|
21
21
|
```
|
package/docs/from-v1.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Migrating from Kiosk SDK V1
|
|
2
2
|
|
|
3
|
-
> Migrate from Kiosk SDK v1 to the current version with the builder-pattern API
|
|
3
|
+
> Migrate from Kiosk SDK v1 to the current version with the builder-pattern API
|
|
4
4
|
|
|
5
5
|
The original version of Kiosk SDK provided basic experimentation with the Kiosk API. The new version
|
|
6
6
|
of the SDK (0.7+) provides a more robust experience for building kiosk/transfer policy transactions.
|
|
@@ -46,8 +46,8 @@ Using the new SDK, you can build the same transaction as follows:
|
|
|
46
46
|
```typescript
|
|
47
47
|
|
|
48
48
|
// You need to do this only once and re-use it in the application.
|
|
49
|
-
const client = new
|
|
50
|
-
|
|
49
|
+
const client = new SuiGrpcClient({
|
|
50
|
+
baseUrl: 'https://fullnode.mainnet.sui.io:443',
|
|
51
51
|
network: 'mainnet',
|
|
52
52
|
}).$extend(kiosk());
|
|
53
53
|
|
|
@@ -98,8 +98,8 @@ Using the new SDK, you can build the same transaction as follows:
|
|
|
98
98
|
```typescript
|
|
99
99
|
|
|
100
100
|
// You need to do this only once and re-use it in the application.
|
|
101
|
-
const client = new
|
|
102
|
-
|
|
101
|
+
const client = new SuiGrpcClient({
|
|
102
|
+
baseUrl: 'https://fullnode.mainnet.sui.io:443',
|
|
103
103
|
network: 'mainnet',
|
|
104
104
|
}).$extend(kiosk());
|
|
105
105
|
|
|
@@ -198,8 +198,8 @@ Using the new SDK, you can build the same transaction as follows:
|
|
|
198
198
|
```typescript
|
|
199
199
|
|
|
200
200
|
// You need to do this only once and re-use it in the application.
|
|
201
|
-
const client = new
|
|
202
|
-
|
|
201
|
+
const client = new SuiGrpcClient({
|
|
202
|
+
baseUrl: 'https://fullnode.mainnet.sui.io:443',
|
|
203
203
|
network: 'mainnet',
|
|
204
204
|
}).$extend(kiosk());
|
|
205
205
|
|
|
@@ -296,8 +296,8 @@ On the new SDK, the same transaction can be built as follows:
|
|
|
296
296
|
```typescript
|
|
297
297
|
|
|
298
298
|
// You need to do this only once and re-use it in the application.
|
|
299
|
-
const client = new
|
|
300
|
-
|
|
299
|
+
const client = new SuiGrpcClient({
|
|
300
|
+
baseUrl: 'https://fullnode.mainnet.sui.io:443',
|
|
301
301
|
network: 'mainnet',
|
|
302
302
|
}).$extend(kiosk());
|
|
303
303
|
|
package/docs/index.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Kiosk SDK
|
|
2
2
|
|
|
3
|
-
> TypeScript SDK for interacting with Sui Kiosk onchain commerce
|
|
3
|
+
> TypeScript SDK for interacting with Sui Kiosk onchain commerce
|
|
4
4
|
|
|
5
5
|
Kiosk SDK is a tool to interact with Sui and Mysten Kiosk. You can use it to query kiosk related
|
|
6
6
|
data, build transactions to interact, and extend Kiosk to support custom rules.
|
|
@@ -16,7 +16,10 @@ npm i @mysten/kiosk
|
|
|
16
16
|
The Kiosk SDK exports a client extension that integrates with Sui clients. Add it to your client
|
|
17
17
|
using `$extend(kiosk())` to access kiosk functionality through `client.kiosk`.
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
The Kiosk extension accepts any Sui client that implements `ClientWithCoreApi`. Use `SuiGrpcClient`
|
|
20
|
+
for new Kiosk code; `SuiGraphQLClient` and the deprecated `SuiJsonRpcClient` are also compatible.
|
|
21
|
+
|
|
22
|
+
> **Note:** The gRPC object API returns Display v2 metadata. Use GraphQL or JSON-RPC when reading objects
|
|
23
|
+
> whose types still rely on legacy Display metadata.
|
|
21
24
|
|
|
22
25
|
- [Read more about setting up the Kiosk client extension](/kiosk/kiosk-client/introduction)
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
# Kiosk Client
|
|
2
2
|
|
|
3
|
-
> Introduction to the KioskClient extension for querying and managing kiosks on Sui
|
|
3
|
+
> Introduction to the KioskClient extension for querying and managing kiosks on Sui
|
|
4
4
|
|
|
5
5
|
The Kiosk SDK exports a client extension that provides all Kiosk functionality.
|
|
6
6
|
|
|
7
7
|
> We recommend you keep only one client instance throughout your app or script. For example, in
|
|
8
8
|
> React, you'd use a context to provide the client.
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
The Kiosk extension accepts any Sui client that implements `ClientWithCoreApi`. Use `SuiGrpcClient`
|
|
11
|
+
for new Kiosk code; `SuiGraphQLClient` and the deprecated `SuiJsonRpcClient` are also compatible.
|
|
12
|
+
|
|
13
|
+
> **Note:** The gRPC object API returns Display v2 metadata. Use GraphQL or JSON-RPC when reading objects
|
|
14
|
+
> whose types still rely on legacy Display metadata.
|
|
12
15
|
|
|
13
16
|
## Setting up the kiosk extension
|
|
14
17
|
|
|
@@ -20,8 +23,8 @@ require constantly changing the package IDs).
|
|
|
20
23
|
|
|
21
24
|
```typescript
|
|
22
25
|
|
|
23
|
-
const client = new
|
|
24
|
-
|
|
26
|
+
const client = new SuiGrpcClient({
|
|
27
|
+
baseUrl: 'https://fullnode.testnet.sui.io:443',
|
|
25
28
|
network: 'testnet',
|
|
26
29
|
}).$extend(kiosk());
|
|
27
30
|
|
|
@@ -36,8 +39,8 @@ for the rules and extensions you want to use.
|
|
|
36
39
|
|
|
37
40
|
```typescript
|
|
38
41
|
|
|
39
|
-
const client = new
|
|
40
|
-
|
|
42
|
+
const client = new SuiGrpcClient({
|
|
43
|
+
baseUrl: 'https://fullnode.devnet.sui.io:443',
|
|
41
44
|
network: 'devnet',
|
|
42
45
|
}).$extend(
|
|
43
46
|
kiosk({
|
package/docs/llms-index.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# Kiosk
|
|
2
2
|
> Interact with on-chain commerce applications
|
|
3
3
|
|
|
4
|
-
- [Kiosk SDK](..md): TypeScript SDK for interacting with Sui Kiosk onchain commerce
|
|
5
|
-
- [Kiosk Client](./kiosk-client/introduction.md): Introduction to the KioskClient extension for querying and managing kiosks on Sui
|
|
4
|
+
- [Kiosk SDK](..md): TypeScript SDK for interacting with Sui Kiosk onchain commerce
|
|
5
|
+
- [Kiosk Client](./kiosk-client/introduction.md): Introduction to the KioskClient extension for querying and managing kiosks on Sui
|
|
6
6
|
- [Querying](./kiosk-client/querying.md): Query kiosk contents, owned kiosks, items, and transfer policies using the Kiosk SDK.
|
|
7
7
|
- [KioskTransaction](./kiosk-client/kiosk-transaction/kiosk-transaction.md): Build kiosk transactions for listing, purchasing, and managing items on Sui.
|
|
8
8
|
- [Managing Owned Kiosk](./kiosk-client/kiosk-transaction/managing.md): Manage kiosk items by placing, listing, delisting, and withdrawing using the Kiosk SDK.
|
|
@@ -10,5 +10,5 @@
|
|
|
10
10
|
- [Examples](./kiosk-client/kiosk-transaction/examples.md): Practical code examples for kiosk transactions including minting, listing, and purchasing.
|
|
11
11
|
- [TransferPolicyTransaction](./kiosk-client/transfer-policy-transaction/introduction.md): Create and manage transfer policies for kiosk items using the Kiosk SDK.
|
|
12
12
|
- [Using the manager](./kiosk-client/transfer-policy-transaction/using-the-manager.md): Use the TransferPolicyTransaction manager to add rules and withdraw profits.
|
|
13
|
-
- [Advanced Examples](./advanced-examples.md): Advanced Kiosk SDK usage patterns and code examples for complex scenarios
|
|
14
|
-
- [Migrating from Kiosk SDK V1](./from-v1.md): Migrate from Kiosk SDK v1 to the current version with the builder-pattern API
|
|
13
|
+
- [Advanced Examples](./advanced-examples.md): Advanced Kiosk SDK usage patterns and code examples for complex scenarios
|
|
14
|
+
- [Migrating from Kiosk SDK V1](./from-v1.md): Migrate from Kiosk SDK v1 to the current version with the builder-pattern API
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@mysten/kiosk",
|
|
3
3
|
"author": "Mysten Labs <build@mystenlabs.com>",
|
|
4
4
|
"description": "Sui Kiosk library",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.4.0",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "./dist/index.mjs",
|
|
@@ -32,8 +32,7 @@
|
|
|
32
32
|
"url": "https://github.com/MystenLabs/ts-sdks/issues/new"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@mysten/bcs": "^2.1.0"
|
|
36
|
-
"@mysten/utils": "^0.4.0"
|
|
35
|
+
"@mysten/bcs": "^2.1.0"
|
|
37
36
|
},
|
|
38
37
|
"devDependencies": {
|
|
39
38
|
"cross-env": "^10.1.0",
|
|
@@ -45,13 +44,13 @@
|
|
|
45
44
|
"wait-on": "^9.0.10"
|
|
46
45
|
},
|
|
47
46
|
"peerDependencies": {
|
|
48
|
-
"@mysten/sui": "^2.
|
|
47
|
+
"@mysten/sui": "^2.24.0"
|
|
49
48
|
},
|
|
50
49
|
"scripts": {
|
|
51
50
|
"build": "rm -rf dist && tsc --noEmit && tsdown",
|
|
52
51
|
"build:docs": "node ../docs/scripts/build-docs.ts",
|
|
53
52
|
"codegen": "sui-ts-codegen generate && pnpm lint:fix",
|
|
54
|
-
"test": "
|
|
53
|
+
"test": "vitest run --typecheck --config vitest.unit.config.mts",
|
|
55
54
|
"pre-commit": "pnpm prettier:fix && pnpm lint && pnpm build",
|
|
56
55
|
"prettier:check": "prettier -c --ignore-unknown .",
|
|
57
56
|
"prettier:fix": "prettier -w --ignore-unknown .",
|
|
@@ -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 { SuiClientTypes } from '@mysten/sui/client';
|
|
6
5
|
|
|
7
6
|
import {
|
|
@@ -24,6 +23,7 @@ import type {
|
|
|
24
23
|
KioskClientOptions,
|
|
25
24
|
KioskCompatibleClient,
|
|
26
25
|
KioskData,
|
|
26
|
+
KioskPaginationArguments,
|
|
27
27
|
OwnedKiosks,
|
|
28
28
|
} from '../types/index.js';
|
|
29
29
|
|
|
@@ -37,11 +37,11 @@ export type KioskExtensionOptions<Name extends string = 'kiosk'> = {
|
|
|
37
37
|
*
|
|
38
38
|
* @example
|
|
39
39
|
* ```ts
|
|
40
|
-
* import {
|
|
40
|
+
* import { SuiGrpcClient } from '@mysten/sui/grpc';
|
|
41
41
|
* import { kiosk } from '@mysten/kiosk';
|
|
42
42
|
*
|
|
43
|
-
* const client = new
|
|
44
|
-
*
|
|
43
|
+
* const client = new SuiGrpcClient({
|
|
44
|
+
* baseUrl: 'https://fullnode.mainnet.sui.io:443',
|
|
45
45
|
* network: 'mainnet',
|
|
46
46
|
* }).$extend(kiosk());
|
|
47
47
|
*
|
|
@@ -100,7 +100,7 @@ export class KioskClient {
|
|
|
100
100
|
pagination,
|
|
101
101
|
}: {
|
|
102
102
|
address: string;
|
|
103
|
-
pagination?:
|
|
103
|
+
pagination?: KioskPaginationArguments;
|
|
104
104
|
}): Promise<OwnedKiosks> {
|
|
105
105
|
const personalPackageId =
|
|
106
106
|
this.packageIds?.personalKioskRulePackageId || PERSONAL_KIOSK_RULE_ADDRESS[this.network];
|
|
@@ -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> {
|