@haneullabs/kiosk 0.1.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 +1070 -0
- package/README.md +8 -0
- package/dist/cjs/bcs.d.ts +23 -0
- package/dist/cjs/bcs.js +50 -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 +123 -0
- package/dist/cjs/client/kiosk-client.js.map +7 -0
- package/dist/cjs/client/kiosk-transaction.d.ts +186 -0
- package/dist/cjs/client/kiosk-transaction.js +462 -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 +307 -0
- package/dist/cjs/client/tp-transaction.js.map +7 -0
- package/dist/cjs/constants.d.ts +31 -0
- package/dist/cjs/constants.js +102 -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 +8 -0
- package/dist/cjs/query/kiosk.js +181 -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 +92 -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 +109 -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 +27 -0
- package/dist/cjs/types/index.js +33 -0
- package/dist/cjs/types/index.js.map +7 -0
- package/dist/cjs/types/kiosk.d.ts +160 -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 +53 -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 +198 -0
- package/dist/cjs/utils.js.map +7 -0
- package/dist/esm/bcs.d.ts +23 -0
- package/dist/esm/bcs.js +35 -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 +114 -0
- package/dist/esm/client/kiosk-client.js.map +7 -0
- package/dist/esm/client/kiosk-transaction.d.ts +186 -0
- package/dist/esm/client/kiosk-transaction.js +432 -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 +298 -0
- package/dist/esm/client/tp-transaction.js.map +7 -0
- package/dist/esm/constants.d.ts +31 -0
- package/dist/esm/constants.js +87 -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 +8 -0
- package/dist/esm/query/kiosk.js +169 -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 +76 -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 +89 -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 +27 -0
- package/dist/esm/types/index.js +12 -0
- package/dist/esm/types/index.js.map +7 -0
- package/dist/esm/types/kiosk.d.ts +160 -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 +53 -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 +183 -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 +59 -0
- package/src/bcs.ts +39 -0
- package/src/client/kiosk-client.ts +163 -0
- package/src/client/kiosk-transaction.ts +526 -0
- package/src/client/tp-transaction.ts +357 -0
- package/src/constants.ts +121 -0
- package/src/index.ts +9 -0
- package/src/query/kiosk.ts +264 -0
- package/src/query/transfer-policy.ts +134 -0
- package/src/tx/kiosk.ts +243 -0
- package/src/tx/personal-kiosk.ts +34 -0
- package/src/tx/rules/attach.ts +73 -0
- package/src/tx/rules/resolve.ts +126 -0
- package/src/tx/transfer-policy.ts +120 -0
- package/src/types/index.ts +35 -0
- package/src/types/kiosk.ts +178 -0
- package/src/types/transfer-policy.ts +71 -0
- package/src/utils.ts +286 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { Transaction } from '@haneullabs/haneul/transactions';
|
|
5
|
+
|
|
6
|
+
import type { ObjectArgument } from '../../types/index.js';
|
|
7
|
+
|
|
8
|
+
export function attachKioskLockRuleTx(
|
|
9
|
+
tx: Transaction,
|
|
10
|
+
type: string,
|
|
11
|
+
policy: ObjectArgument,
|
|
12
|
+
policyCap: ObjectArgument,
|
|
13
|
+
packageId: string,
|
|
14
|
+
) {
|
|
15
|
+
tx.moveCall({
|
|
16
|
+
target: `${packageId}::kiosk_lock_rule::add`,
|
|
17
|
+
typeArguments: [type],
|
|
18
|
+
arguments: [tx.object(policy), tx.object(policyCap)],
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function attachRoyaltyRuleTx(
|
|
23
|
+
tx: Transaction,
|
|
24
|
+
type: string,
|
|
25
|
+
policy: ObjectArgument,
|
|
26
|
+
policyCap: ObjectArgument,
|
|
27
|
+
percentageBps: number | string, // this is in basis points.
|
|
28
|
+
minAmount: number | string,
|
|
29
|
+
packageId: string,
|
|
30
|
+
) {
|
|
31
|
+
if (Number(percentageBps) < 0 || Number(percentageBps) > 10_000)
|
|
32
|
+
throw new Error('Invalid basis point percentage. Use a value between [0,10000].');
|
|
33
|
+
|
|
34
|
+
tx.moveCall({
|
|
35
|
+
target: `${packageId}::royalty_rule::add`,
|
|
36
|
+
typeArguments: [type],
|
|
37
|
+
arguments: [
|
|
38
|
+
tx.object(policy),
|
|
39
|
+
tx.object(policyCap),
|
|
40
|
+
tx.pure.u16(Number(percentageBps)),
|
|
41
|
+
tx.pure.u64(minAmount),
|
|
42
|
+
],
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function attachPersonalKioskRuleTx(
|
|
47
|
+
tx: Transaction,
|
|
48
|
+
type: string,
|
|
49
|
+
policy: ObjectArgument,
|
|
50
|
+
policyCap: ObjectArgument,
|
|
51
|
+
packageId: string,
|
|
52
|
+
) {
|
|
53
|
+
tx.moveCall({
|
|
54
|
+
target: `${packageId}::personal_kiosk_rule::add`,
|
|
55
|
+
typeArguments: [type],
|
|
56
|
+
arguments: [tx.object(policy), tx.object(policyCap)],
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function attachFloorPriceRuleTx(
|
|
61
|
+
tx: Transaction,
|
|
62
|
+
type: string,
|
|
63
|
+
policy: ObjectArgument,
|
|
64
|
+
policyCap: ObjectArgument,
|
|
65
|
+
minPrice: string | bigint,
|
|
66
|
+
packageId: string,
|
|
67
|
+
) {
|
|
68
|
+
tx.moveCall({
|
|
69
|
+
target: `${packageId}::floor_price_rule::add`,
|
|
70
|
+
typeArguments: [type],
|
|
71
|
+
arguments: [tx.object(policy), tx.object(policyCap), tx.pure.u64(minPrice)],
|
|
72
|
+
});
|
|
73
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { bcs } from '@haneullabs/haneul/bcs';
|
|
5
|
+
import type { TransactionArgument } from '@haneullabs/haneul/transactions';
|
|
6
|
+
import { Transaction } from '@haneullabs/haneul/transactions';
|
|
7
|
+
import { normalizeHaneulAddress } from '@haneullabs/haneul/utils';
|
|
8
|
+
|
|
9
|
+
import type { RuleResolvingParams } from '../../types/index.js';
|
|
10
|
+
import { lock } from '../kiosk.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A helper to resolve the royalty rule.
|
|
14
|
+
*/
|
|
15
|
+
export async function resolveRoyaltyRule(params: RuleResolvingParams) {
|
|
16
|
+
const {
|
|
17
|
+
kioskClient,
|
|
18
|
+
transaction: tx,
|
|
19
|
+
itemType,
|
|
20
|
+
price,
|
|
21
|
+
packageId,
|
|
22
|
+
transferRequest,
|
|
23
|
+
policyId,
|
|
24
|
+
} = params;
|
|
25
|
+
|
|
26
|
+
// We attempt to resolve the fee amount outside of the PTB so that the split amount is known before the transaction is sent.
|
|
27
|
+
// This improves the display of the transaction within the wallet.
|
|
28
|
+
|
|
29
|
+
const feeTx = new Transaction();
|
|
30
|
+
|
|
31
|
+
// calculates the amount
|
|
32
|
+
feeTx.moveCall({
|
|
33
|
+
target: `${packageId}::royalty_rule::fee_amount`,
|
|
34
|
+
typeArguments: [itemType],
|
|
35
|
+
arguments: [feeTx.object(policyId), feeTx.pure.u64(price || '0')],
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const policyObj = tx.object(policyId);
|
|
39
|
+
|
|
40
|
+
const { results } = await kioskClient.client.devInspectTransactionBlock({
|
|
41
|
+
sender: tx.getData().sender || normalizeHaneulAddress('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
|
+
|
|
62
|
+
// splits the coin.
|
|
63
|
+
const feeCoin = tx.splitCoins(tx.gas, [amount]);
|
|
64
|
+
|
|
65
|
+
// pays the policy
|
|
66
|
+
tx.moveCall({
|
|
67
|
+
target: `${packageId}::royalty_rule::pay`,
|
|
68
|
+
typeArguments: [itemType],
|
|
69
|
+
arguments: [policyObj, transferRequest, feeCoin],
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function resolveKioskLockRule(params: RuleResolvingParams) {
|
|
74
|
+
const {
|
|
75
|
+
transaction: tx,
|
|
76
|
+
packageId,
|
|
77
|
+
itemType,
|
|
78
|
+
kiosk,
|
|
79
|
+
kioskCap,
|
|
80
|
+
policyId,
|
|
81
|
+
purchasedItem,
|
|
82
|
+
transferRequest,
|
|
83
|
+
} = params;
|
|
84
|
+
|
|
85
|
+
if (!kiosk || !kioskCap) throw new Error('Missing Owned Kiosk or Owned Kiosk Cap');
|
|
86
|
+
|
|
87
|
+
lock(tx, itemType, kiosk, kioskCap, policyId, purchasedItem);
|
|
88
|
+
|
|
89
|
+
// proves that the item is locked in the kiosk to the TP.
|
|
90
|
+
tx.moveCall({
|
|
91
|
+
target: `${packageId}::kiosk_lock_rule::prove`,
|
|
92
|
+
typeArguments: [itemType],
|
|
93
|
+
arguments: [transferRequest, tx.object(kiosk)],
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* A helper to resolve the personalKioskRule.
|
|
99
|
+
* @param params
|
|
100
|
+
*/
|
|
101
|
+
export function resolvePersonalKioskRule(params: RuleResolvingParams) {
|
|
102
|
+
const { transaction: tx, packageId, itemType, kiosk, transferRequest } = params;
|
|
103
|
+
|
|
104
|
+
if (!kiosk) throw new Error('Missing owned Kiosk.');
|
|
105
|
+
|
|
106
|
+
// proves that the destination kiosk is personal.
|
|
107
|
+
tx.moveCall({
|
|
108
|
+
target: `${packageId}::personal_kiosk_rule::prove`,
|
|
109
|
+
typeArguments: [itemType],
|
|
110
|
+
arguments: [tx.object(kiosk), transferRequest],
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Resolves the floor price rule.
|
|
116
|
+
*/
|
|
117
|
+
export function resolveFloorPriceRule(params: RuleResolvingParams) {
|
|
118
|
+
const { transaction: tx, packageId, itemType, policyId, transferRequest } = params;
|
|
119
|
+
|
|
120
|
+
// proves that the destination kiosk is personal
|
|
121
|
+
tx.moveCall({
|
|
122
|
+
target: `${packageId}::floor_price_rule::prove`,
|
|
123
|
+
typeArguments: [itemType],
|
|
124
|
+
arguments: [tx.object(policyId), transferRequest],
|
|
125
|
+
});
|
|
126
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { bcs } from '@haneullabs/haneul/bcs';
|
|
5
|
+
import type {
|
|
6
|
+
Transaction,
|
|
7
|
+
TransactionArgument,
|
|
8
|
+
TransactionObjectArgument,
|
|
9
|
+
} from '@haneullabs/haneul/transactions';
|
|
10
|
+
|
|
11
|
+
import type { ObjectArgument } from '../types/index.js';
|
|
12
|
+
import { TRANSFER_POLICY_MODULE, TRANSFER_POLICY_TYPE } from '../types/index.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Call the `transfer_policy::new` function to create a new transfer policy.
|
|
16
|
+
* Returns `transferPolicyCap`
|
|
17
|
+
*/
|
|
18
|
+
export function createTransferPolicy(
|
|
19
|
+
tx: Transaction,
|
|
20
|
+
itemType: string,
|
|
21
|
+
publisher: ObjectArgument,
|
|
22
|
+
): TransactionObjectArgument {
|
|
23
|
+
const [transferPolicy, transferPolicyCap] = createTransferPolicyWithoutSharing(
|
|
24
|
+
tx,
|
|
25
|
+
itemType,
|
|
26
|
+
publisher,
|
|
27
|
+
);
|
|
28
|
+
|
|
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
|
+
tx.moveCall({
|
|
60
|
+
target: `0x2::transfer::public_share_object`,
|
|
61
|
+
typeArguments: [`${TRANSFER_POLICY_TYPE}<${itemType}>`],
|
|
62
|
+
arguments: [transferPolicy],
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Call the `transfer_policy::withdraw` function to withdraw profits from a transfer policy.
|
|
68
|
+
*/
|
|
69
|
+
export function withdrawFromPolicy(
|
|
70
|
+
tx: Transaction,
|
|
71
|
+
itemType: string,
|
|
72
|
+
policy: ObjectArgument,
|
|
73
|
+
policyCap: ObjectArgument,
|
|
74
|
+
amount?: string | bigint | null,
|
|
75
|
+
): TransactionObjectArgument {
|
|
76
|
+
const amountArg = bcs.option(bcs.u64()).serialize(amount);
|
|
77
|
+
|
|
78
|
+
const [profits] = tx.moveCall({
|
|
79
|
+
target: `${TRANSFER_POLICY_MODULE}::withdraw`,
|
|
80
|
+
typeArguments: [itemType],
|
|
81
|
+
arguments: [tx.object(policy), tx.object(policyCap), amountArg],
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
return profits;
|
|
85
|
+
}
|
|
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
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { HaneulClient } from '@haneullabs/haneul/client';
|
|
5
|
+
import type { TransactionObjectArgument } from '@haneullabs/haneul/transactions';
|
|
6
|
+
|
|
7
|
+
import type { BaseRulePackageIds } from '../constants.js';
|
|
8
|
+
|
|
9
|
+
export * from './kiosk.js';
|
|
10
|
+
export * from './transfer-policy.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A valid argument for any of the Kiosk functions.
|
|
14
|
+
*/
|
|
15
|
+
export type ObjectArgument = string | TransactionObjectArgument;
|
|
16
|
+
|
|
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
|
+
/**
|
|
29
|
+
* The Client Options for Both KioskClient & TransferPolicyManager.
|
|
30
|
+
*/
|
|
31
|
+
export type KioskClientOptions = {
|
|
32
|
+
client: HaneulClient;
|
|
33
|
+
network: Network;
|
|
34
|
+
packageIds?: BaseRulePackageIds;
|
|
35
|
+
};
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
PaginatedObjectsResponse,
|
|
6
|
+
HaneulObjectData,
|
|
7
|
+
HaneulObjectDataOptions,
|
|
8
|
+
} from '@haneullabs/haneul/client';
|
|
9
|
+
import type { TransactionArgument } from '@haneullabs/haneul/transactions';
|
|
10
|
+
|
|
11
|
+
import type { ObjectArgument } from './index.js';
|
|
12
|
+
|
|
13
|
+
/** The Kiosk module. */
|
|
14
|
+
export const KIOSK_MODULE = '0x2::kiosk';
|
|
15
|
+
|
|
16
|
+
/** The Kiosk type. */
|
|
17
|
+
export const KIOSK_TYPE = `${KIOSK_MODULE}::Kiosk`;
|
|
18
|
+
|
|
19
|
+
/** The Kiosk Owner Cap Type */
|
|
20
|
+
export const KIOSK_OWNER_CAP = `${KIOSK_MODULE}::KioskOwnerCap`;
|
|
21
|
+
|
|
22
|
+
/** The Kiosk Item Type */
|
|
23
|
+
export const KIOSK_ITEM = `${KIOSK_MODULE}::Item`;
|
|
24
|
+
|
|
25
|
+
/** The Kiosk Listing Type */
|
|
26
|
+
export const KIOSK_LISTING = `${KIOSK_MODULE}::Listing`;
|
|
27
|
+
|
|
28
|
+
/** The Kiosk Lock Type */
|
|
29
|
+
export const KIOSK_LOCK = `${KIOSK_MODULE}::Lock`;
|
|
30
|
+
|
|
31
|
+
/** The Kiosk PurchaseCap type */
|
|
32
|
+
export const KIOSK_PURCHASE_CAP = `${KIOSK_MODULE}::PurchaseCap`;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The Kiosk object fields (for BCS queries).
|
|
36
|
+
*/
|
|
37
|
+
export type Kiosk = {
|
|
38
|
+
id: string;
|
|
39
|
+
profits: string;
|
|
40
|
+
owner: string;
|
|
41
|
+
itemCount: number;
|
|
42
|
+
allowExtensions: boolean;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* PurchaseCap object fields (for BCS queries).
|
|
47
|
+
*/
|
|
48
|
+
export type PurchaseCap = {
|
|
49
|
+
id: string;
|
|
50
|
+
kioskId: string;
|
|
51
|
+
itemId: string;
|
|
52
|
+
minPrice: string;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The response type of a successful purchase flow.
|
|
57
|
+
* Returns the item, and a `canTransfer` param.
|
|
58
|
+
*/
|
|
59
|
+
export type PurchaseAndResolvePoliciesResponse = {
|
|
60
|
+
item: TransactionArgument;
|
|
61
|
+
canTransfer: boolean;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Optional parameters for `purchaseAndResolvePolicies` flow.
|
|
66
|
+
* This gives us the chance to extend the function in further releases
|
|
67
|
+
* without introducing more breaking changes.
|
|
68
|
+
*/
|
|
69
|
+
export type PurchaseOptionalParams = {
|
|
70
|
+
ownedKiosk?: ObjectArgument;
|
|
71
|
+
ownedKioskCap?: ObjectArgument;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* A dynamic field `Listing { ID, isExclusive }` attached to the Kiosk.
|
|
76
|
+
* Holds a `u64` value - the price of the item.
|
|
77
|
+
*/
|
|
78
|
+
export type KioskListing = {
|
|
79
|
+
/** The ID of the Item */
|
|
80
|
+
objectId: string;
|
|
81
|
+
/**
|
|
82
|
+
* Whether or not there's a `PurchaseCap` issued. `true` means that
|
|
83
|
+
* the listing is controlled by some logic and can't be purchased directly.
|
|
84
|
+
*
|
|
85
|
+
* TODO: consider renaming the field for better indication.
|
|
86
|
+
*/
|
|
87
|
+
isExclusive: boolean;
|
|
88
|
+
/** The ID of the listing */
|
|
89
|
+
listingId: string;
|
|
90
|
+
price?: string;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* A dynamic field `Item { ID }` attached to the Kiosk.
|
|
95
|
+
* Holds an Item `T`. The type of the item is known upfront.
|
|
96
|
+
*/
|
|
97
|
+
export type KioskItem = {
|
|
98
|
+
/** The ID of the Item */
|
|
99
|
+
objectId: string;
|
|
100
|
+
/** The type of the Item */
|
|
101
|
+
type: string;
|
|
102
|
+
/** Whether the item is Locked (there must be a `Lock` Dynamic Field) */
|
|
103
|
+
isLocked: boolean;
|
|
104
|
+
/** Optional listing */
|
|
105
|
+
listing?: KioskListing;
|
|
106
|
+
/** The ID of the kiosk the item is placed in */
|
|
107
|
+
kioskId: string;
|
|
108
|
+
/** Optional Kiosk Data */
|
|
109
|
+
data?: HaneulObjectData;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/** The overview type returned from `getKiosk` */
|
|
113
|
+
export type KioskExtensionOverview = {
|
|
114
|
+
/** The ID of the extension's DF */
|
|
115
|
+
objectId: string;
|
|
116
|
+
/** The inner type of the Extension */
|
|
117
|
+
type: string;
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Hold the KioskExtension data
|
|
121
|
+
*/
|
|
122
|
+
export type KioskExtension = KioskExtensionOverview & {
|
|
123
|
+
/** These fields are only there if we have `withExtensions` flag */
|
|
124
|
+
isEnabled: boolean;
|
|
125
|
+
permissions: string;
|
|
126
|
+
storageId: string;
|
|
127
|
+
storageSize: number;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Aggregated data from the Kiosk.
|
|
132
|
+
*/
|
|
133
|
+
export type KioskData = {
|
|
134
|
+
items: KioskItem[];
|
|
135
|
+
itemIds: string[];
|
|
136
|
+
listingIds: string[];
|
|
137
|
+
kiosk?: Kiosk;
|
|
138
|
+
extensions: KioskExtensionOverview[]; // type will be defined on later versions of the SDK.
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export type PagedKioskData = {
|
|
142
|
+
data: KioskData;
|
|
143
|
+
nextCursor: string | null | undefined;
|
|
144
|
+
hasNextPage: boolean;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
export type FetchKioskOptions = {
|
|
148
|
+
/** Include the base kiosk object, which includes the profits, the owner and the base fields. */
|
|
149
|
+
withKioskFields?: boolean;
|
|
150
|
+
/** Include the listing prices. */
|
|
151
|
+
withListingPrices?: boolean;
|
|
152
|
+
/** Include the objects for the Items in the kiosk. Defaults to `display` only. */
|
|
153
|
+
withObjects?: boolean;
|
|
154
|
+
/** Pass the data options for the objects, when fetching, in case you want to query other details. */
|
|
155
|
+
objectOptions?: HaneulObjectDataOptions;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export type OwnedKiosks = {
|
|
159
|
+
kioskOwnerCaps: KioskOwnerCap[];
|
|
160
|
+
kioskIds: string[];
|
|
161
|
+
} & Omit<PaginatedObjectsResponse, 'data'>;
|
|
162
|
+
|
|
163
|
+
export type KioskOwnerCap = {
|
|
164
|
+
isPersonal?: boolean;
|
|
165
|
+
objectId: string;
|
|
166
|
+
kioskId: string;
|
|
167
|
+
digest: string;
|
|
168
|
+
version: string;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
export type PurchaseOptions = {
|
|
172
|
+
extraArgs?: Record<string, any>;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
export type ItemId = { itemType: string; itemId: string };
|
|
176
|
+
export type ItemReference = { itemType: string; item: ObjectArgument };
|
|
177
|
+
export type ItemValue = { itemType: string; item: TransactionArgument };
|
|
178
|
+
export type Price = { price: string | bigint };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { ObjectOwner } from '@haneullabs/haneul/client';
|
|
5
|
+
import type { Transaction, TransactionObjectArgument } from '@haneullabs/haneul/transactions';
|
|
6
|
+
|
|
7
|
+
import type { KioskClient } from '../client/kiosk-client.js';
|
|
8
|
+
import type { ObjectArgument } from './index.js';
|
|
9
|
+
|
|
10
|
+
/** The Transfer Policy module. */
|
|
11
|
+
export const TRANSFER_POLICY_MODULE = '0x2::transfer_policy';
|
|
12
|
+
|
|
13
|
+
/** Name of the event emitted when a TransferPolicy for T is created. */
|
|
14
|
+
export const TRANSFER_POLICY_CREATED_EVENT = `${TRANSFER_POLICY_MODULE}::TransferPolicyCreated`;
|
|
15
|
+
|
|
16
|
+
/** The Transfer Policy Type */
|
|
17
|
+
export const TRANSFER_POLICY_TYPE = `${TRANSFER_POLICY_MODULE}::TransferPolicy`;
|
|
18
|
+
|
|
19
|
+
/** The Transfer Policy Cap Type */
|
|
20
|
+
export const TRANSFER_POLICY_CAP_TYPE = `${TRANSFER_POLICY_MODULE}::TransferPolicyCap`;
|
|
21
|
+
|
|
22
|
+
/** The Kiosk Lock Rule */
|
|
23
|
+
export const KIOSK_LOCK_RULE = 'kiosk_lock_rule::Rule';
|
|
24
|
+
|
|
25
|
+
/** The Royalty rule */
|
|
26
|
+
export const ROYALTY_RULE = 'royalty_rule::Rule';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The Transfer Policy Cap in a consumable way.
|
|
30
|
+
*/
|
|
31
|
+
export type TransferPolicyCap = {
|
|
32
|
+
policyId: string;
|
|
33
|
+
policyCapId: string;
|
|
34
|
+
type: string;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** The `TransferPolicy` object */
|
|
38
|
+
export type TransferPolicy = {
|
|
39
|
+
id: string;
|
|
40
|
+
type: string;
|
|
41
|
+
balance: string;
|
|
42
|
+
rules: string[];
|
|
43
|
+
owner: ObjectOwner;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/** Event emitted when a TransferPolicy is created. */
|
|
47
|
+
export type TransferPolicyCreated = {
|
|
48
|
+
id: string;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// The object a Rule resolving function accepts
|
|
52
|
+
// It can accept a set of fixed fields, that are part of every purchase flow as well any extra arguments to resolve custom policies!
|
|
53
|
+
// Each rule resolving function should check that the key it's seeking is in the object
|
|
54
|
+
// e.g. `if(!'my_key' in ruleParams!) throw new Error("Can't resolve that rule!")`
|
|
55
|
+
export type RuleResolvingParams = {
|
|
56
|
+
transaction: Transaction;
|
|
57
|
+
/** @deprecated use transaction instead */
|
|
58
|
+
transactionBlock: Transaction;
|
|
59
|
+
itemType: string;
|
|
60
|
+
itemId: string;
|
|
61
|
+
price: string;
|
|
62
|
+
policyId: ObjectArgument;
|
|
63
|
+
sellerKiosk: ObjectArgument;
|
|
64
|
+
kiosk: ObjectArgument;
|
|
65
|
+
kioskCap: ObjectArgument;
|
|
66
|
+
transferRequest: TransactionObjectArgument;
|
|
67
|
+
purchasedItem: TransactionObjectArgument;
|
|
68
|
+
packageId: string;
|
|
69
|
+
extraArgs: Record<string, any>; // extraParams contains more possible {key, values} to pass for custom rules.
|
|
70
|
+
kioskClient: KioskClient;
|
|
71
|
+
};
|