@zofai/zo-sdk 0.2.9 → 0.2.11

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 (173) hide show
  1. package/dist/abstract/BaseAPI.cjs +7 -1
  2. package/dist/abstract/BaseAPI.cjs.map +1 -1
  3. package/dist/abstract/BaseAPI.d.cts +11 -10
  4. package/dist/abstract/BaseAPI.d.cts.map +1 -1
  5. package/dist/abstract/BaseAPI.d.mts +11 -10
  6. package/dist/abstract/BaseAPI.d.mts.map +1 -1
  7. package/dist/abstract/BaseAPI.mjs +7 -1
  8. package/dist/abstract/BaseAPI.mjs.map +1 -1
  9. package/dist/abstract/BaseDataAPI.d.cts +1 -1
  10. package/dist/abstract/BaseDataAPI.d.cts.map +1 -1
  11. package/dist/abstract/BaseDataAPI.d.mts +1 -1
  12. package/dist/abstract/BaseDataAPI.d.mts.map +1 -1
  13. package/dist/api.cjs +12 -12
  14. package/dist/api.cjs.map +1 -1
  15. package/dist/api.d.cts +1 -1
  16. package/dist/api.d.cts.map +1 -1
  17. package/dist/api.d.mts +1 -1
  18. package/dist/api.d.mts.map +1 -1
  19. package/dist/api.mjs +12 -12
  20. package/dist/api.mjs.map +1 -1
  21. package/dist/bcs.d.cts +41 -71
  22. package/dist/bcs.d.cts.map +1 -1
  23. package/dist/bcs.d.mts +41 -71
  24. package/dist/bcs.d.mts.map +1 -1
  25. package/dist/coins.cjs +74 -0
  26. package/dist/coins.cjs.map +1 -0
  27. package/dist/coins.d.cts +37 -0
  28. package/dist/coins.d.cts.map +1 -0
  29. package/dist/coins.d.mts +37 -0
  30. package/dist/coins.d.mts.map +1 -0
  31. package/dist/coins.mjs +67 -0
  32. package/dist/coins.mjs.map +1 -0
  33. package/dist/data.d.cts +6 -6
  34. package/dist/data.d.cts.map +1 -1
  35. package/dist/data.d.mts +6 -6
  36. package/dist/data.d.mts.map +1 -1
  37. package/dist/factory/SDKFactory.d.cts +1 -1
  38. package/dist/factory/SDKFactory.d.cts.map +1 -1
  39. package/dist/factory/SDKFactory.d.mts +1 -1
  40. package/dist/factory/SDKFactory.d.mts.map +1 -1
  41. package/dist/implementations/SLPAPI.cjs +192 -100
  42. package/dist/implementations/SLPAPI.cjs.map +1 -1
  43. package/dist/implementations/SLPAPI.d.cts +24 -24
  44. package/dist/implementations/SLPAPI.d.cts.map +1 -1
  45. package/dist/implementations/SLPAPI.d.mts +24 -24
  46. package/dist/implementations/SLPAPI.d.mts.map +1 -1
  47. package/dist/implementations/SLPAPI.mjs +192 -100
  48. package/dist/implementations/SLPAPI.mjs.map +1 -1
  49. package/dist/implementations/SLPDataAPI.cjs +2 -2
  50. package/dist/implementations/SLPDataAPI.cjs.map +1 -1
  51. package/dist/implementations/SLPDataAPI.d.cts +5 -5
  52. package/dist/implementations/SLPDataAPI.d.cts.map +1 -1
  53. package/dist/implementations/SLPDataAPI.d.mts +5 -5
  54. package/dist/implementations/SLPDataAPI.d.mts.map +1 -1
  55. package/dist/implementations/SLPDataAPI.mjs +2 -2
  56. package/dist/implementations/SLPDataAPI.mjs.map +1 -1
  57. package/dist/implementations/USDZAPI.cjs +176 -92
  58. package/dist/implementations/USDZAPI.cjs.map +1 -1
  59. package/dist/implementations/USDZAPI.d.cts +22 -22
  60. package/dist/implementations/USDZAPI.d.cts.map +1 -1
  61. package/dist/implementations/USDZAPI.d.mts +22 -22
  62. package/dist/implementations/USDZAPI.d.mts.map +1 -1
  63. package/dist/implementations/USDZAPI.mjs +176 -92
  64. package/dist/implementations/USDZAPI.mjs.map +1 -1
  65. package/dist/implementations/USDZDataAPI.d.cts +5 -5
  66. package/dist/implementations/USDZDataAPI.d.cts.map +1 -1
  67. package/dist/implementations/USDZDataAPI.d.mts +5 -5
  68. package/dist/implementations/USDZDataAPI.d.mts.map +1 -1
  69. package/dist/implementations/ZBTCVCAPI.cjs +84 -46
  70. package/dist/implementations/ZBTCVCAPI.cjs.map +1 -1
  71. package/dist/implementations/ZBTCVCAPI.d.cts +12 -12
  72. package/dist/implementations/ZBTCVCAPI.d.cts.map +1 -1
  73. package/dist/implementations/ZBTCVCAPI.d.mts +12 -12
  74. package/dist/implementations/ZBTCVCAPI.d.mts.map +1 -1
  75. package/dist/implementations/ZBTCVCAPI.mjs +84 -46
  76. package/dist/implementations/ZBTCVCAPI.mjs.map +1 -1
  77. package/dist/implementations/ZBTCVCDataAPI.cjs.map +1 -1
  78. package/dist/implementations/ZBTCVCDataAPI.d.cts +5 -5
  79. package/dist/implementations/ZBTCVCDataAPI.d.cts.map +1 -1
  80. package/dist/implementations/ZBTCVCDataAPI.d.mts +5 -5
  81. package/dist/implementations/ZBTCVCDataAPI.d.mts.map +1 -1
  82. package/dist/implementations/ZBTCVCDataAPI.mjs.map +1 -1
  83. package/dist/implementations/ZLPAPI.cjs +192 -100
  84. package/dist/implementations/ZLPAPI.cjs.map +1 -1
  85. package/dist/implementations/ZLPAPI.d.cts +24 -24
  86. package/dist/implementations/ZLPAPI.d.cts.map +1 -1
  87. package/dist/implementations/ZLPAPI.d.mts +24 -24
  88. package/dist/implementations/ZLPAPI.d.mts.map +1 -1
  89. package/dist/implementations/ZLPAPI.mjs +192 -100
  90. package/dist/implementations/ZLPAPI.mjs.map +1 -1
  91. package/dist/implementations/ZLPDataAPI.cjs.map +1 -1
  92. package/dist/implementations/ZLPDataAPI.d.cts +5 -5
  93. package/dist/implementations/ZLPDataAPI.d.cts.map +1 -1
  94. package/dist/implementations/ZLPDataAPI.d.mts +5 -5
  95. package/dist/implementations/ZLPDataAPI.d.mts.map +1 -1
  96. package/dist/implementations/ZLPDataAPI.mjs.map +1 -1
  97. package/dist/index.cjs +2 -0
  98. package/dist/index.cjs.map +1 -1
  99. package/dist/index.d.cts +3 -1
  100. package/dist/index.d.cts.map +1 -1
  101. package/dist/index.d.mts +3 -1
  102. package/dist/index.d.mts.map +1 -1
  103. package/dist/index.mjs +2 -0
  104. package/dist/index.mjs.map +1 -1
  105. package/dist/interfaces/base.d.cts +26 -22
  106. package/dist/interfaces/base.d.cts.map +1 -1
  107. package/dist/interfaces/base.d.mts +26 -22
  108. package/dist/interfaces/base.d.mts.map +1 -1
  109. package/dist/interfaces/slp.d.cts +1 -1
  110. package/dist/interfaces/slp.d.cts.map +1 -1
  111. package/dist/interfaces/slp.d.mts +1 -1
  112. package/dist/interfaces/slp.d.mts.map +1 -1
  113. package/dist/interfaces/usdz.d.cts +1 -1
  114. package/dist/interfaces/usdz.d.cts.map +1 -1
  115. package/dist/interfaces/usdz.d.mts +1 -1
  116. package/dist/interfaces/usdz.d.mts.map +1 -1
  117. package/dist/interfaces/zbtcvc.d.cts +1 -1
  118. package/dist/interfaces/zbtcvc.d.cts.map +1 -1
  119. package/dist/interfaces/zbtcvc.d.mts +1 -1
  120. package/dist/interfaces/zbtcvc.d.mts.map +1 -1
  121. package/dist/interfaces/zlp.d.cts +1 -1
  122. package/dist/interfaces/zlp.d.cts.map +1 -1
  123. package/dist/interfaces/zlp.d.mts +1 -1
  124. package/dist/interfaces/zlp.d.mts.map +1 -1
  125. package/dist/oracle.cjs +27 -22
  126. package/dist/oracle.cjs.map +1 -1
  127. package/dist/oracle.d.cts +14 -2
  128. package/dist/oracle.d.cts.map +1 -1
  129. package/dist/oracle.d.mts +14 -2
  130. package/dist/oracle.d.mts.map +1 -1
  131. package/dist/oracle.mjs +27 -22
  132. package/dist/oracle.mjs.map +1 -1
  133. package/dist/suiClient.cjs +8 -0
  134. package/dist/suiClient.cjs.map +1 -0
  135. package/dist/suiClient.d.cts +8 -0
  136. package/dist/suiClient.d.cts.map +1 -0
  137. package/dist/suiClient.d.mts +8 -0
  138. package/dist/suiClient.d.mts.map +1 -0
  139. package/dist/suiClient.mjs +2 -0
  140. package/dist/suiClient.mjs.map +1 -0
  141. package/dist/utils.cjs +7 -3
  142. package/dist/utils.cjs.map +1 -1
  143. package/dist/utils.d.cts +2 -2
  144. package/dist/utils.d.cts.map +1 -1
  145. package/dist/utils.d.mts +2 -2
  146. package/dist/utils.d.mts.map +1 -1
  147. package/dist/utils.mjs +7 -3
  148. package/dist/utils.mjs.map +1 -1
  149. package/package.json +4 -4
  150. package/src/abstract/BaseAPI.ts +11 -9
  151. package/src/abstract/BaseDataAPI.ts +1 -1
  152. package/src/api.ts +13 -17
  153. package/src/coins.ts +116 -0
  154. package/src/data.ts +1 -1
  155. package/src/factory/SDKFactory.ts +1 -1
  156. package/src/implementations/SLPAPI.ts +200 -116
  157. package/src/implementations/SLPDataAPI.ts +3 -3
  158. package/src/implementations/USDZAPI.ts +185 -95
  159. package/src/implementations/USDZDataAPI.ts +1 -1
  160. package/src/implementations/ZBTCVCAPI.ts +99 -53
  161. package/src/implementations/ZBTCVCDataAPI.ts +1 -1
  162. package/src/implementations/ZLPAPI.ts +200 -111
  163. package/src/implementations/ZLPDataAPI.ts +1 -1
  164. package/src/index.ts +3 -1
  165. package/src/interfaces/base.ts +14 -22
  166. package/src/interfaces/slp.ts +0 -1
  167. package/src/interfaces/usdz.ts +0 -1
  168. package/src/interfaces/zbtcvc.ts +0 -1
  169. package/src/interfaces/zlp.ts +0 -1
  170. package/src/oracle.ts +70 -30
  171. package/src/suiClient.ts +11 -0
  172. package/src/utils.ts +9 -3
  173. package/tsconfig.json +8 -1
