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