@mysten/kiosk 0.8.10 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/cjs/bcs.d.ts +40 -2
- package/dist/cjs/bcs.js +22 -19
- package/dist/cjs/bcs.js.map +2 -2
- package/dist/cjs/client/kiosk-client.d.ts +1 -1
- package/dist/cjs/client/kiosk-client.js.map +1 -1
- package/dist/cjs/client/kiosk-transaction.d.ts +8 -6
- package/dist/cjs/client/kiosk-transaction.js +41 -54
- package/dist/cjs/client/kiosk-transaction.js.map +2 -2
- package/dist/cjs/client/tp-transaction.d.ts +6 -4
- package/dist/cjs/client/tp-transaction.js +24 -19
- package/dist/cjs/client/tp-transaction.js.map +2 -2
- package/dist/cjs/query/kiosk.d.ts +1 -1
- package/dist/cjs/query/kiosk.js +1 -1
- package/dist/cjs/query/kiosk.js.map +1 -1
- package/dist/cjs/query/transfer-policy.d.ts +2 -1
- package/dist/cjs/query/transfer-policy.js +3 -2
- package/dist/cjs/query/transfer-policy.js.map +3 -3
- package/dist/cjs/tx/kiosk.d.ts +14 -14
- package/dist/cjs/tx/kiosk.js +1 -1
- package/dist/cjs/tx/kiosk.js.map +2 -2
- package/dist/cjs/tx/personal-kiosk.d.ts +3 -3
- package/dist/cjs/tx/personal-kiosk.js.map +1 -1
- package/dist/cjs/tx/rules/attach.d.ts +5 -5
- package/dist/cjs/tx/rules/attach.js.map +1 -1
- package/dist/cjs/tx/rules/resolve.js +16 -16
- package/dist/cjs/tx/rules/resolve.js.map +2 -2
- package/dist/cjs/tx/transfer-policy.d.ts +7 -7
- package/dist/cjs/tx/transfer-policy.js +1 -1
- package/dist/cjs/tx/transfer-policy.js.map +1 -1
- package/dist/cjs/types/index.d.ts +2 -2
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/types/kiosk.d.ts +2 -2
- package/dist/cjs/types/kiosk.js.map +1 -1
- package/dist/cjs/types/transfer-policy.d.ts +5 -3
- package/dist/cjs/types/transfer-policy.js.map +1 -1
- package/dist/cjs/utils.d.ts +1 -1
- package/dist/cjs/utils.js +2 -2
- package/dist/cjs/utils.js.map +2 -2
- package/dist/esm/bcs.d.ts +40 -2
- package/dist/esm/bcs.js +22 -19
- package/dist/esm/bcs.js.map +2 -2
- package/dist/esm/client/kiosk-client.d.ts +1 -1
- package/dist/esm/client/kiosk-client.js.map +1 -1
- package/dist/esm/client/kiosk-transaction.d.ts +8 -6
- package/dist/esm/client/kiosk-transaction.js +41 -54
- package/dist/esm/client/kiosk-transaction.js.map +2 -2
- package/dist/esm/client/tp-transaction.d.ts +6 -4
- package/dist/esm/client/tp-transaction.js +24 -19
- package/dist/esm/client/tp-transaction.js.map +2 -2
- package/dist/esm/query/kiosk.d.ts +1 -1
- package/dist/esm/query/kiosk.js +1 -1
- package/dist/esm/query/kiosk.js.map +1 -1
- package/dist/esm/query/transfer-policy.d.ts +2 -1
- package/dist/esm/query/transfer-policy.js +4 -3
- package/dist/esm/query/transfer-policy.js.map +2 -2
- package/dist/esm/tx/kiosk.d.ts +14 -14
- package/dist/esm/tx/kiosk.js +1 -1
- package/dist/esm/tx/kiosk.js.map +2 -2
- package/dist/esm/tx/personal-kiosk.d.ts +3 -3
- package/dist/esm/tx/personal-kiosk.js.map +1 -1
- package/dist/esm/tx/rules/attach.d.ts +5 -5
- package/dist/esm/tx/rules/attach.js.map +1 -1
- package/dist/esm/tx/rules/resolve.js +16 -16
- package/dist/esm/tx/rules/resolve.js.map +2 -2
- package/dist/esm/tx/transfer-policy.d.ts +7 -7
- package/dist/esm/tx/transfer-policy.js +1 -1
- package/dist/esm/tx/transfer-policy.js.map +1 -1
- package/dist/esm/types/index.d.ts +2 -2
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm/types/kiosk.d.ts +2 -2
- package/dist/esm/types/kiosk.js.map +1 -1
- package/dist/esm/types/transfer-policy.d.ts +5 -3
- package/dist/esm/types/transfer-policy.js.map +1 -1
- package/dist/esm/utils.d.ts +1 -1
- package/dist/esm/utils.js +9 -4
- package/dist/esm/utils.js.map +2 -2
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/bcs.ts +18 -20
- package/src/client/kiosk-client.ts +1 -1
- package/src/client/kiosk-transaction.ts +50 -60
- package/src/client/tp-transaction.ts +29 -22
- package/src/query/kiosk.ts +2 -2
- package/src/query/transfer-policy.ts +6 -4
- package/src/tx/kiosk.ts +16 -16
- package/src/tx/personal-kiosk.ts +3 -3
- package/src/tx/rules/attach.ts +5 -5
- package/src/tx/rules/resolve.ts +16 -16
- package/src/tx/transfer-policy.ts +9 -9
- package/src/types/index.ts +2 -2
- package/src/types/kiosk.ts +2 -2
- package/src/types/transfer-policy.ts +5 -3
- package/src/utils.ts +11 -6
|
@@ -26,7 +26,12 @@ import { convertToPersonalTx, transferPersonalCapTx } from "../tx/personal-kiosk
|
|
|
26
26
|
import { confirmRequest } from "../tx/transfer-policy.js";
|
|
27
27
|
import { getNormalizedRuleType } from "../utils.js";
|
|
28
28
|
class KioskTransaction {
|
|
29
|
-
constructor({
|
|
29
|
+
constructor({
|
|
30
|
+
transactionBlock,
|
|
31
|
+
transaction = transactionBlock,
|
|
32
|
+
kioskClient,
|
|
33
|
+
cap
|
|
34
|
+
}) {
|
|
30
35
|
/**
|
|
31
36
|
* A function to borrow from `personalCap`.
|
|
32
37
|
*/
|
|
@@ -45,7 +50,7 @@ class KioskTransaction {
|
|
|
45
50
|
__privateAdd(this, _personalCap, void 0);
|
|
46
51
|
// A flag that checks whether kiosk TX is finalized.
|
|
47
52
|
__privateAdd(this, _finalized, false);
|
|
48
|
-
this.
|
|
53
|
+
this.transaction = transaction;
|
|
49
54
|
this.kioskClient = kioskClient;
|
|
50
55
|
if (cap)
|
|
51
56
|
this.setCap(cap);
|
|
@@ -61,7 +66,7 @@ class KioskTransaction {
|
|
|
61
66
|
share: true,
|
|
62
67
|
transfer: true
|
|
63
68
|
});
|
|
64
|
-
const [kiosk, cap] = kioskTx.createKiosk(this.
|
|
69
|
+
const [kiosk, cap] = kioskTx.createKiosk(this.transaction);
|
|
65
70
|
this.kiosk = kiosk;
|
|
66
71
|
this.kioskCap = cap;
|
|
67
72
|
return this;
|
|
@@ -82,7 +87,7 @@ class KioskTransaction {
|
|
|
82
87
|
convertToPersonal(borrow) {
|
|
83
88
|
__privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
|
|
84
89
|
const cap = convertToPersonalTx(
|
|
85
|
-
this.
|
|
90
|
+
this.transaction,
|
|
86
91
|
this.kiosk,
|
|
87
92
|
this.kioskCap,
|
|
88
93
|
this.kioskClient.getRulePackageId("personalKioskRulePackageId")
|
|
@@ -99,8 +104,8 @@ class KioskTransaction {
|
|
|
99
104
|
*/
|
|
100
105
|
createAndShare(address) {
|
|
101
106
|
__privateMethod(this, _validateFinalizedStatus, validateFinalizedStatus_fn).call(this);
|
|
102
|
-
const cap = kioskTx.createKioskAndShare(this.
|
|
103
|
-
this.
|
|
107
|
+
const cap = kioskTx.createKioskAndShare(this.transaction);
|
|
108
|
+
this.transaction.transferObjects([cap], this.transaction.pure.address(address));
|
|
104
109
|
}
|
|
105
110
|
/**
|
|
106
111
|
* Shares the kiosk.
|
|
@@ -108,7 +113,7 @@ class KioskTransaction {
|
|
|
108
113
|
share() {
|
|
109
114
|
__privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
|
|
110
115
|
__privateMethod(this, _setPendingStatuses, setPendingStatuses_fn).call(this, { share: false });
|
|
111
|
-
kioskTx.shareKiosk(this.
|
|
116
|
+
kioskTx.shareKiosk(this.transaction, this.kiosk);
|
|
112
117
|
}
|
|
113
118
|
/**
|
|
114
119
|
* Should be called only after `create` is called.
|
|
@@ -119,10 +124,7 @@ class KioskTransaction {
|
|
|
119
124
|
throw new Error("You can only call `shareAndTransferCap` on a non-personal kiosk.");
|
|
120
125
|
__privateMethod(this, _setPendingStatuses, setPendingStatuses_fn).call(this, { transfer: false });
|
|
121
126
|
this.share();
|
|
122
|
-
this.
|
|
123
|
-
[this.kioskCap],
|
|
124
|
-
this.transactionBlock.pure.address(address)
|
|
125
|
-
);
|
|
127
|
+
this.transaction.transferObjects([this.kioskCap], this.transaction.pure.address(address));
|
|
126
128
|
}
|
|
127
129
|
/**
|
|
128
130
|
* A function to borrow an item from a kiosk & execute any function with it.
|
|
@@ -131,7 +133,7 @@ class KioskTransaction {
|
|
|
131
133
|
borrowTx({ itemType, itemId }, callback) {
|
|
132
134
|
__privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
|
|
133
135
|
const [itemObj, promise] = kioskTx.borrowValue(
|
|
134
|
-
this.
|
|
136
|
+
this.transaction,
|
|
135
137
|
itemType,
|
|
136
138
|
this.kiosk,
|
|
137
139
|
this.kioskCap,
|
|
@@ -149,7 +151,7 @@ class KioskTransaction {
|
|
|
149
151
|
borrow({ itemType, itemId }) {
|
|
150
152
|
__privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
|
|
151
153
|
const [itemObj, promise] = kioskTx.borrowValue(
|
|
152
|
-
this.
|
|
154
|
+
this.transaction,
|
|
153
155
|
itemType,
|
|
154
156
|
this.kiosk,
|
|
155
157
|
this.kioskCap,
|
|
@@ -163,7 +165,7 @@ class KioskTransaction {
|
|
|
163
165
|
*/
|
|
164
166
|
return({ itemType, item, promise }) {
|
|
165
167
|
__privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
|
|
166
|
-
kioskTx.returnValue(this.
|
|
168
|
+
kioskTx.returnValue(this.transaction, itemType, this.kiosk, item, promise);
|
|
167
169
|
return this;
|
|
168
170
|
}
|
|
169
171
|
/**
|
|
@@ -173,13 +175,8 @@ class KioskTransaction {
|
|
|
173
175
|
*/
|
|
174
176
|
withdraw(address, amount) {
|
|
175
177
|
__privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
|
|
176
|
-
const coin = kioskTx.withdrawFromKiosk(
|
|
177
|
-
|
|
178
|
-
this.kiosk,
|
|
179
|
-
this.kioskCap,
|
|
180
|
-
amount
|
|
181
|
-
);
|
|
182
|
-
this.transactionBlock.transferObjects([coin], this.transactionBlock.pure.address(address));
|
|
178
|
+
const coin = kioskTx.withdrawFromKiosk(this.transaction, this.kiosk, this.kioskCap, amount);
|
|
179
|
+
this.transaction.transferObjects([coin], this.transaction.pure.address(address));
|
|
183
180
|
return this;
|
|
184
181
|
}
|
|
185
182
|
/**
|
|
@@ -189,7 +186,7 @@ class KioskTransaction {
|
|
|
189
186
|
*/
|
|
190
187
|
place({ itemType, item }) {
|
|
191
188
|
__privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
|
|
192
|
-
kioskTx.place(this.
|
|
189
|
+
kioskTx.place(this.transaction, itemType, this.kiosk, this.kioskCap, item);
|
|
193
190
|
return this;
|
|
194
191
|
}
|
|
195
192
|
/**
|
|
@@ -200,7 +197,7 @@ class KioskTransaction {
|
|
|
200
197
|
*/
|
|
201
198
|
placeAndList({ itemType, item, price }) {
|
|
202
199
|
__privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
|
|
203
|
-
kioskTx.placeAndList(this.
|
|
200
|
+
kioskTx.placeAndList(this.transaction, itemType, this.kiosk, this.kioskCap, item, price);
|
|
204
201
|
return this;
|
|
205
202
|
}
|
|
206
203
|
/**
|
|
@@ -211,7 +208,7 @@ class KioskTransaction {
|
|
|
211
208
|
*/
|
|
212
209
|
list({ itemType, itemId, price }) {
|
|
213
210
|
__privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
|
|
214
|
-
kioskTx.list(this.
|
|
211
|
+
kioskTx.list(this.transaction, itemType, this.kiosk, this.kioskCap, itemId, price);
|
|
215
212
|
return this;
|
|
216
213
|
}
|
|
217
214
|
/**
|
|
@@ -221,7 +218,7 @@ class KioskTransaction {
|
|
|
221
218
|
*/
|
|
222
219
|
delist({ itemType, itemId }) {
|
|
223
220
|
__privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
|
|
224
|
-
kioskTx.delist(this.
|
|
221
|
+
kioskTx.delist(this.transaction, itemType, this.kiosk, this.kioskCap, itemId);
|
|
225
222
|
return this;
|
|
226
223
|
}
|
|
227
224
|
/**
|
|
@@ -232,7 +229,7 @@ class KioskTransaction {
|
|
|
232
229
|
*/
|
|
233
230
|
take({ itemType, itemId }) {
|
|
234
231
|
__privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
|
|
235
|
-
return kioskTx.take(this.
|
|
232
|
+
return kioskTx.take(this.transaction, itemType, this.kiosk, this.kioskCap, itemId);
|
|
236
233
|
}
|
|
237
234
|
/**
|
|
238
235
|
* Transfer a non-locked/non-listed item to an address.
|
|
@@ -244,7 +241,7 @@ class KioskTransaction {
|
|
|
244
241
|
transfer({ itemType, itemId, address }) {
|
|
245
242
|
__privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
|
|
246
243
|
const item = this.take({ itemType, itemId });
|
|
247
|
-
this.
|
|
244
|
+
this.transaction.transferObjects([item], this.transaction.pure.address(address));
|
|
248
245
|
return this;
|
|
249
246
|
}
|
|
250
247
|
/**
|
|
@@ -262,14 +259,7 @@ class KioskTransaction {
|
|
|
262
259
|
policy
|
|
263
260
|
}) {
|
|
264
261
|
__privateMethod(this, _validateKioskIsSet, validateKioskIsSet_fn).call(this);
|
|
265
|
-
kioskTx.lock(
|
|
266
|
-
this.transactionBlock,
|
|
267
|
-
itemType,
|
|
268
|
-
this.kiosk,
|
|
269
|
-
this.kioskCap,
|
|
270
|
-
policy,
|
|
271
|
-
itemId ?? item
|
|
272
|
-
);
|
|
262
|
+
kioskTx.lock(this.transaction, itemType, this.kiosk, this.kioskCap, policy, itemId ?? item);
|
|
273
263
|
return this;
|
|
274
264
|
}
|
|
275
265
|
/**
|
|
@@ -287,10 +277,10 @@ class KioskTransaction {
|
|
|
287
277
|
price,
|
|
288
278
|
sellerKiosk
|
|
289
279
|
}) {
|
|
290
|
-
const coin = this.
|
|
291
|
-
this.
|
|
280
|
+
const coin = this.transaction.splitCoins(this.transaction.gas, [
|
|
281
|
+
this.transaction.pure.u64(price)
|
|
292
282
|
]);
|
|
293
|
-
return kioskTx.purchase(this.
|
|
283
|
+
return kioskTx.purchase(this.transaction, itemType, sellerKiosk, itemId, coin);
|
|
294
284
|
}
|
|
295
285
|
/**
|
|
296
286
|
* A function to purchase and resolve a transfer policy.
|
|
@@ -334,7 +324,8 @@ class KioskTransaction {
|
|
|
334
324
|
canTransferOutsideKiosk = false;
|
|
335
325
|
ruleDefinition.resolveRuleFunction({
|
|
336
326
|
packageId: ruleDefinition.packageId,
|
|
337
|
-
transactionBlock: this.
|
|
327
|
+
transactionBlock: this.transaction,
|
|
328
|
+
transaction: this.transaction,
|
|
338
329
|
itemType,
|
|
339
330
|
itemId,
|
|
340
331
|
price: price.toString(),
|
|
@@ -347,7 +338,7 @@ class KioskTransaction {
|
|
|
347
338
|
extraArgs: extraArgs || {}
|
|
348
339
|
});
|
|
349
340
|
}
|
|
350
|
-
confirmRequest(this.
|
|
341
|
+
confirmRequest(this.transaction, itemType, policy.id, transferRequest);
|
|
351
342
|
if (canTransferOutsideKiosk)
|
|
352
343
|
this.place({ itemType, item: purchasedItem });
|
|
353
344
|
return this;
|
|
@@ -359,15 +350,15 @@ class KioskTransaction {
|
|
|
359
350
|
*/
|
|
360
351
|
setCap(cap) {
|
|
361
352
|
__privateMethod(this, _validateFinalizedStatus, validateFinalizedStatus_fn).call(this);
|
|
362
|
-
this.kiosk = this.
|
|
353
|
+
this.kiosk = this.transaction.object(cap.kioskId);
|
|
363
354
|
if (!cap.isPersonal) {
|
|
364
|
-
this.kioskCap = this.
|
|
355
|
+
this.kioskCap = this.transaction.object(cap.objectId);
|
|
365
356
|
return;
|
|
366
357
|
}
|
|
367
358
|
return __privateMethod(this, _borrowFromPersonalCap, borrowFromPersonalCap_fn).call(this, cap.objectId);
|
|
368
359
|
}
|
|
369
360
|
/**
|
|
370
|
-
* A function that ends up the kiosk building
|
|
361
|
+
* A function that ends up the kiosk building tx & returns the `kioskOwnerCap` back to the
|
|
371
362
|
* `PersonalKioskCap`, in case we are operating on a personal kiosk.
|
|
372
363
|
* It will also share the `kiosk` if it's not shared, and finalize the transfer of the personal cap if it's pending.
|
|
373
364
|
*/
|
|
@@ -384,17 +375,13 @@ class KioskTransaction {
|
|
|
384
375
|
}
|
|
385
376
|
const packageId = this.kioskClient.getRulePackageId("personalKioskRulePackageId");
|
|
386
377
|
if (__privateGet(this, _promise)) {
|
|
387
|
-
this.
|
|
378
|
+
this.transaction.moveCall({
|
|
388
379
|
target: `${packageId}::personal_kiosk::return_val`,
|
|
389
|
-
arguments: [
|
|
390
|
-
__privateGet(this, _personalCap),
|
|
391
|
-
this.transactionBlock.object(this.kioskCap),
|
|
392
|
-
__privateGet(this, _promise)
|
|
393
|
-
]
|
|
380
|
+
arguments: [__privateGet(this, _personalCap), this.transaction.object(this.kioskCap), __privateGet(this, _promise)]
|
|
394
381
|
});
|
|
395
382
|
}
|
|
396
383
|
if (__privateGet(this, _pendingTransfer))
|
|
397
|
-
transferPersonalCapTx(this.
|
|
384
|
+
transferPersonalCapTx(this.transaction, __privateGet(this, _personalCap), packageId);
|
|
398
385
|
__privateSet(this, _finalized, true);
|
|
399
386
|
}
|
|
400
387
|
// Some setters in case we want custom behavior.
|
|
@@ -435,14 +422,14 @@ _personalCap = new WeakMap();
|
|
|
435
422
|
_finalized = new WeakMap();
|
|
436
423
|
_borrowFromPersonalCap = new WeakSet();
|
|
437
424
|
borrowFromPersonalCap_fn = function(personalCap) {
|
|
438
|
-
const [kioskCap, promise] = this.
|
|
425
|
+
const [kioskCap, promise] = this.transaction.moveCall({
|
|
439
426
|
target: `${this.kioskClient.getRulePackageId(
|
|
440
427
|
"personalKioskRulePackageId"
|
|
441
428
|
)}::personal_kiosk::borrow_val`,
|
|
442
|
-
arguments: [this.
|
|
429
|
+
arguments: [this.transaction.object(personalCap)]
|
|
443
430
|
});
|
|
444
431
|
this.kioskCap = kioskCap;
|
|
445
|
-
__privateSet(this, _personalCap, this.
|
|
432
|
+
__privateSet(this, _personalCap, this.transaction.object(personalCap));
|
|
446
433
|
__privateSet(this, _promise, promise);
|
|
447
434
|
return this;
|
|
448
435
|
};
|
|
@@ -464,7 +451,7 @@ validateKioskIsSet_fn = function() {
|
|
|
464
451
|
_validateFinalizedStatus = new WeakSet();
|
|
465
452
|
validateFinalizedStatus_fn = function() {
|
|
466
453
|
if (__privateGet(this, _finalized))
|
|
467
|
-
throw new Error("You can't add more transactions to a finalized kiosk transaction
|
|
454
|
+
throw new Error("You can't add more transactions to a finalized kiosk transaction.");
|
|
468
455
|
};
|
|
469
456
|
export {
|
|
470
457
|
KioskTransaction
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/client/kiosk-transaction.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type {\n\tTransactionArgument,\n\tTransactionBlock,\n\tTransactionObjectArgument,\n} from '@mysten/sui.js/transactions';\n\nimport * as kioskTx from '../tx/kiosk.js';\nimport { convertToPersonalTx, transferPersonalCapTx } from '../tx/personal-kiosk.js';\nimport { confirmRequest } from '../tx/transfer-policy.js';\nimport type {\n\tItemId,\n\tItemReference,\n\tItemValue,\n\tKioskOwnerCap,\n\tObjectArgument,\n\tPrice,\n\tPurchaseOptions,\n} from '../types/index.js';\nimport { getNormalizedRuleType } from '../utils.js';\nimport type { KioskClient } from './kiosk-client.js';\n\nexport type KioskTransactionParams = {\n\t/** The TransactionBlock for this run */\n\ttransactionBlock: TransactionBlock;\n\t/**\n\t * You can create a new KioskClient by calling `new KioskClient()`\n\t */\n\tkioskClient: KioskClient;\n\t/**\n\t * You can optionally pass in the `cap` as returned\n\t * from `kioskClient.getOwnedKiosks` when initializing the client\n\t * Otherwise, you can set it by calling `kioskTransaction.setCap()`\n\t */\n\tcap?: KioskOwnerCap;\n};\n\n/**\n * A helper for building transactions that involve kiosk.\n */\nexport class KioskTransaction {\n\ttransactionBlock: TransactionBlock;\n\tkioskClient: KioskClient;\n\tkiosk?: TransactionObjectArgument;\n\tkioskCap?: TransactionObjectArgument;\n\t// If we're pending `share` of a new kiosk, `finalize()` will share it.\n\t#pendingShare?: boolean;\n\t// If we're pending transferring of the cap, `finalize()` will either error or transfer the cap if it's a new personal.\n\t#pendingTransfer?: boolean;\n\t// The promise that the personalCap will be returned on `finalize()`.\n\t#promise?: TransactionArgument | undefined;\n\t// The personal kiosk argument.\n\t#personalCap?: TransactionObjectArgument;\n\t// A flag that checks whether kiosk TX is finalized.\n\t#finalized: boolean = false;\n\n\tconstructor({ transactionBlock, kioskClient, cap }: KioskTransactionParams) {\n\t\tthis.transactionBlock = transactionBlock;\n\t\tthis.kioskClient = kioskClient;\n\n\t\tif (cap) this.setCap(cap);\n\t}\n\n\t/**\n\t * Creates a kiosk and saves `kiosk` and `kioskOwnerCap` in state.\n\t * Helpful if we want to chain some actions before sharing + transferring the cap to the specified address.\n\t * @param borrow If true, the `kioskOwnerCap` is borrowed from the `PersonalKioskCap` to be used in next transactions.\n\t */\n\tcreate() {\n\t\tthis.#validateFinalizedStatus();\n\t\tthis.#setPendingStatuses({\n\t\t\tshare: true,\n\t\t\ttransfer: true,\n\t\t});\n\t\tconst [kiosk, cap] = kioskTx.createKiosk(this.transactionBlock);\n\t\tthis.kiosk = kiosk;\n\t\tthis.kioskCap = cap;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Creates a personal kiosk & shares it.\n\t * The `PersonalKioskCap` is transferred to the signer.\n\t * @param borrow If true, the `kioskOwnerCap` is borrowed from the `PersonalKioskCap` to be used in next transactions.\n\t */\n\tcreatePersonal(borrow?: boolean) {\n\t\tthis.#pendingShare = true;\n\t\treturn this.create().convertToPersonal(borrow);\n\t}\n\n\t/**\n\t * Converts a kiosk to a Personal (Soulbound) Kiosk.\n\t * Requires initialization by either calling `ktxb.create()` or `ktxb.setCap()`.\n\t */\n\tconvertToPersonal(borrow?: boolean) {\n\t\tthis.#validateKioskIsSet();\n\n\t\tconst cap = convertToPersonalTx(\n\t\t\tthis.transactionBlock,\n\t\t\tthis.kiosk!,\n\t\t\tthis.kioskCap!,\n\t\t\tthis.kioskClient.getRulePackageId('personalKioskRulePackageId'),\n\t\t);\n\n\t\t// if we enable `borrow`, we borrow the kioskCap from the cap.\n\t\tif (borrow) this.#borrowFromPersonalCap(cap);\n\t\telse this.#personalCap = cap;\n\n\t\tthis.#setPendingStatuses({ transfer: true });\n\t\treturn this;\n\t}\n\n\t/**\n\t * Single function way to create a kiosk, share it and transfer the cap to the specified address.\n\t */\n\tcreateAndShare(address: string) {\n\t\tthis.#validateFinalizedStatus();\n\t\tconst cap = kioskTx.createKioskAndShare(this.transactionBlock);\n\t\tthis.transactionBlock.transferObjects([cap], this.transactionBlock.pure.address(address));\n\t}\n\n\t/**\n\t * Shares the kiosk.\n\t */\n\tshare() {\n\t\tthis.#validateKioskIsSet();\n\t\tthis.#setPendingStatuses({ share: false });\n\t\tkioskTx.shareKiosk(this.transactionBlock, this.kiosk!);\n\t}\n\n\t/**\n\t * Should be called only after `create` is called.\n\t * It shares the kiosk & transfers the cap to the specified address.\n\t */\n\tshareAndTransferCap(address: string) {\n\t\tif (this.#personalCap)\n\t\t\tthrow new Error('You can only call `shareAndTransferCap` on a non-personal kiosk.');\n\t\tthis.#setPendingStatuses({ transfer: false });\n\t\tthis.share();\n\t\tthis.transactionBlock.transferObjects(\n\t\t\t[this.kioskCap!],\n\t\t\tthis.transactionBlock.pure.address(address),\n\t\t);\n\t}\n\n\t/**\n\t * A function to borrow an item from a kiosk & execute any function with it.\n\t * Example: You could borrow a Fren out of a kiosk, attach an accessory (or mix), and return it.\n\t */\n\tborrowTx({ itemType, itemId }: ItemId, callback: (item: TransactionArgument) => void) {\n\t\tthis.#validateKioskIsSet();\n\t\tconst [itemObj, promise] = kioskTx.borrowValue(\n\t\t\tthis.transactionBlock,\n\t\t\titemType,\n\t\t\tthis.kiosk!,\n\t\t\tthis.kioskCap!,\n\t\t\titemId,\n\t\t);\n\n\t\tcallback(itemObj);\n\n\t\tthis.return({ itemType, item: itemObj, promise });\n\t}\n\n\t/**\n\t * Borrows an item from the kiosk.\n\t * This will fail if the item is listed for sale.\n\t *\n\t * Requires calling `return`.\n\t */\n\tborrow({ itemType, itemId }: ItemId): [TransactionArgument, TransactionArgument] {\n\t\tthis.#validateKioskIsSet();\n\t\tconst [itemObj, promise] = kioskTx.borrowValue(\n\t\t\tthis.transactionBlock,\n\t\t\titemType,\n\t\t\tthis.kiosk!,\n\t\t\tthis.kioskCap!,\n\t\t\titemId,\n\t\t);\n\n\t\treturn [itemObj, promise];\n\t}\n\n\t/**\n\t * Returns the item back to the kiosk.\n\t * Accepts the parameters returned from the `borrow` function.\n\t */\n\treturn({ itemType, item, promise }: ItemValue & { promise: TransactionArgument }) {\n\t\tthis.#validateKioskIsSet();\n\t\tkioskTx.returnValue(this.transactionBlock, itemType, this.kiosk!, item, promise);\n\t\treturn this;\n\t}\n\n\t/**\n\t * A function to withdraw from kiosk\n\t * @param address Where to trasnfer the coin.\n\t * @param amount The amount we aim to withdraw.\n\t */\n\twithdraw(address: string, amount?: string | bigint | number) {\n\t\tthis.#validateKioskIsSet();\n\t\tconst coin = kioskTx.withdrawFromKiosk(\n\t\t\tthis.transactionBlock,\n\t\t\tthis.kiosk!,\n\t\t\tthis.kioskCap!,\n\t\t\tamount,\n\t\t);\n\t\tthis.transactionBlock.transferObjects([coin], this.transactionBlock.pure.address(address));\n\t\treturn this;\n\t}\n\n\t/**\n\t * A function to place an item in the kiosk.\n\t * @param itemType The type `T` of the item\n\t * @param item The ID or Transaction Argument of the item\n\t */\n\tplace({ itemType, item }: ItemReference) {\n\t\tthis.#validateKioskIsSet();\n\t\tkioskTx.place(this.transactionBlock, itemType, this.kiosk!, this.kioskCap!, item);\n\t\treturn this;\n\t}\n\n\t/**\n\t * A function to place an item in the kiosk and list it for sale in one transaction.\n\t * @param itemType The type `T` of the item\n\t * @param item The ID or Transaction Argument of the item\n\t * @param price The price in MIST\n\t */\n\tplaceAndList({ itemType, item, price }: ItemReference & Price) {\n\t\tthis.#validateKioskIsSet();\n\t\tkioskTx.placeAndList(this.transactionBlock, itemType, this.kiosk!, this.kioskCap!, item, price);\n\t\treturn this;\n\t}\n\n\t/**\n\t * A function to list an item in the kiosk.\n\t * @param itemType The type `T` of the item\n\t * @param itemId The ID of the item\n\t * @param price The price in MIST\n\t */\n\tlist({ itemType, itemId, price }: ItemId & { price: string | bigint }) {\n\t\tthis.#validateKioskIsSet();\n\t\tkioskTx.list(this.transactionBlock, itemType, this.kiosk!, this.kioskCap!, itemId, price);\n\t\treturn this;\n\t}\n\n\t/**\n\t * A function to delist an item from the kiosk.\n\t * @param itemType The type `T` of the item\n\t * @param itemId The ID of the item\n\t */\n\tdelist({ itemType, itemId }: ItemId) {\n\t\tthis.#validateKioskIsSet();\n\t\tkioskTx.delist(this.transactionBlock, itemType, this.kiosk!, this.kioskCap!, itemId);\n\t\treturn this;\n\t}\n\n\t/**\n\t * A function to take an item from the kiosk. The transaction won't succeed if the item is listed or locked.\n\n\t * @param itemType The type `T` of the item\n\t * @param itemId The ID of the item\n\t */\n\ttake({ itemType, itemId }: ItemId): TransactionObjectArgument {\n\t\tthis.#validateKioskIsSet();\n\t\treturn kioskTx.take(this.transactionBlock, itemType, this.kiosk!, this.kioskCap!, itemId);\n\t}\n\n\t/**\n\t * Transfer a non-locked/non-listed item to an address.\n\t *\n\t * @param itemType The type `T` of the item\n\t * @param itemId The ID of the item\n\t * @param address The destination address\n\t */\n\ttransfer({ itemType, itemId, address }: ItemId & { address: string }) {\n\t\tthis.#validateKioskIsSet();\n\t\tconst item = this.take({ itemType, itemId });\n\t\tthis.transactionBlock.transferObjects([item], this.transactionBlock.pure.address(address));\n\t\treturn this;\n\t}\n\n\t/**\n\t * A function to take lock an item in the kiosk.\n\n\t * @param itemType The type `T` of the item\n\t * @param item The ID or Transaction Argument of the item\n\t * @param itemId The ID of the item - Deprecated: Use `item` instead.\n\t * @param policy The Policy ID or Transaction Argument for item T\n\t */\n\tlock({\n\t\titemType,\n\t\titem,\n\t\titemId,\n\t\tpolicy,\n\t}: ItemReference & { policy: ObjectArgument; itemId?: string }) {\n\t\tthis.#validateKioskIsSet();\n\t\tkioskTx.lock(\n\t\t\tthis.transactionBlock,\n\t\t\titemType,\n\t\t\tthis.kiosk!,\n\t\t\tthis.kioskCap!,\n\t\t\tpolicy,\n\t\t\titemId ?? item,\n\t\t);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Purchase an item from a seller's kiosk.\n\t * Returns [item, transferRequest]\n\t * Can be called like: `const [item, transferRequest] = kioskTx.purchase({...})`\n\t * @param itemType The type `T` of the item\n\t * @param itemId The ID of the item\n\t * @param price The price in MIST\n\t * @param sellerKiosk The kiosk which is selling the item. Can be an id or an object argument.\n\t */\n\tpurchase({\n\t\titemType,\n\t\titemId,\n\t\tprice,\n\t\tsellerKiosk,\n\t}: ItemId & Price & { sellerKiosk: ObjectArgument }): [\n\t\tTransactionObjectArgument,\n\t\tTransactionObjectArgument,\n\t] {\n\t\t// Split the coin for the amount of the listing.\n\t\tconst coin = this.transactionBlock.splitCoins(this.transactionBlock.gas, [\n\t\t\tthis.transactionBlock.pure.u64(price),\n\t\t]);\n\t\treturn kioskTx.purchase(this.transactionBlock, itemType, sellerKiosk, itemId, coin);\n\t}\n\n\t/**\n\t * A function to purchase and resolve a transfer policy.\n\t * If the transfer policy has the `lock` rule, the item is locked in the kiosk.\n\t * Otherwise, the item is placed in the kiosk.\n\t * @param itemType The type of the item\n\t * @param itemId The id of the item\n\t * @param price The price of the specified item\n\t * @param sellerKiosk The kiosk which is selling the item. Can be an id or an object argument.\n\t * @param extraArgs Used to pass arguments for custom rule resolvers.\n\t */\n\tasync purchaseAndResolve({\n\t\titemType,\n\t\titemId,\n\t\tprice,\n\t\tsellerKiosk,\n\t\textraArgs,\n\t}: ItemId & Price & { sellerKiosk: ObjectArgument } & PurchaseOptions) {\n\t\tthis.#validateKioskIsSet();\n\t\t// Get a list of the transfer policies.\n\t\tconst policies = await this.kioskClient.getTransferPolicies({ type: itemType });\n\n\t\tif (policies.length === 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`The type ${itemType} doesn't have a Transfer Policy so it can't be traded through kiosk.`,\n\t\t\t);\n\t\t}\n\n\t\tconst policy = policies[0]; // we now pick the first one. We need to add an option to define which one.\n\n\t\t// initialize the purchase `kiosk::purchase`\n\t\tconst [purchasedItem, transferRequest] = this.purchase({\n\t\t\titemType,\n\t\t\titemId,\n\t\t\tprice,\n\t\t\tsellerKiosk,\n\t\t});\n\n\t\tlet canTransferOutsideKiosk = true;\n\n\t\tfor (const rule of policy.rules) {\n\t\t\tconst ruleDefinition = this.kioskClient.rules.find(\n\t\t\t\t(x) => getNormalizedRuleType(x.rule) === getNormalizedRuleType(rule),\n\t\t\t);\n\t\t\tif (!ruleDefinition) throw new Error(`No resolver for the following rule: ${rule}.`);\n\n\t\t\tif (ruleDefinition.hasLockingRule) canTransferOutsideKiosk = false;\n\n\t\t\truleDefinition.resolveRuleFunction({\n\t\t\t\tpackageId: ruleDefinition.packageId,\n\t\t\t\ttransactionBlock: this.transactionBlock,\n\t\t\t\titemType,\n\t\t\t\titemId,\n\t\t\t\tprice: price.toString(),\n\t\t\t\tsellerKiosk,\n\t\t\t\tpolicyId: policy.id,\n\t\t\t\ttransferRequest,\n\t\t\t\tpurchasedItem,\n\t\t\t\tkiosk: this.kiosk!,\n\t\t\t\tkioskCap: this.kioskCap!,\n\t\t\t\textraArgs: extraArgs || {},\n\t\t\t});\n\t\t}\n\n\t\tconfirmRequest(this.transactionBlock, itemType, policy.id, transferRequest);\n\n\t\tif (canTransferOutsideKiosk) this.place({ itemType, item: purchasedItem });\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * A function to setup the client using an existing `ownerCap`,\n\t * as return from the `kioskClient.getOwnedKiosks` function.\n\t * @param cap `KioskOwnerCap` object as returned from `getOwnedKiosks` SDK call.\n\t */\n\tsetCap(cap: KioskOwnerCap) {\n\t\tthis.#validateFinalizedStatus();\n\t\tthis.kiosk = this.transactionBlock.object(cap.kioskId);\n\t\tif (!cap.isPersonal) {\n\t\t\tthis.kioskCap = this.transactionBlock.object(cap.objectId);\n\t\t\treturn;\n\t\t}\n\n\t\treturn this.#borrowFromPersonalCap(cap.objectId);\n\t}\n\n\t/**\n\t *\tA function that ends up the kiosk building txb & returns the `kioskOwnerCap` back to the\n\t * `PersonalKioskCap`, in case we are operating on a personal kiosk.\n\t * \tIt will also share the `kiosk` if it's not shared, and finalize the transfer of the personal cap if it's pending.\n\t */\n\tfinalize() {\n\t\tthis.#validateKioskIsSet();\n\t\t// If we're pending the sharing of the new kiosk, share it.\n\t\tif (this.#pendingShare) this.share();\n\n\t\t// If we're operating on a non-personal kiosk, we don't need to do anything else.\n\t\tif (!this.#personalCap) {\n\t\t\t// If we're pending transfer though, we inform user to call `shareAndTransferCap()`.\n\t\t\tif (this.#pendingTransfer)\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'You need to transfer the `kioskOwnerCap` by calling `shareAndTransferCap()` before wrap',\n\t\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst packageId = this.kioskClient.getRulePackageId('personalKioskRulePackageId');\n\n\t\t// if we have a promise, return the `ownerCap` back to the personal cap.\n\t\tif (this.#promise) {\n\t\t\tthis.transactionBlock.moveCall({\n\t\t\t\ttarget: `${packageId}::personal_kiosk::return_val`,\n\t\t\t\targuments: [\n\t\t\t\t\tthis.#personalCap,\n\t\t\t\t\tthis.transactionBlock.object(this.kioskCap!),\n\t\t\t\t\tthis.#promise!,\n\t\t\t\t],\n\t\t\t});\n\t\t}\n\n\t\t// If we are pending transferring the personalCap, we do it here.\n\t\tif (this.#pendingTransfer)\n\t\t\ttransferPersonalCapTx(this.transactionBlock, this.#personalCap, packageId);\n\n\t\t// Mark the transaction block as finalized, so no other functions can be called.\n\t\tthis.#finalized = true;\n\t}\n\n\t// Some setters in case we want custom behavior.\n\tsetKioskCap(cap: TransactionObjectArgument) {\n\t\tthis.#validateFinalizedStatus();\n\t\tthis.kioskCap = cap;\n\t\treturn this;\n\t}\n\n\tsetKiosk(kiosk: TransactionObjectArgument) {\n\t\tthis.#validateFinalizedStatus();\n\t\tthis.kiosk = kiosk;\n\t\treturn this;\n\t}\n\n\t// Some getters\n\t/*\n\t * Returns the active transaction's kiosk, or undefined if `setCap` or `create()` hasn't been called yet.\n\t */\n\tgetKiosk() {\n\t\tthis.#validateFinalizedStatus();\n\t\tif (!this.kiosk) throw new Error('Kiosk is not set.');\n\t\treturn this.kiosk;\n\t}\n\n\t/*\n\t * Returns the active transaction's kioskOwnerCap, or undefined if `setCap` or `create()` hasn't been called yet.\n\t */\n\tgetKioskCap() {\n\t\tthis.#validateFinalizedStatus();\n\t\tif (!this.kioskCap) throw new Error('Kiosk cap is not set');\n\t\treturn this.kioskCap;\n\t}\n\n\t/**\n\t * A function to borrow from `personalCap`.\n\t */\n\t#borrowFromPersonalCap(personalCap: ObjectArgument) {\n\t\tconst [kioskCap, promise] = this.transactionBlock.moveCall({\n\t\t\ttarget: `${this.kioskClient.getRulePackageId(\n\t\t\t\t'personalKioskRulePackageId',\n\t\t\t)}::personal_kiosk::borrow_val`,\n\t\t\targuments: [this.transactionBlock.object(personalCap)],\n\t\t});\n\n\t\tthis.kioskCap = kioskCap;\n\t\tthis.#personalCap = this.transactionBlock.object(personalCap);\n\t\tthis.#promise = promise;\n\n\t\treturn this;\n\t}\n\n\t#setPendingStatuses({ share, transfer }: { share?: boolean; transfer?: boolean }) {\n\t\tif (transfer !== undefined) this.#pendingTransfer = transfer;\n\t\tif (share !== undefined) this.#pendingShare = share;\n\t}\n\n\t#validateKioskIsSet() {\n\t\tthis.#validateFinalizedStatus();\n\n\t\tif (!this.kiosk || !this.kioskCap)\n\t\t\tthrow new Error(\n\t\t\t\t'You need to initialize the client by either supplying an existing owner cap or by creating a new by calling `.create()`',\n\t\t\t);\n\t}\n\n\t// Validates that `finalize`\n\t#validateFinalizedStatus() {\n\t\tif (this.#finalized)\n\t\t\tthrow new Error(\"You can't add more transactions to a finalized kiosk transaction block.\");\n\t}\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AASA,YAAY,aAAa;AACzB,SAAS,qBAAqB,6BAA6B;AAC3D,SAAS,sBAAsB;AAU/B,SAAS,6BAA6B;
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type {\n\tTransaction,\n\tTransactionArgument,\n\tTransactionObjectArgument,\n} from '@mysten/sui/transactions';\n\nimport * as kioskTx from '../tx/kiosk.js';\nimport { convertToPersonalTx, transferPersonalCapTx } from '../tx/personal-kiosk.js';\nimport { confirmRequest } from '../tx/transfer-policy.js';\nimport type {\n\tItemId,\n\tItemReference,\n\tItemValue,\n\tKioskOwnerCap,\n\tObjectArgument,\n\tPrice,\n\tPurchaseOptions,\n} from '../types/index.js';\nimport { getNormalizedRuleType } from '../utils.js';\nimport type { KioskClient } from './kiosk-client.js';\n\nexport type KioskTransactionParams = {\n\t/** The Transaction for this run */\n\ttransaction: Transaction;\n\n\t/** @deprecated use transaction instead */\n\ttransactionBlock?: Transaction;\n\t/**\n\t * You can create a new KioskClient by calling `new KioskClient()`\n\t */\n\tkioskClient: KioskClient;\n\t/**\n\t * You can optionally pass in the `cap` as returned\n\t * from `kioskClient.getOwnedKiosks` when initializing the client\n\t * Otherwise, you can set it by calling `kioskTransaction.setCap()`\n\t */\n\tcap?: KioskOwnerCap;\n};\n\n/**\n * A helper for building transactions that involve kiosk.\n */\nexport class KioskTransaction {\n\ttransaction: Transaction;\n\tkioskClient: KioskClient;\n\tkiosk?: TransactionObjectArgument;\n\tkioskCap?: TransactionObjectArgument;\n\t// If we're pending `share` of a new kiosk, `finalize()` will share it.\n\t#pendingShare?: boolean;\n\t// If we're pending transferring of the cap, `finalize()` will either error or transfer the cap if it's a new personal.\n\t#pendingTransfer?: boolean;\n\t// The promise that the personalCap will be returned on `finalize()`.\n\t#promise?: TransactionArgument | undefined;\n\t// The personal kiosk argument.\n\t#personalCap?: TransactionObjectArgument;\n\t// A flag that checks whether kiosk TX is finalized.\n\t#finalized: boolean = false;\n\n\tconstructor({\n\t\ttransactionBlock,\n\t\ttransaction = transactionBlock!,\n\t\tkioskClient,\n\t\tcap,\n\t}: KioskTransactionParams) {\n\t\tthis.transaction = transaction;\n\t\tthis.kioskClient = kioskClient;\n\n\t\tif (cap) this.setCap(cap);\n\t}\n\n\t/**\n\t * Creates a kiosk and saves `kiosk` and `kioskOwnerCap` in state.\n\t * Helpful if we want to chain some actions before sharing + transferring the cap to the specified address.\n\t * @param borrow If true, the `kioskOwnerCap` is borrowed from the `PersonalKioskCap` to be used in next transactions.\n\t */\n\tcreate() {\n\t\tthis.#validateFinalizedStatus();\n\t\tthis.#setPendingStatuses({\n\t\t\tshare: true,\n\t\t\ttransfer: true,\n\t\t});\n\t\tconst [kiosk, cap] = kioskTx.createKiosk(this.transaction);\n\t\tthis.kiosk = kiosk;\n\t\tthis.kioskCap = cap;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Creates a personal kiosk & shares it.\n\t * The `PersonalKioskCap` is transferred to the signer.\n\t * @param borrow If true, the `kioskOwnerCap` is borrowed from the `PersonalKioskCap` to be used in next transactions.\n\t */\n\tcreatePersonal(borrow?: boolean) {\n\t\tthis.#pendingShare = true;\n\t\treturn this.create().convertToPersonal(borrow);\n\t}\n\n\t/**\n\t * Converts a kiosk to a Personal (Soulbound) Kiosk.\n\t * Requires initialization by either calling `ktxb.create()` or `ktxb.setCap()`.\n\t */\n\tconvertToPersonal(borrow?: boolean) {\n\t\tthis.#validateKioskIsSet();\n\n\t\tconst cap = convertToPersonalTx(\n\t\t\tthis.transaction,\n\t\t\tthis.kiosk!,\n\t\t\tthis.kioskCap!,\n\t\t\tthis.kioskClient.getRulePackageId('personalKioskRulePackageId'),\n\t\t);\n\n\t\t// if we enable `borrow`, we borrow the kioskCap from the cap.\n\t\tif (borrow) this.#borrowFromPersonalCap(cap);\n\t\telse this.#personalCap = cap;\n\n\t\tthis.#setPendingStatuses({ transfer: true });\n\t\treturn this;\n\t}\n\n\t/**\n\t * Single function way to create a kiosk, share it and transfer the cap to the specified address.\n\t */\n\tcreateAndShare(address: string) {\n\t\tthis.#validateFinalizedStatus();\n\t\tconst cap = kioskTx.createKioskAndShare(this.transaction);\n\t\tthis.transaction.transferObjects([cap], this.transaction.pure.address(address));\n\t}\n\n\t/**\n\t * Shares the kiosk.\n\t */\n\tshare() {\n\t\tthis.#validateKioskIsSet();\n\t\tthis.#setPendingStatuses({ share: false });\n\t\tkioskTx.shareKiosk(this.transaction, this.kiosk!);\n\t}\n\n\t/**\n\t * Should be called only after `create` is called.\n\t * It shares the kiosk & transfers the cap to the specified address.\n\t */\n\tshareAndTransferCap(address: string) {\n\t\tif (this.#personalCap)\n\t\t\tthrow new Error('You can only call `shareAndTransferCap` on a non-personal kiosk.');\n\t\tthis.#setPendingStatuses({ transfer: false });\n\t\tthis.share();\n\t\tthis.transaction.transferObjects([this.kioskCap!], this.transaction.pure.address(address));\n\t}\n\n\t/**\n\t * A function to borrow an item from a kiosk & execute any function with it.\n\t * Example: You could borrow a Fren out of a kiosk, attach an accessory (or mix), and return it.\n\t */\n\tborrowTx({ itemType, itemId }: ItemId, callback: (item: TransactionArgument) => void) {\n\t\tthis.#validateKioskIsSet();\n\t\tconst [itemObj, promise] = kioskTx.borrowValue(\n\t\t\tthis.transaction,\n\t\t\titemType,\n\t\t\tthis.kiosk!,\n\t\t\tthis.kioskCap!,\n\t\t\titemId,\n\t\t);\n\n\t\tcallback(itemObj);\n\n\t\tthis.return({ itemType, item: itemObj, promise });\n\t}\n\n\t/**\n\t * Borrows an item from the kiosk.\n\t * This will fail if the item is listed for sale.\n\t *\n\t * Requires calling `return`.\n\t */\n\tborrow({ itemType, itemId }: ItemId): [TransactionArgument, TransactionArgument] {\n\t\tthis.#validateKioskIsSet();\n\t\tconst [itemObj, promise] = kioskTx.borrowValue(\n\t\t\tthis.transaction,\n\t\t\titemType,\n\t\t\tthis.kiosk!,\n\t\t\tthis.kioskCap!,\n\t\t\titemId,\n\t\t);\n\n\t\treturn [itemObj, promise];\n\t}\n\n\t/**\n\t * Returns the item back to the kiosk.\n\t * Accepts the parameters returned from the `borrow` function.\n\t */\n\treturn({ itemType, item, promise }: ItemValue & { promise: TransactionArgument }) {\n\t\tthis.#validateKioskIsSet();\n\t\tkioskTx.returnValue(this.transaction, itemType, this.kiosk!, item, promise);\n\t\treturn this;\n\t}\n\n\t/**\n\t * A function to withdraw from kiosk\n\t * @param address Where to trasnfer the coin.\n\t * @param amount The amount we aim to withdraw.\n\t */\n\twithdraw(address: string, amount?: string | bigint | number) {\n\t\tthis.#validateKioskIsSet();\n\t\tconst coin = kioskTx.withdrawFromKiosk(this.transaction, this.kiosk!, this.kioskCap!, amount);\n\t\tthis.transaction.transferObjects([coin], this.transaction.pure.address(address));\n\t\treturn this;\n\t}\n\n\t/**\n\t * A function to place an item in the kiosk.\n\t * @param itemType The type `T` of the item\n\t * @param item The ID or Transaction Argument of the item\n\t */\n\tplace({ itemType, item }: ItemReference) {\n\t\tthis.#validateKioskIsSet();\n\t\tkioskTx.place(this.transaction, itemType, this.kiosk!, this.kioskCap!, item);\n\t\treturn this;\n\t}\n\n\t/**\n\t * A function to place an item in the kiosk and list it for sale in one transaction.\n\t * @param itemType The type `T` of the item\n\t * @param item The ID or Transaction Argument of the item\n\t * @param price The price in MIST\n\t */\n\tplaceAndList({ itemType, item, price }: ItemReference & Price) {\n\t\tthis.#validateKioskIsSet();\n\t\tkioskTx.placeAndList(this.transaction, itemType, this.kiosk!, this.kioskCap!, item, price);\n\t\treturn this;\n\t}\n\n\t/**\n\t * A function to list an item in the kiosk.\n\t * @param itemType The type `T` of the item\n\t * @param itemId The ID of the item\n\t * @param price The price in MIST\n\t */\n\tlist({ itemType, itemId, price }: ItemId & { price: string | bigint }) {\n\t\tthis.#validateKioskIsSet();\n\t\tkioskTx.list(this.transaction, itemType, this.kiosk!, this.kioskCap!, itemId, price);\n\t\treturn this;\n\t}\n\n\t/**\n\t * A function to delist an item from the kiosk.\n\t * @param itemType The type `T` of the item\n\t * @param itemId The ID of the item\n\t */\n\tdelist({ itemType, itemId }: ItemId) {\n\t\tthis.#validateKioskIsSet();\n\t\tkioskTx.delist(this.transaction, itemType, this.kiosk!, this.kioskCap!, itemId);\n\t\treturn this;\n\t}\n\n\t/**\n\t * A function to take an item from the kiosk. The transaction won't succeed if the item is listed or locked.\n\n\t * @param itemType The type `T` of the item\n\t * @param itemId The ID of the item\n\t */\n\ttake({ itemType, itemId }: ItemId): TransactionObjectArgument {\n\t\tthis.#validateKioskIsSet();\n\t\treturn kioskTx.take(this.transaction, itemType, this.kiosk!, this.kioskCap!, itemId);\n\t}\n\n\t/**\n\t * Transfer a non-locked/non-listed item to an address.\n\t *\n\t * @param itemType The type `T` of the item\n\t * @param itemId The ID of the item\n\t * @param address The destination address\n\t */\n\ttransfer({ itemType, itemId, address }: ItemId & { address: string }) {\n\t\tthis.#validateKioskIsSet();\n\t\tconst item = this.take({ itemType, itemId });\n\t\tthis.transaction.transferObjects([item], this.transaction.pure.address(address));\n\t\treturn this;\n\t}\n\n\t/**\n\t * A function to take lock an item in the kiosk.\n\n\t * @param itemType The type `T` of the item\n\t * @param item The ID or Transaction Argument of the item\n\t * @param itemId The ID of the item - Deprecated: Use `item` instead.\n\t * @param policy The Policy ID or Transaction Argument for item T\n\t */\n\tlock({\n\t\titemType,\n\t\titem,\n\t\titemId,\n\t\tpolicy,\n\t}: ItemReference & { policy: ObjectArgument; itemId?: string }) {\n\t\tthis.#validateKioskIsSet();\n\t\tkioskTx.lock(this.transaction, itemType, this.kiosk!, this.kioskCap!, policy, itemId ?? item);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Purchase an item from a seller's kiosk.\n\t * Returns [item, transferRequest]\n\t * Can be called like: `const [item, transferRequest] = kioskTx.purchase({...})`\n\t * @param itemType The type `T` of the item\n\t * @param itemId The ID of the item\n\t * @param price The price in MIST\n\t * @param sellerKiosk The kiosk which is selling the item. Can be an id or an object argument.\n\t */\n\tpurchase({\n\t\titemType,\n\t\titemId,\n\t\tprice,\n\t\tsellerKiosk,\n\t}: ItemId & Price & { sellerKiosk: ObjectArgument }): [\n\t\tTransactionObjectArgument,\n\t\tTransactionObjectArgument,\n\t] {\n\t\t// Split the coin for the amount of the listing.\n\t\tconst coin = this.transaction.splitCoins(this.transaction.gas, [\n\t\t\tthis.transaction.pure.u64(price),\n\t\t]);\n\t\treturn kioskTx.purchase(this.transaction, itemType, sellerKiosk, itemId, coin);\n\t}\n\n\t/**\n\t * A function to purchase and resolve a transfer policy.\n\t * If the transfer policy has the `lock` rule, the item is locked in the kiosk.\n\t * Otherwise, the item is placed in the kiosk.\n\t * @param itemType The type of the item\n\t * @param itemId The id of the item\n\t * @param price The price of the specified item\n\t * @param sellerKiosk The kiosk which is selling the item. Can be an id or an object argument.\n\t * @param extraArgs Used to pass arguments for custom rule resolvers.\n\t */\n\tasync purchaseAndResolve({\n\t\titemType,\n\t\titemId,\n\t\tprice,\n\t\tsellerKiosk,\n\t\textraArgs,\n\t}: ItemId & Price & { sellerKiosk: ObjectArgument } & PurchaseOptions) {\n\t\tthis.#validateKioskIsSet();\n\t\t// Get a list of the transfer policies.\n\t\tconst policies = await this.kioskClient.getTransferPolicies({ type: itemType });\n\n\t\tif (policies.length === 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`The type ${itemType} doesn't have a Transfer Policy so it can't be traded through kiosk.`,\n\t\t\t);\n\t\t}\n\n\t\tconst policy = policies[0]; // we now pick the first one. We need to add an option to define which one.\n\n\t\t// initialize the purchase `kiosk::purchase`\n\t\tconst [purchasedItem, transferRequest] = this.purchase({\n\t\t\titemType,\n\t\t\titemId,\n\t\t\tprice,\n\t\t\tsellerKiosk,\n\t\t});\n\n\t\tlet canTransferOutsideKiosk = true;\n\n\t\tfor (const rule of policy.rules) {\n\t\t\tconst ruleDefinition = this.kioskClient.rules.find(\n\t\t\t\t(x) => getNormalizedRuleType(x.rule) === getNormalizedRuleType(rule),\n\t\t\t);\n\t\t\tif (!ruleDefinition) throw new Error(`No resolver for the following rule: ${rule}.`);\n\n\t\t\tif (ruleDefinition.hasLockingRule) canTransferOutsideKiosk = false;\n\n\t\t\truleDefinition.resolveRuleFunction({\n\t\t\t\tpackageId: ruleDefinition.packageId,\n\t\t\t\ttransactionBlock: this.transaction,\n\t\t\t\ttransaction: this.transaction,\n\t\t\t\titemType,\n\t\t\t\titemId,\n\t\t\t\tprice: price.toString(),\n\t\t\t\tsellerKiosk,\n\t\t\t\tpolicyId: policy.id,\n\t\t\t\ttransferRequest,\n\t\t\t\tpurchasedItem,\n\t\t\t\tkiosk: this.kiosk!,\n\t\t\t\tkioskCap: this.kioskCap!,\n\t\t\t\textraArgs: extraArgs || {},\n\t\t\t});\n\t\t}\n\n\t\tconfirmRequest(this.transaction, itemType, policy.id, transferRequest);\n\n\t\tif (canTransferOutsideKiosk) this.place({ itemType, item: purchasedItem });\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * A function to setup the client using an existing `ownerCap`,\n\t * as return from the `kioskClient.getOwnedKiosks` function.\n\t * @param cap `KioskOwnerCap` object as returned from `getOwnedKiosks` SDK call.\n\t */\n\tsetCap(cap: KioskOwnerCap) {\n\t\tthis.#validateFinalizedStatus();\n\t\tthis.kiosk = this.transaction.object(cap.kioskId);\n\t\tif (!cap.isPersonal) {\n\t\t\tthis.kioskCap = this.transaction.object(cap.objectId);\n\t\t\treturn;\n\t\t}\n\n\t\treturn this.#borrowFromPersonalCap(cap.objectId);\n\t}\n\n\t/**\n\t *\tA function that ends up the kiosk building tx & returns the `kioskOwnerCap` back to the\n\t * `PersonalKioskCap`, in case we are operating on a personal kiosk.\n\t * \tIt will also share the `kiosk` if it's not shared, and finalize the transfer of the personal cap if it's pending.\n\t */\n\tfinalize() {\n\t\tthis.#validateKioskIsSet();\n\t\t// If we're pending the sharing of the new kiosk, share it.\n\t\tif (this.#pendingShare) this.share();\n\n\t\t// If we're operating on a non-personal kiosk, we don't need to do anything else.\n\t\tif (!this.#personalCap) {\n\t\t\t// If we're pending transfer though, we inform user to call `shareAndTransferCap()`.\n\t\t\tif (this.#pendingTransfer)\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'You need to transfer the `kioskOwnerCap` by calling `shareAndTransferCap()` before wrap',\n\t\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst packageId = this.kioskClient.getRulePackageId('personalKioskRulePackageId');\n\n\t\t// if we have a promise, return the `ownerCap` back to the personal cap.\n\t\tif (this.#promise) {\n\t\t\tthis.transaction.moveCall({\n\t\t\t\ttarget: `${packageId}::personal_kiosk::return_val`,\n\t\t\t\targuments: [this.#personalCap, this.transaction.object(this.kioskCap!), this.#promise!],\n\t\t\t});\n\t\t}\n\n\t\t// If we are pending transferring the personalCap, we do it here.\n\t\tif (this.#pendingTransfer)\n\t\t\ttransferPersonalCapTx(this.transaction, this.#personalCap, packageId);\n\n\t\t// Mark the transaction as finalized, so no other functions can be called.\n\t\tthis.#finalized = true;\n\t}\n\n\t// Some setters in case we want custom behavior.\n\tsetKioskCap(cap: TransactionObjectArgument) {\n\t\tthis.#validateFinalizedStatus();\n\t\tthis.kioskCap = cap;\n\t\treturn this;\n\t}\n\n\tsetKiosk(kiosk: TransactionObjectArgument) {\n\t\tthis.#validateFinalizedStatus();\n\t\tthis.kiosk = kiosk;\n\t\treturn this;\n\t}\n\n\t// Some getters\n\t/*\n\t * Returns the active transaction's kiosk, or undefined if `setCap` or `create()` hasn't been called yet.\n\t */\n\tgetKiosk() {\n\t\tthis.#validateFinalizedStatus();\n\t\tif (!this.kiosk) throw new Error('Kiosk is not set.');\n\t\treturn this.kiosk;\n\t}\n\n\t/*\n\t * Returns the active transaction's kioskOwnerCap, or undefined if `setCap` or `create()` hasn't been called yet.\n\t */\n\tgetKioskCap() {\n\t\tthis.#validateFinalizedStatus();\n\t\tif (!this.kioskCap) throw new Error('Kiosk cap is not set');\n\t\treturn this.kioskCap;\n\t}\n\n\t/**\n\t * A function to borrow from `personalCap`.\n\t */\n\t#borrowFromPersonalCap(personalCap: ObjectArgument) {\n\t\tconst [kioskCap, promise] = this.transaction.moveCall({\n\t\t\ttarget: `${this.kioskClient.getRulePackageId(\n\t\t\t\t'personalKioskRulePackageId',\n\t\t\t)}::personal_kiosk::borrow_val`,\n\t\t\targuments: [this.transaction.object(personalCap)],\n\t\t});\n\n\t\tthis.kioskCap = kioskCap;\n\t\tthis.#personalCap = this.transaction.object(personalCap);\n\t\tthis.#promise = promise;\n\n\t\treturn this;\n\t}\n\n\t#setPendingStatuses({ share, transfer }: { share?: boolean; transfer?: boolean }) {\n\t\tif (transfer !== undefined) this.#pendingTransfer = transfer;\n\t\tif (share !== undefined) this.#pendingShare = share;\n\t}\n\n\t#validateKioskIsSet() {\n\t\tthis.#validateFinalizedStatus();\n\n\t\tif (!this.kiosk || !this.kioskCap)\n\t\t\tthrow new Error(\n\t\t\t\t'You need to initialize the client by either supplying an existing owner cap or by creating a new by calling `.create()`',\n\t\t\t);\n\t}\n\n\t// Validates that `finalize`\n\t#validateFinalizedStatus() {\n\t\tif (this.#finalized)\n\t\t\tthrow new Error(\"You can't add more transactions to a finalized kiosk transaction.\");\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AASA,YAAY,aAAa;AACzB,SAAS,qBAAqB,6BAA6B;AAC3D,SAAS,sBAAsB;AAU/B,SAAS,6BAA6B;AAwB/B,MAAM,iBAAiB;AAAA,EAgB7B,YAAY;AAAA,IACX;AAAA,IACA,cAAc;AAAA,IACd;AAAA,IACA;AAAA,EACD,GAA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B,wBAAK,sDAAL;AAEA,MAAI,CAAC,KAAK,SAAS,CAAC,KAAK;AACxB,UAAM,IAAI;AAAA,MACT;AAAA,IACD;AACF;AAGA;AAAA,6BAAwB,WAAG;AAC1B,MAAI,mBAAK;AACR,UAAM,IAAI,MAAM,mEAAmE;AACrF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Transaction } from '@mysten/sui/transactions';
|
|
2
2
|
import type { ObjectArgument, TransferPolicyCap } from '../types/index.js';
|
|
3
3
|
import type { KioskClient } from './kiosk-client.js';
|
|
4
4
|
export type TransferPolicyBaseParams = {
|
|
@@ -8,17 +8,19 @@ export type TransferPolicyBaseParams = {
|
|
|
8
8
|
};
|
|
9
9
|
export type TransferPolicyTransactionParams = {
|
|
10
10
|
kioskClient: KioskClient;
|
|
11
|
-
|
|
11
|
+
transaction: Transaction;
|
|
12
|
+
/** @deprecated use transaction instead */
|
|
13
|
+
transactionBlock?: Transaction;
|
|
12
14
|
cap?: TransferPolicyCap;
|
|
13
15
|
};
|
|
14
16
|
export declare class TransferPolicyTransaction {
|
|
15
17
|
#private;
|
|
16
|
-
|
|
18
|
+
transaction: Transaction;
|
|
17
19
|
kioskClient: KioskClient;
|
|
18
20
|
policy?: ObjectArgument;
|
|
19
21
|
policyCap?: ObjectArgument;
|
|
20
22
|
type?: string;
|
|
21
|
-
constructor({ kioskClient, transactionBlock, cap }: TransferPolicyTransactionParams);
|
|
23
|
+
constructor({ kioskClient, transactionBlock, transaction, cap, }: TransferPolicyTransactionParams);
|
|
22
24
|
/**
|
|
23
25
|
* A function to create a new transfer policy.
|
|
24
26
|
* Checks if there's already an existing transfer policy to prevent
|
|
@@ -26,7 +26,12 @@ import {
|
|
|
26
26
|
withdrawFromPolicy
|
|
27
27
|
} from "../tx/transfer-policy.js";
|
|
28
28
|
class TransferPolicyTransaction {
|
|
29
|
-
constructor({
|
|
29
|
+
constructor({
|
|
30
|
+
kioskClient,
|
|
31
|
+
transactionBlock,
|
|
32
|
+
transaction = transactionBlock,
|
|
33
|
+
cap
|
|
34
|
+
}) {
|
|
30
35
|
// Internal function that that the policy's Id + Cap + type have been set.
|
|
31
36
|
__privateAdd(this, _validateInputs);
|
|
32
37
|
/**
|
|
@@ -34,7 +39,7 @@ class TransferPolicyTransaction {
|
|
|
34
39
|
*/
|
|
35
40
|
__privateAdd(this, _setup);
|
|
36
41
|
this.kioskClient = kioskClient;
|
|
37
|
-
this.
|
|
42
|
+
this.transaction = transaction;
|
|
38
43
|
if (cap)
|
|
39
44
|
this.setCap(cap);
|
|
40
45
|
}
|
|
@@ -61,8 +66,8 @@ class TransferPolicyTransaction {
|
|
|
61
66
|
if (policies.length > 0)
|
|
62
67
|
throw new Error("There's already transfer policy for this Type.");
|
|
63
68
|
}
|
|
64
|
-
const cap = createTransferPolicy(this.
|
|
65
|
-
this.
|
|
69
|
+
const cap = createTransferPolicy(this.transaction, type, publisher);
|
|
70
|
+
this.transaction.transferObjects([cap], this.transaction.pure.address(address));
|
|
66
71
|
}
|
|
67
72
|
/**
|
|
68
73
|
* A convenient function to create a Transfer Policy and attach some rules
|
|
@@ -83,7 +88,7 @@ class TransferPolicyTransaction {
|
|
|
83
88
|
throw new Error("There's already transfer policy for this Type.");
|
|
84
89
|
}
|
|
85
90
|
const [policy, policyCap] = createTransferPolicyWithoutSharing(
|
|
86
|
-
this.
|
|
91
|
+
this.transaction,
|
|
87
92
|
type,
|
|
88
93
|
publisher
|
|
89
94
|
);
|
|
@@ -99,10 +104,10 @@ class TransferPolicyTransaction {
|
|
|
99
104
|
shareAndTransferCap(address) {
|
|
100
105
|
if (!this.type || !this.policyCap || !this.policy)
|
|
101
106
|
throw new Error("This function can only be called after `transferPolicyManager.create`");
|
|
102
|
-
shareTransferPolicy(this.
|
|
103
|
-
this.
|
|
107
|
+
shareTransferPolicy(this.transaction, this.type, this.policy);
|
|
108
|
+
this.transaction.transferObjects(
|
|
104
109
|
[this.policyCap],
|
|
105
|
-
this.
|
|
110
|
+
this.transaction.pure.address(address)
|
|
106
111
|
);
|
|
107
112
|
}
|
|
108
113
|
/**
|
|
@@ -121,13 +126,13 @@ class TransferPolicyTransaction {
|
|
|
121
126
|
withdraw(address, amount) {
|
|
122
127
|
__privateMethod(this, _validateInputs, validateInputs_fn).call(this);
|
|
123
128
|
const coin = withdrawFromPolicy(
|
|
124
|
-
this.
|
|
129
|
+
this.transaction,
|
|
125
130
|
this.type,
|
|
126
131
|
this.policy,
|
|
127
132
|
this.policyCap,
|
|
128
133
|
amount
|
|
129
134
|
);
|
|
130
|
-
this.
|
|
135
|
+
this.transaction.transferObjects([coin], this.transaction.pure.address(address));
|
|
131
136
|
return this;
|
|
132
137
|
}
|
|
133
138
|
/**
|
|
@@ -143,7 +148,7 @@ class TransferPolicyTransaction {
|
|
|
143
148
|
addRoyaltyRule(percentageBps, minAmount) {
|
|
144
149
|
__privateMethod(this, _validateInputs, validateInputs_fn).call(this);
|
|
145
150
|
attachRoyaltyRuleTx(
|
|
146
|
-
this.
|
|
151
|
+
this.transaction,
|
|
147
152
|
this.type,
|
|
148
153
|
this.policy,
|
|
149
154
|
this.policyCap,
|
|
@@ -160,7 +165,7 @@ class TransferPolicyTransaction {
|
|
|
160
165
|
addLockRule() {
|
|
161
166
|
__privateMethod(this, _validateInputs, validateInputs_fn).call(this);
|
|
162
167
|
attachKioskLockRuleTx(
|
|
163
|
-
this.
|
|
168
|
+
this.transaction,
|
|
164
169
|
this.type,
|
|
165
170
|
this.policy,
|
|
166
171
|
this.policyCap,
|
|
@@ -174,7 +179,7 @@ class TransferPolicyTransaction {
|
|
|
174
179
|
addPersonalKioskRule() {
|
|
175
180
|
__privateMethod(this, _validateInputs, validateInputs_fn).call(this);
|
|
176
181
|
attachPersonalKioskRuleTx(
|
|
177
|
-
this.
|
|
182
|
+
this.transaction,
|
|
178
183
|
this.type,
|
|
179
184
|
this.policy,
|
|
180
185
|
this.policyCap,
|
|
@@ -189,7 +194,7 @@ class TransferPolicyTransaction {
|
|
|
189
194
|
addFloorPriceRule(minPrice) {
|
|
190
195
|
__privateMethod(this, _validateInputs, validateInputs_fn).call(this);
|
|
191
196
|
attachFloorPriceRuleTx(
|
|
192
|
-
this.
|
|
197
|
+
this.transaction,
|
|
193
198
|
this.type,
|
|
194
199
|
this.policy,
|
|
195
200
|
this.policyCap,
|
|
@@ -206,7 +211,7 @@ class TransferPolicyTransaction {
|
|
|
206
211
|
removeRule({ ruleType, configType }) {
|
|
207
212
|
__privateMethod(this, _validateInputs, validateInputs_fn).call(this);
|
|
208
213
|
removeTransferPolicyRule(
|
|
209
|
-
this.
|
|
214
|
+
this.transaction,
|
|
210
215
|
this.type,
|
|
211
216
|
ruleType,
|
|
212
217
|
configType,
|
|
@@ -221,7 +226,7 @@ class TransferPolicyTransaction {
|
|
|
221
226
|
__privateMethod(this, _validateInputs, validateInputs_fn).call(this);
|
|
222
227
|
const packageId = this.kioskClient.getRulePackageId("kioskLockRulePackageId");
|
|
223
228
|
removeTransferPolicyRule(
|
|
224
|
-
this.
|
|
229
|
+
this.transaction,
|
|
225
230
|
this.type,
|
|
226
231
|
`${packageId}::kiosk_lock_rule::Rule`,
|
|
227
232
|
`${packageId}::kiosk_lock_rule::Config`,
|
|
@@ -237,7 +242,7 @@ class TransferPolicyTransaction {
|
|
|
237
242
|
__privateMethod(this, _validateInputs, validateInputs_fn).call(this);
|
|
238
243
|
const packageId = this.kioskClient.getRulePackageId("royaltyRulePackageId");
|
|
239
244
|
removeTransferPolicyRule(
|
|
240
|
-
this.
|
|
245
|
+
this.transaction,
|
|
241
246
|
this.type,
|
|
242
247
|
`${packageId}::royalty_rule::Rule`,
|
|
243
248
|
`${packageId}::royalty_rule::Config`,
|
|
@@ -250,7 +255,7 @@ class TransferPolicyTransaction {
|
|
|
250
255
|
__privateMethod(this, _validateInputs, validateInputs_fn).call(this);
|
|
251
256
|
const packageId = this.kioskClient.getRulePackageId("personalKioskRulePackageId");
|
|
252
257
|
removeTransferPolicyRule(
|
|
253
|
-
this.
|
|
258
|
+
this.transaction,
|
|
254
259
|
this.type,
|
|
255
260
|
`${packageId}::personal_kiosk_rule::Rule`,
|
|
256
261
|
`bool`,
|
|
@@ -263,7 +268,7 @@ class TransferPolicyTransaction {
|
|
|
263
268
|
__privateMethod(this, _validateInputs, validateInputs_fn).call(this);
|
|
264
269
|
const packageId = this.kioskClient.getRulePackageId("floorPriceRulePackageId");
|
|
265
270
|
removeTransferPolicyRule(
|
|
266
|
-
this.
|
|
271
|
+
this.transaction,
|
|
267
272
|
this.type,
|
|
268
273
|
`${packageId}::floor_price_rule::Rule`,
|
|
269
274
|
`${packageId}::floor_price_rule::Config`,
|