@iota/kiosk 0.6.2 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +77 -0
- package/dist/cjs/bcs.d.ts +22 -37
- package/dist/cjs/bcs.d.ts.map +1 -0
- package/dist/cjs/client/kiosk-client.d.ts +1 -0
- package/dist/cjs/client/kiosk-client.d.ts.map +1 -0
- package/dist/cjs/client/kiosk-client.js +1 -8
- package/dist/cjs/client/kiosk-client.js.map +2 -2
- package/dist/cjs/client/kiosk-transaction.d.ts +6 -7
- package/dist/cjs/client/kiosk-transaction.d.ts.map +1 -0
- package/dist/cjs/client/kiosk-transaction.js +8 -10
- package/dist/cjs/client/kiosk-transaction.js.map +2 -2
- package/dist/cjs/client/tp-transaction.d.ts +2 -3
- package/dist/cjs/client/tp-transaction.d.ts.map +1 -0
- package/dist/cjs/client/tp-transaction.js +1 -6
- package/dist/cjs/client/tp-transaction.js.map +2 -2
- package/dist/cjs/constants.d.ts +2 -1
- package/dist/cjs/constants.d.ts.map +1 -0
- package/dist/cjs/constants.js +1 -1
- package/dist/cjs/constants.js.map +2 -2
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/query/kiosk.d.ts +1 -0
- package/dist/cjs/query/kiosk.d.ts.map +1 -0
- package/dist/cjs/query/kiosk.js +81 -22
- package/dist/cjs/query/kiosk.js.map +2 -2
- package/dist/cjs/query/transfer-policy.d.ts +1 -0
- package/dist/cjs/query/transfer-policy.d.ts.map +1 -0
- package/dist/cjs/tx/kiosk.d.ts +1 -0
- package/dist/cjs/tx/kiosk.d.ts.map +1 -0
- package/dist/cjs/tx/personal-kiosk.d.ts +1 -0
- package/dist/cjs/tx/personal-kiosk.d.ts.map +1 -0
- package/dist/cjs/tx/rules/attach.d.ts +1 -0
- package/dist/cjs/tx/rules/attach.d.ts.map +1 -0
- package/dist/cjs/tx/rules/resolve.d.ts +2 -1
- package/dist/cjs/tx/rules/resolve.d.ts.map +1 -0
- package/dist/cjs/tx/rules/resolve.js +35 -5
- package/dist/cjs/tx/rules/resolve.js.map +2 -2
- package/dist/cjs/tx/transfer-policy.d.ts +1 -0
- package/dist/cjs/tx/transfer-policy.d.ts.map +1 -0
- package/dist/cjs/types/index.d.ts +1 -0
- package/dist/cjs/types/index.d.ts.map +1 -0
- package/dist/cjs/types/kiosk.d.ts +1 -0
- package/dist/cjs/types/kiosk.d.ts.map +1 -0
- package/dist/cjs/types/transfer-policy.d.ts +3 -2
- package/dist/cjs/types/transfer-policy.d.ts.map +1 -0
- package/dist/cjs/types/transfer-policy.js.map +2 -2
- package/dist/cjs/utils.d.ts +1 -0
- package/dist/cjs/utils.d.ts.map +1 -0
- package/dist/esm/bcs.d.ts +22 -37
- package/dist/esm/bcs.d.ts.map +1 -0
- package/dist/esm/client/kiosk-client.d.ts +1 -0
- package/dist/esm/client/kiosk-client.d.ts.map +1 -0
- package/dist/esm/client/kiosk-client.js +1 -8
- package/dist/esm/client/kiosk-client.js.map +2 -2
- package/dist/esm/client/kiosk-transaction.d.ts +6 -7
- package/dist/esm/client/kiosk-transaction.d.ts.map +1 -0
- package/dist/esm/client/kiosk-transaction.js +8 -10
- package/dist/esm/client/kiosk-transaction.js.map +2 -2
- package/dist/esm/client/tp-transaction.d.ts +2 -3
- package/dist/esm/client/tp-transaction.d.ts.map +1 -0
- package/dist/esm/client/tp-transaction.js +1 -6
- package/dist/esm/client/tp-transaction.js.map +2 -2
- package/dist/esm/constants.d.ts +2 -1
- package/dist/esm/constants.d.ts.map +1 -0
- package/dist/esm/constants.js +1 -1
- package/dist/esm/constants.js.map +2 -2
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/query/kiosk.d.ts +1 -0
- package/dist/esm/query/kiosk.d.ts.map +1 -0
- package/dist/esm/query/kiosk.js +81 -22
- package/dist/esm/query/kiosk.js.map +2 -2
- package/dist/esm/query/transfer-policy.d.ts +1 -0
- package/dist/esm/query/transfer-policy.d.ts.map +1 -0
- package/dist/esm/tx/kiosk.d.ts +1 -0
- package/dist/esm/tx/kiosk.d.ts.map +1 -0
- package/dist/esm/tx/personal-kiosk.d.ts +1 -0
- package/dist/esm/tx/personal-kiosk.d.ts.map +1 -0
- package/dist/esm/tx/rules/attach.d.ts +1 -0
- package/dist/esm/tx/rules/attach.d.ts.map +1 -0
- package/dist/esm/tx/rules/resolve.d.ts +2 -1
- package/dist/esm/tx/rules/resolve.d.ts.map +1 -0
- package/dist/esm/tx/rules/resolve.js +35 -5
- package/dist/esm/tx/rules/resolve.js.map +2 -2
- package/dist/esm/tx/transfer-policy.d.ts +1 -0
- package/dist/esm/tx/transfer-policy.d.ts.map +1 -0
- package/dist/esm/types/index.d.ts +1 -0
- package/dist/esm/types/index.d.ts.map +1 -0
- package/dist/esm/types/kiosk.d.ts +1 -0
- package/dist/esm/types/kiosk.d.ts.map +1 -0
- package/dist/esm/types/transfer-policy.d.ts +3 -2
- package/dist/esm/types/transfer-policy.d.ts.map +1 -0
- package/dist/esm/types/transfer-policy.js.map +2 -2
- package/dist/esm/utils.d.ts +1 -0
- package/dist/esm/utils.d.ts.map +1 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/client/kiosk-client.ts +1 -10
- package/src/client/kiosk-transaction.ts +7 -11
- package/src/client/tp-transaction.ts +1 -8
- package/src/constants.ts +5 -3
- package/src/query/kiosk.ts +108 -28
- package/src/tx/rules/resolve.ts +45 -6
- package/src/types/transfer-policy.ts +3 -2
package/src/query/kiosk.ts
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
5
|
import type {
|
|
6
|
+
PaginatedObjectsResponse,
|
|
6
7
|
PaginationArguments,
|
|
7
8
|
IotaClient,
|
|
8
9
|
IotaObjectData,
|
|
9
|
-
IotaObjectDataFilter,
|
|
10
10
|
IotaObjectResponse,
|
|
11
11
|
} from '@iota/iota-sdk/client';
|
|
12
12
|
import { isValidIotaAddress } from '@iota/iota-sdk/utils';
|
|
@@ -29,6 +29,10 @@ import {
|
|
|
29
29
|
getKioskObject,
|
|
30
30
|
} from '../utils.js';
|
|
31
31
|
|
|
32
|
+
const DEFAULT_PAGE_SIZE = 50;
|
|
33
|
+
const PERSONAL_KIOSKS_CURSOR = 'personal';
|
|
34
|
+
const OWNED_KIOSKS_CURSOR = 'owned';
|
|
35
|
+
|
|
32
36
|
export async function fetchKiosk(
|
|
33
37
|
client: IotaClient,
|
|
34
38
|
kioskId: string,
|
|
@@ -99,45 +103,121 @@ export async function getOwnedKiosks(
|
|
|
99
103
|
personalKioskType: string;
|
|
100
104
|
},
|
|
101
105
|
): Promise<OwnedKiosks> {
|
|
102
|
-
|
|
106
|
+
// TODO: this should throw an error, but I am not going to change it right now incase it breaks existing code.
|
|
107
|
+
if (!isValidIotaAddress(address)) {
|
|
103
108
|
return {
|
|
104
109
|
nextCursor: null,
|
|
105
110
|
hasNextPage: false,
|
|
106
111
|
kioskOwnerCaps: [],
|
|
107
112
|
kioskIds: [],
|
|
108
113
|
};
|
|
114
|
+
}
|
|
109
115
|
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
116
|
+
const limit = options?.pagination?.limit ?? DEFAULT_PAGE_SIZE;
|
|
117
|
+
const [cursorType, cursor] = options?.pagination?.cursor?.split(':') ?? [
|
|
118
|
+
PERSONAL_KIOSKS_CURSOR,
|
|
119
|
+
null,
|
|
120
|
+
];
|
|
121
|
+
|
|
122
|
+
if (options?.personalKioskType && cursorType === PERSONAL_KIOSKS_CURSOR) {
|
|
123
|
+
const personalKioskResponse = formatOwnedKioskResponse(
|
|
124
|
+
await client.getOwnedObjects({
|
|
125
|
+
owner: address,
|
|
126
|
+
filter: {
|
|
127
|
+
StructType: options.personalKioskType,
|
|
128
|
+
},
|
|
129
|
+
options: {
|
|
130
|
+
showContent: true,
|
|
131
|
+
showType: true,
|
|
132
|
+
},
|
|
133
|
+
cursor,
|
|
134
|
+
limit,
|
|
135
|
+
}),
|
|
136
|
+
PERSONAL_KIOSKS_CURSOR,
|
|
137
|
+
);
|
|
117
138
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
139
|
+
if (personalKioskResponse.hasNextPage) {
|
|
140
|
+
return personalKioskResponse;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const remainingLimit = limit - personalKioskResponse.kioskOwnerCaps.length;
|
|
144
|
+
|
|
145
|
+
// If we have all personal kiosks, but don't have space for the owned kiosks
|
|
146
|
+
// we need to start loading owned kiosks for the next page, but don't have a real cursor
|
|
147
|
+
if (remainingLimit < 1) {
|
|
148
|
+
return {
|
|
149
|
+
nextCursor: `${OWNED_KIOSKS_CURSOR}:`,
|
|
150
|
+
hasNextPage: true,
|
|
151
|
+
kioskOwnerCaps: personalKioskResponse.kioskOwnerCaps,
|
|
152
|
+
kioskIds: personalKioskResponse.kioskIds,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const ownedKiosksResponse = formatOwnedKioskResponse(
|
|
157
|
+
await client.getOwnedObjects({
|
|
158
|
+
owner: address,
|
|
159
|
+
filter: {
|
|
160
|
+
StructType: KIOSK_OWNER_CAP,
|
|
161
|
+
},
|
|
162
|
+
options: {
|
|
163
|
+
showContent: true,
|
|
164
|
+
showType: true,
|
|
165
|
+
},
|
|
166
|
+
limit: remainingLimit,
|
|
167
|
+
}),
|
|
168
|
+
OWNED_KIOSKS_CURSOR,
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
nextCursor: ownedKiosksResponse.nextCursor,
|
|
173
|
+
hasNextPage: ownedKiosksResponse.hasNextPage,
|
|
174
|
+
kioskOwnerCaps: [
|
|
175
|
+
...personalKioskResponse.kioskOwnerCaps,
|
|
176
|
+
...ownedKiosksResponse.kioskOwnerCaps,
|
|
177
|
+
],
|
|
178
|
+
kioskIds: [...personalKioskResponse.kioskIds, ...ownedKiosksResponse.kioskIds],
|
|
179
|
+
};
|
|
122
180
|
}
|
|
123
181
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
182
|
+
return formatOwnedKioskResponse(
|
|
183
|
+
await client.getOwnedObjects({
|
|
184
|
+
owner: address,
|
|
185
|
+
filter: {
|
|
186
|
+
StructType: KIOSK_OWNER_CAP,
|
|
187
|
+
},
|
|
188
|
+
options: {
|
|
189
|
+
showContent: true,
|
|
190
|
+
showType: true,
|
|
191
|
+
},
|
|
192
|
+
// cursor might be an empty string if the number of personal kiosks was a multiple of the limit.
|
|
193
|
+
cursor: cursor ? cursor : null,
|
|
194
|
+
limit,
|
|
195
|
+
}),
|
|
196
|
+
OWNED_KIOSKS_CURSOR,
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function formatOwnedKioskResponse(
|
|
201
|
+
response: PaginatedObjectsResponse,
|
|
202
|
+
cursorType: string,
|
|
203
|
+
): OwnedKiosks {
|
|
204
|
+
const { data, hasNextPage, nextCursor } = response;
|
|
134
205
|
|
|
135
206
|
// get kioskIds from the OwnerCaps.
|
|
136
207
|
const kioskIdList = data?.map((x: IotaObjectResponse) => {
|
|
137
|
-
const fields =
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
208
|
+
const fields =
|
|
209
|
+
x.data?.content?.dataType === 'moveObject'
|
|
210
|
+
? (x.data.content.fields as unknown as
|
|
211
|
+
| {
|
|
212
|
+
cap: { fields: { for: string } };
|
|
213
|
+
for?: never;
|
|
214
|
+
}
|
|
215
|
+
| {
|
|
216
|
+
cap?: never;
|
|
217
|
+
for: string;
|
|
218
|
+
})
|
|
219
|
+
: null;
|
|
220
|
+
return fields?.cap ? fields?.cap?.fields?.for : (fields?.for as string);
|
|
141
221
|
});
|
|
142
222
|
|
|
143
223
|
// clean up data that might have an error in them.
|
|
@@ -145,7 +225,7 @@ export async function getOwnedKiosks(
|
|
|
145
225
|
const filteredData = data.filter((x) => 'data' in x).map((x) => x.data) as IotaObjectData[];
|
|
146
226
|
|
|
147
227
|
return {
|
|
148
|
-
nextCursor,
|
|
228
|
+
nextCursor: nextCursor ? `${cursorType}:${nextCursor}` : nextCursor,
|
|
149
229
|
hasNextPage,
|
|
150
230
|
kioskOwnerCaps: filteredData.map((x, idx) => ({
|
|
151
231
|
isPersonal: x.type !== KIOSK_OWNER_CAP,
|
package/src/tx/rules/resolve.ts
CHANGED
|
@@ -1,25 +1,64 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
-
// Modifications Copyright (c)
|
|
2
|
+
// Modifications Copyright (c) 2026 IOTA Stiftung
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
|
+
import { bcs } from '@iota/iota-sdk/bcs';
|
|
6
|
+
import type { TransactionArgument } from '@iota/iota-sdk/transactions';
|
|
7
|
+
import { Transaction } from '@iota/iota-sdk/transactions';
|
|
8
|
+
import { normalizeIotaAddress } from '@iota/iota-sdk/utils';
|
|
9
|
+
|
|
5
10
|
import type { RuleResolvingParams } from '../../types/index.js';
|
|
6
11
|
import { lock } from '../kiosk.js';
|
|
7
12
|
|
|
8
13
|
/**
|
|
9
14
|
* A helper to resolve the royalty rule.
|
|
10
15
|
*/
|
|
11
|
-
export function resolveRoyaltyRule(params: RuleResolvingParams) {
|
|
12
|
-
const {
|
|
16
|
+
export async function resolveRoyaltyRule(params: RuleResolvingParams) {
|
|
17
|
+
const {
|
|
18
|
+
kioskClient,
|
|
19
|
+
transaction: tx,
|
|
20
|
+
itemType,
|
|
21
|
+
price,
|
|
22
|
+
packageId,
|
|
23
|
+
transferRequest,
|
|
24
|
+
policyId,
|
|
25
|
+
} = params;
|
|
13
26
|
|
|
14
|
-
|
|
27
|
+
// We attempt to resolve the fee amount outside of the PTB so that the split amount is known before the transaction is sent.
|
|
28
|
+
// This improves the display of the transaction within the wallet.
|
|
15
29
|
|
|
30
|
+
const feeTx = new Transaction();
|
|
16
31
|
// calculates the amount
|
|
17
|
-
|
|
32
|
+
feeTx.moveCall({
|
|
18
33
|
target: `${packageId}::royalty_rule::fee_amount`,
|
|
19
34
|
typeArguments: [itemType],
|
|
20
|
-
arguments: [
|
|
35
|
+
arguments: [feeTx.object(policyId), feeTx.pure.u64(price || '0')],
|
|
21
36
|
});
|
|
22
37
|
|
|
38
|
+
const policyObj = tx.object(policyId);
|
|
39
|
+
|
|
40
|
+
const { results } = await kioskClient.client.devInspectTransactionBlock({
|
|
41
|
+
sender: tx.getData().sender || normalizeIotaAddress('0x0'),
|
|
42
|
+
transactionBlock: feeTx,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
let amount: TransactionArgument | bigint | null = null;
|
|
46
|
+
if (results) {
|
|
47
|
+
const returnedAmount = results?.[0].returnValues?.[0]?.[0];
|
|
48
|
+
if (returnedAmount) {
|
|
49
|
+
amount = BigInt(bcs.U64.parse(new Uint8Array(returnedAmount as number[])));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// We were not able to calculate the amount outside of the transaction, so fall back to resolving it within the PTB
|
|
54
|
+
if (!amount) {
|
|
55
|
+
[amount] = tx.moveCall({
|
|
56
|
+
target: `${packageId}::royalty_rule::fee_amount`,
|
|
57
|
+
typeArguments: [itemType],
|
|
58
|
+
arguments: [policyObj, tx.pure.u64(price || '0')],
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
23
62
|
// splits the coin.
|
|
24
63
|
const feeCoin = tx.splitCoins(tx.gas, [amount]);
|
|
25
64
|
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import type { ObjectOwner } from '@iota/iota-sdk/client';
|
|
6
6
|
import type { Transaction, TransactionObjectArgument } from '@iota/iota-sdk/transactions';
|
|
7
7
|
|
|
8
|
+
import type { KioskClient } from '../client/kiosk-client.js';
|
|
8
9
|
import type { ObjectArgument } from './index.js';
|
|
9
10
|
|
|
10
11
|
/** The Transfer Policy module. */
|
|
@@ -54,8 +55,6 @@ export type TransferPolicyCreated = {
|
|
|
54
55
|
// e.g. `if(!'my_key' in ruleParams!) throw new Error("Can't resolve that rule!")`
|
|
55
56
|
export type RuleResolvingParams = {
|
|
56
57
|
transaction: Transaction;
|
|
57
|
-
/** @deprecated use transaction instead */
|
|
58
|
-
transactionBlock: Transaction;
|
|
59
58
|
itemType: string;
|
|
60
59
|
itemId: string;
|
|
61
60
|
price: string;
|
|
@@ -67,4 +66,6 @@ export type RuleResolvingParams = {
|
|
|
67
66
|
purchasedItem: TransactionObjectArgument;
|
|
68
67
|
packageId: string;
|
|
69
68
|
extraArgs: Record<string, any>; // extraParams contains more possible {key, values} to pass for custom rules.
|
|
69
|
+
|
|
70
|
+
kioskClient: KioskClient;
|
|
70
71
|
};
|