@mysten/kiosk 1.0.1 → 1.1.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 +16 -0
- package/dist/client/kiosk-client.d.mts +4 -4
- package/dist/client/kiosk-client.d.mts.map +1 -1
- package/dist/client/kiosk-client.mjs.map +1 -1
- package/dist/contracts/0x2/bag.mjs.map +1 -1
- package/dist/contracts/0x2/balance.mjs +1 -5
- package/dist/contracts/0x2/balance.mjs.map +1 -1
- package/dist/contracts/0x2/kiosk.mjs +5 -5
- package/dist/contracts/0x2/kiosk.mjs.map +1 -1
- package/dist/contracts/0x2/kiosk_extension.mjs +1 -1
- package/dist/contracts/0x2/kiosk_extension.mjs.map +1 -1
- package/dist/contracts/0x2/transfer_policy.mjs +6 -6
- package/dist/contracts/0x2/transfer_policy.mjs.map +1 -1
- package/dist/contracts/0x2/vec_set.mjs.map +1 -1
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +2 -2
- package/dist/query/client-utils.mjs +186 -1
- package/dist/query/client-utils.mjs.map +1 -1
- package/dist/query/kiosk.mjs +2 -1
- package/dist/query/kiosk.mjs.map +1 -1
- package/dist/query/transfer-policy.mjs +1 -1
- package/dist/query/transfer-policy.mjs.map +1 -1
- package/dist/types/index.d.mts +7 -4
- package/dist/types/index.d.mts.map +1 -1
- package/dist/types/kiosk.d.mts +13 -3
- package/dist/types/kiosk.d.mts.map +1 -1
- package/dist/types/kiosk.mjs.map +1 -1
- package/dist/utils.d.mts +3 -9
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +5 -24
- package/dist/utils.mjs.map +1 -1
- package/package.json +8 -7
- package/src/client/kiosk-client.ts +4 -3
- package/src/contracts/0x2/bag.ts +2 -181
- package/src/contracts/0x2/balance.ts +3 -260
- package/src/contracts/0x2/kiosk.ts +4 -4
- package/src/contracts/0x2/kiosk_extension.ts +1 -1
- package/src/contracts/0x2/transfer_policy.ts +6 -6
- package/src/contracts/0x2/vec_set.ts +1 -198
- package/src/contracts/kiosk/witness_rule.ts +1 -1
- package/src/query/client-utils.ts +253 -2
- package/src/query/kiosk.ts +3 -2
- package/src/query/transfer-policy.ts +4 -5
- package/src/types/index.ts +6 -2
- package/src/types/kiosk.ts +15 -3
- package/src/utils.ts +8 -38
- package/src/contracts/0x2/accumulator.ts +0 -24
- package/src/contracts/0x2/accumulator_metadata.ts +0 -38
- package/src/contracts/0x2/accumulator_settlement.ts +0 -14
- package/src/contracts/0x2/address.ts +0 -145
- package/src/contracts/0x2/address_alias.ts +0 -92
- package/src/contracts/0x2/authenticator_state.ts +0 -44
- package/src/contracts/0x2/bcs.ts +0 -495
- package/src/contracts/0x2/bls12381.ts +0 -717
- package/src/contracts/0x2/borrow.ts +0 -99
- package/src/contracts/0x2/clock.ts +0 -30
- package/src/contracts/0x2/coin.ts +0 -977
- package/src/contracts/0x2/coin_registry.ts +0 -874
- package/src/contracts/0x2/config.ts +0 -30
- package/src/contracts/0x2/deny_list.ts +0 -55
- package/src/contracts/0x2/derived_object.ts +0 -95
- package/src/contracts/0x2/display.ts +0 -258
- package/src/contracts/0x2/dynamic_field.ts +0 -171
- package/src/contracts/0x2/dynamic_object_field.ts +0 -167
- package/src/contracts/0x2/ecdsa_k1.ts +0 -65
- package/src/contracts/0x2/ecdsa_r1.ts +0 -49
- package/src/contracts/0x2/ecvrf.ts +0 -29
- package/src/contracts/0x2/ed25519.ts +0 -25
- package/src/contracts/0x2/event.ts +0 -42
- package/src/contracts/0x2/funds_accumulator.ts +0 -86
- package/src/contracts/0x2/groth16.ts +0 -171
- package/src/contracts/0x2/group_ops.ts +0 -49
- package/src/contracts/0x2/hash.ts +0 -37
- package/src/contracts/0x2/hex.ts +0 -37
- package/src/contracts/0x2/hmac.ts +0 -21
- package/src/contracts/0x2/linked_table.ts +0 -354
- package/src/contracts/0x2/math.ts +0 -117
- package/src/contracts/0x2/nitro_attestation.ts +0 -186
- package/src/contracts/0x2/object.ts +0 -249
- package/src/contracts/0x2/object_bag.ts +0 -210
- package/src/contracts/0x2/object_table.ts +0 -200
- package/src/contracts/0x2/package.ts +0 -414
- package/src/contracts/0x2/party.ts +0 -37
- package/src/contracts/0x2/pay.ts +0 -153
- package/src/contracts/0x2/poseidon.ts +0 -21
- package/src/contracts/0x2/priority_queue.ts +0 -139
- package/src/contracts/0x2/random.ts +0 -294
- package/src/contracts/0x2/sui.ts +0 -29
- package/src/contracts/0x2/table.ts +0 -200
- package/src/contracts/0x2/table_vec.ts +0 -232
- package/src/contracts/0x2/token.ts +0 -873
- package/src/contracts/0x2/transfer.ts +0 -216
- package/src/contracts/0x2/tx_context.ts +0 -129
- package/src/contracts/0x2/types.ts +0 -24
- package/src/contracts/0x2/url.ts +0 -77
- package/src/contracts/0x2/vdf.ts +0 -45
- package/src/contracts/0x2/vec_map.ts +0 -401
- package/src/contracts/0x2/versioned.ts +0 -153
- package/src/contracts/0x2/zklogin_verified_id.ts +0 -172
- package/src/contracts/0x2/zklogin_verified_issuer.ts +0 -99
- package/src/contracts/kiosk/deps/sui/object.ts +0 -15
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
* THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
|
|
3
3
|
**************************************************************/
|
|
4
4
|
import { type BcsType, bcs } from '@mysten/sui/bcs';
|
|
5
|
-
import { MoveStruct
|
|
6
|
-
import { type Transaction } from '@mysten/sui/transactions';
|
|
5
|
+
import { MoveStruct } from '../utils/index.js';
|
|
7
6
|
const $moduleName = '0x2::vec_set';
|
|
8
7
|
export function VecSet<T0 extends BcsType<any>>(...typeParameters: [T0]) {
|
|
9
8
|
return new MoveStruct({
|
|
@@ -13,199 +12,3 @@ export function VecSet<T0 extends BcsType<any>>(...typeParameters: [T0]) {
|
|
|
13
12
|
},
|
|
14
13
|
});
|
|
15
14
|
}
|
|
16
|
-
export interface EmptyOptions {
|
|
17
|
-
package?: string;
|
|
18
|
-
arguments?: [];
|
|
19
|
-
typeArguments: [string];
|
|
20
|
-
}
|
|
21
|
-
export function empty(options: EmptyOptions) {
|
|
22
|
-
const packageAddress =
|
|
23
|
-
options.package ?? '0x0000000000000000000000000000000000000000000000000000000000000002';
|
|
24
|
-
return (tx: Transaction) =>
|
|
25
|
-
tx.moveCall({
|
|
26
|
-
package: packageAddress,
|
|
27
|
-
module: 'vec_set',
|
|
28
|
-
function: 'empty',
|
|
29
|
-
typeArguments: options.typeArguments,
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
export interface SingletonOptions<T0 extends BcsType<any>> {
|
|
33
|
-
package?: string;
|
|
34
|
-
arguments: [RawTransactionArgument<T0>];
|
|
35
|
-
typeArguments: [string];
|
|
36
|
-
}
|
|
37
|
-
export function singleton<T0 extends BcsType<any>>(options: SingletonOptions<T0>) {
|
|
38
|
-
const packageAddress =
|
|
39
|
-
options.package ?? '0x0000000000000000000000000000000000000000000000000000000000000002';
|
|
40
|
-
const argumentsTypes = [`${options.typeArguments[0]}`] satisfies (string | null)[];
|
|
41
|
-
return (tx: Transaction) =>
|
|
42
|
-
tx.moveCall({
|
|
43
|
-
package: packageAddress,
|
|
44
|
-
module: 'vec_set',
|
|
45
|
-
function: 'singleton',
|
|
46
|
-
arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
|
|
47
|
-
typeArguments: options.typeArguments,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
export interface InsertOptions<T0 extends BcsType<any>> {
|
|
51
|
-
package?: string;
|
|
52
|
-
arguments: [RawTransactionArgument<string>, RawTransactionArgument<T0>];
|
|
53
|
-
typeArguments: [string];
|
|
54
|
-
}
|
|
55
|
-
export function insert<T0 extends BcsType<any>>(options: InsertOptions<T0>) {
|
|
56
|
-
const packageAddress =
|
|
57
|
-
options.package ?? '0x0000000000000000000000000000000000000000000000000000000000000002';
|
|
58
|
-
const argumentsTypes = [null, `${options.typeArguments[0]}`] satisfies (string | null)[];
|
|
59
|
-
return (tx: Transaction) =>
|
|
60
|
-
tx.moveCall({
|
|
61
|
-
package: packageAddress,
|
|
62
|
-
module: 'vec_set',
|
|
63
|
-
function: 'insert',
|
|
64
|
-
arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
|
|
65
|
-
typeArguments: options.typeArguments,
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
export interface RemoveOptions<T0 extends BcsType<any>> {
|
|
69
|
-
package?: string;
|
|
70
|
-
arguments: [RawTransactionArgument<string>, RawTransactionArgument<T0>];
|
|
71
|
-
typeArguments: [string];
|
|
72
|
-
}
|
|
73
|
-
export function remove<T0 extends BcsType<any>>(options: RemoveOptions<T0>) {
|
|
74
|
-
const packageAddress =
|
|
75
|
-
options.package ?? '0x0000000000000000000000000000000000000000000000000000000000000002';
|
|
76
|
-
const argumentsTypes = [null, `${options.typeArguments[0]}`] satisfies (string | null)[];
|
|
77
|
-
return (tx: Transaction) =>
|
|
78
|
-
tx.moveCall({
|
|
79
|
-
package: packageAddress,
|
|
80
|
-
module: 'vec_set',
|
|
81
|
-
function: 'remove',
|
|
82
|
-
arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
|
|
83
|
-
typeArguments: options.typeArguments,
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
export interface ContainsOptions<T0 extends BcsType<any>> {
|
|
87
|
-
package?: string;
|
|
88
|
-
arguments: [RawTransactionArgument<string>, RawTransactionArgument<T0>];
|
|
89
|
-
typeArguments: [string];
|
|
90
|
-
}
|
|
91
|
-
export function contains<T0 extends BcsType<any>>(options: ContainsOptions<T0>) {
|
|
92
|
-
const packageAddress =
|
|
93
|
-
options.package ?? '0x0000000000000000000000000000000000000000000000000000000000000002';
|
|
94
|
-
const argumentsTypes = [null, `${options.typeArguments[0]}`] satisfies (string | null)[];
|
|
95
|
-
return (tx: Transaction) =>
|
|
96
|
-
tx.moveCall({
|
|
97
|
-
package: packageAddress,
|
|
98
|
-
module: 'vec_set',
|
|
99
|
-
function: 'contains',
|
|
100
|
-
arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
|
|
101
|
-
typeArguments: options.typeArguments,
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
export interface LengthOptions {
|
|
105
|
-
package?: string;
|
|
106
|
-
arguments: [RawTransactionArgument<string>];
|
|
107
|
-
typeArguments: [string];
|
|
108
|
-
}
|
|
109
|
-
export function length(options: LengthOptions) {
|
|
110
|
-
const packageAddress =
|
|
111
|
-
options.package ?? '0x0000000000000000000000000000000000000000000000000000000000000002';
|
|
112
|
-
const argumentsTypes = [null] satisfies (string | null)[];
|
|
113
|
-
return (tx: Transaction) =>
|
|
114
|
-
tx.moveCall({
|
|
115
|
-
package: packageAddress,
|
|
116
|
-
module: 'vec_set',
|
|
117
|
-
function: 'length',
|
|
118
|
-
arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
|
|
119
|
-
typeArguments: options.typeArguments,
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
export interface IsEmptyOptions {
|
|
123
|
-
package?: string;
|
|
124
|
-
arguments: [RawTransactionArgument<string>];
|
|
125
|
-
typeArguments: [string];
|
|
126
|
-
}
|
|
127
|
-
export function isEmpty(options: IsEmptyOptions) {
|
|
128
|
-
const packageAddress =
|
|
129
|
-
options.package ?? '0x0000000000000000000000000000000000000000000000000000000000000002';
|
|
130
|
-
const argumentsTypes = [null] satisfies (string | null)[];
|
|
131
|
-
return (tx: Transaction) =>
|
|
132
|
-
tx.moveCall({
|
|
133
|
-
package: packageAddress,
|
|
134
|
-
module: 'vec_set',
|
|
135
|
-
function: 'is_empty',
|
|
136
|
-
arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
|
|
137
|
-
typeArguments: options.typeArguments,
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
export interface IntoKeysOptions {
|
|
141
|
-
package?: string;
|
|
142
|
-
arguments: [RawTransactionArgument<string>];
|
|
143
|
-
typeArguments: [string];
|
|
144
|
-
}
|
|
145
|
-
export function intoKeys(options: IntoKeysOptions) {
|
|
146
|
-
const packageAddress =
|
|
147
|
-
options.package ?? '0x0000000000000000000000000000000000000000000000000000000000000002';
|
|
148
|
-
const argumentsTypes = [null] satisfies (string | null)[];
|
|
149
|
-
return (tx: Transaction) =>
|
|
150
|
-
tx.moveCall({
|
|
151
|
-
package: packageAddress,
|
|
152
|
-
module: 'vec_set',
|
|
153
|
-
function: 'into_keys',
|
|
154
|
-
arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
|
|
155
|
-
typeArguments: options.typeArguments,
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
export interface FromKeysOptions<T0 extends BcsType<any>> {
|
|
159
|
-
package?: string;
|
|
160
|
-
arguments: [RawTransactionArgument<T0[]>];
|
|
161
|
-
typeArguments: [string];
|
|
162
|
-
}
|
|
163
|
-
export function fromKeys<T0 extends BcsType<any>>(options: FromKeysOptions<T0>) {
|
|
164
|
-
const packageAddress =
|
|
165
|
-
options.package ?? '0x0000000000000000000000000000000000000000000000000000000000000002';
|
|
166
|
-
const argumentsTypes = [`vector<${options.typeArguments[0]}>`] satisfies (string | null)[];
|
|
167
|
-
return (tx: Transaction) =>
|
|
168
|
-
tx.moveCall({
|
|
169
|
-
package: packageAddress,
|
|
170
|
-
module: 'vec_set',
|
|
171
|
-
function: 'from_keys',
|
|
172
|
-
arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
|
|
173
|
-
typeArguments: options.typeArguments,
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
export interface KeysOptions {
|
|
177
|
-
package?: string;
|
|
178
|
-
arguments: [RawTransactionArgument<string>];
|
|
179
|
-
typeArguments: [string];
|
|
180
|
-
}
|
|
181
|
-
export function keys(options: KeysOptions) {
|
|
182
|
-
const packageAddress =
|
|
183
|
-
options.package ?? '0x0000000000000000000000000000000000000000000000000000000000000002';
|
|
184
|
-
const argumentsTypes = [null] satisfies (string | null)[];
|
|
185
|
-
return (tx: Transaction) =>
|
|
186
|
-
tx.moveCall({
|
|
187
|
-
package: packageAddress,
|
|
188
|
-
module: 'vec_set',
|
|
189
|
-
function: 'keys',
|
|
190
|
-
arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
|
|
191
|
-
typeArguments: options.typeArguments,
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
export interface SizeOptions {
|
|
195
|
-
package?: string;
|
|
196
|
-
arguments: [RawTransactionArgument<string>];
|
|
197
|
-
typeArguments: [string];
|
|
198
|
-
}
|
|
199
|
-
export function size(options: SizeOptions) {
|
|
200
|
-
const packageAddress =
|
|
201
|
-
options.package ?? '0x0000000000000000000000000000000000000000000000000000000000000002';
|
|
202
|
-
const argumentsTypes = [null] satisfies (string | null)[];
|
|
203
|
-
return (tx: Transaction) =>
|
|
204
|
-
tx.moveCall({
|
|
205
|
-
package: packageAddress,
|
|
206
|
-
module: 'vec_set',
|
|
207
|
-
function: 'size',
|
|
208
|
-
arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
|
|
209
|
-
typeArguments: options.typeArguments,
|
|
210
|
-
});
|
|
211
|
-
}
|
|
@@ -24,7 +24,7 @@ import { bcs, type BcsType } from '@mysten/sui/bcs';
|
|
|
24
24
|
import { type Transaction } from '@mysten/sui/transactions';
|
|
25
25
|
const $moduleName = '@local-pkg/kiosk::witness_rule';
|
|
26
26
|
export const Rule = new MoveStruct({
|
|
27
|
-
name: `${$moduleName}::Rule
|
|
27
|
+
name: `${$moduleName}::Rule<phantom Proof>`,
|
|
28
28
|
fields: {
|
|
29
29
|
dummy_field: bcs.bool(),
|
|
30
30
|
},
|
|
@@ -1,13 +1,264 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type { SuiClientTypes } from '@mysten/sui/client';
|
|
5
5
|
import { graphql } from '@mysten/sui/graphql/schema';
|
|
6
6
|
import { isSuiGraphQLClient } from '@mysten/sui/graphql';
|
|
7
7
|
import { isSuiJsonRpcClient } from '@mysten/sui/jsonRpc';
|
|
8
|
+
import { normalizeStructTag } from '@mysten/sui/utils';
|
|
9
|
+
import { chunk, fromBase64 } from '@mysten/utils';
|
|
10
|
+
|
|
11
|
+
import type { KioskDisplay, ObjectWithDisplay } from '../types/kiosk.js';
|
|
12
|
+
import type { KioskCompatibleClient } from '../types/index.js';
|
|
13
|
+
|
|
14
|
+
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
|
+
`);
|
|
65
|
+
|
|
66
|
+
export async function getAllObjects(
|
|
67
|
+
client: KioskCompatibleClient,
|
|
68
|
+
ids: string[],
|
|
69
|
+
): Promise<ObjectWithDisplay[]> {
|
|
70
|
+
if (ids.length === 0) return [];
|
|
71
|
+
|
|
72
|
+
const chunks = chunk(ids, DEFAULT_QUERY_LIMIT);
|
|
73
|
+
const results: ObjectWithDisplay[] = [];
|
|
74
|
+
|
|
75
|
+
if (isSuiGraphQLClient(client)) {
|
|
76
|
+
for (const batch of chunks) {
|
|
77
|
+
const { data } = await client.query({
|
|
78
|
+
query: FetchObjectsWithDisplayQuery,
|
|
79
|
+
variables: {
|
|
80
|
+
objectKeys: batch.map((address) => ({ address })),
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
if (data?.multiGetObjects) {
|
|
85
|
+
for (const obj of data.multiGetObjects) {
|
|
86
|
+
if (!obj) continue;
|
|
87
|
+
|
|
88
|
+
let type: string;
|
|
89
|
+
if (obj.asMovePackage) {
|
|
90
|
+
type = 'package';
|
|
91
|
+
} else if (obj.asMoveObject?.contents?.type?.repr) {
|
|
92
|
+
type = obj.asMoveObject.contents.type.repr;
|
|
93
|
+
} else {
|
|
94
|
+
type = '';
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const bcsContent = obj.asMoveObject?.contents?.bcs
|
|
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, string> | 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
|
+
}
|
|
258
|
+
}
|
|
8
259
|
|
|
9
260
|
export async function queryEvents(
|
|
10
|
-
client:
|
|
261
|
+
client: KioskCompatibleClient,
|
|
11
262
|
eventType: string,
|
|
12
263
|
): Promise<{ json: unknown }[]> {
|
|
13
264
|
if (isSuiGraphQLClient(client)) {
|
package/src/query/kiosk.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { isValidSuiAddress } from '@mysten/sui/utils';
|
|
|
8
8
|
import { Extension, ExtensionKey } from '../contracts/0x2/kiosk_extension.js';
|
|
9
9
|
import type {
|
|
10
10
|
FetchKioskOptions,
|
|
11
|
+
KioskCompatibleClient,
|
|
11
12
|
KioskExtension,
|
|
12
13
|
KioskListing,
|
|
13
14
|
OwnedKiosks,
|
|
@@ -20,13 +21,13 @@ import {
|
|
|
20
21
|
attachObjects,
|
|
21
22
|
extractKioskData,
|
|
22
23
|
getAllDynamicFields,
|
|
23
|
-
getAllObjects,
|
|
24
24
|
getKioskObject,
|
|
25
25
|
} from '../utils.js';
|
|
26
|
+
import { getAllObjects } from './client-utils.js';
|
|
26
27
|
import { PersonalKioskCap } from '../contracts/kiosk/personal_kiosk.js';
|
|
27
28
|
|
|
28
29
|
export async function fetchKiosk(
|
|
29
|
-
client:
|
|
30
|
+
client: KioskCompatibleClient,
|
|
30
31
|
kioskId: string,
|
|
31
32
|
pagination: PaginationArguments<string>,
|
|
32
33
|
options: FetchKioskOptions,
|
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { isValidSuiAddress } from '@mysten/sui/utils';
|
|
5
|
-
import type { ClientWithCoreApi } from '@mysten/sui/client';
|
|
6
5
|
|
|
7
6
|
import {
|
|
8
7
|
TransferPolicyCap as TransferPolicyCapStruct,
|
|
9
8
|
TransferPolicy as TransferPolicyStruct,
|
|
10
9
|
} from '../contracts/0x2/transfer_policy.js';
|
|
11
|
-
import type { TransferPolicy, TransferPolicyCap } from '../types/index.js';
|
|
10
|
+
import type { KioskCompatibleClient, TransferPolicy, TransferPolicyCap } from '../types/index.js';
|
|
12
11
|
import {
|
|
13
12
|
TRANSFER_POLICY_CAP_TYPE,
|
|
14
13
|
TRANSFER_POLICY_CREATED_EVENT,
|
|
@@ -30,7 +29,7 @@ import { queryEvents } from './client-utils.js';
|
|
|
30
29
|
* @throws Error if the client doesn't support event querying
|
|
31
30
|
*/
|
|
32
31
|
export async function queryTransferPolicy(
|
|
33
|
-
client:
|
|
32
|
+
client: KioskCompatibleClient,
|
|
34
33
|
type: string,
|
|
35
34
|
): Promise<TransferPolicy[]> {
|
|
36
35
|
const data = await queryEvents(client, `${TRANSFER_POLICY_CREATED_EVENT}<${type}>`);
|
|
@@ -74,7 +73,7 @@ export async function queryTransferPolicy(
|
|
|
74
73
|
* @returns Array of TransferPolicyCap objects
|
|
75
74
|
*/
|
|
76
75
|
export async function queryTransferPolicyCapsByType(
|
|
77
|
-
client:
|
|
76
|
+
client: KioskCompatibleClient,
|
|
78
77
|
address: string,
|
|
79
78
|
type: string,
|
|
80
79
|
): Promise<TransferPolicyCap[]> {
|
|
@@ -125,7 +124,7 @@ export async function queryTransferPolicyCapsByType(
|
|
|
125
124
|
* @returns Array of TransferPolicyCap objects or undefined if address is invalid
|
|
126
125
|
*/
|
|
127
126
|
export async function queryOwnedTransferPolicies(
|
|
128
|
-
client:
|
|
127
|
+
client: KioskCompatibleClient,
|
|
129
128
|
address: string,
|
|
130
129
|
): Promise<TransferPolicyCap[] | undefined> {
|
|
131
130
|
if (!isValidSuiAddress(address)) return;
|
package/src/types/index.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type { 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';
|
|
8
10
|
|
|
9
11
|
export * from './kiosk.js';
|
|
10
12
|
export * from './transfer-policy.js';
|
|
@@ -18,7 +20,9 @@ export type ObjectArgument = string | TransactionObjectArgument;
|
|
|
18
20
|
* The Client Options for Both KioskClient & TransferPolicyManager.
|
|
19
21
|
*/
|
|
20
22
|
export type KioskClientOptions = {
|
|
21
|
-
client:
|
|
23
|
+
client: KioskCompatibleClient;
|
|
22
24
|
network: SuiClientTypes.Network;
|
|
23
25
|
packageIds?: BaseRulePackageIds;
|
|
24
26
|
};
|
|
27
|
+
|
|
28
|
+
export type KioskCompatibleClient = SuiJsonRpcClient | SuiGraphQLClient;
|
package/src/types/kiosk.ts
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import type { TransactionArgument } from '@mysten/sui/transactions';
|
|
5
|
-
import { SuiClientTypes } from '@mysten/sui/client';
|
|
6
5
|
|
|
7
6
|
import type { ObjectArgument } from './index.js';
|
|
8
7
|
|
|
9
8
|
import { SUI_FRAMEWORK_ADDRESS } from '@mysten/sui/utils';
|
|
9
|
+
import { SuiClientTypes } from '@mysten/sui/client';
|
|
10
10
|
|
|
11
11
|
/** The Kiosk module. */
|
|
12
12
|
export const KIOSK_MODULE = `${SUI_FRAMEWORK_ADDRESS}::kiosk`;
|
|
@@ -88,6 +88,18 @@ export type KioskListing = {
|
|
|
88
88
|
price?: string;
|
|
89
89
|
};
|
|
90
90
|
|
|
91
|
+
export type KioskDisplay = {
|
|
92
|
+
data: Record<string, string> | null;
|
|
93
|
+
error: string | null;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export type ObjectWithDisplay = SuiClientTypes.Object<{
|
|
97
|
+
content: true;
|
|
98
|
+
previousTransaction: true;
|
|
99
|
+
}> & {
|
|
100
|
+
display?: KioskDisplay;
|
|
101
|
+
};
|
|
102
|
+
|
|
91
103
|
/**
|
|
92
104
|
* A dynamic field `Item { ID }` attached to the Kiosk.
|
|
93
105
|
* Holds an Item `T`. The type of the item is known upfront.
|
|
@@ -103,8 +115,8 @@ export type KioskItem = {
|
|
|
103
115
|
listing?: KioskListing;
|
|
104
116
|
/** The ID of the kiosk the item is placed in */
|
|
105
117
|
kioskId: string;
|
|
106
|
-
/** Optional
|
|
107
|
-
data?:
|
|
118
|
+
/** Optional object data with display metadata */
|
|
119
|
+
data?: ObjectWithDisplay;
|
|
108
120
|
};
|
|
109
121
|
|
|
110
122
|
/** The overview type returned from `getKiosk` */
|
package/src/utils.ts
CHANGED
|
@@ -5,12 +5,9 @@ import { bcs } from '@mysten/sui/bcs';
|
|
|
5
5
|
import { PaginationArguments } from '@mysten/sui/jsonRpc';
|
|
6
6
|
import type { ClientWithCoreApi, SuiClientTypes } from '@mysten/sui/client';
|
|
7
7
|
import { normalizeStructTag, normalizeSuiAddress, parseStructTag } from '@mysten/sui/utils';
|
|
8
|
-
import { chunk } from '@mysten/utils';
|
|
9
8
|
|
|
10
|
-
import { Listing, Lock, Kiosk as KioskStruct } from './contracts/0x2/kiosk.js';
|
|
11
|
-
import type { Kiosk, KioskData, KioskListing } from './types/index.js';
|
|
12
|
-
|
|
13
|
-
const DEFAULT_QUERY_LIMIT = 50;
|
|
9
|
+
import { Item, Listing, Lock, Kiosk as KioskStruct } from './contracts/0x2/kiosk.js';
|
|
10
|
+
import type { Kiosk, KioskData, KioskListing, ObjectWithDisplay } from './types/index.js';
|
|
14
11
|
|
|
15
12
|
export type DynamicFieldInfo = SuiClientTypes.ListDynamicFieldsResponse['dynamicFields'][number];
|
|
16
13
|
|
|
@@ -53,9 +50,10 @@ export function extractKioskData(
|
|
|
53
50
|
baseType ===
|
|
54
51
|
'0x0000000000000000000000000000000000000000000000000000000000000002::kiosk::Item'
|
|
55
52
|
) {
|
|
56
|
-
|
|
53
|
+
const parsed = Item.parse(val.name.bcs);
|
|
54
|
+
acc.itemIds.push(parsed.id);
|
|
57
55
|
acc.items.push({
|
|
58
|
-
objectId:
|
|
56
|
+
objectId: parsed.id,
|
|
59
57
|
type: val.valueType,
|
|
60
58
|
isLocked: false,
|
|
61
59
|
kioskId,
|
|
@@ -137,9 +135,9 @@ export function attachListingsAndPrices(
|
|
|
137
135
|
* A helper that attaches object data to kiosk items.
|
|
138
136
|
* Works with core API objects that contain BCS content.
|
|
139
137
|
*/
|
|
140
|
-
export function attachObjects(kioskData: KioskData, objects:
|
|
141
|
-
const mapping = objects.reduce<Record<string,
|
|
142
|
-
(acc: Record<string,
|
|
138
|
+
export function attachObjects(kioskData: KioskData, objects: ObjectWithDisplay[]) {
|
|
139
|
+
const mapping = objects.reduce<Record<string, ObjectWithDisplay>>(
|
|
140
|
+
(acc: Record<string, ObjectWithDisplay>, obj) => {
|
|
143
141
|
acc[obj.objectId] = obj;
|
|
144
142
|
return acc;
|
|
145
143
|
},
|
|
@@ -200,34 +198,6 @@ export async function getAllDynamicFields(
|
|
|
200
198
|
return data;
|
|
201
199
|
}
|
|
202
200
|
|
|
203
|
-
/**
|
|
204
|
-
* A helper to fetch all objects that works with pagination.
|
|
205
|
-
* It will fetch all objects in the array, and limit it to 50/request.
|
|
206
|
-
* Requests are sent using `Promise.all`.
|
|
207
|
-
*/
|
|
208
|
-
export async function getAllObjects(
|
|
209
|
-
client: ClientWithCoreApi,
|
|
210
|
-
ids: string[],
|
|
211
|
-
): Promise<SuiClientTypes.Object[]> {
|
|
212
|
-
const chunks = chunk(ids, DEFAULT_QUERY_LIMIT);
|
|
213
|
-
|
|
214
|
-
const results = await Promise.all(
|
|
215
|
-
chunks.map(async (objectIds) => {
|
|
216
|
-
const { objects } = await client.core.getObjects({
|
|
217
|
-
objectIds,
|
|
218
|
-
include: {
|
|
219
|
-
content: true,
|
|
220
|
-
previousTransaction: true,
|
|
221
|
-
},
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
return objects.filter((obj): obj is SuiClientTypes.Object => !(obj instanceof Error));
|
|
225
|
-
}),
|
|
226
|
-
);
|
|
227
|
-
|
|
228
|
-
return results.flat();
|
|
229
|
-
}
|
|
230
|
-
|
|
231
201
|
/**
|
|
232
202
|
* Converts a number to basis points.
|
|
233
203
|
* Supports up to 2 decimal points.
|