@@ -26,7 +26,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
26
26
  /**
27
27
  * Deposits collateral into ZLP vault
28
28
  */
29
- async deposit(coin, coinObjects, amount, minAmountOut = 0, referralAddress, sender, sponsoredTx, suiCoinObjectsForPythUpdate) {
29
+ async deposit(coin, coinObjects, amount, minAmountOut = 0, referralAddress, sender, sponsoredTx) {
30
30
  let tx = new transactions_1.Transaction();
31
31
  // Add referral if needed
32
32
  if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
@@ -36,8 +36,12 @@ class ZLPAPI extends abstract_1.BaseAPI {
36
36
  const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
37
37
  // Handle sponsored transaction case
38
38
  if (sponsoredTx) {
39
- const suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
40
- tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject);
39
+ const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
40
+ sender: this.requireSenderForSponsored(sender),
41
+ additionalSuiAmount: coin === 'sui' ? BigInt(amount) : 0n,
42
+ });
43
+ tx = oracle.tx;
44
+ const { suiCoinObject } = oracle;
41
45
  // Process deposit coins
42
46
  const depositObject = coin === 'sui'
43
47
  ? tx.splitCoins(suiCoinObject, [tx.pure.u64(amount)])[0]
@@ -58,7 +62,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
58
62
  return tx;
59
63
  }
