@zofai/zo-sdk 0.1.92

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 (275) hide show
  1. package/.claude/settings.local.json +9 -0
  2. package/.gitattributes +4 -0
  3. package/.prettierrc.js +9 -0
  4. package/README.md +28 -0
  5. package/dist/abstract/BaseAPI.cjs +206 -0
  6. package/dist/abstract/BaseAPI.cjs.map +1 -0
  7. package/dist/abstract/BaseAPI.d.cts +172 -0
  8. package/dist/abstract/BaseAPI.d.cts.map +1 -0
  9. package/dist/abstract/BaseAPI.d.mts +172 -0
  10. package/dist/abstract/BaseAPI.d.mts.map +1 -0
  11. package/dist/abstract/BaseAPI.mjs +202 -0
  12. package/dist/abstract/BaseAPI.mjs.map +1 -0
  13. package/dist/abstract/BaseDataAPI.cjs +140 -0
  14. package/dist/abstract/BaseDataAPI.cjs.map +1 -0
  15. package/dist/abstract/BaseDataAPI.d.cts +89 -0
  16. package/dist/abstract/BaseDataAPI.d.cts.map +1 -0
  17. package/dist/abstract/BaseDataAPI.d.mts +89 -0
  18. package/dist/abstract/BaseDataAPI.d.mts.map +1 -0
  19. package/dist/abstract/BaseDataAPI.mjs +136 -0
  20. package/dist/abstract/BaseDataAPI.mjs.map +1 -0
  21. package/dist/abstract/index.cjs +12 -0
  22. package/dist/abstract/index.cjs.map +1 -0
  23. package/dist/abstract/index.d.cts +7 -0
  24. package/dist/abstract/index.d.cts.map +1 -0
  25. package/dist/abstract/index.d.mts +7 -0
  26. package/dist/abstract/index.d.mts.map +1 -0
  27. package/dist/abstract/index.mjs +7 -0
  28. package/dist/abstract/index.mjs.map +1 -0
  29. package/dist/api.cjs +779 -0
  30. package/dist/api.cjs.map +1 -0
  31. package/dist/api.d.cts +75 -0
  32. package/dist/api.d.cts.map +1 -0
  33. package/dist/api.d.mts +75 -0
  34. package/dist/api.d.mts.map +1 -0
  35. package/dist/api.mjs +775 -0
  36. package/dist/api.mjs.map +1 -0
  37. package/dist/bcs.cjs +42 -0
  38. package/dist/bcs.cjs.map +1 -0
  39. package/dist/bcs.d.cts +91 -0
  40. package/dist/bcs.d.cts.map +1 -0
  41. package/dist/bcs.d.mts +91 -0
  42. package/dist/bcs.d.mts.map +1 -0
  43. package/dist/bcs.mjs +39 -0
  44. package/dist/bcs.mjs.map +1 -0
  45. package/dist/consts/deployments-shared-mainnet.json +50 -0
  46. package/dist/consts/deployments-shared-testnet.json +45 -0
  47. package/dist/consts/deployments-slp-mainnet.json +600 -0
  48. package/dist/consts/deployments-slp-testnet.json +87 -0
  49. package/dist/consts/deployments-usdz-mainnet.json +494 -0
  50. package/dist/consts/deployments-usdz-testnet.json +98 -0
  51. package/dist/consts/deployments-zbtcvc-mainnet.json +180 -0
  52. package/dist/consts/deployments-zlp-mainnet.json +791 -0
  53. package/dist/consts/deployments-zlp-testnet.json +76 -0
  54. package/dist/consts/index.cjs +200 -0
  55. package/dist/consts/index.cjs.map +1 -0
  56. package/dist/consts/index.d.cts +157 -0
  57. package/dist/consts/index.d.cts.map +1 -0
  58. package/dist/consts/index.d.mts +157 -0
  59. package/dist/consts/index.d.mts.map +1 -0
  60. package/dist/consts/index.mjs +189 -0
  61. package/dist/consts/index.mjs.map +1 -0
  62. package/dist/consts/price_id_to_object_id.mainnet.json +56 -0
  63. package/dist/consts/price_id_to_object_id.testnet.json +17 -0
  64. package/dist/data.cjs +919 -0
  65. package/dist/data.cjs.map +1 -0
  66. package/dist/data.d.cts +235 -0
  67. package/dist/data.d.cts.map +1 -0
  68. package/dist/data.d.mts +235 -0
  69. package/dist/data.d.mts.map +1 -0
  70. package/dist/data.mjs +915 -0
  71. package/dist/data.mjs.map +1 -0
  72. package/dist/factory/SDKFactory.cjs +228 -0
  73. package/dist/factory/SDKFactory.cjs.map +1 -0
  74. package/dist/factory/SDKFactory.d.cts +84 -0
  75. package/dist/factory/SDKFactory.d.cts.map +1 -0
  76. package/dist/factory/SDKFactory.d.mts +84 -0
  77. package/dist/factory/SDKFactory.d.mts.map +1 -0
  78. package/dist/factory/SDKFactory.mjs +222 -0
  79. package/dist/factory/SDKFactory.mjs.map +1 -0
  80. package/dist/implementations/SLPAPI.cjs +1794 -0
  81. package/dist/implementations/SLPAPI.cjs.map +1 -0
  82. package/dist/implementations/SLPAPI.d.cts +183 -0
  83. package/dist/implementations/SLPAPI.d.cts.map +1 -0
  84. package/dist/implementations/SLPAPI.d.mts +183 -0
  85. package/dist/implementations/SLPAPI.d.mts.map +1 -0
  86. package/dist/implementations/SLPAPI.mjs +1790 -0
  87. package/dist/implementations/SLPAPI.mjs.map +1 -0
  88. package/dist/implementations/SLPDataAPI.cjs +1384 -0
  89. package/dist/implementations/SLPDataAPI.cjs.map +1 -0
  90. package/dist/implementations/SLPDataAPI.d.cts +158 -0
  91. package/dist/implementations/SLPDataAPI.d.cts.map +1 -0
  92. package/dist/implementations/SLPDataAPI.d.mts +158 -0
  93. package/dist/implementations/SLPDataAPI.d.mts.map +1 -0
  94. package/dist/implementations/SLPDataAPI.mjs +1380 -0
  95. package/dist/implementations/SLPDataAPI.mjs.map +1 -0
  96. package/dist/implementations/USDZAPI.cjs +1676 -0
  97. package/dist/implementations/USDZAPI.cjs.map +1 -0
  98. package/dist/implementations/USDZAPI.d.cts +180 -0
  99. package/dist/implementations/USDZAPI.d.cts.map +1 -0
  100. package/dist/implementations/USDZAPI.d.mts +180 -0
  101. package/dist/implementations/USDZAPI.d.mts.map +1 -0
  102. package/dist/implementations/USDZAPI.mjs +1672 -0
  103. package/dist/implementations/USDZAPI.mjs.map +1 -0
  104. package/dist/implementations/USDZDataAPI.cjs +1209 -0
  105. package/dist/implementations/USDZDataAPI.cjs.map +1 -0
  106. package/dist/implementations/USDZDataAPI.d.cts +191 -0
  107. package/dist/implementations/USDZDataAPI.d.cts.map +1 -0
  108. package/dist/implementations/USDZDataAPI.d.mts +191 -0
  109. package/dist/implementations/USDZDataAPI.d.mts.map +1 -0
  110. package/dist/implementations/USDZDataAPI.mjs +1205 -0
  111. package/dist/implementations/USDZDataAPI.mjs.map +1 -0
  112. package/dist/implementations/ZBTCVCAPI.cjs +906 -0
  113. package/dist/implementations/ZBTCVCAPI.cjs.map +1 -0
  114. package/dist/implementations/ZBTCVCAPI.d.cts +107 -0
  115. package/dist/implementations/ZBTCVCAPI.d.cts.map +1 -0
  116. package/dist/implementations/ZBTCVCAPI.d.mts +107 -0
  117. package/dist/implementations/ZBTCVCAPI.d.mts.map +1 -0
  118. package/dist/implementations/ZBTCVCAPI.mjs +902 -0
  119. package/dist/implementations/ZBTCVCAPI.mjs.map +1 -0
  120. package/dist/implementations/ZBTCVCDataAPI.cjs +829 -0
  121. package/dist/implementations/ZBTCVCDataAPI.cjs.map +1 -0
  122. package/dist/implementations/ZBTCVCDataAPI.d.cts +94 -0
  123. package/dist/implementations/ZBTCVCDataAPI.d.cts.map +1 -0
  124. package/dist/implementations/ZBTCVCDataAPI.d.mts +94 -0
  125. package/dist/implementations/ZBTCVCDataAPI.d.mts.map +1 -0
  126. package/dist/implementations/ZBTCVCDataAPI.mjs +825 -0
  127. package/dist/implementations/ZBTCVCDataAPI.mjs.map +1 -0
  128. package/dist/implementations/ZLPAPI.cjs +1948 -0
  129. package/dist/implementations/ZLPAPI.cjs.map +1 -0
  130. package/dist/implementations/ZLPAPI.d.cts +192 -0
  131. package/dist/implementations/ZLPAPI.d.cts.map +1 -0
  132. package/dist/implementations/ZLPAPI.d.mts +192 -0
  133. package/dist/implementations/ZLPAPI.d.mts.map +1 -0
  134. package/dist/implementations/ZLPAPI.mjs +1944 -0
  135. package/dist/implementations/ZLPAPI.mjs.map +1 -0
  136. package/dist/implementations/ZLPDataAPI.cjs +1267 -0
  137. package/dist/implementations/ZLPDataAPI.cjs.map +1 -0
  138. package/dist/implementations/ZLPDataAPI.d.cts +193 -0
  139. package/dist/implementations/ZLPDataAPI.d.cts.map +1 -0
  140. package/dist/implementations/ZLPDataAPI.d.mts +193 -0
  141. package/dist/implementations/ZLPDataAPI.d.mts.map +1 -0
  142. package/dist/implementations/ZLPDataAPI.mjs +1263 -0
  143. package/dist/implementations/ZLPDataAPI.mjs.map +1 -0
  144. package/dist/implementations/index.cjs +26 -0
  145. package/dist/implementations/index.cjs.map +1 -0
  146. package/dist/implementations/index.d.cts +13 -0
  147. package/dist/implementations/index.d.cts.map +1 -0
  148. package/dist/implementations/index.d.mts +13 -0
  149. package/dist/implementations/index.d.mts.map +1 -0
  150. package/dist/implementations/index.mjs +15 -0
  151. package/dist/implementations/index.mjs.map +1 -0
  152. package/dist/index.cjs +69 -0
  153. package/dist/index.cjs.map +1 -0
  154. package/dist/index.d.cts +51 -0
  155. package/dist/index.d.cts.map +1 -0
  156. package/dist/index.d.mts +51 -0
  157. package/dist/index.d.mts.map +1 -0
  158. package/dist/index.mjs +51 -0
  159. package/dist/index.mjs.map +1 -0
  160. package/dist/interfaces/base.cjs +7 -0
  161. package/dist/interfaces/base.cjs.map +1 -0
  162. package/dist/interfaces/base.d.cts +346 -0
  163. package/dist/interfaces/base.d.cts.map +1 -0
  164. package/dist/interfaces/base.d.mts +346 -0
  165. package/dist/interfaces/base.d.mts.map +1 -0
  166. package/dist/interfaces/base.mjs +6 -0
  167. package/dist/interfaces/base.mjs.map +1 -0
  168. package/dist/interfaces/index.cjs +31 -0
  169. package/dist/interfaces/index.cjs.map +1 -0
  170. package/dist/interfaces/index.d.cts +15 -0
  171. package/dist/interfaces/index.d.cts.map +1 -0
  172. package/dist/interfaces/index.d.mts +15 -0
  173. package/dist/interfaces/index.d.mts.map +1 -0
  174. package/dist/interfaces/index.mjs +15 -0
  175. package/dist/interfaces/index.mjs.map +1 -0
  176. package/dist/interfaces/slp.cjs +7 -0
  177. package/dist/interfaces/slp.cjs.map +1 -0
  178. package/dist/interfaces/slp.d.cts +179 -0
  179. package/dist/interfaces/slp.d.cts.map +1 -0
  180. package/dist/interfaces/slp.d.mts +179 -0
  181. package/dist/interfaces/slp.d.mts.map +1 -0
  182. package/dist/interfaces/slp.mjs +6 -0
  183. package/dist/interfaces/slp.mjs.map +1 -0
  184. package/dist/interfaces/usdz.cjs +7 -0
  185. package/dist/interfaces/usdz.cjs.map +1 -0
  186. package/dist/interfaces/usdz.d.cts +104 -0
  187. package/dist/interfaces/usdz.d.cts.map +1 -0
  188. package/dist/interfaces/usdz.d.mts +104 -0
  189. package/dist/interfaces/usdz.d.mts.map +1 -0
  190. package/dist/interfaces/usdz.mjs +6 -0
  191. package/dist/interfaces/usdz.mjs.map +1 -0
  192. package/dist/interfaces/zbtcvc.cjs +7 -0
  193. package/dist/interfaces/zbtcvc.cjs.map +1 -0
  194. package/dist/interfaces/zbtcvc.d.cts +64 -0
  195. package/dist/interfaces/zbtcvc.d.cts.map +1 -0
  196. package/dist/interfaces/zbtcvc.d.mts +64 -0
  197. package/dist/interfaces/zbtcvc.d.mts.map +1 -0
  198. package/dist/interfaces/zbtcvc.mjs +6 -0
  199. package/dist/interfaces/zbtcvc.mjs.map +1 -0
  200. package/dist/interfaces/zlp.cjs +7 -0
  201. package/dist/interfaces/zlp.cjs.map +1 -0
  202. package/dist/interfaces/zlp.d.cts +114 -0
  203. package/dist/interfaces/zlp.d.cts.map +1 -0
  204. package/dist/interfaces/zlp.d.mts +114 -0
  205. package/dist/interfaces/zlp.d.mts.map +1 -0
  206. package/dist/interfaces/zlp.mjs +6 -0
  207. package/dist/interfaces/zlp.mjs.map +1 -0
  208. package/dist/oracle.cjs +118 -0
  209. package/dist/oracle.cjs.map +1 -0
  210. package/dist/oracle.d.cts +25 -0
  211. package/dist/oracle.d.cts.map +1 -0
  212. package/dist/oracle.d.mts +25 -0
  213. package/dist/oracle.d.mts.map +1 -0
  214. package/dist/oracle.mjs +114 -0
  215. package/dist/oracle.mjs.map +1 -0
  216. package/dist/utils.cjs +129 -0
  217. package/dist/utils.cjs.map +1 -0
  218. package/dist/utils.d.cts +44 -0
  219. package/dist/utils.d.cts.map +1 -0
  220. package/dist/utils.d.mts +44 -0
  221. package/dist/utils.d.mts.map +1 -0
  222. package/dist/utils.mjs +115 -0
  223. package/dist/utils.mjs.map +1 -0
  224. package/docs/SUMMARY.md +10 -0
  225. package/docs/api-reference.md +32 -0
  226. package/docs/architecture.md +14 -0
  227. package/docs/common-operations.md +52 -0
  228. package/docs/error-handling.md +17 -0
  229. package/docs/getting-started.md +60 -0
  230. package/docs/introduction.md +15 -0
  231. package/docs/lp-specific-features.md +96 -0
  232. package/docs/type-safety.md +29 -0
  233. package/eslint.config.mjs +18 -0
  234. package/package.json +42 -0
  235. package/src/abstract/BaseAPI.ts +575 -0
  236. package/src/abstract/BaseDataAPI.ts +207 -0
  237. package/src/abstract/index.ts +7 -0
  238. package/src/api.ts +1100 -0
  239. package/src/bcs.ts +45 -0
  240. package/src/consts/deployments-shared-mainnet.json +50 -0
  241. package/src/consts/deployments-shared-testnet.json +45 -0
  242. package/src/consts/deployments-slp-mainnet.json +600 -0
  243. package/src/consts/deployments-slp-testnet.json +87 -0
  244. package/src/consts/deployments-usdz-mainnet.json +494 -0
  245. package/src/consts/deployments-usdz-testnet.json +98 -0
  246. package/src/consts/deployments-zbtcvc-mainnet.json +180 -0
  247. package/src/consts/deployments-zlp-mainnet.json +791 -0
  248. package/src/consts/deployments-zlp-testnet.json +76 -0
  249. package/src/consts/index.ts +345 -0
  250. package/src/consts/price_id_to_object_id.mainnet.json +56 -0
  251. package/src/consts/price_id_to_object_id.testnet.json +17 -0
  252. package/src/data.ts +1279 -0
  253. package/src/factory/SDKFactory.ts +340 -0
  254. package/src/implementations/SLPAPI.ts +2722 -0
  255. package/src/implementations/SLPDataAPI.ts +1839 -0
  256. package/src/implementations/USDZAPI.ts +2488 -0
  257. package/src/implementations/USDZDataAPI.ts +1548 -0
  258. package/src/implementations/ZBTCVCAPI.ts +1337 -0
  259. package/src/implementations/ZBTCVCDataAPI.ts +993 -0
  260. package/src/implementations/ZLPAPI.ts +2888 -0
  261. package/src/implementations/ZLPDataAPI.ts +1603 -0
  262. package/src/implementations/index.ts +16 -0
  263. package/src/index.ts +58 -0
  264. package/src/interfaces/base.ts +838 -0
  265. package/src/interfaces/index.ts +50 -0
  266. package/src/interfaces/slp.ts +268 -0
  267. package/src/interfaces/usdz.ts +181 -0
  268. package/src/interfaces/zbtcvc.ts +116 -0
  269. package/src/interfaces/zlp.ts +244 -0
  270. package/src/oracle.ts +153 -0
  271. package/src/utils.ts +168 -0
  272. package/tests/api.test.ts +219 -0
  273. package/tests/data.test.ts +156 -0
  274. package/tests/oracle.test.ts +33 -0
  275. package/tsconfig.json +22 -0
