@mysten/kiosk 1.2.5 → 1.3.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 CHANGED
@@ -1,5 +1,38 @@
1
1
  # @mysten/kiosk
2
2
 
3
+ ## 1.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - bbf63cb: Add `typeTag` and `resolveTypeTag` methods to the generated `MoveStruct`, `MoveEnum`, and
8
+ `MoveTuple` classes.
9
+
10
+ - `typeTag(options?)` builds the type tag string for a generated type. `typeArguments` is the full
11
+ positional list of type arguments in Move declaration order; each entry is a type tag string,
12
+ another `typeTag()` result, or a BCS type (its name is used). Types with unfilled phantom
13
+ parameters require `typeArguments` at compile time, and argument arity is validated at runtime.
14
+ - `resolveTypeTag({ client, ... })` builds the tag, resolves MVR names through
15
+ `client.core.mvr.resolveType`, and returns the normalized address-only form suitable for queries
16
+ and comparisons against on-chain data.
17
+
18
+ - bbf63cb: Updated dependencies
19
+
20
+ ### Patch Changes
21
+
22
+ - Updated dependencies [bbf63cb]
23
+ - @mysten/bcs@2.1.0
24
+ - @mysten/utils@0.4.0
25
+
26
+ ## 1.2.6
27
+
28
+ ### Patch Changes
29
+
30
+ - f7de3e5: Restore docs in published tarballs.
31
+ - Updated dependencies [f7de3e5]
32
+ - @mysten/bcs@2.0.5
33
+ - @mysten/sui@2.16.2
34
+ - @mysten/utils@0.3.3
35
+
3
36
  ## 1.2.5
4
37
 
5
38
  ### Patch Changes
@@ -1,5 +1,5 @@
1
1
  import { BcsStruct, TypeTagSerializer, bcs } from "@mysten/sui/bcs";
2
- import { normalizeSuiAddress } from "@mysten/sui/utils";
2
+ import { normalizeStructTag, normalizeSuiAddress } from "@mysten/sui/utils";
3
3
  import { isArgument } from "@mysten/sui/transactions";
4
4
 
5
5
  //#region src/contracts/utils/index.ts
@@ -84,7 +84,73 @@ function normalizeMoveArguments(args, argTypes, parameterNames) {
84
84
  }
85
85
  return normalizedArgs;
86
86
  }