60
64
  // Handle non-sponsored transaction case
61
- tx = await this.initOracleTxb(pythFeederKeys, tx);
65
+ tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
62
66
  const depositObject = tx.splitCoins(this.processCoins(tx, coin, coinObjects, false), [tx.pure.u64(amount)])[0];
63
67
  const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
64
68
  tx.moveCall({
@@ -81,7 +85,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
81
85
  /**
82
86
  * Deposits collateral into ZLP vault and returns a coin
83
87
  */
84
- async depositPtb(coin, coinObjects, amount, minAmountOut = 0, referralAddress, sender, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
88
+ async depositPtb(coin, coinObjects, amount, minAmountOut = 0, referralAddress, sender, tx, sponsoredTx) {
85
89
  if (!tx) {
86
90
  tx = new transactions_1.Transaction();
87
91
  }
@@ -93,8 +97,12 @@ class ZLPAPI extends abstract_1.BaseAPI {
93
97
  const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
94
98
  // Handle sponsored transaction case
95
99
  if (sponsoredTx) {
96
- const suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
97
- tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject);
100
+ const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
101
+ sender: this.requireSenderForSponsored(sender),
102
+ additionalSuiAmount: coin === 'sui' ? BigInt(amount) : 0n,
103
+ });
104
+ tx = oracle.tx;
105
+ const { suiCoinObject } = oracle;
98
106
  // Process deposit coins
99
107
  const depositObject = coin === 'sui'
100
108
  ? tx.splitCoins(suiCoinObject, [tx.pure.u64(amount)])[0]
@@ -115,7 +123,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
115
123
  return mintedCoin;
116
124
  }
117
125
  // Handle non-sponsored transaction case
118
- tx = await this.initOracleTxb(pythFeederKeys, tx);
126
+ tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
119
127
  const depositObject = tx.splitCoins(this.processCoins(tx, coin, coinObjects, false), [tx.pure.u64(amount)])[0];
120
128
  const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
121
129
  const [mintedCoin] = tx.moveCall({
@@ -135,7 +143,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
135
143
  });
136
144
  return mintedCoin;
137
145
  }
138
- async depositWithPtb(coin, depositObject, minAmountOut = 0, referralAddress, sender, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
146
+ async depositWithPtb(coin, depositObject, minAmountOut = 0, referralAddress, sender, tx, sponsoredTx) {
139
147
  if (!tx) {
140
148
  tx = new transactions_1.Transaction();
141
149
  }
@@ -147,8 +155,12 @@ class ZLPAPI extends abstract_1.BaseAPI {
147
155
  const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
148
156
  // Handle sponsored transaction case
149
157
  if (sponsoredTx) {
150
- const suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
151
- tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject);
158
+ const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
159
+ sender: this.requireSenderForSponsored(sender),
160
+ additionalSuiAmount: 0n,
161
+ });
162
+ tx = oracle.tx;
163
+ const { suiCoinObject } = oracle;
152
164
  const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
153
165
  tx.moveCall({
154
166
  target: `${this.consts.zoCore.upgradedPackage}::market::deposit`,
@@ -165,7 +177,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
165
177
  return tx;
166
178
  }
167
179
  // Handle non-sponsored transaction case
168
- tx = await this.initOracleTxb(pythFeederKeys, tx);
180
+ tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
169
181
  const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
170
182
  tx.moveCall({
171
183
  target: `${this.consts.zoCore.upgradedPackage}::market::deposit`,
@@ -187,16 +199,20 @@ class ZLPAPI extends abstract_1.BaseAPI {
187
199
  /**
188
200
  * Withdraws collateral from ZLP vault
189
201
  */
190
- async withdraw(coin, lpCoinObjects, amount, minAmountOut = 0, sponsoredTx, suiCoinObjectsForPythUpdate) {
202
+ async withdraw(coin, lpCoinObjects, amount, minAmountOut = 0, sponsoredTx, sender) {
191
203
  let tx = new transactions_1.Transaction();
192
204
  // Initialize oracle transaction
193
205
  const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
194
206
  if (sponsoredTx) {
195
- const suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
196
- tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject);
207
+ const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
208
+ sender: this.requireSenderForSponsored(sender),
209
+ additionalSuiAmount: 0n,
210
+ });
211
+ tx = oracle.tx;
212
+ const { suiCoinObject } = oracle;
197
213
  }
198
214
  else {
199
- tx = await this.initOracleTxb(pythFeederKeys, tx);
215
+ tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
200
216
  }
201
217
  const zlpCoinObject = this.processCoins(tx, 'zlp', lpCoinObjects, false);
202
218
  const [withdrawObject] = tx.splitCoins(zlpCoinObject, [tx.pure.u64(amount)]);
@@ -227,7 +243,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
227
243
  }
228
244
  // Initialize oracle transaction
229
245
  const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
230
- tx = await this.initOracleTxb(pythFeederKeys, tx);
246
+ tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
231
247
  const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
232
248
  tx.moveCall({
233
249
  target: `${this.consts.zoCore.upgradedPackage}::market::withdraw`,
@@ -246,18 +262,22 @@ class ZLPAPI extends abstract_1.BaseAPI {
246
262
  });
247
263
  return tx;
248
264
  }
249
- async withdrawPtb(coin, lpCoinObjects, amount, minAmountOut = 0, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
265
+ async withdrawPtb(coin, lpCoinObjects, amount, minAmountOut = 0, tx, sponsoredTx, sender) {
250
266
  if (!tx) {
251
267
  tx = new transactions_1.Transaction();
252
268
  }
253
269
  // Initialize oracle transaction
254
270
  const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
255
271
  if (sponsoredTx) {
256
- const suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
257
- tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject);
272
+ const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
273
+ sender: this.requireSenderForSponsored(sender),
274
+ additionalSuiAmount: 0n,
275
+ });
276
+ tx = oracle.tx;
277
+ const { suiCoinObject } = oracle;
258
278
  }
259
279
  else {
260
- tx = await this.initOracleTxb(pythFeederKeys, tx);
280
+ tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
261
281
  }
262
282
  const zlpCoinObject = this.processCoins(tx, 'zlp', lpCoinObjects, false);
263
283
  const [withdrawObject] = tx.splitCoins(zlpCoinObject, [tx.pure.u64(amount)]);
@@ -442,7 +462,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
442
462
  return rewardCoin;
443
463
  }
444
464
  async swap(fromToken, toToken, fromAmount, fromCoinObjects, minAmountOut) {
445
- const tx = await this.initOracleTxb(Object.keys(this.consts.zoCore.vaults));
465
+ const { tx } = await this.initOracleTxb(Object.keys(this.consts.zoCore.vaults));
446
466
  const fromCoinObject = this.processCoins(tx, fromToken, fromCoinObjects);
447
467
  const [fromDepositObject] = tx.splitCoins(fromCoinObject, [tx.pure.u64(fromAmount)]);
448
468
  const vaultsValuation = this.dataAPI.valuateVaults(tx);
@@ -474,7 +494,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
474
494
  if (!tx) {
475
495
  tx = new transactions_1.Transaction();
476
496
  }
477
- tx = await this.initOracleTxb(Object.keys(this.consts.zoCore.vaults), tx);
497
+ tx = (await this.initOracleTxb(Object.keys(this.consts.zoCore.vaults), tx)).tx;
478
498
  const fromCoinObject = this.processCoins(tx, fromToken, fromCoinObjects);
479
499
  const [fromDepositObject] = tx.splitCoins(fromCoinObject, [
480
500
  tx.pure.u64(fromAmount),
@@ -502,7 +522,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
502
522
  /**
503
523
  * Opens a new position in ZLP
504
524
  */
505
- 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) {
525
+ 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) {
506
526
  let tx = new transactions_1.Transaction();
507
527
  if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
508
528
  tx = await this.addReferral(referralAddress, tx);
@@ -517,11 +537,15 @@ class ZLPAPI extends abstract_1.BaseAPI {
517
537
  // Handle oracle initialization and coin processing
518
538
  let suiCoinObject;
519
539
  if (sponsoredTx) {
520
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
521
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
540
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
541
+ sender: this.requireSenderForSponsored(sender),
542
+ additionalSuiAmount: collateralToken === 'sui' ? collateralAmount + relayerFee : 0n,
543
+ });
544
+ tx = oracle.tx;
545
+ suiCoinObject = oracle.suiCoinObject;
522
546
  }
523
547
  else {
524
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
548
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
525
549
  }
526
550
  // Process coin splitting
527
551
  const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
@@ -556,7 +580,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
556
580
  /**
557
581
  * Opens a new position in ZLP
558
582
  */
559
- 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) {
583
+ 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) {
560
584
  let tx = new transactions_1.Transaction();
561
585
  if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
562
586
  tx = await this.addReferral(referralAddress, tx);
@@ -572,11 +596,15 @@ class ZLPAPI extends abstract_1.BaseAPI {
572
596
  // Handle oracle initialization and coin processing
573
597
  let suiCoinObject;
574
598
  if (sponsoredTx) {
575
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
576
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
599
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
600
+ sender: this.requireSenderForSponsored(sender),
601
+ additionalSuiAmount: collateralToken === 'sui' ? collateralAmount + relayerFee : 0n,
602
+ });
603
+ tx = oracle.tx;
604
+ suiCoinObject = oracle.suiCoinObject;
577
605
  }
578
606
  else {
579
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
607
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
580
608
  }
581
609
  // Process coin splitting
582
610
  const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
@@ -610,7 +638,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
610
638
  /**
611
639
  * Opens a new position with Coin in ZLP
612
640
  */
613
- 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) {
641
+ 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) {
614
642
  if (!tx) {
615
643
  tx = new transactions_1.Transaction();
616
644
  }
@@ -627,11 +655,15 @@ class ZLPAPI extends abstract_1.BaseAPI {
627
655
  // Handle oracle initialization and coin processing
628
656
  let suiCoinObject;
629
657
  if (sponsoredTx) {
630
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
631
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
658
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
659
+ sender: this.requireSenderForSponsored(sender),
660
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
661
+ });
662
+ tx = oracle.tx;
663
+ suiCoinObject = oracle.suiCoinObject;
632
664
  }
633
665
  else {
634
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
666
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
635
667
  }
636
668
  // Process coin splitting
637
669
  const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
@@ -666,7 +698,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
666
698
  /**
667
699
  * Opens a new position with Coin in ZLP (V2)
668
700
  */
669
- 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) {
701
+ 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) {
670
702
  if (!tx) {
671
703
  tx = new transactions_1.Transaction();
672
704
  }
@@ -684,11 +716,15 @@ class ZLPAPI extends abstract_1.BaseAPI {
684
716
  // Handle oracle initialization and coin processing
685
717
  let suiCoinObject;
686
718
  if (sponsoredTx) {
687
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
688
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
719
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
720
+ sender: this.requireSenderForSponsored(sender),
721
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
722
+ });
723
+ tx = oracle.tx;
724
+ suiCoinObject = oracle.suiCoinObject;
689
725
  }
690
726
  else {
691
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
727
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
692
728
  }
693
729
  // Process coin splitting
694
730
  const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
@@ -722,7 +758,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
722
758
  /**
723
759
  * Decreases an existing position in ZLP
724
760
  */
725
- 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) {
761
+ 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, sender) {
726
762
  if (!coinObjects) {
727
763
  throw new Error(`${this.constructor.name}: coinObjects is required`);
728
764
  }
@@ -740,11 +776,15 @@ class ZLPAPI extends abstract_1.BaseAPI {
740
776
  // Handle oracle initialization and coin processing
741
777
  let suiCoinObject;
742
778
  if (sponsoredTx) {
743
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
744
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
779
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
780
+ sender: this.requireSenderForSponsored(sender),
781
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
782
+ });
783
+ tx = oracle.tx;
784
+ suiCoinObject = oracle.suiCoinObject;
745
785
  }
