zo-sdk 0.1.21 → 0.1.23

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 (94) hide show
  1. package/dist/abstract/BaseDataAPI.d.cts +2 -2
  2. package/dist/abstract/BaseDataAPI.d.cts.map +1 -1
  3. package/dist/abstract/BaseDataAPI.d.mts +2 -2
  4. package/dist/abstract/BaseDataAPI.d.mts.map +1 -1
  5. package/dist/consts/deployments-zbtcvc-mainnet.json +180 -0
  6. package/dist/consts/index.cjs +27 -20
  7. package/dist/consts/index.cjs.map +1 -1
  8. package/dist/consts/index.d.cts +5 -17
  9. package/dist/consts/index.d.cts.map +1 -1
  10. package/dist/consts/index.d.mts +5 -17
  11. package/dist/consts/index.d.mts.map +1 -1
  12. package/dist/consts/index.mjs +26 -19
  13. package/dist/consts/index.mjs.map +1 -1
  14. package/dist/factory/SDKFactory.cjs +36 -0
  15. package/dist/factory/SDKFactory.cjs.map +1 -1
  16. package/dist/factory/SDKFactory.d.cts +11 -1
  17. package/dist/factory/SDKFactory.d.cts.map +1 -1
  18. package/dist/factory/SDKFactory.d.mts +11 -1
  19. package/dist/factory/SDKFactory.d.mts.map +1 -1
  20. package/dist/factory/SDKFactory.mjs +36 -0
  21. package/dist/factory/SDKFactory.mjs.map +1 -1
  22. package/dist/implementations/SLPDataAPI.cjs +54 -32
  23. package/dist/implementations/SLPDataAPI.cjs.map +1 -1
  24. package/dist/implementations/SLPDataAPI.d.cts +2 -2
  25. package/dist/implementations/SLPDataAPI.d.cts.map +1 -1
  26. package/dist/implementations/SLPDataAPI.d.mts +2 -2
  27. package/dist/implementations/SLPDataAPI.d.mts.map +1 -1
  28. package/dist/implementations/SLPDataAPI.mjs +54 -32
  29. package/dist/implementations/SLPDataAPI.mjs.map +1 -1
  30. package/dist/implementations/USDZAPI.cjs +1 -1
  31. package/dist/implementations/USDZAPI.cjs.map +1 -1
  32. package/dist/implementations/USDZAPI.d.cts +1 -1
  33. package/dist/implementations/USDZAPI.d.cts.map +1 -1
  34. package/dist/implementations/USDZAPI.d.mts +1 -1
  35. package/dist/implementations/USDZAPI.d.mts.map +1 -1
  36. package/dist/implementations/USDZAPI.mjs +1 -1
  37. package/dist/implementations/USDZAPI.mjs.map +1 -1
  38. package/dist/implementations/ZBTCVCAPI.cjs +984 -0
  39. package/dist/implementations/ZBTCVCAPI.cjs.map +1 -0
  40. package/dist/implementations/ZBTCVCAPI.d.cts +133 -0
  41. package/dist/implementations/ZBTCVCAPI.d.cts.map +1 -0
  42. package/dist/implementations/ZBTCVCAPI.d.mts +133 -0
  43. package/dist/implementations/ZBTCVCAPI.d.mts.map +1 -0
  44. package/dist/implementations/ZBTCVCAPI.mjs +980 -0
  45. package/dist/implementations/ZBTCVCAPI.mjs.map +1 -0
  46. package/dist/implementations/ZBTCVCDataAPI.cjs +824 -0
  47. package/dist/implementations/ZBTCVCDataAPI.cjs.map +1 -0
  48. package/dist/implementations/ZBTCVCDataAPI.d.cts +94 -0
  49. package/dist/implementations/ZBTCVCDataAPI.d.cts.map +1 -0
  50. package/dist/implementations/ZBTCVCDataAPI.d.mts +94 -0
  51. package/dist/implementations/ZBTCVCDataAPI.d.mts.map +1 -0
  52. package/dist/implementations/ZBTCVCDataAPI.mjs +820 -0
  53. package/dist/implementations/ZBTCVCDataAPI.mjs.map +1 -0
  54. package/dist/implementations/index.cjs +5 -1
  55. package/dist/implementations/index.cjs.map +1 -1
  56. package/dist/implementations/index.d.cts +2 -0
  57. package/dist/implementations/index.d.cts.map +1 -1
  58. package/dist/implementations/index.d.mts +2 -0
  59. package/dist/implementations/index.d.mts.map +1 -1
  60. package/dist/implementations/index.mjs +2 -0
  61. package/dist/implementations/index.mjs.map +1 -1
  62. package/dist/interfaces/base.d.cts +2 -2
  63. package/dist/interfaces/base.d.cts.map +1 -1
  64. package/dist/interfaces/base.d.mts +2 -2
  65. package/dist/interfaces/base.d.mts.map +1 -1
  66. package/dist/interfaces/index.cjs +2 -0
  67. package/dist/interfaces/index.cjs.map +1 -1
  68. package/dist/interfaces/index.d.cts +2 -0
  69. package/dist/interfaces/index.d.cts.map +1 -1
  70. package/dist/interfaces/index.d.mts +2 -0
  71. package/dist/interfaces/index.d.mts.map +1 -1
  72. package/dist/interfaces/index.mjs +2 -0
  73. package/dist/interfaces/index.mjs.map +1 -1
  74. package/dist/interfaces/zbtcvc.cjs +7 -0
  75. package/dist/interfaces/zbtcvc.cjs.map +1 -0
  76. package/dist/interfaces/zbtcvc.d.cts +64 -0
  77. package/dist/interfaces/zbtcvc.d.cts.map +1 -0
  78. package/dist/interfaces/zbtcvc.d.mts +64 -0
  79. package/dist/interfaces/zbtcvc.d.mts.map +1 -0
  80. package/dist/interfaces/zbtcvc.mjs +6 -0
  81. package/dist/interfaces/zbtcvc.mjs.map +1 -0
  82. package/package.json +8 -8
  83. package/src/abstract/BaseDataAPI.ts +2 -2
  84. package/src/consts/deployments-zbtcvc-mainnet.json +180 -0
  85. package/src/consts/index.ts +28 -35
  86. package/src/factory/SDKFactory.ts +50 -0
  87. package/src/implementations/SLPDataAPI.ts +71 -41
  88. package/src/implementations/USDZAPI.ts +1 -1
  89. package/src/implementations/ZBTCVCAPI.ts +1453 -0
  90. package/src/implementations/ZBTCVCDataAPI.ts +985 -0
  91. package/src/implementations/index.ts +2 -0
  92. package/src/interfaces/base.ts +2 -2
  93. package/src/interfaces/index.ts +8 -0
  94. package/src/interfaces/zbtcvc.ts +115 -0
