@iota/kiosk 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/README.md +2 -2
- package/dist/cjs/bcs.d.ts +38 -2
- package/dist/cjs/bcs.js +20 -18
- package/dist/cjs/bcs.js.map +2 -2
- package/dist/cjs/client/kiosk-client.d.ts +4 -2
- package/dist/cjs/client/kiosk-client.js +10 -5
- package/dist/cjs/client/kiosk-client.js.map +2 -2
- package/dist/cjs/client/kiosk-transaction.d.ts +11 -10
- package/dist/cjs/client/kiosk-transaction.js +102 -140
- package/dist/cjs/client/kiosk-transaction.js.map +2 -2
- package/dist/cjs/client/tp-transaction.d.ts +8 -6
- package/dist/cjs/client/tp-transaction.js +54 -65
- package/dist/cjs/client/tp-transaction.js.map +2 -2
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/query/kiosk.js +2 -4
- package/dist/cjs/query/kiosk.js.map +1 -1
- package/dist/cjs/query/transfer-policy.d.ts +1 -0
- package/dist/cjs/query/transfer-policy.js +5 -7
- package/dist/cjs/query/transfer-policy.js.map +3 -3
- package/dist/cjs/tx/kiosk.d.ts +14 -14
- package/dist/cjs/tx/kiosk.js.map +2 -2
- package/dist/cjs/tx/personal-kiosk.d.ts +3 -3
- package/dist/cjs/tx/personal-kiosk.js.map +2 -2
- package/dist/cjs/tx/rules/attach.d.ts +5 -5
- package/dist/cjs/tx/rules/attach.js.map +2 -2
- package/dist/cjs/tx/rules/resolve.js +18 -20
- package/dist/cjs/tx/rules/resolve.js.map +2 -2
- package/dist/cjs/tx/transfer-policy.d.ts +7 -7
- package/dist/cjs/tx/transfer-policy.js.map +2 -2
- package/dist/cjs/types/kiosk.d.ts +0 -1
- package/dist/cjs/types/kiosk.js.map +2 -2
- package/dist/cjs/types/transfer-policy.d.ts +4 -2
- package/dist/cjs/types/transfer-policy.js.map +2 -2
- package/dist/cjs/utils.js +4 -7
- package/dist/cjs/utils.js.map +2 -2
- package/dist/esm/bcs.d.ts +38 -2
- package/dist/esm/bcs.js +20 -18
- package/dist/esm/bcs.js.map +2 -2
- package/dist/esm/client/kiosk-client.d.ts +4 -2
- package/dist/esm/client/kiosk-client.js +10 -5
- package/dist/esm/client/kiosk-client.js.map +2 -2
- package/dist/esm/client/kiosk-transaction.d.ts +11 -10
- package/dist/esm/client/kiosk-transaction.js +101 -139
- package/dist/esm/client/kiosk-transaction.js.map +2 -2
- package/dist/esm/client/tp-transaction.d.ts +8 -6
- package/dist/esm/client/tp-transaction.js +53 -64
- package/dist/esm/client/tp-transaction.js.map +2 -2
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/query/kiosk.js +2 -4
- package/dist/esm/query/kiosk.js.map +1 -1
- package/dist/esm/query/transfer-policy.d.ts +1 -0
- package/dist/esm/query/transfer-policy.js +7 -9
- package/dist/esm/query/transfer-policy.js.map +2 -2
- package/dist/esm/tx/kiosk.d.ts +14 -14
- package/dist/esm/tx/kiosk.js.map +2 -2
- package/dist/esm/tx/personal-kiosk.d.ts +3 -3
- package/dist/esm/tx/personal-kiosk.js.map +2 -2
- package/dist/esm/tx/rules/attach.d.ts +5 -5
- package/dist/esm/tx/rules/attach.js.map +2 -2
- package/dist/esm/tx/rules/resolve.js +18 -20
- package/dist/esm/tx/rules/resolve.js.map +2 -2
- package/dist/esm/tx/transfer-policy.d.ts +7 -7
- package/dist/esm/tx/transfer-policy.js.map +2 -2
- package/dist/esm/types/kiosk.d.ts +0 -1
- package/dist/esm/types/kiosk.js.map +2 -2
- package/dist/esm/types/transfer-policy.d.ts +4 -2
- package/dist/esm/types/transfer-policy.js.map +2 -2
- package/dist/esm/utils.js +12 -10
- package/dist/esm/utils.js.map +2 -2
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -11
- package/src/bcs.ts +16 -19
- package/src/client/kiosk-client.ts +15 -5
- package/src/client/kiosk-transaction.ts +52 -56
- package/src/client/tp-transaction.ts +31 -28
- package/src/query/transfer-policy.ts +5 -3
- package/src/tx/kiosk.ts +14 -14
- package/src/tx/personal-kiosk.ts +3 -3
- package/src/tx/rules/attach.ts +5 -5
- package/src/tx/rules/resolve.ts +16 -16
- package/src/tx/transfer-policy.ts +7 -7
- package/src/types/kiosk.ts +0 -1
- package/src/types/transfer-policy.ts +4 -2
- package/src/utils.ts +10 -5
package/src/tx/rules/attach.ts
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
// Modifications Copyright (c) 2024 IOTA Stiftung
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
|
-
import type {
|
|
5
|
+
import type { Transaction } from '@iota/iota-sdk/transactions';
|
|
6
6
|
|
|
7
7
|
import type { ObjectArgument } from '../../types/index.js';
|
|
8
8
|
|
|
9
9
|
export function attachKioskLockRuleTx(
|
|
10
|
-
tx:
|
|
10
|
+
tx: Transaction,
|
|
11
11
|
type: string,
|
|
12
12
|
policy: ObjectArgument,
|
|
13
13
|
policyCap: ObjectArgument,
|
|
@@ -21,7 +21,7 @@ export function attachKioskLockRuleTx(
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export function attachRoyaltyRuleTx(
|
|
24
|
-
tx:
|
|
24
|
+
tx: Transaction,
|
|
25
25
|
type: string,
|
|
26
26
|
policy: ObjectArgument,
|
|
27
27
|
policyCap: ObjectArgument,
|
|
@@ -45,7 +45,7 @@ export function attachRoyaltyRuleTx(
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
export function attachPersonalKioskRuleTx(
|
|
48
|
-
tx:
|
|
48
|
+
tx: Transaction,
|
|
49
49
|
type: string,
|
|
50
50
|
policy: ObjectArgument,
|
|
51
51
|
policyCap: ObjectArgument,
|
|
@@ -59,7 +59,7 @@ export function attachPersonalKioskRuleTx(
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
export function attachFloorPriceRuleTx(
|
|
62
|
-
tx:
|
|
62
|
+
tx: Transaction,
|
|
63
63
|
type: string,
|
|
64
64
|
policy: ObjectArgument,
|
|
65
65
|
policyCap: ObjectArgument,
|
package/src/tx/rules/resolve.ts
CHANGED
|
@@ -9,22 +9,22 @@ import { lock } from '../kiosk.js';
|
|
|
9
9
|
* A helper to resolve the royalty rule.
|
|
10
10
|
*/
|
|
11
11
|
export function resolveRoyaltyRule(params: RuleResolvingParams) {
|
|
12
|
-
const {
|
|
12
|
+
const { transaction: tx, itemType, price, packageId, transferRequest, policyId } = params;
|
|
13
13
|
|
|
14
|
-
const policyObj =
|
|
14
|
+
const policyObj = tx.object(policyId);
|
|
15
15
|
|
|
16
16
|
// calculates the amount
|
|
17
|
-
const [amount] =
|
|
17
|
+
const [amount] = tx.moveCall({
|
|
18
18
|
target: `${packageId}::royalty_rule::fee_amount`,
|
|
19
19
|
typeArguments: [itemType],
|
|
20
|
-
arguments: [policyObj,
|
|
20
|
+
arguments: [policyObj, tx.pure.u64(price || '0')],
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
// splits the coin.
|
|
24
|
-
const feeCoin =
|
|
24
|
+
const feeCoin = tx.splitCoins(tx.gas, [amount]);
|
|
25
25
|
|
|
26
26
|
// pays the policy
|
|
27
|
-
|
|
27
|
+
tx.moveCall({
|
|
28
28
|
target: `${packageId}::royalty_rule::pay`,
|
|
29
29
|
typeArguments: [itemType],
|
|
30
30
|
arguments: [policyObj, transferRequest, feeCoin],
|
|
@@ -33,7 +33,7 @@ export function resolveRoyaltyRule(params: RuleResolvingParams) {
|
|
|
33
33
|
|
|
34
34
|
export function resolveKioskLockRule(params: RuleResolvingParams) {
|
|
35
35
|
const {
|
|
36
|
-
|
|
36
|
+
transaction: tx,
|
|
37
37
|
packageId,
|
|
38
38
|
itemType,
|
|
39
39
|
kiosk,
|
|
@@ -45,13 +45,13 @@ export function resolveKioskLockRule(params: RuleResolvingParams) {
|
|
|
45
45
|
|
|
46
46
|
if (!kiosk || !kioskCap) throw new Error('Missing Owned Kiosk or Owned Kiosk Cap');
|
|
47
47
|
|
|
48
|
-
lock(
|
|
48
|
+
lock(tx, itemType, kiosk, kioskCap, policyId, purchasedItem);
|
|
49
49
|
|
|
50
50
|
// proves that the item is locked in the kiosk to the TP.
|
|
51
|
-
|
|
51
|
+
tx.moveCall({
|
|
52
52
|
target: `${packageId}::kiosk_lock_rule::prove`,
|
|
53
53
|
typeArguments: [itemType],
|
|
54
|
-
arguments: [transferRequest,
|
|
54
|
+
arguments: [transferRequest, tx.object(kiosk)],
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
57
|
|
|
@@ -60,15 +60,15 @@ export function resolveKioskLockRule(params: RuleResolvingParams) {
|
|
|
60
60
|
* @param params
|
|
61
61
|
*/
|
|
62
62
|
export function resolvePersonalKioskRule(params: RuleResolvingParams) {
|
|
63
|
-
const {
|
|
63
|
+
const { transaction: tx, packageId, itemType, kiosk, transferRequest } = params;
|
|
64
64
|
|
|
65
65
|
if (!kiosk) throw new Error('Missing owned Kiosk.');
|
|
66
66
|
|
|
67
67
|
// proves that the destination kiosk is personal.
|
|
68
|
-
|
|
68
|
+
tx.moveCall({
|
|
69
69
|
target: `${packageId}::personal_kiosk_rule::prove`,
|
|
70
70
|
typeArguments: [itemType],
|
|
71
|
-
arguments: [
|
|
71
|
+
arguments: [tx.object(kiosk), transferRequest],
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
74
|
|
|
@@ -76,12 +76,12 @@ export function resolvePersonalKioskRule(params: RuleResolvingParams) {
|
|
|
76
76
|
* Resolves the floor price rule.
|
|
77
77
|
*/
|
|
78
78
|
export function resolveFloorPriceRule(params: RuleResolvingParams) {
|
|
79
|
-
const {
|
|
79
|
+
const { transaction: tx, packageId, itemType, policyId, transferRequest } = params;
|
|
80
80
|
|
|
81
81
|
// proves that the destination kiosk is personal
|
|
82
|
-
|
|
82
|
+
tx.moveCall({
|
|
83
83
|
target: `${packageId}::floor_price_rule::prove`,
|
|
84
84
|
typeArguments: [itemType],
|
|
85
|
-
arguments: [
|
|
85
|
+
arguments: [tx.object(policyId), transferRequest],
|
|
86
86
|
});
|
|
87
87
|
}
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
import { bcs } from '@iota/iota-sdk/bcs';
|
|
6
6
|
import type {
|
|
7
|
+
Transaction,
|
|
7
8
|
TransactionArgument,
|
|
8
|
-
TransactionBlock,
|
|
9
9
|
TransactionObjectArgument,
|
|
10
10
|
} from '@iota/iota-sdk/transactions';
|
|
11
11
|
|
|
@@ -17,7 +17,7 @@ import { TRANSFER_POLICY_MODULE, TRANSFER_POLICY_TYPE } from '../types/index.js'
|
|
|
17
17
|
* Returns `transferPolicyCap`
|
|
18
18
|
*/
|
|
19
19
|
export function createTransferPolicy(
|
|
20
|
-
tx:
|
|
20
|
+
tx: Transaction,
|
|
21
21
|
itemType: string,
|
|
22
22
|
publisher: ObjectArgument,
|
|
23
23
|
): TransactionObjectArgument {
|
|
@@ -37,7 +37,7 @@ export function createTransferPolicy(
|
|
|
37
37
|
* Used if we want to use the policy before making it a shared object.
|
|
38
38
|
*/
|
|
39
39
|
export function createTransferPolicyWithoutSharing(
|
|
40
|
-
tx:
|
|
40
|
+
tx: Transaction,
|
|
41
41
|
itemType: string,
|
|
42
42
|
publisher: ObjectArgument,
|
|
43
43
|
): [TransactionObjectArgument, TransactionObjectArgument] {
|
|
@@ -53,7 +53,7 @@ export function createTransferPolicyWithoutSharing(
|
|
|
53
53
|
* Converts Transfer Policy to a shared object.
|
|
54
54
|
*/
|
|
55
55
|
export function shareTransferPolicy(
|
|
56
|
-
tx:
|
|
56
|
+
tx: Transaction,
|
|
57
57
|
itemType: string,
|
|
58
58
|
transferPolicy: TransactionObjectArgument,
|
|
59
59
|
) {
|
|
@@ -68,7 +68,7 @@ export function shareTransferPolicy(
|
|
|
68
68
|
* Call the `transfer_policy::withdraw` function to withdraw profits from a transfer policy.
|
|
69
69
|
*/
|
|
70
70
|
export function withdrawFromPolicy(
|
|
71
|
-
tx:
|
|
71
|
+
tx: Transaction,
|
|
72
72
|
itemType: string,
|
|
73
73
|
policy: ObjectArgument,
|
|
74
74
|
policyCap: ObjectArgument,
|
|
@@ -90,7 +90,7 @@ export function withdrawFromPolicy(
|
|
|
90
90
|
* transaction.
|
|
91
91
|
*/
|
|
92
92
|
export function confirmRequest(
|
|
93
|
-
tx:
|
|
93
|
+
tx: Transaction,
|
|
94
94
|
itemType: string,
|
|
95
95
|
policy: ObjectArgument,
|
|
96
96
|
request: TransactionArgument,
|
|
@@ -106,7 +106,7 @@ export function confirmRequest(
|
|
|
106
106
|
* Calls the `transfer_policy::remove_rule` function to remove a Rule from the transfer policy's ruleset.
|
|
107
107
|
*/
|
|
108
108
|
export function removeTransferPolicyRule(
|
|
109
|
-
tx:
|
|
109
|
+
tx: Transaction,
|
|
110
110
|
itemType: string,
|
|
111
111
|
ruleType: string,
|
|
112
112
|
configType: string,
|
package/src/types/kiosk.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
5
|
import type { ObjectOwner } from '@iota/iota-sdk/client';
|
|
6
|
-
import type {
|
|
6
|
+
import type { Transaction, TransactionObjectArgument } from '@iota/iota-sdk/transactions';
|
|
7
7
|
|
|
8
8
|
import type { ObjectArgument } from './index.js';
|
|
9
9
|
|
|
@@ -53,7 +53,9 @@ export type TransferPolicyCreated = {
|
|
|
53
53
|
// Each rule resolving function should check that the key it's seeking is in the object
|
|
54
54
|
// e.g. `if(!'my_key' in ruleParams!) throw new Error("Can't resolve that rule!")`
|
|
55
55
|
export type RuleResolvingParams = {
|
|
56
|
-
|
|
56
|
+
transaction: Transaction;
|
|
57
|
+
/** @deprecated use transaction instead */
|
|
58
|
+
transactionBlock: Transaction;
|
|
57
59
|
itemType: string;
|
|
58
60
|
itemId: string;
|
|
59
61
|
price: string;
|
package/src/utils.ts
CHANGED
|
@@ -11,11 +11,16 @@ import type {
|
|
|
11
11
|
IotaObjectDataOptions,
|
|
12
12
|
IotaObjectResponse,
|
|
13
13
|
} from '@iota/iota-sdk/client';
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
import {
|
|
15
|
+
fromB64,
|
|
16
|
+
normalizeStructTag,
|
|
17
|
+
normalizeIotaAddress,
|
|
18
|
+
parseStructTag,
|
|
19
|
+
} from '@iota/iota-sdk/utils';
|
|
20
|
+
|
|
21
|
+
import { KioskType } from './bcs.js';
|
|
17
22
|
import type { Kiosk, KioskData, KioskListing, TransferPolicyCap } from './types/index.js';
|
|
18
|
-
import {
|
|
23
|
+
import { TRANSFER_POLICY_CAP_TYPE } from './types/index.js';
|
|
19
24
|
|
|
20
25
|
const DEFAULT_QUERY_LIMIT = 50;
|
|
21
26
|
|
|
@@ -30,7 +35,7 @@ export async function getKioskObject(client: IotaClient, id: string): Promise<Ki
|
|
|
30
35
|
throw new Error(`Invalid kiosk query: ${id}, expected object, got package`);
|
|
31
36
|
}
|
|
32
37
|
|
|
33
|
-
return
|
|
38
|
+
return KioskType.parse(fromB64(queryRes.data.bcs!.bcsBytes));
|
|
34
39
|
}
|
|
35
40
|
|
|
36
41
|
// helper to extract kiosk data from dynamic fields.
|