746
786
  else {
747
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
787
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
748
788
  }
749
789
  // Process coin splitting
750
790
  const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
@@ -778,7 +818,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
778
818
  /**
779
819
  * Decreases an existing position in ZLP
780
820
  */
781
- 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) {
821
+ 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, sender) {
782
822
  if (!coinObjects) {
783
823
  throw new Error(`${this.constructor.name}: coinObjects is required`);
784
824
  }
@@ -796,11 +836,15 @@ class ZLPAPI extends abstract_1.BaseAPI {
796
836
  // Handle oracle initialization and coin processing
797
837
  let suiCoinObject;
798
838
  if (sponsoredTx) {
799
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
800
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
839
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
840
+ sender: this.requireSenderForSponsored(sender),
841
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
842
+ });
843
+ tx = oracle.tx;
844
+ suiCoinObject = oracle.suiCoinObject;
801
845
  }
802
846
  else {
803
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
847
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
804
848
  }
805
849
  // Process coin splitting
806
850
  const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
@@ -830,18 +874,19 @@ class ZLPAPI extends abstract_1.BaseAPI {
830
874
  });
831
875
  return tx;
832
876
  }
833
- async decreaseMultiPositions(positions, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
877
+ async decreaseMultiPositions(positions, tx, sponsoredTx, sender) {
834
878
  if (!tx) {
835
879
  tx = new transactions_1.Transaction();
836
880
  }
837
881
  // Handle oracle initialization and coin processing
838
882
  let suiCoinObject;
839
883
  if (sponsoredTx) {
840
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
841
- tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx, true, suiCoinObject);
884
+ const oracle = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx, true, { sender: this.requireSenderForSponsored(sender) });
885
+ tx = oracle.tx;
886
+ suiCoinObject = oracle.suiCoinObject;
842
887
  }
