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