@iota/kiosk 0.1.2 → 0.2.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 +12 -0
- package/README.md +2 -2
- package/dist/cjs/bcs.d.ts +38 -2
- package/dist/cjs/bcs.js +20 -18
- package/dist/cjs/bcs.js.map +2 -2
- package/dist/cjs/client/kiosk-client.d.ts +4 -2
- package/dist/cjs/client/kiosk-client.js +10 -5
- package/dist/cjs/client/kiosk-client.js.map +2 -2
- package/dist/cjs/client/kiosk-transaction.d.ts +11 -10
- package/dist/cjs/client/kiosk-transaction.js +102 -140
- package/dist/cjs/client/kiosk-transaction.js.map +2 -2
- package/dist/cjs/client/tp-transaction.d.ts +8 -6
- package/dist/cjs/client/tp-transaction.js +54 -65
- package/dist/cjs/client/tp-transaction.js.map +2 -2
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/query/kiosk.js +2 -4
- package/dist/cjs/query/kiosk.js.map +1 -1
- package/dist/cjs/query/transfer-policy.d.ts +1 -0
- package/dist/cjs/query/transfer-policy.js +5 -7
- 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.map +2 -2
- package/dist/cjs/tx/personal-kiosk.d.ts +3 -3
- package/dist/cjs/tx/personal-kiosk.js.map +2 -2
- package/dist/cjs/tx/rules/attach.d.ts +5 -5
- package/dist/cjs/tx/rules/attach.js.map +2 -2
- package/dist/cjs/tx/rules/resolve.js +18 -20
- 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.map +2 -2
- package/dist/cjs/types/kiosk.d.ts +0 -1
- package/dist/cjs/types/kiosk.js.map +2 -2
- package/dist/cjs/types/transfer-policy.d.ts +4 -2
- package/dist/cjs/types/transfer-policy.js.map +2 -2
- package/dist/cjs/utils.js +4 -7
- package/dist/cjs/utils.js.map +2 -2
- package/dist/esm/bcs.d.ts +38 -2
- package/dist/esm/bcs.js +20 -18
- package/dist/esm/bcs.js.map +2 -2
- package/dist/esm/client/kiosk-client.d.ts +4 -2
- package/dist/esm/client/kiosk-client.js +10 -5
- package/dist/esm/client/kiosk-client.js.map +2 -2
- package/dist/esm/client/kiosk-transaction.d.ts +11 -10
- package/dist/esm/client/kiosk-transaction.js +101 -139
- package/dist/esm/client/kiosk-transaction.js.map +2 -2
- package/dist/esm/client/tp-transaction.d.ts +8 -6
- package/dist/esm/client/tp-transaction.js +53 -64
- package/dist/esm/client/tp-transaction.js.map +2 -2
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/query/kiosk.js +2 -4
- package/dist/esm/query/kiosk.js.map +1 -1
- package/dist/esm/query/transfer-policy.d.ts +1 -0
- package/dist/esm/query/transfer-policy.js +7 -9
- 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.map +2 -2
- package/dist/esm/tx/personal-kiosk.d.ts +3 -3
- package/dist/esm/tx/personal-kiosk.js.map +2 -2
- package/dist/esm/tx/rules/attach.d.ts +5 -5
- package/dist/esm/tx/rules/attach.js.map +2 -2
- package/dist/esm/tx/rules/resolve.js +18 -20
- 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.map +2 -2
- package/dist/esm/types/kiosk.d.ts +0 -1
- package/dist/esm/types/kiosk.js.map +2 -2
- package/dist/esm/types/transfer-policy.d.ts +4 -2
- package/dist/esm/types/transfer-policy.js.map +2 -2
- package/dist/esm/utils.js +12 -10
- package/dist/esm/utils.js.map +2 -2
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -11
- package/src/bcs.ts +16 -19
- package/src/client/kiosk-client.ts +15 -5
- package/src/client/kiosk-transaction.ts +52 -56
- package/src/client/tp-transaction.ts +31 -28
- package/src/query/transfer-policy.ts +5 -3
- package/src/tx/kiosk.ts +14 -14
- 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 +7 -7
- package/src/types/kiosk.ts +0 -1
- package/src/types/transfer-policy.ts +4 -2
- package/src/utils.ts +10 -5
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
5
|
import type {
|
|
6
|
+
Transaction,
|
|
6
7
|
TransactionArgument,
|
|
7
|
-
TransactionBlock,
|
|
8
8
|
TransactionObjectArgument,
|
|
9
9
|
} from '@iota/iota-sdk/transactions';
|
|
10
10
|
|
|
@@ -24,8 +24,11 @@ import { getNormalizedRuleType } from '../utils.js';
|
|
|
24
24
|
import type { KioskClient } from './kiosk-client.js';
|
|
25
25
|
|
|
26
26
|
export type KioskTransactionParams = {
|
|
27
|
-
/** The
|
|
28
|
-
|
|
27
|
+
/** The Transaction for this run */
|
|
28
|
+
transaction: Transaction;
|
|
29
|
+
|
|
30
|
+
/** @deprecated use transaction instead */
|
|
31
|
+
transactionBlock?: Transaction;
|
|
29
32
|
/**
|
|
30
33
|
* You can create a new KioskClient by calling `new KioskClient()`
|
|
31
34
|
*/
|
|
@@ -42,7 +45,7 @@ export type KioskTransactionParams = {
|
|
|
42
45
|
* A helper for building transactions that involve kiosk.
|
|
43
46
|
*/
|
|
44
47
|
export class KioskTransaction {
|
|
45
|
-
|
|
48
|
+
transaction: Transaction;
|
|
46
49
|
kioskClient: KioskClient;
|
|
47
50
|
kiosk?: TransactionObjectArgument;
|
|
48
51
|
kioskCap?: TransactionObjectArgument;
|
|
@@ -57,8 +60,13 @@ export class KioskTransaction {
|
|
|
57
60
|
// A flag that checks whether kiosk TX is finalized.
|
|
58
61
|
#finalized: boolean = false;
|
|
59
62
|
|
|
60
|
-
constructor({
|
|
61
|
-
|
|
63
|
+
constructor({
|
|
64
|
+
transactionBlock,
|
|
65
|
+
transaction = transactionBlock!,
|
|
66
|
+
kioskClient,
|
|
67
|
+
cap,
|
|
68
|
+
}: KioskTransactionParams) {
|
|
69
|
+
this.transaction = transaction;
|
|
62
70
|
this.kioskClient = kioskClient;
|
|
63
71
|
|
|
64
72
|
if (cap) this.setCap(cap);
|
|
@@ -75,7 +83,7 @@ export class KioskTransaction {
|
|
|
75
83
|
share: true,
|
|
76
84
|
transfer: true,
|
|
77
85
|
});
|
|
78
|
-
const [kiosk, cap] = kioskTx.createKiosk(this.
|
|
86
|
+
const [kiosk, cap] = kioskTx.createKiosk(this.transaction);
|
|
79
87
|
this.kiosk = kiosk;
|
|
80
88
|
this.kioskCap = cap;
|
|
81
89
|
return this;
|
|
@@ -99,7 +107,7 @@ export class KioskTransaction {
|
|
|
99
107
|
this.#validateKioskIsSet();
|
|
100
108
|
|
|
101
109
|
const cap = convertToPersonalTx(
|
|
102
|
-
this.
|
|
110
|
+
this.transaction,
|
|
103
111
|
this.kiosk!,
|
|
104
112
|
this.kioskCap!,
|
|
105
113
|
this.kioskClient.getRulePackageId('personalKioskRulePackageId'),
|
|
@@ -118,8 +126,8 @@ export class KioskTransaction {
|
|
|
118
126
|
*/
|
|
119
127
|
createAndShare(address: string) {
|
|
120
128
|
this.#validateFinalizedStatus();
|
|
121
|
-
const cap = kioskTx.createKioskAndShare(this.
|
|
122
|
-
this.
|
|
129
|
+
const cap = kioskTx.createKioskAndShare(this.transaction);
|
|
130
|
+
this.transaction.transferObjects([cap], this.transaction.pure.address(address));
|
|
123
131
|
}
|
|
124
132
|
|
|
125
133
|
/**
|
|
@@ -128,7 +136,7 @@ export class KioskTransaction {
|
|
|
128
136
|
share() {
|
|
129
137
|
this.#validateKioskIsSet();
|
|
130
138
|
this.#setPendingStatuses({ share: false });
|
|
131
|
-
kioskTx.shareKiosk(this.
|
|
139
|
+
kioskTx.shareKiosk(this.transaction, this.kiosk!);
|
|
132
140
|
}
|
|
133
141
|
|
|
134
142
|
/**
|
|
@@ -140,20 +148,16 @@ export class KioskTransaction {
|
|
|
140
148
|
throw new Error('You can only call `shareAndTransferCap` on a non-personal kiosk.');
|
|
141
149
|
this.#setPendingStatuses({ transfer: false });
|
|
142
150
|
this.share();
|
|
143
|
-
this.
|
|
144
|
-
[this.kioskCap!],
|
|
145
|
-
this.transactionBlock.pure.address(address),
|
|
146
|
-
);
|
|
151
|
+
this.transaction.transferObjects([this.kioskCap!], this.transaction.pure.address(address));
|
|
147
152
|
}
|
|
148
153
|
|
|
149
154
|
/**
|
|
150
155
|
* A function to borrow an item from a kiosk & execute any function with it.
|
|
151
|
-
* Example: You could borrow a Fren out of a kiosk, attach an accessory (or mix), and return it.
|
|
152
156
|
*/
|
|
153
157
|
borrowTx({ itemType, itemId }: ItemId, callback: (item: TransactionArgument) => void) {
|
|
154
158
|
this.#validateKioskIsSet();
|
|
155
159
|
const [itemObj, promise] = kioskTx.borrowValue(
|
|
156
|
-
this.
|
|
160
|
+
this.transaction,
|
|
157
161
|
itemType,
|
|
158
162
|
this.kiosk!,
|
|
159
163
|
this.kioskCap!,
|
|
@@ -174,7 +178,7 @@ export class KioskTransaction {
|
|
|
174
178
|
borrow({ itemType, itemId }: ItemId): [TransactionArgument, TransactionArgument] {
|
|
175
179
|
this.#validateKioskIsSet();
|
|
176
180
|
const [itemObj, promise] = kioskTx.borrowValue(
|
|
177
|
-
this.
|
|
181
|
+
this.transaction,
|
|
178
182
|
itemType,
|
|
179
183
|
this.kiosk!,
|
|
180
184
|
this.kioskCap!,
|
|
@@ -190,7 +194,7 @@ export class KioskTransaction {
|
|
|
190
194
|
*/
|
|
191
195
|
return({ itemType, item, promise }: ItemValue & { promise: TransactionArgument }) {
|
|
192
196
|
this.#validateKioskIsSet();
|
|
193
|
-
kioskTx.returnValue(this.
|
|
197
|
+
kioskTx.returnValue(this.transaction, itemType, this.kiosk!, item, promise);
|
|
194
198
|
return this;
|
|
195
199
|
}
|
|
196
200
|
|
|
@@ -202,12 +206,12 @@ export class KioskTransaction {
|
|
|
202
206
|
withdraw(address: string, amount?: string | bigint | number) {
|
|
203
207
|
this.#validateKioskIsSet();
|
|
204
208
|
const coin = kioskTx.withdrawFromKiosk(
|
|
205
|
-
this.
|
|
209
|
+
this.transaction,
|
|
206
210
|
this.kiosk!,
|
|
207
211
|
this.kioskCap!,
|
|
208
212
|
amount,
|
|
209
213
|
);
|
|
210
|
-
this.
|
|
214
|
+
this.transaction.transferObjects([coin], this.transaction.pure.address(address));
|
|
211
215
|
return this;
|
|
212
216
|
}
|
|
213
217
|
|
|
@@ -218,7 +222,7 @@ export class KioskTransaction {
|
|
|
218
222
|
*/
|
|
219
223
|
place({ itemType, item }: ItemReference) {
|
|
220
224
|
this.#validateKioskIsSet();
|
|
221
|
-
kioskTx.place(this.
|
|
225
|
+
kioskTx.place(this.transaction, itemType, this.kiosk!, this.kioskCap!, item);
|
|
222
226
|
return this;
|
|
223
227
|
}
|
|
224
228
|
|
|
@@ -226,18 +230,11 @@ export class KioskTransaction {
|
|
|
226
230
|
* A function to place an item in the kiosk and list it for sale in one transaction.
|
|
227
231
|
* @param itemType The type `T` of the item
|
|
228
232
|
* @param item The ID or Transaction Argument of the item
|
|
229
|
-
* @param price The price in
|
|
233
|
+
* @param price The price in NANOS
|
|
230
234
|
*/
|
|
231
235
|
placeAndList({ itemType, item, price }: ItemReference & Price) {
|
|
232
236
|
this.#validateKioskIsSet();
|
|
233
|
-
kioskTx.placeAndList(
|
|
234
|
-
this.transactionBlock,
|
|
235
|
-
itemType,
|
|
236
|
-
this.kiosk!,
|
|
237
|
-
this.kioskCap!,
|
|
238
|
-
item,
|
|
239
|
-
price,
|
|
240
|
-
);
|
|
237
|
+
kioskTx.placeAndList(this.transaction, itemType, this.kiosk!, this.kioskCap!, item, price);
|
|
241
238
|
return this;
|
|
242
239
|
}
|
|
243
240
|
|
|
@@ -245,11 +242,11 @@ export class KioskTransaction {
|
|
|
245
242
|
* A function to list an item in the kiosk.
|
|
246
243
|
* @param itemType The type `T` of the item
|
|
247
244
|
* @param itemId The ID of the item
|
|
248
|
-
* @param price The price in
|
|
245
|
+
* @param price The price in NANOS
|
|
249
246
|
*/
|
|
250
247
|
list({ itemType, itemId, price }: ItemId & { price: string | bigint }) {
|
|
251
248
|
this.#validateKioskIsSet();
|
|
252
|
-
kioskTx.list(this.
|
|
249
|
+
kioskTx.list(this.transaction, itemType, this.kiosk!, this.kioskCap!, itemId, price);
|
|
253
250
|
return this;
|
|
254
251
|
}
|
|
255
252
|
|
|
@@ -260,7 +257,7 @@ export class KioskTransaction {
|
|
|
260
257
|
*/
|
|
261
258
|
delist({ itemType, itemId }: ItemId) {
|
|
262
259
|
this.#validateKioskIsSet();
|
|
263
|
-
kioskTx.delist(this.
|
|
260
|
+
kioskTx.delist(this.transaction, itemType, this.kiosk!, this.kioskCap!, itemId);
|
|
264
261
|
return this;
|
|
265
262
|
}
|
|
266
263
|
|
|
@@ -272,7 +269,7 @@ export class KioskTransaction {
|
|
|
272
269
|
*/
|
|
273
270
|
take({ itemType, itemId }: ItemId): TransactionObjectArgument {
|
|
274
271
|
this.#validateKioskIsSet();
|
|
275
|
-
return kioskTx.take(this.
|
|
272
|
+
return kioskTx.take(this.transaction, itemType, this.kiosk!, this.kioskCap!, itemId);
|
|
276
273
|
}
|
|
277
274
|
|
|
278
275
|
/**
|
|
@@ -285,7 +282,7 @@ export class KioskTransaction {
|
|
|
285
282
|
transfer({ itemType, itemId, address }: ItemId & { address: string }) {
|
|
286
283
|
this.#validateKioskIsSet();
|
|
287
284
|
const item = this.take({ itemType, itemId });
|
|
288
|
-
this.
|
|
285
|
+
this.transaction.transferObjects([item], this.transaction.pure.address(address));
|
|
289
286
|
return this;
|
|
290
287
|
}
|
|
291
288
|
|
|
@@ -305,7 +302,7 @@ export class KioskTransaction {
|
|
|
305
302
|
}: ItemReference & { policy: ObjectArgument; itemId?: string }) {
|
|
306
303
|
this.#validateKioskIsSet();
|
|
307
304
|
kioskTx.lock(
|
|
308
|
-
this.
|
|
305
|
+
this.transaction,
|
|
309
306
|
itemType,
|
|
310
307
|
this.kiosk!,
|
|
311
308
|
this.kioskCap!,
|
|
@@ -321,7 +318,7 @@ export class KioskTransaction {
|
|
|
321
318
|
* Can be called like: `const [item, transferRequest] = kioskTx.purchase({...})`
|
|
322
319
|
* @param itemType The type `T` of the item
|
|
323
320
|
* @param itemId The ID of the item
|
|
324
|
-
* @param price The price in
|
|
321
|
+
* @param price The price in NANOS
|
|
325
322
|
* @param sellerKiosk The kiosk which is selling the item. Can be an id or an object argument.
|
|
326
323
|
*/
|
|
327
324
|
purchase({
|
|
@@ -334,10 +331,10 @@ export class KioskTransaction {
|
|
|
334
331
|
TransactionObjectArgument,
|
|
335
332
|
] {
|
|
336
333
|
// Split the coin for the amount of the listing.
|
|
337
|
-
const coin = this.
|
|
338
|
-
this.
|
|
334
|
+
const coin = this.transaction.splitCoins(this.transaction.gas, [
|
|
335
|
+
this.transaction.pure.u64(price),
|
|
339
336
|
]);
|
|
340
|
-
return kioskTx.purchase(this.
|
|
337
|
+
return kioskTx.purchase(this.transaction, itemType, sellerKiosk, itemId, coin);
|
|
341
338
|
}
|
|
342
339
|
|
|
343
340
|
/**
|
|
@@ -389,7 +386,8 @@ export class KioskTransaction {
|
|
|
389
386
|
|
|
390
387
|
ruleDefinition.resolveRuleFunction({
|
|
391
388
|
packageId: ruleDefinition.packageId,
|
|
392
|
-
transactionBlock: this.
|
|
389
|
+
transactionBlock: this.transaction,
|
|
390
|
+
transaction: this.transaction,
|
|
393
391
|
itemType,
|
|
394
392
|
itemId,
|
|
395
393
|
price: price.toString(),
|
|
@@ -403,7 +401,7 @@ export class KioskTransaction {
|
|
|
403
401
|
});
|
|
404
402
|
}
|
|
405
403
|
|
|
406
|
-
confirmRequest(this.
|
|
404
|
+
confirmRequest(this.transaction, itemType, policy.id, transferRequest);
|
|
407
405
|
|
|
408
406
|
if (canTransferOutsideKiosk) this.place({ itemType, item: purchasedItem });
|
|
409
407
|
|
|
@@ -417,9 +415,9 @@ export class KioskTransaction {
|
|
|
417
415
|
*/
|
|
418
416
|
setCap(cap: KioskOwnerCap) {
|
|
419
417
|
this.#validateFinalizedStatus();
|
|
420
|
-
this.kiosk = this.
|
|
418
|
+
this.kiosk = this.transaction.object(cap.kioskId);
|
|
421
419
|
if (!cap.isPersonal) {
|
|
422
|
-
this.kioskCap = this.
|
|
420
|
+
this.kioskCap = this.transaction.object(cap.objectId);
|
|
423
421
|
return;
|
|
424
422
|
}
|
|
425
423
|
|
|
@@ -427,7 +425,7 @@ export class KioskTransaction {
|
|
|
427
425
|
}
|
|
428
426
|
|
|
429
427
|
/**
|
|
430
|
-
* A function that ends up the kiosk building
|
|
428
|
+
* A function that ends up the kiosk building tx & returns the `kioskOwnerCap` back to the
|
|
431
429
|
* `PersonalKioskCap`, in case we are operating on a personal kiosk.
|
|
432
430
|
* It will also share the `kiosk` if it's not shared, and finalize the transfer of the personal cap if it's pending.
|
|
433
431
|
*/
|
|
@@ -450,11 +448,11 @@ export class KioskTransaction {
|
|
|
450
448
|
|
|
451
449
|
// if we have a promise, return the `ownerCap` back to the personal cap.
|
|
452
450
|
if (this.#promise) {
|
|
453
|
-
this.
|
|
451
|
+
this.transaction.moveCall({
|
|
454
452
|
target: `${packageId}::personal_kiosk::return_val`,
|
|
455
453
|
arguments: [
|
|
456
454
|
this.#personalCap,
|
|
457
|
-
this.
|
|
455
|
+
this.transaction.object(this.kioskCap!),
|
|
458
456
|
this.#promise!,
|
|
459
457
|
],
|
|
460
458
|
});
|
|
@@ -462,9 +460,9 @@ export class KioskTransaction {
|
|
|
462
460
|
|
|
463
461
|
// If we are pending transferring the personalCap, we do it here.
|
|
464
462
|
if (this.#pendingTransfer)
|
|
465
|
-
transferPersonalCapTx(this.
|
|
463
|
+
transferPersonalCapTx(this.transaction, this.#personalCap, packageId);
|
|
466
464
|
|
|
467
|
-
// Mark the transaction
|
|
465
|
+
// Mark the transaction as finalized, so no other functions can be called.
|
|
468
466
|
this.#finalized = true;
|
|
469
467
|
}
|
|
470
468
|
|
|
@@ -504,15 +502,15 @@ export class KioskTransaction {
|
|
|
504
502
|
* A function to borrow from `personalCap`.
|
|
505
503
|
*/
|
|
506
504
|
#borrowFromPersonalCap(personalCap: ObjectArgument) {
|
|
507
|
-
const [kioskCap, promise] = this.
|
|
505
|
+
const [kioskCap, promise] = this.transaction.moveCall({
|
|
508
506
|
target: `${this.kioskClient.getRulePackageId(
|
|
509
507
|
'personalKioskRulePackageId',
|
|
510
508
|
)}::personal_kiosk::borrow_val`,
|
|
511
|
-
arguments: [this.
|
|
509
|
+
arguments: [this.transaction.object(personalCap)],
|
|
512
510
|
});
|
|
513
511
|
|
|
514
512
|
this.kioskCap = kioskCap;
|
|
515
|
-
this.#personalCap = this.
|
|
513
|
+
this.#personalCap = this.transaction.object(personalCap);
|
|
516
514
|
this.#promise = promise;
|
|
517
515
|
|
|
518
516
|
return this;
|
|
@@ -535,8 +533,6 @@ export class KioskTransaction {
|
|
|
535
533
|
// Validates that `finalize`
|
|
536
534
|
#validateFinalizedStatus() {
|
|
537
535
|
if (this.#finalized)
|
|
538
|
-
throw new Error(
|
|
539
|
-
"You can't add more transactions to a finalized kiosk transaction block.",
|
|
540
|
-
);
|
|
536
|
+
throw new Error("You can't add more transactions to a finalized kiosk transaction.");
|
|
541
537
|
}
|
|
542
538
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Modifications Copyright (c) 2024 IOTA Stiftung
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
|
-
import type {
|
|
5
|
+
import type { Transaction, TransactionObjectArgument } from '@iota/iota-sdk/transactions';
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
8
|
attachFloorPriceRuleTx,
|
|
@@ -28,20 +28,27 @@ export type TransferPolicyBaseParams = {
|
|
|
28
28
|
|
|
29
29
|
export type TransferPolicyTransactionParams = {
|
|
30
30
|
kioskClient: KioskClient;
|
|
31
|
-
|
|
31
|
+
transaction: Transaction;
|
|
32
|
+
/** @deprecated use transaction instead */
|
|
33
|
+
transactionBlock?: Transaction;
|
|
32
34
|
cap?: TransferPolicyCap;
|
|
33
35
|
};
|
|
34
36
|
|
|
35
37
|
export class TransferPolicyTransaction {
|
|
36
|
-
|
|
38
|
+
transaction: Transaction;
|
|
37
39
|
kioskClient: KioskClient;
|
|
38
40
|
policy?: ObjectArgument;
|
|
39
41
|
policyCap?: ObjectArgument;
|
|
40
42
|
type?: string;
|
|
41
43
|
|
|
42
|
-
constructor({
|
|
44
|
+
constructor({
|
|
45
|
+
kioskClient,
|
|
46
|
+
transactionBlock,
|
|
47
|
+
transaction = transactionBlock!,
|
|
48
|
+
cap,
|
|
49
|
+
}: TransferPolicyTransactionParams) {
|
|
43
50
|
this.kioskClient = kioskClient;
|
|
44
|
-
this.
|
|
51
|
+
this.transaction = transaction;
|
|
45
52
|
if (cap) this.setCap(cap);
|
|
46
53
|
}
|
|
47
54
|
|
|
@@ -70,8 +77,8 @@ export class TransferPolicyTransaction {
|
|
|
70
77
|
if (policies.length > 0)
|
|
71
78
|
throw new Error("There's already transfer policy for this Type.");
|
|
72
79
|
}
|
|
73
|
-
const cap = createTransferPolicy(this.
|
|
74
|
-
this.
|
|
80
|
+
const cap = createTransferPolicy(this.transaction, type, publisher);
|
|
81
|
+
this.transaction.transferObjects([cap], this.transaction.pure.address(address));
|
|
75
82
|
}
|
|
76
83
|
|
|
77
84
|
/**
|
|
@@ -93,7 +100,7 @@ export class TransferPolicyTransaction {
|
|
|
93
100
|
throw new Error("There's already transfer policy for this Type.");
|
|
94
101
|
}
|
|
95
102
|
const [policy, policyCap] = createTransferPolicyWithoutSharing(
|
|
96
|
-
this.
|
|
103
|
+
this.transaction,
|
|
97
104
|
type,
|
|
98
105
|
publisher,
|
|
99
106
|
);
|
|
@@ -114,14 +121,10 @@ export class TransferPolicyTransaction {
|
|
|
114
121
|
'This function can only be called after `transferPolicyManager.create`',
|
|
115
122
|
);
|
|
116
123
|
|
|
117
|
-
shareTransferPolicy(
|
|
118
|
-
|
|
119
|
-
this.type,
|
|
120
|
-
this.policy as TransactionObjectArgument,
|
|
121
|
-
);
|
|
122
|
-
this.transactionBlock.transferObjects(
|
|
124
|
+
shareTransferPolicy(this.transaction, this.type, this.policy as TransactionObjectArgument);
|
|
125
|
+
this.transaction.transferObjects(
|
|
123
126
|
[this.policyCap as TransactionObjectArgument],
|
|
124
|
-
this.
|
|
127
|
+
this.transaction.pure.address(address),
|
|
125
128
|
);
|
|
126
129
|
}
|
|
127
130
|
|
|
@@ -143,14 +146,14 @@ export class TransferPolicyTransaction {
|
|
|
143
146
|
this.#validateInputs();
|
|
144
147
|
// Withdraw coin for specified amount (or none)
|
|
145
148
|
const coin = withdrawFromPolicy(
|
|
146
|
-
this.
|
|
149
|
+
this.transaction,
|
|
147
150
|
this.type!,
|
|
148
151
|
this.policy!,
|
|
149
152
|
this.policyCap!,
|
|
150
153
|
amount,
|
|
151
154
|
);
|
|
152
155
|
|
|
153
|
-
this.
|
|
156
|
+
this.transaction.transferObjects([coin], this.transaction.pure.address(address));
|
|
154
157
|
|
|
155
158
|
return this;
|
|
156
159
|
}
|
|
@@ -163,7 +166,7 @@ export class TransferPolicyTransaction {
|
|
|
163
166
|
* (but you should define at least one of them for the rule to make sense).
|
|
164
167
|
*
|
|
165
168
|
* @param percentageBps The royalty percentage in basis points. Use `percentageToBasisPoints` helper to convert from percentage [0,100].
|
|
166
|
-
* @param minAmount The minimum royalty amount per request in
|
|
169
|
+
* @param minAmount The minimum royalty amount per request in NANOS.
|
|
167
170
|
*/
|
|
168
171
|
addRoyaltyRule(
|
|
169
172
|
percentageBps: number | string, // this is in basis points.
|
|
@@ -175,7 +178,7 @@ export class TransferPolicyTransaction {
|
|
|
175
178
|
// Also, it's hard to keep versioning as with network wipes, mainnet
|
|
176
179
|
// and testnet will conflict.
|
|
177
180
|
attachRoyaltyRuleTx(
|
|
178
|
-
this.
|
|
181
|
+
this.transaction,
|
|
179
182
|
this.type!,
|
|
180
183
|
this.policy!,
|
|
181
184
|
this.policyCap!,
|
|
@@ -194,7 +197,7 @@ export class TransferPolicyTransaction {
|
|
|
194
197
|
this.#validateInputs();
|
|
195
198
|
|
|
196
199
|
attachKioskLockRuleTx(
|
|
197
|
-
this.
|
|
200
|
+
this.transaction,
|
|
198
201
|
this.type!,
|
|
199
202
|
this.policy!,
|
|
200
203
|
this.policyCap!,
|
|
@@ -210,7 +213,7 @@ export class TransferPolicyTransaction {
|
|
|
210
213
|
this.#validateInputs();
|
|
211
214
|
|
|
212
215
|
attachPersonalKioskRuleTx(
|
|
213
|
-
this.
|
|
216
|
+
this.transaction,
|
|
214
217
|
this.type!,
|
|
215
218
|
this.policy!,
|
|
216
219
|
this.policyCap!,
|
|
@@ -221,13 +224,13 @@ export class TransferPolicyTransaction {
|
|
|
221
224
|
|
|
222
225
|
/**
|
|
223
226
|
* A function to add the floor price rule to a transfer policy.
|
|
224
|
-
* @param minPrice The minimum price in
|
|
227
|
+
* @param minPrice The minimum price in NANOS.
|
|
225
228
|
*/
|
|
226
229
|
addFloorPriceRule(minPrice: string | bigint) {
|
|
227
230
|
this.#validateInputs();
|
|
228
231
|
|
|
229
232
|
attachFloorPriceRuleTx(
|
|
230
|
-
this.
|
|
233
|
+
this.transaction,
|
|
231
234
|
this.type!,
|
|
232
235
|
this.policy!,
|
|
233
236
|
this.policyCap!,
|
|
@@ -246,7 +249,7 @@ export class TransferPolicyTransaction {
|
|
|
246
249
|
this.#validateInputs();
|
|
247
250
|
|
|
248
251
|
removeTransferPolicyRule(
|
|
249
|
-
this.
|
|
252
|
+
this.transaction,
|
|
250
253
|
this.type!,
|
|
251
254
|
ruleType,
|
|
252
255
|
configType,
|
|
@@ -264,7 +267,7 @@ export class TransferPolicyTransaction {
|
|
|
264
267
|
const packageId = this.kioskClient.getRulePackageId('kioskLockRulePackageId');
|
|
265
268
|
|
|
266
269
|
removeTransferPolicyRule(
|
|
267
|
-
this.
|
|
270
|
+
this.transaction,
|
|
268
271
|
this.type!,
|
|
269
272
|
`${packageId}::kiosk_lock_rule::Rule`,
|
|
270
273
|
`${packageId}::kiosk_lock_rule::Config`,
|
|
@@ -283,7 +286,7 @@ export class TransferPolicyTransaction {
|
|
|
283
286
|
const packageId = this.kioskClient.getRulePackageId('royaltyRulePackageId');
|
|
284
287
|
|
|
285
288
|
removeTransferPolicyRule(
|
|
286
|
-
this.
|
|
289
|
+
this.transaction,
|
|
287
290
|
this.type!,
|
|
288
291
|
`${packageId}::royalty_rule::Rule`,
|
|
289
292
|
`${packageId}::royalty_rule::Config`,
|
|
@@ -299,7 +302,7 @@ export class TransferPolicyTransaction {
|
|
|
299
302
|
const packageId = this.kioskClient.getRulePackageId('personalKioskRulePackageId');
|
|
300
303
|
|
|
301
304
|
removeTransferPolicyRule(
|
|
302
|
-
this.
|
|
305
|
+
this.transaction,
|
|
303
306
|
this.type!,
|
|
304
307
|
`${packageId}::personal_kiosk_rule::Rule`,
|
|
305
308
|
`bool`,
|
|
@@ -315,7 +318,7 @@ export class TransferPolicyTransaction {
|
|
|
315
318
|
const packageId = this.kioskClient.getRulePackageId('floorPriceRulePackageId');
|
|
316
319
|
|
|
317
320
|
removeTransferPolicyRule(
|
|
318
|
-
this.
|
|
321
|
+
this.transaction,
|
|
319
322
|
this.type!,
|
|
320
323
|
`${packageId}::floor_price_rule::Rule`,
|
|
321
324
|
`${packageId}::floor_price_rule::Config`,
|
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
5
|
import type { IotaClient } from '@iota/iota-sdk/client';
|
|
6
|
-
import { isValidIotaAddress } from '@iota/iota-sdk/utils';
|
|
6
|
+
import { fromB64, isValidIotaAddress } from '@iota/iota-sdk/utils';
|
|
7
7
|
|
|
8
|
-
import
|
|
8
|
+
import '../bcs.js';
|
|
9
|
+
|
|
10
|
+
import { TransferPolicyType } from '../bcs.js';
|
|
9
11
|
import type { TransferPolicy, TransferPolicyCap } from '../types/index.js';
|
|
10
12
|
import {
|
|
11
13
|
TRANSFER_POLICY_CAP_TYPE,
|
|
@@ -51,7 +53,7 @@ export async function queryTransferPolicy(
|
|
|
51
53
|
);
|
|
52
54
|
}
|
|
53
55
|
|
|
54
|
-
const parsed =
|
|
56
|
+
const parsed = TransferPolicyType.parse(fromB64(policy.bcs.bcsBytes));
|
|
55
57
|
|
|
56
58
|
return {
|
|
57
59
|
id: policy?.objectId,
|
package/src/tx/kiosk.ts
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
import { bcs } from '@iota/iota-sdk/bcs';
|
|
6
6
|
import type {
|
|
7
|
+
Transaction,
|
|
7
8
|
TransactionArgument,
|
|
8
|
-
TransactionBlock,
|
|
9
9
|
TransactionObjectArgument,
|
|
10
10
|
} from '@iota/iota-sdk/transactions';
|
|
11
11
|
|
|
@@ -16,7 +16,7 @@ import { KIOSK_MODULE, KIOSK_TYPE } from '../types/index.js';
|
|
|
16
16
|
* Create a new shared Kiosk and returns the [kiosk, kioskOwnerCap] tuple.
|
|
17
17
|
*/
|
|
18
18
|
export function createKiosk(
|
|
19
|
-
tx:
|
|
19
|
+
tx: Transaction,
|
|
20
20
|
): [TransactionObjectArgument, TransactionObjectArgument] {
|
|
21
21
|
const [kiosk, kioskOwnerCap] = tx.moveCall({
|
|
22
22
|
target: `${KIOSK_MODULE}::new`,
|
|
@@ -29,7 +29,7 @@ export function createKiosk(
|
|
|
29
29
|
* Calls the `kiosk::new()` function and shares the kiosk.
|
|
30
30
|
* Returns the `kioskOwnerCap` object.
|
|
31
31
|
*/
|
|
32
|
-
export function createKioskAndShare(tx:
|
|
32
|
+
export function createKioskAndShare(tx: Transaction): TransactionObjectArgument {
|
|
33
33
|
const [kiosk, kioskOwnerCap] = createKiosk(tx);
|
|
34
34
|
shareKiosk(tx, kiosk);
|
|
35
35
|
return kioskOwnerCap;
|
|
@@ -38,7 +38,7 @@ export function createKioskAndShare(tx: TransactionBlock): TransactionObjectArgu
|
|
|
38
38
|
/**
|
|
39
39
|
* Converts Transfer Policy to a shared object.
|
|
40
40
|
*/
|
|
41
|
-
export function shareKiosk(tx:
|
|
41
|
+
export function shareKiosk(tx: Transaction, kiosk: TransactionArgument) {
|
|
42
42
|
tx.moveCall({
|
|
43
43
|
target: `0x2::transfer::public_share_object`,
|
|
44
44
|
typeArguments: [KIOSK_TYPE],
|
|
@@ -51,7 +51,7 @@ export function shareKiosk(tx: TransactionBlock, kiosk: TransactionArgument) {
|
|
|
51
51
|
* Place an item to the Kiosk.
|
|
52
52
|
*/
|
|
53
53
|
export function place(
|
|
54
|
-
tx:
|
|
54
|
+
tx: Transaction,
|
|
55
55
|
itemType: string,
|
|
56
56
|
kiosk: ObjectArgument,
|
|
57
57
|
kioskCap: ObjectArgument,
|
|
@@ -73,7 +73,7 @@ export function place(
|
|
|
73
73
|
* locked without an option to take it out.
|
|
74
74
|
*/
|
|
75
75
|
export function lock(
|
|
76
|
-
tx:
|
|
76
|
+
tx: Transaction,
|
|
77
77
|
itemType: string,
|
|
78
78
|
kiosk: ObjectArgument,
|
|
79
79
|
kioskCap: ObjectArgument,
|
|
@@ -92,7 +92,7 @@ export function lock(
|
|
|
92
92
|
* Take an item from the Kiosk.
|
|
93
93
|
*/
|
|
94
94
|
export function take(
|
|
95
|
-
tx:
|
|
95
|
+
tx: Transaction,
|
|
96
96
|
itemType: string,
|
|
97
97
|
kiosk: ObjectArgument,
|
|
98
98
|
kioskCap: ObjectArgument,
|
|
@@ -112,7 +112,7 @@ export function take(
|
|
|
112
112
|
* List an item for sale.
|
|
113
113
|
*/
|
|
114
114
|
export function list(
|
|
115
|
-
tx:
|
|
115
|
+
tx: Transaction,
|
|
116
116
|
itemType: string,
|
|
117
117
|
kiosk: ObjectArgument,
|
|
118
118
|
kioskCap: ObjectArgument,
|
|
@@ -131,7 +131,7 @@ export function list(
|
|
|
131
131
|
* List an item for sale.
|
|
132
132
|
*/
|
|
133
133
|
export function delist(
|
|
134
|
-
tx:
|
|
134
|
+
tx: Transaction,
|
|
135
135
|
itemType: string,
|
|
136
136
|
kiosk: ObjectArgument,
|
|
137
137
|
kioskCap: ObjectArgument,
|
|
@@ -149,7 +149,7 @@ export function delist(
|
|
|
149
149
|
* Place an item to the Kiosk and list it for sale.
|
|
150
150
|
*/
|
|
151
151
|
export function placeAndList(
|
|
152
|
-
tx:
|
|
152
|
+
tx: Transaction,
|
|
153
153
|
itemType: string,
|
|
154
154
|
kiosk: ObjectArgument,
|
|
155
155
|
kioskCap: ObjectArgument,
|
|
@@ -168,7 +168,7 @@ export function placeAndList(
|
|
|
168
168
|
* a TransferRequest which needs to be dealt with (via a matching TransferPolicy).
|
|
169
169
|
*/
|
|
170
170
|
export function purchase(
|
|
171
|
-
tx:
|
|
171
|
+
tx: Transaction,
|
|
172
172
|
itemType: string,
|
|
173
173
|
kiosk: ObjectArgument,
|
|
174
174
|
itemId: string,
|
|
@@ -188,7 +188,7 @@ export function purchase(
|
|
|
188
188
|
* If the amount is null, then the entire balance will be withdrawn.
|
|
189
189
|
*/
|
|
190
190
|
export function withdrawFromKiosk(
|
|
191
|
-
tx:
|
|
191
|
+
tx: Transaction,
|
|
192
192
|
kiosk: ObjectArgument,
|
|
193
193
|
kioskCap: ObjectArgument,
|
|
194
194
|
amount?: string | bigint | number,
|
|
@@ -210,7 +210,7 @@ export function withdrawFromKiosk(
|
|
|
210
210
|
* Requires calling `returnValue` to return the item.
|
|
211
211
|
*/
|
|
212
212
|
export function borrowValue(
|
|
213
|
-
tx:
|
|
213
|
+
tx: Transaction,
|
|
214
214
|
itemType: string,
|
|
215
215
|
kiosk: ObjectArgument,
|
|
216
216
|
kioskCap: ObjectArgument,
|
|
@@ -230,7 +230,7 @@ export function borrowValue(
|
|
|
230
230
|
* Return an item to the Kiosk after it was `borrowValue`-d.
|
|
231
231
|
*/
|
|
232
232
|
export function returnValue(
|
|
233
|
-
tx:
|
|
233
|
+
tx: Transaction,
|
|
234
234
|
itemType: string,
|
|
235
235
|
kiosk: ObjectArgument,
|
|
236
236
|
item: TransactionArgument,
|
package/src/tx/personal-kiosk.ts
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
// Modifications Copyright (c) 2024 IOTA Stiftung
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
|
-
import type {
|
|
5
|
+
import type { Transaction, TransactionObjectArgument } from '@iota/iota-sdk/transactions';
|
|
6
6
|
|
|
7
7
|
import type { ObjectArgument } from '../types/index.js';
|
|
8
8
|
|
|
9
9
|
export function convertToPersonalTx(
|
|
10
|
-
tx:
|
|
10
|
+
tx: Transaction,
|
|
11
11
|
kiosk: ObjectArgument,
|
|
12
12
|
kioskOwnerCap: ObjectArgument,
|
|
13
13
|
packageId: string,
|
|
@@ -24,7 +24,7 @@ export function convertToPersonalTx(
|
|
|
24
24
|
* Transfers the personal kiosk Cap to the sender.
|
|
25
25
|
*/
|
|
26
26
|
export function transferPersonalCapTx(
|
|
27
|
-
tx:
|
|
27
|
+
tx: Transaction,
|
|
28
28
|
personalKioskCap: TransactionObjectArgument,
|
|
29
29
|
packageId: string,
|
|
30
30
|
) {
|