843
888
  else {
844
- tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx);
889
+ tx = (await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx)).tx;
845
890
  }
846
891
  for (const position of positions) {
847
892
  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;
@@ -886,14 +931,21 @@ class ZLPAPI extends abstract_1.BaseAPI {
886
931
  }
887
932
  return tx;
888
933
  }
889
- async decreaseMultiPositionsV2(positions, tx, sponsoredTx, suiCoinObjectsForPythUpdate, feeObjects) {
890
- const transaction = tx ?? new transactions_1.Transaction();
934
+ async decreaseMultiPositionsV2(positions, tx, sponsoredTx, sender, feeObjects) {
935
+ let transaction = tx ?? new transactions_1.Transaction();
891
936
  // Handle oracle initialization and coin processing
892
937
  const tokens = positions.flatMap(position => [position.collateralToken, position.indexToken]);
893
- const suiCoinObject = sponsoredTx
894
- ? this.processCoins(transaction, 'sui', suiCoinObjectsForPythUpdate || [], true)
895
- : undefined;
896
- await this.initOracleTxb(tokens, transaction, !!sponsoredTx, suiCoinObject);
938
+ let suiCoinObject;
939
+ if (sponsoredTx) {
940
+ const oracle = await this.initOracleTxb(tokens, transaction, true, {
941
+ sender: this.requireSenderForSponsored(sender),
942
+ });
943
+ transaction = oracle.tx;
944
+ suiCoinObject = oracle.suiCoinObject;
945
+ }
946
+ else {
947
+ transaction = (await this.initOracleTxb(tokens, transaction, false)).tx;
948
+ }
897
949
  if (!feeObjects || feeObjects.length !== positions.length) {
898
950
  throw new Error('feeObjects must be provided (pre-processed via buildFeeCoinObjects) and match positions length');
899
951
  }
@@ -938,7 +990,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
938
990
  }
939
991
  return transaction;
940
992
  }
