@mysten/kiosk 0.8.10 → 0.9.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 +20 -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
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import type {
|
|
5
|
+
Transaction,
|
|
5
6
|
TransactionArgument,
|
|
6
|
-
TransactionBlock,
|
|
7
7
|
TransactionObjectArgument,
|
|
8
|
-
} from '@mysten/sui
|
|
8
|
+
} from '@mysten/sui/transactions';
|
|
9
9
|
|
|
10
10
|
import * as kioskTx from '../tx/kiosk.js';
|
|
11
11
|
import { convertToPersonalTx, transferPersonalCapTx } from '../tx/personal-kiosk.js';
|
|
@@ -23,8 +23,11 @@ import { getNormalizedRuleType } from '../utils.js';
|
|
|
23
23
|
import type { KioskClient } from './kiosk-client.js';
|
|
24
24
|
|
|
25
25
|
export type KioskTransactionParams = {
|
|
26
|
-
/** The
|
|
27
|
-
|
|
26
|
+
/** The Transaction for this run */
|
|
27
|
+
transaction: Transaction;
|
|
28
|
+
|
|
29
|
+
/** @deprecated use transaction instead */
|
|
30
|
+
transactionBlock?: Transaction;
|
|
28
31
|
/**
|
|
29
32
|
* You can create a new KioskClient by calling `new KioskClient()`
|
|
30
33
|
*/
|
|
@@ -41,7 +44,7 @@ export type KioskTransactionParams = {
|
|
|
41
44
|
* A helper for building transactions that involve kiosk.
|
|
42
45
|
*/
|
|
43
46
|
export class KioskTransaction {
|
|
44
|
-
|
|
47
|
+
transaction: Transaction;
|
|
45
48
|
kioskClient: KioskClient;
|
|
46
49
|
kiosk?: TransactionObjectArgument;
|
|
47
50
|
kioskCap?: TransactionObjectArgument;
|
|
@@ -56,8 +59,13 @@ export class KioskTransaction {
|
|
|
56
59
|
// A flag that checks whether kiosk TX is finalized.
|
|
57
60
|
#finalized: boolean = false;
|
|
58
61
|
|
|
59
|
-
constructor({
|
|
60
|
-
|
|
62
|
+
constructor({
|
|
63
|
+
transactionBlock,
|
|
64
|
+
transaction = transactionBlock!,
|
|
65
|
+
kioskClient,
|
|
66
|
+
cap,
|
|
67
|
+
}: KioskTransactionParams) {
|
|
68
|
+
this.transaction = transaction;
|
|
61
69
|
this.kioskClient = kioskClient;
|
|
62
70
|
|
|
63
71
|
if (cap) this.setCap(cap);
|
|
@@ -74,7 +82,7 @@ export class KioskTransaction {
|
|
|
74
82
|
share: true,
|
|
75
83
|
transfer: true,
|
|
76
84
|
});
|
|
77
|
-
const [kiosk, cap] = kioskTx.createKiosk(this.
|
|
85
|
+
const [kiosk, cap] = kioskTx.createKiosk(this.transaction);
|
|
78
86
|
this.kiosk = kiosk;
|
|
79
87
|
this.kioskCap = cap;
|
|
80
88
|
return this;
|
|
@@ -98,7 +106,7 @@ export class KioskTransaction {
|
|
|
98
106
|
this.#validateKioskIsSet();
|
|
99
107
|
|
|
100
108
|
const cap = convertToPersonalTx(
|
|
101
|
-
this.
|
|
109
|
+
this.transaction,
|
|
102
110
|
this.kiosk!,
|
|
103
111
|
this.kioskCap!,
|
|
104
112
|
this.kioskClient.getRulePackageId('personalKioskRulePackageId'),
|
|
@@ -117,8 +125,8 @@ export class KioskTransaction {
|
|
|
117
125
|
*/
|
|
118
126
|
createAndShare(address: string) {
|
|
119
127
|
this.#validateFinalizedStatus();
|
|
120
|
-
const cap = kioskTx.createKioskAndShare(this.
|
|
121
|
-
this.
|
|
128
|
+
const cap = kioskTx.createKioskAndShare(this.transaction);
|
|
129
|
+
this.transaction.transferObjects([cap], this.transaction.pure.address(address));
|
|
122
130
|
}
|
|
123
131
|
|
|
124
132
|
/**
|
|
@@ -127,7 +135,7 @@ export class KioskTransaction {
|
|
|
127
135
|
share() {
|
|
128
136
|
this.#validateKioskIsSet();
|
|
129
137
|
this.#setPendingStatuses({ share: false });
|
|
130
|
-
kioskTx.shareKiosk(this.
|
|
138
|
+
kioskTx.shareKiosk(this.transaction, this.kiosk!);
|
|
131
139
|
}
|
|
132
140
|
|
|
133
141
|
/**
|
|
@@ -139,10 +147,7 @@ export class KioskTransaction {
|
|
|
139
147
|
throw new Error('You can only call `shareAndTransferCap` on a non-personal kiosk.');
|
|
140
148
|
this.#setPendingStatuses({ transfer: false });
|
|
141
149
|
this.share();
|
|
142
|
-
this.
|
|
143
|
-
[this.kioskCap!],
|
|
144
|
-
this.transactionBlock.pure.address(address),
|
|
145
|
-
);
|
|
150
|
+
this.transaction.transferObjects([this.kioskCap!], this.transaction.pure.address(address));
|
|
146
151
|
}
|
|
147
152
|
|
|
148
153
|
/**
|
|
@@ -152,7 +157,7 @@ export class KioskTransaction {
|
|
|
152
157
|
borrowTx({ itemType, itemId }: ItemId, callback: (item: TransactionArgument) => void) {
|
|
153
158
|
this.#validateKioskIsSet();
|
|
154
159
|
const [itemObj, promise] = kioskTx.borrowValue(
|
|
155
|
-
this.
|
|
160
|
+
this.transaction,
|
|
156
161
|
itemType,
|
|
157
162
|
this.kiosk!,
|
|
158
163
|
this.kioskCap!,
|
|
@@ -173,7 +178,7 @@ export class KioskTransaction {
|
|
|
173
178
|
borrow({ itemType, itemId }: ItemId): [TransactionArgument, TransactionArgument] {
|
|
174
179
|
this.#validateKioskIsSet();
|
|
175
180
|
const [itemObj, promise] = kioskTx.borrowValue(
|
|
176
|
-
this.
|
|
181
|
+
this.transaction,
|
|
177
182
|
itemType,
|
|
178
183
|
this.kiosk!,
|
|
179
184
|
this.kioskCap!,
|
|
@@ -189,7 +194,7 @@ export class KioskTransaction {
|
|
|
189
194
|
*/
|
|
190
195
|
return({ itemType, item, promise }: ItemValue & { promise: TransactionArgument }) {
|
|
191
196
|
this.#validateKioskIsSet();
|
|
192
|
-
kioskTx.returnValue(this.
|
|
197
|
+
kioskTx.returnValue(this.transaction, itemType, this.kiosk!, item, promise);
|
|
193
198
|
return this;
|
|
194
199
|
}
|
|
195
200
|
|
|
@@ -200,13 +205,8 @@ export class KioskTransaction {
|
|
|
200
205
|
*/
|
|
201
206
|
withdraw(address: string, amount?: string | bigint | number) {
|
|
202
207
|
this.#validateKioskIsSet();
|
|
203
|
-
const coin = kioskTx.withdrawFromKiosk(
|
|
204
|
-
|
|
205
|
-
this.kiosk!,
|
|
206
|
-
this.kioskCap!,
|
|
207
|
-
amount,
|
|
208
|
-
);
|
|
209
|
-
this.transactionBlock.transferObjects([coin], this.transactionBlock.pure.address(address));
|
|
208
|
+
const coin = kioskTx.withdrawFromKiosk(this.transaction, this.kiosk!, this.kioskCap!, amount);
|
|
209
|
+
this.transaction.transferObjects([coin], this.transaction.pure.address(address));
|
|
210
210
|
return this;
|
|
211
211
|
}
|
|
212
212
|
|
|
@@ -217,7 +217,7 @@ export class KioskTransaction {
|
|
|
217
217
|
*/
|
|
218
218
|
place({ itemType, item }: ItemReference) {
|
|
219
219
|
this.#validateKioskIsSet();
|
|
220
|
-
kioskTx.place(this.
|
|
220
|
+
kioskTx.place(this.transaction, itemType, this.kiosk!, this.kioskCap!, item);
|
|
221
221
|
return this;
|
|
222
222
|
}
|
|
223
223
|
|
|
@@ -229,7 +229,7 @@ export class KioskTransaction {
|
|
|
229
229
|
*/
|
|
230
230
|
placeAndList({ itemType, item, price }: ItemReference & Price) {
|
|
231
231
|
this.#validateKioskIsSet();
|
|
232
|
-
kioskTx.placeAndList(this.
|
|
232
|
+
kioskTx.placeAndList(this.transaction, itemType, this.kiosk!, this.kioskCap!, item, price);
|
|
233
233
|
return this;
|
|
234
234
|
}
|
|
235
235
|
|
|
@@ -241,7 +241,7 @@ export class KioskTransaction {
|
|
|
241
241
|
*/
|
|
242
242
|
list({ itemType, itemId, price }: ItemId & { price: string | bigint }) {
|
|
243
243
|
this.#validateKioskIsSet();
|
|
244
|
-
kioskTx.list(this.
|
|
244
|
+
kioskTx.list(this.transaction, itemType, this.kiosk!, this.kioskCap!, itemId, price);
|
|
245
245
|
return this;
|
|
246
246
|
}
|
|
247
247
|
|
|
@@ -252,7 +252,7 @@ export class KioskTransaction {
|
|
|
252
252
|
*/
|
|
253
253
|
delist({ itemType, itemId }: ItemId) {
|
|
254
254
|
this.#validateKioskIsSet();
|
|
255
|
-
kioskTx.delist(this.
|
|
255
|
+
kioskTx.delist(this.transaction, itemType, this.kiosk!, this.kioskCap!, itemId);
|
|
256
256
|
return this;
|
|
257
257
|
}
|
|
258
258
|
|
|
@@ -264,7 +264,7 @@ export class KioskTransaction {
|
|
|
264
264
|
*/
|
|
265
265
|
take({ itemType, itemId }: ItemId): TransactionObjectArgument {
|
|
266
266
|
this.#validateKioskIsSet();
|
|
267
|
-
return kioskTx.take(this.
|
|
267
|
+
return kioskTx.take(this.transaction, itemType, this.kiosk!, this.kioskCap!, itemId);
|
|
268
268
|
}
|
|
269
269
|
|
|
270
270
|
/**
|
|
@@ -277,7 +277,7 @@ export class KioskTransaction {
|
|
|
277
277
|
transfer({ itemType, itemId, address }: ItemId & { address: string }) {
|
|
278
278
|
this.#validateKioskIsSet();
|
|
279
279
|
const item = this.take({ itemType, itemId });
|
|
280
|
-
this.
|
|
280
|
+
this.transaction.transferObjects([item], this.transaction.pure.address(address));
|
|
281
281
|
return this;
|
|
282
282
|
}
|
|
283
283
|
|
|
@@ -296,14 +296,7 @@ export class KioskTransaction {
|
|
|
296
296
|
policy,
|
|
297
297
|
}: ItemReference & { policy: ObjectArgument; itemId?: string }) {
|
|
298
298
|
this.#validateKioskIsSet();
|
|
299
|
-
kioskTx.lock(
|
|
300
|
-
this.transactionBlock,
|
|
301
|
-
itemType,
|
|
302
|
-
this.kiosk!,
|
|
303
|
-
this.kioskCap!,
|
|
304
|
-
policy,
|
|
305
|
-
itemId ?? item,
|
|
306
|
-
);
|
|
299
|
+
kioskTx.lock(this.transaction, itemType, this.kiosk!, this.kioskCap!, policy, itemId ?? item);
|
|
307
300
|
return this;
|
|
308
301
|
}
|
|
309
302
|
|
|
@@ -326,10 +319,10 @@ export class KioskTransaction {
|
|
|
326
319
|
TransactionObjectArgument,
|
|
327
320
|
] {
|
|
328
321
|
// Split the coin for the amount of the listing.
|
|
329
|
-
const coin = this.
|
|
330
|
-
this.
|
|
322
|
+
const coin = this.transaction.splitCoins(this.transaction.gas, [
|
|
323
|
+
this.transaction.pure.u64(price),
|
|
331
324
|
]);
|
|
332
|
-
return kioskTx.purchase(this.
|
|
325
|
+
return kioskTx.purchase(this.transaction, itemType, sellerKiosk, itemId, coin);
|
|
333
326
|
}
|
|
334
327
|
|
|
335
328
|
/**
|
|
@@ -381,7 +374,8 @@ export class KioskTransaction {
|
|
|
381
374
|
|
|
382
375
|
ruleDefinition.resolveRuleFunction({
|
|
383
376
|
packageId: ruleDefinition.packageId,
|
|
384
|
-
transactionBlock: this.
|
|
377
|
+
transactionBlock: this.transaction,
|
|
378
|
+
transaction: this.transaction,
|
|
385
379
|
itemType,
|
|
386
380
|
itemId,
|
|
387
381
|
price: price.toString(),
|
|
@@ -395,7 +389,7 @@ export class KioskTransaction {
|
|
|
395
389
|
});
|
|
396
390
|
}
|
|
397
391
|
|
|
398
|
-
confirmRequest(this.
|
|
392
|
+
confirmRequest(this.transaction, itemType, policy.id, transferRequest);
|
|
399
393
|
|
|
400
394
|
if (canTransferOutsideKiosk) this.place({ itemType, item: purchasedItem });
|
|
401
395
|
|
|
@@ -409,9 +403,9 @@ export class KioskTransaction {
|
|
|
409
403
|
*/
|
|
410
404
|
setCap(cap: KioskOwnerCap) {
|
|
411
405
|
this.#validateFinalizedStatus();
|
|
412
|
-
this.kiosk = this.
|
|
406
|
+
this.kiosk = this.transaction.object(cap.kioskId);
|
|
413
407
|
if (!cap.isPersonal) {
|
|
414
|
-
this.kioskCap = this.
|
|
408
|
+
this.kioskCap = this.transaction.object(cap.objectId);
|
|
415
409
|
return;
|
|
416
410
|
}
|
|
417
411
|
|
|
@@ -419,7 +413,7 @@ export class KioskTransaction {
|
|
|
419
413
|
}
|
|
420
414
|
|
|
421
415
|
/**
|
|
422
|
-
* A function that ends up the kiosk building
|
|
416
|
+
* A function that ends up the kiosk building tx & returns the `kioskOwnerCap` back to the
|
|
423
417
|
* `PersonalKioskCap`, in case we are operating on a personal kiosk.
|
|
424
418
|
* It will also share the `kiosk` if it's not shared, and finalize the transfer of the personal cap if it's pending.
|
|
425
419
|
*/
|
|
@@ -442,21 +436,17 @@ export class KioskTransaction {
|
|
|
442
436
|
|
|
443
437
|
// if we have a promise, return the `ownerCap` back to the personal cap.
|
|
444
438
|
if (this.#promise) {
|
|
445
|
-
this.
|
|
439
|
+
this.transaction.moveCall({
|
|
446
440
|
target: `${packageId}::personal_kiosk::return_val`,
|
|
447
|
-
arguments: [
|
|
448
|
-
this.#personalCap,
|
|
449
|
-
this.transactionBlock.object(this.kioskCap!),
|
|
450
|
-
this.#promise!,
|
|
451
|
-
],
|
|
441
|
+
arguments: [this.#personalCap, this.transaction.object(this.kioskCap!), this.#promise!],
|
|
452
442
|
});
|
|
453
443
|
}
|
|
454
444
|
|
|
455
445
|
// If we are pending transferring the personalCap, we do it here.
|
|
456
446
|
if (this.#pendingTransfer)
|
|
457
|
-
transferPersonalCapTx(this.
|
|
447
|
+
transferPersonalCapTx(this.transaction, this.#personalCap, packageId);
|
|
458
448
|
|
|
459
|
-
// Mark the transaction
|
|
449
|
+
// Mark the transaction as finalized, so no other functions can be called.
|
|
460
450
|
this.#finalized = true;
|
|
461
451
|
}
|
|
462
452
|
|
|
@@ -496,15 +486,15 @@ export class KioskTransaction {
|
|
|
496
486
|
* A function to borrow from `personalCap`.
|
|
497
487
|
*/
|
|
498
488
|
#borrowFromPersonalCap(personalCap: ObjectArgument) {
|
|
499
|
-
const [kioskCap, promise] = this.
|
|
489
|
+
const [kioskCap, promise] = this.transaction.moveCall({
|
|
500
490
|
target: `${this.kioskClient.getRulePackageId(
|
|
501
491
|
'personalKioskRulePackageId',
|
|
502
492
|
)}::personal_kiosk::borrow_val`,
|
|
503
|
-
arguments: [this.
|
|
493
|
+
arguments: [this.transaction.object(personalCap)],
|
|
504
494
|
});
|
|
505
495
|
|
|
506
496
|
this.kioskCap = kioskCap;
|
|
507
|
-
this.#personalCap = this.
|
|
497
|
+
this.#personalCap = this.transaction.object(personalCap);
|
|
508
498
|
this.#promise = promise;
|
|
509
499
|
|
|
510
500
|
return this;
|
|
@@ -527,6 +517,6 @@ export class KioskTransaction {
|
|
|
527
517
|
// Validates that `finalize`
|
|
528
518
|
#validateFinalizedStatus() {
|
|
529
519
|
if (this.#finalized)
|
|
530
|
-
throw new Error("You can't add more transactions to a finalized kiosk transaction
|
|
520
|
+
throw new Error("You can't add more transactions to a finalized kiosk transaction.");
|
|
531
521
|
}
|
|
532
522
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
7
|
attachFloorPriceRuleTx,
|
|
@@ -27,20 +27,27 @@ export type TransferPolicyBaseParams = {
|
|
|
27
27
|
|
|
28
28
|
export type TransferPolicyTransactionParams = {
|
|
29
29
|
kioskClient: KioskClient;
|
|
30
|
-
|
|
30
|
+
transaction: Transaction;
|
|
31
|
+
/** @deprecated use transaction instead */
|
|
32
|
+
transactionBlock?: Transaction;
|
|
31
33
|
cap?: TransferPolicyCap;
|
|
32
34
|
};
|
|
33
35
|
|
|
34
36
|
export class TransferPolicyTransaction {
|
|
35
|
-
|
|
37
|
+
transaction: Transaction;
|
|
36
38
|
kioskClient: KioskClient;
|
|
37
39
|
policy?: ObjectArgument;
|
|
38
40
|
policyCap?: ObjectArgument;
|
|
39
41
|
type?: string;
|
|
40
42
|
|
|
41
|
-
constructor({
|
|
43
|
+
constructor({
|
|
44
|
+
kioskClient,
|
|
45
|
+
transactionBlock,
|
|
46
|
+
transaction = transactionBlock!,
|
|
47
|
+
cap,
|
|
48
|
+
}: TransferPolicyTransactionParams) {
|
|
42
49
|
this.kioskClient = kioskClient;
|
|
43
|
-
this.
|
|
50
|
+
this.transaction = transaction;
|
|
44
51
|
if (cap) this.setCap(cap);
|
|
45
52
|
}
|
|
46
53
|
|
|
@@ -68,8 +75,8 @@ export class TransferPolicyTransaction {
|
|
|
68
75
|
const policies = await this.kioskClient.getTransferPolicies({ type });
|
|
69
76
|
if (policies.length > 0) throw new Error("There's already transfer policy for this Type.");
|
|
70
77
|
}
|
|
71
|
-
const cap = createTransferPolicy(this.
|
|
72
|
-
this.
|
|
78
|
+
const cap = createTransferPolicy(this.transaction, type, publisher);
|
|
79
|
+
this.transaction.transferObjects([cap], this.transaction.pure.address(address));
|
|
73
80
|
}
|
|
74
81
|
|
|
75
82
|
/**
|
|
@@ -90,7 +97,7 @@ export class TransferPolicyTransaction {
|
|
|
90
97
|
if (policies.length > 0) throw new Error("There's already transfer policy for this Type.");
|
|
91
98
|
}
|
|
92
99
|
const [policy, policyCap] = createTransferPolicyWithoutSharing(
|
|
93
|
-
this.
|
|
100
|
+
this.transaction,
|
|
94
101
|
type,
|
|
95
102
|
publisher,
|
|
96
103
|
);
|
|
@@ -109,10 +116,10 @@ export class TransferPolicyTransaction {
|
|
|
109
116
|
if (!this.type || !this.policyCap || !this.policy)
|
|
110
117
|
throw new Error('This function can only be called after `transferPolicyManager.create`');
|
|
111
118
|
|
|
112
|
-
shareTransferPolicy(this.
|
|
113
|
-
this.
|
|
119
|
+
shareTransferPolicy(this.transaction, this.type, this.policy as TransactionObjectArgument);
|
|
120
|
+
this.transaction.transferObjects(
|
|
114
121
|
[this.policyCap as TransactionObjectArgument],
|
|
115
|
-
this.
|
|
122
|
+
this.transaction.pure.address(address),
|
|
116
123
|
);
|
|
117
124
|
}
|
|
118
125
|
|
|
@@ -134,14 +141,14 @@ export class TransferPolicyTransaction {
|
|
|
134
141
|
this.#validateInputs();
|
|
135
142
|
// Withdraw coin for specified amount (or none)
|
|
136
143
|
const coin = withdrawFromPolicy(
|
|
137
|
-
this.
|
|
144
|
+
this.transaction,
|
|
138
145
|
this.type!,
|
|
139
146
|
this.policy!,
|
|
140
147
|
this.policyCap!,
|
|
141
148
|
amount,
|
|
142
149
|
);
|
|
143
150
|
|
|
144
|
-
this.
|
|
151
|
+
this.transaction.transferObjects([coin], this.transaction.pure.address(address));
|
|
145
152
|
|
|
146
153
|
return this;
|
|
147
154
|
}
|
|
@@ -166,7 +173,7 @@ export class TransferPolicyTransaction {
|
|
|
166
173
|
// Also, it's hard to keep versioning as with network wipes, mainnet
|
|
167
174
|
// and testnet will conflict.
|
|
168
175
|
attachRoyaltyRuleTx(
|
|
169
|
-
this.
|
|
176
|
+
this.transaction,
|
|
170
177
|
this.type!,
|
|
171
178
|
this.policy!,
|
|
172
179
|
this.policyCap!,
|
|
@@ -185,7 +192,7 @@ export class TransferPolicyTransaction {
|
|
|
185
192
|
this.#validateInputs();
|
|
186
193
|
|
|
187
194
|
attachKioskLockRuleTx(
|
|
188
|
-
this.
|
|
195
|
+
this.transaction,
|
|
189
196
|
this.type!,
|
|
190
197
|
this.policy!,
|
|
191
198
|
this.policyCap!,
|
|
@@ -201,7 +208,7 @@ export class TransferPolicyTransaction {
|
|
|
201
208
|
this.#validateInputs();
|
|
202
209
|
|
|
203
210
|
attachPersonalKioskRuleTx(
|
|
204
|
-
this.
|
|
211
|
+
this.transaction,
|
|
205
212
|
this.type!,
|
|
206
213
|
this.policy!,
|
|
207
214
|
this.policyCap!,
|
|
@@ -218,7 +225,7 @@ export class TransferPolicyTransaction {
|
|
|
218
225
|
this.#validateInputs();
|
|
219
226
|
|
|
220
227
|
attachFloorPriceRuleTx(
|
|
221
|
-
this.
|
|
228
|
+
this.transaction,
|
|
222
229
|
this.type!,
|
|
223
230
|
this.policy!,
|
|
224
231
|
this.policyCap!,
|
|
@@ -237,7 +244,7 @@ export class TransferPolicyTransaction {
|
|
|
237
244
|
this.#validateInputs();
|
|
238
245
|
|
|
239
246
|
removeTransferPolicyRule(
|
|
240
|
-
this.
|
|
247
|
+
this.transaction,
|
|
241
248
|
this.type!,
|
|
242
249
|
ruleType,
|
|
243
250
|
configType,
|
|
@@ -255,7 +262,7 @@ export class TransferPolicyTransaction {
|
|
|
255
262
|
const packageId = this.kioskClient.getRulePackageId('kioskLockRulePackageId');
|
|
256
263
|
|
|
257
264
|
removeTransferPolicyRule(
|
|
258
|
-
this.
|
|
265
|
+
this.transaction,
|
|
259
266
|
this.type!,
|
|
260
267
|
`${packageId}::kiosk_lock_rule::Rule`,
|
|
261
268
|
`${packageId}::kiosk_lock_rule::Config`,
|
|
@@ -274,7 +281,7 @@ export class TransferPolicyTransaction {
|
|
|
274
281
|
const packageId = this.kioskClient.getRulePackageId('royaltyRulePackageId');
|
|
275
282
|
|
|
276
283
|
removeTransferPolicyRule(
|
|
277
|
-
this.
|
|
284
|
+
this.transaction,
|
|
278
285
|
this.type!,
|
|
279
286
|
`${packageId}::royalty_rule::Rule`,
|
|
280
287
|
`${packageId}::royalty_rule::Config`,
|
|
@@ -290,7 +297,7 @@ export class TransferPolicyTransaction {
|
|
|
290
297
|
const packageId = this.kioskClient.getRulePackageId('personalKioskRulePackageId');
|
|
291
298
|
|
|
292
299
|
removeTransferPolicyRule(
|
|
293
|
-
this.
|
|
300
|
+
this.transaction,
|
|
294
301
|
this.type!,
|
|
295
302
|
`${packageId}::personal_kiosk_rule::Rule`,
|
|
296
303
|
`bool`,
|
|
@@ -306,7 +313,7 @@ export class TransferPolicyTransaction {
|
|
|
306
313
|
const packageId = this.kioskClient.getRulePackageId('floorPriceRulePackageId');
|
|
307
314
|
|
|
308
315
|
removeTransferPolicyRule(
|
|
309
|
-
this.
|
|
316
|
+
this.transaction,
|
|
310
317
|
this.type!,
|
|
311
318
|
`${packageId}::floor_price_rule::Rule`,
|
|
312
319
|
`${packageId}::floor_price_rule::Config`,
|
package/src/query/kiosk.ts
CHANGED
|
@@ -7,8 +7,8 @@ import type {
|
|
|
7
7
|
SuiObjectData,
|
|
8
8
|
SuiObjectDataFilter,
|
|
9
9
|
SuiObjectResponse,
|
|
10
|
-
} from '@mysten/sui
|
|
11
|
-
import { isValidSuiAddress } from '@mysten/sui
|
|
10
|
+
} from '@mysten/sui/client';
|
|
11
|
+
import { isValidSuiAddress } from '@mysten/sui/utils';
|
|
12
12
|
|
|
13
13
|
import type {
|
|
14
14
|
FetchKioskOptions,
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import type { SuiClient } from '@mysten/sui
|
|
5
|
-
import { isValidSuiAddress } from '@mysten/sui
|
|
4
|
+
import type { SuiClient } from '@mysten/sui/client';
|
|
5
|
+
import { fromB64, isValidSuiAddress } from '@mysten/sui/utils';
|
|
6
6
|
|
|
7
|
-
import
|
|
7
|
+
import '../bcs.js';
|
|
8
|
+
|
|
9
|
+
import { TransferPolicyType } from '../bcs.js';
|
|
8
10
|
import type { TransferPolicy, TransferPolicyCap } from '../types/index.js';
|
|
9
11
|
import {
|
|
10
12
|
TRANSFER_POLICY_CAP_TYPE,
|
|
@@ -48,7 +50,7 @@ export async function queryTransferPolicy(
|
|
|
48
50
|
throw new Error(`Invalid policy: ${policy?.objectId}, expected object, got package`);
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
const parsed =
|
|
53
|
+
const parsed = TransferPolicyType.parse(fromB64(policy.bcs.bcsBytes));
|
|
52
54
|
|
|
53
55
|
return {
|
|
54
56
|
id: policy?.objectId,
|
package/src/tx/kiosk.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { bcs } from '@mysten/sui
|
|
4
|
+
import { bcs } from '@mysten/sui/bcs';
|
|
5
5
|
import type {
|
|
6
|
+
Transaction,
|
|
6
7
|
TransactionArgument,
|
|
7
|
-
TransactionBlock,
|
|
8
8
|
TransactionObjectArgument,
|
|
9
|
-
} from '@mysten/sui
|
|
9
|
+
} from '@mysten/sui/transactions';
|
|
10
10
|
|
|
11
11
|
import type { ObjectArgument } from '../types/index.js';
|
|
12
12
|
import { KIOSK_MODULE, KIOSK_TYPE } from '../types/index.js';
|
|
@@ -15,7 +15,7 @@ import { KIOSK_MODULE, KIOSK_TYPE } from '../types/index.js';
|
|
|
15
15
|
* Create a new shared Kiosk and returns the [kiosk, kioskOwnerCap] tuple.
|
|
16
16
|
*/
|
|
17
17
|
export function createKiosk(
|
|
18
|
-
tx:
|
|
18
|
+
tx: Transaction,
|
|
19
19
|
): [TransactionObjectArgument, TransactionObjectArgument] {
|
|
20
20
|
const [kiosk, kioskOwnerCap] = tx.moveCall({
|
|
21
21
|
target: `${KIOSK_MODULE}::new`,
|
|
@@ -28,7 +28,7 @@ export function createKiosk(
|
|
|
28
28
|
* Calls the `kiosk::new()` function and shares the kiosk.
|
|
29
29
|
* Returns the `kioskOwnerCap` object.
|
|
30
30
|
*/
|
|
31
|
-
export function createKioskAndShare(tx:
|
|
31
|
+
export function createKioskAndShare(tx: Transaction): TransactionObjectArgument {
|
|
32
32
|
const [kiosk, kioskOwnerCap] = createKiosk(tx);
|
|
33
33
|
shareKiosk(tx, kiosk);
|
|
34
34
|
return kioskOwnerCap;
|
|
@@ -37,7 +37,7 @@ export function createKioskAndShare(tx: TransactionBlock): TransactionObjectArgu
|
|
|
37
37
|
/**
|
|
38
38
|
* Converts Transfer Policy to a shared object.
|
|
39
39
|
*/
|
|
40
|
-
export function shareKiosk(tx:
|
|
40
|
+
export function shareKiosk(tx: Transaction, kiosk: TransactionArgument) {
|
|
41
41
|
tx.moveCall({
|
|
42
42
|
target: `0x2::transfer::public_share_object`,
|
|
43
43
|
typeArguments: [KIOSK_TYPE],
|
|
@@ -50,7 +50,7 @@ export function shareKiosk(tx: TransactionBlock, kiosk: TransactionArgument) {
|
|
|
50
50
|
* Place an item to the Kiosk.
|
|
51
51
|
*/
|
|
52
52
|
export function place(
|
|
53
|
-
tx:
|
|
53
|
+
tx: Transaction,
|
|
54
54
|
itemType: string,
|
|
55
55
|
kiosk: ObjectArgument,
|
|
56
56
|
kioskCap: ObjectArgument,
|
|
@@ -72,7 +72,7 @@ export function place(
|
|
|
72
72
|
* locked without an option to take it out.
|
|
73
73
|
*/
|
|
74
74
|
export function lock(
|
|
75
|
-
tx:
|
|
75
|
+
tx: Transaction,
|
|
76
76
|
itemType: string,
|
|
77
77
|
kiosk: ObjectArgument,
|
|
78
78
|
kioskCap: ObjectArgument,
|
|
@@ -91,7 +91,7 @@ export function lock(
|
|
|
91
91
|
* Take an item from the Kiosk.
|
|
92
92
|
*/
|
|
93
93
|
export function take(
|
|
94
|
-
tx:
|
|
94
|
+
tx: Transaction,
|
|
95
95
|
itemType: string,
|
|
96
96
|
kiosk: ObjectArgument,
|
|
97
97
|
kioskCap: ObjectArgument,
|
|
@@ -111,7 +111,7 @@ export function take(
|
|
|
111
111
|
* List an item for sale.
|
|
112
112
|
*/
|
|
113
113
|
export function list(
|
|
114
|
-
tx:
|
|
114
|
+
tx: Transaction,
|
|
115
115
|
itemType: string,
|
|
116
116
|
kiosk: ObjectArgument,
|
|
117
117
|
kioskCap: ObjectArgument,
|
|
@@ -130,7 +130,7 @@ export function list(
|
|
|
130
130
|
* List an item for sale.
|
|
131
131
|
*/
|
|
132
132
|
export function delist(
|
|
133
|
-
tx:
|
|
133
|
+
tx: Transaction,
|
|
134
134
|
itemType: string,
|
|
135
135
|
kiosk: ObjectArgument,
|
|
136
136
|
kioskCap: ObjectArgument,
|
|
@@ -148,7 +148,7 @@ export function delist(
|
|
|
148
148
|
* Place an item to the Kiosk and list it for sale.
|
|
149
149
|
*/
|
|
150
150
|
export function placeAndList(
|
|
151
|
-
tx:
|
|
151
|
+
tx: Transaction,
|
|
152
152
|
itemType: string,
|
|
153
153
|
kiosk: ObjectArgument,
|
|
154
154
|
kioskCap: ObjectArgument,
|
|
@@ -167,7 +167,7 @@ export function placeAndList(
|
|
|
167
167
|
* a TransferRequest which needs to be dealt with (via a matching TransferPolicy).
|
|
168
168
|
*/
|
|
169
169
|
export function purchase(
|
|
170
|
-
tx:
|
|
170
|
+
tx: Transaction,
|
|
171
171
|
itemType: string,
|
|
172
172
|
kiosk: ObjectArgument,
|
|
173
173
|
itemId: string,
|
|
@@ -187,7 +187,7 @@ export function purchase(
|
|
|
187
187
|
* If the amount is null, then the entire balance will be withdrawn.
|
|
188
188
|
*/
|
|
189
189
|
export function withdrawFromKiosk(
|
|
190
|
-
tx:
|
|
190
|
+
tx: Transaction,
|
|
191
191
|
kiosk: ObjectArgument,
|
|
192
192
|
kioskCap: ObjectArgument,
|
|
193
193
|
amount?: string | bigint | number,
|
|
@@ -209,7 +209,7 @@ export function withdrawFromKiosk(
|
|
|
209
209
|
* Requires calling `returnValue` to return the item.
|
|
210
210
|
*/
|
|
211
211
|
export function borrowValue(
|
|
212
|
-
tx:
|
|
212
|
+
tx: Transaction,
|
|
213
213
|
itemType: string,
|
|
214
214
|
kiosk: ObjectArgument,
|
|
215
215
|
kioskCap: ObjectArgument,
|
|
@@ -229,7 +229,7 @@ export function borrowValue(
|
|
|
229
229
|
* Return an item to the Kiosk after it was `borrowValue`-d.
|
|
230
230
|
*/
|
|
231
231
|
export function returnValue(
|
|
232
|
-
tx:
|
|
232
|
+
tx: Transaction,
|
|
233
233
|
itemType: string,
|
|
234
234
|
kiosk: ObjectArgument,
|
|
235
235
|
item: TransactionArgument,
|
package/src/tx/personal-kiosk.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
5
5
|
|
|
6
6
|
import type { ObjectArgument } from '../types/index.js';
|
|
7
7
|
|
|
8
8
|
export function convertToPersonalTx(
|
|
9
|
-
tx:
|
|
9
|
+
tx: Transaction,
|
|
10
10
|
kiosk: ObjectArgument,
|
|
11
11
|
kioskOwnerCap: ObjectArgument,
|
|
12
12
|
packageId: string,
|
|
@@ -23,7 +23,7 @@ export function convertToPersonalTx(
|
|
|
23
23
|
* Transfers the personal kiosk Cap to the sender.
|
|
24
24
|
*/
|
|
25
25
|
export function transferPersonalCapTx(
|
|
26
|
-
tx:
|
|
26
|
+
tx: Transaction,
|
|
27
27
|
personalKioskCap: TransactionObjectArgument,
|
|
28
28
|
packageId: string,
|
|
29
29
|
) {
|