@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.
Files changed (213) hide show
  1. package/CHANGELOG.md +271 -137
  2. package/README.md +3 -3
  3. package/dist/client/kiosk-client.d.mts +126 -0
  4. package/dist/client/kiosk-client.d.mts.map +1 -0
  5. package/dist/client/kiosk-client.mjs +124 -0
  6. package/dist/client/kiosk-client.mjs.map +1 -0
  7. package/dist/client/kiosk-transaction.d.mts +236 -0
  8. package/dist/client/kiosk-transaction.d.mts.map +1 -0
  9. package/dist/client/kiosk-transaction.mjs +472 -0
  10. package/dist/client/kiosk-transaction.mjs.map +1 -0
  11. package/dist/client/tp-transaction.d.mts +139 -0
  12. package/dist/client/tp-transaction.d.mts.map +1 -0
  13. package/dist/client/tp-transaction.mjs +273 -0
  14. package/dist/client/tp-transaction.mjs.map +1 -0
  15. package/dist/constants.d.mts +42 -0
  16. package/dist/constants.d.mts.map +1 -0
  17. package/dist/constants.mjs +62 -0
  18. package/dist/constants.mjs.map +1 -0
  19. package/dist/contracts/0x2/bag.mjs +19 -0
  20. package/dist/contracts/0x2/bag.mjs.map +1 -0
  21. package/dist/contracts/0x2/balance.mjs +16 -0
  22. package/dist/contracts/0x2/balance.mjs.map +1 -0
  23. package/dist/contracts/0x2/deps/0x0000000000000000000000000000000000000000000000000000000000000001/type_name.mjs +16 -0
  24. package/dist/contracts/0x2/deps/0x0000000000000000000000000000000000000000000000000000000000000001/type_name.mjs.map +1 -0
  25. package/dist/contracts/0x2/kiosk.mjs +244 -0
  26. package/dist/contracts/0x2/kiosk.mjs.map +1 -0
  27. package/dist/contracts/0x2/kiosk_extension.mjs +25 -0
  28. package/dist/contracts/0x2/kiosk_extension.mjs.map +1 -0
  29. package/dist/contracts/0x2/transfer_policy.mjs +99 -0
  30. package/dist/contracts/0x2/transfer_policy.mjs.map +1 -0
  31. package/dist/contracts/0x2/vec_set.mjs +18 -0
  32. package/dist/contracts/0x2/vec_set.mjs.map +1 -0
  33. package/dist/contracts/kiosk/deps/haneul/kiosk.mjs +98 -0
  34. package/dist/contracts/kiosk/deps/haneul/kiosk.mjs.map +1 -0
  35. package/dist/contracts/kiosk/floor_price_rule.mjs +70 -0
  36. package/dist/contracts/kiosk/floor_price_rule.mjs.map +1 -0
  37. package/dist/contracts/kiosk/kiosk_lock_rule.mjs +72 -0
  38. package/dist/contracts/kiosk/kiosk_lock_rule.mjs.map +1 -0
  39. package/dist/contracts/kiosk/personal_kiosk.mjs +102 -0
  40. package/dist/contracts/kiosk/personal_kiosk.mjs.map +1 -0
  41. package/dist/contracts/kiosk/personal_kiosk_rule.mjs +66 -0
  42. package/dist/contracts/kiosk/personal_kiosk_rule.mjs.map +1 -0
  43. package/dist/contracts/kiosk/royalty_rule.mjs +115 -0
  44. package/dist/contracts/kiosk/royalty_rule.mjs.map +1 -0
  45. package/dist/contracts/utils/index.mjs +118 -0
  46. package/dist/contracts/utils/index.mjs.map +1 -0
  47. package/dist/index.d.mts +9 -0
  48. package/dist/index.mjs +9 -0
  49. package/dist/query/client-utils.mjs +215 -0
  50. package/dist/query/client-utils.mjs.map +1 -0
  51. package/dist/query/kiosk.mjs +155 -0
  52. package/dist/query/kiosk.mjs.map +1 -0
  53. package/dist/query/transfer-policy.mjs +110 -0
  54. package/dist/query/transfer-policy.mjs.map +1 -0
  55. package/dist/tx/kiosk.mjs +20 -0
  56. package/dist/tx/kiosk.mjs.map +1 -0
  57. package/dist/tx/rules/resolve.mjs +114 -0
  58. package/dist/tx/rules/resolve.mjs.map +1 -0
  59. package/dist/tx/transfer-policy.mjs +38 -0
  60. package/dist/tx/transfer-policy.mjs.map +1 -0
  61. package/dist/types/index.d.mts +26 -0
  62. package/dist/types/index.d.mts.map +1 -0
  63. package/dist/types/kiosk.d.mts +175 -0
  64. package/dist/types/kiosk.d.mts.map +1 -0
  65. package/dist/types/kiosk.mjs +21 -0
  66. package/dist/types/kiosk.mjs.map +1 -0
  67. package/dist/types/transfer-policy.d.mts +56 -0
  68. package/dist/types/transfer-policy.d.mts.map +1 -0
  69. package/dist/types/transfer-policy.mjs +19 -0
  70. package/dist/types/transfer-policy.mjs.map +1 -0
  71. package/dist/utils.d.mts +39 -0
  72. package/dist/utils.d.mts.map +1 -0
  73. package/dist/utils.mjs +137 -0
  74. package/dist/utils.mjs.map +1 -0
  75. package/package.json +25 -20
  76. package/src/client/kiosk-client.ts +43 -5
  77. package/src/client/kiosk-transaction.ts +144 -65
  78. package/src/client/tp-transaction.ts +149 -95
  79. package/src/constants.ts +19 -24
  80. package/src/contracts/0x2/bag.ts +13 -0
  81. package/src/contracts/0x2/balance.ts +12 -0
  82. package/src/contracts/0x2/deps/0x0000000000000000000000000000000000000000000000000000000000000001/type_name.ts +12 -0
  83. package/src/contracts/0x2/kiosk.ts +797 -0
  84. package/src/contracts/0x2/kiosk_extension.ts +270 -0
  85. package/src/contracts/0x2/transfer_policy.ts +400 -0
  86. package/src/contracts/0x2/vec_set.ts +14 -0
  87. package/src/contracts/kiosk/deps/haneul/kiosk.ts +94 -0
  88. package/src/contracts/kiosk/floor_price_rule.ts +92 -0
  89. package/src/contracts/kiosk/kiosk_lock_rule.ts +97 -0
  90. package/src/contracts/kiosk/personal_kiosk.ts +295 -0
  91. package/src/contracts/kiosk/personal_kiosk_rule.ts +89 -0
  92. package/src/contracts/kiosk/royalty_rule.ts +144 -0
  93. package/src/contracts/kiosk/witness_rule.ts +92 -0
  94. package/src/contracts/utils/index.ts +234 -0
  95. package/src/query/client-utils.ts +302 -0
  96. package/src/query/kiosk.ts +130 -101
  97. package/src/query/transfer-policy.ts +112 -79
  98. package/src/tx/kiosk.ts +7 -231
  99. package/src/tx/rules/resolve.ts +97 -48
  100. package/src/tx/transfer-policy.ts +25 -86
  101. package/src/types/index.ts +7 -14
  102. package/src/types/kiosk.ts +22 -12
  103. package/src/types/transfer-policy.ts +4 -4
  104. package/src/utils.ts +79 -147
  105. package/dist/cjs/bcs.d.ts +0 -23
  106. package/dist/cjs/bcs.js +0 -50
  107. package/dist/cjs/bcs.js.map +0 -7
  108. package/dist/cjs/client/kiosk-client.d.ts +0 -76
  109. package/dist/cjs/client/kiosk-client.js +0 -123
  110. package/dist/cjs/client/kiosk-client.js.map +0 -7
  111. package/dist/cjs/client/kiosk-transaction.d.ts +0 -186
  112. package/dist/cjs/client/kiosk-transaction.js +0 -462
  113. package/dist/cjs/client/kiosk-transaction.js.map +0 -7
  114. package/dist/cjs/client/tp-transaction.d.ts +0 -114
  115. package/dist/cjs/client/tp-transaction.js +0 -307
  116. package/dist/cjs/client/tp-transaction.js.map +0 -7
  117. package/dist/cjs/constants.d.ts +0 -31
  118. package/dist/cjs/constants.js +0 -102
  119. package/dist/cjs/constants.js.map +0 -7
  120. package/dist/cjs/index.d.ts +0 -6
  121. package/dist/cjs/index.js +0 -24
  122. package/dist/cjs/index.js.map +0 -7
  123. package/dist/cjs/package.json +0 -5
  124. package/dist/cjs/query/kiosk.d.ts +0 -8
  125. package/dist/cjs/query/kiosk.js +0 -181
  126. package/dist/cjs/query/kiosk.js.map +0 -7
  127. package/dist/cjs/query/transfer-policy.d.ts +0 -29
  128. package/dist/cjs/query/transfer-policy.js +0 -92
  129. package/dist/cjs/query/transfer-policy.js.map +0 -7
  130. package/dist/cjs/tx/kiosk.d.ts +0 -71
  131. package/dist/cjs/tx/kiosk.js +0 -130
  132. package/dist/cjs/tx/kiosk.js.map +0 -7
  133. package/dist/cjs/tx/personal-kiosk.d.ts +0 -7
  134. package/dist/cjs/tx/personal-kiosk.js +0 -38
  135. package/dist/cjs/tx/personal-kiosk.js.map +0 -7
  136. package/dist/cjs/tx/rules/attach.d.ts +0 -7
  137. package/dist/cjs/tx/rules/attach.js +0 -62
  138. package/dist/cjs/tx/rules/attach.js.map +0 -7
  139. package/dist/cjs/tx/rules/resolve.d.ts +0 -15
  140. package/dist/cjs/tx/rules/resolve.js +0 -109
  141. package/dist/cjs/tx/rules/resolve.js.map +0 -7
  142. package/dist/cjs/tx/transfer-policy.d.ts +0 -29
  143. package/dist/cjs/tx/transfer-policy.js +0 -78
  144. package/dist/cjs/tx/transfer-policy.js.map +0 -7
  145. package/dist/cjs/types/index.d.ts +0 -27
  146. package/dist/cjs/types/index.js +0 -33
  147. package/dist/cjs/types/index.js.map +0 -7
  148. package/dist/cjs/types/kiosk.d.ts +0 -160
  149. package/dist/cjs/types/kiosk.js +0 -37
  150. package/dist/cjs/types/kiosk.js.map +0 -7
  151. package/dist/cjs/types/transfer-policy.d.ts +0 -53
  152. package/dist/cjs/types/transfer-policy.js +0 -35
  153. package/dist/cjs/types/transfer-policy.js.map +0 -7
  154. package/dist/cjs/utils.d.ts +0 -51
  155. package/dist/cjs/utils.js +0 -198
  156. package/dist/cjs/utils.js.map +0 -7
  157. package/dist/esm/bcs.d.ts +0 -23
  158. package/dist/esm/bcs.js +0 -35
  159. package/dist/esm/bcs.js.map +0 -7
  160. package/dist/esm/client/kiosk-client.d.ts +0 -76
  161. package/dist/esm/client/kiosk-client.js +0 -114
  162. package/dist/esm/client/kiosk-client.js.map +0 -7
  163. package/dist/esm/client/kiosk-transaction.d.ts +0 -186
  164. package/dist/esm/client/kiosk-transaction.js +0 -432
  165. package/dist/esm/client/kiosk-transaction.js.map +0 -7
  166. package/dist/esm/client/tp-transaction.d.ts +0 -114
  167. package/dist/esm/client/tp-transaction.js +0 -298
  168. package/dist/esm/client/tp-transaction.js.map +0 -7
  169. package/dist/esm/constants.d.ts +0 -31
  170. package/dist/esm/constants.js +0 -87
  171. package/dist/esm/constants.js.map +0 -7
  172. package/dist/esm/index.d.ts +0 -6
  173. package/dist/esm/index.js +0 -7
  174. package/dist/esm/index.js.map +0 -7
  175. package/dist/esm/package.json +0 -5
  176. package/dist/esm/query/kiosk.d.ts +0 -8
  177. package/dist/esm/query/kiosk.js +0 -169
  178. package/dist/esm/query/kiosk.js.map +0 -7
  179. package/dist/esm/query/transfer-policy.d.ts +0 -29
  180. package/dist/esm/query/transfer-policy.js +0 -76
  181. package/dist/esm/query/transfer-policy.js.map +0 -7
  182. package/dist/esm/tx/kiosk.d.ts +0 -71
  183. package/dist/esm/tx/kiosk.js +0 -110
  184. package/dist/esm/tx/kiosk.js.map +0 -7
  185. package/dist/esm/tx/personal-kiosk.d.ts +0 -7
  186. package/dist/esm/tx/personal-kiosk.js +0 -18
  187. package/dist/esm/tx/personal-kiosk.js.map +0 -7
  188. package/dist/esm/tx/rules/attach.d.ts +0 -7
  189. package/dist/esm/tx/rules/attach.js +0 -42
  190. package/dist/esm/tx/rules/attach.js.map +0 -7
  191. package/dist/esm/tx/rules/resolve.d.ts +0 -15
  192. package/dist/esm/tx/rules/resolve.js +0 -89
  193. package/dist/esm/tx/rules/resolve.js.map +0 -7
  194. package/dist/esm/tx/transfer-policy.d.ts +0 -29
  195. package/dist/esm/tx/transfer-policy.js +0 -58
  196. package/dist/esm/tx/transfer-policy.js.map +0 -7
  197. package/dist/esm/types/index.d.ts +0 -27
  198. package/dist/esm/types/index.js +0 -12
  199. package/dist/esm/types/index.js.map +0 -7
  200. package/dist/esm/types/kiosk.d.ts +0 -160
  201. package/dist/esm/types/kiosk.js +0 -17
  202. package/dist/esm/types/kiosk.js.map +0 -7
  203. package/dist/esm/types/transfer-policy.d.ts +0 -53
  204. package/dist/esm/types/transfer-policy.js +0 -15
  205. package/dist/esm/types/transfer-policy.js.map +0 -7
  206. package/dist/esm/utils.d.ts +0 -51
  207. package/dist/esm/utils.js +0 -183
  208. package/dist/esm/utils.js.map +0 -7
  209. package/dist/tsconfig.esm.tsbuildinfo +0 -1
  210. package/dist/tsconfig.tsbuildinfo +0 -1
  211. package/src/bcs.ts +0 -39
  212. package/src/tx/personal-kiosk.ts +0 -34
  213. 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 '@haneullabs/haneul/bcs';