941
- 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) {
993
+ 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) {
942
994
  let tx = new transactions_1.Transaction();
943
995
  if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
944
996
  tx = await this.addReferral(referralAddress, tx);
@@ -962,11 +1014,15 @@ class ZLPAPI extends abstract_1.BaseAPI {
962
1014
  // Handle oracle initialization and coin processing
963
1015
  let suiCoinObject;
964
1016
  if (sponsoredTx) {
965
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
966
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1017
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
1018
+ sender: this.requireSenderForSponsored(sender),
1019
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
1020
+ });
1021
+ tx = oracle.tx;
1022
+ suiCoinObject = oracle.suiCoinObject;
967
1023
  }
968
1024
  else {
969
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1025
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
970
1026
  }
971
1027
  // Process coin splitting
972
1028
  const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
@@ -1006,7 +1062,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
1006
1062
  .finalize();
1007
1063
  return tx;
1008
1064
  }
1009
- 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) {
1065
+ 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) {
1010
1066
  let tx = new transactions_1.Transaction();
1011
1067
  if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
1012
1068
  tx = await this.addReferral(referralAddress, tx);
@@ -1031,11 +1087,15 @@ class ZLPAPI extends abstract_1.BaseAPI {
1031
1087
  // Handle oracle initialization and coin processing
1032
1088
  let suiCoinObject;
1033
1089
  if (sponsoredTx) {
1034
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1035
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1090
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
1091
+ sender: this.requireSenderForSponsored(sender),
1092
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
1093
+ });
1094
+ tx = oracle.tx;
1095
+ suiCoinObject = oracle.suiCoinObject;
1036
1096
  }
