@mysten/kiosk 0.14.6 → 1.0.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 +114 -2
- package/dist/client/kiosk-client.d.mts +126 -0
- package/dist/client/kiosk-client.d.mts.map +1 -0
- package/dist/client/kiosk-client.mjs +124 -0
- package/dist/client/kiosk-client.mjs.map +1 -0
- package/dist/client/kiosk-transaction.d.mts +236 -0
- package/dist/client/kiosk-transaction.d.mts.map +1 -0
- package/dist/client/kiosk-transaction.mjs +472 -0
- package/dist/client/kiosk-transaction.mjs.map +1 -0
- package/dist/client/tp-transaction.d.mts +139 -0
- package/dist/client/tp-transaction.d.mts.map +1 -0
- package/dist/client/tp-transaction.mjs +273 -0
- package/dist/client/tp-transaction.mjs.map +1 -0
- package/dist/constants.d.mts +42 -0
- package/dist/constants.d.mts.map +1 -0
- package/dist/constants.mjs +62 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/contracts/0x2/bag.mjs +19 -0
- package/dist/contracts/0x2/bag.mjs.map +1 -0
- package/dist/contracts/0x2/balance.mjs +20 -0
- package/dist/contracts/0x2/balance.mjs.map +1 -0
- package/dist/contracts/0x2/deps/0x0000000000000000000000000000000000000000000000000000000000000001/type_name.mjs +16 -0
- package/dist/contracts/0x2/deps/0x0000000000000000000000000000000000000000000000000000000000000001/type_name.mjs.map +1 -0
- package/dist/contracts/0x2/kiosk.mjs +244 -0
- package/dist/contracts/0x2/kiosk.mjs.map +1 -0
- package/dist/contracts/0x2/kiosk_extension.mjs +25 -0
- package/dist/contracts/0x2/kiosk_extension.mjs.map +1 -0
- package/dist/contracts/0x2/transfer_policy.mjs +99 -0
- package/dist/contracts/0x2/transfer_policy.mjs.map +1 -0
- package/dist/contracts/0x2/vec_set.mjs +18 -0
- package/dist/contracts/0x2/vec_set.mjs.map +1 -0
- package/dist/contracts/kiosk/deps/sui/kiosk.mjs +98 -0
- package/dist/contracts/kiosk/deps/sui/kiosk.mjs.map +1 -0
- package/dist/contracts/kiosk/floor_price_rule.mjs +70 -0
- package/dist/contracts/kiosk/floor_price_rule.mjs.map +1 -0
- package/dist/contracts/kiosk/kiosk_lock_rule.mjs +72 -0
- package/dist/contracts/kiosk/kiosk_lock_rule.mjs.map +1 -0
- package/dist/contracts/kiosk/personal_kiosk.mjs +102 -0
- package/dist/contracts/kiosk/personal_kiosk.mjs.map +1 -0
- package/dist/contracts/kiosk/personal_kiosk_rule.mjs +66 -0
- package/dist/contracts/kiosk/personal_kiosk_rule.mjs.map +1 -0
- package/dist/contracts/kiosk/royalty_rule.mjs +115 -0
- package/dist/contracts/kiosk/royalty_rule.mjs.map +1 -0
- package/dist/contracts/utils/index.mjs +118 -0
- package/dist/contracts/utils/index.mjs.map +1 -0
- package/dist/index.d.mts +9 -0
- package/dist/index.mjs +9 -0
- package/dist/query/client-utils.mjs +30 -0
- package/dist/query/client-utils.mjs.map +1 -0
- package/dist/query/kiosk.mjs +154 -0
- package/dist/query/kiosk.mjs.map +1 -0
- package/dist/query/transfer-policy.mjs +110 -0
- package/dist/query/transfer-policy.mjs.map +1 -0
- package/dist/tx/kiosk.mjs +20 -0
- package/dist/tx/kiosk.mjs.map +1 -0
- package/dist/tx/rules/resolve.mjs +114 -0
- package/dist/tx/rules/resolve.mjs.map +1 -0
- package/dist/tx/transfer-policy.mjs +38 -0
- package/dist/tx/transfer-policy.mjs.map +1 -0
- package/dist/types/index.d.mts +23 -0
- package/dist/types/index.d.mts.map +1 -0
- package/dist/types/kiosk.d.mts +165 -0
- package/dist/types/kiosk.d.mts.map +1 -0
- package/dist/types/kiosk.mjs +21 -0
- package/dist/types/kiosk.mjs.map +1 -0
- package/dist/types/transfer-policy.d.mts +56 -0
- package/dist/types/transfer-policy.d.mts.map +1 -0
- package/dist/types/transfer-policy.mjs +19 -0
- package/dist/types/transfer-policy.mjs.map +1 -0
- package/dist/utils.d.mts +45 -0
- package/dist/utils.d.mts.map +1 -0
- package/dist/utils.mjs +156 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +31 -20
- package/src/client/kiosk-client.ts +42 -5
- package/src/client/kiosk-transaction.ts +144 -65
- package/src/client/tp-transaction.ts +149 -95
- package/src/constants.ts +19 -24
- package/src/contracts/0x2/accumulator.ts +24 -0
- package/src/contracts/0x2/accumulator_metadata.ts +38 -0
- package/src/contracts/0x2/accumulator_settlement.ts +14 -0
- package/src/contracts/0x2/address.ts +145 -0
- package/src/contracts/0x2/address_alias.ts +92 -0
- package/src/contracts/0x2/authenticator_state.ts +44 -0
- package/src/contracts/0x2/bag.ts +192 -0
- package/src/contracts/0x2/balance.ts +269 -0
- package/src/contracts/0x2/bcs.ts +495 -0
- package/src/contracts/0x2/bls12381.ts +717 -0
- package/src/contracts/0x2/borrow.ts +99 -0
- package/src/contracts/0x2/clock.ts +30 -0
- package/src/contracts/0x2/coin.ts +977 -0
- package/src/contracts/0x2/coin_registry.ts +874 -0
- package/src/contracts/0x2/config.ts +30 -0
- package/src/contracts/0x2/deny_list.ts +55 -0
- package/src/contracts/0x2/deps/0x0000000000000000000000000000000000000000000000000000000000000001/type_name.ts +12 -0
- package/src/contracts/0x2/derived_object.ts +95 -0
- package/src/contracts/0x2/display.ts +258 -0
- package/src/contracts/0x2/dynamic_field.ts +171 -0
- package/src/contracts/0x2/dynamic_object_field.ts +167 -0
- package/src/contracts/0x2/ecdsa_k1.ts +65 -0
- package/src/contracts/0x2/ecdsa_r1.ts +49 -0
- package/src/contracts/0x2/ecvrf.ts +29 -0
- package/src/contracts/0x2/ed25519.ts +25 -0
- package/src/contracts/0x2/event.ts +42 -0
- package/src/contracts/0x2/funds_accumulator.ts +86 -0
- package/src/contracts/0x2/groth16.ts +171 -0
- package/src/contracts/0x2/group_ops.ts +49 -0
- package/src/contracts/0x2/hash.ts +37 -0
- package/src/contracts/0x2/hex.ts +37 -0
- package/src/contracts/0x2/hmac.ts +21 -0
- package/src/contracts/0x2/kiosk.ts +797 -0
- package/src/contracts/0x2/kiosk_extension.ts +270 -0
- package/src/contracts/0x2/linked_table.ts +354 -0
- package/src/contracts/0x2/math.ts +117 -0
- package/src/contracts/0x2/nitro_attestation.ts +186 -0
- package/src/contracts/0x2/object.ts +249 -0
- package/src/contracts/0x2/object_bag.ts +210 -0
- package/src/contracts/0x2/object_table.ts +200 -0
- package/src/contracts/0x2/package.ts +414 -0
- package/src/contracts/0x2/party.ts +37 -0
- package/src/contracts/0x2/pay.ts +153 -0
- package/src/contracts/0x2/poseidon.ts +21 -0
- package/src/contracts/0x2/priority_queue.ts +139 -0
- package/src/contracts/0x2/random.ts +294 -0
- package/src/contracts/0x2/sui.ts +29 -0
- package/src/contracts/0x2/table.ts +200 -0
- package/src/contracts/0x2/table_vec.ts +232 -0
- package/src/contracts/0x2/token.ts +873 -0
- package/src/contracts/0x2/transfer.ts +216 -0
- package/src/contracts/0x2/transfer_policy.ts +400 -0
- package/src/contracts/0x2/tx_context.ts +129 -0
- package/src/contracts/0x2/types.ts +24 -0
- package/src/contracts/0x2/url.ts +77 -0
- package/src/contracts/0x2/vdf.ts +45 -0
- package/src/contracts/0x2/vec_map.ts +401 -0
- package/src/contracts/0x2/vec_set.ts +211 -0
- package/src/contracts/0x2/versioned.ts +153 -0
- package/src/contracts/0x2/zklogin_verified_id.ts +172 -0
- package/src/contracts/0x2/zklogin_verified_issuer.ts +99 -0
- package/src/contracts/kiosk/deps/sui/kiosk.ts +94 -0
- package/src/contracts/kiosk/deps/sui/object.ts +15 -0
- package/src/contracts/kiosk/floor_price_rule.ts +92 -0
- package/src/contracts/kiosk/kiosk_lock_rule.ts +97 -0
- package/src/contracts/kiosk/personal_kiosk.ts +295 -0
- package/src/contracts/kiosk/personal_kiosk_rule.ts +89 -0
- package/src/contracts/kiosk/royalty_rule.ts +144 -0
- package/src/contracts/kiosk/witness_rule.ts +92 -0
- package/src/contracts/utils/index.ts +234 -0
- package/src/query/client-utils.ts +51 -0
- package/src/query/kiosk.ts +128 -100
- package/src/query/transfer-policy.ts +112 -78
- package/src/tx/kiosk.ts +7 -231
- package/src/tx/rules/resolve.ts +97 -48
- package/src/tx/transfer-policy.ts +25 -86
- package/src/types/index.ts +3 -14
- package/src/types/kiosk.ts +10 -12
- package/src/types/transfer-policy.ts +4 -4
- package/src/utils.ts +90 -128
- package/dist/cjs/bcs.d.ts +0 -23
- package/dist/cjs/bcs.js +0 -50
- package/dist/cjs/bcs.js.map +0 -7
- package/dist/cjs/client/kiosk-client.d.ts +0 -76
- package/dist/cjs/client/kiosk-client.js +0 -123
- package/dist/cjs/client/kiosk-client.js.map +0 -7
- package/dist/cjs/client/kiosk-transaction.d.ts +0 -186
- package/dist/cjs/client/kiosk-transaction.js +0 -462
- package/dist/cjs/client/kiosk-transaction.js.map +0 -7
- package/dist/cjs/client/tp-transaction.d.ts +0 -114
- package/dist/cjs/client/tp-transaction.js +0 -307
- package/dist/cjs/client/tp-transaction.js.map +0 -7
- package/dist/cjs/constants.d.ts +0 -31
- package/dist/cjs/constants.js +0 -102
- package/dist/cjs/constants.js.map +0 -7
- package/dist/cjs/index.d.ts +0 -6
- package/dist/cjs/index.js +0 -24
- package/dist/cjs/index.js.map +0 -7
- package/dist/cjs/package.json +0 -5
- package/dist/cjs/query/kiosk.d.ts +0 -8
- package/dist/cjs/query/kiosk.js +0 -181
- package/dist/cjs/query/kiosk.js.map +0 -7
- package/dist/cjs/query/transfer-policy.d.ts +0 -29
- package/dist/cjs/query/transfer-policy.js +0 -92
- package/dist/cjs/query/transfer-policy.js.map +0 -7
- package/dist/cjs/tx/kiosk.d.ts +0 -71
- package/dist/cjs/tx/kiosk.js +0 -130
- package/dist/cjs/tx/kiosk.js.map +0 -7
- package/dist/cjs/tx/personal-kiosk.d.ts +0 -7
- package/dist/cjs/tx/personal-kiosk.js +0 -38
- package/dist/cjs/tx/personal-kiosk.js.map +0 -7
- package/dist/cjs/tx/rules/attach.d.ts +0 -7
- package/dist/cjs/tx/rules/attach.js +0 -62
- package/dist/cjs/tx/rules/attach.js.map +0 -7
- package/dist/cjs/tx/rules/resolve.d.ts +0 -15
- package/dist/cjs/tx/rules/resolve.js +0 -109
- package/dist/cjs/tx/rules/resolve.js.map +0 -7
- package/dist/cjs/tx/transfer-policy.d.ts +0 -29
- package/dist/cjs/tx/transfer-policy.js +0 -78
- package/dist/cjs/tx/transfer-policy.js.map +0 -7
- package/dist/cjs/types/index.d.ts +0 -27
- package/dist/cjs/types/index.js +0 -33
- package/dist/cjs/types/index.js.map +0 -7
- package/dist/cjs/types/kiosk.d.ts +0 -160
- package/dist/cjs/types/kiosk.js +0 -37
- package/dist/cjs/types/kiosk.js.map +0 -7
- package/dist/cjs/types/transfer-policy.d.ts +0 -53
- package/dist/cjs/types/transfer-policy.js +0 -35
- package/dist/cjs/types/transfer-policy.js.map +0 -7
- package/dist/cjs/utils.d.ts +0 -51
- package/dist/cjs/utils.js +0 -198
- package/dist/cjs/utils.js.map +0 -7
- package/dist/esm/bcs.d.ts +0 -23
- package/dist/esm/bcs.js +0 -35
- package/dist/esm/bcs.js.map +0 -7
- package/dist/esm/client/kiosk-client.d.ts +0 -76
- package/dist/esm/client/kiosk-client.js +0 -114
- package/dist/esm/client/kiosk-client.js.map +0 -7
- package/dist/esm/client/kiosk-transaction.d.ts +0 -186
- package/dist/esm/client/kiosk-transaction.js +0 -432
- package/dist/esm/client/kiosk-transaction.js.map +0 -7
- package/dist/esm/client/tp-transaction.d.ts +0 -114
- package/dist/esm/client/tp-transaction.js +0 -298
- package/dist/esm/client/tp-transaction.js.map +0 -7
- package/dist/esm/constants.d.ts +0 -31
- package/dist/esm/constants.js +0 -87
- package/dist/esm/constants.js.map +0 -7
- package/dist/esm/index.d.ts +0 -6
- package/dist/esm/index.js +0 -7
- package/dist/esm/index.js.map +0 -7
- package/dist/esm/package.json +0 -5
- package/dist/esm/query/kiosk.d.ts +0 -8
- package/dist/esm/query/kiosk.js +0 -169
- package/dist/esm/query/kiosk.js.map +0 -7
- package/dist/esm/query/transfer-policy.d.ts +0 -29
- package/dist/esm/query/transfer-policy.js +0 -76
- package/dist/esm/query/transfer-policy.js.map +0 -7
- package/dist/esm/tx/kiosk.d.ts +0 -71
- package/dist/esm/tx/kiosk.js +0 -110
- package/dist/esm/tx/kiosk.js.map +0 -7
- package/dist/esm/tx/personal-kiosk.d.ts +0 -7
- package/dist/esm/tx/personal-kiosk.js +0 -18
- package/dist/esm/tx/personal-kiosk.js.map +0 -7
- package/dist/esm/tx/rules/attach.d.ts +0 -7
- package/dist/esm/tx/rules/attach.js +0 -42
- package/dist/esm/tx/rules/attach.js.map +0 -7
- package/dist/esm/tx/rules/resolve.d.ts +0 -15
- package/dist/esm/tx/rules/resolve.js +0 -89
- package/dist/esm/tx/rules/resolve.js.map +0 -7
- package/dist/esm/tx/transfer-policy.d.ts +0 -29
- package/dist/esm/tx/transfer-policy.js +0 -58
- package/dist/esm/tx/transfer-policy.js.map +0 -7
- package/dist/esm/types/index.d.ts +0 -27
- package/dist/esm/types/index.js +0 -12
- package/dist/esm/types/index.js.map +0 -7
- package/dist/esm/types/kiosk.d.ts +0 -160
- package/dist/esm/types/kiosk.js +0 -17
- package/dist/esm/types/kiosk.js.map +0 -7
- package/dist/esm/types/transfer-policy.d.ts +0 -53
- package/dist/esm/types/transfer-policy.js +0 -15
- package/dist/esm/types/transfer-policy.js.map +0 -7
- package/dist/esm/utils.d.ts +0 -51
- package/dist/esm/utils.js +0 -183
- package/dist/esm/utils.js.map +0 -7
- package/dist/tsconfig.esm.tsbuildinfo +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/src/bcs.ts +0 -39
- package/src/tx/personal-kiosk.ts +0 -34
- package/src/tx/rules/attach.ts +0 -73
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
import { _new, borrowVal, delist, list, lock, place, placeAndList, purchase, returnVal, take, withdraw } from "../contracts/0x2/kiosk.mjs";
|
|
2
|
+
import { getNormalizedRuleType } from "../utils.mjs";
|
|
3
|
+
import { _new as _new$1, borrowVal as borrowVal$1, returnVal as returnVal$1, transferToSender } from "../contracts/kiosk/personal_kiosk.mjs";
|
|
4
|
+
import { confirmRequest } from "../contracts/0x2/transfer_policy.mjs";
|
|
5
|
+
import { createKioskAndShare } from "../tx/kiosk.mjs";
|
|
6
|
+
|
|
7
|
+
//#region src/client/kiosk-transaction.ts
|
|
8
|
+
/**
|
|
9
|
+
* A helper for building transactions that involve kiosk.
|
|
10
|
+
*/
|
|
11
|
+
var KioskTransaction = class {
|
|
12
|
+
#pendingShare;
|
|
13
|
+
#pendingTransfer;
|
|
14
|
+
#promise;
|
|
15
|
+
#personalCap;
|
|
16
|
+
#finalized = false;
|
|
17
|
+
constructor({ transaction, kioskClient, cap }) {
|
|
18
|
+
this.transaction = transaction;
|
|
19
|
+
this.kioskClient = kioskClient;
|
|
20
|
+
if (cap) this.setCap(cap);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Creates a kiosk and saves `kiosk` and `kioskOwnerCap` in state.
|
|
24
|
+
* Helpful if we want to chain some actions before sharing + transferring the cap to the specified address.
|
|
25
|
+
* @param borrow If true, the `kioskOwnerCap` is borrowed from the `PersonalKioskCap` to be used in next transactions.
|
|
26
|
+
*/
|
|
27
|
+
create() {
|
|
28
|
+
this.#validateFinalizedStatus();
|
|
29
|
+
this.#setPendingStatuses({
|
|
30
|
+
share: true,
|
|
31
|
+
transfer: true
|
|
32
|
+
});
|
|
33
|
+
const [kiosk, cap] = this.transaction.add(_new({}));
|
|
34
|
+
this.kiosk = kiosk;
|
|
35
|
+
this.kioskCap = cap;
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Creates a personal kiosk & shares it.
|
|
40
|
+
* The `PersonalKioskCap` is transferred to the signer.
|
|
41
|
+
* @param borrow If true, the `kioskOwnerCap` is borrowed from the `PersonalKioskCap` to be used in next transactions.
|
|
42
|
+
*/
|
|
43
|
+
createPersonal(borrow) {
|
|
44
|
+
this.#pendingShare = true;
|
|
45
|
+
return this.create().convertToPersonal(borrow);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Converts a kiosk to a Personal (Soulbound) Kiosk.
|
|
49
|
+
* Requires initialization by either calling `ktxb.create()` or `ktxb.setCap()`.
|
|
50
|
+
*/
|
|
51
|
+
convertToPersonal(borrow) {
|
|
52
|
+
this.#validateKioskIsSet();
|
|
53
|
+
const packageId = this.kioskClient.getRulePackageId("personalKioskRulePackageId");
|
|
54
|
+
const [cap] = this.transaction.add(_new$1({
|
|
55
|
+
package: packageId,
|
|
56
|
+
arguments: {
|
|
57
|
+
kiosk: this.kiosk,
|
|
58
|
+
cap: this.kioskCap
|
|
59
|
+
}
|
|
60
|
+
}));
|
|
61
|
+
if (borrow) this.#borrowFromPersonalCap(cap);
|
|
62
|
+
else this.#personalCap = cap;
|
|
63
|
+
this.#setPendingStatuses({ transfer: true });
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Single function way to create a kiosk, share it and transfer the cap to the specified address.
|
|
68
|
+
*/
|
|
69
|
+
createAndShare(address) {
|
|
70
|
+
this.#validateFinalizedStatus();
|
|
71
|
+
const cap = createKioskAndShare(this.transaction);
|
|
72
|
+
this.transaction.transferObjects([cap], address);
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Shares the kiosk.
|
|
77
|
+
*/
|
|
78
|
+
share() {
|
|
79
|
+
this.#validateKioskIsSet();
|
|
80
|
+
this.#setPendingStatuses({ share: false });
|
|
81
|
+
this.transaction.moveCall({
|
|
82
|
+
target: "0x2::transfer::public_share_object",
|
|
83
|
+
arguments: [this.kiosk],
|
|
84
|
+
typeArguments: ["0x2::kiosk::Kiosk"]
|
|
85
|
+
});
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Should be called only after `create` is called.
|
|
90
|
+
* It shares the kiosk & transfers the cap to the specified address.
|
|
91
|
+
*/
|
|
92
|
+
shareAndTransferCap(address) {
|
|
93
|
+
if (this.#personalCap) throw new Error("You can only call `shareAndTransferCap` on a non-personal kiosk.");
|
|
94
|
+
this.#setPendingStatuses({ transfer: false });
|
|
95
|
+
this.share();
|
|
96
|
+
this.transaction.transferObjects([this.kioskCap], address);
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* A function to borrow an item from a kiosk & execute any function with it.
|
|
101
|
+
* Example: You could borrow a Fren out of a kiosk, attach an accessory (or mix), and return it.
|
|
102
|
+
*/
|
|
103
|
+
borrowTx({ itemType, itemId }, callback) {
|
|
104
|
+
this.#validateKioskIsSet();
|
|
105
|
+
const [itemObj, promise] = this.transaction.add(borrowVal({
|
|
106
|
+
arguments: [
|
|
107
|
+
this.kiosk,
|
|
108
|
+
this.kioskCap,
|
|
109
|
+
itemId
|
|
110
|
+
],
|
|
111
|
+
typeArguments: [itemType]
|
|
112
|
+
}));
|
|
113
|
+
callback(itemObj);
|
|
114
|
+
return this.return({
|
|
115
|
+
itemType,
|
|
116
|
+
item: itemObj,
|
|
117
|
+
promise
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Borrows an item from the kiosk.
|
|
122
|
+
* This will fail if the item is listed for sale.
|
|
123
|
+
*
|
|
124
|
+
* Requires calling `return`.
|
|
125
|
+
*/
|
|
126
|
+
borrow({ itemType, itemId }) {
|
|
127
|
+
this.#validateKioskIsSet();
|
|
128
|
+
const [itemObj, promise] = this.transaction.add(borrowVal({
|
|
129
|
+
arguments: [
|
|
130
|
+
this.kiosk,
|
|
131
|
+
this.kioskCap,
|
|
132
|
+
itemId
|
|
133
|
+
],
|
|
134
|
+
typeArguments: [itemType]
|
|
135
|
+
}));
|
|
136
|
+
return [itemObj, promise];
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Returns the item back to the kiosk.
|
|
140
|
+
* Accepts the parameters returned from the `borrow` function.
|
|
141
|
+
*/
|
|
142
|
+
return({ itemType, item, promise }) {
|
|
143
|
+
this.#validateKioskIsSet();
|
|
144
|
+
this.transaction.add(returnVal({
|
|
145
|
+
arguments: [
|
|
146
|
+
this.kiosk,
|
|
147
|
+
item,
|
|
148
|
+
promise
|
|
149
|
+
],
|
|
150
|
+
typeArguments: [itemType]
|
|
151
|
+
}));
|
|
152
|
+
return this;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* A function to withdraw from kiosk
|
|
156
|
+
* @param address Where to transfer the coin.
|
|
157
|
+
* @param amount The amount we aim to withdraw.
|
|
158
|
+
*/
|
|
159
|
+
withdraw(address, amount) {
|
|
160
|
+
this.#validateKioskIsSet();
|
|
161
|
+
const [coin] = this.transaction.add(withdraw({ arguments: [
|
|
162
|
+
this.kiosk,
|
|
163
|
+
this.kioskCap,
|
|
164
|
+
amount == null ? null : BigInt(amount)
|
|
165
|
+
] }));
|
|
166
|
+
this.transaction.transferObjects([coin], address);
|
|
167
|
+
return this;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* A function to place an item in the kiosk.
|
|
171
|
+
* @param itemType The type `T` of the item
|
|
172
|
+
* @param item The ID or Transaction Argument of the item
|
|
173
|
+
*/
|
|
174
|
+
place({ itemType, item }) {
|
|
175
|
+
this.#validateKioskIsSet();
|
|
176
|
+
const itemArg = typeof item === "string" ? this.transaction.object(item) : item;
|
|
177
|
+
this.transaction.add(place({
|
|
178
|
+
arguments: [
|
|
179
|
+
this.kiosk,
|
|
180
|
+
this.kioskCap,
|
|
181
|
+
itemArg
|
|
182
|
+
],
|
|
183
|
+
typeArguments: [itemType]
|
|
184
|
+
}));
|
|
185
|
+
return this;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* A function to place an item in the kiosk and list it for sale in one transaction.
|
|
189
|
+
* @param itemType The type `T` of the item
|
|
190
|
+
* @param item The ID or Transaction Argument of the item
|
|
191
|
+
* @param price The price in MIST
|
|
192
|
+
*/
|
|
193
|
+
placeAndList({ itemType, item, price }) {
|
|
194
|
+
this.#validateKioskIsSet();
|
|
195
|
+
const itemArg = typeof item === "string" ? this.transaction.object(item) : item;
|
|
196
|
+
const priceArg = typeof price === "string" ? BigInt(price) : price;
|
|
197
|
+
this.transaction.add(placeAndList({
|
|
198
|
+
arguments: [
|
|
199
|
+
this.kiosk,
|
|
200
|
+
this.kioskCap,
|
|
201
|
+
itemArg,
|
|
202
|
+
priceArg
|
|
203
|
+
],
|
|
204
|
+
typeArguments: [itemType]
|
|
205
|
+
}));
|
|
206
|
+
return this;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* A function to list an item in the kiosk.
|
|
210
|
+
* @param itemType The type `T` of the item
|
|
211
|
+
* @param itemId The ID of the item
|
|
212
|
+
* @param price The price in MIST
|
|
213
|
+
*/
|
|
214
|
+
list({ itemType, itemId, price }) {
|
|
215
|
+
this.#validateKioskIsSet();
|
|
216
|
+
const priceArg = typeof price === "string" ? BigInt(price) : price;
|
|
217
|
+
this.transaction.add(list({
|
|
218
|
+
arguments: [
|
|
219
|
+
this.kiosk,
|
|
220
|
+
this.kioskCap,
|
|
221
|
+
itemId,
|
|
222
|
+
priceArg
|
|
223
|
+
],
|
|
224
|
+
typeArguments: [itemType]
|
|
225
|
+
}));
|
|
226
|
+
return this;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* A function to delist an item from the kiosk.
|
|
230
|
+
* @param itemType The type `T` of the item
|
|
231
|
+
* @param itemId The ID of the item
|
|
232
|
+
*/
|
|
233
|
+
delist({ itemType, itemId }) {
|
|
234
|
+
this.#validateKioskIsSet();
|
|
235
|
+
this.transaction.add(delist({
|
|
236
|
+
arguments: [
|
|
237
|
+
this.kiosk,
|
|
238
|
+
this.kioskCap,
|
|
239
|
+
itemId
|
|
240
|
+
],
|
|
241
|
+
typeArguments: [itemType]
|
|
242
|
+
}));
|
|
243
|
+
return this;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* A function to take an item from the kiosk. The transaction won't succeed if the item is listed or locked.
|
|
247
|
+
|
|
248
|
+
* @param itemType The type `T` of the item
|
|
249
|
+
* @param itemId The ID of the item
|
|
250
|
+
*/
|
|
251
|
+
take({ itemType, itemId }) {
|
|
252
|
+
this.#validateKioskIsSet();
|
|
253
|
+
const [item] = this.transaction.add(take({
|
|
254
|
+
arguments: [
|
|
255
|
+
this.kiosk,
|
|
256
|
+
this.kioskCap,
|
|
257
|
+
itemId
|
|
258
|
+
],
|
|
259
|
+
typeArguments: [itemType]
|
|
260
|
+
}));
|
|
261
|
+
return item;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Transfer a non-locked/non-listed item to an address.
|
|
265
|
+
*
|
|
266
|
+
* @param itemType The type `T` of the item
|
|
267
|
+
* @param itemId The ID of the item
|
|
268
|
+
* @param address The destination address
|
|
269
|
+
*/
|
|
270
|
+
transfer({ itemType, itemId, address }) {
|
|
271
|
+
this.#validateKioskIsSet();
|
|
272
|
+
const item = this.take({
|
|
273
|
+
itemType,
|
|
274
|
+
itemId
|
|
275
|
+
});
|
|
276
|
+
this.transaction.transferObjects([item], address);
|
|
277
|
+
return this;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* A function to take lock an item in the kiosk.
|
|
281
|
+
|
|
282
|
+
* @param itemType The type `T` of the item
|
|
283
|
+
* @param item The ID or Transaction Argument of the item
|
|
284
|
+
* @param itemId The ID of the item - Deprecated: Use `item` instead.
|
|
285
|
+
* @param policy The Policy ID or Transaction Argument for item T
|
|
286
|
+
*/
|
|
287
|
+
lock({ itemType, item, itemId, policy }) {
|
|
288
|
+
this.#validateKioskIsSet();
|
|
289
|
+
const itemArg = itemId ? this.transaction.object(itemId) : typeof item === "string" ? this.transaction.object(item) : item;
|
|
290
|
+
const policyArg = typeof policy === "string" ? this.transaction.object(policy) : policy;
|
|
291
|
+
this.transaction.add(lock({
|
|
292
|
+
arguments: [
|
|
293
|
+
this.kiosk,
|
|
294
|
+
this.kioskCap,
|
|
295
|
+
policyArg,
|
|
296
|
+
itemArg
|
|
297
|
+
],
|
|
298
|
+
typeArguments: [itemType]
|
|
299
|
+
}));
|
|
300
|
+
return this;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Purchase an item from a seller's kiosk.
|
|
304
|
+
* Returns [item, transferRequest]
|
|
305
|
+
* Can be called like: `const [item, transferRequest] = kioskTx.purchase({...})`
|
|
306
|
+
* @param itemType The type `T` of the item
|
|
307
|
+
* @param itemId The ID of the item
|
|
308
|
+
* @param price The price in MIST
|
|
309
|
+
* @param sellerKiosk The kiosk which is selling the item. Can be an id or an object argument.
|
|
310
|
+
*/
|
|
311
|
+
purchase({ itemType, itemId, price, sellerKiosk }) {
|
|
312
|
+
const [coin] = this.transaction.splitCoins(this.transaction.gas, [price]);
|
|
313
|
+
const kioskArg = typeof sellerKiosk === "string" ? this.transaction.object(sellerKiosk) : sellerKiosk;
|
|
314
|
+
const [item, transferRequest] = this.transaction.add(purchase({
|
|
315
|
+
arguments: [
|
|
316
|
+
kioskArg,
|
|
317
|
+
itemId,
|
|
318
|
+
coin
|
|
319
|
+
],
|
|
320
|
+
typeArguments: [itemType]
|
|
321
|
+
}));
|
|
322
|
+
return [item, transferRequest];
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* A function to purchase and resolve a transfer policy.
|
|
326
|
+
* If the transfer policy has the `lock` rule, the item is locked in the kiosk.
|
|
327
|
+
* Otherwise, the item is placed in the kiosk.
|
|
328
|
+
* @param itemType The type of the item
|
|
329
|
+
* @param itemId The id of the item
|
|
330
|
+
* @param price The price of the specified item
|
|
331
|
+
* @param sellerKiosk The kiosk which is selling the item. Can be an id or an object argument.
|
|
332
|
+
* @param extraArgs Used to pass arguments for custom rule resolvers.
|
|
333
|
+
*/
|
|
334
|
+
async purchaseAndResolve({ itemType, itemId, price, sellerKiosk, extraArgs }) {
|
|
335
|
+
this.#validateKioskIsSet();
|
|
336
|
+
const policies = await this.kioskClient.getTransferPolicies({ type: itemType });
|
|
337
|
+
if (policies.length === 0) throw new Error(`The type ${itemType} doesn't have a Transfer Policy so it can't be traded through kiosk.`);
|
|
338
|
+
const policy = policies[0];
|
|
339
|
+
const [purchasedItem, transferRequest] = this.purchase({
|
|
340
|
+
itemType,
|
|
341
|
+
itemId,
|
|
342
|
+
price,
|
|
343
|
+
sellerKiosk
|
|
344
|
+
});
|
|
345
|
+
let canTransferOutsideKiosk = true;
|
|
346
|
+
for (const rule of policy.rules) {
|
|
347
|
+
const ruleDefinition = this.kioskClient.rules.find((x) => getNormalizedRuleType(x.rule) === getNormalizedRuleType(rule));
|
|
348
|
+
if (!ruleDefinition) throw new Error(`No resolver for the following rule: ${rule}.`);
|
|
349
|
+
if (ruleDefinition.hasLockingRule) canTransferOutsideKiosk = false;
|
|
350
|
+
await ruleDefinition.resolveRuleFunction({
|
|
351
|
+
packageId: ruleDefinition.packageId,
|
|
352
|
+
transaction: this.transaction,
|
|
353
|
+
itemType,
|
|
354
|
+
itemId,
|
|
355
|
+
price: price.toString(),
|
|
356
|
+
sellerKiosk,
|
|
357
|
+
policyId: policy.id,
|
|
358
|
+
transferRequest,
|
|
359
|
+
purchasedItem,
|
|
360
|
+
kiosk: this.kiosk,
|
|
361
|
+
kioskCap: this.kioskCap,
|
|
362
|
+
extraArgs: extraArgs || {},
|
|
363
|
+
kioskClient: this.kioskClient
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
this.transaction.add(confirmRequest({
|
|
367
|
+
arguments: [this.transaction.object(policy.id), transferRequest],
|
|
368
|
+
typeArguments: [itemType]
|
|
369
|
+
}));
|
|
370
|
+
if (canTransferOutsideKiosk) this.place({
|
|
371
|
+
itemType,
|
|
372
|
+
item: purchasedItem
|
|
373
|
+
});
|
|
374
|
+
return this;
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* A function to setup the client using an existing `ownerCap`,
|
|
378
|
+
* as return from the `kioskClient.getOwnedKiosks` function.
|
|
379
|
+
* @param cap `KioskOwnerCap` object as returned from `getOwnedKiosks` SDK call.
|
|
380
|
+
*/
|
|
381
|
+
setCap(cap) {
|
|
382
|
+
this.#validateFinalizedStatus();
|
|
383
|
+
this.kiosk = this.transaction.object(cap.kioskId);
|
|
384
|
+
if (!cap.isPersonal) {
|
|
385
|
+
this.kioskCap = this.transaction.object(cap.objectId);
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
return this.#borrowFromPersonalCap(cap.objectId);
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* A function that ends up the kiosk building tx & returns the `kioskOwnerCap` back to the
|
|
392
|
+
* `PersonalKioskCap`, in case we are operating on a personal kiosk.
|
|
393
|
+
* It will also share the `kiosk` if it's not shared, and finalize the transfer of the personal cap if it's pending.
|
|
394
|
+
*/
|
|
395
|
+
finalize() {
|
|
396
|
+
this.#validateKioskIsSet();
|
|
397
|
+
if (this.#pendingShare) this.share();
|
|
398
|
+
if (!this.#personalCap) {
|
|
399
|
+
if (this.#pendingTransfer) throw new Error("You need to transfer the `kioskOwnerCap` by calling `shareAndTransferCap()` before wrap");
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
if (this.#promise) {
|
|
403
|
+
const packageId = this.kioskClient.getRulePackageId("personalKioskRulePackageId");
|
|
404
|
+
this.transaction.add(returnVal$1({
|
|
405
|
+
package: packageId,
|
|
406
|
+
arguments: {
|
|
407
|
+
self: this.#personalCap,
|
|
408
|
+
cap: this.kioskCap,
|
|
409
|
+
borrow: this.#promise
|
|
410
|
+
}
|
|
411
|
+
}));
|
|
412
|
+
}
|
|
413
|
+
if (this.#pendingTransfer) {
|
|
414
|
+
const packageId = this.kioskClient.getRulePackageId("personalKioskRulePackageId");
|
|
415
|
+
this.transaction.add(transferToSender({
|
|
416
|
+
package: packageId,
|
|
417
|
+
arguments: { self: this.#personalCap }
|
|
418
|
+
}));
|
|
419
|
+
}
|
|
420
|
+
this.#finalized = true;
|
|
421
|
+
}
|
|
422
|
+
setKioskCap(cap) {
|
|
423
|
+
this.#validateFinalizedStatus();
|
|
424
|
+
this.kioskCap = cap;
|
|
425
|
+
return this;
|
|
426
|
+
}
|
|
427
|
+
setKiosk(kiosk) {
|
|
428
|
+
this.#validateFinalizedStatus();
|
|
429
|
+
this.kiosk = kiosk;
|
|
430
|
+
return this;
|
|
431
|
+
}
|
|
432
|
+
getKiosk() {
|
|
433
|
+
this.#validateFinalizedStatus();
|
|
434
|
+
if (!this.kiosk) throw new Error("Kiosk is not set.");
|
|
435
|
+
return this.kiosk;
|
|
436
|
+
}
|
|
437
|
+
getKioskCap() {
|
|
438
|
+
this.#validateFinalizedStatus();
|
|
439
|
+
if (!this.kioskCap) throw new Error("Kiosk cap is not set");
|
|
440
|
+
return this.kioskCap;
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* A function to borrow from `personalCap`.
|
|
444
|
+
*/
|
|
445
|
+
#borrowFromPersonalCap(personalCap) {
|
|
446
|
+
const packageId = this.kioskClient.getRulePackageId("personalKioskRulePackageId");
|
|
447
|
+
const personalCapArg = typeof personalCap === "string" ? this.transaction.object(personalCap) : personalCap;
|
|
448
|
+
const [kioskCap, promise] = this.transaction.add(borrowVal$1({
|
|
449
|
+
package: packageId,
|
|
450
|
+
arguments: { self: personalCapArg }
|
|
451
|
+
}));
|
|
452
|
+
this.kioskCap = kioskCap;
|
|
453
|
+
this.#personalCap = personalCapArg;
|
|
454
|
+
this.#promise = promise;
|
|
455
|
+
return this;
|
|
456
|
+
}
|
|
457
|
+
#setPendingStatuses({ share, transfer }) {
|
|
458
|
+
if (transfer !== void 0) this.#pendingTransfer = transfer;
|
|
459
|
+
if (share !== void 0) this.#pendingShare = share;
|
|
460
|
+
}
|
|
461
|
+
#validateKioskIsSet() {
|
|
462
|
+
this.#validateFinalizedStatus();
|
|
463
|
+
if (!this.kiosk || !this.kioskCap) throw new Error("You need to initialize the client by either supplying an existing owner cap or by creating a new by calling `.create()`");
|
|
464
|
+
}
|
|
465
|
+
#validateFinalizedStatus() {
|
|
466
|
+
if (this.#finalized) throw new Error("You can't add more transactions to a finalized kiosk transaction.");
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
//#endregion
|
|
471
|
+
export { KioskTransaction };
|
|
472
|
+
//# sourceMappingURL=kiosk-transaction.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kiosk-transaction.mjs","names":["#validateFinalizedStatus","#setPendingStatuses","kioskContract._new","#pendingShare","#validateKioskIsSet","personalKioskContract._new","#borrowFromPersonalCap","#personalCap","kioskContract.borrowVal","kioskContract.returnVal","kioskContract.withdraw","kioskContract.place","kioskContract.placeAndList","kioskContract.list","kioskContract.delist","kioskContract.take","kioskContract.lock","kioskContract.purchase","transferPolicyContract.confirmRequest","#pendingTransfer","#promise","personalKioskContract.returnVal","personalKioskContract.transferToSender","#finalized","personalKioskContract.borrowVal"],"sources":["../../src/client/kiosk-transaction.ts"],"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 kioskContract from '../contracts/0x2/kiosk.js';\nimport * as transferPolicyContract from '../contracts/0x2/transfer_policy.js';\nimport * as personalKioskContract from '../contracts/kiosk/personal_kiosk.js';\nimport { createKioskAndShare } from '../tx/kiosk.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/**\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({ transaction, kioskClient, cap }: 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] = this.transaction.add(kioskContract._new({}));\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 packageId = this.kioskClient.getRulePackageId('personalKioskRulePackageId');\n\n\t\tconst [cap] = this.transaction.add(\n\t\t\tpersonalKioskContract._new({\n\t\t\t\tpackage: packageId,\n\t\t\t\targuments: {\n\t\t\t\t\tkiosk: this.kiosk!,\n\t\t\t\t\tcap: this.kioskCap!,\n\t\t\t\t},\n\t\t\t}),\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 = createKioskAndShare(this.transaction);\n\t\tthis.transaction.transferObjects([cap], address);\n\t\treturn this;\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\tthis.transaction.moveCall({\n\t\t\ttarget: '0x2::transfer::public_share_object',\n\t\t\targuments: [this.kiosk!],\n\t\t\ttypeArguments: ['0x2::kiosk::Kiosk'],\n\t\t});\n\t\treturn this;\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!], address);\n\t\treturn this;\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] = this.transaction.add(\n\t\t\tkioskContract.borrowVal({\n\t\t\t\targuments: [this.kiosk!, this.kioskCap!, itemId],\n\t\t\t\ttypeArguments: [itemType],\n\t\t\t}),\n\t\t);\n\n\t\tcallback(itemObj);\n\n\t\treturn this.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] = this.transaction.add(\n\t\t\tkioskContract.borrowVal({\n\t\t\t\targuments: [this.kiosk!, this.kioskCap!, itemId],\n\t\t\t\ttypeArguments: [itemType],\n\t\t\t}),\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\tthis.transaction.add(\n\t\t\tkioskContract.returnVal({\n\t\t\t\targuments: [this.kiosk!, item, promise],\n\t\t\t\ttypeArguments: [itemType],\n\t\t\t}),\n\t\t);\n\t\treturn this;\n\t}\n\n\t/**\n\t * A function to withdraw from kiosk\n\t * @param address Where to transfer 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\n\t\tconst [coin] = this.transaction.add(\n\t\t\tkioskContract.withdraw({\n\t\t\t\targuments: [this.kiosk!, this.kioskCap!, amount == null ? null : BigInt(amount)],\n\t\t\t}),\n\t\t);\n\t\tthis.transaction.transferObjects([coin], 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\tconst itemArg = typeof item === 'string' ? this.transaction.object(item) : item;\n\t\tthis.transaction.add(\n\t\t\tkioskContract.place({\n\t\t\t\targuments: [this.kiosk!, this.kioskCap!, itemArg],\n\t\t\t\ttypeArguments: [itemType],\n\t\t\t}),\n\t\t);\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\tconst itemArg = typeof item === 'string' ? this.transaction.object(item) : item;\n\t\tconst priceArg = typeof price === 'string' ? BigInt(price) : price;\n\t\tthis.transaction.add(\n\t\t\tkioskContract.placeAndList({\n\t\t\t\targuments: [this.kiosk!, this.kioskCap!, itemArg, priceArg],\n\t\t\t\ttypeArguments: [itemType],\n\t\t\t}),\n\t\t);\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\tconst priceArg = typeof price === 'string' ? BigInt(price) : price;\n\t\tthis.transaction.add(\n\t\t\tkioskContract.list({\n\t\t\t\targuments: [this.kiosk!, this.kioskCap!, itemId, priceArg],\n\t\t\t\ttypeArguments: [itemType],\n\t\t\t}),\n\t\t);\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\tthis.transaction.add(\n\t\t\tkioskContract.delist({\n\t\t\t\targuments: [this.kiosk!, this.kioskCap!, itemId],\n\t\t\t\ttypeArguments: [itemType],\n\t\t\t}),\n\t\t);\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\tconst [item] = this.transaction.add(\n\t\t\tkioskContract.take({\n\t\t\t\targuments: [this.kiosk!, this.kioskCap!, itemId],\n\t\t\t\ttypeArguments: [itemType],\n\t\t\t}),\n\t\t);\n\t\treturn item;\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], 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\tconst itemArg = itemId\n\t\t\t? this.transaction.object(itemId)\n\t\t\t: typeof item === 'string'\n\t\t\t\t? this.transaction.object(item)\n\t\t\t\t: item;\n\t\tconst policyArg = typeof policy === 'string' ? this.transaction.object(policy) : policy;\n\t\tthis.transaction.add(\n\t\t\tkioskContract.lock({\n\t\t\t\targuments: [this.kiosk!, this.kioskCap!, policyArg, itemArg],\n\t\t\t\ttypeArguments: [itemType],\n\t\t\t}),\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.transaction.splitCoins(this.transaction.gas, [price]);\n\t\tconst kioskArg =\n\t\t\ttypeof sellerKiosk === 'string' ? this.transaction.object(sellerKiosk) : sellerKiosk;\n\t\tconst [item, transferRequest] = this.transaction.add(\n\t\t\tkioskContract.purchase({\n\t\t\t\targuments: [kioskArg, itemId, coin],\n\t\t\t\ttypeArguments: [itemType],\n\t\t\t}),\n\t\t);\n\t\treturn [item, transferRequest];\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\tawait ruleDefinition.resolveRuleFunction({\n\t\t\t\tpackageId: ruleDefinition.packageId,\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\tkioskClient: this.kioskClient,\n\t\t\t});\n\t\t}\n\n\t\tthis.transaction.add(\n\t\t\ttransferPolicyContract.confirmRequest({\n\t\t\t\targuments: [this.transaction.object(policy.id), transferRequest],\n\t\t\t\ttypeArguments: [itemType],\n\t\t\t}),\n\t\t);\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\t// if we have a promise, return the `ownerCap` back to the personal cap.\n\t\tif (this.#promise) {\n\t\t\tconst packageId = this.kioskClient.getRulePackageId('personalKioskRulePackageId');\n\n\t\t\tthis.transaction.add(\n\t\t\t\tpersonalKioskContract.returnVal({\n\t\t\t\t\tpackage: packageId,\n\t\t\t\t\targuments: {\n\t\t\t\t\t\tself: this.#personalCap,\n\t\t\t\t\t\tcap: this.kioskCap!,\n\t\t\t\t\t\tborrow: this.#promise,\n\t\t\t\t\t},\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\tconst packageId = this.kioskClient.getRulePackageId('personalKioskRulePackageId');\n\n\t\t\tthis.transaction.add(\n\t\t\t\tpersonalKioskContract.transferToSender({\n\t\t\t\t\tpackage: packageId,\n\t\t\t\t\targuments: { self: this.#personalCap },\n\t\t\t\t}),\n\t\t\t);\n\t\t}\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 packageId = this.kioskClient.getRulePackageId('personalKioskRulePackageId');\n\t\tconst personalCapArg =\n\t\t\ttypeof personalCap === 'string' ? this.transaction.object(personalCap) : personalCap;\n\t\tconst [kioskCap, promise] = this.transaction.add(\n\t\t\tpersonalKioskContract.borrowVal({\n\t\t\t\tpackage: packageId,\n\t\t\t\targuments: { self: personalCapArg },\n\t\t\t}),\n\t\t);\n\n\t\tthis.kioskCap = kioskCap;\n\t\tthis.#personalCap = personalCapArg;\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"],"mappings":";;;;;;;;;;AA4CA,IAAa,mBAAb,MAA8B;CAM7B;CAEA;CAEA;CAEA;CAEA,aAAsB;CAEtB,YAAY,EAAE,aAAa,aAAa,OAA+B;AACtE,OAAK,cAAc;AACnB,OAAK,cAAc;AAEnB,MAAI,IAAK,MAAK,OAAO,IAAI;;;;;;;CAQ1B,SAAS;AACR,QAAKA,yBAA0B;AAC/B,QAAKC,mBAAoB;GACxB,OAAO;GACP,UAAU;GACV,CAAC;EACF,MAAM,CAAC,OAAO,OAAO,KAAK,YAAY,IAAIC,KAAmB,EAAE,CAAC,CAAC;AACjE,OAAK,QAAQ;AACb,OAAK,WAAW;AAChB,SAAO;;;;;;;CAQR,eAAe,QAAkB;AAChC,QAAKC,eAAgB;AACrB,SAAO,KAAK,QAAQ,CAAC,kBAAkB,OAAO;;;;;;CAO/C,kBAAkB,QAAkB;AACnC,QAAKC,oBAAqB;EAE1B,MAAM,YAAY,KAAK,YAAY,iBAAiB,6BAA6B;EAEjF,MAAM,CAAC,OAAO,KAAK,YAAY,IAC9BC,OAA2B;GAC1B,SAAS;GACT,WAAW;IACV,OAAO,KAAK;IACZ,KAAK,KAAK;IACV;GACD,CAAC,CACF;AAGD,MAAI,OAAQ,OAAKC,sBAAuB,IAAI;MACvC,OAAKC,cAAe;AAEzB,QAAKN,mBAAoB,EAAE,UAAU,MAAM,CAAC;AAC5C,SAAO;;;;;CAMR,eAAe,SAAiB;AAC/B,QAAKD,yBAA0B;EAC/B,MAA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C,CAAC,CACF;AAED,OAAK,WAAW;AAChB,QAAKjB,cAAe;AACpB,QAAKa,UAAW;AAEhB,SAAO;;CAGR,oBAAoB,EAAE,OAAO,YAAqD;AACjF,MAAI,aAAa,OAAW,OAAKD,kBAAmB;AACpD,MAAI,UAAU,OAAW,OAAKhB,eAAgB;;CAG/C,sBAAsB;AACrB,QAAKH,yBAA0B;AAE/B,MAAI,CAAC,KAAK,SAAS,CAAC,KAAK,SACxB,OAAM,IAAI,MACT,0HACA;;CAIH,2BAA2B;AAC1B,MAAI,MAAKuB,UACR,OAAM,IAAI,MAAM,oEAAoE"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { KioskClient } from "./kiosk-client.mjs";
|
|
2
|
+
import { TransferPolicyCap } from "../types/transfer-policy.mjs";
|
|
3
|
+
import { ObjectArgument } from "../types/index.mjs";
|
|
4
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
5
|
+
|
|
6
|
+
//#region src/client/tp-transaction.d.ts
|
|
7
|
+
type TransferPolicyBaseParams = {
|
|
8
|
+
type: string;
|
|
9
|
+
publisher: ObjectArgument;
|
|
10
|
+
skipCheck?: boolean;
|
|
11
|
+
};
|
|
12
|
+
type TransferPolicyTransactionParams = {
|
|
13
|
+
kioskClient: KioskClient;
|
|
14
|
+
transaction: Transaction;
|
|
15
|
+
cap?: TransferPolicyCap;
|
|
16
|
+
};
|
|
17
|
+
declare class TransferPolicyTransaction {
|
|
18
|
+
#private;
|
|
19
|
+
transaction: Transaction;
|
|
20
|
+
kioskClient: KioskClient;
|
|
21
|
+
policy?: ObjectArgument;
|
|
22
|
+
policyCap?: ObjectArgument;
|
|
23
|
+
type?: string;
|
|
24
|
+
constructor({
|
|
25
|
+
kioskClient,
|
|
26
|
+
transaction,
|
|
27
|
+
cap
|
|
28
|
+
}: TransferPolicyTransactionParams);
|
|
29
|
+
/**
|
|
30
|
+
* A function to create a new transfer policy.
|
|
31
|
+
* Checks if there's already an existing transfer policy to prevent
|
|
32
|
+
* double transfer polciy mistakes.
|
|
33
|
+
* There's an optional `skipCheck` flag that will just create the policy
|
|
34
|
+
* without checking
|
|
35
|
+
*
|
|
36
|
+
* @param type The Type (`T`) for which we're creating the transfer policy.
|
|
37
|
+
* @param publisher The Publisher Object Id.
|
|
38
|
+
* @param address Address to save the `TransferPolicyCap` object to.
|
|
39
|
+
* @param skipCheck (Optional) skip checking if a transfer policy already exists
|
|
40
|
+
*/
|
|
41
|
+
createAndShare({
|
|
42
|
+
type,
|
|
43
|
+
publisher,
|
|
44
|
+
address,
|
|
45
|
+
skipCheck
|
|
46
|
+
}: TransferPolicyBaseParams & {
|
|
47
|
+
address: string;
|
|
48
|
+
}): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* A convenient function to create a Transfer Policy and attach some rules
|
|
51
|
+
* before sharing it (so you can prepare it in a single PTB)
|
|
52
|
+
* @param type The Type (`T`) for which we're creating the transfer policy.
|
|
53
|
+
* @param publisher The Publisher Object Id.
|
|
54
|
+
* @param address Address to save the `TransferPolicyCap` object to.
|
|
55
|
+
* @param skipCheck (Optional) skip checking if a transfer policy already exists
|
|
56
|
+
*/
|
|
57
|
+
create({
|
|
58
|
+
type,
|
|
59
|
+
publisher,
|
|
60
|
+
skipCheck
|
|
61
|
+
}: TransferPolicyBaseParams): Promise<TransferPolicyTransaction>;
|
|
62
|
+
/**
|
|
63
|
+
* This can be called after calling the `create` function to share the `TransferPolicy`,
|
|
64
|
+
* and transfer the `TransferPolicyCap` to the specified address
|
|
65
|
+
*
|
|
66
|
+
* @param address The address to transfer the `TransferPolicyCap`
|
|
67
|
+
*/
|
|
68
|
+
shareAndTransferCap(address: string): void;
|
|
69
|
+
/**
|
|
70
|
+
* Setup the TransferPolicy by passing a `cap` returned from `kioskClient.getOwnedTransferPolicies` or
|
|
71
|
+
* `kioskClient.getOwnedTransferPoliciesByType`.
|
|
72
|
+
* @param policyCapId The `TransferPolicyCap`
|
|
73
|
+
*/
|
|
74
|
+
setCap({
|
|
75
|
+
policyId,
|
|
76
|
+
policyCapId,
|
|
77
|
+
type
|
|
78
|
+
}: TransferPolicyCap): this;
|
|
79
|
+
/**
|
|
80
|
+
* Withdraw from the transfer policy's profits.
|
|
81
|
+
* @param address Address to transfer the profits to.
|
|
82
|
+
* @param amount (Optional) amount parameter. Will withdraw all profits if the amount is not specified.
|
|
83
|
+
*/
|
|
84
|
+
withdraw(address: string, amount?: string | bigint): this;
|
|
85
|
+
/**
|
|
86
|
+
* Adds the Kiosk Royalty rule to the Transfer Policy.
|
|
87
|
+
* You can pass the percentage, as well as a minimum amount.
|
|
88
|
+
* The royalty that will be paid is the MAX(percentage, minAmount).
|
|
89
|
+
* You can pass 0 in either value if you want only percentage royalty, or a fixed amount fee.
|
|
90
|
+
* (but you should define at least one of them for the rule to make sense).
|
|
91
|
+
*
|
|
92
|
+
* @param percentageBps The royalty percentage in basis points. Use `percentageToBasisPoints` helper to convert from percentage [0,100].
|
|
93
|
+
* @param minAmount The minimum royalty amount per request in MIST.
|
|
94
|
+
*/
|
|
95
|
+
addRoyaltyRule(percentageBps: number | string,
|
|
96
|
+
// this is in basis points.
|
|
97
|
+
minAmount: number | string): this;
|
|
98
|
+
/**
|
|
99
|
+
* Adds the Kiosk Lock Rule to the Transfer Policy.
|
|
100
|
+
* This Rule forces buyer to lock the item in the kiosk, preserving strong royalties.
|
|
101
|
+
*/
|
|
102
|
+
addLockRule(): this;
|
|
103
|
+
/**
|
|
104
|
+
* Attaches the Personal Kiosk Rule, making a purchase valid only for `SoulBound` kiosks.
|
|
105
|
+
*/
|
|
106
|
+
addPersonalKioskRule(): this;
|
|
107
|
+
/**
|
|
108
|
+
* A function to add the floor price rule to a transfer policy.
|
|
109
|
+
* @param minPrice The minimum price in MIST.
|
|
110
|
+
*/
|
|
111
|
+
addFloorPriceRule(minPrice: string | bigint): this;
|
|
112
|
+
/**
|
|
113
|
+
* Generic helper to remove a rule, not from the SDK's base ruleset.
|
|
114
|
+
* @param ruleType The Rule Type
|
|
115
|
+
* @param configType The Config Type
|
|
116
|
+
*/
|
|
117
|
+
removeRule({
|
|
118
|
+
ruleType,
|
|
119
|
+
configType
|
|
120
|
+
}: {
|
|
121
|
+
ruleType: string;
|
|
122
|
+
configType: string;
|
|
123
|
+
}): void;
|
|
124
|
+
/**
|
|
125
|
+
* Removes the lock rule.
|
|
126
|
+
*/
|
|
127
|
+
removeLockRule(): this;
|
|
128
|
+
/**
|
|
129
|
+
* Removes the Royalty rule
|
|
130
|
+
*/
|
|
131
|
+
removeRoyaltyRule(): this;
|
|
132
|
+
removePersonalKioskRule(): this;
|
|
133
|
+
removeFloorPriceRule(): this;
|
|
134
|
+
getPolicy(): ObjectArgument;
|
|
135
|
+
getPolicyCap(): ObjectArgument;
|
|
136
|
+
}
|
|
137
|
+
//#endregion
|
|
138
|
+
export { TransferPolicyBaseParams, TransferPolicyTransaction, TransferPolicyTransactionParams };
|
|
139
|
+
//# sourceMappingURL=tp-transaction.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tp-transaction.d.mts","names":[],"sources":["../../src/client/tp-transaction.ts"],"sourcesContent":[],"mappings":";;;;;;KAcY,wBAAA;;aAEA;EAFA,SAAA,CAAA,EAAA,OAAA;AAMZ,CAAA;AACc,KADF,+BAAA,GACE;EACA,WAAA,EADA,WACA;EACP,WAAA,EADO,WACP;EAAiB,GAAA,CAAA,EAAjB,iBAAiB;AAGxB,CAAA;AACc,cADD,yBAAA,CACC;EACA,CAAA,OAAA;EACJ,WAAA,EAFI,WAEJ;EACG,WAAA,EAFC,WAED;EAGE,MAAA,CAAA,EAJL,cAIK;EAAa,SAAA,CAAA,EAHf,cAGe;EAAa,IAAA,CAAA,EAAA,MAAA;EAAO,WAAA,CAAA;IAAA,WAAA;IAAA,WAAA;IAAA;EAAA,CAAA,EAAA,+BAAA;EAmB9C;;;;;;;;;;;;EA6EQ,cAAA,CAAA;IAAA,IAAA;IAAA,SAAA;IAAA,OAAA;IAAA;EAAuB,CAAvB,EAzEN,wBAyEM,GAAA;IAAU,OAAA,EAAA,MAAA;EAAa,CAAA,CAAA,EAvE/B,OAuE+B,CAAA,IAAA,CAAA;EAAQ;;;;;;;;;;;;KAlDrC,2BAA2B,QAAQ;;;;;;;;;;;;;;;;;KAkDE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eA0P/B;kBAKG"}
|