@iota/kiosk 0.0.0-dev-20251015065834
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 +198 -0
- package/LICENSE +201 -0
- package/README.md +39 -0
- package/dist/cjs/bcs.d.ts +38 -0
- package/dist/cjs/bcs.js +49 -0
- package/dist/cjs/bcs.js.map +7 -0
- package/dist/cjs/client/kiosk-client.d.ts +76 -0
- package/dist/cjs/client/kiosk-client.js +126 -0
- package/dist/cjs/client/kiosk-client.js.map +7 -0
- package/dist/cjs/client/kiosk-transaction.d.ts +185 -0
- package/dist/cjs/client/kiosk-transaction.js +473 -0
- package/dist/cjs/client/kiosk-transaction.js.map +7 -0
- package/dist/cjs/client/tp-transaction.d.ts +114 -0
- package/dist/cjs/client/tp-transaction.js +312 -0
- package/dist/cjs/client/tp-transaction.js.map +7 -0
- package/dist/cjs/constants.d.ts +24 -0
- package/dist/cjs/constants.js +66 -0
- package/dist/cjs/constants.js.map +7 -0
- package/dist/cjs/index.d.ts +6 -0
- package/dist/cjs/index.js +24 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/package.json +5 -0
- package/dist/cjs/query/kiosk.d.ts +14 -0
- package/dist/cjs/query/kiosk.js +129 -0
- package/dist/cjs/query/kiosk.js.map +7 -0
- package/dist/cjs/query/transfer-policy.d.ts +29 -0
- package/dist/cjs/query/transfer-policy.js +94 -0
- package/dist/cjs/query/transfer-policy.js.map +7 -0
- package/dist/cjs/tx/kiosk.d.ts +71 -0
- package/dist/cjs/tx/kiosk.js +130 -0
- package/dist/cjs/tx/kiosk.js.map +7 -0
- package/dist/cjs/tx/personal-kiosk.d.ts +7 -0
- package/dist/cjs/tx/personal-kiosk.js +38 -0
- package/dist/cjs/tx/personal-kiosk.js.map +7 -0
- package/dist/cjs/tx/rules/attach.d.ts +7 -0
- package/dist/cjs/tx/rules/attach.js +62 -0
- package/dist/cjs/tx/rules/attach.js.map +7 -0
- package/dist/cjs/tx/rules/resolve.d.ts +15 -0
- package/dist/cjs/tx/rules/resolve.js +79 -0
- package/dist/cjs/tx/rules/resolve.js.map +7 -0
- package/dist/cjs/tx/transfer-policy.d.ts +29 -0
- package/dist/cjs/tx/transfer-policy.js +78 -0
- package/dist/cjs/tx/transfer-policy.js.map +7 -0
- package/dist/cjs/types/index.d.ts +17 -0
- package/dist/cjs/types/index.js +20 -0
- package/dist/cjs/types/index.js.map +7 -0
- package/dist/cjs/types/kiosk.d.ts +159 -0
- package/dist/cjs/types/kiosk.js +37 -0
- package/dist/cjs/types/kiosk.js.map +7 -0
- package/dist/cjs/types/transfer-policy.d.ts +51 -0
- package/dist/cjs/types/transfer-policy.js +35 -0
- package/dist/cjs/types/transfer-policy.js.map +7 -0
- package/dist/cjs/utils.d.ts +51 -0
- package/dist/cjs/utils.js +201 -0
- package/dist/cjs/utils.js.map +7 -0
- package/dist/esm/bcs.d.ts +38 -0
- package/dist/esm/bcs.js +34 -0
- package/dist/esm/bcs.js.map +7 -0
- package/dist/esm/client/kiosk-client.d.ts +76 -0
- package/dist/esm/client/kiosk-client.js +110 -0
- package/dist/esm/client/kiosk-client.js.map +7 -0
- package/dist/esm/client/kiosk-transaction.d.ts +185 -0
- package/dist/esm/client/kiosk-transaction.js +443 -0
- package/dist/esm/client/kiosk-transaction.js.map +7 -0
- package/dist/esm/client/tp-transaction.d.ts +114 -0
- package/dist/esm/client/tp-transaction.js +303 -0
- package/dist/esm/client/tp-transaction.js.map +7 -0
- package/dist/esm/constants.d.ts +24 -0
- package/dist/esm/constants.js +51 -0
- package/dist/esm/constants.js.map +7 -0
- package/dist/esm/index.d.ts +6 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/package.json +5 -0
- package/dist/esm/query/kiosk.d.ts +14 -0
- package/dist/esm/query/kiosk.js +117 -0
- package/dist/esm/query/kiosk.js.map +7 -0
- package/dist/esm/query/transfer-policy.d.ts +29 -0
- package/dist/esm/query/transfer-policy.js +78 -0
- package/dist/esm/query/transfer-policy.js.map +7 -0
- package/dist/esm/tx/kiosk.d.ts +71 -0
- package/dist/esm/tx/kiosk.js +110 -0
- package/dist/esm/tx/kiosk.js.map +7 -0
- package/dist/esm/tx/personal-kiosk.d.ts +7 -0
- package/dist/esm/tx/personal-kiosk.js +18 -0
- package/dist/esm/tx/personal-kiosk.js.map +7 -0
- package/dist/esm/tx/rules/attach.d.ts +7 -0
- package/dist/esm/tx/rules/attach.js +42 -0
- package/dist/esm/tx/rules/attach.js.map +7 -0
- package/dist/esm/tx/rules/resolve.d.ts +15 -0
- package/dist/esm/tx/rules/resolve.js +59 -0
- package/dist/esm/tx/rules/resolve.js.map +7 -0
- package/dist/esm/tx/transfer-policy.d.ts +29 -0
- package/dist/esm/tx/transfer-policy.js +58 -0
- package/dist/esm/tx/transfer-policy.js.map +7 -0
- package/dist/esm/types/index.d.ts +17 -0
- package/dist/esm/types/index.js +3 -0
- package/dist/esm/types/index.js.map +7 -0
- package/dist/esm/types/kiosk.d.ts +159 -0
- package/dist/esm/types/kiosk.js +17 -0
- package/dist/esm/types/kiosk.js.map +7 -0
- package/dist/esm/types/transfer-policy.d.ts +51 -0
- package/dist/esm/types/transfer-policy.js +15 -0
- package/dist/esm/types/transfer-policy.js.map +7 -0
- package/dist/esm/utils.d.ts +51 -0
- package/dist/esm/utils.js +186 -0
- package/dist/esm/utils.js.map +7 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +53 -0
- package/src/bcs.ts +39 -0
- package/src/client/kiosk-client.ts +169 -0
- package/src/client/kiosk-transaction.ts +538 -0
- package/src/client/tp-transaction.ts +363 -0
- package/src/constants.ts +85 -0
- package/src/index.ts +10 -0
- package/src/query/kiosk.ts +193 -0
- package/src/query/transfer-policy.ts +137 -0
- package/src/tx/kiosk.ts +244 -0
- package/src/tx/personal-kiosk.ts +35 -0
- package/src/tx/rules/attach.ts +74 -0
- package/src/tx/rules/resolve.ts +87 -0
- package/src/tx/transfer-policy.ts +121 -0
- package/src/types/index.ts +25 -0
- package/src/types/kiosk.ts +178 -0
- package/src/types/transfer-policy.ts +70 -0
- package/src/utils.ts +289 -0
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __typeError = (msg) => {
|
|
7
|
+
throw TypeError(msg);
|
|
8
|
+
};
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
23
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
24
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
25
|
+
var tp_transaction_exports = {};
|
|
26
|
+
__export(tp_transaction_exports, {
|
|
27
|
+
TransferPolicyTransaction: () => TransferPolicyTransaction
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(tp_transaction_exports);
|
|
30
|
+
var import_attach = require("../tx/rules/attach.js");
|
|
31
|
+
var import_transfer_policy = require("../tx/transfer-policy.js");
|
|
32
|
+
var _TransferPolicyTransaction_instances, validateInputs_fn, setup_fn;
|
|
33
|
+
class TransferPolicyTransaction {
|
|
34
|
+
constructor({
|
|
35
|
+
kioskClient,
|
|
36
|
+
transactionBlock,
|
|
37
|
+
transaction = transactionBlock,
|
|
38
|
+
cap
|
|
39
|
+
}) {
|
|
40
|
+
__privateAdd(this, _TransferPolicyTransaction_instances);
|
|
41
|
+
this.kioskClient = kioskClient;
|
|
42
|
+
this.transaction = transaction;
|
|
43
|
+
if (cap) this.setCap(cap);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A function to create a new transfer policy.
|
|
47
|
+
* Checks if there's already an existing transfer policy to prevent
|
|
48
|
+
* double transfer policy mistakes.
|
|
49
|
+
* There's an optional `skipCheck` flag that will just create the policy
|
|
50
|
+
* without checking
|
|
51
|
+
*
|
|
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
|
+
async createAndShare({
|
|
58
|
+
type,
|
|
59
|
+
publisher,
|
|
60
|
+
address,
|
|
61
|
+
skipCheck
|
|
62
|
+
}) {
|
|
63
|
+
if (!skipCheck) {
|
|
64
|
+
const policies = await this.kioskClient.getTransferPolicies({ type });
|
|
65
|
+
if (policies.length > 0)
|
|
66
|
+
throw new Error("There's already transfer policy for this Type.");
|
|
67
|
+
}
|
|
68
|
+
const cap = (0, import_transfer_policy.createTransferPolicy)(this.transaction, type, publisher);
|
|
69
|
+
this.transaction.transferObjects([cap], this.transaction.pure.address(address));
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* A convenient function to create a Transfer Policy and attach some rules
|
|
73
|
+
* before sharing it (so you can prepare it in a single PTB)
|
|
74
|
+
* @param type The Type (`T`) for which we're creating the transfer policy.
|
|
75
|
+
* @param publisher The Publisher Object Id.
|
|
76
|
+
* @param address Address to save the `TransferPolicyCap` object to.
|
|
77
|
+
* @param skipCheck (Optional) skip checking if a transfer policy already exists
|
|
78
|
+
*/
|
|
79
|
+
async create({
|
|
80
|
+
type,
|
|
81
|
+
publisher,
|
|
82
|
+
skipCheck
|
|
83
|
+
}) {
|
|
84
|
+
if (!skipCheck) {
|
|
85
|
+
const policies = await this.kioskClient.getTransferPolicies({ type });
|
|
86
|
+
if (policies.length > 0)
|
|
87
|
+
throw new Error("There's already transfer policy for this Type.");
|
|
88
|
+
}
|
|
89
|
+
const [policy, policyCap] = (0, import_transfer_policy.createTransferPolicyWithoutSharing)(
|
|
90
|
+
this.transaction,
|
|
91
|
+
type,
|
|
92
|
+
publisher
|
|
93
|
+
);
|
|
94
|
+
__privateMethod(this, _TransferPolicyTransaction_instances, setup_fn).call(this, policy, policyCap, type);
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* This can be called after calling the `create` function to share the `TransferPolicy`,
|
|
99
|
+
* and transfer the `TransferPolicyCap` to the specified address
|
|
100
|
+
*
|
|
101
|
+
* @param address The address to transfer the `TransferPolicyCap`
|
|
102
|
+
*/
|
|
103
|
+
shareAndTransferCap(address) {
|
|
104
|
+
if (!this.type || !this.policyCap || !this.policy)
|
|
105
|
+
throw new Error(
|
|
106
|
+
"This function can only be called after `transferPolicyManager.create`"
|
|
107
|
+
);
|
|
108
|
+
(0, import_transfer_policy.shareTransferPolicy)(this.transaction, this.type, this.policy);
|
|
109
|
+
this.transaction.transferObjects(
|
|
110
|
+
[this.policyCap],
|
|
111
|
+
this.transaction.pure.address(address)
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Setup the TransferPolicy by passing a `cap` returned from `kioskClient.getOwnedTransferPolicies` or
|
|
116
|
+
* `kioskClient.getOwnedTransferPoliciesByType`.
|
|
117
|
+
* @param policyCapId The `TransferPolicyCap`
|
|
118
|
+
*/
|
|
119
|
+
setCap({ policyId, policyCapId, type }) {
|
|
120
|
+
return __privateMethod(this, _TransferPolicyTransaction_instances, setup_fn).call(this, policyId, policyCapId, type);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Withdraw from the transfer policy's profits.
|
|
124
|
+
* @param address Address to transfer the profits to.
|
|
125
|
+
* @param amount (Optional) amount parameter. Will withdraw all profits if the amount is not specified.
|
|
126
|
+
*/
|
|
127
|
+
withdraw(address, amount) {
|
|
128
|
+
__privateMethod(this, _TransferPolicyTransaction_instances, validateInputs_fn).call(this);
|
|
129
|
+
const coin = (0, import_transfer_policy.withdrawFromPolicy)(
|
|
130
|
+
this.transaction,
|
|
131
|
+
this.type,
|
|
132
|
+
this.policy,
|
|
133
|
+
this.policyCap,
|
|
134
|
+
amount
|
|
135
|
+
);
|
|
136
|
+
this.transaction.transferObjects([coin], this.transaction.pure.address(address));
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Adds the Kiosk Royalty rule to the Transfer Policy.
|
|
141
|
+
* You can pass the percentage, as well as a minimum amount.
|
|
142
|
+
* The royalty that will be paid is the MAX(percentage, minAmount).
|
|
143
|
+
* You can pass 0 in either value if you want only percentage royalty, or a fixed amount fee.
|
|
144
|
+
* (but you should define at least one of them for the rule to make sense).
|
|
145
|
+
*
|
|
146
|
+
* @param percentageBps The royalty percentage in basis points. Use `percentageToBasisPoints` helper to convert from percentage [0,100].
|
|
147
|
+
* @param minAmount The minimum royalty amount per request in NANOS.
|
|
148
|
+
*/
|
|
149
|
+
addRoyaltyRule(percentageBps, minAmount) {
|
|
150
|
+
__privateMethod(this, _TransferPolicyTransaction_instances, validateInputs_fn).call(this);
|
|
151
|
+
(0, import_attach.attachRoyaltyRuleTx)(
|
|
152
|
+
this.transaction,
|
|
153
|
+
this.type,
|
|
154
|
+
this.policy,
|
|
155
|
+
this.policyCap,
|
|
156
|
+
percentageBps,
|
|
157
|
+
minAmount,
|
|
158
|
+
this.kioskClient.getRulePackageId("royaltyRulePackageId")
|
|
159
|
+
);
|
|
160
|
+
return this;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Adds the Kiosk Lock Rule to the Transfer Policy.
|
|
164
|
+
* This Rule forces buyer to lock the item in the kiosk, preserving strong royalties.
|
|
165
|
+
*/
|
|
166
|
+
addLockRule() {
|
|
167
|
+
__privateMethod(this, _TransferPolicyTransaction_instances, validateInputs_fn).call(this);
|
|
168
|
+
(0, import_attach.attachKioskLockRuleTx)(
|
|
169
|
+
this.transaction,
|
|
170
|
+
this.type,
|
|
171
|
+
this.policy,
|
|
172
|
+
this.policyCap,
|
|
173
|
+
this.kioskClient.getRulePackageId("kioskLockRulePackageId")
|
|
174
|
+
);
|
|
175
|
+
return this;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Attaches the Personal Kiosk Rule, making a purchase valid only for `SoulBound` kiosks.
|
|
179
|
+
*/
|
|
180
|
+
addPersonalKioskRule() {
|
|
181
|
+
__privateMethod(this, _TransferPolicyTransaction_instances, validateInputs_fn).call(this);
|
|
182
|
+
(0, import_attach.attachPersonalKioskRuleTx)(
|
|
183
|
+
this.transaction,
|
|
184
|
+
this.type,
|
|
185
|
+
this.policy,
|
|
186
|
+
this.policyCap,
|
|
187
|
+
this.kioskClient.getRulePackageId("personalKioskRulePackageId")
|
|
188
|
+
);
|
|
189
|
+
return this;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* A function to add the floor price rule to a transfer policy.
|
|
193
|
+
* @param minPrice The minimum price in NANOS.
|
|
194
|
+
*/
|
|
195
|
+
addFloorPriceRule(minPrice) {
|
|
196
|
+
__privateMethod(this, _TransferPolicyTransaction_instances, validateInputs_fn).call(this);
|
|
197
|
+
(0, import_attach.attachFloorPriceRuleTx)(
|
|
198
|
+
this.transaction,
|
|
199
|
+
this.type,
|
|
200
|
+
this.policy,
|
|
201
|
+
this.policyCap,
|
|
202
|
+
minPrice,
|
|
203
|
+
this.kioskClient.getRulePackageId("floorPriceRulePackageId")
|
|
204
|
+
);
|
|
205
|
+
return this;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Generic helper to remove a rule, not from the SDK's base ruleset.
|
|
209
|
+
* @param ruleType The Rule Type
|
|
210
|
+
* @param configType The Config Type
|
|
211
|
+
*/
|
|
212
|
+
removeRule({ ruleType, configType }) {
|
|
213
|
+
__privateMethod(this, _TransferPolicyTransaction_instances, validateInputs_fn).call(this);
|
|
214
|
+
(0, import_transfer_policy.removeTransferPolicyRule)(
|
|
215
|
+
this.transaction,
|
|
216
|
+
this.type,
|
|
217
|
+
ruleType,
|
|
218
|
+
configType,
|
|
219
|
+
this.policy,
|
|
220
|
+
this.policyCap
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Removes the lock rule.
|
|
225
|
+
*/
|
|
226
|
+
removeLockRule() {
|
|
227
|
+
__privateMethod(this, _TransferPolicyTransaction_instances, validateInputs_fn).call(this);
|
|
228
|
+
const packageId = this.kioskClient.getRulePackageId("kioskLockRulePackageId");
|
|
229
|
+
(0, import_transfer_policy.removeTransferPolicyRule)(
|
|
230
|
+
this.transaction,
|
|
231
|
+
this.type,
|
|
232
|
+
`${packageId}::kiosk_lock_rule::Rule`,
|
|
233
|
+
`${packageId}::kiosk_lock_rule::Config`,
|
|
234
|
+
this.policy,
|
|
235
|
+
this.policyCap
|
|
236
|
+
);
|
|
237
|
+
return this;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Removes the Royalty rule
|
|
241
|
+
*/
|
|
242
|
+
removeRoyaltyRule() {
|
|
243
|
+
__privateMethod(this, _TransferPolicyTransaction_instances, validateInputs_fn).call(this);
|
|
244
|
+
const packageId = this.kioskClient.getRulePackageId("royaltyRulePackageId");
|
|
245
|
+
(0, import_transfer_policy.removeTransferPolicyRule)(
|
|
246
|
+
this.transaction,
|
|
247
|
+
this.type,
|
|
248
|
+
`${packageId}::royalty_rule::Rule`,
|
|
249
|
+
`${packageId}::royalty_rule::Config`,
|
|
250
|
+
this.policy,
|
|
251
|
+
this.policyCap
|
|
252
|
+
);
|
|
253
|
+
return this;
|
|
254
|
+
}
|
|
255
|
+
removePersonalKioskRule() {
|
|
256
|
+
__privateMethod(this, _TransferPolicyTransaction_instances, validateInputs_fn).call(this);
|
|
257
|
+
const packageId = this.kioskClient.getRulePackageId("personalKioskRulePackageId");
|
|
258
|
+
(0, import_transfer_policy.removeTransferPolicyRule)(
|
|
259
|
+
this.transaction,
|
|
260
|
+
this.type,
|
|
261
|
+
`${packageId}::personal_kiosk_rule::Rule`,
|
|
262
|
+
`bool`,
|
|
263
|
+
this.policy,
|
|
264
|
+
this.policyCap
|
|
265
|
+
);
|
|
266
|
+
return this;
|
|
267
|
+
}
|
|
268
|
+
removeFloorPriceRule() {
|
|
269
|
+
__privateMethod(this, _TransferPolicyTransaction_instances, validateInputs_fn).call(this);
|
|
270
|
+
const packageId = this.kioskClient.getRulePackageId("floorPriceRulePackageId");
|
|
271
|
+
(0, import_transfer_policy.removeTransferPolicyRule)(
|
|
272
|
+
this.transaction,
|
|
273
|
+
this.type,
|
|
274
|
+
`${packageId}::floor_price_rule::Rule`,
|
|
275
|
+
`${packageId}::floor_price_rule::Config`,
|
|
276
|
+
this.policy,
|
|
277
|
+
this.policyCap
|
|
278
|
+
);
|
|
279
|
+
return this;
|
|
280
|
+
}
|
|
281
|
+
getPolicy() {
|
|
282
|
+
if (!this.policy) throw new Error("Policy not set.");
|
|
283
|
+
return this.policy;
|
|
284
|
+
}
|
|
285
|
+
getPolicyCap() {
|
|
286
|
+
if (!this.policyCap) throw new Error("Transfer Policy Cap not set.");
|
|
287
|
+
return this.policyCap;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
_TransferPolicyTransaction_instances = new WeakSet();
|
|
291
|
+
// Internal function that that the policy's Id + Cap + type have been set.
|
|
292
|
+
validateInputs_fn = function() {
|
|
293
|
+
const genericErrorMessage = `Please use 'setCap()' to setup the TransferPolicy.`;
|
|
294
|
+
if (!this.policy)
|
|
295
|
+
throw new Error(`${genericErrorMessage} Missing: Transfer Policy Object.`);
|
|
296
|
+
if (!this.policyCap)
|
|
297
|
+
throw new Error(`${genericErrorMessage} Missing: TransferPolicyCap Object ID`);
|
|
298
|
+
if (!this.type)
|
|
299
|
+
throw new Error(
|
|
300
|
+
`${genericErrorMessage} Missing: Transfer Policy object type (e.g. {packageId}::item::Item)`
|
|
301
|
+
);
|
|
302
|
+
};
|
|
303
|
+
/**
|
|
304
|
+
* Setup the state of the TransferPolicyTransaction.
|
|
305
|
+
*/
|
|
306
|
+
setup_fn = function(policyId, policyCap, type) {
|
|
307
|
+
this.policy = policyId;
|
|
308
|
+
this.policyCap = policyCap;
|
|
309
|
+
this.type = type;
|
|
310
|
+
return this;
|
|
311
|
+
};
|
|
312
|
+
//# sourceMappingURL=tp-transaction.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/client/tp-transaction.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Transaction, TransactionObjectArgument } from '@iota/iota-sdk/transactions';\n\nimport {\n attachFloorPriceRuleTx,\n attachKioskLockRuleTx,\n attachPersonalKioskRuleTx,\n attachRoyaltyRuleTx,\n} from '../tx/rules/attach.js';\nimport {\n createTransferPolicy,\n createTransferPolicyWithoutSharing,\n removeTransferPolicyRule,\n shareTransferPolicy,\n withdrawFromPolicy,\n} from '../tx/transfer-policy.js';\nimport type { ObjectArgument, TransferPolicyCap } from '../types/index.js';\nimport type { KioskClient } from './kiosk-client.js';\n\nexport type TransferPolicyBaseParams = {\n type: string;\n publisher: ObjectArgument;\n skipCheck?: boolean;\n};\n\nexport type TransferPolicyTransactionParams = {\n kioskClient: KioskClient;\n transaction: Transaction;\n /** @deprecated use transaction instead */\n transactionBlock?: Transaction;\n cap?: TransferPolicyCap;\n};\n\nexport class TransferPolicyTransaction {\n transaction: Transaction;\n kioskClient: KioskClient;\n policy?: ObjectArgument;\n policyCap?: ObjectArgument;\n type?: string;\n\n constructor({\n kioskClient,\n transactionBlock,\n transaction = transactionBlock!,\n cap,\n }: TransferPolicyTransactionParams) {\n this.kioskClient = kioskClient;\n this.transaction = transaction;\n if (cap) this.setCap(cap);\n }\n\n /**\n * A function to create a new transfer policy.\n * Checks if there's already an existing transfer policy to prevent\n * double transfer policy mistakes.\n * There's an optional `skipCheck` flag that will just create the policy\n * without checking\n *\n * @param type The Type (`T`) for which we're creating the transfer policy.\n * @param publisher The Publisher Object Id.\n * @param address Address to save the `TransferPolicyCap` object to.\n * @param skipCheck (Optional) skip checking if a transfer policy already exists\n */\n async createAndShare({\n type,\n publisher,\n address,\n skipCheck,\n }: TransferPolicyBaseParams & {\n address: string;\n }) {\n if (!skipCheck) {\n const policies = await this.kioskClient.getTransferPolicies({ type });\n if (policies.length > 0)\n throw new Error(\"There's already transfer policy for this Type.\");\n }\n const cap = createTransferPolicy(this.transaction, type, publisher);\n this.transaction.transferObjects([cap], this.transaction.pure.address(address));\n }\n\n /**\n * A convenient function to create a Transfer Policy and attach some rules\n * before sharing it (so you can prepare it in a single PTB)\n * @param type The Type (`T`) for which we're creating the transfer policy.\n * @param publisher The Publisher Object Id.\n * @param address Address to save the `TransferPolicyCap` object to.\n * @param skipCheck (Optional) skip checking if a transfer policy already exists\n */\n async create({\n type,\n publisher,\n skipCheck,\n }: TransferPolicyBaseParams): Promise<TransferPolicyTransaction> {\n if (!skipCheck) {\n const policies = await this.kioskClient.getTransferPolicies({ type });\n if (policies.length > 0)\n throw new Error(\"There's already transfer policy for this Type.\");\n }\n const [policy, policyCap] = createTransferPolicyWithoutSharing(\n this.transaction,\n type,\n publisher,\n );\n\n this.#setup(policy, policyCap, type); // sets the client's TP to the newly created one.\n return this;\n }\n\n /**\n * This can be called after calling the `create` function to share the `TransferPolicy`,\n * and transfer the `TransferPolicyCap` to the specified address\n *\n * @param address The address to transfer the `TransferPolicyCap`\n */\n shareAndTransferCap(address: string) {\n if (!this.type || !this.policyCap || !this.policy)\n throw new Error(\n 'This function can only be called after `transferPolicyManager.create`',\n );\n\n shareTransferPolicy(this.transaction, this.type, this.policy as TransactionObjectArgument);\n this.transaction.transferObjects(\n [this.policyCap as TransactionObjectArgument],\n this.transaction.pure.address(address),\n );\n }\n\n /**\n * Setup the TransferPolicy by passing a `cap` returned from `kioskClient.getOwnedTransferPolicies` or\n * `kioskClient.getOwnedTransferPoliciesByType`.\n * @param policyCapId The `TransferPolicyCap`\n */\n setCap({ policyId, policyCapId, type }: TransferPolicyCap) {\n return this.#setup(policyId, policyCapId, type);\n }\n\n /**\n * Withdraw from the transfer policy's profits.\n * @param address Address to transfer the profits to.\n * @param amount (Optional) amount parameter. Will withdraw all profits if the amount is not specified.\n */\n withdraw(address: string, amount?: string | bigint) {\n this.#validateInputs();\n // Withdraw coin for specified amount (or none)\n const coin = withdrawFromPolicy(\n this.transaction,\n this.type!,\n this.policy!,\n this.policyCap!,\n amount,\n );\n\n this.transaction.transferObjects([coin], this.transaction.pure.address(address));\n\n return this;\n }\n\n /**\n * Adds the Kiosk Royalty rule to the Transfer Policy.\n * You can pass the percentage, as well as a minimum amount.\n * The royalty that will be paid is the MAX(percentage, minAmount).\n * \tYou can pass 0 in either value if you want only percentage royalty, or a fixed amount fee.\n * \t(but you should define at least one of them for the rule to make sense).\n *\n * \t@param percentageBps The royalty percentage in basis points. Use `percentageToBasisPoints` helper to convert from percentage [0,100].\n * \t@param minAmount The minimum royalty amount per request in NANOS.\n */\n addRoyaltyRule(\n percentageBps: number | string, // this is in basis points.\n minAmount: number | string,\n ) {\n this.#validateInputs();\n\n // Hard-coding package Ids as these don't change.\n // Also, it's hard to keep versioning as with network wipes, mainnet\n // and testnet will conflict.\n attachRoyaltyRuleTx(\n this.transaction,\n this.type!,\n this.policy!,\n this.policyCap!,\n percentageBps,\n minAmount,\n this.kioskClient.getRulePackageId('royaltyRulePackageId'),\n );\n return this;\n }\n\n /**\n * Adds the Kiosk Lock Rule to the Transfer Policy.\n * This Rule forces buyer to lock the item in the kiosk, preserving strong royalties.\n */\n addLockRule() {\n this.#validateInputs();\n\n attachKioskLockRuleTx(\n this.transaction,\n this.type!,\n this.policy!,\n this.policyCap!,\n this.kioskClient.getRulePackageId('kioskLockRulePackageId'),\n );\n return this;\n }\n\n /**\n * Attaches the Personal Kiosk Rule, making a purchase valid only for `SoulBound` kiosks.\n */\n addPersonalKioskRule() {\n this.#validateInputs();\n\n attachPersonalKioskRuleTx(\n this.transaction,\n this.type!,\n this.policy!,\n this.policyCap!,\n this.kioskClient.getRulePackageId('personalKioskRulePackageId'),\n );\n return this;\n }\n\n /**\n * A function to add the floor price rule to a transfer policy.\n * @param minPrice The minimum price in NANOS.\n */\n addFloorPriceRule(minPrice: string | bigint) {\n this.#validateInputs();\n\n attachFloorPriceRuleTx(\n this.transaction,\n this.type!,\n this.policy!,\n this.policyCap!,\n minPrice,\n this.kioskClient.getRulePackageId('floorPriceRulePackageId'),\n );\n return this;\n }\n\n /**\n * Generic helper to remove a rule, not from the SDK's base ruleset.\n * @param ruleType The Rule Type\n * @param configType The Config Type\n */\n removeRule({ ruleType, configType }: { ruleType: string; configType: string }) {\n this.#validateInputs();\n\n removeTransferPolicyRule(\n this.transaction,\n this.type!,\n ruleType,\n configType,\n this.policy!,\n this.policyCap!,\n );\n }\n\n /**\n * Removes the lock rule.\n */\n removeLockRule() {\n this.#validateInputs();\n\n const packageId = this.kioskClient.getRulePackageId('kioskLockRulePackageId');\n\n removeTransferPolicyRule(\n this.transaction,\n this.type!,\n `${packageId}::kiosk_lock_rule::Rule`,\n `${packageId}::kiosk_lock_rule::Config`,\n this.policy!,\n this.policyCap!,\n );\n return this;\n }\n\n /**\n * Removes the Royalty rule\n */\n removeRoyaltyRule() {\n this.#validateInputs();\n\n const packageId = this.kioskClient.getRulePackageId('royaltyRulePackageId');\n\n removeTransferPolicyRule(\n this.transaction,\n this.type!,\n `${packageId}::royalty_rule::Rule`,\n `${packageId}::royalty_rule::Config`,\n this.policy!,\n this.policyCap!,\n );\n return this;\n }\n\n removePersonalKioskRule() {\n this.#validateInputs();\n\n const packageId = this.kioskClient.getRulePackageId('personalKioskRulePackageId');\n\n removeTransferPolicyRule(\n this.transaction,\n this.type!,\n `${packageId}::personal_kiosk_rule::Rule`,\n `bool`,\n this.policy!,\n this.policyCap!,\n );\n return this;\n }\n\n removeFloorPriceRule() {\n this.#validateInputs();\n\n const packageId = this.kioskClient.getRulePackageId('floorPriceRulePackageId');\n\n removeTransferPolicyRule(\n this.transaction,\n this.type!,\n `${packageId}::floor_price_rule::Rule`,\n `${packageId}::floor_price_rule::Config`,\n this.policy!,\n this.policyCap!,\n );\n return this;\n }\n\n getPolicy() {\n if (!this.policy) throw new Error('Policy not set.');\n return this.policy;\n }\n\n getPolicyCap() {\n if (!this.policyCap) throw new Error('Transfer Policy Cap not set.');\n return this.policyCap;\n }\n\n // Internal function that that the policy's Id + Cap + type have been set.\n #validateInputs() {\n const genericErrorMessage = `Please use 'setCap()' to setup the TransferPolicy.`;\n if (!this.policy)\n throw new Error(`${genericErrorMessage} Missing: Transfer Policy Object.`);\n if (!this.policyCap)\n throw new Error(`${genericErrorMessage} Missing: TransferPolicyCap Object ID`);\n if (!this.type)\n throw new Error(\n `${genericErrorMessage} Missing: Transfer Policy object type (e.g. {packageId}::item::Item)`,\n );\n }\n\n /**\n * Setup the state of the TransferPolicyTransaction.\n */\n #setup(policyId: ObjectArgument, policyCap: ObjectArgument, type: string) {\n this.policy = policyId;\n this.policyCap = policyCap;\n this.type = type;\n return this;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;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AAK;AAAA,MACL,KAAK;AAAA,MACL,GAAG,SAAS;AAAA,MACZ;AAAA,MACA,KAAK;AAAA,MACL,KAAK;AAAA,IACT;AACA,WAAO;AAAA,EACX;AAAA,EAEA,uBAAuB;AACnB,0BAAK,yDAAL;AAEA,UAAM,YAAY,KAAK,YAAY,iBAAiB,yBAAyB;AAE7E;AAAA,MACI,KAAK;AAAA,MACL,KAAK;AAAA,MACL,GAAG,SAAS;AAAA,MACZ,GAAG,SAAS;AAAA,MACZ,KAAK;AAAA,MACL,KAAK;AAAA,IACT;AACA,WAAO;AAAA,EACX;AAAA,EAEA,YAAY;AACR,QAAI,CAAC,KAAK,OAAQ,OAAM,IAAI,MAAM,iBAAiB;AACnD,WAAO,KAAK;AAAA,EAChB;AAAA,EAEA,eAAe;AACX,QAAI,CAAC,KAAK,UAAW,OAAM,IAAI,MAAM,8BAA8B;AACnE,WAAO,KAAK;AAAA,EAChB;AAwBJ;AAtUO;AAAA;AAiTH,oBAAe,WAAG;AACd,QAAM,sBAAsB;AAC5B,MAAI,CAAC,KAAK;AACN,UAAM,IAAI,MAAM,GAAG,mBAAmB,mCAAmC;AAC7E,MAAI,CAAC,KAAK;AACN,UAAM,IAAI,MAAM,GAAG,mBAAmB,uCAAuC;AACjF,MAAI,CAAC,KAAK;AACN,UAAM,IAAI;AAAA,MACN,GAAG,mBAAmB;AAAA,IAC1B;AACR;AAAA;AAAA;AAAA;AAKA,WAAM,SAAC,UAA0B,WAA2B,MAAc;AACtE,OAAK,SAAS;AACd,OAAK,YAAY;AACjB,OAAK,OAAO;AACZ,SAAO;AACX;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ObjectArgument, RuleResolvingParams } from './types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* The base rule package ids that can be extended
|
|
4
|
+
*/
|
|
5
|
+
export type BaseRulePackageIds = {
|
|
6
|
+
royaltyRulePackageId?: string;
|
|
7
|
+
kioskLockRulePackageId?: string;
|
|
8
|
+
personalKioskRulePackageId?: string;
|
|
9
|
+
floorPriceRulePackageId?: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* The Transfer Policy rule.
|
|
13
|
+
*/
|
|
14
|
+
export type TransferPolicyRule = {
|
|
15
|
+
rule: string;
|
|
16
|
+
packageId: string;
|
|
17
|
+
resolveRuleFunction: (rule: RuleResolvingParams) => ObjectArgument | void;
|
|
18
|
+
hasLockingRule?: boolean;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Constructs a list of rule resolvers based on the params.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getBaseRules({ royaltyRulePackageId, kioskLockRulePackageId, personalKioskRulePackageId, floorPriceRulePackageId, }: BaseRulePackageIds): TransferPolicyRule[];
|
|
24
|
+
export declare const rules: TransferPolicyRule[];
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var constants_exports = {};
|
|
20
|
+
__export(constants_exports, {
|
|
21
|
+
getBaseRules: () => getBaseRules,
|
|
22
|
+
rules: () => rules
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(constants_exports);
|
|
25
|
+
var import_client = require("@iota/iota-sdk/client");
|
|
26
|
+
var import_resolve = require("./tx/rules//resolve.js");
|
|
27
|
+
function getBaseRules({
|
|
28
|
+
royaltyRulePackageId,
|
|
29
|
+
kioskLockRulePackageId,
|
|
30
|
+
personalKioskRulePackageId,
|
|
31
|
+
floorPriceRulePackageId
|
|
32
|
+
}) {
|
|
33
|
+
const rules2 = [];
|
|
34
|
+
if (royaltyRulePackageId) {
|
|
35
|
+
rules2.push({
|
|
36
|
+
rule: `${royaltyRulePackageId}::royalty_rule::Rule`,
|
|
37
|
+
packageId: royaltyRulePackageId,
|
|
38
|
+
resolveRuleFunction: import_resolve.resolveRoyaltyRule
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if (kioskLockRulePackageId) {
|
|
42
|
+
rules2.push({
|
|
43
|
+
rule: `${kioskLockRulePackageId}::kiosk_lock_rule::Rule`,
|
|
44
|
+
packageId: kioskLockRulePackageId,
|
|
45
|
+
resolveRuleFunction: import_resolve.resolveKioskLockRule,
|
|
46
|
+
hasLockingRule: true
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
if (personalKioskRulePackageId) {
|
|
50
|
+
rules2.push({
|
|
51
|
+
rule: `${personalKioskRulePackageId}::personal_kiosk_rule::Rule`,
|
|
52
|
+
packageId: personalKioskRulePackageId,
|
|
53
|
+
resolveRuleFunction: import_resolve.resolvePersonalKioskRule
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
if (floorPriceRulePackageId) {
|
|
57
|
+
rules2.push({
|
|
58
|
+
rule: `${floorPriceRulePackageId}::floor_price_rule::Rule`,
|
|
59
|
+
packageId: floorPriceRulePackageId,
|
|
60
|
+
resolveRuleFunction: import_resolve.resolveFloorPriceRule
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return rules2;
|
|
64
|
+
}
|
|
65
|
+
const rules = Object.values((0, import_client.getAllNetworks)()).filter((network) => network.kiosk).flatMap((network) => getBaseRules(network.kiosk));
|
|
66
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/constants.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\n// eslint-disable-next-line import/no-cycle\nimport type { KioskConfiguration } from '@iota/iota-sdk/client';\nimport { getAllNetworks } from '@iota/iota-sdk/client';\nimport {\n resolveFloorPriceRule,\n resolveKioskLockRule,\n resolvePersonalKioskRule,\n resolveRoyaltyRule,\n} from './tx/rules//resolve.js';\nimport type { ObjectArgument, RuleResolvingParams } from './types/index.js';\n\n/**\n * The base rule package ids that can be extended\n */\nexport type BaseRulePackageIds = {\n royaltyRulePackageId?: string;\n kioskLockRulePackageId?: string;\n personalKioskRulePackageId?: string;\n floorPriceRulePackageId?: string;\n};\n\n/**\n * The Transfer Policy rule.\n */\nexport type TransferPolicyRule = {\n rule: string;\n packageId: string;\n resolveRuleFunction: (rule: RuleResolvingParams) => ObjectArgument | void;\n hasLockingRule?: boolean;\n};\n\n/**\n * Constructs a list of rule resolvers based on the params.\n */\nexport function getBaseRules({\n royaltyRulePackageId,\n kioskLockRulePackageId,\n personalKioskRulePackageId,\n floorPriceRulePackageId,\n}: BaseRulePackageIds): TransferPolicyRule[] {\n const rules = [];\n\n if (royaltyRulePackageId) {\n rules.push({\n rule: `${royaltyRulePackageId}::royalty_rule::Rule`,\n packageId: royaltyRulePackageId,\n resolveRuleFunction: resolveRoyaltyRule,\n });\n }\n\n if (kioskLockRulePackageId) {\n rules.push({\n rule: `${kioskLockRulePackageId}::kiosk_lock_rule::Rule`,\n packageId: kioskLockRulePackageId,\n resolveRuleFunction: resolveKioskLockRule,\n hasLockingRule: true,\n });\n }\n\n if (personalKioskRulePackageId) {\n rules.push({\n rule: `${personalKioskRulePackageId}::personal_kiosk_rule::Rule`,\n packageId: personalKioskRulePackageId,\n resolveRuleFunction: resolvePersonalKioskRule,\n });\n }\n\n if (floorPriceRulePackageId) {\n rules.push({\n rule: `${floorPriceRulePackageId}::floor_price_rule::Rule`,\n packageId: floorPriceRulePackageId,\n resolveRuleFunction: resolveFloorPriceRule,\n });\n }\n\n return rules;\n}\n\nexport const rules: TransferPolicyRule[] = Object.values(getAllNetworks())\n .filter((network) => network.kiosk)\n .flatMap((network) => getBaseRules(network.kiosk as KioskConfiguration));\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,oBAA+B;AAC/B,qBAKO;AA0BA,SAAS,aAAa;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ,GAA6C;AACzC,QAAMA,SAAQ,CAAC;AAEf,MAAI,sBAAsB;AACtB,IAAAA,OAAM,KAAK;AAAA,MACP,MAAM,GAAG,oBAAoB;AAAA,MAC7B,WAAW;AAAA,MACX,qBAAqB;AAAA,IACzB,CAAC;AAAA,EACL;AAEA,MAAI,wBAAwB;AACxB,IAAAA,OAAM,KAAK;AAAA,MACP,MAAM,GAAG,sBAAsB;AAAA,MAC/B,WAAW;AAAA,MACX,qBAAqB;AAAA,MACrB,gBAAgB;AAAA,IACpB,CAAC;AAAA,EACL;AAEA,MAAI,4BAA4B;AAC5B,IAAAA,OAAM,KAAK;AAAA,MACP,MAAM,GAAG,0BAA0B;AAAA,MACnC,WAAW;AAAA,MACX,qBAAqB;AAAA,IACzB,CAAC;AAAA,EACL;AAEA,MAAI,yBAAyB;AACzB,IAAAA,OAAM,KAAK;AAAA,MACP,MAAM,GAAG,uBAAuB;AAAA,MAChC,WAAW;AAAA,MACX,qBAAqB;AAAA,IACzB,CAAC;AAAA,EACL;AAEA,SAAOA;AACX;AAEO,MAAM,QAA8B,OAAO,WAAO,8BAAe,CAAC,EACpE,OAAO,CAAC,YAAY,QAAQ,KAAK,EACjC,QAAQ,CAAC,YAAY,aAAa,QAAQ,KAA2B,CAAC;",
|
|
6
|
+
"names": ["rules"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var index_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(index_exports);
|
|
18
|
+
__reExport(index_exports, require("./utils.js"), module.exports);
|
|
19
|
+
__reExport(index_exports, require("./types/index.js"), module.exports);
|
|
20
|
+
__reExport(index_exports, require("./constants.js"), module.exports);
|
|
21
|
+
__reExport(index_exports, require("./client/kiosk-client.js"), module.exports);
|
|
22
|
+
__reExport(index_exports, require("./client/tp-transaction.js"), module.exports);
|
|
23
|
+
__reExport(index_exports, require("./client/kiosk-transaction.js"), module.exports);
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nexport * from './utils.js';\nexport * from './types/index.js';\nexport * from './constants.js';\nexport * from './client/kiosk-client.js';\nexport * from './client/tp-transaction.js';\nexport * from './client/kiosk-transaction.js';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAIA,0BAAc,uBAJd;AAKA,0BAAc,6BALd;AAMA,0BAAc,2BANd;AAOA,0BAAc,qCAPd;AAQA,0BAAc,uCARd;AASA,0BAAc,0CATd;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PaginationArguments, IotaClient } from '@iota/iota-sdk/client';
|
|
2
|
+
import type { FetchKioskOptions, KioskExtension, OwnedKiosks, PagedKioskData } from '../types/index.js';
|
|
3
|
+
export declare function fetchKiosk(client: IotaClient, kioskId: string, pagination: PaginationArguments<string>, options: FetchKioskOptions): Promise<PagedKioskData>;
|
|
4
|
+
/**
|
|
5
|
+
* A function to fetch all the user's kiosk Caps
|
|
6
|
+
* And a list of the kiosk address ids.
|
|
7
|
+
* Returns a list of `kioskOwnerCapIds` and `kioskIds`.
|
|
8
|
+
* Extra options allow pagination.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getOwnedKiosks(client: IotaClient, address: string, options?: {
|
|
11
|
+
pagination?: PaginationArguments<string>;
|
|
12
|
+
personalKioskType: string;
|
|
13
|
+
}): Promise<OwnedKiosks>;
|
|
14
|
+
export declare function fetchKioskExtension(client: IotaClient, kioskId: string, extensionType: string): Promise<KioskExtension | null>;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var kiosk_exports = {};
|
|
20
|
+
__export(kiosk_exports, {
|
|
21
|
+
fetchKiosk: () => fetchKiosk,
|
|
22
|
+
fetchKioskExtension: () => fetchKioskExtension,
|
|
23
|
+
getOwnedKiosks: () => getOwnedKiosks
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(kiosk_exports);
|
|
26
|
+
var import_utils = require("@iota/iota-sdk/utils");
|
|
27
|
+
var import_types = require("../types/index.js");
|
|
28
|
+
var import_utils2 = require("../utils.js");
|
|
29
|
+
async function fetchKiosk(client, kioskId, pagination, options) {
|
|
30
|
+
const data = await (0, import_utils2.getAllDynamicFields)(client, kioskId, pagination);
|
|
31
|
+
const listings = [];
|
|
32
|
+
const lockedItemIds = [];
|
|
33
|
+
const kioskData = (0, import_utils2.extractKioskData)(data, listings, lockedItemIds, kioskId);
|
|
34
|
+
const [kiosk, listingObjects, items] = await Promise.all([
|
|
35
|
+
options.withKioskFields ? (0, import_utils2.getKioskObject)(client, kioskId) : Promise.resolve(void 0),
|
|
36
|
+
options.withListingPrices ? (0, import_utils2.getAllObjects)(client, kioskData.listingIds, {
|
|
37
|
+
showContent: true
|
|
38
|
+
}) : Promise.resolve([]),
|
|
39
|
+
options.withObjects ? (0, import_utils2.getAllObjects)(
|
|
40
|
+
client,
|
|
41
|
+
kioskData.itemIds,
|
|
42
|
+
options.objectOptions || { showDisplay: true }
|
|
43
|
+
) : Promise.resolve([])
|
|
44
|
+
]);
|
|
45
|
+
if (options.withKioskFields) kioskData.kiosk = kiosk;
|
|
46
|
+
(0, import_utils2.attachListingsAndPrices)(kioskData, listings, listingObjects);
|
|
47
|
+
(0, import_utils2.attachLockedItems)(kioskData, lockedItemIds);
|
|
48
|
+
(0, import_utils2.attachObjects)(
|
|
49
|
+
kioskData,
|
|
50
|
+
items.filter((x) => !!x.data).map((x) => x.data)
|
|
51
|
+
);
|
|
52
|
+
return {
|
|
53
|
+
data: kioskData,
|
|
54
|
+
nextCursor: null,
|
|
55
|
+
hasNextPage: false
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
async function getOwnedKiosks(client, address, options) {
|
|
59
|
+
if (!(0, import_utils.isValidIotaAddress)(address))
|
|
60
|
+
return {
|
|
61
|
+
nextCursor: null,
|
|
62
|
+
hasNextPage: false,
|
|
63
|
+
kioskOwnerCaps: [],
|
|
64
|
+
kioskIds: []
|
|
65
|
+
};
|
|
66
|
+
const filter = {
|
|
67
|
+
MatchAny: [
|
|
68
|
+
{
|
|
69
|
+
StructType: import_types.KIOSK_OWNER_CAP
|
|
70
|
+
}
|
|
71
|
+
]
|
|
72
|
+
};
|
|
73
|
+
if (options?.personalKioskType) {
|
|
74
|
+
filter.MatchAny.push({
|
|
75
|
+
StructType: options.personalKioskType
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
const { data, hasNextPage, nextCursor } = await client.getOwnedObjects({
|
|
79
|
+
owner: address,
|
|
80
|
+
filter,
|
|
81
|
+
options: {
|
|
82
|
+
showContent: true,
|
|
83
|
+
showType: true
|
|
84
|
+
},
|
|
85
|
+
...options?.pagination || {}
|
|
86
|
+
});
|
|
87
|
+
const kioskIdList = data?.map((x) => {
|
|
88
|
+
const fields = x.data?.content?.dataType === "moveObject" ? x.data.content.fields : null;
|
|
89
|
+
return fields?.cap ? fields?.cap?.fields?.for : fields?.for;
|
|
90
|
+
});
|
|
91
|
+
const filteredData = data.filter((x) => "data" in x).map((x) => x.data);
|
|
92
|
+
return {
|
|
93
|
+
nextCursor,
|
|
94
|
+
hasNextPage,
|
|
95
|
+
kioskOwnerCaps: filteredData.map((x, idx) => ({
|
|
96
|
+
isPersonal: x.type !== import_types.KIOSK_OWNER_CAP,
|
|
97
|
+
digest: x.digest,
|
|
98
|
+
version: x.version,
|
|
99
|
+
objectId: x.objectId,
|
|
100
|
+
kioskId: kioskIdList[idx]
|
|
101
|
+
})),
|
|
102
|
+
kioskIds: kioskIdList
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
async function fetchKioskExtension(client, kioskId, extensionType) {
|
|
106
|
+
const extension = await client.getDynamicFieldObjectV2({
|
|
107
|
+
parentObjectId: kioskId,
|
|
108
|
+
name: {
|
|
109
|
+
type: `0x2::kiosk_extension::ExtensionKey<${extensionType}>`,
|
|
110
|
+
value: {
|
|
111
|
+
dummy_field: false
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
options: {
|
|
115
|
+
showContent: true
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
if (!extension.data) return null;
|
|
119
|
+
const fields = extension?.data?.content?.fields?.value?.fields;
|
|
120
|
+
return {
|
|
121
|
+
objectId: extension.data.objectId,
|
|
122
|
+
type: extensionType,
|
|
123
|
+
isEnabled: fields?.is_enabled,
|
|
124
|
+
permissions: fields?.permissions,
|
|
125
|
+
storageId: fields?.storage?.fields?.id?.id,
|
|
126
|
+
storageSize: fields?.storage?.fields?.size
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=kiosk.js.map
|