@mysten/kiosk 0.14.6 → 1.0.1

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 +114 -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
@@ -1,186 +0,0 @@
1
- import type { Transaction, TransactionArgument, TransactionObjectArgument } from '@mysten/sui/transactions';
2
- import type { ItemId, ItemReference, ItemValue, KioskOwnerCap, ObjectArgument, Price, PurchaseOptions } from '../types/index.js';
3
- import type { KioskClient } from './kiosk-client.js';
4
- export type KioskTransactionParams = {
5
- /** The Transaction for this run */
6
- transaction: Transaction;
7
- /** @deprecated use transaction instead */
8
- transactionBlock?: Transaction;
9
- /**
10
- * You can create a new KioskClient by calling `new KioskClient()`
11
- */
12
- kioskClient: KioskClient;
13
- /**
14
- * You can optionally pass in the `cap` as returned
15
- * from `kioskClient.getOwnedKiosks` when initializing the client
16
- * Otherwise, you can set it by calling `kioskTransaction.setCap()`
17
- */
18
- cap?: KioskOwnerCap;
19
- };
20
- /**
21
- * A helper for building transactions that involve kiosk.
22
- */
23
- export declare class KioskTransaction {
24
- #private;
25
- transaction: Transaction;
26
- kioskClient: KioskClient;
27
- kiosk?: TransactionObjectArgument;
28
- kioskCap?: TransactionObjectArgument;
29
- constructor({ transactionBlock, transaction, kioskClient, cap, }: KioskTransactionParams);
30
- /**
31
- * Creates a kiosk and saves `kiosk` and `kioskOwnerCap` in state.
32
- * Helpful if we want to chain some actions before sharing + transferring the cap to the specified address.
33
- * @param borrow If true, the `kioskOwnerCap` is borrowed from the `PersonalKioskCap` to be used in next transactions.
34
- */
35
- create(): this;
36
- /**
37
- * Creates a personal kiosk & shares it.
38
- * The `PersonalKioskCap` is transferred to the signer.
39
- * @param borrow If true, the `kioskOwnerCap` is borrowed from the `PersonalKioskCap` to be used in next transactions.
40
- */
41
- createPersonal(borrow?: boolean): this;
42
- /**
43
- * Converts a kiosk to a Personal (Soulbound) Kiosk.
44
- * Requires initialization by either calling `ktxb.create()` or `ktxb.setCap()`.
45
- */
46
- convertToPersonal(borrow?: boolean): this;
47
- /**
48
- * Single function way to create a kiosk, share it and transfer the cap to the specified address.
49
- */
50
- createAndShare(address: string): this;
51
- /**
52
- * Shares the kiosk.
53
- */
54
- share(): this;
55
- /**
56
- * Should be called only after `create` is called.
57
- * It shares the kiosk & transfers the cap to the specified address.
58
- */
59
- shareAndTransferCap(address: string): this;
60
- /**
61
- * A function to borrow an item from a kiosk & execute any function with it.
62
- * Example: You could borrow a Fren out of a kiosk, attach an accessory (or mix), and return it.
63
- */
64
- borrowTx({ itemType, itemId }: ItemId, callback: (item: TransactionArgument) => void): this;
65
- /**
66
- * Borrows an item from the kiosk.
67
- * This will fail if the item is listed for sale.
68
- *
69
- * Requires calling `return`.
70
- */
71
- borrow({ itemType, itemId }: ItemId): [TransactionArgument, TransactionArgument];
72
- /**
73
- * Returns the item back to the kiosk.
74
- * Accepts the parameters returned from the `borrow` function.
75
- */
76
- return({ itemType, item, promise }: ItemValue & {
77
- promise: TransactionArgument;
78
- }): this;
79
- /**
80
- * A function to withdraw from kiosk
81
- * @param address Where to trasnfer the coin.
82
- * @param amount The amount we aim to withdraw.
83
- */
84
- withdraw(address: string, amount?: string | bigint | number): this;
85
- /**
86
- * A function to place an item in the kiosk.
87
- * @param itemType The type `T` of the item
88
- * @param item The ID or Transaction Argument of the item
89
- */
90
- place({ itemType, item }: ItemReference): this;
91
- /**
92
- * A function to place an item in the kiosk and list it for sale in one transaction.
93
- * @param itemType The type `T` of the item
94
- * @param item The ID or Transaction Argument of the item
95
- * @param price The price in MIST
96
- */
97
- placeAndList({ itemType, item, price }: ItemReference & Price): this;
98
- /**
99
- * A function to list an item in the kiosk.
100
- * @param itemType The type `T` of the item
101
- * @param itemId The ID of the item
102
- * @param price The price in MIST
103
- */
104
- list({ itemType, itemId, price }: ItemId & {
105
- price: string | bigint;
106
- }): this;
107
- /**
108
- * A function to delist an item from the kiosk.
109
- * @param itemType The type `T` of the item
110
- * @param itemId The ID of the item
111
- */
112
- delist({ itemType, itemId }: ItemId): this;
113
- /**
114
- * A function to take an item from the kiosk. The transaction won't succeed if the item is listed or locked.
115
-
116
- * @param itemType The type `T` of the item
117
- * @param itemId The ID of the item
118
- */
119
- take({ itemType, itemId }: ItemId): TransactionObjectArgument;
120
- /**
121
- * Transfer a non-locked/non-listed item to an address.
122
- *
123
- * @param itemType The type `T` of the item
124
- * @param itemId The ID of the item
125
- * @param address The destination address
126
- */
127
- transfer({ itemType, itemId, address }: ItemId & {
128
- address: string;
129
- }): this;
130
- /**
131
- * A function to take lock an item in the kiosk.
132
-
133
- * @param itemType The type `T` of the item
134
- * @param item The ID or Transaction Argument of the item
135
- * @param itemId The ID of the item - Deprecated: Use `item` instead.
136
- * @param policy The Policy ID or Transaction Argument for item T
137
- */
138
- lock({ itemType, item, itemId, policy, }: ItemReference & {
139
- policy: ObjectArgument;
140
- itemId?: string;
141
- }): this;
142
- /**
143
- * Purchase an item from a seller's kiosk.
144
- * Returns [item, transferRequest]
145
- * Can be called like: `const [item, transferRequest] = kioskTx.purchase({...})`
146
- * @param itemType The type `T` of the item
147
- * @param itemId The ID of the item
148
- * @param price The price in MIST
149
- * @param sellerKiosk The kiosk which is selling the item. Can be an id or an object argument.
150
- */
151
- purchase({ itemType, itemId, price, sellerKiosk, }: ItemId & Price & {
152
- sellerKiosk: ObjectArgument;
153
- }): [
154
- TransactionObjectArgument,
155
- TransactionObjectArgument
156
- ];
157
- /**
158
- * A function to purchase and resolve a transfer policy.
159
- * If the transfer policy has the `lock` rule, the item is locked in the kiosk.
160
- * Otherwise, the item is placed in the kiosk.
161
- * @param itemType The type of the item
162
- * @param itemId The id of the item
163
- * @param price The price of the specified item
164
- * @param sellerKiosk The kiosk which is selling the item. Can be an id or an object argument.
165
- * @param extraArgs Used to pass arguments for custom rule resolvers.
166
- */
167
- purchaseAndResolve({ itemType, itemId, price, sellerKiosk, extraArgs, }: ItemId & Price & {
168
- sellerKiosk: ObjectArgument;
169
- } & PurchaseOptions): Promise<this>;
170
- /**
171
- * A function to setup the client using an existing `ownerCap`,
172
- * as return from the `kioskClient.getOwnedKiosks` function.
173
- * @param cap `KioskOwnerCap` object as returned from `getOwnedKiosks` SDK call.
174
- */
175
- setCap(cap: KioskOwnerCap): this | undefined;
176
- /**
177
- * A function that ends up the kiosk building tx & returns the `kioskOwnerCap` back to the
178
- * `PersonalKioskCap`, in case we are operating on a personal kiosk.
179
- * It will also share the `kiosk` if it's not shared, and finalize the transfer of the personal cap if it's pending.
180
- */
181
- finalize(): void;
182
- setKioskCap(cap: TransactionObjectArgument): this;
183
- setKiosk(kiosk: TransactionObjectArgument): this;
184
- getKiosk(): TransactionObjectArgument;
185
- getKioskCap(): TransactionObjectArgument;
186
- }
@@ -1,462 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __typeError = (msg) => {
9
- throw TypeError(msg);
10
- };
11
- var __export = (target, all) => {
12
- for (var name in all)
13
- __defProp(target, name, { get: all[name], enumerable: true });
14
- };
15
- var __copyProps = (to, from, except, desc) => {
16
- if (from && typeof from === "object" || typeof from === "function") {
17
- for (let key of __getOwnPropNames(from))
18
- if (!__hasOwnProp.call(to, key) && key !== except)
19
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
- }
21
- return to;
22
- };
23
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
- // If the importer is in node compatibility mode or this is not an ESM
25
- // file that has been converted to a CommonJS file using a Babel-
26
- // compatible transform (i.e. "__esModule" has not been set), then set
27
- // "default" to the CommonJS "module.exports" for node compatibility.
28
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
- mod
30
- ));
31
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
33
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
34
- var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
35
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
36
- var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
37
- var kiosk_transaction_exports = {};
38
- __export(kiosk_transaction_exports, {
39
- KioskTransaction: () => KioskTransaction
40
- });
41
- module.exports = __toCommonJS(kiosk_transaction_exports);
42
- var kioskTx = __toESM(require("../tx/kiosk.js"));
43
- var import_personal_kiosk = require("../tx/personal-kiosk.js");
44
- var import_transfer_policy = require("../tx/transfer-policy.js");
45
- var import_utils = require("../utils.js");
46
- var _pendingShare, _pendingTransfer, _promise, _personalCap, _finalized, _KioskTransaction_instances, borrowFromPersonalCap_fn, setPendingStatuses_fn, validateKioskIsSet_fn, validateFinalizedStatus_fn;
47
- class KioskTransaction {
48
- constructor({
49
- transactionBlock,
50
- transaction = transactionBlock,
51
- kioskClient,
52
- cap
53
- }) {
54
- __privateAdd(this, _KioskTransaction_instances);
55
- // If we're pending `share` of a new kiosk, `finalize()` will share it.
56
- __privateAdd(this, _pendingShare);
57
- // If we're pending transferring of the cap, `finalize()` will either error or transfer the cap if it's a new personal.
58
- __privateAdd(this, _pendingTransfer);
59
- // The promise that the personalCap will be returned on `finalize()`.
60
- __privateAdd(this, _promise);
61
- // The personal kiosk argument.
62
- __privateAdd(this, _personalCap);
63
- // A flag that checks whether kiosk TX is finalized.
64
- __privateAdd(this, _finalized, false);
65
- this.transaction = transaction;
66
- this.kioskClient = kioskClient;
67
- if (cap) this.setCap(cap);
68
- }
69
- /**
70
- * Creates a kiosk and saves `kiosk` and `kioskOwnerCap` in state.
71
- * Helpful if we want to chain some actions before sharing + transferring the cap to the specified address.
72
- * @param borrow If true, the `kioskOwnerCap` is borrowed from the `PersonalKioskCap` to be used in next transactions.
73
- */
74
- create() {
75
- __privateMethod(this, _KioskTransaction_instances, validateFinalizedStatus_fn).call(this);
76
- __privateMethod(this, _KioskTransaction_instances, setPendingStatuses_fn).call(this, {
77
- share: true,
78
- transfer: true
79
- });
80
- const [kiosk, cap] = kioskTx.createKiosk(this.transaction);
81
- this.kiosk = kiosk;
82
- this.kioskCap = cap;
83
- return this;
84
- }
85
- /**
86
- * Creates a personal kiosk & shares it.
87
- * The `PersonalKioskCap` is transferred to the signer.
88
- * @param borrow If true, the `kioskOwnerCap` is borrowed from the `PersonalKioskCap` to be used in next transactions.
89
- */
90
- createPersonal(borrow) {
91
- __privateSet(this, _pendingShare, true);
92
- return this.create().convertToPersonal(borrow);
93
- }
94
- /**
95
- * Converts a kiosk to a Personal (Soulbound) Kiosk.
96
- * Requires initialization by either calling `ktxb.create()` or `ktxb.setCap()`.
97
- */
98
- convertToPersonal(borrow) {
99
- __privateMethod(this, _KioskTransaction_instances, validateKioskIsSet_fn).call(this);
100
- const cap = (0, import_personal_kiosk.convertToPersonalTx)(
101
- this.transaction,
102
- this.kiosk,
103
- this.kioskCap,
104
- this.kioskClient.getRulePackageId("personalKioskRulePackageId")
105
- );
106
- if (borrow) __privateMethod(this, _KioskTransaction_instances, borrowFromPersonalCap_fn).call(this, cap);
107
- else __privateSet(this, _personalCap, cap);
108
- __privateMethod(this, _KioskTransaction_instances, setPendingStatuses_fn).call(this, { transfer: true });
109
- return this;
110
- }
111
- /**
112
- * Single function way to create a kiosk, share it and transfer the cap to the specified address.
113
- */
114
- createAndShare(address) {
115
- __privateMethod(this, _KioskTransaction_instances, validateFinalizedStatus_fn).call(this);
116
- const cap = kioskTx.createKioskAndShare(this.transaction);
117
- this.transaction.transferObjects([cap], this.transaction.pure.address(address));
118
- return this;
119
- }
120
- /**
121
- * Shares the kiosk.
122
- */
123
- share() {
124
- __privateMethod(this, _KioskTransaction_instances, validateKioskIsSet_fn).call(this);
125
- __privateMethod(this, _KioskTransaction_instances, setPendingStatuses_fn).call(this, { share: false });
126
- kioskTx.shareKiosk(this.transaction, this.kiosk);
127
- return this;
128
- }
129
- /**
130
- * Should be called only after `create` is called.
131
- * It shares the kiosk & transfers the cap to the specified address.
132
- */
133
- shareAndTransferCap(address) {
134
- if (__privateGet(this, _personalCap))
135
- throw new Error("You can only call `shareAndTransferCap` on a non-personal kiosk.");
136
- __privateMethod(this, _KioskTransaction_instances, setPendingStatuses_fn).call(this, { transfer: false });
137
- this.share();
138
- this.transaction.transferObjects([this.kioskCap], this.transaction.pure.address(address));
139
- return this;
140
- }
141
- /**
142
- * A function to borrow an item from a kiosk & execute any function with it.
143
- * Example: You could borrow a Fren out of a kiosk, attach an accessory (or mix), and return it.
144
- */
145
- borrowTx({ itemType, itemId }, callback) {
146
- __privateMethod(this, _KioskTransaction_instances, validateKioskIsSet_fn).call(this);
147
- const [itemObj, promise] = kioskTx.borrowValue(
148
- this.transaction,
149
- itemType,
150
- this.kiosk,
151
- this.kioskCap,
152
- itemId
153
- );
154
- callback(itemObj);
155
- return this.return({ itemType, item: itemObj, promise });
156
- }
157
- /**
158
- * Borrows an item from the kiosk.
159
- * This will fail if the item is listed for sale.
160
- *
161
- * Requires calling `return`.
162
- */
163
- borrow({ itemType, itemId }) {
164
- __privateMethod(this, _KioskTransaction_instances, validateKioskIsSet_fn).call(this);
165
- const [itemObj, promise] = kioskTx.borrowValue(
166
- this.transaction,
167
- itemType,
168
- this.kiosk,
169
- this.kioskCap,
170
- itemId
171
- );
172
- return [itemObj, promise];
173
- }
174
- /**
175
- * Returns the item back to the kiosk.
176
- * Accepts the parameters returned from the `borrow` function.
177
- */
178
- return({ itemType, item, promise }) {
179
- __privateMethod(this, _KioskTransaction_instances, validateKioskIsSet_fn).call(this);
180
- kioskTx.returnValue(this.transaction, itemType, this.kiosk, item, promise);
181
- return this;
182
- }
183
- /**
184
- * A function to withdraw from kiosk
185
- * @param address Where to trasnfer the coin.
186
- * @param amount The amount we aim to withdraw.
187
- */
188
- withdraw(address, amount) {
189
- __privateMethod(this, _KioskTransaction_instances, validateKioskIsSet_fn).call(this);
190
- const coin = kioskTx.withdrawFromKiosk(this.transaction, this.kiosk, this.kioskCap, amount);
191
- this.transaction.transferObjects([coin], this.transaction.pure.address(address));
192
- return this;
193
- }
194
- /**
195
- * A function to place an item in the kiosk.
196
- * @param itemType The type `T` of the item
197
- * @param item The ID or Transaction Argument of the item
198
- */
199
- place({ itemType, item }) {
200
- __privateMethod(this, _KioskTransaction_instances, validateKioskIsSet_fn).call(this);
201
- kioskTx.place(this.transaction, itemType, this.kiosk, this.kioskCap, item);
202
- return this;
203
- }
204
- /**
205
- * A function to place an item in the kiosk and list it for sale in one transaction.
206
- * @param itemType The type `T` of the item
207
- * @param item The ID or Transaction Argument of the item
208
- * @param price The price in MIST
209
- */
210
- placeAndList({ itemType, item, price }) {
211
- __privateMethod(this, _KioskTransaction_instances, validateKioskIsSet_fn).call(this);
212
- kioskTx.placeAndList(this.transaction, itemType, this.kiosk, this.kioskCap, item, price);
213
- return this;
214
- }
215
- /**
216
- * A function to list an item in the kiosk.
217
- * @param itemType The type `T` of the item
218
- * @param itemId The ID of the item
219
- * @param price The price in MIST
220
- */
221
- list({ itemType, itemId, price }) {
222
- __privateMethod(this, _KioskTransaction_instances, validateKioskIsSet_fn).call(this);
223
- kioskTx.list(this.transaction, itemType, this.kiosk, this.kioskCap, itemId, price);
224
- return this;
225
- }
226
- /**
227
- * A function to delist an item from the kiosk.
228
- * @param itemType The type `T` of the item
229
- * @param itemId The ID of the item
230
- */
231
- delist({ itemType, itemId }) {
232
- __privateMethod(this, _KioskTransaction_instances, validateKioskIsSet_fn).call(this);
233
- kioskTx.delist(this.transaction, itemType, this.kiosk, this.kioskCap, itemId);
234
- return this;
235
- }
236
- /**
237
- * A function to take an item from the kiosk. The transaction won't succeed if the item is listed or locked.
238
-
239
- * @param itemType The type `T` of the item
240
- * @param itemId The ID of the item
241
- */
242
- take({ itemType, itemId }) {
243
- __privateMethod(this, _KioskTransaction_instances, validateKioskIsSet_fn).call(this);
244
- return kioskTx.take(this.transaction, itemType, this.kiosk, this.kioskCap, itemId);
245
- }
246
- /**
247
- * Transfer a non-locked/non-listed item to an address.
248
- *
249
- * @param itemType The type `T` of the item
250
- * @param itemId The ID of the item
251
- * @param address The destination address
252
- */
253
- transfer({ itemType, itemId, address }) {
254
- __privateMethod(this, _KioskTransaction_instances, validateKioskIsSet_fn).call(this);
255
- const item = this.take({ itemType, itemId });
256
- this.transaction.transferObjects([item], this.transaction.pure.address(address));
257
- return this;
258
- }
259
- /**
260
- * A function to take lock an item in the kiosk.
261
-
262
- * @param itemType The type `T` of the item
263
- * @param item The ID or Transaction Argument of the item
264
- * @param itemId The ID of the item - Deprecated: Use `item` instead.
265
- * @param policy The Policy ID or Transaction Argument for item T
266
- */
267
- lock({
268
- itemType,
269
- item,
270
- itemId,
271
- policy
272
- }) {
273
- __privateMethod(this, _KioskTransaction_instances, validateKioskIsSet_fn).call(this);
274
- kioskTx.lock(this.transaction, itemType, this.kiosk, this.kioskCap, policy, itemId ?? item);
275
- return this;
276
- }
277
- /**
278
- * Purchase an item from a seller's kiosk.
279
- * Returns [item, transferRequest]
280
- * Can be called like: `const [item, transferRequest] = kioskTx.purchase({...})`
281
- * @param itemType The type `T` of the item
282
- * @param itemId The ID of the item
283
- * @param price The price in MIST
284
- * @param sellerKiosk The kiosk which is selling the item. Can be an id or an object argument.
285
- */
286
- purchase({
287
- itemType,
288
- itemId,
289
- price,
290
- sellerKiosk
291
- }) {
292
- const coin = this.transaction.splitCoins(this.transaction.gas, [
293
- this.transaction.pure.u64(price)
294
- ]);
295
- return kioskTx.purchase(this.transaction, itemType, sellerKiosk, itemId, coin);
296
- }
297
- /**
298
- * A function to purchase and resolve a transfer policy.
299
- * If the transfer policy has the `lock` rule, the item is locked in the kiosk.
300
- * Otherwise, the item is placed in the kiosk.
301
- * @param itemType The type of the item
302
- * @param itemId The id of the item
303
- * @param price The price of the specified item
304
- * @param sellerKiosk The kiosk which is selling the item. Can be an id or an object argument.
305
- * @param extraArgs Used to pass arguments for custom rule resolvers.
306
- */
307
- async purchaseAndResolve({
308
- itemType,
309
- itemId,
310
- price,
311
- sellerKiosk,
312
- extraArgs
313
- }) {
314
- __privateMethod(this, _KioskTransaction_instances, validateKioskIsSet_fn).call(this);
315
- const policies = await this.kioskClient.getTransferPolicies({ type: itemType });
316
- if (policies.length === 0) {
317
- throw new Error(
318
- `The type ${itemType} doesn't have a Transfer Policy so it can't be traded through kiosk.`
319
- );
320
- }
321
- const policy = policies[0];
322
- const [purchasedItem, transferRequest] = this.purchase({
323
- itemType,
324
- itemId,
325
- price,
326
- sellerKiosk
327
- });
328
- let canTransferOutsideKiosk = true;
329
- for (const rule of policy.rules) {
330
- const ruleDefinition = this.kioskClient.rules.find(
331
- (x) => (0, import_utils.getNormalizedRuleType)(x.rule) === (0, import_utils.getNormalizedRuleType)(rule)
332
- );
333
- if (!ruleDefinition) throw new Error(`No resolver for the following rule: ${rule}.`);
334
- if (ruleDefinition.hasLockingRule) canTransferOutsideKiosk = false;
335
- await ruleDefinition.resolveRuleFunction({
336
- packageId: ruleDefinition.packageId,
337
- transactionBlock: this.transaction,
338
- transaction: this.transaction,
339
- itemType,
340
- itemId,
341
- price: price.toString(),
342
- sellerKiosk,
343
- policyId: policy.id,
344
- transferRequest,
345
- purchasedItem,
346
- kiosk: this.kiosk,
347
- kioskCap: this.kioskCap,
348
- extraArgs: extraArgs || {},
349
- kioskClient: this.kioskClient
350
- });
351
- }
352
- (0, import_transfer_policy.confirmRequest)(this.transaction, itemType, policy.id, transferRequest);
353
- if (canTransferOutsideKiosk) this.place({ itemType, item: purchasedItem });
354
- return this;
355
- }
356
- /**
357
- * A function to setup the client using an existing `ownerCap`,
358
- * as return from the `kioskClient.getOwnedKiosks` function.
359
- * @param cap `KioskOwnerCap` object as returned from `getOwnedKiosks` SDK call.
360
- */
361
- setCap(cap) {
362
- __privateMethod(this, _KioskTransaction_instances, validateFinalizedStatus_fn).call(this);
363
- this.kiosk = this.transaction.object(cap.kioskId);
364
- if (!cap.isPersonal) {
365
- this.kioskCap = this.transaction.object(cap.objectId);
366
- return;
367
- }
368
- return __privateMethod(this, _KioskTransaction_instances, borrowFromPersonalCap_fn).call(this, cap.objectId);
369
- }
370
- /**
371
- * A function that ends up the kiosk building tx & returns the `kioskOwnerCap` back to the
372
- * `PersonalKioskCap`, in case we are operating on a personal kiosk.
373
- * It will also share the `kiosk` if it's not shared, and finalize the transfer of the personal cap if it's pending.
374
- */
375
- finalize() {
376
- __privateMethod(this, _KioskTransaction_instances, validateKioskIsSet_fn).call(this);
377
- if (__privateGet(this, _pendingShare)) this.share();
378
- if (!__privateGet(this, _personalCap)) {
379
- if (__privateGet(this, _pendingTransfer))
380
- throw new Error(
381
- "You need to transfer the `kioskOwnerCap` by calling `shareAndTransferCap()` before wrap"
382
- );
383
- return;
384
- }
385
- const packageId = this.kioskClient.getRulePackageId("personalKioskRulePackageId");
386
- if (__privateGet(this, _promise)) {
387
- this.transaction.moveCall({
388
- target: `${packageId}::personal_kiosk::return_val`,
389
- arguments: [__privateGet(this, _personalCap), this.transaction.object(this.kioskCap), __privateGet(this, _promise)]
390
- });
391
- }
392
- if (__privateGet(this, _pendingTransfer))
393
- (0, import_personal_kiosk.transferPersonalCapTx)(this.transaction, __privateGet(this, _personalCap), packageId);
394
- __privateSet(this, _finalized, true);
395
- }
396
- // Some setters in case we want custom behavior.
397
- setKioskCap(cap) {
398
- __privateMethod(this, _KioskTransaction_instances, validateFinalizedStatus_fn).call(this);
399
- this.kioskCap = cap;
400
- return this;
401
- }
402
- setKiosk(kiosk) {
403
- __privateMethod(this, _KioskTransaction_instances, validateFinalizedStatus_fn).call(this);
404
- this.kiosk = kiosk;
405
- return this;
406
- }
407
- // Some getters
408
- /*
409
- * Returns the active transaction's kiosk, or undefined if `setCap` or `create()` hasn't been called yet.
410
- */
411
- getKiosk() {
412
- __privateMethod(this, _KioskTransaction_instances, validateFinalizedStatus_fn).call(this);
413
- if (!this.kiosk) throw new Error("Kiosk is not set.");
414
- return this.kiosk;
415
- }
416
- /*
417
- * Returns the active transaction's kioskOwnerCap, or undefined if `setCap` or `create()` hasn't been called yet.
418
- */
419
- getKioskCap() {
420
- __privateMethod(this, _KioskTransaction_instances, validateFinalizedStatus_fn).call(this);
421
- if (!this.kioskCap) throw new Error("Kiosk cap is not set");
422
- return this.kioskCap;
423
- }
424
- }
425
- _pendingShare = new WeakMap();
426
- _pendingTransfer = new WeakMap();
427
- _promise = new WeakMap();
428
- _personalCap = new WeakMap();
429
- _finalized = new WeakMap();
430
- _KioskTransaction_instances = new WeakSet();
431
- /**
432
- * A function to borrow from `personalCap`.
433
- */
434
- borrowFromPersonalCap_fn = function(personalCap) {
435
- const [kioskCap, promise] = this.transaction.moveCall({
436
- target: `${this.kioskClient.getRulePackageId(
437
- "personalKioskRulePackageId"
438
- )}::personal_kiosk::borrow_val`,
439
- arguments: [this.transaction.object(personalCap)]
440
- });
441
- this.kioskCap = kioskCap;
442
- __privateSet(this, _personalCap, this.transaction.object(personalCap));
443
- __privateSet(this, _promise, promise);
444
- return this;
445
- };
446
- setPendingStatuses_fn = function({ share, transfer }) {
447
- if (transfer !== void 0) __privateSet(this, _pendingTransfer, transfer);
448
- if (share !== void 0) __privateSet(this, _pendingShare, share);
449
- };
450
- validateKioskIsSet_fn = function() {
451
- __privateMethod(this, _KioskTransaction_instances, validateFinalizedStatus_fn).call(this);
452
- if (!this.kiosk || !this.kioskCap)
453
- throw new Error(
454
- "You need to initialize the client by either supplying an existing owner cap or by creating a new by calling `.create()`"
455
- );
456
- };
457
- // Validates that `finalize`
458
- validateFinalizedStatus_fn = function() {
459
- if (__privateGet(this, _finalized))
460
- throw new Error("You can't add more transactions to a finalized kiosk transaction.");
461
- };
462
- //# sourceMappingURL=kiosk-transaction.js.map