@@ -0,0 +1,984 @@
1
+ "use strict";
2
+ /**
3
+ * ZBTCVC API implementation
4
+ * Implements ZBTCVC-specific trading and transaction methods
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.ZBTCVCAPI = void 0;
8
+ const kiosk_1 = require("@mysten/kiosk");
9
+ const transactions_1 = require("@mysten/sui/transactions");
10
+ const utils_1 = require("@mysten/sui/utils");
11
+ const abstract_1 = require("../abstract/index.cjs");
12
+ const consts_1 = require("../consts/index.cjs");
13
+ const utils_2 = require("../utils.cjs");
14
+ const ZBTCVCDataAPI_1 = require("./ZBTCVCDataAPI.cjs");
15
+ class ZBTCVCAPI extends abstract_1.BaseAPI {
16
+ constructor(network, provider, apiEndpoint, connectionURL) {
17
+ super(network, provider, apiEndpoint, connectionURL, consts_1.LPToken.ZBTCVC);
18
+ this.dataAPI = new ZBTCVCDataAPI_1.ZBTCVCDataAPI(network, provider, apiEndpoint, connectionURL);
19
+ }
20
+ claimTokenFromSCard(_token, _coinObjects, _kioskClient, _kioskCap, _scard) {
21
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
22
+ }
23
+ valuateVaults(_tx) {
24
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
25
+ }
26
+ valuateSymbols(_tx) {
27
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
28
+ }
29
+ valuate(_tx) {
30
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
31
+ }
32
+ valuateMarket() {
33
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
34
+ }
35
+ fundingFeeRate(_indexToken, _long) {
36
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
37
+ }
38
+ rebaseFeeRate(_collateralToken, _increase, _amount) {
39
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
40
+ }
41
+ reservingFeeRate(_collateralToken, _amount) {
42
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
43
+ }
44
+ calcPositionReserveFeeAmount(_position) {
45
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
46
+ }
47
+ calcPositionFundingFeeValue(_position) {
48
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
49
+ }
50
+ getMarketInfo() {
51
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
52
+ }
53
+ getVaultInfo(_vault) {
54
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
55
+ }
56
+ getSymbolInfo(_tokenId, _long) {
57
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
58
+ }
59
+ getPositionConfig(_indexToken, _long) {
60
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
61
+ }
62
+ getRebaseFeeModel() {
63
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
64
+ }
65
+ getOpenPositions() {
66
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
67
+ }
68
+ getPositionCapInfoList(_owner) {
69
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
70
+ }
71
+ getPositionInfoList(_positionCapInfoList, _owner, _batchSize) {
72
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
73
+ }
74
+ getOrderCapInfoList(_owner) {
75
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
76
+ }
77
+ getOrderInfoList(_orderCapInfoList, _owner) {
78
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
79
+ }
80
+ getHistory(_trader, _page, _limit, _orderType, _symbol) {
81
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
82
+ }
83
+ getStaked(_owner) {
84
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
85
+ }
86
+ getStakePool() {
87
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
88
+ }
89
+ hasReferral(_referree) {
90
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
91
+ }
92
+ getReferralData(_referree) {
93
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
94
+ }
95
+ clearClosedPosition(pcpId, collateralToken, indexToken, long, tx) {
96
+ tx.moveCall({
97
+ target: `${this.consts.zoCore.upgradedPackage}::market::clear_closed_position`,
98
+ typeArguments: [
99
+ `${this.consts.zoCore.package}::zbtcvc::ZBTCVC`,
100
+ this.consts.coins[collateralToken].module,
101
+ this.consts.coins[indexToken].module,
102
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
103
+ ],
104
+ arguments: [tx.object(this.consts.zoCore.market), tx.object(pcpId)],
105
+ });
106
+ }
107
+ clearOpenPositionOrder(orderCapId, collateralToken, indexToken, long, tx, isV11Order) {
108
+ const funcName = isV11Order ? 'clear_open_position_order' : 'clear_open_position_order';
109
+ tx.moveCall({
110
+ target: `${this.consts.zoCore.upgradedPackage}::market::${funcName}`,
111
+ typeArguments: [
112
+ `${this.consts.zoCore.package}::zbtcvc::ZBTCVC`,
113
+ this.consts.coins[collateralToken].module,
114
+ this.consts.coins[indexToken].module,
115
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
116
+ this.consts.coins[collateralToken].module,
117
+ ],
118
+ arguments: [tx.object(this.consts.zoCore.market), tx.object(orderCapId)],
119
+ });
120
+ }
121
+ clearDecreasePositionOrder(orderCapId, collateralToken, indexToken, long, tx, isV11Order) {
122
+ const funcName = isV11Order ? 'clear_decrease_position_order' : 'clear_decrease_position_order';
123
+ tx.moveCall({
124
+ target: `${this.consts.zoCore.upgradedPackage}::market::${funcName}`,
125
+ typeArguments: [
126
+ `${this.consts.zoCore.package}::zbtcvc::ZBTCVC`,
127
+ this.consts.coins[collateralToken].module,
128
+ this.consts.coins[indexToken].module,
129
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
130
+ this.consts.coins[collateralToken].module,
131
+ ],
132
+ arguments: [tx.object(this.consts.zoCore.market), tx.object(orderCapId)],
133
+ });
134
+ }
135
+ 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) {
136
+ let tx = new transactions_1.Transaction();
137
+ if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
138
+ tx = await this.addReferral(referralAddress, tx);
139
+ }
140
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
141
+ const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage);
142
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
143
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
144
+ if (isLimitOrder) {
145
+ allowTrade = isIocOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
146
+ }
147
+ const kioskTx = new kiosk_1.KioskTransaction({
148
+ transaction: tx,
149
+ kioskClient,
150
+ cap: kioskCap,
151
+ });
152
+ const [sudoCard, promise] = kioskTx.borrow({
153
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
154
+ itemId: scard,
155
+ });
156
+ // Handle oracle initialization and coin processing
157
+ let suiCoinObject;
158
+ if (sponsoredTx) {
159
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
160
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
161
+ }
162
+ else {
163
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx);
164
+ }
165
+ // Process coin splitting
166
+ const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
167
+ tx.moveCall({
168
+ target: `${this.consts.zoCore.upgradedPackage}::market::open_position_with_scard`,
169
+ typeArguments: [
170
+ `${this.consts.zoCore.package}::zbtcvc::ZBTCVC`,
171
+ this.consts.coins[collateralToken].module,
172
+ this.consts.coins[indexToken].module,
173
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
174
+ this.consts.coins[collateralToken].module,
175
+ ],
176
+ arguments: [
177
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
178
+ tx.object(this.consts.zoCore.market),
179
+ tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
180
+ tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
181
+ tx.object(this.consts.zoCore.symbols[symbol].positionConfig),
182
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
183
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
184
+ depositObject,
185
+ feeObject,
186
+ tx.pure.u8(allowTrade),
187
+ tx.pure.u64(size),
188
+ tx.pure.u64(reserveAmount),
189
+ tx.pure.u256(adjustCollateralPrice),
190
+ tx.pure.u256(adjustPrice),
191
+ sudoCard,
192
+ ],
193
+ });
194
+ kioskTx
195
+ .return({
196
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
197
+ item: sudoCard,
198
+ promise,
199
+ })
200
+ .finalize();
201
+ return tx;
202
+ }
203
+ 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) {
204
+ if (!coinObjects) {
205
+ throw new Error(`${this.constructor.name}: coinObjects is required`);
206
+ }
207
+ let tx = new transactions_1.Transaction();
208
+ const kioskTx = new kiosk_1.KioskTransaction({
209
+ transaction: tx,
210
+ kioskClient,
211
+ cap: kioskCap,
212
+ });
213
+ const [sudoCard, promise] = kioskTx.borrow({
214
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
215
+ itemId: scard,
216
+ });
217
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
218
+ const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage);
219
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
220
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
221
+ if (isTriggerOrder) {
222
+ allowTrade = isIocOrder || !isTakeProfitOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
223
+ }
224
+ else {
225
+ isTakeProfitOrder = true;
226
+ }
227
+ // Handle oracle initialization and coin processing
228
+ let suiCoinObject;
229
+ if (sponsoredTx) {
230
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
231
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
232
+ }
233
+ else {
234
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx);
235
+ }
236
+ // Process coin splitting
237
+ const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
238
+ tx.moveCall({
239
+ target: `${this.consts.zoCore.upgradedPackage}::market::decrease_position_with_scard`,
240
+ typeArguments: [
241
+ `${this.consts.zoCore.package}::zbtcvc::ZBTCVC`,
242
+ this.consts.coins[collateralToken].module,
243
+ this.consts.coins[indexToken].module,
244
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
245
+ this.consts.coins[collateralToken].module,
246
+ ],
247
+ arguments: [
248
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
249
+ tx.object(this.consts.zoCore.market),
250
+ tx.object(pcpId),
251
+ tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
252
+ tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
253
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
254
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
255
+ feeObject,
256
+ tx.pure.u8(allowTrade),
257
+ tx.pure.bool(isTakeProfitOrder),
258
+ tx.pure.u64(amount),
259
+ tx.pure.u256(adjustCollateralPrice),
260
+ tx.pure.u256(adjustPrice),
261
+ sudoCard,
262
+ ],
263
+ });
264
+ kioskTx
265
+ .return({
266
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
267
+ item: sudoCard,
268
+ promise,
269
+ })
270
+ .finalize();
271
+ return tx;
272
+ }
273
+ async decreaseMultiPositionsWithSCard(positions, kioskClient, kioskCap, scard, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
274
+ if (!tx) {
275
+ tx = new transactions_1.Transaction();
276
+ }
277
+ // Handle oracle initialization and coin processing
278
+ let suiCoinObject;
279
+ if (sponsoredTx) {
280
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
281
+ tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx, true, suiCoinObject);
282
+ }
283
+ else {
284
+ tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx);
285
+ }
286
+ const kioskTx = new kiosk_1.KioskTransaction({
287
+ transaction: tx,
288
+ kioskClient,
289
+ cap: kioskCap,
290
+ });
291
+ const [sudoCard, promise] = kioskTx.borrow({
292
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
293
+ itemId: scard,
294
+ });
295
+ for (const position of positions) {
296
+ 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;
297
+ let innerIsTakeProfitOrder = isTakeProfitOrder;
298
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
299
+ const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage);
300
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
301
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
302
+ if (isTriggerOrder) {
303
+ allowTrade = isIocOrder || !innerIsTakeProfitOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
304
+ }
305
+ else {
306
+ innerIsTakeProfitOrder = true;
307
+ }
308
+ // Process coin splitting
309
+ const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
310
+ tx.moveCall({
311
+ target: `${this.consts.zoCore.upgradedPackage}::market::decrease_position_with_scard`,
312
+ typeArguments: [
313
+ `${this.consts.zoCore.package}::zbtcvc::ZBTCVC`,
314
+ this.consts.coins[collateralToken].module,
315
+ this.consts.coins[indexToken].module,
316
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
317
+ this.consts.coins[collateralToken].module,
318
+ ],
319
+ arguments: [
320
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
321
+ tx.object(this.consts.zoCore.market),
322
+ tx.object(pcpId),
323
+ tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
324
+ tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
325
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
326
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
327
+ feeObject,
328
+ tx.pure.u8(allowTrade),
329
+ tx.pure.bool(innerIsTakeProfitOrder),
330
+ tx.pure.u64(amount),
331
+ tx.pure.u256(adjustCollateralPrice),
332
+ tx.pure.u256(adjustPrice),
333
+ sudoCard,
334
+ ],
335
+ });
336
+ }
337
+ kioskTx
338
+ .return({
339
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
340
+ item: sudoCard,
341
+ promise,
342
+ })
343
+ .finalize();
344
+ return tx;
345
+ }
346
+ /**
347
+ * Deposits collateral into ZBTCVC vault
348
+ */
349
+ async deposit(coin, coinObjects, amount, minAmountOut = 0, referralAddress, sender, sponsoredTx, suiCoinObjectsForPythUpdate) {
350
+ let tx = new transactions_1.Transaction();
351
+ // Add referral if needed
352
+ if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
353
+ tx = await this.addReferral(referralAddress, tx);
354
+ }
355
+ // Initialize oracle transaction
356
+ const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
357
+ // Handle sponsored transaction case
358
+ if (sponsoredTx) {
359
+ const suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
360
+ tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject);
361
+ // Process deposit coins
362
+ const depositObject = coin === 'sui'
363
+ ? tx.splitCoins(suiCoinObject, [tx.pure.u64(amount)])[0]
364
+ : tx.splitCoins(this.processCoins(tx, coin, coinObjects, true), [tx.pure.u64(amount)])[0];
365
+ const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
366
+ tx.moveCall({
367
+ target: `${this.consts.zoCore.upgradedPackage}::market::deposit`,
368
+ typeArguments: [`${this.consts.zoCore.package}::zbtcvc::ZBTCVC`, this.consts.coins[coin].module],
369
+ arguments: [
370
+ tx.object(this.consts.zoCore.market),
371
+ tx.object(this.consts.zoCore.rebaseFeeModel),
372
+ depositObject,
373
+ tx.pure.u64(minAmountOut),
374
+ vaultsValuation,
375
+ symbolsValuation,
376
+ ],
377
+ });
378
+ return tx;
379
+ }
380
+ // Handle non-sponsored transaction case
381
+ tx = await this.initOracleTxb(pythFeederKeys, tx);
382
+ const depositObject = tx.splitCoins(this.processCoins(tx, coin, coinObjects, false), [tx.pure.u64(amount)])[0];
383
+ const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
384
+ tx.moveCall({
385
+ target: `${this.consts.zoCore.upgradedPackage}::market::deposit`,
386
+ typeArguments: [
387
+ `${this.consts.zoCore.package}::zbtcvc::ZBTCVC`,
388
+ this.consts.coins[coin].module,
389
+ ],
390
+ arguments: [
391
+ tx.object(this.consts.zoCore.market),
392
+ tx.object(this.consts.zoCore.rebaseFeeModel),
393
+ depositObject,
394
+ tx.pure.u64(minAmountOut),
395
+ vaultsValuation,
396
+ symbolsValuation,
397
+ ],
398
+ });
399
+ return tx;
400
+ }
401
+ /**
402
+ * Deposits collateral into ZBTCVC vault
403
+ */
404
+ async depositPtb(coin, coinObjects, amount, minAmountOut = 0, referralAddress, sender, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
405
+ if (!tx) {
406
+ tx = new transactions_1.Transaction();
407
+ }
408
+ // Add referral if needed
409
+ if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
410
+ tx = await this.addReferral(referralAddress, tx);
411
+ }
412
+ // Initialize oracle transaction
413
+ const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
414
+ // Handle sponsored transaction case
415
+ if (sponsoredTx) {
416
+ const suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
417
+ tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject);
418
+ // Process deposit coins
419
+ const depositObject = coin === 'sui'
420
+ ? tx.splitCoins(suiCoinObject, [tx.pure.u64(amount)])[0]
421
+ : tx.splitCoins(this.processCoins(tx, coin, coinObjects, true), [tx.pure.u64(amount)])[0];
422
+ const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
423
+ const [mintedCoin] = tx.moveCall({
424
+ target: `${this.consts.zoCore.upgradedPackage}::market::deposit_ptb`,
425
+ typeArguments: [`${this.consts.zoCore.package}::zbtcvc::ZBTCVC`, this.consts.coins[coin].module],
426
+ arguments: [
427
+ tx.object(this.consts.zoCore.market),
428
+ tx.object(this.consts.zoCore.rebaseFeeModel),
429
+ depositObject,
430
+ tx.pure.u64(minAmountOut),
431
+ vaultsValuation,
432
+ symbolsValuation,
433
+ ],
434
+ });
435
+ return mintedCoin;
436
+ }
437
+ // Handle non-sponsored transaction case
438
+ tx = await this.initOracleTxb(pythFeederKeys, tx);
439
+ const depositObject = tx.splitCoins(this.processCoins(tx, coin, coinObjects, false), [tx.pure.u64(amount)])[0];
440
+ const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
441
+ const [mintedCoin] = tx.moveCall({
442
+ target: `${this.consts.zoCore.upgradedPackage}::market::deposit_ptb`,
443
+ typeArguments: [
444
+ `${this.consts.zoCore.package}::zbtcvc::ZBTCVC`,
445
+ this.consts.coins[coin].module,
446
+ ],
447
+ arguments: [
448
+ tx.object(this.consts.zoCore.market),
449
+ tx.object(this.consts.zoCore.rebaseFeeModel),
450
+ depositObject,
451
+ tx.pure.u64(minAmountOut),
452
+ vaultsValuation,
453
+ symbolsValuation,
454
+ ],
455
+ });
456
+ return mintedCoin;
457
+ }
458
+ /**
459
+ * Withdraws collateral from ZBTCVC vault
460
+ */
461
+ async withdraw(coin, lpCoinObjects, amount, minAmountOut = 0, sponsoredTx, suiCoinObjectsForPythUpdate) {
462
+ let tx = new transactions_1.Transaction();
463
+ // Initialize oracle transaction
464
+ const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
465
+ if (sponsoredTx) {
466
+ const suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
467
+ tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject);
468
+ }
469
+ else {
470
+ tx = await this.initOracleTxb(pythFeederKeys, tx);
471
+ }
472
+ const zbtcvcCoinObject = this.processCoins(tx, 'zbtcvc', lpCoinObjects, false);
473
+ const [withdrawObject] = tx.splitCoins(zbtcvcCoinObject, [tx.pure.u64(amount)]);
474
+ const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
475
+ tx.moveCall({
476
+ target: `${this.consts.zoCore.upgradedPackage}::market::withdraw`,
477
+ typeArguments: [
478
+ `${this.consts.zoCore.package}::zbtcvc::ZBTCVC`,
479
+ this.consts.coins[coin].module,
480
+ ],
481
+ arguments: [
482
+ tx.object(this.consts.zoCore.market),
483
+ tx.object(this.consts.zoCore.rebaseFeeModel),
484
+ withdrawObject,
485
+ tx.pure.u64(minAmountOut),
486
+ vaultsValuation,
487
+ symbolsValuation,
488
+ ],
489
+ });
490
+ return tx;
491
+ }
492
+ /**
493
+ * Stakes ZBTCVC tokens in ZO staking pools
494
+ */
495
+ stake(lpCoinObjects, amount, pool, tx) {
496
+ if (!this.consts.zoStaking) {
497
+ throw new Error('ZO staking configuration not found');
498
+ }
499
+ if (!tx) {
500
+ tx = new transactions_1.Transaction();
501
+ }
502
+ const coinObject = this.processCoins(tx, 'zbtcvc', lpCoinObjects);
503
+ const [depositObject] = tx.splitCoins(coinObject, [tx.pure.u64(amount)]);
504
+ tx.moveCall({
505
+ target: `${this.consts.zoStaking.package}::pool::deposit`,
506
+ typeArguments: [
507
+ `${this.consts.zoCore.package}::zbtcvc::ZBTCVC`,
508
+ `${this.consts.coins.sui.module}`,
509
+ ],
510
+ arguments: [
511
+ tx.object(pool),
512
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
513
+ depositObject,
514
+ ],
515
+ });
516
+ return tx;
517
+ }
518
+ /**
519
+ * Stakes ZBTCVC tokens using coin object only (PTB)
520
+ */
521
+ stakeCoinObject(coinObject, pool, tx) {
522
+ if (!this.consts.zoStaking) {
523
+ throw new Error('ZO staking configuration not found');
524
+ }
525
+ if (!tx) {
526
+ tx = new transactions_1.Transaction();
527
+ }
528
+ tx.moveCall({
529
+ target: `${this.consts.zoStaking.package}::pool::deposit`,
530
+ typeArguments: [
531
+ `${this.consts.zoCore.package}::zbtcvc::ZBTCVC`,
532
+ `${this.consts.coins.sui.module}`,
533
+ ],
534
+ arguments: [
535
+ tx.object(pool),
536
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
537
+ coinObject,
538
+ ],
539
+ });
540
+ return tx;
541
+ }
542
+ /**
543
+ * Unstakes ZBTCVC tokens from ZO staking pools
544
+ */
545
+ unstake(credentials, amount, pool, tx) {
546
+ if (!this.consts.zoStaking) {
547
+ throw new Error('ZO staking configuration not found');
548
+ }
549
+ let unstakeAmount = amount;
550
+ if (!tx) {
551
+ tx = new transactions_1.Transaction();
552
+ }
553
+ for (const credential of credentials) {
554
+ const withdrawAmount = (() => {
555
+ const min = (a, b) => a < b ? a : b;
556
+ return min(unstakeAmount, credential.amount);
557
+ })();
558
+ unstakeAmount -= withdrawAmount;
559
+ tx.moveCall({
560
+ target: `${this.consts.zoStaking.package}::pool::withdraw`,
561
+ typeArguments: [
562
+ `${this.consts.zoCore.package}::zbtcvc::ZBTCVC`,
563
+ `${this.consts.coins.sui.module}`,
564
+ ],
565
+ arguments: [
566
+ tx.object(pool),
567
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
568
+ tx.object(credential.id),
569
+ tx.pure.u64(withdrawAmount),
570
+ ],
571
+ });
572
+ if (credential.amount === BigInt(0)) {
573
+ tx.moveCall({
574
+ target: `${this.consts.zoStaking.package}::pool::clear_empty_credential`,
575
+ typeArguments: [
576
+ `${this.consts.zoCore.package}::zbtcvc::ZBTCVC`,
577
+ `${this.consts.coins.sui.module}`,
578
+ ],
579
+ arguments: [tx.object(credential.id)],
580
+ });
581
+ }
582
+ }
583
+ return tx;
584
+ }
585
+ async swap(fromToken, toToken, fromAmount, fromCoinObjects, minAmountOut) {
586
+ const tx = await this.initOracleTxb(Object.keys(this.consts.zoCore.vaults));
587
+ const fromCoinObject = this.processCoins(tx, fromToken, fromCoinObjects);
588
+ const [fromDepositObject] = tx.splitCoins(fromCoinObject, [tx.pure.u64(fromAmount)]);
589
+ const vaultsValuation = this.dataAPI.valuateVaults(tx);
590
+ tx.moveCall({
591
+ target: `${this.consts.zoCore.upgradedPackage}::market::swap`,
592
+ typeArguments: [
593
+ `${this.consts.zoCore.package}::zbtcvc::ZBTCVC`,
594
+ this.consts.coins[fromToken].module,
595
+ this.consts.coins[toToken].module,
596
+ ],
597
+ arguments: [
598
+ tx.object(this.consts.zoCore.market),
599
+ tx.object(this.consts.zoCore.rebaseFeeModel),
600
+ fromDepositObject,
601
+ tx.pure.u64(minAmountOut || 0),
602
+ vaultsValuation,
603
+ ],
604
+ });
605
+ return tx;
606
+ }
607
+ /**
608
+ * Opens a new position in ZBTCVC
609
+ */
610
+ 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) {
611
+ let tx = new transactions_1.Transaction();
612
+ if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
613
+ tx = await this.addReferral(referralAddress, tx);
614
+ }
615
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
616
+ const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage);
617
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
618
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
619
+ if (isLimitOrder) {
620
+ allowTrade = isIocOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
621
+ }
622
+ // Handle oracle initialization and coin processing
623
+ let suiCoinObject;
624
+ if (sponsoredTx) {
625
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
626
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
627
+ }
628
+ else {
629
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx);
630
+ }
631
+ // Process coin splitting
632
+ const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
633
+ tx.moveCall({
634
+ target: `${this.consts.zoCore.upgradedPackage}::market::open_position`,
635
+ typeArguments: [
636
+ `${this.consts.zoCore.package}::zbtcvc::ZBTCVC`,
637
+ this.consts.coins[collateralToken].module,
638
+ this.consts.coins[indexToken].module,
639
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
640
+ this.consts.coins[collateralToken].module,
641
+ ],
642
+ arguments: [
643
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
644
+ tx.object(this.consts.zoCore.market),
645
+ tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
646
+ tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
647
+ tx.object(this.consts.zoCore.symbols[symbol].positionConfig),
648
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
649
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
650
+ depositObject,
651
+ feeObject,
652
+ tx.pure.u8(allowTrade),
653
+ tx.pure.u64(size),
654
+ tx.pure.u64(reserveAmount),
655
+ tx.pure.u256(adjustCollateralPrice),
656
+ tx.pure.u256(adjustPrice),
657
+ ],
658
+ });
659
+ return tx;
660
+ }
661
+ /**
662
+ * Decreases an existing position in ZBTCVC
663
+ */
664
+ 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) {
665
+ if (!coinObjects) {
666
+ throw new Error(`${this.constructor.name}: coinObjects is required`);
667
+ }
668
+ let tx = new transactions_1.Transaction();
669
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
670
+ const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage);
671
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
672
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
673
+ if (isTriggerOrder) {
674
+ allowTrade = isIocOrder || !isTakeProfitOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
675
+ }
676
+ else {
677
+ isTakeProfitOrder = true;
678
+ }
679
+ // Handle oracle initialization and coin processing
680
+ let suiCoinObject;
681
+ if (sponsoredTx) {
682
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
683
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
684
+ }
685
+ else {
686
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx);
687
+ }
688
+ // Process coin splitting
689
+ const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
690
+ tx.moveCall({
691
+ target: `${this.consts.zoCore.upgradedPackage}::market::decrease_position`,
692
+ typeArguments: [
693
+ `${this.consts.zoCore.package}::zbtcvc::ZBTCVC`,
694
+ this.consts.coins[collateralToken].module,
695
+ this.consts.coins[indexToken].module,
696
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
697
+ this.consts.coins[collateralToken].module,
698
+ ],
699
+ arguments: [
700
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
701
+ tx.object(this.consts.zoCore.market),
702
+ tx.object(pcpId),
703
+ tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
704
+ tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
705
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
706
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
707
+ feeObject,
708
+ tx.pure.u8(allowTrade),
709
+ tx.pure.bool(isTakeProfitOrder),
710
+ tx.pure.u64(amount),
711
+ tx.pure.u256(adjustCollateralPrice),
712
+ tx.pure.u256(adjustPrice),
713
+ ],
714
+ });
715
+ return tx;
716
+ }
717
+ async decreaseMultiPositions(positions, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
718
+ if (!tx) {
719
+ tx = new transactions_1.Transaction();
720
+ }
721
+ // Handle oracle initialization and coin processing
722
+ let suiCoinObject;
723
+ if (sponsoredTx) {
724
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
725
+ tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx, true, suiCoinObject);
726
+ }
727
+ else {
728
+ tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx);
729
+ }
730
+ for (const position of positions) {
731
+ 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;
732
+ let innerIsTakeProfitOrder = isTakeProfitOrder;
733
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
734
+ const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage);
735
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
736
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
737
+ if (isTriggerOrder) {
738
+ allowTrade = isIocOrder || !innerIsTakeProfitOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
739
+ }
740
+ else {
741
+ innerIsTakeProfitOrder = true;
742
+ }
743
+ // Process coin splitting
744
+ const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
745
+ tx.moveCall({
746
+ target: `${this.consts.zoCore.upgradedPackage}::market::decrease_position`,
747
+ typeArguments: [
748
+ `${this.consts.zoCore.package}::zbtcvc::ZBTCVC`,
749
+ this.consts.coins[collateralToken].module,
750
+ this.consts.coins[indexToken].module,
751
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
752
+ this.consts.coins[collateralToken].module,
753
+ ],
754
+ arguments: [
755
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
756
+ tx.object(this.consts.zoCore.market),
757
+ tx.object(pcpId),
758
+ tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
759
+ tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
760
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
761
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
762
+ feeObject,
763
+ tx.pure.u8(allowTrade),
764
+ tx.pure.bool(innerIsTakeProfitOrder),
765
+ tx.pure.u64(amount),
766
+ tx.pure.u256(adjustCollateralPrice),
767
+ tx.pure.u256(adjustPrice),
768
+ ],
769
+ });
770
+ }
771
+ return tx;
772
+ }
773
+ /**
774
+ * Pledges in position (ZBTCVC-specific functionality)
775
+ */
776
+ async pledgeInPosition(pcpId, collateralToken, indexToken, amount, coinObjects, long, sponsoredTx, suiCoinObjectsForPythUpdate) {
777
+ let tx = new transactions_1.Transaction();
778
+ // Handle oracle initialization and coin processing
779
+ let suiCoinObject;
780
+ if (sponsoredTx) {
781
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
782
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
783
+ }
784
+ else {
785
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx);
786
+ }
787
+ // Process coin splitting
788
+ const [depositObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(amount)], sponsoredTx, suiCoinObject);
789
+ tx.moveCall({
790
+ target: `${this.consts.zoCore.upgradedPackage}::market::pledge_in_position`,
791
+ typeArguments: [
792
+ `${this.consts.zoCore.package}::zbtcvc::ZBTCVC`,
793
+ this.consts.coins[collateralToken].module,
794
+ this.consts.coins[indexToken].module,
795
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
796
+ ],
797
+ arguments: [tx.object(this.consts.zoCore.market), tx.object(pcpId), depositObject],
798
+ });
799
+ return tx;
800
+ }
801
+ async redeemFromPosition(pcpId, collateralToken, indexToken, amount, long, sponsoredTx, suiCoinObjectsForPythUpdate) {
802
+ let tx = new transactions_1.Transaction();
803
+ // Handle oracle initialization and coin processing
804
+ let suiCoinObject;
805
+ if (sponsoredTx) {
806
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
807
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
808
+ }
809
+ else {
810
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx);
811
+ }
812
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
813
+ tx.moveCall({
814
+ target: `${this.consts.zoCore.upgradedPackage}::market::redeem_from_position`,
815
+ typeArguments: [
816
+ `${this.consts.zoCore.package}::zbtcvc::ZBTCVC`,
817
+ this.consts.coins[collateralToken].module,
818
+ this.consts.coins[indexToken].module,
819
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
820
+ ],
821
+ arguments: [
822
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
823
+ tx.object(this.consts.zoCore.market),
824
+ tx.object(pcpId),
825
+ tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
826
+ tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
827
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
828
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
829
+ tx.pure.u64(amount),
830
+ ],
831
+ });
832
+ return tx;
833
+ }
834
+ cancelOrder(orderCapId, collateralToken, indexToken, long, type, isV11Order) {
835
+ const tx = new transactions_1.Transaction();
836
+ let functionName = '';
837
+ switch (type) {
838
+ case 'OPEN_POSITION': {
839
+ functionName = isV11Order ? 'clear_open_position_order' : 'clear_open_position_order';
840
+ break;
841
+ }
842
+ case 'DECREASE_POSITION': {
843
+ functionName = isV11Order
844
+ ? 'clear_decrease_position_order'
845
+ : 'clear_decrease_position_order';
846
+ break;
847
+ }
848
+ default: {
849
+ throw new Error('invalid order type');
850
+ }
851
+ }
852
+ tx.moveCall({
853
+ target: `${this.consts.zoCore.upgradedPackage}::market::${functionName}`,
854
+ typeArguments: [
855
+ `${this.consts.zoCore.package}::zbtcvc::ZBTCVC`,
856
+ this.consts.coins[collateralToken].module,
857
+ this.consts.coins[indexToken].module,
858
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
859
+ this.consts.coins[collateralToken].module,
860
+ ],
861
+ arguments: [tx.object(this.consts.zoCore.market), tx.object(orderCapId)],
862
+ });
863
+ return tx;
864
+ }
865
+ cancelMultiOrders(orders, tx) {
866
+ if (!tx) {
867
+ tx = new transactions_1.Transaction();
868
+ }
869
+ for (const order of orders) {
870
+ const { orderCapId, collateralToken, indexToken, long, type, isV11Order } = order;
871
+ let functionName = '';
872
+ switch (type) {
873
+ case 'OPEN_POSITION': {
874
+ functionName = isV11Order ? 'clear_open_position_order' : 'clear_open_position_order';
875
+ break;
876
+ }
877
+ case 'DECREASE_POSITION': {
878
+ functionName = isV11Order
879
+ ? 'clear_decrease_position_order'
880
+ : 'clear_decrease_position_order';
881
+ break;
882
+ }
883
+ default: {
884
+ throw new Error('invalid order type');
885
+ }
886
+ }
887
+ tx.moveCall({
888
+ target: `${this.consts.zoCore.upgradedPackage}::market::${functionName}`,
889
+ typeArguments: [
890
+ `${this.consts.zoCore.package}::zbtcvc::ZBTCVC`,
891
+ this.consts.coins[collateralToken].module,
892
+ this.consts.coins[indexToken].module,
893
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
894
+ this.consts.coins[collateralToken].module,
895
+ ],
896
+ arguments: [tx.object(this.consts.zoCore.market), tx.object(orderCapId)],
897
+ });
898
+ }
899
+ return tx;
900
+ }
901
+ addReferral(referralAddress, tx) {
902
+ if (!tx) {
903
+ tx = new transactions_1.Transaction();
904
+ }
905
+ tx.moveCall({
906
+ target: `${this.consts.zoCore.upgradedPackage}::market::add_new_referral`,
907
+ typeArguments: [`${this.consts.zoCore.package}::zbtcvc::ZBTCVC`],
908
+ arguments: [tx.object(this.consts.zoCore.market), tx.object(referralAddress)],
909
+ });
910
+ return tx;
911
+ }
912
+ async adminUpdatePriceFeed(collateralToken, indexToken) {
913
+ const tx = await this.initOracleTxb([collateralToken, indexToken]);
914
+ return tx;
915
+ }
916
+ adminSettlePosition(positionId, owner, collateralToken, indexToken, long) {
917
+ const tx = new transactions_1.Transaction();
918
+ tx.moveCall({
919
+ target: `${this.consts.zoCore.upgradedPackage}::market::force_settle_position`,
920
+ typeArguments: [
921
+ `${this.consts.zoCore.package}::zbtcvc::ZBTCVC`,
922
+ this.consts.coins[collateralToken].module,
923
+ this.consts.coins[indexToken].module,
924
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
925
+ ],
926
+ arguments: [
927
+ tx.object(this.consts.zoCore.adminCap),
928
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
929
+ tx.object(this.consts.zoCore.market),
930
+ tx.object(owner),
931
+ tx.object(positionId),
932
+ ],
933
+ });
934
+ this.adminClearClosedPosition(positionId, owner, collateralToken, indexToken, long, tx);
935
+ return tx;
936
+ }
937
+ adminDecreasePosition(positionId, owner, collateralToken, indexToken, positionAmount, amount, long) {
938
+ const tx = new transactions_1.Transaction();
939
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
940
+ tx.moveCall({
941
+ target: `${this.consts.zoCore.upgradedPackage}::market::force_close_position`,
942
+ typeArguments: [
943
+ `${this.consts.zoCore.package}::zbtcvc::ZBTCVC`,
944
+ this.consts.coins[collateralToken].module,
945
+ this.consts.coins[indexToken].module,
946
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
947
+ ],
948
+ arguments: [
949
+ tx.object(this.consts.zoCore.adminCap),
950
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
951
+ tx.object(this.consts.zoCore.market),
952
+ tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
953
+ tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
954
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
955
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
956
+ tx.object(owner),
957
+ tx.object(positionId),
958
+ ],
959
+ });
960
+ if (amount === BigInt(positionAmount)) {
961
+ this.adminClearClosedPosition(positionId, owner, collateralToken, indexToken, long, tx);
962
+ }
963
+ return tx;
964
+ }
965
+ adminClearClosedPosition(positionId, owner, collateralToken, indexToken, long, tx) {
966
+ tx.moveCall({
967
+ target: `${this.consts.zoCore.upgradedPackage}::market::force_clear_closed_position`,
968
+ typeArguments: [
969
+ `${this.consts.zoCore.package}::zbtcvc::ZBTCVC`,
970
+ this.consts.coins[collateralToken].module,
971
+ this.consts.coins[indexToken].module,
972
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
973
+ ],
974
+ arguments: [
975
+ tx.object(this.consts.zoCore.adminCap),
976
+ tx.object(this.consts.zoCore.market),
977
+ tx.object(positionId),
978
+ tx.object(owner),
979
+ ],
980
+ });
981
+ }
982
+ }
983
+ exports.ZBTCVCAPI = ZBTCVCAPI;
984
+ //# sourceMappingURL=ZBTCVCAPI.cjs.map