1037
1097
  else {
1038
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1098
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
1039
1099
  }
1040
1100
  // Process coin splitting
1041
1101
  const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
@@ -1074,7 +1134,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
1074
1134
  .finalize();
1075
1135
  return tx;
1076
1136
  }
1077
- 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) {
1137
+ 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) {
1078
1138
  if (!tx) {
1079
1139
  tx = new transactions_1.Transaction();
1080
1140
  }
@@ -1100,11 +1160,15 @@ class ZLPAPI extends abstract_1.BaseAPI {
1100
1160
  // Handle oracle initialization and coin processing
1101
1161
  let suiCoinObject;
1102
1162
  if (sponsoredTx) {
1103
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1104
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1163
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
1164
+ sender: this.requireSenderForSponsored(sender),
1165
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
1166
+ });
1167
+ tx = oracle.tx;
1168
+ suiCoinObject = oracle.suiCoinObject;
1105
1169
  }
1106
1170
  else {
1107
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1171
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
1108
1172
  }
1109
1173
  // Process coin splitting
1110
1174
  const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
@@ -1144,7 +1208,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
1144
1208
  .finalize();
1145
1209
  return tx;
1146
1210
  }
1147
- 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) {
1211
+ 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) {
1148
1212
  if (!tx) {
1149
1213
  tx = new transactions_1.Transaction();
1150
1214
  }
@@ -1171,11 +1235,15 @@ class ZLPAPI extends abstract_1.BaseAPI {
1171
1235
  // Handle oracle initialization and coin processing
1172
1236
  let suiCoinObject;
1173
1237
  if (sponsoredTx) {
1174
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1175
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1238
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
1239
+ sender: this.requireSenderForSponsored(sender),
1240
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
1241
+ });
1242
+ tx = oracle.tx;
1243
+ suiCoinObject = oracle.suiCoinObject;
1176
1244
  }
1177
1245
  else {
1178
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1246
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
1179
1247
  }
1180
1248
  // Process coin splitting
1181
1249
  const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
@@ -1214,7 +1282,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
1214
1282
  .finalize();
1215
1283
  return tx;
1216
1284
  }
1217
- 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) {
1285
+ 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, sender) {
1218
1286
  if (!coinObjects) {
1219
1287
  throw new Error(`${this.constructor.name}: coinObjects is required`);
1220
1288
  }
@@ -1241,11 +1309,15 @@ class ZLPAPI extends abstract_1.BaseAPI {
1241
1309
  // Handle oracle initialization and coin processing
1242
1310
  let suiCoinObject;
1243
1311
  if (sponsoredTx) {
1244
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1245
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1312
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
1313
+ sender: this.requireSenderForSponsored(sender),
1314
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
1315
+ });
1316
+ tx = oracle.tx;
1317
+ suiCoinObject = oracle.suiCoinObject;
1246
1318
  }
1247
1319
  else {
1248
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1320
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
1249
1321
  }
1250
1322
  // Process coin splitting
1251
1323
  const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
@@ -1284,7 +1356,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
1284
1356
  .finalize();
1285
1357
  return tx;
1286
1358
  }
1287
- 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) {
1359
+ 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, sender) {
1288
1360
  if (!coinObjects) {
1289
1361
  throw new Error(`${this.constructor.name}: coinObjects is required`);
1290
1362
  }
@@ -1311,11 +1383,15 @@ class ZLPAPI extends abstract_1.BaseAPI {
1311
1383
  // Handle oracle initialization and coin processing
1312
1384
  let suiCoinObject;
1313
1385
  if (sponsoredTx) {
1314
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1315
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1386
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
1387
+ sender: this.requireSenderForSponsored(sender),
1388
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
1389
+ });
1390
+ tx = oracle.tx;
1391
+ suiCoinObject = oracle.suiCoinObject;
1316
1392
  }
1317
1393
  else {
1318
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1394
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
1319
1395
  }
1320
1396
  // Process coin splitting
1321
1397
  const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
@@ -1353,18 +1429,19 @@ class ZLPAPI extends abstract_1.BaseAPI {
1353
1429
  .finalize();
1354
1430
  return tx;
1355
1431
  }
1356
- async decreaseMultiPositionsWithSCard(positions, kioskClient, kioskCap, scard, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
1432
+ async decreaseMultiPositionsWithSCard(positions, kioskClient, kioskCap, scard, tx, sponsoredTx, sender) {
1357
1433
  if (!tx) {
1358
1434
  tx = new transactions_1.Transaction();
1359
1435
  }
1360
1436
  // Handle oracle initialization and coin processing
1361
1437
  let suiCoinObject;
1362
1438
  if (sponsoredTx) {
1363
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1364
- tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx, true, suiCoinObject);
1439
+ const oracle = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx, true, { sender: this.requireSenderForSponsored(sender) });
1440
+ tx = oracle.tx;
1441
+ suiCoinObject = oracle.suiCoinObject;
1365
1442
  }
