@haneullabs/kiosk 0.1.0 → 1.1.2
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 +271 -137
- package/README.md +3 -3
- 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 +16 -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/haneul/kiosk.mjs +98 -0
- package/dist/contracts/kiosk/deps/haneul/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 +215 -0
- package/dist/query/client-utils.mjs.map +1 -0
- package/dist/query/kiosk.mjs +155 -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 +26 -0
- package/dist/types/index.d.mts.map +1 -0
- package/dist/types/kiosk.d.mts +175 -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 +39 -0
- package/dist/utils.d.mts.map +1 -0
- package/dist/utils.mjs +137 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +25 -20
- package/src/client/kiosk-client.ts +43 -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/bag.ts +13 -0
- package/src/contracts/0x2/balance.ts +12 -0
- package/src/contracts/0x2/deps/0x0000000000000000000000000000000000000000000000000000000000000001/type_name.ts +12 -0
- package/src/contracts/0x2/kiosk.ts +797 -0
- package/src/contracts/0x2/kiosk_extension.ts +270 -0
- package/src/contracts/0x2/transfer_policy.ts +400 -0
- package/src/contracts/0x2/vec_set.ts +14 -0
- package/src/contracts/kiosk/deps/haneul/kiosk.ts +94 -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 +302 -0
- package/src/query/kiosk.ts +130 -101
- package/src/query/transfer-policy.ts +112 -79
- 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 +7 -14
- package/src/types/kiosk.ts +22 -12
- package/src/types/transfer-policy.ts +4 -4
- package/src/utils.ts +79 -147
- 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
package/src/tx/rules/resolve.ts
CHANGED
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { bcs } from '@haneullabs/haneul/bcs';
|
|
5
4
|
import type { TransactionArgument } from '@haneullabs/haneul/transactions';
|
|
6
5
|
import { Transaction } from '@haneullabs/haneul/transactions';
|
|
6
|
+
import { bcs } from '@haneullabs/haneul/bcs';
|
|
7
7
|
import { normalizeHaneulAddress } from '@haneullabs/haneul/utils';
|
|
8
8
|
|
|
9
9
|
import type { RuleResolvingParams } from '../../types/index.js';
|
|
10
|
-
import
|
|
11
|
-
|
|
10
|
+
import * as kiosk from '../../contracts/0x2/kiosk.js';
|
|
11
|
+
import * as royaltyRule from '../../contracts/kiosk/royalty_rule.js';
|
|
12
|
+
import * as kioskLockRule from '../../contracts/kiosk/kiosk_lock_rule.js';
|
|
13
|
+
import * as personalKioskRule from '../../contracts/kiosk/personal_kiosk_rule.js';
|
|
14
|
+
import * as floorPriceRule from '../../contracts/kiosk/floor_price_rule.js';
|
|
12
15
|
/**
|
|
13
16
|
* A helper to resolve the royalty rule.
|
|
14
17
|
*/
|
|
15
18
|
export async function resolveRoyaltyRule(params: RuleResolvingParams) {
|
|
16
19
|
const {
|
|
17
|
-
kioskClient,
|
|
18
20
|
transaction: tx,
|
|
19
21
|
itemType,
|
|
20
22
|
price,
|
|
21
23
|
packageId,
|
|
22
24
|
transferRequest,
|
|
23
25
|
policyId,
|
|
26
|
+
kioskClient,
|
|
24
27
|
} = params;
|
|
25
28
|
|
|
26
29
|
// We attempt to resolve the fee amount outside of the PTB so that the split amount is known before the transaction is sent.
|
|
@@ -29,45 +32,69 @@ export async function resolveRoyaltyRule(params: RuleResolvingParams) {
|
|
|
29
32
|
const feeTx = new Transaction();
|
|
30
33
|
|
|
31
34
|
// calculates the amount
|
|
32
|
-
feeTx.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
feeTx.add(
|
|
36
|
+
royaltyRule.feeAmount({
|
|
37
|
+
package: packageId,
|
|
38
|
+
arguments: {
|
|
39
|
+
policy: feeTx.object(policyId),
|
|
40
|
+
paid: BigInt(price || '0'),
|
|
41
|
+
},
|
|
42
|
+
typeArguments: [itemType],
|
|
43
|
+
}),
|
|
44
|
+
);
|
|
37
45
|
|
|
38
46
|
const policyObj = tx.object(policyId);
|
|
39
47
|
|
|
40
|
-
const { results } = await kioskClient.client.devInspectTransactionBlock({
|
|
41
|
-
sender: tx.getData().sender || normalizeHaneulAddress('0x0'),
|
|
42
|
-
transactionBlock: feeTx,
|
|
43
|
-
});
|
|
44
|
-
|
|
45
48
|
let amount: TransactionArgument | bigint | null = null;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
feeTx.setSender(tx.getData().sender || normalizeHaneulAddress('0x0'));
|
|
52
|
+
const txBytes = await feeTx.build({ client: kioskClient.client });
|
|
53
|
+
|
|
54
|
+
const result = await kioskClient.client.core.simulateTransaction({
|
|
55
|
+
transaction: txBytes,
|
|
56
|
+
include: { commandResults: true },
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
if (result.commandResults && result.commandResults.length > 0) {
|
|
60
|
+
const returnedAmount = result.commandResults[0]?.returnValues?.[0]?.bcs;
|
|
61
|
+
if (returnedAmount) {
|
|
62
|
+
amount = BigInt(bcs.U64.parse(returnedAmount));
|
|
63
|
+
}
|
|
50
64
|
}
|
|
65
|
+
} catch {
|
|
66
|
+
// If simulate fails, fall back to resolving within the PTB
|
|
51
67
|
}
|
|
52
68
|
|
|
53
69
|
// We were not able to calculate the amount outside of the transaction, so fall back to resolving it within the PTB
|
|
54
70
|
if (!amount) {
|
|
55
|
-
[amount] = tx.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
71
|
+
[amount] = tx.add(
|
|
72
|
+
royaltyRule.feeAmount({
|
|
73
|
+
package: packageId,
|
|
74
|
+
arguments: {
|
|
75
|
+
policy: policyObj,
|
|
76
|
+
paid: BigInt(price || '0'),
|
|
77
|
+
},
|
|
78
|
+
typeArguments: [itemType],
|
|
79
|
+
}),
|
|
80
|
+
);
|
|
60
81
|
}
|
|
61
82
|
|
|
62
83
|
// splits the coin.
|
|
63
84
|
const feeCoin = tx.splitCoins(tx.gas, [amount]);
|
|
64
85
|
|
|
65
86
|
// pays the policy
|
|
66
|
-
tx.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
87
|
+
tx.add(
|
|
88
|
+
royaltyRule.pay({
|
|
89
|
+
package: packageId,
|
|
90
|
+
arguments: {
|
|
91
|
+
policy: policyObj,
|
|
92
|
+
request: transferRequest,
|
|
93
|
+
payment: feeCoin,
|
|
94
|
+
},
|
|
95
|
+
typeArguments: [itemType],
|
|
96
|
+
}),
|
|
97
|
+
);
|
|
71
98
|
}
|
|
72
99
|
|
|
73
100
|
export function resolveKioskLockRule(params: RuleResolvingParams) {
|
|
@@ -75,23 +102,33 @@ export function resolveKioskLockRule(params: RuleResolvingParams) {
|
|
|
75
102
|
transaction: tx,
|
|
76
103
|
packageId,
|
|
77
104
|
itemType,
|
|
78
|
-
kiosk,
|
|
105
|
+
kiosk: kioskId,
|
|
79
106
|
kioskCap,
|
|
80
107
|
policyId,
|
|
81
108
|
purchasedItem,
|
|
82
109
|
transferRequest,
|
|
83
110
|
} = params;
|
|
84
111
|
|
|
85
|
-
if (!
|
|
112
|
+
if (!kioskId || !kioskCap) throw new Error('Missing Owned Kiosk or Owned Kiosk Cap');
|
|
86
113
|
|
|
87
|
-
|
|
114
|
+
tx.add(
|
|
115
|
+
kiosk.lock({
|
|
116
|
+
arguments: [kioskId, kioskCap, policyId, purchasedItem],
|
|
117
|
+
typeArguments: [itemType],
|
|
118
|
+
}),
|
|
119
|
+
);
|
|
88
120
|
|
|
89
121
|
// proves that the item is locked in the kiosk to the TP.
|
|
90
|
-
tx.
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
122
|
+
tx.add(
|
|
123
|
+
kioskLockRule.prove({
|
|
124
|
+
package: packageId,
|
|
125
|
+
arguments: {
|
|
126
|
+
request: transferRequest,
|
|
127
|
+
kiosk: tx.object(kioskId),
|
|
128
|
+
},
|
|
129
|
+
typeArguments: [itemType],
|
|
130
|
+
}),
|
|
131
|
+
);
|
|
95
132
|
}
|
|
96
133
|
|
|
97
134
|
/**
|
|
@@ -104,23 +141,35 @@ export function resolvePersonalKioskRule(params: RuleResolvingParams) {
|
|
|
104
141
|
if (!kiosk) throw new Error('Missing owned Kiosk.');
|
|
105
142
|
|
|
106
143
|
// proves that the destination kiosk is personal.
|
|
107
|
-
tx.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
144
|
+
tx.add(
|
|
145
|
+
personalKioskRule.prove({
|
|
146
|
+
package: packageId,
|
|
147
|
+
arguments: {
|
|
148
|
+
kiosk: tx.object(kiosk),
|
|
149
|
+
request: transferRequest,
|
|
150
|
+
},
|
|
151
|
+
typeArguments: [itemType],
|
|
152
|
+
}),
|
|
153
|
+
);
|
|
112
154
|
}
|
|
113
155
|
|
|
114
156
|
/**
|
|
115
|
-
*
|
|
157
|
+
* A helper to resolve the floor price rule.
|
|
158
|
+
* The floor price rule verifies that the paid amount meets the minimum price.
|
|
159
|
+
* @param params
|
|
116
160
|
*/
|
|
117
161
|
export function resolveFloorPriceRule(params: RuleResolvingParams) {
|
|
118
162
|
const { transaction: tx, packageId, itemType, policyId, transferRequest } = params;
|
|
119
163
|
|
|
120
|
-
// proves that the
|
|
121
|
-
tx.
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
164
|
+
// proves that the paid amount meets the floor price requirement
|
|
165
|
+
tx.add(
|
|
166
|
+
floorPriceRule.prove({
|
|
167
|
+
package: packageId,
|
|
168
|
+
arguments: {
|
|
169
|
+
policy: tx.object(policyId),
|
|
170
|
+
request: transferRequest,
|
|
171
|
+
},
|
|
172
|
+
typeArguments: [itemType],
|
|
173
|
+
}),
|
|
174
|
+
);
|
|
126
175
|
}
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import type {
|
|
6
|
-
Transaction,
|
|
7
|
-
TransactionArgument,
|
|
8
|
-
TransactionObjectArgument,
|
|
9
|
-
} from '@haneullabs/haneul/transactions';
|
|
4
|
+
import type { Transaction, TransactionObjectArgument } from '@haneullabs/haneul/transactions';
|
|
10
5
|
|
|
11
6
|
import type { ObjectArgument } from '../types/index.js';
|
|
12
|
-
import
|
|
7
|
+
import * as transferPolicy from '../contracts/0x2/transfer_policy.js';
|
|
13
8
|
|
|
14
9
|
/**
|
|
15
10
|
* Call the `transfer_policy::new` function to create a new transfer policy.
|
|
@@ -20,47 +15,20 @@ export function createTransferPolicy(
|
|
|
20
15
|
itemType: string,
|
|
21
16
|
publisher: ObjectArgument,
|
|
22
17
|
): TransactionObjectArgument {
|
|
23
|
-
const [
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
const [policy, policyCap] = tx.add(
|
|
19
|
+
transferPolicy._new({
|
|
20
|
+
arguments: [publisher],
|
|
21
|
+
typeArguments: [itemType],
|
|
22
|
+
}),
|
|
27
23
|
);
|
|
28
24
|
|
|
29
|
-
shareTransferPolicy(tx, itemType, transferPolicy);
|
|
30
|
-
|
|
31
|
-
return transferPolicyCap;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Creates a transfer Policy and returns both the Policy and the Cap.
|
|
36
|
-
* Used if we want to use the policy before making it a shared object.
|
|
37
|
-
*/
|
|
38
|
-
export function createTransferPolicyWithoutSharing(
|
|
39
|
-
tx: Transaction,
|
|
40
|
-
itemType: string,
|
|
41
|
-
publisher: ObjectArgument,
|
|
42
|
-
): [TransactionObjectArgument, TransactionObjectArgument] {
|
|
43
|
-
const [transferPolicy, transferPolicyCap] = tx.moveCall({
|
|
44
|
-
target: `${TRANSFER_POLICY_MODULE}::new`,
|
|
45
|
-
typeArguments: [itemType],
|
|
46
|
-
arguments: [tx.object(publisher)],
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
return [transferPolicy, transferPolicyCap];
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Converts Transfer Policy to a shared object.
|
|
53
|
-
*/
|
|
54
|
-
export function shareTransferPolicy(
|
|
55
|
-
tx: Transaction,
|
|
56
|
-
itemType: string,
|
|
57
|
-
transferPolicy: TransactionObjectArgument,
|
|
58
|
-
) {
|
|
59
25
|
tx.moveCall({
|
|
60
|
-
target:
|
|
61
|
-
|
|
62
|
-
|
|
26
|
+
target: '0x2::transfer::public_share_object',
|
|
27
|
+
arguments: [policy],
|
|
28
|
+
typeArguments: [`0x2::transfer_policy::TransferPolicy<${itemType}>`],
|
|
63
29
|
});
|
|
30
|
+
|
|
31
|
+
return policyCap;
|
|
64
32
|
}
|
|
65
33
|
|
|
66
34
|
/**
|
|
@@ -73,48 +41,19 @@ export function withdrawFromPolicy(
|
|
|
73
41
|
policyCap: ObjectArgument,
|
|
74
42
|
amount?: string | bigint | null,
|
|
75
43
|
): TransactionObjectArgument {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
44
|
+
// Convert string to bigint if needed for the generated function
|
|
45
|
+
const amountArg: bigint | null = amount
|
|
46
|
+
? typeof amount === 'string'
|
|
47
|
+
? BigInt(amount)
|
|
48
|
+
: amount
|
|
49
|
+
: null;
|
|
50
|
+
|
|
51
|
+
const [profits] = tx.add(
|
|
52
|
+
transferPolicy.withdraw({
|
|
53
|
+
arguments: [policy, policyCap, amountArg],
|
|
54
|
+
typeArguments: [itemType],
|
|
55
|
+
}),
|
|
56
|
+
);
|
|
83
57
|
|
|
84
58
|
return profits;
|
|
85
59
|
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Call the `transfer_policy::confirm_request` function to unblock the
|
|
89
|
-
* transaction.
|
|
90
|
-
*/
|
|
91
|
-
export function confirmRequest(
|
|
92
|
-
tx: Transaction,
|
|
93
|
-
itemType: string,
|
|
94
|
-
policy: ObjectArgument,
|
|
95
|
-
request: TransactionArgument,
|
|
96
|
-
): void {
|
|
97
|
-
tx.moveCall({
|
|
98
|
-
target: `${TRANSFER_POLICY_MODULE}::confirm_request`,
|
|
99
|
-
typeArguments: [itemType],
|
|
100
|
-
arguments: [tx.object(policy), request],
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Calls the `transfer_policy::remove_rule` function to remove a Rule from the transfer policy's ruleset.
|
|
106
|
-
*/
|
|
107
|
-
export function removeTransferPolicyRule(
|
|
108
|
-
tx: Transaction,
|
|
109
|
-
itemType: string,
|
|
110
|
-
ruleType: string,
|
|
111
|
-
configType: string,
|
|
112
|
-
policy: ObjectArgument,
|
|
113
|
-
policyCap: ObjectArgument,
|
|
114
|
-
): void {
|
|
115
|
-
tx.moveCall({
|
|
116
|
-
target: `${TRANSFER_POLICY_MODULE}::remove_rule`,
|
|
117
|
-
typeArguments: [itemType, ruleType, configType],
|
|
118
|
-
arguments: [tx.object(policy), tx.object(policyCap)],
|
|
119
|
-
});
|
|
120
|
-
}
|
package/src/types/index.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type { HaneulClientTypes } from '@haneullabs/haneul/client';
|
|
5
5
|
import type { TransactionObjectArgument } from '@haneullabs/haneul/transactions';
|
|
6
6
|
|
|
7
7
|
import type { BaseRulePackageIds } from '../constants.js';
|
|
8
|
+
import { HaneulJsonRpcClient } from '@haneullabs/haneul/jsonRpc';
|
|
9
|
+
import { HaneulGraphQLClient } from '@haneullabs/haneul/graphql';
|
|
8
10
|
|
|
9
11
|
export * from './kiosk.js';
|
|
10
12
|
export * from './transfer-policy.js';
|
|
@@ -14,22 +16,13 @@ export * from './transfer-policy.js';
|
|
|
14
16
|
*/
|
|
15
17
|
export type ObjectArgument = string | TransactionObjectArgument;
|
|
16
18
|
|
|
17
|
-
/**
|
|
18
|
-
* A Network selector.
|
|
19
|
-
* Kiosk SDK supports mainnet & testnet.
|
|
20
|
-
* Pass `custom` for any other network (devnet, localnet).
|
|
21
|
-
*/
|
|
22
|
-
export enum Network {
|
|
23
|
-
MAINNET = 'mainnet',
|
|
24
|
-
TESTNET = 'testnet',
|
|
25
|
-
CUSTOM = 'custom',
|
|
26
|
-
}
|
|
27
|
-
|
|
28
19
|
/**
|
|
29
20
|
* The Client Options for Both KioskClient & TransferPolicyManager.
|
|
30
21
|
*/
|
|
31
22
|
export type KioskClientOptions = {
|
|
32
|
-
client:
|
|
33
|
-
network: Network;
|
|
23
|
+
client: KioskCompatibleClient;
|
|
24
|
+
network: HaneulClientTypes.Network;
|
|
34
25
|
packageIds?: BaseRulePackageIds;
|
|
35
26
|
};
|
|
27
|
+
|
|
28
|
+
export type KioskCompatibleClient = HaneulJsonRpcClient | HaneulGraphQLClient;
|
package/src/types/kiosk.ts
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import type {
|
|
5
|
-
PaginatedObjectsResponse,
|
|
6
|
-
HaneulObjectData,
|
|
7
|
-
HaneulObjectDataOptions,
|
|
8
|
-
} from '@haneullabs/haneul/client';
|
|
9
4
|
import type { TransactionArgument } from '@haneullabs/haneul/transactions';
|
|
10
5
|
|
|
11
6
|
import type { ObjectArgument } from './index.js';
|
|
12
7
|
|
|
8
|
+
import { HANEUL_FRAMEWORK_ADDRESS } from '@haneullabs/haneul/utils';
|
|
9
|
+
import { HaneulClientTypes } from '@haneullabs/haneul/client';
|
|
10
|
+
|
|
13
11
|
/** The Kiosk module. */
|
|
14
|
-
export const KIOSK_MODULE =
|
|
12
|
+
export const KIOSK_MODULE = `${HANEUL_FRAMEWORK_ADDRESS}::kiosk`;
|
|
15
13
|
|
|
16
14
|
/** The Kiosk type. */
|
|
17
15
|
export const KIOSK_TYPE = `${KIOSK_MODULE}::Kiosk`;
|
|
@@ -90,6 +88,18 @@ export type KioskListing = {
|
|
|
90
88
|
price?: string;
|
|
91
89
|
};
|
|
92
90
|
|
|
91
|
+
export type KioskDisplay = {
|
|
92
|
+
data: Record<string, string> | null;
|
|
93
|
+
error: string | null;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export type ObjectWithDisplay = HaneulClientTypes.Object<{
|
|
97
|
+
content: true;
|
|
98
|
+
previousTransaction: true;
|
|
99
|
+
}> & {
|
|
100
|
+
display?: KioskDisplay;
|
|
101
|
+
};
|
|
102
|
+
|
|
93
103
|
/**
|
|
94
104
|
* A dynamic field `Item { ID }` attached to the Kiosk.
|
|
95
105
|
* Holds an Item `T`. The type of the item is known upfront.
|
|
@@ -105,8 +115,8 @@ export type KioskItem = {
|
|
|
105
115
|
listing?: KioskListing;
|
|
106
116
|
/** The ID of the kiosk the item is placed in */
|
|
107
117
|
kioskId: string;
|
|
108
|
-
/** Optional
|
|
109
|
-
data?:
|
|
118
|
+
/** Optional object data with display metadata */
|
|
119
|
+
data?: ObjectWithDisplay;
|
|
110
120
|
};
|
|
111
121
|
|
|
112
122
|
/** The overview type returned from `getKiosk` */
|
|
@@ -149,16 +159,16 @@ export type FetchKioskOptions = {
|
|
|
149
159
|
withKioskFields?: boolean;
|
|
150
160
|
/** Include the listing prices. */
|
|
151
161
|
withListingPrices?: boolean;
|
|
152
|
-
/** Include the objects for the Items in the kiosk.
|
|
162
|
+
/** Include the objects for the Items in the kiosk. */
|
|
153
163
|
withObjects?: boolean;
|
|
154
|
-
/** Pass the data options for the objects, when fetching, in case you want to query other details. */
|
|
155
|
-
objectOptions?: HaneulObjectDataOptions;
|
|
156
164
|
};
|
|
157
165
|
|
|
158
166
|
export type OwnedKiosks = {
|
|
159
167
|
kioskOwnerCaps: KioskOwnerCap[];
|
|
160
168
|
kioskIds: string[];
|
|
161
|
-
|
|
169
|
+
nextCursor: string | null;
|
|
170
|
+
hasNextPage: boolean;
|
|
171
|
+
};
|
|
162
172
|
|
|
163
173
|
export type KioskOwnerCap = {
|
|
164
174
|
isPersonal?: boolean;
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import type { ObjectOwner } from '@haneullabs/haneul/
|
|
4
|
+
import type { ObjectOwner } from '@haneullabs/haneul/jsonRpc';
|
|
5
5
|
import type { Transaction, TransactionObjectArgument } from '@haneullabs/haneul/transactions';
|
|
6
6
|
|
|
7
7
|
import type { KioskClient } from '../client/kiosk-client.js';
|
|
8
8
|
import type { ObjectArgument } from './index.js';
|
|
9
9
|
|
|
10
|
+
import { HANEUL_FRAMEWORK_ADDRESS } from '@haneullabs/haneul/utils';
|
|
11
|
+
|
|
10
12
|
/** The Transfer Policy module. */
|
|
11
|
-
export const TRANSFER_POLICY_MODULE =
|
|
13
|
+
export const TRANSFER_POLICY_MODULE = `${HANEUL_FRAMEWORK_ADDRESS}::transfer_policy`;
|
|
12
14
|
|
|
13
15
|
/** Name of the event emitted when a TransferPolicy for T is created. */
|
|
14
16
|
export const TRANSFER_POLICY_CREATED_EVENT = `${TRANSFER_POLICY_MODULE}::TransferPolicyCreated`;
|
|
@@ -54,8 +56,6 @@ export type TransferPolicyCreated = {
|
|
|
54
56
|
// e.g. `if(!'my_key' in ruleParams!) throw new Error("Can't resolve that rule!")`
|
|
55
57
|
export type RuleResolvingParams = {
|
|
56
58
|
transaction: Transaction;
|
|
57
|
-
/** @deprecated use transaction instead */
|
|
58
|
-
transactionBlock: Transaction;
|
|
59
59
|
itemType: string;
|
|
60
60
|
itemId: string;
|
|
61
61
|
price: string;
|