@@ -0,0 +1,1948 @@
1
+ "use strict";
2
+ /**
3
+ * ZLP API implementation
4
+ * Implements ZLP-specific trading and transaction methods
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.ZLPAPI = void 0;
8
+ const kiosk_1 = require("@mysten/kiosk");
9
+ const transactions_1 = require("@mysten/sui/transactions");
10
+ const utils_1 = require("@mysten/sui/utils");
11
+ const abstract_1 = require("../abstract/index.cjs");
12
+ const consts_1 = require("../consts/index.cjs");
13
+ const utils_2 = require("../utils.cjs");
14
+ const ZLPDataAPI_1 = require("./ZLPDataAPI.cjs");
15
+ class ZLPAPI extends abstract_1.BaseAPI {
16
+ constructor(network, provider, apiEndpoint, connectionURL) {
17
+ super(network, provider, apiEndpoint, connectionURL, consts_1.LPToken.ZLP);
18
+ this.dataAPI = new ZLPDataAPI_1.ZLPDataAPI(network, provider, apiEndpoint, connectionURL);
19
+ }
20
+ calcPositionReserveFeeAmount(_position) {
21
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
22
+ }
23
+ calcPositionFundingFeeValue(_position) {
24
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
25
+ }
26
+ /**
27
+ * Deposits collateral into ZLP vault
28
+ */
29
+ async deposit(coin, coinObjects, amount, minAmountOut = 0, referralAddress, sender, sponsoredTx, suiCoinObjectsForPythUpdate) {
30
+ let tx = new transactions_1.Transaction();
31
+ // Add referral if needed
32
+ if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
33
+ tx = await this.addReferral(referralAddress, tx);
34
+ }
35
+ // Initialize oracle transaction
36
+ const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
37
+ // Handle sponsored transaction case
38
+ if (sponsoredTx) {
39
+ const suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
40
+ tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject);
41
+ // Process deposit coins
42
+ const depositObject = coin === 'sui'
43
+ ? tx.splitCoins(suiCoinObject, [tx.pure.u64(amount)])[0]
44
+ : tx.splitCoins(this.processCoins(tx, coin, coinObjects, true), [tx.pure.u64(amount)])[0];
45
+ const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
46
+ tx.moveCall({
47
+ target: `${this.consts.zoCore.upgradedPackage}::market::deposit`,
48
+ typeArguments: [`${this.consts.zoCore.package}::zlp::ZLP`, this.consts.coins[coin].module],
49
+ arguments: [
50
+ tx.object(this.consts.zoCore.market),
51
+ tx.object(this.consts.zoCore.rebaseFeeModel),
52
+ depositObject,
53
+ tx.pure.u64(minAmountOut),
54
+ vaultsValuation,
55
+ symbolsValuation,
56
+ ],
57
+ });
58
+ return tx;
59
+ }
60
+ // Handle non-sponsored transaction case
61
+ tx = await this.initOracleTxb(pythFeederKeys, tx);
62
+ const depositObject = tx.splitCoins(this.processCoins(tx, coin, coinObjects, false), [tx.pure.u64(amount)])[0];
63
+ const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
64
+ tx.moveCall({
65
+ target: `${this.consts.zoCore.upgradedPackage}::market::deposit`,
66
+ typeArguments: [
67
+ `${this.consts.zoCore.package}::zlp::ZLP`,
68
+ this.consts.coins[coin].module,
69
+ ],
70
+ arguments: [
71
+ tx.object(this.consts.zoCore.market),
72
+ tx.object(this.consts.zoCore.rebaseFeeModel),
73
+ depositObject,
74
+ tx.pure.u64(minAmountOut),
75
+ vaultsValuation,
76
+ symbolsValuation,
77
+ ],
78
+ });
79
+ return tx;
80
+ }
81
+ /**
82
+ * Deposits collateral into ZLP vault and returns a coin
83
+ */
84
+ async depositPtb(coin, coinObjects, amount, minAmountOut = 0, referralAddress, sender, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
85
+ if (!tx) {
86
+ tx = new transactions_1.Transaction();
87
+ }
88
+ // Add referral if needed
89
+ if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
90
+ tx = await this.addReferral(referralAddress, tx);
91
+ }
92
+ // Initialize oracle transaction
93
+ const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
94
+ // Handle sponsored transaction case
95
+ if (sponsoredTx) {
96
+ const suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
97
+ tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject);
98
+ // Process deposit coins
99
+ const depositObject = coin === 'sui'
100
+ ? tx.splitCoins(suiCoinObject, [tx.pure.u64(amount)])[0]
101
+ : tx.splitCoins(this.processCoins(tx, coin, coinObjects, true), [tx.pure.u64(amount)])[0];
102
+ const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
103
+ const [mintedCoin] = tx.moveCall({
104
+ target: `${this.consts.zoCore.upgradedPackage}::market::deposit_ptb`,
105
+ typeArguments: [`${this.consts.zoCore.package}::zlp::ZLP`, this.consts.coins[coin].module],
106
+ arguments: [
107
+ tx.object(this.consts.zoCore.market),
108
+ tx.object(this.consts.zoCore.rebaseFeeModel),
109
+ depositObject,
110
+ tx.pure.u64(minAmountOut),
111
+ vaultsValuation,
112
+ symbolsValuation,
113
+ ],
114
+ });
115
+ return mintedCoin;
116
+ }
117
+ // Handle non-sponsored transaction case
118
+ tx = await this.initOracleTxb(pythFeederKeys, tx);
119
+ const depositObject = tx.splitCoins(this.processCoins(tx, coin, coinObjects, false), [tx.pure.u64(amount)])[0];
120
+ const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
121
+ const [mintedCoin] = tx.moveCall({
122
+ target: `${this.consts.zoCore.upgradedPackage}::market::deposit_ptb`,
123
+ typeArguments: [
124
+ `${this.consts.zoCore.package}::zlp::ZLP`,
125
+ this.consts.coins[coin].module,
126
+ ],
127
+ arguments: [
128
+ tx.object(this.consts.zoCore.market),
129
+ tx.object(this.consts.zoCore.rebaseFeeModel),
130
+ depositObject,
131
+ tx.pure.u64(minAmountOut),
132
+ vaultsValuation,
133
+ symbolsValuation,
134
+ ],
135
+ });
136
+ return mintedCoin;
137
+ }
138
+ async depositWithPtb(coin, depositObject, minAmountOut = 0, referralAddress, sender, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
139
+ if (!tx) {
140
+ tx = new transactions_1.Transaction();
141
+ }
142
+ // Add referral if needed
143
+ if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
144
+ tx = await this.addReferral(referralAddress, tx);
145
+ }
146
+ // Initialize oracle transaction
147
+ const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
148
+ // Handle sponsored transaction case
149
+ if (sponsoredTx) {
150
+ const suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
151
+ tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject);
152
+ const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
153
+ tx.moveCall({
154
+ target: `${this.consts.zoCore.upgradedPackage}::market::deposit`,
155
+ typeArguments: [`${this.consts.zoCore.package}::zlp::ZLP`, this.consts.coins[coin].module],
156
+ arguments: [
157
+ tx.object(this.consts.zoCore.market),
158
+ tx.object(this.consts.zoCore.rebaseFeeModel),
159
+ depositObject,
160
+ tx.pure.u64(minAmountOut),
161
+ vaultsValuation,
162
+ symbolsValuation,
163
+ ],
164
+ });
165
+ return tx;
166
+ }
167
+ // Handle non-sponsored transaction case
168
+ tx = await this.initOracleTxb(pythFeederKeys, tx);
169
+ const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
170
+ tx.moveCall({
171
+ target: `${this.consts.zoCore.upgradedPackage}::market::deposit`,
172
+ typeArguments: [
173
+ `${this.consts.zoCore.package}::zlp::ZLP`,
174
+ this.consts.coins[coin].module,
175
+ ],
176
+ arguments: [
177
+ tx.object(this.consts.zoCore.market),
178
+ tx.object(this.consts.zoCore.rebaseFeeModel),
179
+ depositObject,
180
+ tx.pure.u64(minAmountOut),
181
+ vaultsValuation,
182
+ symbolsValuation,
183
+ ],
184
+ });
185
+ return tx;
186
+ }
187
+ /**
188
+ * Withdraws collateral from ZLP vault
189
+ */
190
+ async withdraw(coin, lpCoinObjects, amount, minAmountOut = 0, sponsoredTx, suiCoinObjectsForPythUpdate) {
191
+ let tx = new transactions_1.Transaction();
192
+ // Initialize oracle transaction
193
+ const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
194
+ if (sponsoredTx) {
195
+ const suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
196
+ tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject);
197
+ }
198
+ else {
199
+ tx = await this.initOracleTxb(pythFeederKeys, tx);
200
+ }
201
+ const zlpCoinObject = this.processCoins(tx, 'zlp', lpCoinObjects, false);
202
+ const [withdrawObject] = tx.splitCoins(zlpCoinObject, [tx.pure.u64(amount)]);
203
+ const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
204
+ tx.moveCall({
205
+ target: `${this.consts.zoCore.upgradedPackage}::market::withdraw`,
206
+ typeArguments: [
207
+ `${this.consts.zoCore.package}::zlp::ZLP`,
208
+ this.consts.coins[coin].module,
209
+ ],
210
+ arguments: [
211
+ tx.object(this.consts.zoCore.market),
212
+ tx.object(this.consts.zoCore.rebaseFeeModel),
213
+ withdrawObject,
214
+ tx.pure.u64(minAmountOut),
215
+ vaultsValuation,
216
+ symbolsValuation,
217
+ ],
218
+ });
219
+ return tx;
220
+ }
221
+ /**
222
+ * Withdraws LP coin object from ZLP vault
223
+ */
224
+ async withdrawLpCoinObject(coin, lpCoinObject, minAmountOut = 0, tx) {
225
+ if (!tx) {
226
+ tx = new transactions_1.Transaction();
227
+ }
228
+ // Initialize oracle transaction
229
+ const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
230
+ tx = await this.initOracleTxb(pythFeederKeys, tx);
231
+ const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
232
+ tx.moveCall({
233
+ target: `${this.consts.zoCore.upgradedPackage}::market::withdraw`,
234
+ typeArguments: [
235
+ `${this.consts.zoCore.package}::zlp::ZLP`,
236
+ this.consts.coins[coin].module,
237
+ ],
238
+ arguments: [
239
+ tx.object(this.consts.zoCore.market),
240
+ tx.object(this.consts.zoCore.rebaseFeeModel),
241
+ lpCoinObject,
242
+ tx.pure.u64(minAmountOut),
243
+ vaultsValuation,
244
+ symbolsValuation,
245
+ ],
246
+ });
247
+ return tx;
248
+ }
249
+ async withdrawPtb(coin, lpCoinObjects, amount, minAmountOut = 0, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
250
+ if (!tx) {
251
+ tx = new transactions_1.Transaction();
252
+ }
253
+ // Initialize oracle transaction
254
+ const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
255
+ if (sponsoredTx) {
256
+ const suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
257
+ tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject);
258
+ }
259
+ else {
260
+ tx = await this.initOracleTxb(pythFeederKeys, tx);
261
+ }
262
+ const zlpCoinObject = this.processCoins(tx, 'zlp', lpCoinObjects, false);
263
+ const [withdrawObject] = tx.splitCoins(zlpCoinObject, [tx.pure.u64(amount)]);
264
+ const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
265
+ const [withdrawCoin] = tx.moveCall({
266
+ target: `${this.consts.zoCore.upgradedPackage}::market::withdraw_ptb`,
267
+ typeArguments: [
268
+ `${this.consts.zoCore.package}::zlp::ZLP`,
269
+ this.consts.coins[coin].module,
270
+ ],
271
+ arguments: [
272
+ tx.object(this.consts.zoCore.market),
273
+ tx.object(this.consts.zoCore.rebaseFeeModel),
274
+ withdrawObject,
275
+ tx.pure.u64(minAmountOut),
276
+ vaultsValuation,
277
+ symbolsValuation,
278
+ ],
279
+ });
280
+ return withdrawCoin;
281
+ }
282
+ /**
283
+ * Stakes ZLP tokens in ZO staking pools
284
+ */
285
+ stake(lpCoinObjects, amount, pool, tx) {
286
+ if (!tx) {
287
+ tx = new transactions_1.Transaction();
288
+ }
289
+ const coinObject = this.processCoins(tx, 'zlp', lpCoinObjects);
290
+ const [depositObject] = tx.splitCoins(coinObject, [tx.pure.u64(amount)]);
291
+ tx.moveCall({
292
+ target: `${this.sharedConfig.zoStaking.upgradedPackage}::pool::deposit`,
293
+ typeArguments: [
294
+ `${this.consts.zoCore.package}::zlp::ZLP`,
295
+ `${this.consts.coins.sui.module}`,
296
+ ],
297
+ arguments: [
298
+ tx.object(pool),
299
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
300
+ depositObject,
301
+ ],
302
+ });
303
+ return tx;
304
+ }
305
+ /**
306
+ * Stakes ZLP tokens using coin object only (PTB)
307
+ */
308
+ stakeCoinObject(coinObject, pool, tx) {
309
+ if (!tx) {
310
+ tx = new transactions_1.Transaction();
311
+ }
312
+ tx.moveCall({
313
+ target: `${this.sharedConfig.zoStaking.upgradedPackage}::pool::deposit`,
314
+ typeArguments: [
315
+ `${this.consts.zoCore.package}::zlp::ZLP`,
316
+ `${this.consts.coins.sui.module}`,
317
+ ],
318
+ arguments: [
319
+ tx.object(pool),
320
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
321
+ coinObject,
322
+ ],
323
+ });
324
+ return tx;
325
+ }
326
+ /**
327
+ * Unstakes ZLP tokens from ZO staking pools
328
+ */
329
+ unstake(credentials, amount, pool, tx) {
330
+ let unstakeAmount = amount;
331
+ if (!tx) {
332
+ tx = new transactions_1.Transaction();
333
+ }
334
+ for (const credential of credentials) {
335
+ const withdrawAmount = (() => {
336
+ const min = (a, b) => a < b ? a : b;
337
+ return min(unstakeAmount, credential.amount);
338
+ })();
339
+ unstakeAmount -= withdrawAmount;
340
+ tx.moveCall({
341
+ target: `${this.sharedConfig.zoStaking.upgradedPackage}::pool::withdraw`,
342
+ typeArguments: [
343
+ `${this.consts.zoCore.package}::zlp::ZLP`,
344
+ `${this.consts.coins.sui.module}`,
345
+ ],
346
+ arguments: [
347
+ tx.object(pool),
348
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
349
+ tx.object(credential.id),
350
+ tx.pure.u64(withdrawAmount),
351
+ ],
352
+ });
353
+ if (credential.amount === BigInt(0)) {
354
+ tx.moveCall({
355
+ target: `${this.sharedConfig.zoStaking.upgradedPackage}::pool::clear_empty_credential`,
356
+ typeArguments: [
357
+ `${this.consts.zoCore.package}::zlp::ZLP`,
358
+ `${this.consts.coins.sui.module}`,
359
+ ],
360
+ arguments: [tx.object(credential.id)],
361
+ });
362
+ }
363
+ }
364
+ return tx;
365
+ }
366
+ /**
367
+ * Unstakes ZLP tokens from ZO staking pools and return Coins
368
+ */
369
+ unstakeToCoins(credentials, amount, pool, tx) {
370
+ let unstakeAmount = amount;
371
+ const withdrawnCoinObjects = [];
372
+ for (const credential of credentials) {
373
+ const withdrawAmount = (() => {
374
+ const min = (a, b) => a < b ? a : b;
375
+ return min(unstakeAmount, credential.amount);
376
+ })();
377
+ unstakeAmount -= withdrawAmount;
378
+ const [withdrawnCoin] = tx.moveCall({
379
+ target: `${this.sharedConfig.zoStaking.upgradedPackage}::pool::withdraw_ptb`,
380
+ typeArguments: [
381
+ `${this.consts.zoCore.package}::zlp::ZLP`,
382
+ `${this.consts.coins.sui.module}`,
383
+ ],
384
+ arguments: [
385
+ tx.object(pool),
386
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
387
+ tx.object(credential.id),
388
+ tx.pure.u64(withdrawAmount),
389
+ ],
390
+ });
391
+ withdrawnCoinObjects.push(withdrawnCoin);
392
+ if (credential.amount === BigInt(0)) {
393
+ tx.moveCall({
394
+ target: `${this.sharedConfig.zoStaking.upgradedPackage}::pool::clear_empty_credential`,
395
+ typeArguments: [
396
+ `${this.consts.zoCore.package}::zlp::ZLP`,
397
+ `${this.consts.coins.sui.module}`,
398
+ ],
399
+ arguments: [tx.object(credential.id)],
400
+ });
401
+ }
402
+ }
403
+ return withdrawnCoinObjects;
404
+ }
405
+ /**
406
+ * Withdraws ZLP tokens from a staking pool credential (PTB)
407
+ * Returns the withdrawn coin object for use in programmable transaction blocks
408
+ */
409
+ withdrawFromVaultPtb(pool, credential, withdrawAmount, tx) {
410
+ const [withdrawnCoin] = tx.moveCall({
411
+ target: `${this.sharedConfig.zoStaking.upgradedPackage}::pool::withdraw_ptb`,
412
+ typeArguments: [
413
+ `${this.consts.zoCore.package}::zlp::ZLP`,
414
+ `${this.consts.coins.sui.module}`,
415
+ ],
416
+ arguments: [
417
+ tx.object(pool),
418
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
419
+ tx.object(credential),
420
+ tx.pure.u64(withdrawAmount),
421
+ ],
422
+ });
423
+ return withdrawnCoin;
424
+ }
425
+ /**
426
+ * Claims rewards from a staking pool credential (PTB)
427
+ * Returns the reward coin object for use in programmable transaction blocks
428
+ */
429
+ claimRewardsPtb(pool, credential, tx) {
430
+ const [rewardCoin] = tx.moveCall({
431
+ target: `${this.sharedConfig.zoStaking.upgradedPackage}::pool::claim_rewards_ptb`,
432
+ typeArguments: [
433
+ `${this.consts.zoCore.package}::zlp::ZLP`,
434
+ `${this.consts.coins.sui.module}`,
435
+ ],
436
+ arguments: [
437
+ tx.object(pool),
438
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
439
+ tx.object(credential),
440
+ ],
441
+ });
442
+ return rewardCoin;
443
+ }
444
+ async swap(fromToken, toToken, fromAmount, fromCoinObjects, minAmountOut) {
445
+ const tx = await this.initOracleTxb(Object.keys(this.consts.zoCore.vaults));
446
+ const fromCoinObject = this.processCoins(tx, fromToken, fromCoinObjects);
447
+ const [fromDepositObject] = tx.splitCoins(fromCoinObject, [tx.pure.u64(fromAmount)]);
448
+ const vaultsValuation = this.dataAPI.valuateVaults(tx);
449
+ tx.moveCall({
450
+ target: `${this.consts.zoCore.upgradedPackage}::market::swap_v2`,
451
+ typeArguments: [
452
+ `${this.consts.zoCore.package}::zlp::ZLP`,
453
+ this.consts.coins[fromToken].module,
454
+ this.consts.coins[toToken].module,
455
+ ],
456
+ arguments: [
457
+ tx.object(this.consts.zoCore.market),
458
+ tx.object(this.consts.zoCore.rebaseFeeModel),
459
+ fromDepositObject,
460
+ tx.pure.u64(minAmountOut || 0),
461
+ vaultsValuation,
462
+ tx.object(this.consts.pythFeeder.feeder[fromToken]),
463
+ tx.object(this.consts.pythFeeder.feeder[toToken]),
464
+ ],
465
+ });
466
+ return tx;
467
+ }
468
+ /**
469
+ * Opens a new position in ZLP
470
+ */
471
+ async openPosition(collateralToken, indexToken, size, collateralAmount, coinObjects, long, reserveAmount, indexPrice, collateralPrice, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, sponsoredTx, suiCoinObjectsForPythUpdate) {
472
+ let tx = new transactions_1.Transaction();
473
+ if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
474
+ tx = await this.addReferral(referralAddress, tx);
475
+ }
476
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
477
+ const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage);
478
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
479
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
480
+ if (isLimitOrder) {
481
+ allowTrade = isIocOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
482
+ }
483
+ // Handle oracle initialization and coin processing
484
+ let suiCoinObject;
485
+ if (sponsoredTx) {
486
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
487
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
488
+ }
489
+ else {
490
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx);
491
+ }
492
+ // Process coin splitting
493
+ const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
494
+ tx.moveCall({
495
+ target: `${this.consts.zoCore.upgradedPackage}::market::open_position`,
496
+ typeArguments: [
497
+ `${this.consts.zoCore.package}::zlp::ZLP`,
498
+ this.consts.coins[collateralToken].module,
499
+ this.consts.coins[indexToken].module,
500
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
501
+ this.consts.coins[collateralToken].module,
502
+ ],
503
+ arguments: [
504
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
505
+ tx.object(this.consts.zoCore.market),
506
+ tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
507
+ tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
508
+ tx.object(this.consts.zoCore.symbols[symbol].positionConfig),
509
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
510
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
511
+ depositObject,
512
+ feeObject,
513
+ tx.pure.u8(allowTrade),
514
+ tx.pure.u64(size),
515
+ tx.pure.u64(reserveAmount),
516
+ tx.pure.u256(adjustCollateralPrice),
517
+ tx.pure.u256(adjustPrice),
518
+ ],
519
+ });
520
+ return tx;
521
+ }
522
+ /**
523
+ * Opens a new position in ZLP
524
+ */
525
+ async openPositionV2(collateralToken, indexToken, size, collateralAmount, coinObjects, long, reserveAmount, indexPrice, collateralPrice, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, sponsoredTx, suiCoinObjectsForPythUpdate) {
526
+ let tx = new transactions_1.Transaction();
527
+ if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
528
+ tx = await this.addReferral(referralAddress, tx);
529
+ }
530
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
531
+ const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage);
532
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
533
+ const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
534
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
535
+ if (isLimitOrder) {
536
+ allowTrade = isIocOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
537
+ }
538
+ // Handle oracle initialization and coin processing
539
+ let suiCoinObject;
540
+ if (sponsoredTx) {
541
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
542
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
543
+ }
544
+ else {
545
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx);
546
+ }
547
+ // Process coin splitting
548
+ const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
549
+ tx.moveCall({
550
+ target: `${this.consts.zoCore.upgradedPackage}::market::open_position_v2`,
551
+ typeArguments: [
552
+ `${this.consts.zoCore.package}::zlp::ZLP`,
553
+ this.consts.coins[collateralToken].module,
554
+ this.consts.coins[indexToken].module,
555
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
556
+ this.consts.coins[collateralToken].module,
557
+ ],
558
+ arguments: [
559
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
560
+ tx.object(this.consts.zoCore.market),
561
+ tx.object(this.consts.zoCore.symbols[symbol].positionConfig),
562
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
563
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
564
+ depositObject,
565
+ feeObject,
566
+ tx.pure.u8(allowTrade),
567
+ tx.pure.u64(size),
568
+ tx.pure.u64(reserveAmount),
569
+ tx.pure.u256(adjustCollateralPrice),
570
+ tx.pure.u256(adjustPrice),
571
+ tx.pure.u256(indexPriceThreshold),
572
+ ],
573
+ });
574
+ return tx;
575
+ }
576
+ /**
577
+ * Opens a new position with Coin in ZLP
578
+ */
579
+ async openPositionWithCoin(collateralToken, indexToken, size, coinObj, long, reserveAmount, indexPrice, collateralPrice, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
580
+ if (!tx) {
581
+ tx = new transactions_1.Transaction();
582
+ }
583
+ if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
584
+ tx = await this.addReferral(referralAddress, tx);
585
+ }
586
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
587
+ const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage);
588
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
589
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
590
+ if (isLimitOrder) {
591
+ allowTrade = isIocOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
592
+ }
593
+ // Handle oracle initialization and coin processing
594
+ let suiCoinObject;
595
+ if (sponsoredTx) {
596
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
597
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
598
+ }
599
+ else {
600
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx);
601
+ }
602
+ // Process coin splitting
603
+ const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
604
+ tx.moveCall({
605
+ target: `${this.consts.zoCore.upgradedPackage}::market::open_position`,
606
+ typeArguments: [
607
+ `${this.consts.zoCore.package}::zlp::ZLP`,
608
+ this.consts.coins[collateralToken].module,
609
+ this.consts.coins[indexToken].module,
610
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
611
+ this.consts.coins[collateralToken].module,
612
+ ],
613
+ arguments: [
614
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
615
+ tx.object(this.consts.zoCore.market),
616
+ tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
617
+ tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
618
+ tx.object(this.consts.zoCore.symbols[symbol].positionConfig),
619
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
620
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
621
+ coinObj,
622
+ feeObject,
623
+ tx.pure.u8(allowTrade),
624
+ tx.pure.u64(size),
625
+ tx.pure.u64(reserveAmount),
626
+ tx.pure.u256(adjustCollateralPrice),
627
+ tx.pure.u256(adjustPrice),
628
+ ],
629
+ });
630
+ return tx;
631
+ }
632
+ /**
633
+ * Opens a new position with Coin in ZLP (V2)
634
+ */
635
+ async openPositionWithCoinV2(collateralToken, indexToken, size, coinObj, long, reserveAmount, indexPrice, collateralPrice, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
636
+ if (!tx) {
637
+ tx = new transactions_1.Transaction();
638
+ }
639
+ if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
640
+ tx = await this.addReferral(referralAddress, tx);
641
+ }
642
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
643
+ const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage);
644
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
645
+ const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
646
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
647
+ if (isLimitOrder) {
648
+ allowTrade = isIocOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
649
+ }
650
+ // Handle oracle initialization and coin processing
651
+ let suiCoinObject;
652
+ if (sponsoredTx) {
653
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
654
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
655
+ }
656
+ else {
657
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx);
658
+ }
659
+ // Process coin splitting
660
+ const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
661
+ tx.moveCall({
662
+ target: `${this.consts.zoCore.upgradedPackage}::market::open_position_v2`,
663
+ typeArguments: [
664
+ `${this.consts.zoCore.package}::zlp::ZLP`,
665
+ this.consts.coins[collateralToken].module,
666
+ this.consts.coins[indexToken].module,
667
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
668
+ this.consts.coins[collateralToken].module,
669
+ ],
670
+ arguments: [
671
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
672
+ tx.object(this.consts.zoCore.market),
673
+ tx.object(this.consts.zoCore.symbols[symbol].positionConfig),
674
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
675
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
676
+ coinObj,
677
+ feeObject,
678
+ tx.pure.u8(allowTrade),
679
+ tx.pure.u64(size),
680
+ tx.pure.u64(reserveAmount),
681
+ tx.pure.u256(adjustCollateralPrice),
682
+ tx.pure.u256(adjustPrice),
683
+ tx.pure.u256(indexPriceThreshold),
684
+ ],
685
+ });
686
+ return tx;
687
+ }
688
+ /**
689
+ * Decreases an existing position in ZLP
690
+ */
691
+ async decreasePosition(pcpId, collateralToken, indexToken, amount, long, indexPrice, collateralPrice, isTriggerOrder = false, isTakeProfitOrder = true, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), coinObjects, sponsoredTx, suiCoinObjectsForPythUpdate) {
692
+ if (!coinObjects) {
693
+ throw new Error(`${this.constructor.name}: coinObjects is required`);
694
+ }
695
+ let tx = new transactions_1.Transaction();
696
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
697
+ const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage);
698
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
699
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
700
+ if (isTriggerOrder) {
701
+ allowTrade = isIocOrder || !isTakeProfitOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
702
+ }
703
+ else {
704
+ isTakeProfitOrder = true;
705
+ }
706
+ // Handle oracle initialization and coin processing
707
+ let suiCoinObject;
708
+ if (sponsoredTx) {
709
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
710
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
711
+ }
712
+ else {
713
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx);
714
+ }
715
+ // Process coin splitting
716
+ const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
717
+ tx.moveCall({
718
+ target: `${this.consts.zoCore.upgradedPackage}::market::decrease_position`,
719
+ typeArguments: [
720
+ `${this.consts.zoCore.package}::zlp::ZLP`,
721
+ this.consts.coins[collateralToken].module,
722
+ this.consts.coins[indexToken].module,
723
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
724
+ this.consts.coins[collateralToken].module,
725
+ ],
726
+ arguments: [
727
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
728
+ tx.object(this.consts.zoCore.market),
729
+ tx.object(pcpId),
730
+ tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
731
+ tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
732
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
733
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
734
+ feeObject,
735
+ tx.pure.u8(allowTrade),
736
+ tx.pure.bool(isTakeProfitOrder),
737
+ tx.pure.u64(amount),
738
+ tx.pure.u256(adjustCollateralPrice),
739
+ tx.pure.u256(adjustPrice),
740
+ ],
741
+ });
742
+ return tx;
743
+ }
744
+ /**
745
+ * Decreases an existing position in ZLP
746
+ */
747
+ async decreasePositionV2(pcpId, collateralToken, indexToken, amount, long, indexPrice, collateralPrice, isTriggerOrder = false, isTakeProfitOrder = true, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), coinObjects, sponsoredTx, suiCoinObjectsForPythUpdate) {
748
+ if (!coinObjects) {
749
+ throw new Error(`${this.constructor.name}: coinObjects is required`);
750
+ }
751
+ let tx = new transactions_1.Transaction();
752
+ const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage);
753
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
754
+ const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
755
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
756
+ if (isTriggerOrder) {
757
+ allowTrade = isIocOrder || !isTakeProfitOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
758
+ }
759
+ else {
760
+ isTakeProfitOrder = true;
761
+ }
762
+ // Handle oracle initialization and coin processing
763
+ let suiCoinObject;
764
+ if (sponsoredTx) {
765
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
766
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
767
+ }
768
+ else {
769
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx);
770
+ }
771
+ // Process coin splitting
772
+ const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
773
+ tx.moveCall({
774
+ target: `${this.consts.zoCore.upgradedPackage}::market::decrease_position_v2`,
775
+ typeArguments: [
776
+ `${this.consts.zoCore.package}::zlp::ZLP`,
777
+ this.consts.coins[collateralToken].module,
778
+ this.consts.coins[indexToken].module,
779
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
780
+ this.consts.coins[collateralToken].module,
781
+ ],
782
+ arguments: [
783
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
784
+ tx.object(this.consts.zoCore.market),
785
+ tx.object(pcpId),
786
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
787
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
788
+ feeObject,
789
+ tx.pure.u8(allowTrade),
790
+ tx.pure.bool(isTakeProfitOrder),
791
+ tx.pure.u64(amount),
792
+ tx.pure.u256(adjustCollateralPrice),
793
+ tx.pure.u256(adjustPrice),
794
+ tx.pure.u256(indexPriceThreshold),
795
+ ],
796
+ });
797
+ return tx;
798
+ }
799
+ async decreaseMultiPositions(positions, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
800
+ if (!tx) {
801
+ tx = new transactions_1.Transaction();
802
+ }
803
+ // Handle oracle initialization and coin processing
804
+ let suiCoinObject;
805
+ if (sponsoredTx) {
806
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
807
+ tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx, true, suiCoinObject);
808
+ }
809
+ else {
810
+ tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx);
811
+ }
812
+ for (const position of positions) {
813
+ const { pcpId, collateralToken, coinObjects = [], indexToken, amount, long, indexPrice, collateralPrice, isTriggerOrder = false, isTakeProfitOrder = true, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), } = position;
814
+ let innerIsTakeProfitOrder = isTakeProfitOrder;
815
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
816
+ const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage);
817
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
818
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
819
+ if (isTriggerOrder) {
820
+ allowTrade = isIocOrder || !innerIsTakeProfitOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
821
+ }
822
+ else {
823
+ innerIsTakeProfitOrder = true;
824
+ }
825
+ // Process coin splitting
826
+ const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
827
+ tx.moveCall({
828
+ target: `${this.consts.zoCore.upgradedPackage}::market::decrease_position`,
829
+ typeArguments: [
830
+ `${this.consts.zoCore.package}::zlp::ZLP`,
831
+ this.consts.coins[collateralToken].module,
832
+ this.consts.coins[indexToken].module,
833
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
834
+ this.consts.coins[collateralToken].module,
835
+ ],
836
+ arguments: [
837
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
838
+ tx.object(this.consts.zoCore.market),
839
+ tx.object(pcpId),
840
+ tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
841
+ tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
842
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
843
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
844
+ feeObject,
845
+ tx.pure.u8(allowTrade),
846
+ tx.pure.bool(innerIsTakeProfitOrder),
847
+ tx.pure.u64(amount),
848
+ tx.pure.u256(adjustCollateralPrice),
849
+ tx.pure.u256(adjustPrice),
850
+ ],
851
+ });
852
+ }
853
+ return tx;
854
+ }
855
+ async decreaseMultiPositionsV2(positions, tx, sponsoredTx, suiCoinObjectsForPythUpdate, feeObjects) {
856
+ const transaction = tx ?? new transactions_1.Transaction();
857
+ // Handle oracle initialization and coin processing
858
+ const tokens = positions.flatMap(position => [position.collateralToken, position.indexToken]);
859
+ const suiCoinObject = sponsoredTx
860
+ ? this.processCoins(transaction, 'sui', suiCoinObjectsForPythUpdate || [], true)
861
+ : undefined;
862
+ await this.initOracleTxb(tokens, transaction, !!sponsoredTx, suiCoinObject);
863
+ if (!feeObjects || feeObjects.length !== positions.length) {
864
+ throw new Error('feeObjects must be provided (pre-processed via buildFeeCoinObjects) and match positions length');
865
+ }
866
+ for (const [i, position] of positions.entries()) {
867
+ const feeObject = feeObjects[i];
868
+ const { pcpId, collateralToken, indexToken, amount, long, indexPrice, collateralPrice, isTriggerOrder = false, isTakeProfitOrder = true, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, } = position;
869
+ let innerIsTakeProfitOrder = isTakeProfitOrder;
870
+ const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage);
871
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
872
+ const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
873
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
874
+ if (isTriggerOrder) {
875
+ allowTrade = isIocOrder || !innerIsTakeProfitOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
876
+ }
877
+ else {
878
+ innerIsTakeProfitOrder = true;
879
+ }
880
+ transaction.moveCall({
881
+ target: `${this.consts.zoCore.upgradedPackage}::market::decrease_position_v2`,
882
+ typeArguments: [
883
+ `${this.consts.zoCore.package}::zlp::ZLP`,
884
+ this.consts.coins[collateralToken].module,
885
+ this.consts.coins[indexToken].module,
886
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
887
+ this.consts.coins[collateralToken].module,
888
+ ],
889
+ arguments: [
890
+ transaction.object(utils_1.SUI_CLOCK_OBJECT_ID),
891
+ transaction.object(this.consts.zoCore.market),
892
+ transaction.object(pcpId),
893
+ transaction.object(this.consts.pythFeeder.feeder[collateralToken]),
894
+ transaction.object(this.consts.pythFeeder.feeder[indexToken]),
895
+ feeObject,
896
+ transaction.pure.u8(allowTrade),
897
+ transaction.pure.bool(innerIsTakeProfitOrder),
898
+ transaction.pure.u64(amount),
899
+ transaction.pure.u256(adjustCollateralPrice),
900
+ transaction.pure.u256(adjustPrice),
901
+ transaction.pure.u256(indexPriceThreshold),
902
+ ],
903
+ });
904
+ }
905
+ return transaction;
906
+ }
907
+ async openPositionWithSCard(collateralToken, indexToken, size, collateralAmount, coinObjects, long, reserveAmount, indexPrice, collateralPrice, kioskClient, kioskCap, scard, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, sponsoredTx, suiCoinObjectsForPythUpdate) {
908
+ let tx = new transactions_1.Transaction();
909
+ if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
910
+ tx = await this.addReferral(referralAddress, tx);
911
+ }
912
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
913
+ const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage);
914
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
915
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
916
+ if (isLimitOrder) {
917
+ allowTrade = isIocOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
918
+ }
919
+ const kioskTx = new kiosk_1.KioskTransaction({
920
+ transaction: tx,
921
+ kioskClient,
922
+ cap: kioskCap,
923
+ });
924
+ const [sudoCard, promise] = kioskTx.borrow({
925
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
926
+ itemId: scard,
927
+ });
928
+ // Handle oracle initialization and coin processing
929
+ let suiCoinObject;
930
+ if (sponsoredTx) {
931
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
932
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
933
+ }
934
+ else {
935
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx);
936
+ }
937
+ // Process coin splitting
938
+ const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
939
+ tx.moveCall({
940
+ target: `${this.consts.zoCore.upgradedPackage}::market::open_position_with_scard`,
941
+ typeArguments: [
942
+ `${this.consts.zoCore.package}::zlp::ZLP`,
943
+ this.consts.coins[collateralToken].module,
944
+ this.consts.coins[indexToken].module,
945
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
946
+ this.consts.coins[collateralToken].module,
947
+ ],
948
+ arguments: [
949
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
950
+ tx.object(this.consts.zoCore.market),
951
+ tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
952
+ tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
953
+ tx.object(this.consts.zoCore.symbols[symbol].positionConfig),
954
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
955
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
956
+ depositObject,
957
+ feeObject,
958
+ tx.pure.u8(allowTrade),
959
+ tx.pure.u64(size),
960
+ tx.pure.u64(reserveAmount),
961
+ tx.pure.u256(adjustCollateralPrice),
962
+ tx.pure.u256(adjustPrice),
963
+ sudoCard,
964
+ ],
965
+ });
966
+ kioskTx
967
+ .return({
968
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
969
+ item: sudoCard,
970
+ promise,
971
+ })
972
+ .finalize();
973
+ return tx;
974
+ }
975
+ async openPositionWithSCardV2(collateralToken, indexToken, size, collateralAmount, coinObjects, long, reserveAmount, indexPrice, collateralPrice, kioskClient, kioskCap, scard, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, sponsoredTx, suiCoinObjectsForPythUpdate) {
976
+ let tx = new transactions_1.Transaction();
977
+ if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
978
+ tx = await this.addReferral(referralAddress, tx);
979
+ }
980
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
981
+ const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage);
982
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
983
+ const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
984
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
985
+ if (isLimitOrder) {
986
+ allowTrade = isIocOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
987
+ }
988
+ const kioskTx = new kiosk_1.KioskTransaction({
989
+ transaction: tx,
990
+ kioskClient,
991
+ cap: kioskCap,
992
+ });
993
+ const [sudoCard, promise] = kioskTx.borrow({
994
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
995
+ itemId: scard,
996
+ });
997
+ // Handle oracle initialization and coin processing
998
+ let suiCoinObject;
999
+ if (sponsoredTx) {
1000
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1001
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1002
+ }
1003
+ else {
1004
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1005
+ }
1006
+ // Process coin splitting
1007
+ const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
1008
+ tx.moveCall({
1009
+ target: `${this.consts.zoCore.upgradedPackage}::market::open_position_with_scard_v2`,
1010
+ typeArguments: [
1011
+ `${this.consts.zoCore.package}::zlp::ZLP`,
1012
+ this.consts.coins[collateralToken].module,
1013
+ this.consts.coins[indexToken].module,
1014
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1015
+ this.consts.coins[collateralToken].module,
1016
+ ],
1017
+ arguments: [
1018
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
1019
+ tx.object(this.consts.zoCore.market),
1020
+ tx.object(this.consts.zoCore.symbols[symbol].positionConfig),
1021
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
1022
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
1023
+ depositObject,
1024
+ feeObject,
1025
+ tx.pure.u8(allowTrade),
1026
+ tx.pure.u64(size),
1027
+ tx.pure.u64(reserveAmount),
1028
+ tx.pure.u256(adjustCollateralPrice),
1029
+ tx.pure.u256(adjustPrice),
1030
+ tx.pure.u256(indexPriceThreshold),
1031
+ sudoCard,
1032
+ ],
1033
+ });
1034
+ kioskTx
1035
+ .return({
1036
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
1037
+ item: sudoCard,
1038
+ promise,
1039
+ })
1040
+ .finalize();
1041
+ return tx;
1042
+ }
1043
+ async openPositionWithCoinAndSCard(collateralToken, indexToken, size, coinObj, long, reserveAmount, indexPrice, collateralPrice, kioskClient, kioskCap, scard, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
1044
+ if (!tx) {
1045
+ tx = new transactions_1.Transaction();
1046
+ }
1047
+ if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
1048
+ tx = await this.addReferral(referralAddress, tx);
1049
+ }
1050
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
1051
+ const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage);
1052
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
1053
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
1054
+ if (isLimitOrder) {
1055
+ allowTrade = isIocOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
1056
+ }
1057
+ const kioskTx = new kiosk_1.KioskTransaction({
1058
+ transaction: tx,
1059
+ kioskClient,
1060
+ cap: kioskCap,
1061
+ });
1062
+ const [sudoCard, promise] = kioskTx.borrow({
1063
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
1064
+ itemId: scard,
1065
+ });
1066
+ // Handle oracle initialization and coin processing
1067
+ let suiCoinObject;
1068
+ if (sponsoredTx) {
1069
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1070
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1071
+ }
1072
+ else {
1073
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1074
+ }
1075
+ // Process coin splitting
1076
+ const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
1077
+ tx.moveCall({
1078
+ target: `${this.consts.zoCore.upgradedPackage}::market::open_position_with_scard`,
1079
+ typeArguments: [
1080
+ `${this.consts.zoCore.package}::zlp::ZLP`,
1081
+ this.consts.coins[collateralToken].module,
1082
+ this.consts.coins[indexToken].module,
1083
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1084
+ this.consts.coins[collateralToken].module,
1085
+ ],
1086
+ arguments: [
1087
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
1088
+ tx.object(this.consts.zoCore.market),
1089
+ tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
1090
+ tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
1091
+ tx.object(this.consts.zoCore.symbols[symbol].positionConfig),
1092
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
1093
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
1094
+ coinObj,
1095
+ feeObject,
1096
+ tx.pure.u8(allowTrade),
1097
+ tx.pure.u64(size),
1098
+ tx.pure.u64(reserveAmount),
1099
+ tx.pure.u256(adjustCollateralPrice),
1100
+ tx.pure.u256(adjustPrice),
1101
+ sudoCard,
1102
+ ],
1103
+ });
1104
+ kioskTx
1105
+ .return({
1106
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
1107
+ item: sudoCard,
1108
+ promise,
1109
+ })
1110
+ .finalize();
1111
+ return tx;
1112
+ }
1113
+ async openPositionWithCoinAndSCardV2(collateralToken, indexToken, size, coinObj, long, reserveAmount, indexPrice, collateralPrice, kioskClient, kioskCap, scard, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
1114
+ if (!tx) {
1115
+ tx = new transactions_1.Transaction();
1116
+ }
1117
+ if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
1118
+ tx = await this.addReferral(referralAddress, tx);
1119
+ }
1120
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
1121
+ const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage);
1122
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
1123
+ const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
1124
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
1125
+ if (isLimitOrder) {
1126
+ allowTrade = isIocOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
1127
+ }
1128
+ const kioskTx = new kiosk_1.KioskTransaction({
1129
+ transaction: tx,
1130
+ kioskClient,
1131
+ cap: kioskCap,
1132
+ });
1133
+ const [sudoCard, promise] = kioskTx.borrow({
1134
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
1135
+ itemId: scard,
1136
+ });
1137
+ // Handle oracle initialization and coin processing
1138
+ let suiCoinObject;
1139
+ if (sponsoredTx) {
1140
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1141
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1142
+ }
1143
+ else {
1144
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1145
+ }
1146
+ // Process coin splitting
1147
+ const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
1148
+ tx.moveCall({
1149
+ target: `${this.consts.zoCore.upgradedPackage}::market::open_position_with_scard_v2`,
1150
+ typeArguments: [
1151
+ `${this.consts.zoCore.package}::zlp::ZLP`,
1152
+ this.consts.coins[collateralToken].module,
1153
+ this.consts.coins[indexToken].module,
1154
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1155
+ this.consts.coins[collateralToken].module,
1156
+ ],
1157
+ arguments: [
1158
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
1159
+ tx.object(this.consts.zoCore.market),
1160
+ tx.object(this.consts.zoCore.symbols[symbol].positionConfig),
1161
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
1162
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
1163
+ coinObj,
1164
+ feeObject,
1165
+ tx.pure.u8(allowTrade),
1166
+ tx.pure.u64(size),
1167
+ tx.pure.u64(reserveAmount),
1168
+ tx.pure.u256(adjustCollateralPrice),
1169
+ tx.pure.u256(adjustPrice),
1170
+ tx.pure.u256(indexPriceThreshold),
1171
+ sudoCard,
1172
+ ],
1173
+ });
1174
+ kioskTx
1175
+ .return({
1176
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
1177
+ item: sudoCard,
1178
+ promise,
1179
+ })
1180
+ .finalize();
1181
+ return tx;
1182
+ }
1183
+ async decreasePositionWithSCard(pcpId, collateralToken, indexToken, amount, long, indexPrice, collateralPrice, kioskClient, kioskCap, scard, isTriggerOrder = false, isTakeProfitOrder = true, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), coinObjects, sponsoredTx, suiCoinObjectsForPythUpdate) {
1184
+ if (!coinObjects) {
1185
+ throw new Error(`${this.constructor.name}: coinObjects is required`);
1186
+ }
1187
+ let tx = new transactions_1.Transaction();
1188
+ const kioskTx = new kiosk_1.KioskTransaction({
1189
+ transaction: tx,
1190
+ kioskClient,
1191
+ cap: kioskCap,
1192
+ });
1193
+ const [sudoCard, promise] = kioskTx.borrow({
1194
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
1195
+ itemId: scard,
1196
+ });
1197
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
1198
+ const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage);
1199
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
1200
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
1201
+ if (isTriggerOrder) {
1202
+ allowTrade = isIocOrder || !isTakeProfitOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
1203
+ }
1204
+ else {
1205
+ isTakeProfitOrder = true;
1206
+ }
1207
+ // Handle oracle initialization and coin processing
1208
+ let suiCoinObject;
1209
+ if (sponsoredTx) {
1210
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1211
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1212
+ }
1213
+ else {
1214
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1215
+ }
1216
+ // Process coin splitting
1217
+ const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
1218
+ tx.moveCall({
1219
+ target: `${this.consts.zoCore.upgradedPackage}::market::decrease_position_with_scard`,
1220
+ typeArguments: [
1221
+ `${this.consts.zoCore.package}::zlp::ZLP`,
1222
+ this.consts.coins[collateralToken].module,
1223
+ this.consts.coins[indexToken].module,
1224
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1225
+ this.consts.coins[collateralToken].module,
1226
+ ],
1227
+ arguments: [
1228
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
1229
+ tx.object(this.consts.zoCore.market),
1230
+ tx.object(pcpId),
1231
+ tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
1232
+ tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
1233
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
1234
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
1235
+ feeObject,
1236
+ tx.pure.u8(allowTrade),
1237
+ tx.pure.bool(isTakeProfitOrder),
1238
+ tx.pure.u64(amount),
1239
+ tx.pure.u256(adjustCollateralPrice),
1240
+ tx.pure.u256(adjustPrice),
1241
+ sudoCard,
1242
+ ],
1243
+ });
1244
+ kioskTx
1245
+ .return({
1246
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
1247
+ item: sudoCard,
1248
+ promise,
1249
+ })
1250
+ .finalize();
1251
+ return tx;
1252
+ }
1253
+ async decreasePositionWithSCardV2(pcpId, collateralToken, indexToken, amount, long, indexPrice, collateralPrice, kioskClient, kioskCap, scard, isTriggerOrder = false, isTakeProfitOrder = true, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), coinObjects, sponsoredTx, suiCoinObjectsForPythUpdate) {
1254
+ if (!coinObjects) {
1255
+ throw new Error(`${this.constructor.name}: coinObjects is required`);
1256
+ }
1257
+ let tx = new transactions_1.Transaction();
1258
+ const kioskTx = new kiosk_1.KioskTransaction({
1259
+ transaction: tx,
1260
+ kioskClient,
1261
+ cap: kioskCap,
1262
+ });
1263
+ const [sudoCard, promise] = kioskTx.borrow({
1264
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
1265
+ itemId: scard,
1266
+ });
1267
+ const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage);
1268
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
1269
+ const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
1270
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
1271
+ if (isTriggerOrder) {
1272
+ allowTrade = isIocOrder || !isTakeProfitOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
1273
+ }
1274
+ else {
1275
+ isTakeProfitOrder = true;
1276
+ }
1277
+ // Handle oracle initialization and coin processing
1278
+ let suiCoinObject;
1279
+ if (sponsoredTx) {
1280
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1281
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1282
+ }
1283
+ else {
1284
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1285
+ }
1286
+ // Process coin splitting
1287
+ const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
1288
+ tx.moveCall({
1289
+ target: `${this.consts.zoCore.upgradedPackage}::market::decrease_position_with_scard_v2`,
1290
+ typeArguments: [
1291
+ `${this.consts.zoCore.package}::zlp::ZLP`,
1292
+ this.consts.coins[collateralToken].module,
1293
+ this.consts.coins[indexToken].module,
1294
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1295
+ this.consts.coins[collateralToken].module,
1296
+ ],
1297
+ arguments: [
1298
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
1299
+ tx.object(this.consts.zoCore.market),
1300
+ tx.object(pcpId),
1301
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
1302
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
1303
+ feeObject,
1304
+ tx.pure.u8(allowTrade),
1305
+ tx.pure.bool(isTakeProfitOrder),
1306
+ tx.pure.u64(amount),
1307
+ tx.pure.u256(adjustCollateralPrice),
1308
+ tx.pure.u256(adjustPrice),
1309
+ tx.pure.u256(indexPriceThreshold),
1310
+ sudoCard,
1311
+ ],
1312
+ });
1313
+ kioskTx
1314
+ .return({
1315
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
1316
+ item: sudoCard,
1317
+ promise,
1318
+ })
1319
+ .finalize();
1320
+ return tx;
1321
+ }
1322
+ async decreaseMultiPositionsWithSCard(positions, kioskClient, kioskCap, scard, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
1323
+ if (!tx) {
1324
+ tx = new transactions_1.Transaction();
1325
+ }
1326
+ // Handle oracle initialization and coin processing
1327
+ let suiCoinObject;
1328
+ if (sponsoredTx) {
1329
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1330
+ tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx, true, suiCoinObject);
1331
+ }
1332
+ else {
1333
+ tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx);
1334
+ }
1335
+ const kioskTx = new kiosk_1.KioskTransaction({
1336
+ transaction: tx,
1337
+ kioskClient,
1338
+ cap: kioskCap,
1339
+ });
1340
+ const [sudoCard, promise] = kioskTx.borrow({
1341
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
1342
+ itemId: scard,
1343
+ });
1344
+ for (const position of positions) {
1345
+ const { pcpId, collateralToken, indexToken, amount, long, indexPrice, collateralPrice, isTriggerOrder = false, isTakeProfitOrder = true, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), coinObjects = [], } = position;
1346
+ let innerIsTakeProfitOrder = isTakeProfitOrder;
1347
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
1348
+ const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage);
1349
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
1350
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
1351
+ if (isTriggerOrder) {
1352
+ allowTrade = isIocOrder || !innerIsTakeProfitOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
1353
+ }
1354
+ else {
1355
+ innerIsTakeProfitOrder = true;
1356
+ }
1357
+ // Process coin splitting
1358
+ const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
1359
+ tx.moveCall({
1360
+ target: `${this.consts.zoCore.upgradedPackage}::market::decrease_position_with_scard`,
1361
+ typeArguments: [
1362
+ `${this.consts.zoCore.package}::zlp::ZLP`,
1363
+ this.consts.coins[collateralToken].module,
1364
+ this.consts.coins[indexToken].module,
1365
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1366
+ this.consts.coins[collateralToken].module,
1367
+ ],
1368
+ arguments: [
1369
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
1370
+ tx.object(this.consts.zoCore.market),
1371
+ tx.object(pcpId),
1372
+ tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
1373
+ tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
1374
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
1375
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
1376
+ feeObject,
1377
+ tx.pure.u8(allowTrade),
1378
+ tx.pure.bool(innerIsTakeProfitOrder),
1379
+ tx.pure.u64(amount),
1380
+ tx.pure.u256(adjustCollateralPrice),
1381
+ tx.pure.u256(adjustPrice),
1382
+ sudoCard,
1383
+ ],
1384
+ });
1385
+ }
1386
+ kioskTx
1387
+ .return({
1388
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
1389
+ item: sudoCard,
1390
+ promise,
1391
+ })
1392
+ .finalize();
1393
+ return tx;
1394
+ }
1395
+ async decreaseMultiPositionsWithSCardV2(positions, kioskClient, kioskCap, scard, tx, sponsoredTx, suiCoinObjectsForPythUpdate, feeObjects) {
1396
+ const transaction = tx ?? new transactions_1.Transaction();
1397
+ // Handle oracle initialization and coin processing
1398
+ const tokens = positions.flatMap(position => [position.collateralToken, position.indexToken]);
1399
+ const suiCoinObject = sponsoredTx
1400
+ ? this.processCoins(transaction, 'sui', suiCoinObjectsForPythUpdate || [], true)
1401
+ : undefined;
1402
+ await this.initOracleTxb(tokens, transaction, !!sponsoredTx, suiCoinObject);
1403
+ if (!feeObjects || feeObjects.length !== positions.length) {
1404
+ throw new Error('feeObjects must be provided (pre-processed via buildFeeCoinObjects) and match positions length');
1405
+ }
1406
+ const kioskTx = new kiosk_1.KioskTransaction({
1407
+ transaction,
1408
+ kioskClient,
1409
+ cap: kioskCap,
1410
+ });
1411
+ const [sudoCard, promise] = kioskTx.borrow({
1412
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
1413
+ itemId: scard,
1414
+ });
1415
+ for (const [i, position] of positions.entries()) {
1416
+ const feeObject = feeObjects[i];
1417
+ const { pcpId, collateralToken, indexToken, amount, long, indexPrice, collateralPrice, isTriggerOrder = false, isTakeProfitOrder = true, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, } = position;
1418
+ let innerIsTakeProfitOrder = isTakeProfitOrder;
1419
+ const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage);
1420
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
1421
+ const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
1422
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
1423
+ if (isTriggerOrder) {
1424
+ allowTrade = isIocOrder || !innerIsTakeProfitOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
1425
+ }
1426
+ else {
1427
+ innerIsTakeProfitOrder = true;
1428
+ }
1429
+ transaction.moveCall({
1430
+ target: `${this.consts.zoCore.upgradedPackage}::market::decrease_position_with_scard_v2`,
1431
+ typeArguments: [
1432
+ `${this.consts.zoCore.package}::zlp::ZLP`,
1433
+ this.consts.coins[collateralToken].module,
1434
+ this.consts.coins[indexToken].module,
1435
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1436
+ this.consts.coins[collateralToken].module,
1437
+ ],
1438
+ arguments: [
1439
+ transaction.object(utils_1.SUI_CLOCK_OBJECT_ID),
1440
+ transaction.object(this.consts.zoCore.market),
1441
+ transaction.object(pcpId),
1442
+ transaction.object(this.consts.pythFeeder.feeder[collateralToken]),
1443
+ transaction.object(this.consts.pythFeeder.feeder[indexToken]),
1444
+ feeObject,
1445
+ transaction.pure.u8(allowTrade),
1446
+ transaction.pure.bool(innerIsTakeProfitOrder),
1447
+ transaction.pure.u64(amount),
1448
+ transaction.pure.u256(adjustCollateralPrice),
1449
+ transaction.pure.u256(adjustPrice),
1450
+ transaction.pure.u256(indexPriceThreshold),
1451
+ sudoCard,
1452
+ ],
1453
+ });
1454
+ }
1455
+ kioskTx
1456
+ .return({
1457
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
1458
+ item: sudoCard,
1459
+ promise,
1460
+ })
1461
+ .finalize();
1462
+ return transaction;
1463
+ }
1464
+ /**
1465
+ * Pledges in position (ZLP-specific functionality)
1466
+ */
1467
+ async pledgeInPosition(pcpId, collateralToken, indexToken, amount, coinObjects, long, sponsoredTx, suiCoinObjectsForPythUpdate) {
1468
+ let tx = new transactions_1.Transaction();
1469
+ // Handle oracle initialization and coin processing
1470
+ let suiCoinObject;
1471
+ if (sponsoredTx) {
1472
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1473
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1474
+ }
1475
+ else {
1476
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1477
+ }
1478
+ // Process coin splitting
1479
+ const [depositObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(amount)], sponsoredTx, suiCoinObject);
1480
+ tx.moveCall({
1481
+ target: `${this.consts.zoCore.upgradedPackage}::market::pledge_in_position`,
1482
+ typeArguments: [
1483
+ `${this.consts.zoCore.package}::zlp::ZLP`,
1484
+ this.consts.coins[collateralToken].module,
1485
+ this.consts.coins[indexToken].module,
1486
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1487
+ ],
1488
+ arguments: [tx.object(this.consts.zoCore.market), tx.object(pcpId), depositObject],
1489
+ });
1490
+ return tx;
1491
+ }
1492
+ async redeemFromPosition(pcpId, collateralToken, indexToken, amount, long, sponsoredTx, suiCoinObjectsForPythUpdate) {
1493
+ let tx = new transactions_1.Transaction();
1494
+ // Handle oracle initialization and coin processing
1495
+ let suiCoinObject;
1496
+ if (sponsoredTx) {
1497
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1498
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1499
+ }
1500
+ else {
1501
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1502
+ }
1503
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
1504
+ tx.moveCall({
1505
+ target: `${this.consts.zoCore.upgradedPackage}::market::redeem_from_position`,
1506
+ typeArguments: [
1507
+ `${this.consts.zoCore.package}::zlp::ZLP`,
1508
+ this.consts.coins[collateralToken].module,
1509
+ this.consts.coins[indexToken].module,
1510
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1511
+ ],
1512
+ arguments: [
1513
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
1514
+ tx.object(this.consts.zoCore.market),
1515
+ tx.object(pcpId),
1516
+ tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
1517
+ tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
1518
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
1519
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
1520
+ tx.pure.u64(amount),
1521
+ ],
1522
+ });
1523
+ return tx;
1524
+ }
1525
+ cancelOrder(orderCapId, collateralToken, indexToken, long, type, isV11Order) {
1526
+ const tx = new transactions_1.Transaction();
1527
+ let functionName = '';
1528
+ switch (type) {
1529
+ case 'OPEN_POSITION': {
1530
+ functionName = isV11Order ? 'clear_open_position_order' : 'clear_open_position_order';
1531
+ break;
1532
+ }
1533
+ case 'OPEN_MARKET': {
1534
+ functionName = 'clear_open_market_order';
1535
+ break;
1536
+ }
1537
+ case 'DECREASE_POSITION': {
1538
+ functionName = isV11Order
1539
+ ? 'clear_decrease_position_order'
1540
+ : 'clear_decrease_position_order';
1541
+ break;
1542
+ }
1543
+ case 'DECREASE_MARKET': {
1544
+ functionName = 'clear_decrease_market_order';
1545
+ break;
1546
+ }
1547
+ default: {
1548
+ throw new Error('invalid order type');
1549
+ }
1550
+ }
1551
+ tx.moveCall({
1552
+ target: `${this.consts.zoCore.upgradedPackage}::market::${functionName}`,
1553
+ typeArguments: [
1554
+ `${this.consts.zoCore.package}::zlp::ZLP`,
1555
+ this.consts.coins[collateralToken].module,
1556
+ this.consts.coins[indexToken].module,
1557
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1558
+ this.consts.coins[collateralToken].module,
1559
+ ],
1560
+ arguments: [tx.object(this.consts.zoCore.market), tx.object(orderCapId)],
1561
+ });
1562
+ return tx;
1563
+ }
1564
+ cancelMultiOrders(orders, tx) {
1565
+ if (!tx) {
1566
+ tx = new transactions_1.Transaction();
1567
+ }
1568
+ for (const order of orders) {
1569
+ const { orderCapId, collateralToken, indexToken, long, type, isV11Order } = order;
1570
+ let functionName = '';
1571
+ switch (type) {
1572
+ case 'OPEN_POSITION': {
1573
+ functionName = isV11Order ? 'clear_open_position_order' : 'clear_open_position_order';
1574
+ break;
1575
+ }
1576
+ case 'OPEN_MARKET': {
1577
+ functionName = 'clear_open_market_order';
1578
+ break;
1579
+ }
1580
+ case 'DECREASE_POSITION': {
1581
+ functionName = isV11Order
1582
+ ? 'clear_decrease_position_order'
1583
+ : 'clear_decrease_position_order';
1584
+ break;
1585
+ }
1586
+ case 'DECREASE_MARKET': {
1587
+ functionName = 'clear_decrease_market_order';
1588
+ break;
1589
+ }
1590
+ default: {
1591
+ throw new Error('invalid order type');
1592
+ }
1593
+ }
1594
+ tx.moveCall({
1595
+ target: `${this.consts.zoCore.upgradedPackage}::market::${functionName}`,
1596
+ typeArguments: [
1597
+ `${this.consts.zoCore.package}::zlp::ZLP`,
1598
+ this.consts.coins[collateralToken].module,
1599
+ this.consts.coins[indexToken].module,
1600
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1601
+ this.consts.coins[collateralToken].module,
1602
+ ],
1603
+ arguments: [tx.object(this.consts.zoCore.market), tx.object(orderCapId)],
1604
+ });
1605
+ }
1606
+ return tx;
1607
+ }
1608
+ clearClosedPosition(pcpId, collateralToken, indexToken, long, tx) {
1609
+ tx.moveCall({
1610
+ target: `${this.consts.zoCore.upgradedPackage}::market::clear_closed_position`,
1611
+ typeArguments: [
1612
+ `${this.consts.zoCore.package}::zlp::ZLP`,
1613
+ this.consts.coins[collateralToken].module,
1614
+ this.consts.coins[indexToken].module,
1615
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1616
+ ],
1617
+ arguments: [tx.object(this.consts.zoCore.market), tx.object(pcpId)],
1618
+ });
1619
+ }
1620
+ clearOpenPositionOrder(orderCapId, collateralToken, indexToken, long, tx, isV11Order) {
1621
+ const funcName = isV11Order ? 'clear_open_position_order' : 'clear_open_position_order';
1622
+ tx.moveCall({
1623
+ target: `${this.consts.zoCore.upgradedPackage}::market::${funcName}`,
1624
+ typeArguments: [
1625
+ `${this.consts.zoCore.package}::zlp::ZLP`,
1626
+ this.consts.coins[collateralToken].module,
1627
+ this.consts.coins[indexToken].module,
1628
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1629
+ this.consts.coins[collateralToken].module,
1630
+ ],
1631
+ arguments: [tx.object(this.consts.zoCore.market), tx.object(orderCapId)],
1632
+ });
1633
+ }
1634
+ clearOpenMarketOrder(orderCapId, collateralToken, indexToken, long, tx, _isV11Order) {
1635
+ const funcName = 'clear_open_market_order';
1636
+ tx.moveCall({
1637
+ target: `${this.consts.zoCore.upgradedPackage}::market::${funcName}`,
1638
+ typeArguments: [
1639
+ `${this.consts.zoCore.package}::zlp::ZLP`,
1640
+ this.consts.coins[collateralToken].module,
1641
+ this.consts.coins[indexToken].module,
1642
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1643
+ this.consts.coins[collateralToken].module,
1644
+ ],
1645
+ arguments: [tx.object(this.consts.zoCore.market), tx.object(orderCapId)],
1646
+ });
1647
+ }
1648
+ clearDecreasePositionOrder(orderCapId, collateralToken, indexToken, long, tx, isV11Order) {
1649
+ const funcName = isV11Order ? 'clear_decrease_position_order' : 'clear_decrease_position_order';
1650
+ tx.moveCall({
1651
+ target: `${this.consts.zoCore.upgradedPackage}::market::${funcName}`,
1652
+ typeArguments: [
1653
+ `${this.consts.zoCore.package}::zlp::ZLP`,
1654
+ this.consts.coins[collateralToken].module,
1655
+ this.consts.coins[indexToken].module,
1656
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1657
+ this.consts.coins[collateralToken].module,
1658
+ ],
1659
+ arguments: [tx.object(this.consts.zoCore.market), tx.object(orderCapId)],
1660
+ });
1661
+ }
1662
+ clearDecreaseMarketOrder(orderCapId, collateralToken, indexToken, long, tx, _isV11Order) {
1663
+ const funcName = 'clear_decrease_market_order';
1664
+ tx.moveCall({
1665
+ target: `${this.consts.zoCore.upgradedPackage}::market::${funcName}`,
1666
+ typeArguments: [
1667
+ `${this.consts.zoCore.package}::zlp::ZLP`,
1668
+ this.consts.coins[collateralToken].module,
1669
+ this.consts.coins[indexToken].module,
1670
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1671
+ this.consts.coins[collateralToken].module,
1672
+ ],
1673
+ arguments: [tx.object(this.consts.zoCore.market), tx.object(orderCapId)],
1674
+ });
1675
+ }
1676
+ addReferral(referralAddress, tx) {
1677
+ if (!tx) {
1678
+ tx = new transactions_1.Transaction();
1679
+ }
1680
+ tx.moveCall({
1681
+ target: `${this.consts.zoCore.upgradedPackage}::market::add_new_referral`,
1682
+ typeArguments: [`${this.consts.zoCore.package}::zlp::ZLP`],
1683
+ arguments: [tx.object(this.consts.zoCore.market), tx.pure.address(referralAddress)],
1684
+ });
1685
+ return tx;
1686
+ }
1687
+ async adminUpdatePriceFeed(collateralToken, indexToken) {
1688
+ const tx = await this.initOracleTxb([collateralToken, indexToken]);
1689
+ return tx;
1690
+ }
1691
+ adminSettlePosition(positionId, owner, collateralToken, indexToken, long) {
1692
+ const tx = new transactions_1.Transaction();
1693
+ tx.moveCall({
1694
+ target: `${this.consts.zoCore.upgradedPackage}::market::force_settle_position`,
1695
+ typeArguments: [
1696
+ `${this.consts.zoCore.package}::zlp::ZLP`,
1697
+ this.consts.coins[collateralToken].module,
1698
+ this.consts.coins[indexToken].module,
1699
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1700
+ ],
1701
+ arguments: [
1702
+ tx.object(this.consts.zoCore.adminCap),
1703
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
1704
+ tx.object(this.consts.zoCore.market),
1705
+ tx.object(owner),
1706
+ tx.object(positionId),
1707
+ ],
1708
+ });
1709
+ this.adminClearClosedPosition(positionId, owner, collateralToken, indexToken, long, tx);
1710
+ return tx;
1711
+ }
1712
+ adminDecreasePosition(positionId, owner, collateralToken, indexToken, positionAmount, amount, long) {
1713
+ const tx = new transactions_1.Transaction();
1714
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
1715
+ tx.moveCall({
1716
+ target: `${this.consts.zoCore.upgradedPackage}::market::force_close_position`,
1717
+ typeArguments: [
1718
+ `${this.consts.zoCore.package}::zlp::ZLP`,
1719
+ this.consts.coins[collateralToken].module,
1720
+ this.consts.coins[indexToken].module,
1721
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1722
+ ],
1723
+ arguments: [
1724
+ tx.object(this.consts.zoCore.adminCap),
1725
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
1726
+ tx.object(this.consts.zoCore.market),
1727
+ tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
1728
+ tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
1729
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
1730
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
1731
+ tx.object(owner),
1732
+ tx.object(positionId),
1733
+ ],
1734
+ });
1735
+ if (amount === BigInt(positionAmount)) {
1736
+ this.adminClearClosedPosition(positionId, owner, collateralToken, indexToken, long, tx);
1737
+ }
1738
+ return tx;
1739
+ }
1740
+ adminClearClosedPosition(positionId, owner, collateralToken, indexToken, long, tx) {
1741
+ tx.moveCall({
1742
+ target: `${this.consts.zoCore.upgradedPackage}::market::force_clear_closed_position`,
1743
+ typeArguments: [
1744
+ `${this.consts.zoCore.package}::zlp::ZLP`,
1745
+ this.consts.coins[collateralToken].module,
1746
+ this.consts.coins[indexToken].module,
1747
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1748
+ ],
1749
+ arguments: [
1750
+ tx.object(this.consts.zoCore.adminCap),
1751
+ tx.object(this.consts.zoCore.market),
1752
+ tx.object(positionId),
1753
+ tx.object(owner),
1754
+ ],
1755
+ });
1756
+ }
1757
+ adminIssueLootbox(coin, tiers, beneficiaries, amounts, tx) {
1758
+ let module = `${this.consts.zoCore.package}::zlp::ZLP`;
1759
+ if (coin !== 'zlp') {
1760
+ module = this.consts.coins[coin].module;
1761
+ }
1762
+ for (const [i, beneficiary] of beneficiaries.entries()) {
1763
+ tx.moveCall({
1764
+ target: `${this.sharedConfig.zoLootbox.package}::lootbox::admin_issue_lootbox`,
1765
+ typeArguments: [module],
1766
+ arguments: [
1767
+ tx.object(this.sharedConfig.zoLootbox.adminCap),
1768
+ tx.pure.u8(tiers[i]),
1769
+ tx.pure.address(beneficiary),
1770
+ tx.pure.u64(amounts[i]),
1771
+ tx.pure.bool(amounts[i] > 0),
1772
+ tx.object(`${this.sharedConfig.zoLootbox.lootboxSettings}`),
1773
+ ],
1774
+ });
1775
+ }
1776
+ }
1777
+ depositToPrizePool(coin, coinObjects, amount) {
1778
+ const tx = new transactions_1.Transaction();
1779
+ const coinObject = this.processCoins(tx, coin, coinObjects);
1780
+ const [depositObject] = tx.splitCoins(coinObject, [tx.pure.u64(amount)]);
1781
+ let module = `${this.consts.zoCore.package}::zlp::ZLP`;
1782
+ if (coin !== 'zlp') {
1783
+ module = this.consts.coins[coin].module;
1784
+ }
1785
+ tx.moveCall({
1786
+ target: `${this.sharedConfig.zoLootbox.package}::lootbox::deposit`,
1787
+ typeArguments: [module],
1788
+ arguments: [
1789
+ tx.object(this.sharedConfig.zoLootbox.adminCap),
1790
+ tx.object(this.sharedConfig.zoLootbox.lootboxTreasury),
1791
+ depositObject,
1792
+ ],
1793
+ });
1794
+ return tx;
1795
+ }
1796
+ withdrawFromPricePool(coin, amount) {
1797
+ const tx = new transactions_1.Transaction();
1798
+ let module = `${this.consts.zoCore.package}::zlp::ZLP`;
1799
+ let metadata = this.consts.zoCore.zlpMetadata;
1800
+ if (coin !== 'zlp') {
1801
+ module = this.consts.coins[coin].module;
1802
+ metadata = this.consts.coins[coin].metadata;
1803
+ }
1804
+ tx.moveCall({
1805
+ target: `${this.sharedConfig.zoLootbox.package}::lootbox::withdraw`,
1806
+ typeArguments: [module],
1807
+ arguments: [
1808
+ tx.object(this.sharedConfig.zoLootbox.adminCap),
1809
+ tx.object(this.sharedConfig.zoLootbox.lootboxTreasury),
1810
+ tx.object(metadata),
1811
+ tx.pure.u64(amount),
1812
+ ],
1813
+ });
1814
+ return tx;
1815
+ }
1816
+ openLootbox(coin, lootbox) {
1817
+ const tx = new transactions_1.Transaction();
1818
+ let module = `${this.consts.zoCore.package}::zlp::ZLP`;
1819
+ let metadata = this.consts.zoCore.zlpMetadata;
1820
+ if (coin !== 'zlp') {
1821
+ module = this.consts.coins[coin].module;
1822
+ metadata = this.consts.coins[coin].metadata;
1823
+ }
1824
+ tx.moveCall({
1825
+ target: `${this.sharedConfig.zoLootbox.upgradedPackage}::lootbox::open_lootbox`,
1826
+ typeArguments: [module],
1827
+ arguments: [
1828
+ tx.object(`${this.sharedConfig.zoLootbox.lootboxTreasury}`),
1829
+ tx.object(lootbox),
1830
+ tx.object(metadata),
1831
+ tx.object(`${this.sharedConfig.zoLootbox.lootboxSettings}`),
1832
+ ],
1833
+ });
1834
+ return tx;
1835
+ }
1836
+ // V2 Lootbox Methods for new contract
1837
+ adminIssueLootboxV2(coin, tiers, beneficiaries, amounts, titles, descriptions, tx) {
1838
+ let module = `${this.consts.zoCore.package}::zlp::ZLP`;
1839
+ if (coin !== 'zlp') {
1840
+ module = this.consts.coins[coin].module;
1841
+ }
1842
+ for (const [i, beneficiary] of beneficiaries.entries()) {
1843
+ const moveCallArgs = {
1844
+ target: `${this.sharedConfig.zoLootboxV2.upgradedPackage}::lootbox::admin_issue_lootbox`,
1845
+ typeArguments: [module],
1846
+ arguments: [
1847
+ tx.object(this.sharedConfig.zoLootboxV2.adminCap),
1848
+ tx.object(this.sharedConfig.zoLootboxV2.lootboxTreasury),
1849
+ tx.pure.u8(tiers[i]),
1850
+ tx.pure.address(beneficiary),
1851
+ tx.pure.u64(amounts[i]),
1852
+ tx.pure.bool(amounts[i] > 0),
1853
+ tx.pure.string(titles[i]),
1854
+ tx.pure.string(descriptions[i]),
1855
+ tx.object(`${this.sharedConfig.zoLootboxV2.lootboxSettings}`),
1856
+ ],
1857
+ };
1858
+ tx.moveCall(moveCallArgs);
1859
+ }
1860
+ }
1861
+ openLootboxV2(coin, lootbox) {
1862
+ const tx = new transactions_1.Transaction();
1863
+ let module = `${this.consts.zoCore.package}::zlp::ZLP`;
1864
+ let metadata = this.consts.zoCore.zlpMetadata;
1865
+ if (coin !== 'zlp') {
1866
+ module = this.consts.coins[coin].module;
1867
+ metadata = this.consts.coins[coin].metadata;
1868
+ }
1869
+ tx.moveCall({
1870
+ target: `${this.sharedConfig.zoLootboxV2.upgradedPackage}::lootbox::open_lootbox`,
1871
+ typeArguments: [module],
1872
+ arguments: [
1873
+ tx.object(this.sharedConfig.zoLootboxV2.lootboxTreasury),
1874
+ tx.object(lootbox),
1875
+ tx.object(metadata),
1876
+ tx.object(this.sharedConfig.zoLootboxV2.lootboxSettings),
1877
+ ],
1878
+ });
1879
+ return tx;
1880
+ }
1881
+ // Vesting Lootbox Methods (V2)
1882
+ adminIssueVestingLootboxV2(_coin, beneficiaries, unlockedAmounts, lockedAmounts, lockDurationsMs, tx) {
1883
+ const module = `${this.consts.zoCore.package}::zlp::ZLP`;
1884
+ for (const [i, beneficiary] of beneficiaries.entries()) {
1885
+ tx.moveCall({
1886
+ target: `${this.sharedConfig.zoLootboxV2.upgradedPackage}::lootbox::admin_issue_vesting_lootbox_precision`,
1887
+ typeArguments: [module],
1888
+ arguments: [
1889
+ tx.object(this.sharedConfig.zoLootboxV2.adminCap),
1890
+ tx.object(this.sharedConfig.zoLootboxV2.lootboxTreasury),
1891
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
1892
+ tx.pure.u64(unlockedAmounts[i]),
1893
+ tx.pure.u64(lockedAmounts[i]),
1894
+ tx.pure.u64(lockDurationsMs[i]),
1895
+ tx.pure.address(beneficiary),
1896
+ ],
1897
+ });
1898
+ }
1899
+ }
1900
+ claimUnlockedV2(coin, vestingLootbox) {
1901
+ const tx = new transactions_1.Transaction();
1902
+ let module = `${this.consts.zoCore.package}::zlp::ZLP`;
1903
+ if (coin !== 'zlp') {
1904
+ module = this.consts.coins[coin].module;
1905
+ }
1906
+ tx.moveCall({
1907
+ target: `${this.sharedConfig.zoLootboxV2.upgradedPackage}::lootbox::claim_unlocked`,
1908
+ typeArguments: [module],
1909
+ arguments: [
1910
+ tx.object(this.sharedConfig.zoLootboxV2.lootboxTreasury),
1911
+ tx.object(vestingLootbox),
1912
+ ],
1913
+ });
1914
+ return tx;
1915
+ }
1916
+ claimVestedV2(coin, vestingLootbox) {
1917
+ const tx = new transactions_1.Transaction();
1918
+ let module = `${this.consts.zoCore.package}::zlp::ZLP`;
1919
+ if (coin !== 'zlp') {
1920
+ module = this.consts.coins[coin].module;
1921
+ }
1922
+ tx.moveCall({
1923
+ target: `${this.sharedConfig.zoLootboxV2.upgradedPackage}::lootbox::claim_vested`,
1924
+ typeArguments: [module],
1925
+ arguments: [
1926
+ tx.object(this.sharedConfig.zoLootboxV2.lootboxTreasury),
1927
+ tx.object(vestingLootbox),
1928
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
1929
+ ],
1930
+ });
1931
+ return tx;
1932
+ }
1933
+ destroyVestingLootboxV2(coin, vestingLootbox) {
1934
+ const tx = new transactions_1.Transaction();
1935
+ let module = `${this.consts.zoCore.package}::zlp::ZLP`;
1936
+ if (coin !== 'zlp') {
1937
+ module = this.consts.coins[coin].module;
1938
+ }
1939
+ tx.moveCall({
1940
+ target: `${this.sharedConfig.zoLootboxV2.upgradedPackage}::lootbox::destroy_vesting_lootbox`,
1941
+ typeArguments: [module],
1942
+ arguments: [tx.object(vestingLootbox)],
1943
+ });
1944
+ return tx;
1945
+ }
1946
+ }
1947
+ exports.ZLPAPI = ZLPAPI;
1948
+ //# sourceMappingURL=ZLPAPI.cjs.map