1366
1443
  else {
1367
- tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx);
1444
+ tx = (await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx)).tx;
1368
1445
  }
1369
1446
  const kioskTx = new kiosk_1.KioskTransaction({
1370
1447
  transaction: tx,
@@ -1426,14 +1503,21 @@ class ZLPAPI extends abstract_1.BaseAPI {
1426
1503
  .finalize();
1427
1504
  return tx;
1428
1505
  }
1429
- async decreaseMultiPositionsWithSCardV2(positions, kioskClient, kioskCap, scard, tx, sponsoredTx, suiCoinObjectsForPythUpdate, feeObjects) {
1430
- const transaction = tx ?? new transactions_1.Transaction();
1506
+ async decreaseMultiPositionsWithSCardV2(positions, kioskClient, kioskCap, scard, tx, sponsoredTx, sender, feeObjects) {
1507
+ let transaction = tx ?? new transactions_1.Transaction();
1431
1508
  // Handle oracle initialization and coin processing
1432
1509
  const tokens = positions.flatMap(position => [position.collateralToken, position.indexToken]);
1433
- const suiCoinObject = sponsoredTx
1434
- ? this.processCoins(transaction, 'sui', suiCoinObjectsForPythUpdate || [], true)
1435
- : undefined;
1436
- await this.initOracleTxb(tokens, transaction, !!sponsoredTx, suiCoinObject);
1510
+ let suiCoinObject;
1511
+ if (sponsoredTx) {
1512
+ const oracle = await this.initOracleTxb(tokens, transaction, true, {
1513
+ sender: this.requireSenderForSponsored(sender),
1514
+ });
1515
+ transaction = oracle.tx;
1516
+ suiCoinObject = oracle.suiCoinObject;
1517
+ }
1518
+ else {
1519
+ transaction = (await this.initOracleTxb(tokens, transaction, false)).tx;
1520
+ }
1437
1521
  if (!feeObjects || feeObjects.length !== positions.length) {
1438
1522
  throw new Error('feeObjects must be provided (pre-processed via buildFeeCoinObjects) and match positions length');
1439
1523
  }
@@ -1498,16 +1582,20 @@ class ZLPAPI extends abstract_1.BaseAPI {
1498
1582
  /**
1499
1583
  * Pledges in position (ZLP-specific functionality)
1500
1584
  */
1501
- async pledgeInPosition(pcpId, collateralToken, indexToken, amount, coinObjects, long, sponsoredTx, suiCoinObjectsForPythUpdate) {
1585
+ async pledgeInPosition(pcpId, collateralToken, indexToken, amount, coinObjects, long, sponsoredTx, sender) {
1502
1586
  let tx = new transactions_1.Transaction();
1503
1587
  // Handle oracle initialization and coin processing
1504
1588
  let suiCoinObject;
1505
1589
  if (sponsoredTx) {
1506
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1507
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1590
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
1591
+ sender: this.requireSenderForSponsored(sender),
1592
+ additionalSuiAmount: collateralToken === 'sui' ? BigInt(amount) : 0n,
1593
+ });
1594
+ tx = oracle.tx;
1595
+ suiCoinObject = oracle.suiCoinObject;
1508
1596
  }
1509
1597
  else {
1510
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1598
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
1511
1599
  }
1512
1600
  // Process coin splitting
1513
1601
  const [depositObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(amount)], sponsoredTx, suiCoinObject);
@@ -1523,16 +1611,20 @@ class ZLPAPI extends abstract_1.BaseAPI {
1523
1611
  });
1524
1612
  return tx;
1525
1613
  }
1526
- async redeemFromPosition(pcpId, collateralToken, indexToken, amount, long, sponsoredTx, suiCoinObjectsForPythUpdate) {
1614
+ async redeemFromPosition(pcpId, collateralToken, indexToken, amount, long, sponsoredTx, sender) {
1527
1615
  let tx = new transactions_1.Transaction();
1528
1616
  // Handle oracle initialization and coin processing
1529
1617
  let suiCoinObject;
1530
1618
  if (sponsoredTx) {
1531
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1532
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1619
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
1620
+ sender: this.requireSenderForSponsored(sender),
1621
+ additionalSuiAmount: 0n,
1622
+ });
1623
+ tx = oracle.tx;
1624
+ suiCoinObject = oracle.suiCoinObject;
1533
1625
  }
1534
1626
  else {
1535
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1627
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
1536
1628
  }
1537
1629
  const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
1538
1630
  tx.moveCall({
@@ -1719,7 +1811,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
1719
1811
  return tx;
1720
1812
  }
1721
1813
  async adminUpdatePriceFeed(collateralToken, indexToken) {
1722
- const tx = await this.initOracleTxb([collateralToken, indexToken]);
1814
+ const { tx } = await this.initOracleTxb([collateralToken, indexToken]);
1723
1815
  return tx;
1724
1816
  }
1725
1817
  adminSettlePosition(positionId, owner, collateralToken, indexToken, long) {