87
+ const HAS_PHANTOM_REGEX = /phantom [A-Za-z_$][A-Za-z0-9_$]*/;
88
+ function splitTopLevelTypeArgs(inner) {
89
+ const parts = [];
90
+ let depth = 0;
91
+ let current = "";
92
+ for (const char of inner) {
93
+ if (char === "," && depth === 0) {
94
+ parts.push(current.trim());
95
+ current = "";
96
+ continue;
97
+ }
98
+ if (char === "<") depth++;
99
+ if (char === ">") depth--;
100
+ current += char;
101
+ }
102
+ if (current) parts.push(current.trim());
103
+ return parts;
104
+ }
105
+ function buildTypeTag(name, options) {
106
+ const lt = name.indexOf("<");
107
+ const base = lt === -1 ? name : name.slice(0, lt);
108
+ if (base.split("::").length !== 3) throw new Error(`${name} is not a top-level Move type`);
109
+ let result = name;
110
+ if (options?.typeArguments) {
111
+ const baked = lt === -1 ? [] : splitTopLevelTypeArgs(name.slice(lt + 1, -1));
112
+ const supplied = options.typeArguments.map((arg) => {
113
+ if (typeof arg === "string") return arg;
114
+ if (arg && typeof arg.serialize === "function" && typeof arg.name === "string") return arg.name;
115
+ throw new Error(`Invalid type argument ${stringify(arg)}`);
116
+ });
117
+ if (supplied.length !== baked.length) throw new Error(`Expected ${baked.length} type arguments for ${base}, got ${supplied.length}`);
118
+ result = supplied.length === 0 ? base : `${base}<${supplied.join(", ")}>`;
119
+ }
120
+ if (HAS_PHANTOM_REGEX.test(result)) throw new Error(options?.typeArguments ? `A type argument contains an unfilled phantom parameter in ${result}` : `Missing type arguments for ${result}`);
121
+ if (options?.package) {
122
+ const [, ...rest] = result.split("::");
123
+ result = [options.package, ...rest].join("::");
124
+ }
125
+ if (!HAS_PHANTOM_REGEX.test(result) && !/[@/]/.test(result)) TypeTagSerializer.parseFromStr(result);
126
+ return result;
127
+ }
128
+ async function resolveBuiltTypeTag(name, options) {
129
+ const { client, ...rest } = options;
130
+ const { type } = await client.core.mvr.resolveType({ type: buildTypeTag(name, rest) });
131
+ return normalizeStructTag(type);
132
+ }
87
133
  var MoveStruct = class extends BcsStruct {
134
+ /**
135
+ * Build the type tag for this struct.
136
+ *
137
+ * `typeArguments` is the full positional list, in Move declaration order, and
138
+ * is required when the struct has unfilled phantom parameters. The result may
139
+ * contain MVR names: those are valid in transaction `typeArguments`, but for
140
+ * queries or comparisons against on-chain data use `resolveTypeTag` instead.
141
+ */
142
+ typeTag(...args) {
143
+ return buildTypeTag(this.name, args[0]);
144
+ }
145
+ /**
146
+ * Build the type tag for this struct, then resolve any MVR names through the
147
+ * client (using its configured overrides and the MVR API) and return the
148
+ * normalized, address-only form suitable for queries and comparisons against
149
+ * on-chain data.
150
+ */
151
+ async resolveTypeTag(options) {
152
+ return resolveBuiltTypeTag(this.name, options);
153
+ }
88
154
  async get({ objectId, ...options }) {
89
155
  const [res] = await this.getMany({
90
156
  ...options,
@@ -110,7 +176,7 @@ var MoveStruct = class extends BcsStruct {
110
176
  }
111
177
  };
112
178
  function stringify(val) {
113
- if (typeof val === "object") return JSON.stringify(val, (val$1) => val$1);
179
+ if (typeof val === "object") return JSON.stringify(val, (_key, value) => typeof value === "bigint" ? value.toString() : value);
114
180
  if (typeof val === "bigint") return val.toString();
115
181
  return val;
116
182
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["SUI_FRAMEWORK_ADDRESS","val"],"sources":["../../../src/contracts/utils/index.ts"],"sourcesContent":["import {\n\tbcs,\n\ttype BcsType,\n\ttype TypeTag,\n\tTypeTagSerializer,\n\tBcsStruct,\n\tBcsEnum,\n\tBcsTuple,\n} from '@mysten/sui/bcs';\nimport { normalizeSuiAddress } from '@mysten/sui/utils';\nimport { type TransactionArgument, isArgument } from '@mysten/sui/transactions';\nimport { type ClientWithCoreApi, type SuiClientTypes } from '@mysten/sui/client';\n\nconst MOVE_STDLIB_ADDRESS = normalizeSuiAddress('0x1');\nconst SUI_FRAMEWORK_ADDRESS = normalizeSuiAddress('0x2');\n\nexport type RawTransactionArgument<T> = T | TransactionArgument;\n\nexport type GetOptions<Include extends Omit<SuiClientTypes.ObjectInclude, 'content'> = {}> =\n\tSuiClientTypes.GetObjectOptions<Include> & { client: ClientWithCoreApi };\n\nexport type GetManyOptions<Include extends Omit<SuiClientTypes.ObjectInclude, 'content'> = {}> =\n\tSuiClientTypes.GetObjectsOptions<Include> & { client: ClientWithCoreApi };\n\nexport function getPureBcsSchema(typeTag: string | TypeTag): BcsType<any> | null {\n\tconst parsedTag = typeof typeTag === 'string' ? TypeTagSerializer.parseFromStr(typeTag) : typeTag;\n\n\tif ('u8' in parsedTag) {\n\t\treturn bcs.U8;\n\t} else if ('u16' in parsedTag) {\n\t\treturn bcs.U16;\n\t} else if ('u32' in parsedTag) {\n\t\treturn bcs.U32;\n\t} else if ('u64' in parsedTag) {\n\t\treturn bcs.U64;\n\t} else if ('u128' in parsedTag) {\n\t\treturn bcs.U128;\n\t} else if ('u256' in parsedTag) {\n\t\treturn bcs.U256;\n\t} else if ('address' in parsedTag) {\n\t\treturn bcs.Address;\n\t} else if ('bool' in parsedTag) {\n\t\treturn bcs.Bool;\n\t} else if ('vector' in parsedTag) {\n\t\tconst type = getPureBcsSchema(parsedTag.vector);\n\t\treturn type ? bcs.vector(type) : null;\n\t} else if ('struct' in parsedTag) {\n\t\tconst structTag = parsedTag.struct;\n\t\tconst pkg = normalizeSuiAddress(structTag.address);\n\n\t\tif (pkg === MOVE_STDLIB_ADDRESS) {\n\t\t\tif (\n\t\t\t\t(structTag.module === 'ascii' || structTag.module === 'string') &&\n\t\t\t\tstructTag.name === 'String'\n\t\t\t) {\n\t\t\t\treturn bcs.String;\n\t\t\t}\n\n\t\t\tif (structTag.module === 'option' && structTag.name === 'Option') {\n\t\t\t\tconst inner = structTag.typeParams[0];\n\t\t\t\tconst type = inner ? getPureBcsSchema(inner) : null;\n\t\t\t\treturn type ? bcs.option(type) : null;\n\t\t\t}\n\t\t}\n\n\t\tif (\n\t\t\tpkg === SUI_FRAMEWORK_ADDRESS &&\n\t\t\tstructTag.module === 'object' &&\n\t\t\t(structTag.name === 'ID' || structTag.name === 'UID')\n\t\t) {\n\t\t\treturn bcs.Address;\n\t\t}\n\t}\n\n\treturn null;\n}\n\nexport function normalizeMoveArguments(\n\targs: unknown[] | object,\n\targTypes: readonly (string | null)[],\n\tparameterNames?: string[],\n) {\n\tconst argLen = Array.isArray(args) ? args.length : Object.keys(args).length;\n\tif (parameterNames && argLen !== parameterNames.length) {\n\t\tthrow new Error(\n\t\t\t`Invalid number of arguments, expected ${parameterNames.length}, got ${argLen}`,\n\t\t);\n\t}\n\n\tconst normalizedArgs: TransactionArgument[] = [];\n\n\tlet index = 0;\n\tfor (const argType of argTypes) {\n\t\tif (argType === '0x2::clock::Clock') {\n\t\t\tnormalizedArgs.push((tx) => tx.object.clock());\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (argType === '0x2::random::Random') {\n\t\t\tnormalizedArgs.push((tx) => tx.object.random());\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (argType === '0x2::deny_list::DenyList') {\n\t\t\tnormalizedArgs.push((tx) => tx.object.denyList());\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (argType === '0x3::sui_system::SuiSystemState') {\n\t\t\tnormalizedArgs.push((tx) => tx.object.system());\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet arg;\n\t\tif (Array.isArray(args)) {\n\t\t\tif (index >= args.length) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Invalid number of arguments, expected at least ${index + 1}, got ${args.length}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\targ = args[index];\n\t\t} else {\n\t\t\tif (!parameterNames) {\n\t\t\t\tthrow new Error(`Expected arguments to be passed as an array`);\n\t\t\t}\n\t\t\tconst name = parameterNames[index];\n\t\t\targ = args[name as keyof typeof args];\n\n\t\t\tif (arg === undefined) {\n\t\t\t\tthrow new Error(`Parameter ${name} is required`);\n\t\t\t}\n\t\t}\n\n\t\tindex += 1;\n\n\t\tif (typeof arg === 'function' || isArgument(arg)) {\n\t\t\tnormalizedArgs.push(arg as TransactionArgument);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst bcsType = argType === null ? null : getPureBcsSchema(argType);\n\n\t\tif (bcsType) {\n\t\t\tconst bytes = bcsType.serialize(arg as never);\n\t\t\tnormalizedArgs.push((tx) => tx.pure(bytes));\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (typeof arg === 'string') {\n\t\t\tnormalizedArgs.push((tx) => tx.object(arg));\n\t\t\tcontinue;\n\t\t}\n\n\t\tthrow new Error(`Invalid argument ${stringify(arg)} for type ${argType}`);\n\t}\n\n\treturn normalizedArgs;\n}\n\nexport class MoveStruct<\n\tT extends Record<string, BcsType<any>>,\n\tconst Name extends string = string,\n> extends BcsStruct<T, Name> {\n\tasync get<Include extends Omit<SuiClientTypes.ObjectInclude, 'content' | 'json'> = {}>({\n\t\tobjectId,\n\t\t...options\n\t}: GetOptions<Include>): Promise<\n\t\tSuiClientTypes.Object<Include & { content: true; json: true }> & {\n\t\t\tjson: BcsStruct<T>['$inferType'];\n\t\t}\n\t> {\n\t\tconst [res] = await this.getMany<Include>({\n\t\t\t...options,\n\t\t\tobjectIds: [objectId],\n\t\t});\n\n\t\tif (!res) {\n\t\t\tthrow new Error(`No object found for id ${objectId}`);\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tasync getMany<Include extends Omit<SuiClientTypes.ObjectInclude, 'content' | 'json'> = {}>({\n\t\tclient,\n\t\t...options\n\t}: GetManyOptions<Include>): Promise<\n\t\tArray<\n\t\t\tSuiClientTypes.Object<Include & { content: true; json: true }> & {\n\t\t\t\tjson: BcsStruct<T>['$inferType'];\n\t\t\t}\n\t\t>\n\t> {\n\t\tconst response = (await client.core.getObjects({\n\t\t\t...options,\n\t\t\tinclude: {\n\t\t\t\t...options.include,\n\t\t\t\tcontent: true,\n\t\t\t},\n\t\t})) as SuiClientTypes.GetObjectsResponse<Include & { content: true }>;\n\n\t\treturn response.objects.map((obj) => {\n\t\t\tif (obj instanceof Error) {\n\t\t\t\tthrow obj;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...obj,\n\t\t\t\tjson: this.parse(obj.content),\n\t\t\t};\n\t\t});\n\t}\n}\n\nexport class MoveEnum<\n\tT extends Record<string, BcsType<any> | null>,\n\tconst Name extends string,\n> extends BcsEnum<T, Name> {}\n\nexport class MoveTuple<\n\tconst T extends readonly BcsType<any>[],\n\tconst Name extends string,\n> extends BcsTuple<T, Name> {}\n\nfunction stringify(val: unknown) {\n\tif (typeof val === 'object') {\n\t\treturn JSON.stringify(val, (val: unknown) => val);\n\t}\n\tif (typeof val === 'bigint') {\n\t\treturn val.toString();\n\t}\n\n\treturn val;\n}\n"],"mappings":";;;;;AAaA,MAAM,sBAAsB,oBAAoB,MAAM;AACtD,MAAMA,0BAAwB,oBAAoB,MAAM;AAUxD,SAAgB,iBAAiB,SAAgD;CAChF,MAAM,YAAY,OAAO,YAAY,WAAW,kBAAkB,aAAa,QAAQ,GAAG;AAE1F,KAAI,QAAQ,UACX,QAAO,IAAI;UACD,SAAS,UACnB,QAAO,IAAI;UACD,SAAS,UACnB,QAAO,IAAI;UACD,SAAS,UACnB,QAAO,IAAI;UACD,UAAU,UACpB,QAAO,IAAI;UACD,UAAU,UACpB,QAAO,IAAI;UACD,aAAa,UACvB,QAAO,IAAI;UACD,UAAU,UACpB,QAAO,IAAI;UACD,YAAY,WAAW;EACjC,MAAM,OAAO,iBAAiB,UAAU,OAAO;AAC/C,SAAO,OAAO,IAAI,OAAO,KAAK,GAAG;YACvB,YAAY,WAAW;EACjC,MAAM,YAAY,UAAU;EAC5B,MAAM,MAAM,oBAAoB,UAAU,QAAQ;AAElD,MAAI,QAAQ,qBAAqB;AAChC,QACE,UAAU,WAAW,WAAW,UAAU,WAAW,aACtD,UAAU,SAAS,SAEnB,QAAO,IAAI;AAGZ,OAAI,UAAU,WAAW,YAAY,UAAU,SAAS,UAAU;IACjE,MAAM,QAAQ,UAAU,WAAW;IACnC,MAAM,OAAO,QAAQ,iBAAiB,MAAM,GAAG;AAC/C,WAAO,OAAO,IAAI,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ACZ,MAAM,QAAQ,QAAQ,UAAU,IAAa;AAC7C,kBAAe,MAAM,OAAO,GAAG,KAAK,MAAM,CAAC;AAC3C;;AAGD,MAAI,OAAO,QAAQ,UAAU;AAC5B,kBAAe,MAAM,OAAO,GAAG,OAAO,IAAI,CAAC;AAC3C;;AAGD,QAAM,IAAI,MAAM,oBAAoB,UAAU,IAAI,CAAC,YAAY,UAAU;;AAG1E,QAAO;;AAGR,IAAa,aAAb,cAGU,UAAmB;CAC5B,MAAM,IAAiF,EACtF,UACA,GAAG,WAKF;EACD,MAAM,CAAC,OAAO,MAAM,KAAK,QAAiB;GACzC,GAAG;GACH,WAAW,CAAC,SAAS;GACrB,CAAC;AAEF,MAAI,CAAC,IACJ,OAAM,IAAI,MAAM,0BAA0B,WAAW;AAGtD,SAAO;;CAGR,MAAM,QAAqF,EAC1F,QACA,GAAG,WAOF;AASD,UARkB,MAAM,OAAO,KAAK,WAAW;GAC9C,GAAG;GACH,SAAS;IACR,GAAG,QAAQ;IACX,SAAS;IACT;GACD,CAAC,EAEc,QAAQ,KAAK,QAAQ;AACpC,OAAI,eAAe,MAClB,OAAM;AAGP,UAAO;IACN,GAAG;IACH,MAAM,KAAK,MAAM,IAAI,QAAQ;IAC7B;IACA;;;AAcJ,SAAS,UAAU,KAAc;AAChC,KAAI,OAAO,QAAQ,SAClB,QAAO,KAAK,UAAU,MAAM,UAAiBC,MAAI;AAElD,KAAI,OAAO,QAAQ,SAClB,QAAO,IAAI,UAAU;AAGtB,QAAO"}
1
+ {"version":3,"file":"index.mjs","names":["SUI_FRAMEWORK_ADDRESS"],"sources":["../../../src/contracts/utils/index.ts"],"sourcesContent":["import {\n\tbcs,\n\ttype BcsType,\n\ttype TypeTag,\n\tTypeTagSerializer,\n\tBcsStruct,\n\tBcsEnum,\n\tBcsTuple,\n} from '@mysten/sui/bcs';\nimport { normalizeStructTag, normalizeSuiAddress } from '@mysten/sui/utils';\nimport { type TransactionArgument, isArgument } from '@mysten/sui/transactions';\nimport { type ClientWithCoreApi, type SuiClientTypes } from '@mysten/sui/client';\n\nconst MOVE_STDLIB_ADDRESS = normalizeSuiAddress('0x1');\nconst SUI_FRAMEWORK_ADDRESS = normalizeSuiAddress('0x2');\n\nexport type RawTransactionArgument<T> = T | TransactionArgument;\n\nexport type GetOptions<Include extends Omit<SuiClientTypes.ObjectInclude, 'content'> = {}> =\n\tSuiClientTypes.GetObjectOptions<Include> & { client: ClientWithCoreApi };\n\nexport type GetManyOptions<Include extends Omit<SuiClientTypes.ObjectInclude, 'content'> = {}> =\n\tSuiClientTypes.GetObjectsOptions<Include> & { client: ClientWithCoreApi };\n\nexport function getPureBcsSchema(typeTag: string | TypeTag): BcsType<any> | null {\n\tconst parsedTag = typeof typeTag === 'string' ? TypeTagSerializer.parseFromStr(typeTag) : typeTag;\n\n\tif ('u8' in parsedTag) {\n\t\treturn bcs.U8;\n\t} else if ('u16' in parsedTag) {\n\t\treturn bcs.U16;\n\t} else if ('u32' in parsedTag) {\n\t\treturn bcs.U32;\n\t} else if ('u64' in parsedTag) {\n\t\treturn bcs.U64;\n\t} else if ('u128' in parsedTag) {\n\t\treturn bcs.U128;\n\t} else if ('u256' in parsedTag) {\n\t\treturn bcs.U256;\n\t} else if ('address' in parsedTag) {\n\t\treturn bcs.Address;\n\t} else if ('bool' in parsedTag) {\n\t\treturn bcs.Bool;\n\t} else if ('vector' in parsedTag) {\n\t\tconst type = getPureBcsSchema(parsedTag.vector);\n\t\treturn type ? bcs.vector(type) : null;\n\t} else if ('struct' in parsedTag) {\n\t\tconst structTag = parsedTag.struct;\n\t\tconst pkg = normalizeSuiAddress(structTag.address);\n\n\t\tif (pkg === MOVE_STDLIB_ADDRESS) {\n\t\t\tif (\n\t\t\t\t(structTag.module === 'ascii' || structTag.module === 'string') &&\n\t\t\t\tstructTag.name === 'String'\n\t\t\t) {\n\t\t\t\treturn bcs.String;\n\t\t\t}\n\n\t\t\tif (structTag.module === 'option' && structTag.name === 'Option') {\n\t\t\t\tconst inner = structTag.typeParams[0];\n\t\t\t\tconst type = inner ? getPureBcsSchema(inner) : null;\n\t\t\t\treturn type ? bcs.option(type) : null;\n\t\t\t}\n\t\t}\n\n\t\tif (\n\t\t\tpkg === SUI_FRAMEWORK_ADDRESS &&\n\t\t\tstructTag.module === 'object' &&\n\t\t\t(structTag.name === 'ID' || structTag.name === 'UID')\n\t\t) {\n\t\t\treturn bcs.Address;\n\t\t}\n\t}\n\n\treturn null;\n}\n\nexport function normalizeMoveArguments(\n\targs: unknown[] | object,\n\targTypes: readonly (string | null)[],\n\tparameterNames?: string[],\n) {\n\tconst argLen = Array.isArray(args) ? args.length : Object.keys(args).length;\n\tif (parameterNames && argLen !== parameterNames.length) {\n\t\tthrow new Error(\n\t\t\t`Invalid number of arguments, expected ${parameterNames.length}, got ${argLen}`,\n\t\t);\n\t}\n\n\tconst normalizedArgs: TransactionArgument[] = [];\n\n\tlet index = 0;\n\tfor (const argType of argTypes) {\n\t\tif (argType === '0x2::clock::Clock') {\n\t\t\tnormalizedArgs.push((tx) => tx.object.clock());\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (argType === '0x2::random::Random') {\n\t\t\tnormalizedArgs.push((tx) => tx.object.random());\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (argType === '0x2::deny_list::DenyList') {\n\t\t\tnormalizedArgs.push((tx) => tx.object.denyList());\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (argType === '0x3::sui_system::SuiSystemState') {\n\t\t\tnormalizedArgs.push((tx) => tx.object.system());\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet arg;\n\t\tif (Array.isArray(args)) {\n\t\t\tif (index >= args.length) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Invalid number of arguments, expected at least ${index + 1}, got ${args.length}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\targ = args[index];\n\t\t} else {\n\t\t\tif (!parameterNames) {\n\t\t\t\tthrow new Error(`Expected arguments to be passed as an array`);\n\t\t\t}\n\t\t\tconst name = parameterNames[index];\n\t\t\targ = args[name as keyof typeof args];\n\n\t\t\tif (arg === undefined) {\n\t\t\t\tthrow new Error(`Parameter ${name} is required`);\n\t\t\t}\n\t\t}\n\n\t\tindex += 1;\n\n\t\tif (typeof arg === 'function' || isArgument(arg)) {\n\t\t\tnormalizedArgs.push(arg as TransactionArgument);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst bcsType = argType === null ? null : getPureBcsSchema(argType);\n\n\t\tif (bcsType) {\n\t\t\tconst bytes = bcsType.serialize(arg as never);\n\t\t\tnormalizedArgs.push((tx) => tx.pure(bytes));\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (typeof arg === 'string') {\n\t\t\tnormalizedArgs.push((tx) => tx.object(arg));\n\t\t\tcontinue;\n\t\t}\n\n\t\tthrow new Error(`Invalid argument ${stringify(arg)} for type ${argType}`);\n\t}\n\n\treturn normalizedArgs;\n}\n\n/* -------------------------- Move type tags -------------------------- */\n\n/** A type argument: a type tag string, or a BCS type whose name is a Move type. */\nexport type TypeArgument = string | BcsType<any>;\n\nexport interface TypeTagOptions {\n\tpackage?: string;\n\ttypeArguments?: readonly TypeArgument[];\n}\n\n/**\n * `typeArguments` is required when the type's name contains unfilled\n * `phantom X` parameters (at any depth). Everything else — argument arity,\n * position contents, and tag validity — is validated at runtime.\n */\ntype TypeTagParams<Name extends string> = Name extends `${string}phantom ${string}`\n\t? [options: TypeTagOptions & { typeArguments: readonly TypeArgument[] }]\n\t: [options?: TypeTagOptions];\n\ntype ResolveTypeTagOptions<Name extends string> = {\n\tclient: ClientWithCoreApi;\n} & (Name extends `${string}phantom ${string}`\n\t? TypeTagOptions & { typeArguments: readonly TypeArgument[] }\n\t: TypeTagOptions);\n\nconst HAS_PHANTOM_REGEX = /phantom [A-Za-z_$][A-Za-z0-9_$]*/;\n\nfunction splitTopLevelTypeArgs(inner: string): string[] {\n\tconst parts: string[] = [];\n\tlet depth = 0;\n\tlet current = '';\n\tfor (const char of inner) {\n\t\tif (char === ',' && depth === 0) {\n\t\t\tparts.push(current.trim());\n\t\t\tcurrent = '';\n\t\t\tcontinue;\n\t\t}\n\t\tif (char === '<') depth++;\n\t\tif (char === '>') depth--;\n\t\tcurrent += char;\n\t}\n\tif (current) parts.push(current.trim());\n\treturn parts;\n}\n\nfunction buildTypeTag(name: string, options: TypeTagOptions | undefined): string {\n\tconst lt = name.indexOf('<');\n\tconst base = lt === -1 ? name : name.slice(0, lt);\n\n\tif (base.split('::').length !== 3) {\n\t\tthrow new Error(`${name} is not a top-level Move type`);\n\t}\n\n\tlet result = name;\n\n\tif (options?.typeArguments) {\n\t\tconst baked = lt === -1 ? [] : splitTopLevelTypeArgs(name.slice(lt + 1, -1));\n\t\tconst supplied = options.typeArguments.map((arg) => {\n\t\t\tif (typeof arg === 'string') {\n\t\t\t\treturn arg;\n\t\t\t}\n\t\t\tif (arg && typeof arg.serialize === 'function' && typeof arg.name === 'string') {\n\t\t\t\treturn arg.name;\n\t\t\t}\n\t\t\tthrow new Error(`Invalid type argument ${stringify(arg)}`);\n\t\t});\n\n\t\tif (supplied.length !== baked.length) {\n\t\t\tthrow new Error(\n\t\t\t\t`Expected ${baked.length} type arguments for ${base}, got ${supplied.length}`,\n\t\t\t);\n\t\t}\n\n\t\tresult = supplied.length === 0 ? base : `${base}<${supplied.join(', ')}>`;\n\t}\n\n\tif (HAS_PHANTOM_REGEX.test(result)) {\n\t\tthrow new Error(\n\t\t\toptions?.typeArguments\n\t\t\t\t? `A type argument contains an unfilled phantom parameter in ${result}`\n\t\t\t\t: `Missing type arguments for ${result}`,\n\t\t);\n\t}\n\n\tif (options?.package) {\n\t\tconst [, ...rest] = result.split('::');\n\t\tresult = [options.package, ...rest].join('::');\n\t}\n\n\t// fully validate address-only tags (MVR names can't be parsed as type tags)\n\tif (!HAS_PHANTOM_REGEX.test(result) && !/[@/]/.test(result)) {\n\t\tTypeTagSerializer.parseFromStr(result);\n\t}\n\n\treturn result;\n}\n\nasync function resolveBuiltTypeTag(\n\tname: string,\n\toptions: { client: ClientWithCoreApi } & TypeTagOptions,\n): Promise<string> {\n\tconst { client, ...rest } = options;\n\tconst { type } = await client.core.mvr.resolveType({\n\t\ttype: buildTypeTag(name, rest),\n\t});\n\treturn normalizeStructTag(type);\n}\n\nexport class MoveStruct<\n\tT extends Record<string, BcsType<any>>,\n\tconst Name extends string = string,\n> extends BcsStruct<T, Name> {\n\t/**\n\t * Build the type tag for this struct.\n\t *\n\t * `typeArguments` is the full positional list, in Move declaration order, and\n\t * is required when the struct has unfilled phantom parameters. The result may\n\t * contain MVR names: those are valid in transaction `typeArguments`, but for\n\t * queries or comparisons against on-chain data use `resolveTypeTag` instead.\n\t */\n\ttypeTag(...args: TypeTagParams<Name>): string {\n\t\treturn buildTypeTag(this.name, args[0] as TypeTagOptions | undefined);\n\t}\n\n\t/**\n\t * Build the type tag for this struct, then resolve any MVR names through the\n\t * client (using its configured overrides and the MVR API) and return the\n\t * normalized, address-only form suitable for queries and comparisons against\n\t * on-chain data.\n\t */\n\tasync resolveTypeTag(options: ResolveTypeTagOptions<Name>): Promise<string> {\n\t\treturn resolveBuiltTypeTag(\n\t\t\tthis.name,\n\t\t\toptions as { client: ClientWithCoreApi } & TypeTagOptions,\n\t\t);\n\t}\n\n\tasync get<Include extends Omit<SuiClientTypes.ObjectInclude, 'content' | 'json'> = {}>({\n\t\tobjectId,\n\t\t...options\n\t}: GetOptions<Include>): Promise<\n\t\tSuiClientTypes.Object<Include & { content: true; json: true }> & {\n\t\t\tjson: BcsStruct<T>['$inferType'];\n\t\t}\n\t> {\n\t\tconst [res] = await this.getMany<Include>({\n\t\t\t...options,\n\t\t\tobjectIds: [objectId],\n\t\t});\n\n\t\tif (!res) {\n\t\t\tthrow new Error(`No object found for id ${objectId}`);\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tasync getMany<Include extends Omit<SuiClientTypes.ObjectInclude, 'content' | 'json'> = {}>({\n\t\tclient,\n\t\t...options\n\t}: GetManyOptions<Include>): Promise<\n\t\tArray<\n\t\t\tSuiClientTypes.Object<Include & { content: true; json: true }> & {\n\t\t\t\tjson: BcsStruct<T>['$inferType'];\n\t\t\t}\n\t\t>\n\t> {\n\t\tconst response = (await client.core.getObjects({\n\t\t\t...options,\n\t\t\tinclude: {\n\t\t\t\t...options.include,\n\t\t\t\tcontent: true,\n\t\t\t},\n\t\t})) as SuiClientTypes.GetObjectsResponse<Include & { content: true }>;\n\n\t\treturn response.objects.map((obj) => {\n\t\t\tif (obj instanceof Error) {\n\t\t\t\tthrow obj;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...obj,\n\t\t\t\tjson: this.parse(obj.content),\n\t\t\t};\n\t\t});\n\t}\n}\n\nexport class MoveEnum<\n\tT extends Record<string, BcsType<any> | null>,\n\tconst Name extends string,\n> extends BcsEnum<T, Name> {\n\t/** Build the type tag for this enum. See `MoveStruct.typeTag` for semantics. */\n\ttypeTag(...args: TypeTagParams<Name>): string {\n\t\treturn buildTypeTag(this.name, args[0] as TypeTagOptions | undefined);\n\t}\n\n\t/** Build and resolve the type tag for this enum. See `MoveStruct.resolveTypeTag`. */\n\tasync resolveTypeTag(options: ResolveTypeTagOptions<Name>): Promise<string> {\n\t\treturn resolveBuiltTypeTag(\n\t\t\tthis.name,\n\t\t\toptions as { client: ClientWithCoreApi } & TypeTagOptions,\n\t\t);\n\t}\n}\n\nexport class MoveTuple<\n\tconst T extends readonly BcsType<any>[],\n\tconst Name extends string,\n> extends BcsTuple<T, Name> {\n\t/** Build the type tag for this struct. See `MoveStruct.typeTag` for semantics. */\n\ttypeTag(...args: TypeTagParams<Name>): string {\n\t\treturn buildTypeTag(this.name, args[0] as TypeTagOptions | undefined);\n\t}\n\n\t/** Build and resolve the type tag for this struct. See `MoveStruct.resolveTypeTag`. */\n\tasync resolveTypeTag(options: ResolveTypeTagOptions<Name>): Promise<string> {\n\t\treturn resolveBuiltTypeTag(\n\t\t\tthis.name,\n\t\t\toptions as { client: ClientWithCoreApi } & TypeTagOptions,\n\t\t);\n\t}\n}\n\nfunction stringify(val: unknown) {\n\tif (typeof val === 'object') {\n\t\treturn JSON.stringify(val, (_key, value) =>\n\t\t\ttypeof value === 'bigint' ? value.toString() : value,\n\t\t);\n\t}\n\tif (typeof val === 'bigint') {\n\t\treturn val.toString();\n\t}\n\n\treturn val;\n}\n"],"mappings":";;;;;AAaA,MAAM,sBAAsB,oBAAoB,MAAM;AACtD,MAAMA,0BAAwB,oBAAoB,MAAM;AAUxD,SAAgB,iBAAiB,SAAgD;CAChF,MAAM,YAAY,OAAO,YAAY,WAAW,kBAAkB,aAAa,QAAQ,GAAG;AAE1F,KAAI,QAAQ,UACX,QAAO,IAAI;UACD,SAAS,UACnB,QAAO,IAAI;UACD,SAAS,UACnB,QAAO,IAAI;UACD,SAAS,UACnB,QAAO,IAAI;UACD,UAAU,UACpB,QAAO,IAAI;UACD,UAAU,UACpB,QAAO,IAAI;UACD,aAAa,UACvB,QAAO,IAAI;UACD,UAAU,UACpB,QAAO,IAAI;UACD,YAAY,WAAW;EACjC,MAAM,OAAO,iBAAiB,UAAU,OAAO;AAC/C,SAAO,OAAO,IAAI,OAAO,KAAK,GAAG;YACvB,YAAY,WAAW;EACjC,MAAM,YAAY,UAAU;EAC5B,MAAM,MAAM,oBAAoB,UAAU,QAAQ;AAElD,MAAI,QAAQ,qBAAqB;AAChC,QACE,UAAU,WAAW,WAAW,UAAU,WAAW,aACtD,UAAU,SAAS,SAEnB,QAAO,IAAI;AAGZ,OAAI,UAAU,WAAW,YAAY,UAAU,SAAS,UAAU;IACjE,MAAM,QAAQ,UAAU,WAAW;IACnC,MAAM,OAAO,QAAQ,iBAAiB,MAAM,GAAG;AAC/C,WAAO,OAAO,IAAI,OAAO,KAAK,GAAG;;;AAInC,MACC,QAAQA,2BACR,UAAU,WAAW,aACpB,UAAU,SAAS,QAAQ,UAAU,SAAS,OAE/C,QAAO,IAAI;;AAIb,QAAO;;AAGR,SAAgB,uBACf,MACA,UACA,gBACC;CACD,MAAM,S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QAAO,KAAK,UAAU,MAAM,MAAM,UACjC,OAAO,UAAU,WAAW,MAAM,UAAU,GAAG,MAC/C;AAEF,KAAI,OAAO,QAAQ,SAClB,QAAO,IAAI,UAAU;AAGtB,QAAO"}
@@ -0,0 +1,101 @@
1
+ # Advanced Examples
2
+
3
+ > Advanced Kiosk SDK usage patterns and code examples for complex scenarios.
4
+
5
+ # Some extended examples
6
+
7
+ For these examples, assume you have the following data and functions available:
8
+
9
+ ```typescript
10
+
11
+ // a constant for bullshark's type.
12
+ const bullsharkType = `${packageId}::suifrens::SuiFren<${packageId}::bullshark::Bullshark>`;
13
+ // a constant for capy's type.
14
+ const capyType = `${packageId}::suifrens::SuiFren<${packageId}::capy::Capy>`;
15
+
16
+ // initialize the client with the kiosk extension.
17
+ const client = new SuiJsonRpcClient({
18
+ url: getJsonRpcFullnodeUrl('mainnet'),
19
+ network: 'mainnet',
20
+ }).$extend(kiosk());
21
+ ```
22
+
23
+ ## Minting a SuiFren
24
+
25
+ This example demonstrates how to mint a SuiFren.
26
+
27
+ ```typescript
28
+ async function mintFren(address: string) {
29
+ const { kioskOwnerCaps } = await client.kiosk.getOwnedKiosks({ address });
30
+
31
+ // Choose the first kiosk for simplicity. We could have extra logic here (e.g. let the user choose, pick a personal one, etc).
32
+ const cap = kioskOwnerCaps[0];
33
+
34
+ const tx = new Transaction();
35
+ const kioskTx = new KioskTransaction({ transaction: tx, kioskClient: client.kiosk, cap });
36
+
37
+ // We're mixing the logic here. If the cap is undefined, we create a new kiosk.
38
+ if (!cap) kioskTx.create();
39
+
40
+ // Let's mint a capy here into the kiosk (either a new or an existing one).
41
+ tx.moveCall({
42
+ target: `${packageId}::suifrens::mint_app::mint`,
43
+ arguments: [kioskTx.getKiosk(), kioskTx.getKioskCap()],
44
+ typeArguments: [capyType],
45
+ });
46
+
47
+ // If we don't have a cap, that means we create a new kiosk for the user in this flow.
48
+ if (!cap) kioskTx.shareAndTransferCap(address);
49
+
50
+ kioskTx.finalize();
51
+
52
+ // sign and execute transaction.
53
+ await signAndExecuteTransaction({ tx: tx });
54
+ }
55
+ ```
56
+
57
+ ## Mixing two Suifrens
58
+
59
+ This example demonstrates how to use the Kiosk SDK to mix two `bullsharks`.
60
+
61
+ ```typescript
62
+ // We're mixing two frens.
63
+ async function mixFrens(firstFrenObjectId: string, secondFrenObjectId: string, cap: KioskOwnerCap) {
64
+ const tx = new Transaction();
65
+ const kioskTx = new KioskTransaction({ transaction: tx, kioskClient: client.kiosk, cap });
66
+
67
+ // borrow both frens.
68
+ const [fren1, promise1] = kioskTx.borrow({
69
+ itemType: bullsharkType,
70
+ itemId: firstFrenObjectId,
71
+ });
72
+
73
+ const [fren2, promise2] = kioskTx.borrow({
74
+ itemType: bullsharkType,
75
+ itemId: secondFrenObjectId,
76
+ });
77
+
78
+ // Let's call the mix function. We skip any payment related stuff here.
79
+ tx.moveCall({
80
+ target: `${packageId}::mix_app::mix`,
81
+ arguments: [fren1, fren2, kioskTx.getKiosk(), kioskTx.getKioskCap()],
82
+ typeArguments: [bullsharkType],
83
+ });
84
+
85
+ kioskTx
86
+ .return({
87
+ itemType: bullsharkType,
88
+ item: fren1,
89
+ promise: promise1,
90
+ })
91
+ .return({
92
+ itemType: bullsharkType,
93
+ item: fren2,
94
+ promise: promise2,
95
+ })
96
+ .finalize();
97
+
98
+ // sign and execute transaction.
99
+ await signAndExecuteTransaction({ tx: tx });
100
+ }
101
+ ```
@@ -0,0 +1,320 @@
1
+ # Migrating from Kiosk SDK V1
2
+
3
+ > Migrate from Kiosk SDK v1 to the current version with the builder-pattern API.
4
+
5
+ The original version of Kiosk SDK provided basic experimentation with the Kiosk API. The new version
6
+ of the SDK (0.7+) provides a more robust experience for building kiosk/transfer policy transactions.
7
+
8
+ The new SDK offers a builder-pattern API, which provides better autocomplete capabilities, and also
9
+ makes code more readable.
10
+
11
+ While a one-to-one mapping between the old and new SDK is not possible, the following examples
12
+ should help you get started.
13
+
14
+ > An important benefit of the new SDK is that it works seamlessly with Personal Kiosk, which was not
15
+ > the case with the previous SDK (you would always have to wrap the transaction with `borrow_cap` /
16
+ > `return_cap` calls depending on whether the kiosk is personal or not).
17
+
18
+ ## Placing an item to kiosk and listing it for sale
19
+
20
+ The following example is from the original Kiosk SDK V1 documentation.
21
+
22
+ ### Before
23
+
24
+ ```typescript
25
+
26
+ const placeAndListToKiosk = async () => {
27
+ const kiosk = 'SomeKioskId';
28
+ const kioskCap = 'KioskCapObjectId';
29
+ const itemType = '0xItemAddr::some:ItemType';
30
+ const item = 'SomeItemId';
31
+ const price = '100000';
32
+
33
+ const tx = new Transaction();
34
+
35
+ placeAndList(tx, itemType, kiosk, kioskCap, item, price);
36
+
37
+ // ... continue to sign and execute the transaction
38
+ // ...
39
+ };
40
+ ```
41
+
42
+ ### After
43
+
44
+ Using the new SDK, you can build the same transaction as follows:
45
+
46
+ ```typescript
47
+
48
+ // You need to do this only once and re-use it in the application.
49
+ const client = new SuiJsonRpcClient({
50
+ url: getJsonRpcFullnodeUrl('mainnet'),
51
+ network: 'mainnet',
52
+ }).$extend(kiosk());
53
+
54
+ const placeAndListToKiosk = async () => {
55
+ // Assume you have saved the user's preferred kiosk Cap somewhere in your app's state.
56
+ const { kioskOwnerCaps } = await client.kiosk.getOwnedKiosks({ address: '0xSomeAddress' });
57
+
58
+ const tx = new Transaction();
59
+
60
+ // Assume you use the first owned kiosk.
61
+ new KioskTransaction({ transaction: tx, kioskClient: client.kiosk, cap: kioskOwnerCaps[0] })
62
+ .placeAndList({
63
+ itemType: '0xItemAddr::some:ItemType',
64
+ item: 'SomeItemId',
65
+ price: '100000',
66
+ })
67
+ .finalize();
68
+
69
+ // ... continue to sign and execute the transaction
70
+ };
71
+ ```
72
+
73
+ ## Create a new kiosk
74
+
75
+ The following example is from the original Kiosk SDK V1 documentation.
76
+
77
+ ### Before
78
+
79
+ ```typescript
80
+
81
+ const createKiosk = async () => {
82
+ const accountAddress = '0xSomeSuiAddress';
83
+
84
+ const tx = new Transaction();
85
+ const kiosk_cap = createKioskAndShare(tx);
86
+
87
+ tx.transferObjects([kiosk_cap], accountAddress);
88
+
89
+ // ... continue to sign and execute the transaction
90
+ // ...
91
+ };
92
+ ```
93
+
94
+ ### After
95
+
96
+ Using the new SDK, you can build the same transaction as follows:
97
+
98
+ ```typescript
99
+
100
+ // You need to do this only once and re-use it in the application.
101
+ const client = new SuiJsonRpcClient({
102
+ url: getJsonRpcFullnodeUrl('mainnet'),
103
+ network: 'mainnet',
104
+ }).$extend(kiosk());
105
+
106
+ const createKiosk = async () => {
107
+ const tx = new Transaction();
108
+
109
+ const kioskTx = new KioskTransaction({ transaction: tx, kioskClient: client.kiosk });
110
+
111
+ kioskTx.create().shareAndTransferCap('0xSomeSuiAddress').finalize();
112
+
113
+ // ... continue to sign and execute the transaction
114
+ };
115
+ ```
116
+
117
+ ## Purchasing an item and resolving rules
118
+
119
+ The following example is from the original Kiosk SDK V1 documentation.
120
+
121
+ ### Before
122
+
123
+ ```typescript
124
+
125
+ queryTransferPolicy,
126
+ purchaseAndResolvePolicies,
127
+ place,
128
+ testnetEnvironment,
129
+ } from '@mysten/kiosk';
130
+
131
+ const client = new SuiJsonRpcClient({
132
+ url: 'https://fullnode.testnet.sui.io:443',
133
+ });
134
+
135
+ // The kiosk we're purchasing from.
136
+ const kioskId = `0xSomeKioskAddress`;
137
+ // A sample item retrieved from `fetchKiosk` function (or hard-coded).
138
+ const item = {
139
+ isLocked: false,
140
+ objectId: '0xb892d61a9992a10c9453efcdbd14ca9720d7dc1000a2048224209c9e544ed223',
141
+ type: '0x52852c4ba80040395b259c641e70b702426a58990ff73cecf5afd31954429090::test::TestItem',
142
+ listing: {
143
+ isExclusive: false,
144
+ listingId: '0x368b512ff2514dbea814f26ec9a3d41198c00e8ed778099961e9ed22a9f0032b',
145
+ price: '20000000000', // in MIST
146
+ },
147
+ };
148
+ const ownedKiosk = `0xMyKioskAddress`;
149
+ const ownedKioskCap = `0xMyKioskOwnerCap`;
150
+
151
+ const purchaseItem = async (item, kioskId) => {
152
+ // Fetch the policy of the item (could be an array, if there's more than one transfer policy)
153
+ const policies = await queryTransferPolicy(client, item.type);
154
+ // Selecting the first one for simplicity.
155
+ const policyId = policy[0]?.id;
156
+ // Initialize transaction.
157
+ const tx = new Transaction();
158
+
159
+ // Both are required if there is a `kiosk_lock_rule`.
160
+ // Optional otherwise. Function throws an error if there's a kiosk_lock_rule and these are missing.
161
+ const extraParams = {
162
+ ownedKiosk,
163
+ ownedKioskCap,
164
+ };
165
+ // Define the environment.
166
+ // To use a custom package address for rules, you could call:
167
+ // const environment = customEnvironment('<PackageAddress>');
168
+ const environment = testnetEnvironment;
169
+
170
+ // Extra params. Optional, but required if the user tries to resolve a `kiosk_lock_rule`.
171
+ // Purchases the item. Supports `kiosk_lock_rule`, `royalty_rule` (accepts combination too).
172
+ const result = purchaseAndResolvePolicies(
173
+ tx,
174
+ item.type,
175
+ item.listing.price,
176
+ kioskId,
177
+ item.objectId,
178
+ policy[0],
179
+ environment,
180
+ extraParams,
181
+ );
182
+
183
+ // result = {item: <the_purchased_item>, canTransfer: true/false // depending on whether there was a kiosk lock rule }
184
+ // If the item didn't have a kiosk_lock_rule, you need to do something with it.
185
+ // For example, place it in your own kiosk. (demonstrated below)
186
+ if (result.canTransfer) place(tx, item.type, ownedKiosk, ownedKioskCap, result.item);
187
+
188
+ // ...finally, sign PTB & execute it.
189
+ };
190
+ ```
191
+
192
+ ### After
193
+
194
+ Using the new SDK, you can build the same transaction as follows:
195
+
196
+ > This works with both personal and non-personal kiosks.
197
+
198
+ ```typescript
199
+
200
+ // You need to do this only once and re-use it in the application.
201
+ const client = new SuiJsonRpcClient({
202
+ url: getJsonRpcFullnodeUrl('mainnet'),
203
+ network: 'mainnet',
204
+ }).$extend(kiosk());
205
+
206
+ // An Item as returned from `client.kiosk.getKiosk()` call.
207
+ const item = {
208
+ isLocked: false,
209
+ objectId: '0xb892d61a9992a10c9453efcdbd14ca9720d7dc1000a2048224209c9e544ed223',
210
+ type: '0x52852c4ba80040395b259c641e70b702426a58990ff73cecf5afd31954429090::test::TestItem',
211
+ kioskId: '0xSomeKioskAddress',
212
+ listing: {
213
+ isExclusive: false,
214
+ listingId: '0x368b512ff2514dbea814f26ec9a3d41198c00e8ed778099961e9ed22a9f0032b',
215
+ price: '20000000000', // in MIST
216
+ },
217
+ };
218
+
219
+ const purchase = async () => {
220
+ // Assume you have saved the user's preferred kiosk Cap somewhere in your app's state.
221
+ // You wouldn't need to query this for every purchase.
222
+ const { kioskOwnerCaps } = await client.kiosk.getOwnedKiosks({ address: '0xSomeAddress' });
223
+
224
+ const tx = new Transaction();
225
+
226
+ const kioskTx = new KioskTransaction({
227
+ transaction: tx,
228
+ kioskClient: client.kiosk,
229
+ cap: kioskOwnerCaps[0],
230
+ });
231
+
232
+ // Purchase the item and resolve the rules.
233
+ await kioskTx.purchaseAndResolve({
234
+ itemType: item.type,
235
+ itemId: item.objectId,
236
+ price: item.listing.price,
237
+ sellerKiosk: item.kioskId,
238
+ });
239
+
240
+ kioskTx.finalize();
241
+ };
242
+ ```
243
+
244
+ ## Attach rules to transfer policy
245
+
246
+ The following example was taken from the original Kiosk SDK V1 documentation.
247
+
248
+ ### Before
249
+
250
+ ```typescript
251
+
252
+ attachKioskLockRule,
253
+ attachRoyaltyRule,
254
+ createTransferPolicy,
255
+ percentageToBasisPoints,
256
+ testnetEnvironment,
257
+ } from '@mysten/kiosk';
258
+
259
+ // Attaches a royalty rule of 1% or 0.1 SUI (whichever is bigger)
260
+ // as well as a kiosk lock, making the objects tradeable only from/to a kiosk.
261
+ const attachStrongRoyalties = async () => {
262
+ const type = 'SomePackageId::type::MyType'; // the Type for which we're attaching rules.
263
+ const policyId = 'policyObjectId'; // the transfer Policy ID that was created for that Type.
264
+ const transferPolicyCap = 'transferPolicyCapId'; // the transferPolicyCap for that policy.
265
+
266
+ // Royalties configuration.
267
+ const percentage = 2.55; // 2.55%
268
+ const minAmount = 100_000_000; // 0.1 SUI.
269
+
270
+ // The environment on which we're referencing the rules package.
271
+ // Use `mainnetEnvironment` for mainnet.
272
+ const environment = testnetEnvironment;
273
+
274
+ const tx = new Transaction();
275
+
276
+ attachKioskLockRule(tx, type, policyId, policyCapId, environment);
277
+ attachRoyaltyRule(
278
+ tx,
279
+ type,
280
+ policyId,
281
+ policyCapId,
282
+ percentageToBasisPoints(percentage),
283
+ minAmount,
284
+ environment,
285
+ );
286
+
287
+ // ... continue to sign and execute the transaction
288
+ // ...
289
+ };
290
+ ```
291
+
292
+ ### After
293
+
294
+ On the new SDK, the same transaction can be built as follows:
295
+
296
+ ```typescript
297
+
298
+ // You need to do this only once and re-use it in the application.
299
+ const client = new SuiJsonRpcClient({
300
+ url: getJsonRpcFullnodeUrl('mainnet'),
301
+ network: 'mainnet',
302
+ }).$extend(kiosk());
303
+
304
+ const adjustPolicy = async () => {
305
+ const tx = new Transaction();
306
+
307
+ // You could have more than one cap, since you can create more than one transfer policy.
308
+ const policyCaps = await client.kiosk.getOwnedTransferPoliciesByType({
309
+ type: `SomePackageId::type::MyType`,
310
+ address: '0xOwnerAddress',
311
+ });
312
+
313
+ new TransferPolicyTransaction({ transaction: tx, kioskClient: client.kiosk, cap: policyCaps[0] })
314
+ .addRoyaltyRule(percentageToBasisPoints(2.55), 100_000_000)
315
+ .addLockRule();
316
+
317
+ // ... continue to sign and execute the transaction
318
+ // ...
319
+ };
320
+ ```
package/docs/index.md ADDED
@@ -0,0 +1,22 @@
1
+ # Kiosk SDK
2
+
3
+ > TypeScript SDK for interacting with Sui Kiosk onchain commerce.
4
+
5
+ Kiosk SDK is a tool to interact with Sui and Mysten Kiosk. You can use it to query kiosk related
6
+ data, build transactions to interact, and extend Kiosk to support custom rules.
7
+
8
+ ## Installation
9
+
10
+ ```npm
11
+ npm i @mysten/kiosk
12
+ ```
13
+
14
+ ## About
15
+
16
+ The Kiosk SDK exports a client extension that integrates with Sui clients. Add it to your client
17
+ using `$extend(kiosk())` to access kiosk functionality through `client.kiosk`.
18
+
19
+ > The Kiosk SDK requires `SuiJsonRpcClient` or `SuiGraphQLClient`. It does not work with
20
+ > `SuiGrpcClient` because it uses event queries that are not available in gRPC.
21
+
22
+ - [Read more about setting up the Kiosk client extension](/kiosk/kiosk-client/introduction)
@@ -0,0 +1,52 @@
1
+ # Kiosk Client
2
+
3
+ > Introduction to the KioskClient extension for querying and managing kiosks on Sui.
4
+
5
+ The Kiosk SDK exports a client extension that provides all Kiosk functionality.
6
+
7
+ > We recommend you keep only one client instance throughout your app or script. For example, in
8
+ > React, you'd use a context to provide the client.
9
+
10
+ > The Kiosk SDK requires `SuiJsonRpcClient` or `SuiGraphQLClient`. It does not work with
11
+ > `SuiGrpcClient` because it uses event queries that are not available in gRPC.
12
+
13
+ ## Setting up the kiosk extension
14
+
15
+ Add the kiosk extension to your Sui client using `$extend()`. The extension currently supports
16
+ `mainnet` and `testnet`. See the next section for usage on other networks.
17
+
18
+ Mysten Kiosk rules and extensions are not supported in Devnet due to network wipes (that would
19
+ require constantly changing the package IDs).
20
+
21
+ ```typescript
22
+
23
+ const client = new SuiJsonRpcClient({
24
+ url: getJsonRpcFullnodeUrl('testnet'),
25
+ network: 'testnet',
26
+ }).$extend(kiosk());
27
+
28
+ // Now you can use client.kiosk for all kiosk operations
29
+ const { kioskOwnerCaps } = await client.kiosk.getOwnedKiosks({ address: '0x...' });
30
+ ```
31
+
32
+ ### Using the kiosk extension on Devnet or Localnet
33
+
34
+ To use all the functionality of Kiosk SDK outside of `mainnet` and `testnet`, pass the `packageIds`
35
+ for the rules and extensions you want to use.
36
+
37
+ ```typescript
38
+
39
+ const client = new SuiJsonRpcClient({
40
+ url: getJsonRpcFullnodeUrl('devnet'),
41
+ network: 'devnet',
42
+ }).$extend(
43
+ kiosk({
44
+ packageIds: {
45
+ kioskLockRulePackageId: '0x...',
46
+ royaltyRulePackageId: '0x...',
47
+ personalKioskRulePackageId: '0x...',
48
+ floorPriceRulePackageId: '0x...',
49
+ },
50
+ }),
51
+ );
52
+ ```