@mysten/kiosk 0.14.6 → 1.0.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.
Files changed (267) hide show
  1. package/CHANGELOG.md +105 -2
  2. package/dist/client/kiosk-client.d.mts +126 -0
  3. package/dist/client/kiosk-client.d.mts.map +1 -0
  4. package/dist/client/kiosk-client.mjs +124 -0
  5. package/dist/client/kiosk-client.mjs.map +1 -0
  6. package/dist/client/kiosk-transaction.d.mts +236 -0
  7. package/dist/client/kiosk-transaction.d.mts.map +1 -0
  8. package/dist/client/kiosk-transaction.mjs +472 -0
  9. package/dist/client/kiosk-transaction.mjs.map +1 -0
  10. package/dist/client/tp-transaction.d.mts +139 -0
  11. package/dist/client/tp-transaction.d.mts.map +1 -0
  12. package/dist/client/tp-transaction.mjs +273 -0
  13. package/dist/client/tp-transaction.mjs.map +1 -0
  14. package/dist/constants.d.mts +42 -0
  15. package/dist/constants.d.mts.map +1 -0
  16. package/dist/constants.mjs +62 -0
  17. package/dist/constants.mjs.map +1 -0
  18. package/dist/contracts/0x2/bag.mjs +19 -0
  19. package/dist/contracts/0x2/bag.mjs.map +1 -0
  20. package/dist/contracts/0x2/balance.mjs +20 -0
  21. package/dist/contracts/0x2/balance.mjs.map +1 -0
  22. package/dist/contracts/0x2/deps/0x0000000000000000000000000000000000000000000000000000000000000001/type_name.mjs +16 -0
  23. package/dist/contracts/0x2/deps/0x0000000000000000000000000000000000000000000000000000000000000001/type_name.mjs.map +1 -0
  24. package/dist/contracts/0x2/kiosk.mjs +244 -0
  25. package/dist/contracts/0x2/kiosk.mjs.map +1 -0
  26. package/dist/contracts/0x2/kiosk_extension.mjs +25 -0
  27. package/dist/contracts/0x2/kiosk_extension.mjs.map +1 -0
  28. package/dist/contracts/0x2/transfer_policy.mjs +99 -0
  29. package/dist/contracts/0x2/transfer_policy.mjs.map +1 -0
  30. package/dist/contracts/0x2/vec_set.mjs +18 -0
  31. package/dist/contracts/0x2/vec_set.mjs.map +1 -0
  32. package/dist/contracts/kiosk/deps/sui/kiosk.mjs +98 -0
  33. package/dist/contracts/kiosk/deps/sui/kiosk.mjs.map +1 -0
  34. package/dist/contracts/kiosk/floor_price_rule.mjs +70 -0
  35. package/dist/contracts/kiosk/floor_price_rule.mjs.map +1 -0
  36. package/dist/contracts/kiosk/kiosk_lock_rule.mjs +72 -0
  37. package/dist/contracts/kiosk/kiosk_lock_rule.mjs.map +1 -0
  38. package/dist/contracts/kiosk/personal_kiosk.mjs +102 -0
  39. package/dist/contracts/kiosk/personal_kiosk.mjs.map +1 -0
  40. package/dist/contracts/kiosk/personal_kiosk_rule.mjs +66 -0
  41. package/dist/contracts/kiosk/personal_kiosk_rule.mjs.map +1 -0
  42. package/dist/contracts/kiosk/royalty_rule.mjs +115 -0
  43. package/dist/contracts/kiosk/royalty_rule.mjs.map +1 -0
  44. package/dist/contracts/utils/index.mjs +118 -0
  45. package/dist/contracts/utils/index.mjs.map +1 -0
  46. package/dist/index.d.mts +9 -0
  47. package/dist/index.mjs +9 -0
  48. package/dist/query/client-utils.mjs +30 -0
  49. package/dist/query/client-utils.mjs.map +1 -0
  50. package/dist/query/kiosk.mjs +154 -0
  51. package/dist/query/kiosk.mjs.map +1 -0
  52. package/dist/query/transfer-policy.mjs +110 -0
  53. package/dist/query/transfer-policy.mjs.map +1 -0
  54. package/dist/tx/kiosk.mjs +20 -0
  55. package/dist/tx/kiosk.mjs.map +1 -0
  56. package/dist/tx/rules/resolve.mjs +114 -0
  57. package/dist/tx/rules/resolve.mjs.map +1 -0
  58. package/dist/tx/transfer-policy.mjs +38 -0
  59. package/dist/tx/transfer-policy.mjs.map +1 -0
  60. package/dist/types/index.d.mts +23 -0
  61. package/dist/types/index.d.mts.map +1 -0
  62. package/dist/types/kiosk.d.mts +165 -0
  63. package/dist/types/kiosk.d.mts.map +1 -0
  64. package/dist/types/kiosk.mjs +21 -0
  65. package/dist/types/kiosk.mjs.map +1 -0
  66. package/dist/types/transfer-policy.d.mts +56 -0
  67. package/dist/types/transfer-policy.d.mts.map +1 -0
  68. package/dist/types/transfer-policy.mjs +19 -0
  69. package/dist/types/transfer-policy.mjs.map +1 -0
  70. package/dist/utils.d.mts +45 -0
  71. package/dist/utils.d.mts.map +1 -0
  72. package/dist/utils.mjs +156 -0
  73. package/dist/utils.mjs.map +1 -0
  74. package/package.json +31 -20
  75. package/src/client/kiosk-client.ts +42 -5
  76. package/src/client/kiosk-transaction.ts +144 -65
  77. package/src/client/tp-transaction.ts +149 -95
  78. package/src/constants.ts +19 -24
  79. package/src/contracts/0x2/accumulator.ts +24 -0
  80. package/src/contracts/0x2/accumulator_metadata.ts +38 -0
  81. package/src/contracts/0x2/accumulator_settlement.ts +14 -0
  82. package/src/contracts/0x2/address.ts +145 -0
  83. package/src/contracts/0x2/address_alias.ts +92 -0
  84. package/src/contracts/0x2/authenticator_state.ts +44 -0
  85. package/src/contracts/0x2/bag.ts +192 -0
  86. package/src/contracts/0x2/balance.ts +269 -0
  87. package/src/contracts/0x2/bcs.ts +495 -0
  88. package/src/contracts/0x2/bls12381.ts +717 -0
  89. package/src/contracts/0x2/borrow.ts +99 -0
  90. package/src/contracts/0x2/clock.ts +30 -0
  91. package/src/contracts/0x2/coin.ts +977 -0
  92. package/src/contracts/0x2/coin_registry.ts +874 -0
  93. package/src/contracts/0x2/config.ts +30 -0
  94. package/src/contracts/0x2/deny_list.ts +55 -0
  95. package/src/contracts/0x2/deps/0x0000000000000000000000000000000000000000000000000000000000000001/type_name.ts +12 -0
  96. package/src/contracts/0x2/derived_object.ts +95 -0
  97. package/src/contracts/0x2/display.ts +258 -0
  98. package/src/contracts/0x2/dynamic_field.ts +171 -0
  99. package/src/contracts/0x2/dynamic_object_field.ts +167 -0
  100. package/src/contracts/0x2/ecdsa_k1.ts +65 -0
  101. package/src/contracts/0x2/ecdsa_r1.ts +49 -0
  102. package/src/contracts/0x2/ecvrf.ts +29 -0
  103. package/src/contracts/0x2/ed25519.ts +25 -0
  104. package/src/contracts/0x2/event.ts +42 -0
  105. package/src/contracts/0x2/funds_accumulator.ts +86 -0
  106. package/src/contracts/0x2/groth16.ts +171 -0
  107. package/src/contracts/0x2/group_ops.ts +49 -0
  108. package/src/contracts/0x2/hash.ts +37 -0
  109. package/src/contracts/0x2/hex.ts +37 -0
  110. package/src/contracts/0x2/hmac.ts +21 -0
  111. package/src/contracts/0x2/kiosk.ts +797 -0
  112. package/src/contracts/0x2/kiosk_extension.ts +270 -0
  113. package/src/contracts/0x2/linked_table.ts +354 -0
  114. package/src/contracts/0x2/math.ts +117 -0
  115. package/src/contracts/0x2/nitro_attestation.ts +186 -0
  116. package/src/contracts/0x2/object.ts +249 -0
  117. package/src/contracts/0x2/object_bag.ts +210 -0
  118. package/src/contracts/0x2/object_table.ts +200 -0
  119. package/src/contracts/0x2/package.ts +414 -0
  120. package/src/contracts/0x2/party.ts +37 -0
  121. package/src/contracts/0x2/pay.ts +153 -0
  122. package/src/contracts/0x2/poseidon.ts +21 -0
  123. package/src/contracts/0x2/priority_queue.ts +139 -0
  124. package/src/contracts/0x2/random.ts +294 -0
  125. package/src/contracts/0x2/sui.ts +29 -0
  126. package/src/contracts/0x2/table.ts +200 -0
  127. package/src/contracts/0x2/table_vec.ts +232 -0
  128. package/src/contracts/0x2/token.ts +873 -0
  129. package/src/contracts/0x2/transfer.ts +216 -0
  130. package/src/contracts/0x2/transfer_policy.ts +400 -0
  131. package/src/contracts/0x2/tx_context.ts +129 -0
  132. package/src/contracts/0x2/types.ts +24 -0
  133. package/src/contracts/0x2/url.ts +77 -0
  134. package/src/contracts/0x2/vdf.ts +45 -0
  135. package/src/contracts/0x2/vec_map.ts +401 -0
  136. package/src/contracts/0x2/vec_set.ts +211 -0
  137. package/src/contracts/0x2/versioned.ts +153 -0
  138. package/src/contracts/0x2/zklogin_verified_id.ts +172 -0
  139. package/src/contracts/0x2/zklogin_verified_issuer.ts +99 -0
  140. package/src/contracts/kiosk/deps/sui/kiosk.ts +94 -0
  141. package/src/contracts/kiosk/deps/sui/object.ts +15 -0
  142. package/src/contracts/kiosk/floor_price_rule.ts +92 -0
  143. package/src/contracts/kiosk/kiosk_lock_rule.ts +97 -0
  144. package/src/contracts/kiosk/personal_kiosk.ts +295 -0
  145. package/src/contracts/kiosk/personal_kiosk_rule.ts +89 -0
  146. package/src/contracts/kiosk/royalty_rule.ts +144 -0
  147. package/src/contracts/kiosk/witness_rule.ts +92 -0
  148. package/src/contracts/utils/index.ts +234 -0
  149. package/src/query/client-utils.ts +51 -0
  150. package/src/query/kiosk.ts +128 -100
  151. package/src/query/transfer-policy.ts +112 -78
  152. package/src/tx/kiosk.ts +7 -231
  153. package/src/tx/rules/resolve.ts +97 -48
  154. package/src/tx/transfer-policy.ts +25 -86
  155. package/src/types/index.ts +3 -14
  156. package/src/types/kiosk.ts +10 -12
  157. package/src/types/transfer-policy.ts +4 -4
  158. package/src/utils.ts +90 -128
  159. package/dist/cjs/bcs.d.ts +0 -23
  160. package/dist/cjs/bcs.js +0 -50
  161. package/dist/cjs/bcs.js.map +0 -7
  162. package/dist/cjs/client/kiosk-client.d.ts +0 -76
  163. package/dist/cjs/client/kiosk-client.js +0 -123
  164. package/dist/cjs/client/kiosk-client.js.map +0 -7
  165. package/dist/cjs/client/kiosk-transaction.d.ts +0 -186
  166. package/dist/cjs/client/kiosk-transaction.js +0 -462
  167. package/dist/cjs/client/kiosk-transaction.js.map +0 -7
  168. package/dist/cjs/client/tp-transaction.d.ts +0 -114
  169. package/dist/cjs/client/tp-transaction.js +0 -307
  170. package/dist/cjs/client/tp-transaction.js.map +0 -7
  171. package/dist/cjs/constants.d.ts +0 -31
  172. package/dist/cjs/constants.js +0 -102
  173. package/dist/cjs/constants.js.map +0 -7
  174. package/dist/cjs/index.d.ts +0 -6
  175. package/dist/cjs/index.js +0 -24
  176. package/dist/cjs/index.js.map +0 -7
  177. package/dist/cjs/package.json +0 -5
  178. package/dist/cjs/query/kiosk.d.ts +0 -8
  179. package/dist/cjs/query/kiosk.js +0 -181
  180. package/dist/cjs/query/kiosk.js.map +0 -7
  181. package/dist/cjs/query/transfer-policy.d.ts +0 -29
  182. package/dist/cjs/query/transfer-policy.js +0 -92
  183. package/dist/cjs/query/transfer-policy.js.map +0 -7
  184. package/dist/cjs/tx/kiosk.d.ts +0 -71
  185. package/dist/cjs/tx/kiosk.js +0 -130
  186. package/dist/cjs/tx/kiosk.js.map +0 -7
  187. package/dist/cjs/tx/personal-kiosk.d.ts +0 -7
  188. package/dist/cjs/tx/personal-kiosk.js +0 -38
  189. package/dist/cjs/tx/personal-kiosk.js.map +0 -7
  190. package/dist/cjs/tx/rules/attach.d.ts +0 -7
  191. package/dist/cjs/tx/rules/attach.js +0 -62
  192. package/dist/cjs/tx/rules/attach.js.map +0 -7
  193. package/dist/cjs/tx/rules/resolve.d.ts +0 -15
  194. package/dist/cjs/tx/rules/resolve.js +0 -109
  195. package/dist/cjs/tx/rules/resolve.js.map +0 -7
  196. package/dist/cjs/tx/transfer-policy.d.ts +0 -29
  197. package/dist/cjs/tx/transfer-policy.js +0 -78
  198. package/dist/cjs/tx/transfer-policy.js.map +0 -7
  199. package/dist/cjs/types/index.d.ts +0 -27
  200. package/dist/cjs/types/index.js +0 -33
  201. package/dist/cjs/types/index.js.map +0 -7
  202. package/dist/cjs/types/kiosk.d.ts +0 -160
  203. package/dist/cjs/types/kiosk.js +0 -37
  204. package/dist/cjs/types/kiosk.js.map +0 -7
  205. package/dist/cjs/types/transfer-policy.d.ts +0 -53
  206. package/dist/cjs/types/transfer-policy.js +0 -35
  207. package/dist/cjs/types/transfer-policy.js.map +0 -7
  208. package/dist/cjs/utils.d.ts +0 -51
  209. package/dist/cjs/utils.js +0 -198
  210. package/dist/cjs/utils.js.map +0 -7
  211. package/dist/esm/bcs.d.ts +0 -23
  212. package/dist/esm/bcs.js +0 -35
  213. package/dist/esm/bcs.js.map +0 -7
  214. package/dist/esm/client/kiosk-client.d.ts +0 -76
  215. package/dist/esm/client/kiosk-client.js +0 -114
  216. package/dist/esm/client/kiosk-client.js.map +0 -7
  217. package/dist/esm/client/kiosk-transaction.d.ts +0 -186
  218. package/dist/esm/client/kiosk-transaction.js +0 -432
  219. package/dist/esm/client/kiosk-transaction.js.map +0 -7
  220. package/dist/esm/client/tp-transaction.d.ts +0 -114
  221. package/dist/esm/client/tp-transaction.js +0 -298
  222. package/dist/esm/client/tp-transaction.js.map +0 -7
  223. package/dist/esm/constants.d.ts +0 -31
  224. package/dist/esm/constants.js +0 -87
  225. package/dist/esm/constants.js.map +0 -7
  226. package/dist/esm/index.d.ts +0 -6
  227. package/dist/esm/index.js +0 -7
  228. package/dist/esm/index.js.map +0 -7
  229. package/dist/esm/package.json +0 -5
  230. package/dist/esm/query/kiosk.d.ts +0 -8
  231. package/dist/esm/query/kiosk.js +0 -169
  232. package/dist/esm/query/kiosk.js.map +0 -7
  233. package/dist/esm/query/transfer-policy.d.ts +0 -29
  234. package/dist/esm/query/transfer-policy.js +0 -76
  235. package/dist/esm/query/transfer-policy.js.map +0 -7
  236. package/dist/esm/tx/kiosk.d.ts +0 -71
  237. package/dist/esm/tx/kiosk.js +0 -110
  238. package/dist/esm/tx/kiosk.js.map +0 -7
  239. package/dist/esm/tx/personal-kiosk.d.ts +0 -7
  240. package/dist/esm/tx/personal-kiosk.js +0 -18
  241. package/dist/esm/tx/personal-kiosk.js.map +0 -7
  242. package/dist/esm/tx/rules/attach.d.ts +0 -7
  243. package/dist/esm/tx/rules/attach.js +0 -42
  244. package/dist/esm/tx/rules/attach.js.map +0 -7
  245. package/dist/esm/tx/rules/resolve.d.ts +0 -15
  246. package/dist/esm/tx/rules/resolve.js +0 -89
  247. package/dist/esm/tx/rules/resolve.js.map +0 -7
  248. package/dist/esm/tx/transfer-policy.d.ts +0 -29
  249. package/dist/esm/tx/transfer-policy.js +0 -58
  250. package/dist/esm/tx/transfer-policy.js.map +0 -7
  251. package/dist/esm/types/index.d.ts +0 -27
  252. package/dist/esm/types/index.js +0 -12
  253. package/dist/esm/types/index.js.map +0 -7
  254. package/dist/esm/types/kiosk.d.ts +0 -160
  255. package/dist/esm/types/kiosk.js +0 -17
  256. package/dist/esm/types/kiosk.js.map +0 -7
  257. package/dist/esm/types/transfer-policy.d.ts +0 -53
  258. package/dist/esm/types/transfer-policy.js +0 -15
  259. package/dist/esm/types/transfer-policy.js.map +0 -7
  260. package/dist/esm/utils.d.ts +0 -51
  261. package/dist/esm/utils.js +0 -183
  262. package/dist/esm/utils.js.map +0 -7
  263. package/dist/tsconfig.esm.tsbuildinfo +0 -1
  264. package/dist/tsconfig.tsbuildinfo +0 -1
  265. package/src/bcs.ts +0 -39
  266. package/src/tx/personal-kiosk.ts +0 -34
  267. package/src/tx/rules/attach.ts +0 -73