36
+ import { type Transaction } from '@haneullabs/haneul/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 '@haneullabs/haneul/bcs';
24
+ import { type Transaction } from '@haneullabs/haneul/transactions';
25
+ const $moduleName = '@local-pkg/kiosk::witness_rule';
26
+ export const Rule = new MoveStruct({
27
+ name: `${$moduleName}::Rule<phantom Proof>`,
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 '@haneullabs/haneul/bcs';
10
+ import { normalizeHaneulAddress } from '@haneullabs/haneul/utils';
11
+ import { TransactionArgument, isArgument } from '@haneullabs/haneul/transactions';
12
+ import { ClientWithCoreApi, HaneulClientTypes } from '@haneullabs/haneul/client';
13
+
14
+ const MOVE_STDLIB_ADDRESS = normalizeHaneulAddress('0x1');
15
+ const HANEUL_FRAMEWORK_ADDRESS = normalizeHaneulAddress('0x2');
16
+
17
+ export type RawTransactionArgument<T> = T | TransactionArgument;
18
+
19
+ export interface GetOptions<
20
+ Include extends Omit<HaneulClientTypes.ObjectInclude, 'content'> = {},
21
+ > extends HaneulClientTypes.GetObjectOptions<Include> {
22
+ client: ClientWithCoreApi;
23
+ }
24
+
25
+ export interface GetManyOptions<
26
+ Include extends Omit<HaneulClientTypes.ObjectInclude, 'content'> = {},
27
+ > extends HaneulClientTypes.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 = normalizeHaneulAddress(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 === HANEUL_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::haneul_system::HaneulSystemState') {
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<HaneulClientTypes.ObjectInclude, 'content' | 'json'> = {}>({
169
+ objectId,
170
+ ...options
171
+ }: GetOptions<Include>): Promise<
172
+ HaneulClientTypes.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<HaneulClientTypes.ObjectInclude, 'content' | 'json'> = {}>({
185
+ client,
186
+ ...options
187
+ }: GetManyOptions<Include>): Promise<
188
+ Array<
189
+ HaneulClientTypes.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 HaneulClientTypes.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
+ const 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
+ }