@mysten/kiosk 0.7.13 → 0.8.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 +19 -0
- package/dist/cjs/bcs.js +47 -0
- package/dist/cjs/bcs.js.map +7 -0
- package/dist/{client → cjs/client}/kiosk-client.d.ts +8 -7
- package/dist/cjs/client/kiosk-client.js +126 -0
- package/dist/cjs/client/kiosk-client.js.map +7 -0
- package/dist/{client → cjs/client}/kiosk-transaction.d.ts +3 -3
- package/dist/cjs/client/kiosk-transaction.js +489 -0
- package/dist/cjs/client/kiosk-transaction.js.map +7 -0
- package/dist/{client → cjs/client}/tp-transaction.d.ts +3 -3
- package/dist/cjs/client/tp-transaction.js +317 -0
- package/dist/cjs/client/tp-transaction.js.map +7 -0
- package/dist/{constants.d.ts → cjs/constants.d.ts} +2 -1
- package/dist/cjs/constants.js +102 -0
- package/dist/cjs/constants.js.map +7 -0
- package/dist/cjs/index.d.ts +6 -0
- package/dist/cjs/index.js +24 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/package.json +5 -0
- package/dist/{query → cjs/query}/kiosk.d.ts +2 -2
- package/dist/cjs/query/kiosk.js +124 -0
- package/dist/cjs/query/kiosk.js.map +7 -0
- package/dist/{query → cjs/query}/transfer-policy.d.ts +2 -2
- package/dist/cjs/query/transfer-policy.js +94 -0
- package/dist/cjs/query/transfer-policy.js.map +7 -0
- package/dist/{tx → cjs/tx}/kiosk.d.ts +2 -2
- package/dist/cjs/tx/kiosk.js +130 -0
- package/dist/cjs/tx/kiosk.js.map +7 -0
- package/dist/{tx → cjs/tx}/personal-kiosk.d.ts +2 -2
- package/dist/cjs/tx/personal-kiosk.js +38 -0
- package/dist/cjs/tx/personal-kiosk.js.map +7 -0
- package/dist/{tx → cjs/tx}/rules/attach.d.ts +2 -2
- package/dist/cjs/tx/rules/attach.js +62 -0
- package/dist/cjs/tx/rules/attach.js.map +7 -0
- package/dist/{tx → cjs/tx}/rules/resolve.d.ts +1 -1
- package/dist/cjs/tx/rules/resolve.js +81 -0
- package/dist/cjs/tx/rules/resolve.js.map +7 -0
- package/dist/{tx → cjs/tx}/transfer-policy.d.ts +2 -2
- package/dist/cjs/tx/transfer-policy.js +78 -0
- package/dist/cjs/tx/transfer-policy.js.map +7 -0
- package/dist/{types → cjs/types}/index.d.ts +5 -5
- package/dist/cjs/types/index.js +33 -0
- package/dist/cjs/types/index.js.map +7 -0
- package/dist/{types → cjs/types}/kiosk.d.ts +3 -3
- package/dist/cjs/types/kiosk.js +37 -0
- package/dist/cjs/types/kiosk.js.map +7 -0
- package/dist/{types → cjs/types}/transfer-policy.d.ts +3 -3
- package/dist/cjs/types/transfer-policy.js +35 -0
- package/dist/cjs/types/transfer-policy.js.map +7 -0
- package/dist/{utils.d.ts → cjs/utils.d.ts} +2 -2
- package/dist/cjs/utils.js +203 -0
- package/dist/cjs/utils.js.map +7 -0
- package/dist/esm/bcs.d.ts +2 -0
- package/dist/esm/bcs.js +32 -0
- package/dist/esm/bcs.js.map +7 -0
- package/dist/esm/client/kiosk-client.d.ts +74 -0
- package/dist/esm/client/kiosk-client.js +117 -0
- package/dist/esm/client/kiosk-client.js.map +7 -0
- package/dist/esm/client/kiosk-transaction.d.ts +182 -0
- package/dist/esm/client/kiosk-transaction.js +459 -0
- package/dist/esm/client/kiosk-transaction.js.map +7 -0
- package/dist/esm/client/tp-transaction.d.ts +112 -0
- package/dist/esm/client/tp-transaction.js +308 -0
- package/dist/esm/client/tp-transaction.js.map +7 -0
- package/dist/esm/constants.d.ts +31 -0
- package/dist/esm/constants.js +87 -0
- package/dist/esm/constants.js.map +7 -0
- package/dist/esm/index.d.ts +6 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/package.json +5 -0
- package/dist/esm/query/kiosk.d.ts +14 -0
- package/dist/esm/query/kiosk.js +112 -0
- package/dist/esm/query/kiosk.js.map +7 -0
- package/dist/esm/query/transfer-policy.d.ts +28 -0
- package/dist/esm/query/transfer-policy.js +78 -0
- package/dist/esm/query/transfer-policy.js.map +7 -0
- package/dist/esm/tx/kiosk.d.ts +71 -0
- package/dist/esm/tx/kiosk.js +110 -0
- package/dist/esm/tx/kiosk.js.map +7 -0
- package/dist/esm/tx/personal-kiosk.d.ts +7 -0
- package/dist/esm/tx/personal-kiosk.js +18 -0
- package/dist/esm/tx/personal-kiosk.js.map +7 -0
- package/dist/esm/tx/rules/attach.d.ts +7 -0
- package/dist/esm/tx/rules/attach.js +42 -0
- package/dist/esm/tx/rules/attach.js.map +7 -0
- package/dist/esm/tx/rules/resolve.d.ts +15 -0
- package/dist/esm/tx/rules/resolve.js +61 -0
- package/dist/esm/tx/rules/resolve.js.map +7 -0
- package/dist/esm/tx/transfer-policy.d.ts +29 -0
- package/dist/esm/tx/transfer-policy.js +58 -0
- package/dist/esm/tx/transfer-policy.js.map +7 -0
- package/dist/esm/types/index.d.ts +27 -0
- package/dist/esm/types/index.js +12 -0
- package/dist/esm/types/index.js.map +7 -0
- package/dist/esm/types/kiosk.d.ts +160 -0
- package/dist/esm/types/kiosk.js +17 -0
- package/dist/esm/types/kiosk.js.map +7 -0
- package/dist/esm/types/transfer-policy.d.ts +49 -0
- package/dist/esm/types/transfer-policy.js +15 -0
- package/dist/esm/types/transfer-policy.js.map +7 -0
- package/dist/esm/utils.d.ts +51 -0
- package/dist/esm/utils.js +183 -0
- package/dist/esm/utils.js.map +7 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +17 -19
- package/src/bcs.ts +1 -1
- package/src/client/kiosk-client.ts +12 -13
- package/src/client/kiosk-transaction.ts +10 -10
- package/src/client/tp-transaction.ts +5 -5
- package/src/constants.ts +4 -2
- package/src/index.ts +6 -6
- package/src/query/kiosk.ts +5 -5
- package/src/query/transfer-policy.ts +5 -6
- package/src/tx/kiosk.ts +3 -2
- package/src/tx/personal-kiosk.ts +2 -2
- package/src/tx/rules/attach.ts +2 -2
- package/src/tx/rules/resolve.ts +2 -2
- package/src/tx/transfer-policy.ts +3 -2
- package/src/types/index.ts +5 -5
- package/src/types/kiosk.ts +3 -3
- package/src/types/transfer-policy.ts +3 -3
- package/src/utils.ts +5 -11
- package/dist/index.d.ts +0 -6
- package/dist/index.js +0 -1643
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -1582
- package/dist/index.mjs.map +0 -1
- /package/dist/{bcs.d.ts → cjs/bcs.d.ts} +0 -0
package/dist/index.mjs
DELETED
|
@@ -1,1582 +0,0 @@
|
|
|
1
|
-
var __accessCheck = (obj, member, msg) => {
|
|
2
|
-
if (!member.has(obj))
|
|
3
|
-
throw TypeError("Cannot " + msg);
|
|
4
|
-
};
|
|
5
|
-
var __privateGet = (obj, member, getter) => {
|
|
6
|
-
__accessCheck(obj, member, "read from private field");
|
|
7
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
8
|
-
};
|
|
9
|
-
var __privateAdd = (obj, member, value) => {
|
|
10
|
-
if (member.has(obj))
|
|
11
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
12
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
13
|
-
};
|
|
14
|
-
var __privateSet = (obj, member, value, setter) => {
|
|
15
|
-
__accessCheck(obj, member, "write to private field");
|
|
16
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
17
|
-
return value;
|
|
18
|
-
};
|
|
19
|
-
var __privateMethod = (obj, member, method) => {
|
|
20
|
-
__accessCheck(obj, member, "access private method");
|
|
21
|
-
return method;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
// src/utils.ts
|
|
25
|
-
import { normalizeStructTag, normalizeSuiAddress, parseStructTag } from "@mysten/sui.js/utils";
|
|
26
|
-
|
|
27
|
-
// src/bcs.ts
|
|
28
|
-
import { bcs } from "@mysten/sui.js/bcs";
|
|
29
|
-
|
|
30
|
-
// src/types/kiosk.ts
|
|
31
|
-
var KIOSK_MODULE = "0x2::kiosk";
|
|
32
|
-
var KIOSK_TYPE = `${KIOSK_MODULE}::Kiosk`;
|
|
33
|
-
var KIOSK_OWNER_CAP = `${KIOSK_MODULE}::KioskOwnerCap`;
|
|
34
|
-
var KIOSK_ITEM = `${KIOSK_MODULE}::Item`;
|
|
35
|
-
var KIOSK_LISTING = `${KIOSK_MODULE}::Listing`;
|
|
36
|
-
var KIOSK_LOCK = `${KIOSK_MODULE}::Lock`;
|
|
37
|
-
var KIOSK_PURCHASE_CAP = `${KIOSK_MODULE}::PurchaseCap`;
|
|
38
|
-
|
|
39
|
-
// src/types/transfer-policy.ts
|
|
40
|
-
var TRANSFER_POLICY_MODULE = "0x2::transfer_policy";
|
|
41
|
-
var TRANSFER_POLICY_CREATED_EVENT = `${TRANSFER_POLICY_MODULE}::TransferPolicyCreated`;
|
|
42
|
-
var TRANSFER_POLICY_TYPE = `${TRANSFER_POLICY_MODULE}::TransferPolicy`;
|
|
43
|
-
var TRANSFER_POLICY_CAP_TYPE = `${TRANSFER_POLICY_MODULE}::TransferPolicyCap`;
|
|
44
|
-
var KIOSK_LOCK_RULE = "kiosk_lock_rule::Rule";
|
|
45
|
-
var ROYALTY_RULE = "royalty_rule::Rule";
|
|
46
|
-
|
|
47
|
-
// src/types/index.ts
|
|
48
|
-
var Network = /* @__PURE__ */ ((Network2) => {
|
|
49
|
-
Network2["MAINNET"] = "mainnet";
|
|
50
|
-
Network2["TESTNET"] = "testnet";
|
|
51
|
-
Network2["CUSTOM"] = "custom";
|
|
52
|
-
return Network2;
|
|
53
|
-
})(Network || {});
|
|
54
|
-
|
|
55
|
-
// src/bcs.ts
|
|
56
|
-
bcs.registerStructType(KIOSK_TYPE, {
|
|
57
|
-
id: "address",
|
|
58
|
-
profits: "u64",
|
|
59
|
-
owner: "address",
|
|
60
|
-
itemCount: "u32",
|
|
61
|
-
allowExtensions: "bool"
|
|
62
|
-
});
|
|
63
|
-
bcs.registerStructType(KIOSK_PURCHASE_CAP, {
|
|
64
|
-
id: "address",
|
|
65
|
-
kioskId: "address",
|
|
66
|
-
itemId: "address",
|
|
67
|
-
minPrice: "u64"
|
|
68
|
-
});
|
|
69
|
-
bcs.registerStructType(TRANSFER_POLICY_CREATED_EVENT, {
|
|
70
|
-
id: "address"
|
|
71
|
-
});
|
|
72
|
-
bcs.registerStructType(TRANSFER_POLICY_TYPE, {
|
|
73
|
-
id: "address",
|
|
74
|
-
balance: "u64",
|
|
75
|
-
rules: ["vector", "string"]
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
// src/utils.ts
|
|
79
|
-
var DEFAULT_QUERY_LIMIT = 50;
|
|
80
|
-
async function getKioskObject(client, id) {
|
|
81
|
-
const queryRes = await client.getObject({ id, options: { showBcs: true } });
|
|
82
|
-
if (!queryRes || queryRes.error || !queryRes.data) {
|
|
83
|
-
throw new Error(`Kiosk ${id} not found; ${queryRes.error}`);
|
|
84
|
-
}
|
|
85
|
-
if (!queryRes.data.bcs || !("bcsBytes" in queryRes.data.bcs)) {
|
|
86
|
-
throw new Error(`Invalid kiosk query: ${id}, expected object, got package`);
|
|
87
|
-
}
|
|
88
|
-
return bcs.de(KIOSK_TYPE, queryRes.data.bcs.bcsBytes, "base64");
|
|
89
|
-
}
|
|
90
|
-
function extractKioskData(data, listings, lockedItemIds, kioskId) {
|
|
91
|
-
return data.reduce(
|
|
92
|
-
(acc, val) => {
|
|
93
|
-
const type = val.name.type;
|
|
94
|
-
if (type.startsWith("0x2::kiosk::Item")) {
|
|
95
|
-
acc.itemIds.push(val.objectId);
|
|
96
|
-
acc.items.push({
|
|
97
|
-
objectId: val.objectId,
|
|
98
|
-
type: val.objectType,
|
|
99
|
-
isLocked: false,
|
|
100
|
-
kioskId
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
if (type.startsWith("0x2::kiosk::Listing")) {
|
|
104
|
-
acc.listingIds.push(val.objectId);
|
|
105
|
-
listings.push({
|
|
106
|
-
objectId: val.name.value.id,
|
|
107
|
-
listingId: val.objectId,
|
|
108
|
-
isExclusive: val.name.value.is_exclusive
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
if (type.startsWith("0x2::kiosk::Lock")) {
|
|
112
|
-
lockedItemIds?.push(val.name.value.id);
|
|
113
|
-
}
|
|
114
|
-
if (type.startsWith("0x2::kiosk_extension::ExtensionKey")) {
|
|
115
|
-
acc.extensions.push({
|
|
116
|
-
objectId: val.objectId,
|
|
117
|
-
type: normalizeStructTag(parseStructTag(val.name.type).typeParams[0])
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
return acc;
|
|
121
|
-
},
|
|
122
|
-
{ items: [], itemIds: [], listingIds: [], extensions: [] }
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
function attachListingsAndPrices(kioskData, listings, listingObjects) {
|
|
126
|
-
const itemListings = listings.reduce(
|
|
127
|
-
(acc, item, idx) => {
|
|
128
|
-
acc[item.objectId] = { ...item };
|
|
129
|
-
if (listingObjects.length === 0)
|
|
130
|
-
return acc;
|
|
131
|
-
const content = listingObjects[idx].data?.content;
|
|
132
|
-
const data = content?.dataType === "moveObject" ? content?.fields : null;
|
|
133
|
-
if (!data)
|
|
134
|
-
return acc;
|
|
135
|
-
acc[item.objectId].price = data.value;
|
|
136
|
-
return acc;
|
|
137
|
-
},
|
|
138
|
-
{}
|
|
139
|
-
);
|
|
140
|
-
kioskData.items.forEach((item) => {
|
|
141
|
-
item.listing = itemListings[item.objectId] || void 0;
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
function attachObjects(kioskData, objects) {
|
|
145
|
-
const mapping = objects.reduce(
|
|
146
|
-
(acc, obj) => {
|
|
147
|
-
acc[obj.objectId] = obj;
|
|
148
|
-
return acc;
|
|
149
|
-
},
|
|
150
|
-
{}
|
|
151
|
-
);
|
|
152
|
-
kioskData.items.forEach((item) => {
|
|
153
|
-
item.data = mapping[item.objectId] || void 0;
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
function attachLockedItems(kioskData, lockedItemIds) {
|
|
157
|
-
const lockedStatuses = lockedItemIds.reduce(
|
|
158
|
-
(acc, item) => {
|
|
159
|
-
acc[item] = true;
|
|
160
|
-
return acc;
|
|
161
|
-
},
|
|
162
|
-
{}
|
|
163
|
-
);
|
|
164
|
-
kioskData.items.forEach((item) => {
|
|
165
|
-
item.isLocked = lockedStatuses[item.objectId] || false;
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
async function getAllDynamicFields(client, parentId, pagination) {
|
|
169
|
-
let hasNextPage = true;
|
|
170
|
-
let cursor = void 0;
|
|
171
|
-
const data = [];
|
|
172
|
-
while (hasNextPage) {
|
|
173
|
-
const result = await client.getDynamicFields({
|
|
174
|
-
parentId,
|
|
175
|
-
limit: pagination.limit || void 0,
|
|
176
|
-
cursor
|
|
177
|
-
});
|
|
178
|
-
data.push(...result.data);
|
|
179
|
-
hasNextPage = result.hasNextPage;
|
|
180
|
-
cursor = result.nextCursor;
|
|
181
|
-
}
|
|
182
|
-
return data;
|
|
183
|
-
}
|
|
184
|
-
async function getAllObjects(client, ids, options, limit = DEFAULT_QUERY_LIMIT) {
|
|
185
|
-
const chunks = Array.from(
|
|
186
|
-
{ length: Math.ceil(ids.length / limit) },
|
|
187
|
-
(_, index) => ids.slice(index * limit, index * limit + limit)
|
|
188
|
-
);
|
|
189
|
-
const results = await Promise.all(
|
|
190
|
-
chunks.map((chunk) => {
|
|
191
|
-
return client.multiGetObjects({
|
|
192
|
-
ids: chunk,
|
|
193
|
-
options
|
|
194
|
-
});
|
|
195
|
-
})
|
|
196
|
-
);
|
|
197
|
-
return results.flat();
|
|
198
|
-
}
|
|
199
|
-
async function getAllOwnedObjects({
|
|
200
|
-
client,
|
|
201
|
-
owner,
|
|
202
|
-
filter,
|
|
203
|
-
limit = DEFAULT_QUERY_LIMIT,
|
|
204
|
-
options = { showType: true, showContent: true }
|
|
205
|
-
}) {
|
|
206
|
-
let hasNextPage = true;
|
|
207
|
-
let cursor = void 0;
|
|
208
|
-
const data = [];
|
|
209
|
-
while (hasNextPage) {
|
|
210
|
-
const result = await client.getOwnedObjects({
|
|
211
|
-
owner,
|
|
212
|
-
filter,
|
|
213
|
-
limit,
|
|
214
|
-
cursor,
|
|
215
|
-
options
|
|
216
|
-
});
|
|
217
|
-
data.push(...result.data);
|
|
218
|
-
hasNextPage = result.hasNextPage;
|
|
219
|
-
cursor = result.nextCursor;
|
|
220
|
-
}
|
|
221
|
-
return data;
|
|
222
|
-
}
|
|
223
|
-
function percentageToBasisPoints(percentage) {
|
|
224
|
-
if (percentage < 0 || percentage > 100)
|
|
225
|
-
throw new Error("Percentage needs to be in the [0,100] range.");
|
|
226
|
-
return Math.ceil(percentage * 100);
|
|
227
|
-
}
|
|
228
|
-
function parseTransferPolicyCapObject(item) {
|
|
229
|
-
const type = item?.data?.content?.type;
|
|
230
|
-
const policy = item?.data?.content?.fields?.policy_id;
|
|
231
|
-
if (!type.includes(TRANSFER_POLICY_CAP_TYPE))
|
|
232
|
-
return void 0;
|
|
233
|
-
const objectType = type.replace(TRANSFER_POLICY_CAP_TYPE + "<", "").slice(0, -1);
|
|
234
|
-
return {
|
|
235
|
-
policyId: policy,
|
|
236
|
-
policyCapId: item.data?.objectId,
|
|
237
|
-
type: objectType
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
function getNormalizedRuleType(rule) {
|
|
241
|
-
const normalizedRuleAddress = rule.split("::");
|
|
242
|
-
normalizedRuleAddress[0] = normalizeSuiAddress(normalizedRuleAddress[0]);
|
|
243
|
-
return normalizedRuleAddress.join("::");
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// src/tx/kiosk.ts
|
|
247
|
-
import { bcs as bcs2 } from "@mysten/sui.js/bcs";
|
|
248
|
-
function createKiosk(tx) {
|
|
249
|
-
const [kiosk, kioskOwnerCap] = tx.moveCall({
|
|
250
|
-
target: `${KIOSK_MODULE}::new`
|
|
251
|
-
});
|
|
252
|
-
return [kiosk, kioskOwnerCap];
|
|
253
|
-
}
|
|
254
|
-
function createKioskAndShare(tx) {
|
|
255
|
-
const [kiosk, kioskOwnerCap] = createKiosk(tx);
|
|
256
|
-
shareKiosk(tx, kiosk);
|
|
257
|
-
return kioskOwnerCap;
|
|
258
|
-
}
|
|
259
|
-
function shareKiosk(tx, kiosk) {
|
|
260
|
-
tx.moveCall({
|
|
261
|
-
target: `0x2::transfer::public_share_object`,
|
|
262
|
-
typeArguments: [KIOSK_TYPE],
|
|
263
|
-
arguments: [kiosk]
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
function place(tx, itemType, kiosk, kioskCap, item) {
|
|
267
|
-
tx.moveCall({
|
|
268
|
-
target: `${KIOSK_MODULE}::place`,
|
|
269
|
-
typeArguments: [itemType],
|
|
270
|
-
arguments: [tx.object(kiosk), tx.object(kioskCap), tx.object(item)]
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
function lock(tx, itemType, kiosk, kioskCap, policy, item) {
|
|
274
|
-
tx.moveCall({
|
|
275
|
-
target: `${KIOSK_MODULE}::lock`,
|
|
276
|
-
typeArguments: [itemType],
|
|
277
|
-
arguments: [tx.object(kiosk), tx.object(kioskCap), tx.object(policy), tx.object(item)]
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
function take(tx, itemType, kiosk, kioskCap, itemId) {
|
|
281
|
-
const [item] = tx.moveCall({
|
|
282
|
-
target: `${KIOSK_MODULE}::take`,
|
|
283
|
-
typeArguments: [itemType],
|
|
284
|
-
arguments: [tx.object(kiosk), tx.object(kioskCap), tx.pure.id(itemId)]
|
|
285
|
-
});
|
|
286
|
-
return item;
|
|
287
|
-
}
|
|
288
|
-
function list(tx, itemType, kiosk, kioskCap, itemId, price) {
|
|
289
|
-
tx.moveCall({
|
|
290
|
-
target: `${KIOSK_MODULE}::list`,
|
|
291
|
-
typeArguments: [itemType],
|
|
292
|
-
arguments: [tx.object(kiosk), tx.object(kioskCap), tx.pure.id(itemId), tx.pure.u64(price)]
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
function delist(tx, itemType, kiosk, kioskCap, itemId) {
|
|
296
|
-
tx.moveCall({
|
|
297
|
-
target: `${KIOSK_MODULE}::delist`,
|
|
298
|
-
typeArguments: [itemType],
|
|
299
|
-
arguments: [tx.object(kiosk), tx.object(kioskCap), tx.pure.id(itemId)]
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
function placeAndList(tx, itemType, kiosk, kioskCap, item, price) {
|
|
303
|
-
tx.moveCall({
|
|
304
|
-
target: `${KIOSK_MODULE}::place_and_list`,
|
|
305
|
-
typeArguments: [itemType],
|
|
306
|
-
arguments: [tx.object(kiosk), tx.object(kioskCap), tx.object(item), tx.pure.u64(price)]
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
function purchase(tx, itemType, kiosk, itemId, payment) {
|
|
310
|
-
const [item, transferRequest] = tx.moveCall({
|
|
311
|
-
target: `${KIOSK_MODULE}::purchase`,
|
|
312
|
-
typeArguments: [itemType],
|
|
313
|
-
arguments: [tx.object(kiosk), tx.pure.id(itemId), tx.object(payment)]
|
|
314
|
-
});
|
|
315
|
-
return [item, transferRequest];
|
|
316
|
-
}
|
|
317
|
-
function withdrawFromKiosk(tx, kiosk, kioskCap, amount) {
|
|
318
|
-
const amountArg = bcs2.option(bcs2.u64()).serialize(amount);
|
|
319
|
-
const [coin] = tx.moveCall({
|
|
320
|
-
target: `${KIOSK_MODULE}::withdraw`,
|
|
321
|
-
arguments: [tx.object(kiosk), tx.object(kioskCap), amountArg]
|
|
322
|
-
});
|
|
323
|
-
return coin;
|
|
324
|
-
}
|
|
325
|
-
function borrowValue(tx, itemType, kiosk, kioskCap, itemId) {
|
|
326
|
-
const [item, promise] = tx.moveCall({
|
|
327
|
-
target: `${KIOSK_MODULE}::borrow_val`,
|
|
328
|
-
typeArguments: [itemType],
|
|
329
|
-
arguments: [tx.object(kiosk), tx.object(kioskCap), tx.pure.id(itemId)]
|
|
330
|
-
});
|
|
331
|
-
return [item, promise];
|
|
332
|
-
}
|
|
333
|
-
function returnValue(tx, itemType, kiosk, item, promise) {
|
|
334
|
-
tx.moveCall({
|
|
335
|
-
target: `${KIOSK_MODULE}::return_val`,
|
|
336
|
-
typeArguments: [itemType],
|
|
337
|
-
arguments: [tx.object(kiosk), item, promise]
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
// src/tx/rules/resolve.ts
|
|
342
|
-
function resolveRoyaltyRule(params) {
|
|
343
|
-
const { transactionBlock: txb, itemType, price, packageId, transferRequest, policyId } = params;
|
|
344
|
-
const policyObj = txb.object(policyId);
|
|
345
|
-
const [amount] = txb.moveCall({
|
|
346
|
-
target: `${packageId}::royalty_rule::fee_amount`,
|
|
347
|
-
typeArguments: [itemType],
|
|
348
|
-
arguments: [policyObj, txb.pure.u64(price || "0")]
|
|
349
|
-
});
|
|
350
|
-
const feeCoin = txb.splitCoins(txb.gas, [amount]);
|
|
351
|
-
txb.moveCall({
|
|
352
|
-
target: `${packageId}::royalty_rule::pay`,
|
|
353
|
-
typeArguments: [itemType],
|
|
354
|
-
arguments: [policyObj, transferRequest, feeCoin]
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
function resolveKioskLockRule(params) {
|
|
358
|
-
const {
|
|
359
|
-
transactionBlock: txb,
|
|
360
|
-
packageId,
|
|
361
|
-
itemType,
|
|
362
|
-
kiosk,
|
|
363
|
-
kioskCap,
|
|
364
|
-
policyId,
|
|
365
|
-
purchasedItem,
|
|
366
|
-
transferRequest
|
|
367
|
-
} = params;
|
|
368
|
-
if (!kiosk || !kioskCap)
|
|
369
|
-
throw new Error("Missing Owned Kiosk or Owned Kiosk Cap");
|
|
370
|
-
lock(txb, itemType, kiosk, kioskCap, policyId, purchasedItem);
|
|
371
|
-
txb.moveCall({
|
|
372
|
-
target: `${packageId}::kiosk_lock_rule::prove`,
|
|
373
|
-
typeArguments: [itemType],
|
|
374
|
-
arguments: [transferRequest, txb.object(kiosk)]
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
function resolvePersonalKioskRule(params) {
|
|
378
|
-
const { transactionBlock: txb, packageId, itemType, kiosk, transferRequest } = params;
|
|
379
|
-
if (!kiosk)
|
|
380
|
-
throw new Error("Missing owned Kiosk.");
|
|
381
|
-
txb.moveCall({
|
|
382
|
-
target: `${packageId}::personal_kiosk_rule::prove`,
|
|
383
|
-
typeArguments: [itemType],
|
|
384
|
-
arguments: [txb.object(kiosk), transferRequest]
|
|
385
|
-
});
|
|
386
|
-
}
|
|
387
|
-
function resolveFloorPriceRule(params) {
|
|
388
|
-
const { transactionBlock: txb, packageId, itemType, policyId, transferRequest } = params;
|
|
389
|
-
txb.moveCall({
|
|
390
|
-
target: `${packageId}::floor_price_rule::prove`,
|
|
391
|
-
typeArguments: [itemType],
|
|
392
|
-
arguments: [txb.object(policyId), transferRequest]
|
|
393
|
-
});
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
// src/constants.ts
|
|
397
|
-
var ROYALTY_RULE_ADDRESS = {
|
|
398
|
-
["testnet" /* TESTNET */]: "bd8fc1947cf119350184107a3087e2dc27efefa0dd82e25a1f699069fe81a585",
|
|
399
|
-
["mainnet" /* MAINNET */]: "0x434b5bd8f6a7b05fede0ff46c6e511d71ea326ed38056e3bcd681d2d7c2a7879",
|
|
400
|
-
["custom" /* CUSTOM */]: ""
|
|
401
|
-
};
|
|
402
|
-
var KIOSK_LOCK_RULE_ADDRESS = {
|
|
403
|
-
["testnet" /* TESTNET */]: "bd8fc1947cf119350184107a3087e2dc27efefa0dd82e25a1f699069fe81a585",
|
|
404
|
-
["mainnet" /* MAINNET */]: "0x434b5bd8f6a7b05fede0ff46c6e511d71ea326ed38056e3bcd681d2d7c2a7879",
|
|
405
|
-
["custom" /* CUSTOM */]: ""
|
|
406
|
-
};
|
|
407
|
-
var FLOOR_PRICE_RULE_ADDRESS = {
|
|
408
|
-
["testnet" /* TESTNET */]: "0x06f6bdd3f2e2e759d8a4b9c252f379f7a05e72dfe4c0b9311cdac27b8eb791b1",
|
|
409
|
-
["mainnet" /* MAINNET */]: "0x34cc6762780f4f6f153c924c0680cfe2a1fb4601e7d33cc28a92297b62de1e0e",
|
|
410
|
-
["custom" /* CUSTOM */]: ""
|
|
411
|
-
};
|
|
412
|
-
var PERSONAL_KIOSK_RULE_ADDRESS = {
|
|
413
|
-
["testnet" /* TESTNET */]: "0x06f6bdd3f2e2e759d8a4b9c252f379f7a05e72dfe4c0b9311cdac27b8eb791b1",
|
|
414
|
-
["mainnet" /* MAINNET */]: "0x0cb4bcc0560340eb1a1b929cabe56b33fc6449820ec8c1980d69bb98b649b802",
|
|
415
|
-
["custom" /* CUSTOM */]: ""
|
|
416
|
-
};
|
|
417
|
-
function getBaseRules({
|
|
418
|
-
royaltyRulePackageId,
|
|
419
|
-
kioskLockRulePackageId,
|
|
420
|
-
personalKioskRulePackageId,
|
|
421
|
-
floorPriceRulePackageId
|
|
422
|
-
}) {
|
|
423
|
-
const rules2 = [];
|
|
424
|
-
if (royaltyRulePackageId) {
|
|
425
|
-
rules2.push({
|
|
426
|
-
rule: `${royaltyRulePackageId}::royalty_rule::Rule`,
|
|
427
|
-
packageId: royaltyRulePackageId,
|
|
428
|
-
resolveRuleFunction: resolveRoyaltyRule
|
|
429
|
-
});
|
|
430
|
-
}
|
|
431
|
-
if (kioskLockRulePackageId) {
|
|
432
|
-
rules2.push({
|
|
433
|
-
rule: `${kioskLockRulePackageId}::kiosk_lock_rule::Rule`,
|
|
434
|
-
packageId: kioskLockRulePackageId,
|
|
435
|
-
resolveRuleFunction: resolveKioskLockRule,
|
|
436
|
-
hasLockingRule: true
|
|
437
|
-
});
|
|
438
|
-
}
|
|
439
|
-
if (personalKioskRulePackageId) {
|
|
440
|
-
rules2.push({
|
|
441
|
-
rule: `${personalKioskRulePackageId}::personal_kiosk_rule::Rule`,
|
|
442
|
-
packageId: personalKioskRulePackageId,
|
|
443
|
-
resolveRuleFunction: resolvePersonalKioskRule
|
|
444
|
-
});
|
|
445
|
-
}
|
|
446
|
-
if (floorPriceRulePackageId) {
|
|
447
|
-
rules2.push({
|
|
448
|
-
rule: `${floorPriceRulePackageId}::floor_price_rule::Rule`,
|
|
449
|
-
packageId: floorPriceRulePackageId,
|
|
450
|
-
resolveRuleFunction: resolveFloorPriceRule
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
return rules2;
|
|
454
|
-
}
|
|
455
|
-
var testnetRules = getBaseRules({
|
|
456
|
-
royaltyRulePackageId: ROYALTY_RULE_ADDRESS["testnet" /* TESTNET */],
|
|
457
|
-
kioskLockRulePackageId: KIOSK_LOCK_RULE_ADDRESS["testnet" /* TESTNET */],
|
|
458
|
-
personalKioskRulePackageId: PERSONAL_KIOSK_RULE_ADDRESS["testnet" /* TESTNET */],
|
|
459
|
-
floorPriceRulePackageId: FLOOR_PRICE_RULE_ADDRESS["testnet" /* TESTNET */]
|
|
460
|
-
});
|
|
461
|
-
var mainnetRules = getBaseRules({
|
|
462
|
-
royaltyRulePackageId: ROYALTY_RULE_ADDRESS["mainnet" /* MAINNET */],
|
|
463
|
-
kioskLockRulePackageId: KIOSK_LOCK_RULE_ADDRESS["mainnet" /* MAINNET */]
|
|
464
|
-
});
|
|
465
|
-
var rules = [...testnetRules, ...mainnetRules];
|
|
466
|
-
|
|
467
|
-
// src/query/kiosk.ts
|
|
468
|
-
import { isValidSuiAddress } from "@mysten/sui.js/utils";
|
|
469
|
-
async function fetchKiosk(client, kioskId, pagination, options) {
|
|
470
|
-
const data = await getAllDynamicFields(client, kioskId, pagination);
|
|
471
|
-
const listings = [];
|
|
472
|
-
const lockedItemIds = [];
|
|
473
|
-
const kioskData = extractKioskData(data, listings, lockedItemIds, kioskId);
|
|
474
|
-
const [kiosk, listingObjects, items] = await Promise.all([
|
|
475
|
-
options.withKioskFields ? getKioskObject(client, kioskId) : Promise.resolve(void 0),
|
|
476
|
-
options.withListingPrices ? getAllObjects(client, kioskData.listingIds, {
|
|
477
|
-
showContent: true
|
|
478
|
-
}) : Promise.resolve([]),
|
|
479
|
-
options.withObjects ? getAllObjects(client, kioskData.itemIds, options.objectOptions || { showDisplay: true }) : Promise.resolve([])
|
|
480
|
-
]);
|
|
481
|
-
if (options.withKioskFields)
|
|
482
|
-
kioskData.kiosk = kiosk;
|
|
483
|
-
attachListingsAndPrices(kioskData, listings, listingObjects);
|
|
484
|
-
attachLockedItems(kioskData, lockedItemIds);
|
|
485
|
-
attachObjects(
|
|
486
|
-
kioskData,
|
|
487
|
-
items.filter((x) => !!x.data).map((x) => x.data)
|
|
488
|
-
);
|
|
489
|
-
return {
|
|
490
|
-
data: kioskData,
|
|
491
|
-
nextCursor: null,
|
|
492
|
-
hasNextPage: false
|
|
493
|
-
};
|
|
494
|
-
}
|
|
495
|
-
async function getOwnedKiosks(client, address, options) {
|
|
496
|
-
if (!isValidSuiAddress(address))
|
|
497
|
-
return {
|
|
498
|
-
nextCursor: null,
|
|
499
|
-
hasNextPage: false,
|
|
500
|
-
kioskOwnerCaps: [],
|
|
501
|
-
kioskIds: []
|
|
502
|
-
};
|
|
503
|
-
const filter = {
|
|
504
|
-
MatchAny: [
|
|
505
|
-
{
|
|
506
|
-
StructType: KIOSK_OWNER_CAP
|
|
507
|
-
}
|
|
508
|
-
]
|
|
509
|
-
};
|
|
510
|
-
if (options?.personalKioskType) {
|
|
511
|
-
filter.MatchAny.push({
|
|
512
|
-
StructType: options.personalKioskType
|
|
513
|
-
});
|
|
514
|
-
}
|
|
515
|
-
const { data, hasNextPage, nextCursor } = await client.getOwnedObjects({
|
|
516
|
-
owner: address,
|
|
517
|
-
filter,
|
|
518
|
-
options: {
|
|
519
|
-
showContent: true,
|
|
520
|
-
showType: true
|
|
521
|
-
},
|
|
522
|
-
...options?.pagination || {}
|
|
523
|
-
});
|
|
524
|
-
const kioskIdList = data?.map((x) => {
|
|
525
|
-
const fields = x.data?.content?.dataType === "moveObject" ? x.data.content.fields : null;
|
|
526
|
-
return fields?.cap ? fields?.cap?.fields?.for : fields?.for;
|
|
527
|
-
});
|
|
528
|
-
const filteredData = data.filter((x) => "data" in x).map((x) => x.data);
|
|
529
|
-
return {
|
|
530
|
-
nextCursor,
|
|
531
|
-
hasNextPage,
|
|
532
|
-
kioskOwnerCaps: filteredData.map((x, idx) => ({
|
|
533
|
-
isPersonal: x.type !== KIOSK_OWNER_CAP,
|
|
534
|
-
digest: x.digest,
|
|
535
|
-
version: x.version,
|
|
536
|
-
objectId: x.objectId,
|
|
537
|
-
kioskId: kioskIdList[idx]
|
|
538
|
-
})),
|
|
539
|
-
kioskIds: kioskIdList
|
|
540
|
-
};
|
|
541
|
-
}
|
|
542
|
-
async function fetchKioskExtension(client, kioskId, extensionType) {
|
|
543
|
-
const extension = await client.getDynamicFieldObject({
|
|
544
|
-
parentId: kioskId,
|
|
545
|
-
name: {
|
|
546
|
-
type: `0x2::kiosk_extension::ExtensionKey<${extensionType}>`,
|
|
547
|
-
value: {
|
|
548
|
-
dummy_field: false
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
});
|
|
552
|
-
if (!extension.data)
|
|
553
|
-
return null;
|
|
554
|
-
const fields = extension?.data?.content?.fields?.value?.fields;
|
|
555
|
-
return {
|
|
556
|
-
objectId: extension.data.objectId,
|
|
557
|
-
type: extensionType,
|
|
558
|
-
isEnabled: fields?.is_enabled,
|
|
559
|
-
permissions: fields?.permissions,
|
|
560
|
-
storageId: fields?.storage?.fields?.id?.id,
|
|
561
|
-
storageSize: fields?.storage?.fields?.size
|
|
562
|
-
};
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
// src/query/transfer-policy.ts
|
|
566
|
-
import { isValidSuiAddress as isValidSuiAddress2 } from "@mysten/sui.js/utils";
|
|
567
|
-
async function queryTransferPolicy(client, type) {
|
|
568
|
-
const { data } = await client.queryEvents({
|
|
569
|
-
query: {
|
|
570
|
-
MoveEventType: `${TRANSFER_POLICY_CREATED_EVENT}<${type}>`
|
|
571
|
-
}
|
|
572
|
-
});
|
|
573
|
-
const search = data.map((event) => event.parsedJson);
|
|
574
|
-
const policies = await client.multiGetObjects({
|
|
575
|
-
ids: search.map((policy) => policy.id),
|
|
576
|
-
options: { showBcs: true, showOwner: true }
|
|
577
|
-
});
|
|
578
|
-
return policies.filter((policy) => !!policy && "data" in policy).map(({ data: policy }) => {
|
|
579
|
-
if (!policy || !policy.bcs || !("bcsBytes" in policy.bcs)) {
|
|
580
|
-
throw new Error(`Invalid policy: ${policy?.objectId}, expected object, got package`);
|
|
581
|
-
}
|
|
582
|
-
const parsed = bcs.de(TRANSFER_POLICY_TYPE, policy.bcs.bcsBytes, "base64");
|
|
583
|
-
return {
|
|
584
|
-
id: policy?.objectId,
|
|
585
|
-
type: `${TRANSFER_POLICY_TYPE}<${type}>`,
|
|
586
|
-
owner: policy?.owner,
|
|
587
|
-
rules: parsed.rules,
|
|
588
|
-
balance: parsed.balance
|
|
589
|
-
};
|
|
590
|
-
});
|
|
591
|
-
}
|
|
592
|
-
async function queryTransferPolicyCapsByType(client, address, type) {
|
|
593
|
-
if (!isValidSuiAddress2(address))
|
|
594
|
-
return [];
|
|
595
|
-
const filter = {
|
|
596
|
-
MatchAll: [
|
|
597
|
-
{
|
|
598
|
-
StructType: `${TRANSFER_POLICY_CAP_TYPE}<${type}>`
|
|
599
|
-
}
|
|
600
|
-
]
|
|
601
|
-
};
|
|
602
|
-
const data = await getAllOwnedObjects({
|
|
603
|
-
client,
|
|
604
|
-
filter,
|
|
605
|
-
owner: address
|
|
606
|
-
});
|
|
607
|
-
return data.map((item) => parseTransferPolicyCapObject(item)).filter((item) => !!item);
|
|
608
|
-
}
|
|
609
|
-
async function queryOwnedTransferPolicies(client, address) {
|
|
610
|
-
if (!isValidSuiAddress2(address))
|
|
611
|
-
return;
|
|
612
|
-
const filter = {
|
|
613
|
-
MatchAll: [
|
|
614
|
-
{
|
|
615
|
-
MoveModule: {
|
|
616
|
-
module: "transfer_policy",
|
|
617
|
-
package: "0x2"
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
]
|
|
621
|
-
};
|
|
622
|
-
const data = await getAllOwnedObjects({ client, owner: address, filter });
|
|
623
|
-
const policies = [];
|
|
624
|
-
for (const item of data) {
|
|
625
|
-
const data2 = parseTransferPolicyCapObject(item);
|
|
626
|
-
if (data2)
|
|
627
|
-
policies.push(data2);
|
|
628
|
-
}
|
|
629
|
-
return policies;
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
// src/client/kiosk-client.ts
|
|
633
|
-
var KioskClient = class {
|
|
634
|
-
constructor(options) {
|
|
635
|
-
this.client = options.client;
|
|
636
|
-
this.network = options.network;
|
|
637
|
-
this.rules = rules;
|
|
638
|
-
this.packageIds = options.packageIds;
|
|
639
|
-
if (options.packageIds)
|
|
640
|
-
this.rules.push(...getBaseRules(options.packageIds));
|
|
641
|
-
}
|
|
642
|
-
/// Querying
|
|
643
|
-
/**
|
|
644
|
-
* Get an addresses's owned kiosks.
|
|
645
|
-
* @param address The address for which we want to retrieve the kiosks.
|
|
646
|
-
* @returns An Object containing all the `kioskOwnerCap` objects as well as the kioskIds.
|
|
647
|
-
*/
|
|
648
|
-
async getOwnedKiosks({ address }) {
|
|
649
|
-
const personalPackageId = this.packageIds?.personalKioskRulePackageId || PERSONAL_KIOSK_RULE_ADDRESS[this.network];
|
|
650
|
-
return getOwnedKiosks(this.client, address, {
|
|
651
|
-
personalKioskType: personalPackageId ? `${personalPackageId}::personal_kiosk::PersonalKioskCap` : ""
|
|
652
|
-
});
|
|
653
|
-
}
|
|
654
|
-
/**
|
|
655
|
-
* Fetches the kiosk contents.
|
|
656
|
-
* @param kioskId The ID of the kiosk to fetch.
|
|
657
|
-
* @param options Optioal
|
|
658
|
-
* @returns
|
|
659
|
-
*/
|
|
660
|
-
async getKiosk({ id, options }) {
|
|
661
|
-
return (await fetchKiosk(
|
|
662
|
-
this.client,
|
|
663
|
-
id,
|
|
664
|
-
{
|
|
665
|
-
limit: 1e3
|
|
666
|
-
},
|
|
667
|
-
options || {}
|
|
668
|
-
)).data;
|
|
669
|
-
}
|
|
670
|
-
/**
|
|
671
|
-
* Fetch the extension data (if any) for a kiosk, by type
|
|
672
|
-
* @param kioskId The ID of the kiosk to lookup
|
|
673
|
-
* @param extensionType The Type of the extension (can be used from by using the type returned by `getKiosk()`)
|
|
674
|
-
*/
|
|
675
|
-
async getKioskExtension({ kioskId, type }) {
|
|
676
|
-
return fetchKioskExtension(this.client, kioskId, type);
|
|
677
|
-
}
|
|
678
|
-
/**
|
|
679
|
-
* Query the Transfer Policy(ies) for type `T`.
|
|
680
|
-
* @param type The Type we're querying for (E.g `0xMyAddress::hero::Hero`)
|
|
681
|
-
*/
|
|
682
|
-
async getTransferPolicies({ type }) {
|
|
683
|
-
return queryTransferPolicy(this.client, type);
|
|
684
|
-
}
|
|
685
|
-
/**
|
|
686
|
-
* Query all the owned transfer policies for an address.
|
|
687
|
-
* Returns `TransferPolicyCap` which uncludes `policyId, policyCapId, type`.
|
|
688
|
-
* @param address The address we're searching the owned transfer policies for.
|
|
689
|
-
*/
|
|
690
|
-
async getOwnedTransferPolicies({ address }) {
|
|
691
|
-
return queryOwnedTransferPolicies(this.client, address);
|
|
692
|
-
}
|
|
693
|
-
/**
|
|
694
|
-
* Query the Transfer Policy Cap for type `T`, owned by `address`
|
|
695
|
-
* @param type The Type `T` for the object
|
|
696
|
-
* @param address The address that owns the cap.
|
|
697
|
-
*/
|
|
698
|
-
async getOwnedTransferPoliciesByType({ type, address }) {
|
|
699
|
-
return queryTransferPolicyCapsByType(this.client, address, type);
|
|
700
|
-
}
|
|
701
|
-
// Someone would just have to create a `kiosk-client.ts` file in their project, initialize a KioskClient
|
|
702
|
-
// and call the `addRuleResolver` function. Each rule has a `resolve` function.
|
|
703
|
-
// The resolve function is automatically called on `purchaseAndResolve` function call.
|
|
704
|
-
addRuleResolver(rule) {
|
|
705
|
-
if (this.rules.find((x) => x.rule === rule.rule))
|
|
706
|
-
throw new Error(`Rule ${rule.rule} resolver already exists.`);
|
|
707
|
-
this.rules.push(rule);
|
|
708
|
-
}
|
|
709
|
-
/**
|
|
710
|
-
* A convenient helper to get the packageIds for our supported ruleset,
|
|
711
|
-
* based on `kioskClient` configuration.
|
|
712
|
-
*/
|
|
713
|
-
getRulePackageId(rule) {
|
|
714
|
-
const rules2 = this.packageIds || {};
|
|
715
|
-
const network = this.network;
|
|
716
|
-
if (!rules2[rule] && network !== "mainnet" /* MAINNET */ && network !== "testnet" /* TESTNET */) {
|
|
717
|
-
throw new Error(`Missing packageId for rule ${rule}`);
|
|
718
|
-
}
|
|
719
|
-
switch (rule) {
|
|
720
|
-
case "kioskLockRulePackageId":
|
|
721
|
-
return rules2[rule] || KIOSK_LOCK_RULE_ADDRESS[network];
|
|
722
|
-
case "royaltyRulePackageId":
|
|
723
|
-
return rules2[rule] || ROYALTY_RULE_ADDRESS[network];
|
|
724
|
-
case "personalKioskRulePackageId":
|
|
725
|
-
return rules2[rule] || PERSONAL_KIOSK_RULE_ADDRESS[network];
|
|
726
|
-
case "floorPriceRulePackageId":
|
|
727
|
-
return rules2[rule] || FLOOR_PRICE_RULE_ADDRESS[network];
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
};
|
|
731
|
-
|
|
732
|
-
// src/tx/rules/attach.ts
|
|
733
|
-
function attachKioskLockRuleTx(tx, type, policy, policyCap, packageId) {
|
|
734
|
-
tx.moveCall({
|
|
735
|
-
target: `${packageId}::kiosk_lock_rule::add`,
|
|
736
|
-
typeArguments: [type],
|
|
737
|
-
arguments: [tx.object(policy), tx.object(policyCap)]
|
|
738
|
-
});
|
|
739
|
-
}
|
|
740
|
-
function attachRoyaltyRuleTx(tx, type, policy, policyCap, percentageBps, minAmount, packageId) {
|
|
741
|
-
if (Number(percentageBps) < 0 || Number(percentageBps) > 1e4)
|
|
742
|
-
throw new Error("Invalid basis point percentage. Use a value between [0,10000].");
|
|
743
|
-
tx.moveCall({
|
|
744
|
-
target: `${packageId}::royalty_rule::add`,
|
|
745
|
-
typeArguments: [type],
|
|
746
|
-
arguments: [
|
|
747
|
-
tx.object(policy),
|
|
748
|
-
tx.object(policyCap),
|
|
749
|
-
tx.pure.u16(Number(percentageBps)),
|
|
750
|
-
tx.pure.u64(minAmount)
|
|
751
|
-
]
|
|
752
|
-
});
|
|
753
|
-
}
|
|
754
|
-
function attachPersonalKioskRuleTx(tx, type, policy, policyCap, packageId) {
|
|
755
|
-
tx.moveCall({
|
|
756
|
-
target: `${packageId}::personal_kiosk_rule::add`,
|
|
757
|
-
typeArguments: [type],
|
|
758
|
-
arguments: [tx.object(policy), tx.object(policyCap)]
|
|
759
|
-
});
|
|
760
|
-
}
|
|
761
|
-
function attachFloorPriceRuleTx(tx, type, policy, policyCap, minPrice, packageId) {
|
|
762
|
-
tx.moveCall({
|
|
763
|
-
target: `${packageId}::floor_price_rule::add`,
|
|
764
|
-
typeArguments: [type],
|
|
765
|
-
arguments: [tx.object(policy), tx.object(policyCap), tx.pure.u64(minPrice)]
|
|
766
|
-
});
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
// src/tx/transfer-policy.ts
|
|
770
|
-
import { bcs as bcs3 } from "@mysten/sui.js/bcs";
|
|
771
|
-
function createTransferPolicy(tx, itemType, publisher) {
|
|
772
|
-
const [transferPolicy, transferPolicyCap] = createTransferPolicyWithoutSharing(
|
|
773
|
-
tx,
|
|
774
|
-
itemType,
|
|
775
|
-
publisher
|
|
776
|
-
);
|
|
777
|
-
shareTransferPolicy(tx, itemType, transferPolicy);
|
|
778
|
-
return transferPolicyCap;
|
|
779
|
-
}
|
|
780
|
-
function createTransferPolicyWithoutSharing(tx, itemType, publisher) {
|
|
781
|
-
const [transferPolicy, transferPolicyCap] = tx.moveCall({
|
|
782
|
-
target: `${TRANSFER_POLICY_MODULE}::new`,
|
|
783
|
-
typeArguments: [itemType],
|
|
784
|
-
arguments: [tx.object(publisher)]
|
|
785
|
-
});
|
|
786
|
-
return [transferPolicy, transferPolicyCap];
|
|
787
|
-
}
|
|
788
|
-
function shareTransferPolicy(tx, itemType, transferPolicy) {
|
|
789
|
-
tx.moveCall({
|
|
790
|
-
target: `0x2::transfer::public_share_object`,
|
|
791
|
-
typeArguments: [`${TRANSFER_POLICY_TYPE}<${itemType}>`],
|
|
792
|
-
arguments: [transferPolicy]
|
|
793
|
-
});
|
|
794
|
-
}
|
|
795
|
-
function withdrawFromPolicy(tx, itemType, policy, policyCap, amount) {
|
|
796
|
-
const amountArg = bcs3.option(bcs3.u64()).serialize(amount);
|
|
797
|
-
const [profits] = tx.moveCall({
|
|
798
|
-
target: `${TRANSFER_POLICY_MODULE}::withdraw`,
|
|
799
|
-
typeArguments: [itemType],
|
|
800
|
-
arguments: [tx.object(policy), tx.object(policyCap), amountArg]
|
|
801
|
-
});
|
|
802
|
-
return profits;
|
|
803
|
-
}
|
|
804
|
-
function confirmRequest(tx, itemType, policy, request) {
|
|
805
|
-
tx.moveCall({
|
|
806
|
-
target: `${TRANSFER_POLICY_MODULE}::confirm_request`,
|
|
807
|
-
typeArguments: [itemType],
|
|
808
|
-
arguments: [tx.object(policy), request]
|
|
809
|
-
});
|
|
810
|
-
}
|
|
811
|
-
function removeTransferPolicyRule(tx, itemType, ruleType, configType, policy, policyCap) {
|
|
812
|
-
tx.moveCall({
|
|
813
|
-
target: `${TRANSFER_POLICY_MODULE}::remove_rule`,
|
|
814
|
-
typeArguments: [itemType, ruleType, configType],
|
|
815
|
-
arguments: [tx.object(policy), tx.object(policyCap)]
|
|
816
|
-
});
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
// src/client/tp-transaction.ts
|
|
820
|
-
var _validateInputs, validateInputs_fn, _setup, setup_fn;
|
|
821
|
-
var TransferPolicyTransaction = class {
|
|
822
|
-
constructor({ kioskClient, transactionBlock, cap }) {
|
|
823
|
-
// Internal function that that the policy's Id + Cap + type have been set.
|
|
824
|
-
__privateAdd(this, _validateInputs);
|
|
825
|
-
/**
|
|
826
|
-
* Setup the state of the TransferPolicyTransaction.
|
|
827
|
-
*/
|
|
828
|
-
__privateAdd(this, _setup);
|
|
829
|
-
this.kioskClient = kioskClient;
|
|
830
|
-
this.transactionBlock = transactionBlock;
|
|
831
|
-
if (cap)
|
|
832
|
-
this.setCap(cap);
|
|
833
|
-
}
|
|
834
|
-
/**
|
|
835
|
-
* A function to create a new transfer policy.
|
|
836
|
-
* Checks if there's already an existing transfer policy to prevent
|
|
837
|
-
* double transfer polciy mistakes.
|
|
838
|
-
* There's an optional `skipCheck` flag that will just create the policy
|
|
839
|
-
* without checking
|
|
840
|
-
*
|
|
841
|
-
* @param type The Type (`T`) for which we're creating the transfer policy.
|
|
842
|
-
* @param publisher The Publisher Object Id.
|
|
843
|
-
* @param address Address to save the `TransferPolicyCap` object to.
|
|
844
|
-
* @param skipCheck (Optional) skip checking if a transfer policy already exists
|
|
845
|
-
*/
|
|
846
|
-
async createAndShare({
|
|
847
|
-
type,
|
|
848
|
-
publisher,
|
|
849
|
-
address,
|
|
850
|
-
skipCheck
|
|
851
|
-
}) {
|
|
852
|
-
if (!skipCheck) {
|
|
853
|
-
const policies = await this.kioskClient.getTransferPolicies({ type });
|
|
854
|
-
if (policies.length > 0)
|
|
855
|
-
throw new Error("There's already transfer policy for this Type.");
|
|
856
|
-
}
|
|
857
|
-
const cap = createTransferPolicy(this.transactionBlock, type, publisher);
|
|
858
|
-
this.transactionBlock.transferObjects([cap], this.transactionBlock.pure.address(address));
|
|
859
|
-
}
|
|
860
|
-
/**
|
|
861
|
-
* A convenient function to create a Transfer Policy and attach some rules
|
|
862
|
-
* before sharing it (so you can prepare it in a single PTB)
|
|
863
|
-
* @param type The Type (`T`) for which we're creating the transfer policy.
|
|
864
|
-
* @param publisher The Publisher Object Id.
|
|
865
|
-
* @param address Address to save the `TransferPolicyCap` object to.
|
|
866
|
-
* @param skipCheck (Optional) skip checking if a transfer policy already exists
|
|
867
|
-
*/
|
|
868
|
-
async create({
|
|
869
|
-
type,
|
|
870
|
-
publisher,
|
|
871
|
-
skipCheck
|
|
872
|
-
}) {
|
|
873
|
-
if (!skipCheck) {
|
|
874
|
-
const policies = await this.kioskClient.getTransferPolicies({ type });
|
|
875
|
-
if (policies.length > 0)
|
|
876
|
-
throw new Error("There's already transfer policy for this Type.");
|
|
877
|
-
}
|
|
878
|
-
const [policy, policyCap] = createTransferPolicyWithoutSharing(
|
|
879
|
-
this.transactionBlock,
|
|
880
|
-
type,
|
|
881
|
-
publisher
|
|
882
|
-
);
|
|
883
|
-
__privateMethod(this, _setup, setup_fn).call(this, policy, policyCap, type);
|
|
884
|
-
return this;
|
|
885
|
-
}
|
|
886
|
-
/**
|
|
887
|
-
* This can be called after calling the `create` function to share the `TransferPolicy`,
|
|
888
|
-
* and transfer the `TransferPolicyCap` to the specified address
|
|
889
|
-
*
|
|
890
|
-
* @param address The address to transfer the `TransferPolicyCap`
|
|
891
|
-
*/
|
|
892
|
-
shareAndTransferCap(address) {
|
|
893
|
-
if (!this.type || !this.policyCap || !this.policy)
|
|
894
|
-
throw new Error("This function can only be called after `transferPolicyManager.create`");
|
|
895
|
-
shareTransferPolicy(this.transactionBlock, this.type, this.policy);
|
|
896
|
-
this.transactionBlock.transferObjects(
|
|
897
|
-
[this.policyCap],
|
|
898
|
-
this.transactionBlock.pure.address(address)
|
|
899
|
-
);
|
|
900
|
-
}
|
|
901
|
-
/**
|
|
902
|
-
* Setup the TransferPolicy by passing a `cap` returned from `kioskClient.getOwnedTransferPolicies` or
|
|
903
|
-
* `kioskClient.getOwnedTransferPoliciesByType`.
|
|
904
|
-
* @param policyCapId The `TransferPolicyCap`
|
|
905
|
-
*/
|
|
906
|
-
setCap({ policyId, policyCapId, type }) {
|
|
907
|
-
return __privateMethod(this, _setup, setup_fn).call(this, policyId, policyCapId, type);
|
|
908
|
-
}
|
|
909
|
-
/**
|
|
910
|
-
* Withdraw from the transfer policy's profits.
|
|
911
|
-
* @param address Address to transfer the profits to.
|
|
912
|
-
* @param amount (Optional) amount parameter. Will withdraw all profits if the amount is not specified.
|
|
913
|
-
*/
|
|
914
|
-
withdraw(address, amount) {
|
|
915
|
-
__privateMethod(this, _validateInputs, validateInputs_fn).call(this);
|
|
916
|
-
const coin = withdrawFromPolicy(
|
|
917
|
-
this.transactionBlock,
|
|
918
|
-
this.type,
|
|
919
|
-
this.policy,
|
|
920
|
-
this.policyCap,
|
|
921
|
-
amount
|
|
922
|
-
);
|
|
923
|
-
this.transactionBlock.transferObjects([coin], this.transactionBlock.pure.address(address));
|
|
924
|
-
return this;
|
|
925
|
-
}
|
|
926
|
-
/**
|
|
927
|
-
* Adds the Kiosk Royalty rule to the Transfer Policy.
|
|
928
|
-
* You can pass the percentage, as well as a minimum amount.
|
|
929
|
-
* The royalty that will be paid is the MAX(percentage, minAmount).
|
|
930
|
-
* You can pass 0 in either value if you want only percentage royalty, or a fixed amount fee.
|
|
931
|
-
* (but you should define at least one of them for the rule to make sense).
|
|
932
|
-
*
|
|
933
|
-
* @param percentageBps The royalty percentage in basis points. Use `percentageToBasisPoints` helper to convert from percentage [0,100].
|
|
934
|
-
* @param minAmount The minimum royalty amount per request in MIST.
|
|
935
|
-
*/
|
|
936
|
-
addRoyaltyRule(percentageBps, minAmount) {
|
|
937
|
-
__privateMethod(this, _validateInputs, validateInputs_fn).call(this);
|
|
938
|
-
attachRoyaltyRuleTx(
|
|
939
|
-
this.transactionBlock,
|
|
940
|
-
this.type,
|
|
941
|
-
this.policy,
|
|
942
|
-
this.policyCap,
|
|
943
|
-
percentageBps,
|
|
944
|
-
minAmount,
|
|
945
|
-
this.kioskClient.getRulePackageId("royaltyRulePackageId")
|
|
946
|
-
);
|
|
947
|
-
return this;
|
|
948
|
-
}
|
|
949
|
-
/**
|
|
950
|
-
* Adds the Kiosk Lock Rule to the Transfer Policy.
|
|
951
|
-
* This Rule forces buyer to lock the item in the kiosk, preserving strong royalties.
|
|
952
|
-
*/
|
|
953
|
-
addLockRule() {
|
|
954
|
-
__privateMethod(this, _validateInputs, validateInputs_fn).call(this);
|
|
955
|
-
attachKioskLockRuleTx(
|
|
956
|
-
this.transactionBlock,
|
|
957
|
-
this.type,
|
|
958
|
-
this.policy,
|
|
959
|
-
this.policyCap,
|
|
960
|
-
this.kioskClient.getRulePackageId("kioskLockRulePackageId")
|
|
961
|
-
);
|
|
962
|
-
return this;
|
|
963
|
-
}
|
|
964
|
-
/**
|
|
965
|
-
* Attaches the Personal Kiosk Rule, making a purchase valid only for `SoulBound` kiosks.
|
|
966
|
-
*/
|
|
967
|
-
addPersonalKioskRule() {
|
|
968
|
-
__privateMethod(this, _validateInputs, validateInputs_fn).call(this);
|
|
969
|
-
attachPersonalKioskRuleTx(
|
|
970
|
-
this.transactionBlock,
|
|
971
|
-
this.type,
|
|
972
|
-
this.policy,
|
|
973
|
-
this.policyCap,
|
|
974
|
-
this.kioskClient.getRulePackageId("personalKioskRulePackageId")
|
|
975
|
-
);
|
|
976
|
-
return this;
|
|
977
|
-
}
|
|
978
|
-
/**
|
|
979
|
-
* A function to add the floor price rule to a transfer policy.
|
|
980
|
-
* @param minPrice The minimum price in MIST.
|
|
981
|
-
*/
|
|
982
|
-
addFloorPriceRule(minPrice) {
|
|
983
|
-
__privateMethod(this, _validateInputs, validateInputs_fn).call(this);
|
|
984
|
-
attachFloorPriceRuleTx(
|
|
985
|
-
this.transactionBlock,
|
|
986
|
-
this.type,
|
|
987
|
-
this.policy,
|
|
988
|
-
this.policyCap,
|
|
989
|
-
minPrice,
|
|
990
|
-
this.kioskClient.getRulePackageId("floorPriceRulePackageId")
|
|
991
|
-
);
|
|
992
|
-
return this;
|
|
993
|
-
}
|
|
994
|
-
/**
|
|
995
|
-
* Generic helper to remove a rule, not from the SDK's base ruleset.
|
|
996
|
-
* @param ruleType The Rule Type
|
|
997
|
-
* @param configType The Config Type
|
|
998
|
-
*/
|
|
999
|
-
removeRule({ ruleType, configType }) {
|
|
1000
|
-
__privateMethod(this, _validateInputs, validateInputs_fn).call(this);
|
|
1001
|
-
removeTransferPolicyRule(
|
|
1002
|
-
this.transactionBlock,
|
|
1003
|
-
this.type,
|
|
1004
|
-
ruleType,
|
|
1005
|
-
configType,
|
|
1006
|
-
this.policy,
|
|
1007
|
-
this.policyCap
|
|
1008
|
-
);
|
|
1009
|
-
}
|
|
1010
|
-
/**
|
|
1011
|
-
* Removes the lock rule.
|
|
1012
|
-
*/
|
|
1013
|
-
removeLockRule() {
|
|
1014
|
-
__privateMethod(this, _validateInputs, validateInputs_fn).call(this);
|
|
1015
|
-
const packageId = this.kioskClient.getRulePackageId("kioskLockRulePackageId");
|
|
1016
|
-
removeTransferPolicyRule(
|
|
1017
|
-
this.transactionBlock,
|
|
1018
|
-
this.type,
|
|
1019
|
-
`${packageId}::kiosk_lock_rule::Rule`,
|
|
1020
|
-
`${packageId}::kiosk_lock_rule::Config`,
|
|
1021
|
-
this.policy,
|
|
1022
|
-
this.policyCap
|
|
1023
|
-
);
|
|
1024
|
-
return this;
|
|
1025
|
-
}
|
|
1026
|
-
/**
|
|
1027
|
-
* Removes the Royalty rule
|
|
1028
|
-
*/
|
|
1029
|
-
removeRoyaltyRule() {
|
|
1030
|
-
__privateMethod(this, _validateInputs, validateInputs_fn).call(this);
|
|
1031
|
-
const packageId = this.kioskClient.getRulePackageId("royaltyRulePackageId");
|
|
1032
|
-
removeTransferPolicyRule(
|
|
1033
|
-
this.transactionBlock,
|
|
1034
|
-
this.type,
|
|
1035
|
-
`${packageId}::royalty_rule::Rule`,
|
|
1036
|
-
`${packageId}::royalty_rule::Config`,
|
|
1037
|
-
this.policy,
|
|
1038
|
-
this.policyCap
|
|
1039
|
-
);
|
|
1040
|
-
return this;
|
|
1041
|
-
}
|
|
1042
|
-
removePersonalKioskRule() {
|
|
1043
|
-
__privateMethod(this, _validateInputs, validateInputs_fn).call(this);
|
|
1044
|
-
const packageId = this.kioskClient.getRulePackageId("personalKioskRulePackageId");
|
|
1045
|
-
removeTransferPolicyRule(
|
|
1046
|
-
this.transactionBlock,
|
|
1047
|
-
this.type,
|
|
1048
|
-
`${packageId}::personal_kiosk_rule::Rule`,
|
|
1049
|
-
`bool`,
|
|
1050
|
-
this.policy,
|
|
1051
|
-
this.policyCap
|
|
1052
|
-
);
|
|
1053
|
-
return this;
|
|
1054
|
-
}
|
|
1055
|
-
removeFloorPriceRule() {
|
|
1056
|
-
__privateMethod(this, _validateInputs, validateInputs_fn).call(this);
|
|
1057
|
-
const packageId = this.kioskClient.getRulePackageId("floorPriceRulePackageId");
|
|
1058
|
-
removeTransferPolicyRule(
|
|
1059
|
-
this.transactionBlock,
|
|
1060
|
-
this.type,
|
|
1061
|
-
`${packageId}::floor_price_rule::Rule`,
|
|
1062
|
-
`${packageId}::floor_price_rule::Config`,
|
|
1063
|
-
this.policy,
|
|
1064
|
-
this.policyCap
|
|
1065
|
-
);
|
|
1066
|
-
return this;
|
|
1067
|
-
}
|
|
1068
|
-
getPolicy() {
|
|
1069
|
-
if (!this.policy)
|
|
1070
|
-
throw new Error("Policy not set.");
|
|
1071
|
-
return this.policy;
|
|
1072
|
-
}
|
|
1073
|
-
getPolicyCap() {
|
|
1074
|
-
if (!this.policyCap)
|
|
1075
|
-
throw new Error("Transfer Policy Cap not set.");
|
|
1076
|
-
return this.policyCap;
|
|
1077
|
-
}
|
|
1078
|
-
};
|
|
1079
|
-
_validateInputs = new WeakSet();
|
|
1080
|
-
validateInputs_fn = function() {
|
|
1081
|
-
const genericErrorMessage = `Please use 'setCap()' to setup the TransferPolicy.`;
|
|
1082
|
-
if (!this.policy)
|
|
1083
|
-
throw new Error(`${genericErrorMessage} Missing: Transfer Policy Object.`);
|
|
1084
|
-
if (!this.policyCap)
|
|
1085
|
-
throw new Error(`${genericErrorMessage} Missing: TransferPolicyCap Object ID`);
|
|
1086
|
-
if (!this.type)
|
|
1087
|
-
throw new Error(
|
|
1088
|
-
`${genericErrorMessage} Missing: Transfer Policy object type (e.g. {packageId}::item::Item)`
|
|
1089
|
-
);
|
|
1090
|
-
};
|
|
1091
|
-
_setup = new WeakSet();
|
|
1092
|
-
setup_fn = function(policyId, policyCap, type) {
|
|
1093
|
-
this.policy = policyId;
|
|
1094
|
-
this.policyCap = policyCap;
|
|
1095
|
-
this.type = type;
|
|
1096
|
-
return this;
|
|
1097
|
-
};
|
|
1098
|
-
|
|
1099
|
-
// src/tx/personal-kiosk.ts
|
|
1100
|
-
function convertToPersonalTx(tx, kiosk, kioskOwnerCap, packageId) {
|
|
1101
|
-
const personalKioskCap = tx.moveCall({
|
|
1102
|
-
target: `${packageId}::personal_kiosk::new`,
|
|
1103
|
-
arguments: [tx.object(kiosk), tx.object(kioskOwnerCap)]
|
|
1104
|
-
});
|
|
1105
|
-
return personalKioskCap;
|
|
1106
|
-
}
|
|
1107
|
-
function transferPersonalCapTx(tx, personalKioskCap, packageId) {
|
|
1108
|
-
tx.moveCall({
|
|
1109
|
-
target: `${packageId}::personal_kiosk::transfer_to_sender`,
|
|
1110
|
-
arguments: [personalKioskCap]
|
|
1111
|
-
});
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
// src/client/kiosk-transaction.ts
|
|
1115
|
-
var _pendingShare, _pendingTransfer, _promise, _personalCap, _finalized, _borrowFromPersonalCap, borrowFromPersonalCap_fn, _setPendingStatuses, setPendingStatuses_fn, _validateKioskIsSet, validateKioskIsSet_fn, _validateFinalizedStatus, validateFinalizedStatus_fn;
|
|
1116
|
-
var KioskTransaction = class {
|
|
1117
|
-
constructor({ transactionBlock, kioskClient, cap }) {
|
|
1118
|
-
/**
|
|
1119
|
-
* A function to borrow from `personalCap`.
|
|
1120
|
-
*/
|
|
1121
|
-
__privateAdd(this, _borrowFromPersonalCap);
|
|
1122
|
-
__privateAdd(this, _setPendingStatuses);
|
|
1123
|
-
__privateAdd(this, _validateKioskIsSet);
|
|
1124
|
-
// Validates that `finalize`
|
|
1125
|
-
__privateAdd(this, _validateFinalizedStatus);
|
|
1126
|
-
// If we're pending `share` of a new kiosk, `finalize()` will share it.
|
|
1127
|
-
__privateAdd(this, _pendingShare, void 0);
|
|
1128
|
-
// If we're pending transferring of the cap, `finalize()` will either error or transfer the cap if it's a new personal.
|
|
1129
|
-
__privateAdd(this, _pendingTransfer, void 0);
|
|
1130
|
-
// The promise that the personalCap will be returned on `finalize()`.
|
|
1131
|
-
__privateAdd(this, _promise, void 0);
|
|
1132
|
-
// The personal kiosk argument.
|
|
1133
|
-
__privateAdd(this, _personalCap, void 0);
|
|
1134
|
-
// A flag that checks whether kiosk TX is finalized.
|
|
1135
|
-
__privateAdd(this, _finalized, false);
|
|
1136
|
-
this.transactionBlock = transactionBlock;
|
|
1137
|
-
this.kioskClient = kioskClient;
|
|
1138
|
-
if (cap)
|
|
1139
|
-
this.setCap(cap);
|
|
1140
|
-
}
|
|
1141
|
-
/**
|
|
1142
|
-
* Creates a kiosk and saves `kiosk` and `kioskOwnerCap` in state.
|
|
1143
|
-
* Helpful if we want to chain some actions before sharing + transferring the cap to the specified address.
|
|
1144
|
-
* @param borrow If true, the `kioskOwnerCap` is borrowed from the `PersonalKioskCap` to be used in next transactions.
|
|
1145
|
-
*/
|
|
1146
|
-
create() {
|
|
1147
|
-
__privateMethod(this, _validateFinalizedStatus, validateFinalizedStatus_fn).call(this);
|
|
1148
|
-
__privateMethod(this, _setPendingStatuses, setPendingStatuses_fn).call(this, {
|
|
1149
|
-
share: true,
|
|
1150
|
-
transfer: true
|
|
1151
|
-
});
|
|
1152
|
-
const [kiosk, cap] = createKiosk(this.transactionBlock);
|
|
1153
|
-
this.kiosk = kiosk;
|
|
1154
|
-
this.kioskCap = cap;
|
|
1155
|
-
return this;
|
|
1156
|
-
}
|
|
1157
|
-
/**
|
|
1158
|
-
* Creates a personal kiosk & shares it.
|
|
1159
|
-
* The `PersonalKioskCap` is transferred to the signer.
|
|
1160
|
-
* @param borrow If true, the `kioskOwnerCap` is borrowed from the `PersonalKioskCap` to be used in next transactions.
|
|
1161
|
-
*/
|
|
1162
|
-
createPersonal(borrow) {
|
|
1163
|
-
__privateSet(this, _pendingShare, true);
|
|
1164
|
-
return this.create().convertToPersonal(borrow);
|
|
1165
|
-
}
|
|
1166
|
-
/**
|
|
1167
|
-
* Converts a kiosk to a Personal (Soulbound) Kiosk.
|
|
1168
|
-
* Requires initialization by either calling `ktxb.create()` or `ktxb.setCap()`.
|
|
1169
|
-
*/
|
|
1170
|
-
convertToPersonal(borrow) {
|
|
1171
|
-
__privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
|
|
1172
|
-
const cap = convertToPersonalTx(
|
|
1173
|
-
this.transactionBlock,
|
|
1174
|
-
this.kiosk,
|
|
1175
|
-
this.kioskCap,
|
|
1176
|
-
this.kioskClient.getRulePackageId("personalKioskRulePackageId")
|
|
1177
|
-
);
|
|
1178
|
-
if (borrow)
|
|
1179
|
-
__privateMethod(this, _borrowFromPersonalCap, borrowFromPersonalCap_fn).call(this, cap);
|
|
1180
|
-
else
|
|
1181
|
-
__privateSet(this, _personalCap, cap);
|
|
1182
|
-
__privateMethod(this, _setPendingStatuses, setPendingStatuses_fn).call(this, { transfer: true });
|
|
1183
|
-
return this;
|
|
1184
|
-
}
|
|
1185
|
-
/**
|
|
1186
|
-
* Single function way to create a kiosk, share it and transfer the cap to the specified address.
|
|
1187
|
-
*/
|
|
1188
|
-
createAndShare(address) {
|
|
1189
|
-
__privateMethod(this, _validateFinalizedStatus, validateFinalizedStatus_fn).call(this);
|
|
1190
|
-
const cap = createKioskAndShare(this.transactionBlock);
|
|
1191
|
-
this.transactionBlock.transferObjects([cap], this.transactionBlock.pure.address(address));
|
|
1192
|
-
}
|
|
1193
|
-
/**
|
|
1194
|
-
* Shares the kiosk.
|
|
1195
|
-
*/
|
|
1196
|
-
share() {
|
|
1197
|
-
__privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
|
|
1198
|
-
__privateMethod(this, _setPendingStatuses, setPendingStatuses_fn).call(this, { share: false });
|
|
1199
|
-
shareKiosk(this.transactionBlock, this.kiosk);
|
|
1200
|
-
}
|
|
1201
|
-
/**
|
|
1202
|
-
* Should be called only after `create` is called.
|
|
1203
|
-
* It shares the kiosk & transfers the cap to the specified address.
|
|
1204
|
-
*/
|
|
1205
|
-
shareAndTransferCap(address) {
|
|
1206
|
-
if (__privateGet(this, _personalCap))
|
|
1207
|
-
throw new Error("You can only call `shareAndTransferCap` on a non-personal kiosk.");
|
|
1208
|
-
__privateMethod(this, _setPendingStatuses, setPendingStatuses_fn).call(this, { transfer: false });
|
|
1209
|
-
this.share();
|
|
1210
|
-
this.transactionBlock.transferObjects(
|
|
1211
|
-
[this.kioskCap],
|
|
1212
|
-
this.transactionBlock.pure.address(address)
|
|
1213
|
-
);
|
|
1214
|
-
}
|
|
1215
|
-
/**
|
|
1216
|
-
* A function to borrow an item from a kiosk & execute any function with it.
|
|
1217
|
-
* Example: You could borrow a Fren out of a kiosk, attach an accessory (or mix), and return it.
|
|
1218
|
-
*/
|
|
1219
|
-
borrowTx({ itemType, itemId }, callback) {
|
|
1220
|
-
__privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
|
|
1221
|
-
const [itemObj, promise] = borrowValue(
|
|
1222
|
-
this.transactionBlock,
|
|
1223
|
-
itemType,
|
|
1224
|
-
this.kiosk,
|
|
1225
|
-
this.kioskCap,
|
|
1226
|
-
itemId
|
|
1227
|
-
);
|
|
1228
|
-
callback(itemObj);
|
|
1229
|
-
this.return({ itemType, item: itemObj, promise });
|
|
1230
|
-
}
|
|
1231
|
-
/**
|
|
1232
|
-
* Borrows an item from the kiosk.
|
|
1233
|
-
* This will fail if the item is listed for sale.
|
|
1234
|
-
*
|
|
1235
|
-
* Requires calling `return`.
|
|
1236
|
-
*/
|
|
1237
|
-
borrow({ itemType, itemId }) {
|
|
1238
|
-
__privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
|
|
1239
|
-
const [itemObj, promise] = borrowValue(
|
|
1240
|
-
this.transactionBlock,
|
|
1241
|
-
itemType,
|
|
1242
|
-
this.kiosk,
|
|
1243
|
-
this.kioskCap,
|
|
1244
|
-
itemId
|
|
1245
|
-
);
|
|
1246
|
-
return [itemObj, promise];
|
|
1247
|
-
}
|
|
1248
|
-
/**
|
|
1249
|
-
* Returns the item back to the kiosk.
|
|
1250
|
-
* Accepts the parameters returned from the `borrow` function.
|
|
1251
|
-
*/
|
|
1252
|
-
return({ itemType, item, promise }) {
|
|
1253
|
-
__privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
|
|
1254
|
-
returnValue(this.transactionBlock, itemType, this.kiosk, item, promise);
|
|
1255
|
-
return this;
|
|
1256
|
-
}
|
|
1257
|
-
/**
|
|
1258
|
-
* A function to withdraw from kiosk
|
|
1259
|
-
* @param address Where to trasnfer the coin.
|
|
1260
|
-
* @param amount The amount we aim to withdraw.
|
|
1261
|
-
*/
|
|
1262
|
-
withdraw(address, amount) {
|
|
1263
|
-
__privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
|
|
1264
|
-
const coin = withdrawFromKiosk(
|
|
1265
|
-
this.transactionBlock,
|
|
1266
|
-
this.kiosk,
|
|
1267
|
-
this.kioskCap,
|
|
1268
|
-
amount
|
|
1269
|
-
);
|
|
1270
|
-
this.transactionBlock.transferObjects([coin], this.transactionBlock.pure.address(address));
|
|
1271
|
-
return this;
|
|
1272
|
-
}
|
|
1273
|
-
/**
|
|
1274
|
-
* A function to place an item in the kiosk.
|
|
1275
|
-
* @param itemType The type `T` of the item
|
|
1276
|
-
* @param item The ID or Transaction Argument of the item
|
|
1277
|
-
*/
|
|
1278
|
-
place({ itemType, item }) {
|
|
1279
|
-
__privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
|
|
1280
|
-
place(this.transactionBlock, itemType, this.kiosk, this.kioskCap, item);
|
|
1281
|
-
return this;
|
|
1282
|
-
}
|
|
1283
|
-
/**
|
|
1284
|
-
* A function to place an item in the kiosk and list it for sale in one transaction.
|
|
1285
|
-
* @param itemType The type `T` of the item
|
|
1286
|
-
* @param item The ID or Transaction Argument of the item
|
|
1287
|
-
* @param price The price in MIST
|
|
1288
|
-
*/
|
|
1289
|
-
placeAndList({ itemType, item, price }) {
|
|
1290
|
-
__privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
|
|
1291
|
-
placeAndList(this.transactionBlock, itemType, this.kiosk, this.kioskCap, item, price);
|
|
1292
|
-
return this;
|
|
1293
|
-
}
|
|
1294
|
-
/**
|
|
1295
|
-
* A function to list an item in the kiosk.
|
|
1296
|
-
* @param itemType The type `T` of the item
|
|
1297
|
-
* @param itemId The ID of the item
|
|
1298
|
-
* @param price The price in MIST
|
|
1299
|
-
*/
|
|
1300
|
-
list({ itemType, itemId, price }) {
|
|
1301
|
-
__privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
|
|
1302
|
-
list(this.transactionBlock, itemType, this.kiosk, this.kioskCap, itemId, price);
|
|
1303
|
-
return this;
|
|
1304
|
-
}
|
|
1305
|
-
/**
|
|
1306
|
-
* A function to delist an item from the kiosk.
|
|
1307
|
-
* @param itemType The type `T` of the item
|
|
1308
|
-
* @param itemId The ID of the item
|
|
1309
|
-
*/
|
|
1310
|
-
delist({ itemType, itemId }) {
|
|
1311
|
-
__privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
|
|
1312
|
-
delist(this.transactionBlock, itemType, this.kiosk, this.kioskCap, itemId);
|
|
1313
|
-
return this;
|
|
1314
|
-
}
|
|
1315
|
-
/**
|
|
1316
|
-
* A function to take an item from the kiosk. The transaction won't succeed if the item is listed or locked.
|
|
1317
|
-
|
|
1318
|
-
* @param itemType The type `T` of the item
|
|
1319
|
-
* @param itemId The ID of the item
|
|
1320
|
-
*/
|
|
1321
|
-
take({ itemType, itemId }) {
|
|
1322
|
-
__privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
|
|
1323
|
-
return take(this.transactionBlock, itemType, this.kiosk, this.kioskCap, itemId);
|
|
1324
|
-
}
|
|
1325
|
-
/**
|
|
1326
|
-
* Transfer a non-locked/non-listed item to an address.
|
|
1327
|
-
*
|
|
1328
|
-
* @param itemType The type `T` of the item
|
|
1329
|
-
* @param itemId The ID of the item
|
|
1330
|
-
* @param address The destination address
|
|
1331
|
-
*/
|
|
1332
|
-
transfer({ itemType, itemId, address }) {
|
|
1333
|
-
__privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
|
|
1334
|
-
const item = this.take({ itemType, itemId });
|
|
1335
|
-
this.transactionBlock.transferObjects([item], this.transactionBlock.pure.address(address));
|
|
1336
|
-
return this;
|
|
1337
|
-
}
|
|
1338
|
-
/**
|
|
1339
|
-
* A function to take lock an item in the kiosk.
|
|
1340
|
-
|
|
1341
|
-
* @param itemType The type `T` of the item
|
|
1342
|
-
* @param itemId The ID of the item
|
|
1343
|
-
* @param policy The Policy ID or Transaction Argument for item T
|
|
1344
|
-
*/
|
|
1345
|
-
lock({ itemType, itemId, policy }) {
|
|
1346
|
-
__privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
|
|
1347
|
-
lock(this.transactionBlock, itemType, this.kiosk, this.kioskCap, policy, itemId);
|
|
1348
|
-
return this;
|
|
1349
|
-
}
|
|
1350
|
-
/**
|
|
1351
|
-
* Purchase an item from a seller's kiosk.
|
|
1352
|
-
* Returns [item, transferRequest]
|
|
1353
|
-
* Can be called like: `const [item, transferRequest] = kioskTx.purchase({...})`
|
|
1354
|
-
* @param itemType The type `T` of the item
|
|
1355
|
-
* @param itemId The ID of the item
|
|
1356
|
-
* @param price The price in MIST
|
|
1357
|
-
* @param sellerKiosk The kiosk which is selling the item. Can be an id or an object argument.
|
|
1358
|
-
*/
|
|
1359
|
-
purchase({
|
|
1360
|
-
itemType,
|
|
1361
|
-
itemId,
|
|
1362
|
-
price,
|
|
1363
|
-
sellerKiosk
|
|
1364
|
-
}) {
|
|
1365
|
-
const coin = this.transactionBlock.splitCoins(this.transactionBlock.gas, [
|
|
1366
|
-
this.transactionBlock.pure.u64(price)
|
|
1367
|
-
]);
|
|
1368
|
-
return purchase(this.transactionBlock, itemType, sellerKiosk, itemId, coin);
|
|
1369
|
-
}
|
|
1370
|
-
/**
|
|
1371
|
-
* A function to purchase and resolve a transfer policy.
|
|
1372
|
-
* If the transfer policy has the `lock` rule, the item is locked in the kiosk.
|
|
1373
|
-
* Otherwise, the item is placed in the kiosk.
|
|
1374
|
-
* @param itemType The type of the item
|
|
1375
|
-
* @param itemId The id of the item
|
|
1376
|
-
* @param price The price of the specified item
|
|
1377
|
-
* @param sellerKiosk The kiosk which is selling the item. Can be an id or an object argument.
|
|
1378
|
-
* @param extraArgs Used to pass arguments for custom rule resolvers.
|
|
1379
|
-
*/
|
|
1380
|
-
async purchaseAndResolve({
|
|
1381
|
-
itemType,
|
|
1382
|
-
itemId,
|
|
1383
|
-
price,
|
|
1384
|
-
sellerKiosk,
|
|
1385
|
-
extraArgs
|
|
1386
|
-
}) {
|
|
1387
|
-
__privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
|
|
1388
|
-
const policies = await this.kioskClient.getTransferPolicies({ type: itemType });
|
|
1389
|
-
if (policies.length === 0) {
|
|
1390
|
-
throw new Error(
|
|
1391
|
-
`The type ${itemType} doesn't have a Transfer Policy so it can't be traded through kiosk.`
|
|
1392
|
-
);
|
|
1393
|
-
}
|
|
1394
|
-
const policy = policies[0];
|
|
1395
|
-
const [purchasedItem, transferRequest] = this.purchase({
|
|
1396
|
-
itemType,
|
|
1397
|
-
itemId,
|
|
1398
|
-
price,
|
|
1399
|
-
sellerKiosk
|
|
1400
|
-
});
|
|
1401
|
-
let canTransferOutsideKiosk = true;
|
|
1402
|
-
for (const rule of policy.rules) {
|
|
1403
|
-
const ruleDefinition = this.kioskClient.rules.find(
|
|
1404
|
-
(x) => getNormalizedRuleType(x.rule) === getNormalizedRuleType(rule)
|
|
1405
|
-
);
|
|
1406
|
-
if (!ruleDefinition)
|
|
1407
|
-
throw new Error(`No resolver for the following rule: ${rule}.`);
|
|
1408
|
-
if (ruleDefinition.hasLockingRule)
|
|
1409
|
-
canTransferOutsideKiosk = false;
|
|
1410
|
-
ruleDefinition.resolveRuleFunction({
|
|
1411
|
-
packageId: ruleDefinition.packageId,
|
|
1412
|
-
transactionBlock: this.transactionBlock,
|
|
1413
|
-
itemType,
|
|
1414
|
-
itemId,
|
|
1415
|
-
price: price.toString(),
|
|
1416
|
-
sellerKiosk,
|
|
1417
|
-
policyId: policy.id,
|
|
1418
|
-
transferRequest,
|
|
1419
|
-
purchasedItem,
|
|
1420
|
-
kiosk: this.kiosk,
|
|
1421
|
-
kioskCap: this.kioskCap,
|
|
1422
|
-
extraArgs: extraArgs || {}
|
|
1423
|
-
});
|
|
1424
|
-
}
|
|
1425
|
-
confirmRequest(this.transactionBlock, itemType, policy.id, transferRequest);
|
|
1426
|
-
if (canTransferOutsideKiosk)
|
|
1427
|
-
this.place({ itemType, item: purchasedItem });
|
|
1428
|
-
return this;
|
|
1429
|
-
}
|
|
1430
|
-
/**
|
|
1431
|
-
* A function to setup the client using an existing `ownerCap`,
|
|
1432
|
-
* as return from the `kioskClient.getOwnedKiosks` function.
|
|
1433
|
-
* @param cap `KioskOwnerCap` object as returned from `getOwnedKiosks` SDK call.
|
|
1434
|
-
*/
|
|
1435
|
-
setCap(cap) {
|
|
1436
|
-
__privateMethod(this, _validateFinalizedStatus, validateFinalizedStatus_fn).call(this);
|
|
1437
|
-
this.kiosk = this.transactionBlock.object(cap.kioskId);
|
|
1438
|
-
if (!cap.isPersonal) {
|
|
1439
|
-
this.kioskCap = this.transactionBlock.object(cap.objectId);
|
|
1440
|
-
return;
|
|
1441
|
-
}
|
|
1442
|
-
return __privateMethod(this, _borrowFromPersonalCap, borrowFromPersonalCap_fn).call(this, cap.objectId);
|
|
1443
|
-
}
|
|
1444
|
-
/**
|
|
1445
|
-
* A function that ends up the kiosk building txb & returns the `kioskOwnerCap` back to the
|
|
1446
|
-
* `PersonalKioskCap`, in case we are operating on a personal kiosk.
|
|
1447
|
-
* It will also share the `kiosk` if it's not shared, and finalize the transfer of the personal cap if it's pending.
|
|
1448
|
-
*/
|
|
1449
|
-
finalize() {
|
|
1450
|
-
__privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
|
|
1451
|
-
if (__privateGet(this, _pendingShare))
|
|
1452
|
-
this.share();
|
|
1453
|
-
if (!__privateGet(this, _personalCap)) {
|
|
1454
|
-
if (__privateGet(this, _pendingTransfer))
|
|
1455
|
-
throw new Error(
|
|
1456
|
-
"You need to transfer the `kioskOwnerCap` by calling `shareAndTransferCap()` before wrap"
|
|
1457
|
-
);
|
|
1458
|
-
return;
|
|
1459
|
-
}
|
|
1460
|
-
const packageId = this.kioskClient.getRulePackageId("personalKioskRulePackageId");
|
|
1461
|
-
if (__privateGet(this, _promise)) {
|
|
1462
|
-
this.transactionBlock.moveCall({
|
|
1463
|
-
target: `${packageId}::personal_kiosk::return_val`,
|
|
1464
|
-
arguments: [
|
|
1465
|
-
__privateGet(this, _personalCap),
|
|
1466
|
-
this.transactionBlock.object(this.kioskCap),
|
|
1467
|
-
__privateGet(this, _promise)
|
|
1468
|
-
]
|
|
1469
|
-
});
|
|
1470
|
-
}
|
|
1471
|
-
if (__privateGet(this, _pendingTransfer))
|
|
1472
|
-
transferPersonalCapTx(this.transactionBlock, __privateGet(this, _personalCap), packageId);
|
|
1473
|
-
__privateSet(this, _finalized, true);
|
|
1474
|
-
}
|
|
1475
|
-
// Some setters in case we want custom behavior.
|
|
1476
|
-
setKioskCap(cap) {
|
|
1477
|
-
__privateMethod(this, _validateFinalizedStatus, validateFinalizedStatus_fn).call(this);
|
|
1478
|
-
this.kioskCap = cap;
|
|
1479
|
-
return this;
|
|
1480
|
-
}
|
|
1481
|
-
setKiosk(kiosk) {
|
|
1482
|
-
__privateMethod(this, _validateFinalizedStatus, validateFinalizedStatus_fn).call(this);
|
|
1483
|
-
this.kiosk = kiosk;
|
|
1484
|
-
return this;
|
|
1485
|
-
}
|
|
1486
|
-
// Some getters
|
|
1487
|
-
/*
|
|
1488
|
-
* Returns the active transaction's kiosk, or undefined if `setCap` or `create()` hasn't been called yet.
|
|
1489
|
-
*/
|
|
1490
|
-
getKiosk() {
|
|
1491
|
-
__privateMethod(this, _validateFinalizedStatus, validateFinalizedStatus_fn).call(this);
|
|
1492
|
-
if (!this.kiosk)
|
|
1493
|
-
throw new Error("Kiosk is not set.");
|
|
1494
|
-
return this.kiosk;
|
|
1495
|
-
}
|
|
1496
|
-
/*
|
|
1497
|
-
* Returns the active transaction's kioskOwnerCap, or undefined if `setCap` or `create()` hasn't been called yet.
|
|
1498
|
-
*/
|
|
1499
|
-
getKioskCap() {
|
|
1500
|
-
__privateMethod(this, _validateFinalizedStatus, validateFinalizedStatus_fn).call(this);
|
|
1501
|
-
if (!this.kioskCap)
|
|
1502
|
-
throw new Error("Kiosk cap is not set");
|
|
1503
|
-
return this.kioskCap;
|
|
1504
|
-
}
|
|
1505
|
-
};
|
|
1506
|
-
_pendingShare = new WeakMap();
|
|
1507
|
-
_pendingTransfer = new WeakMap();
|
|
1508
|
-
_promise = new WeakMap();
|
|
1509
|
-
_personalCap = new WeakMap();
|
|
1510
|
-
_finalized = new WeakMap();
|
|
1511
|
-
_borrowFromPersonalCap = new WeakSet();
|
|
1512
|
-
borrowFromPersonalCap_fn = function(personalCap) {
|
|
1513
|
-
const [kioskCap, promise] = this.transactionBlock.moveCall({
|
|
1514
|
-
target: `${this.kioskClient.getRulePackageId(
|
|
1515
|
-
"personalKioskRulePackageId"
|
|
1516
|
-
)}::personal_kiosk::borrow_val`,
|
|
1517
|
-
arguments: [this.transactionBlock.object(personalCap)]
|
|
1518
|
-
});
|
|
1519
|
-
this.kioskCap = kioskCap;
|
|
1520
|
-
__privateSet(this, _personalCap, this.transactionBlock.object(personalCap));
|
|
1521
|
-
__privateSet(this, _promise, promise);
|
|
1522
|
-
return this;
|
|
1523
|
-
};
|
|
1524
|
-
_setPendingStatuses = new WeakSet();
|
|
1525
|
-
setPendingStatuses_fn = function({ share, transfer }) {
|
|
1526
|
-
if (transfer !== void 0)
|
|
1527
|
-
__privateSet(this, _pendingTransfer, transfer);
|
|
1528
|
-
if (share !== void 0)
|
|
1529
|
-
__privateSet(this, _pendingShare, share);
|
|
1530
|
-
};
|
|
1531
|
-
_validateKioskIsSet = new WeakSet();
|
|
1532
|
-
validateKioskIsSet_fn = function() {
|
|
1533
|
-
__privateMethod(this, _validateFinalizedStatus, validateFinalizedStatus_fn).call(this);
|
|
1534
|
-
if (!this.kiosk || !this.kioskCap)
|
|
1535
|
-
throw new Error(
|
|
1536
|
-
"You need to initialize the client by either supplying an existing owner cap or by creating a new by calling `.create()`"
|
|
1537
|
-
);
|
|
1538
|
-
};
|
|
1539
|
-
_validateFinalizedStatus = new WeakSet();
|
|
1540
|
-
validateFinalizedStatus_fn = function() {
|
|
1541
|
-
if (__privateGet(this, _finalized))
|
|
1542
|
-
throw new Error("You can't add more transactions to a finalized kiosk transaction block.");
|
|
1543
|
-
};
|
|
1544
|
-
export {
|
|
1545
|
-
FLOOR_PRICE_RULE_ADDRESS,
|
|
1546
|
-
KIOSK_ITEM,
|
|
1547
|
-
KIOSK_LISTING,
|
|
1548
|
-
KIOSK_LOCK,
|
|
1549
|
-
KIOSK_LOCK_RULE,
|
|
1550
|
-
KIOSK_LOCK_RULE_ADDRESS,
|
|
1551
|
-
KIOSK_MODULE,
|
|
1552
|
-
KIOSK_OWNER_CAP,
|
|
1553
|
-
KIOSK_PURCHASE_CAP,
|
|
1554
|
-
KIOSK_TYPE,
|
|
1555
|
-
KioskClient,
|
|
1556
|
-
KioskTransaction,
|
|
1557
|
-
Network,
|
|
1558
|
-
PERSONAL_KIOSK_RULE_ADDRESS,
|
|
1559
|
-
ROYALTY_RULE,
|
|
1560
|
-
ROYALTY_RULE_ADDRESS,
|
|
1561
|
-
TRANSFER_POLICY_CAP_TYPE,
|
|
1562
|
-
TRANSFER_POLICY_CREATED_EVENT,
|
|
1563
|
-
TRANSFER_POLICY_MODULE,
|
|
1564
|
-
TRANSFER_POLICY_TYPE,
|
|
1565
|
-
TransferPolicyTransaction,
|
|
1566
|
-
attachListingsAndPrices,
|
|
1567
|
-
attachLockedItems,
|
|
1568
|
-
attachObjects,
|
|
1569
|
-
extractKioskData,
|
|
1570
|
-
getAllDynamicFields,
|
|
1571
|
-
getAllObjects,
|
|
1572
|
-
getAllOwnedObjects,
|
|
1573
|
-
getBaseRules,
|
|
1574
|
-
getKioskObject,
|
|
1575
|
-
getNormalizedRuleType,
|
|
1576
|
-
mainnetRules,
|
|
1577
|
-
parseTransferPolicyCapObject,
|
|
1578
|
-
percentageToBasisPoints,
|
|
1579
|
-
rules,
|
|
1580
|
-
testnetRules
|
|
1581
|
-
};
|
|
1582
|
-
//# sourceMappingURL=index.mjs.map
|