@@ -0,0 +1,144 @@
1
+ /**************************************************************
2
+ * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
3
+ **************************************************************/
4
+
5
+ /**
6
+ * Description: This module defines a Rule which requires a payment on a purchase.
7
+ * The payment amount can be either a fixed amount (min_amount) or a percentage of
8
+ * the purchase price (amount_bp). Or both: the higher of the two is used.
9
+ *
10
+ * Configuration:
11
+ *
12
+ * - amount_bp - the percentage of the purchase price to be paid as a fee,
13
+ * denominated in basis points (100_00 = 100%, 1 = 0.01%).
14
+ * - min_amount - the minimum amount to be paid as a fee if the relative amount is
15
+ * lower than this setting.
16
+ *
17
+ * Use cases:
18
+ *
19
+ * - Percentage-based Royalty fee for the creator of the NFT.
20
+ * - Fixed commission fee on a trade.
21
+ * - A mix of both: the higher of the two is used.
22
+ *
23
+ * Notes:
24
+ *
25
+ * - To use it as a fixed commission set the `amount_bp` to 0 and use the
26
+ * `min_amount` to set the fixed amount.
27
+ * - To use it as a percentage-based fee set the `min_amount` to 0 and use the
28
+ * `amount_bp` to set the percentage.
29
+ * - To use it as a mix of both set the `min_amount` to the min amount acceptable
30
+ * and the `amount_bp` to the percentage of the purchase price. The higher of the
31
+ * two will be used.
32
+ */
33
+
34
+ import { MoveStruct, normalizeMoveArguments, type RawTransactionArgument } from '../utils/index.js';
35
+ import { bcs } from '@mysten/sui/bcs';
36
+ import { type Transaction } from '@mysten/sui/transactions';
37
+ const $moduleName = '@local-pkg/kiosk::royalty_rule';
38
+ export const Rule = new MoveStruct({
39
+ name: `${$moduleName}::Rule`,
40
+ fields: {
41
+ dummy_field: bcs.bool(),
42
+ },
43
+ });
44
+ export const Config = new MoveStruct({
45
+ name: `${$moduleName}::Config`,
46
+ fields: {
47
+ amount_bp: bcs.u16(),
48
+ min_amount: bcs.u64(),
49
+ },
50
+ });
51
+ export interface AddArguments {
52
+ policy: RawTransactionArgument<string>;
53
+ cap: RawTransactionArgument<string>;
54
+ amountBp: RawTransactionArgument<number>;
55
+ minAmount: RawTransactionArgument<number | bigint>;
56
+ }
57
+ export interface AddOptions {
58
+ package?: string;
59
+ arguments:
60
+ | AddArguments
61
+ | [
62
+ policy: RawTransactionArgument<string>,
63
+ cap: RawTransactionArgument<string>,
64
+ amountBp: RawTransactionArgument<number>,
65
+ minAmount: RawTransactionArgument<number | bigint>,
66
+ ];
67
+ typeArguments: [string];
68
+ }
69
+ /**
70
+ * Creator action: Add the Royalty Rule for the `T`. Pass in the `TransferPolicy`,
71
+ * `TransferPolicyCap` and the configuration for the policy: `amount_bp` and
72
+ * `min_amount`.
73
+ */
74
+ export function add(options: AddOptions) {
75
+ const packageAddress = options.package ?? '@local-pkg/kiosk';
76
+ const argumentsTypes = [null, null, 'u16', 'u64'] satisfies (string | null)[];
77
+ const parameterNames = ['policy', 'cap', 'amountBp', 'minAmount'];
78
+ return (tx: Transaction) =>
79
+ tx.moveCall({
80
+ package: packageAddress,
81
+ module: 'royalty_rule',
82
+ function: 'add',
83
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
84
+ typeArguments: options.typeArguments,
85
+ });
86
+ }
87
+ export interface PayArguments {
88
+ policy: RawTransactionArgument<string>;
89
+ request: RawTransactionArgument<string>;
90
+ payment: RawTransactionArgument<string>;
91
+ }
92
+ export interface PayOptions {
93
+ package?: string;
94
+ arguments:
95
+ | PayArguments
96
+ | [
97
+ policy: RawTransactionArgument<string>,
98
+ request: RawTransactionArgument<string>,
99
+ payment: RawTransactionArgument<string>,
100
+ ];
101
+ typeArguments: [string];
102
+ }
103
+ /** Buyer action: Pay the royalty fee for the transfer. */
104
+ export function pay(options: PayOptions) {
105
+ const packageAddress = options.package ?? '@local-pkg/kiosk';
106
+ const argumentsTypes = [null, null, null] satisfies (string | null)[];
107
+ const parameterNames = ['policy', 'request', 'payment'];
108
+ return (tx: Transaction) =>
109
+ tx.moveCall({
110
+ package: packageAddress,
111
+ module: 'royalty_rule',
112
+ function: 'pay',
113
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
114
+ typeArguments: options.typeArguments,
115
+ });
116
+ }
117
+ export interface FeeAmountArguments {
118
+ policy: RawTransactionArgument<string>;
119
+ paid: RawTransactionArgument<number | bigint>;
120
+ }
121
+ export interface FeeAmountOptions {
122
+ package?: string;
123
+ arguments:
124
+ | FeeAmountArguments
125
+ | [policy: RawTransactionArgument<string>, paid: RawTransactionArgument<number | bigint>];
126
+ typeArguments: [string];
127
+ }
128
+ /**
129
+ * Helper function to calculate the amount to be paid for the transfer. Can be used
130
+ * dry-runned to estimate the fee amount based on the Kiosk listing price.
131
+ */
132
+ export function feeAmount(options: FeeAmountOptions) {
133
+ const packageAddress = options.package ?? '@local-pkg/kiosk';
134
+ const argumentsTypes = [null, 'u64'] satisfies (string | null)[];
135
+ const parameterNames = ['policy', 'paid'];
136
+ return (tx: Transaction) =>
137
+ tx.moveCall({
138
+ package: packageAddress,
139
+ module: 'royalty_rule',
140
+ function: 'fee_amount',
141
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
142
+ typeArguments: options.typeArguments,
143
+ });
144
+ }
@@ -0,0 +1,92 @@
1
+ /**************************************************************
2
+ * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
3
+ **************************************************************/
4
+
5
+ /**
6
+ * Description: This module implements a Rule that requires a "Proof" witness to be
7
+ * presented on every transfer. The "Proof" witness is a type chosen by the owner
8
+ * of the policy.
9
+ *
10
+ * Configuration:
11
+ *
12
+ * - The type to require for every transfer.
13
+ *
14
+ * Use Cases:
15
+ *
16
+ * - Can be used to link custom logic to the TransferPolicy via the Witness.
17
+ * - Only allow trading on a certain marketplace.
18
+ * - Require a confirmation in a third party module
19
+ * - Implement a custom requirement on the creator side an link the logic.
20
+ */
21
+
22
+ import { MoveStruct, normalizeMoveArguments, type RawTransactionArgument } from '../utils/index.js';
23
+ import { bcs, type BcsType } from '@mysten/sui/bcs';
24
+ import { type Transaction } from '@mysten/sui/transactions';
25
+ const $moduleName = '@local-pkg/kiosk::witness_rule';
26
+ export const Rule = new MoveStruct({
27
+ name: `${$moduleName}::Rule`,
28
+ fields: {
29
+ dummy_field: bcs.bool(),
30
+ },
31
+ });
32
+ export interface AddArguments {
33
+ policy: RawTransactionArgument<string>;
34
+ cap: RawTransactionArgument<string>;
35
+ }
36
+ export interface AddOptions {
37
+ package?: string;
38
+ arguments:
39
+ | AddArguments
40
+ | [policy: RawTransactionArgument<string>, cap: RawTransactionArgument<string>];
41
+ typeArguments: [string, string];
42
+ }
43
+ /**
44
+ * Creator action: adds the Rule. Requires a "Proof" witness confirmation on every
45
+ * transfer.
46
+ */
47
+ export function add(options: AddOptions) {
48
+ const packageAddress = options.package ?? '@local-pkg/kiosk';
49
+ const argumentsTypes = [null, null] satisfies (string | null)[];
50
+ const parameterNames = ['policy', 'cap'];
51
+ return (tx: Transaction) =>
52
+ tx.moveCall({
53
+ package: packageAddress,
54
+ module: 'witness_rule',
55
+ function: 'add',
56
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
57
+ typeArguments: options.typeArguments,
58
+ });
59
+ }
60
+ export interface ProveArguments<Proof extends BcsType<any>> {
61
+ Proof: RawTransactionArgument<Proof>;
62
+ policy: RawTransactionArgument<string>;
63
+ request: RawTransactionArgument<string>;
64
+ }
65
+ export interface ProveOptions<Proof extends BcsType<any>> {
66
+ package?: string;
67
+ arguments:
68
+ | ProveArguments<Proof>
69
+ | [
70
+ Proof: RawTransactionArgument<Proof>,
71
+ policy: RawTransactionArgument<string>,
72
+ request: RawTransactionArgument<string>,
73
+ ];
74
+ typeArguments: [string, string];
75
+ }
76
+ /**
77
+ * Buyer action: follow the policy. Present the required "Proof" instance to get a
78
+ * receipt.
79
+ */
80
+ export function prove<Proof extends BcsType<any>>(options: ProveOptions<Proof>) {
81
+ const packageAddress = options.package ?? '@local-pkg/kiosk';
82
+ const argumentsTypes = [`${options.typeArguments[1]}`, null, null] satisfies (string | null)[];
83
+ const parameterNames = ['Proof', 'policy', 'request'];
84
+ return (tx: Transaction) =>
85
+ tx.moveCall({
86
+ package: packageAddress,
87
+ module: 'witness_rule',
88
+ function: 'prove',
89
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
90
+ typeArguments: options.typeArguments,
91
+ });
92
+ }
@@ -0,0 +1,234 @@
1
+ import {
2
+ bcs,
3
+ BcsType,
4
+ TypeTag,
5
+ TypeTagSerializer,
6
+ BcsStruct,
7
+ BcsEnum,
8
+ BcsTuple,
9
+ } from '@mysten/sui/bcs';
10
+ import { normalizeSuiAddress } from '@mysten/sui/utils';
11
+ import { TransactionArgument, isArgument } from '@mysten/sui/transactions';
12
+ import { ClientWithCoreApi, SuiClientTypes } from '@mysten/sui/client';
13
+
14
+ const MOVE_STDLIB_ADDRESS = normalizeSuiAddress('0x1');
15
+ const SUI_FRAMEWORK_ADDRESS = normalizeSuiAddress('0x2');
16
+
17
+ export type RawTransactionArgument<T> = T | TransactionArgument;
18
+
19
+ export interface GetOptions<
20
+ Include extends Omit<SuiClientTypes.ObjectInclude, 'content'> = {},
21
+ > extends SuiClientTypes.GetObjectOptions<Include> {
22
+ client: ClientWithCoreApi;
23
+ }
24
+
25
+ export interface GetManyOptions<
26
+ Include extends Omit<SuiClientTypes.ObjectInclude, 'content'> = {},
27
+ > extends SuiClientTypes.GetObjectsOptions<Include> {
28
+ client: ClientWithCoreApi;
29
+ }
30
+
31
+ export function getPureBcsSchema(typeTag: string | TypeTag): BcsType<any> | null {
32
+ const parsedTag = typeof typeTag === 'string' ? TypeTagSerializer.parseFromStr(typeTag) : typeTag;
33
+
34
+ if ('u8' in parsedTag) {
35
+ return bcs.U8;
36
+ } else if ('u16' in parsedTag) {
37
+ return bcs.U16;
38
+ } else if ('u32' in parsedTag) {
39
+ return bcs.U32;
40
+ } else if ('u64' in parsedTag) {
41
+ return bcs.U64;
42
+ } else if ('u128' in parsedTag) {
43
+ return bcs.U128;
44
+ } else if ('u256' in parsedTag) {
45
+ return bcs.U256;
46
+ } else if ('address' in parsedTag) {
47
+ return bcs.Address;
48
+ } else if ('bool' in parsedTag) {
49
+ return bcs.Bool;
50
+ } else if ('vector' in parsedTag) {
51
+ const type = getPureBcsSchema(parsedTag.vector);
52
+ return type ? bcs.vector(type) : null;
53
+ } else if ('struct' in parsedTag) {
54
+ const structTag = parsedTag.struct;
55
+ const pkg = normalizeSuiAddress(structTag.address);
56
+
57
+ if (pkg === MOVE_STDLIB_ADDRESS) {
58
+ if (
59
+ (structTag.module === 'ascii' || structTag.module === 'string') &&
60
+ structTag.name === 'String'
61
+ ) {
62
+ return bcs.String;
63
+ }
64
+
65
+ if (structTag.module === 'option' && structTag.name === 'Option') {
66
+ const type = getPureBcsSchema(structTag.typeParams[0]);
67
+ return type ? bcs.option(type) : null;
68
+ }
69
+ }
70
+
71
+ if (
72
+ pkg === SUI_FRAMEWORK_ADDRESS &&
73
+ structTag.module === 'object' &&
74
+ (structTag.name === 'ID' || structTag.name === 'UID')
75
+ ) {
76
+ return bcs.Address;
77
+ }
78
+ }
79
+
80
+ return null;
81
+ }
82
+
83
+ export function normalizeMoveArguments(
84
+ args: unknown[] | object,
85
+ argTypes: readonly (string | null)[],
86
+ parameterNames?: string[],
87
+ ) {
88
+ const argLen = Array.isArray(args) ? args.length : Object.keys(args).length;
89
+ if (parameterNames && argLen !== parameterNames.length) {
90
+ throw new Error(
91
+ `Invalid number of arguments, expected ${parameterNames.length}, got ${argLen}`,
92
+ );
93
+ }
94
+
95
+ const normalizedArgs: TransactionArgument[] = [];
96
+
97
+ let index = 0;
98
+ for (const [i, argType] of argTypes.entries()) {
99
+ if (argType === '0x2::clock::Clock') {
100
+ normalizedArgs.push((tx) => tx.object.clock());
101
+ continue;
102
+ }
103
+
104
+ if (argType === '0x2::random::Random') {
105
+ normalizedArgs.push((tx) => tx.object.random());
106
+ continue;
107
+ }
108
+
109
+ if (argType === '0x2::deny_list::DenyList') {
110
+ normalizedArgs.push((tx) => tx.object.denyList());
111
+ continue;
112
+ }
113
+
114
+ if (argType === '0x3::sui_system::SuiSystemState') {
115
+ normalizedArgs.push((tx) => tx.object.system());
116
+ continue;
117
+ }
118
+
119
+ let arg;
120
+ if (Array.isArray(args)) {
121
+ if (index >= args.length) {
122
+ throw new Error(
123
+ `Invalid number of arguments, expected at least ${index + 1}, got ${args.length}`,
124
+ );
125
+ }
126
+ arg = args[index];
127
+ } else {
128
+ if (!parameterNames) {
129
+ throw new Error(`Expected arguments to be passed as an array`);
130
+ }
131
+ const name = parameterNames[index];
132
+ arg = args[name as keyof typeof args];
133
+
134
+ if (arg === undefined) {
135
+ throw new Error(`Parameter ${name} is required`);
136
+ }
137
+ }
138
+
139
+ index += 1;
140
+
141
+ if (typeof arg === 'function' || isArgument(arg)) {
142
+ normalizedArgs.push(arg as TransactionArgument);
143
+ continue;
144
+ }
145
+
146
+ const type = argTypes[i];
147
+ const bcsType = type === null ? null : getPureBcsSchema(type);
148
+
149
+ if (bcsType) {
150
+ const bytes = bcsType.serialize(arg as never);
151
+ normalizedArgs.push((tx) => tx.pure(bytes));
152
+ continue;
153
+ } else if (typeof arg === 'string') {
154
+ normalizedArgs.push((tx) => tx.object(arg));
155
+ continue;
156
+ }
157
+
158
+ throw new Error(`Invalid argument ${stringify(arg)} for type ${type}`);
159
+ }
160
+
161
+ return normalizedArgs;
162
+ }
163
+
164
+ export class MoveStruct<
165
+ T extends Record<string, BcsType<any>>,
166
+ const Name extends string = string,
167
+ > extends BcsStruct<T, Name> {
168
+ async get<Include extends Omit<SuiClientTypes.ObjectInclude, 'content' | 'json'> = {}>({
169
+ objectId,
170
+ ...options
171
+ }: GetOptions<Include>): Promise<
172
+ SuiClientTypes.Object<Include & { content: true; json: true }> & {
173
+ json: BcsStruct<T>['$inferType'];
174
+ }
175
+ > {
176
+ const [res] = await this.getMany<Include>({
177
+ ...options,
178
+ objectIds: [objectId],
179
+ });
180
+
181
+ return res;
182
+ }
183
+
184
+ async getMany<Include extends Omit<SuiClientTypes.ObjectInclude, 'content' | 'json'> = {}>({
185
+ client,
186
+ ...options
187
+ }: GetManyOptions<Include>): Promise<
188
+ Array<
189
+ SuiClientTypes.Object<Include & { content: true; json: true }> & {
190
+ json: BcsStruct<T>['$inferType'];
191
+ }
192
+ >
193
+ > {
194
+ const response = (await client.core.getObjects({
195
+ ...options,
196
+ include: {
197
+ ...options.include,
198
+ content: true,
199
+ },
200
+ })) as SuiClientTypes.GetObjectsResponse<Include & { content: true }>;
201
+
202
+ return response.objects.map((obj) => {
203
+ if (obj instanceof Error) {
204
+ throw obj;
205
+ }
206
+
207
+ return {
208
+ ...obj,
209
+ json: this.parse(obj.content),
210
+ };
211
+ });
212
+ }
213
+ }
214
+
215
+ export class MoveEnum<
216
+ T extends Record<string, BcsType<any> | null>,
217
+ const Name extends string,
218
+ > extends BcsEnum<T, Name> {}
219
+
220
+ export class MoveTuple<
221
+ T extends readonly BcsType<any>[],
222
+ const Name extends string,
223
+ > extends BcsTuple<T, Name> {}
224
+
225
+ function stringify(val: unknown) {
226
+ if (typeof val === 'object') {
227
+ return JSON.stringify(val, (val: unknown) => val);
228
+ }
229
+ if (typeof val === 'bigint') {
230
+ return val.toString();
231
+ }
232
+
233
+ return val;
234
+ }
@@ -0,0 +1,51 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { ClientWithCoreApi } from '@mysten/sui/client';
5
+ import { graphql } from '@mysten/sui/graphql/schema';
6
+ import { isSuiGraphQLClient } from '@mysten/sui/graphql';
7
+ import { isSuiJsonRpcClient } from '@mysten/sui/jsonRpc';
8
+
9
+ export async function queryEvents(
10
+ client: ClientWithCoreApi,
11
+ eventType: string,
12
+ ): Promise<{ json: unknown }[]> {
13
+ if (isSuiGraphQLClient(client)) {
14
+ const query = graphql(`
15
+ query QueryEvents($eventType: String!) {
16
+ events(filter: { eventType: $eventType }, first: 50) {
17
+ nodes {
18
+ contents {
19
+ json
20
+ }
21
+ }
22
+ }
23
+ }
24
+ `);
25
+
26
+ const result = await client.query({
27
+ query,
28
+ variables: { eventType },
29
+ });
30
+
31
+ return (
32
+ result.data?.events?.nodes.map((event) => ({
33
+ json: event.contents?.json,
34
+ })) ?? []
35
+ );
36
+ }
37
+
38
+ if (isSuiJsonRpcClient(client)) {
39
+ const events = await client.queryEvents({
40
+ query: { MoveEventType: eventType },
41
+ });
42
+
43
+ return events.data?.map((d) => ({ json: d.parsedJson })) ?? [];
44
+ }
45
+
46
+ throw new Error(
47
+ 'Event querying is not supported by this client type. ' +
48
+ 'JSON-RPC and GraphQL clients support event querying, but gRPC does not. ' +
49
+ 'Please use a JSON-RPC or GraphQL client, or provide the required IDs directly.',
50
+ );
51
+ }