@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
@@ -23,7 +23,7 @@ export class SLPAPI extends BaseAPI {
23
23
  /**
24
24
  * Deposits collateral into SLP vault using Sudo SDK approach
25
25
  */
26
- async deposit(coin, coinObjects, amount, minAmountOut = 0, referralAddress, sender, sponsoredTx, suiCoinObjectsForPythUpdate) {
26
+ async deposit(coin, coinObjects, amount, minAmountOut = 0, referralAddress, sender, sponsoredTx) {
27
27
  let tx = new Transaction();
28
28
  // Add referral if needed
29
29
  if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
@@ -33,8 +33,12 @@ export class SLPAPI extends BaseAPI {
33
33
  const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
34
34
  // Handle sponsored transaction case
35
35
  if (sponsoredTx) {
36
- const suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
37
- tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject);
36
+ const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
37
+ sender: this.requireSenderForSponsored(sender),
38
+ additionalSuiAmount: coin === 'sui' ? BigInt(amount) : 0n,
39
+ });
40
+ tx = oracle.tx;
41
+ const { suiCoinObject } = oracle;
38
42
  // Process deposit coins
39
43
  const depositObject = coin === 'sui'
40
44
  ? tx.splitCoins(suiCoinObject, [tx.pure.u64(amount)])[0]
@@ -58,7 +62,7 @@ export class SLPAPI extends 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 @@ export class SLPAPI extends BaseAPI {
81
85
  /**
82
86
  * Deposits collateral into SLP 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 Transaction();
87
91
  }
@@ -93,8 +97,12 @@ export class SLPAPI extends 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 @@ export class SLPAPI extends 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({
@@ -138,7 +146,7 @@ export class SLPAPI extends BaseAPI {
138
146
  /**
139
147
  * Deposits collateral pool with PTB deposit object
140
148
  */
141
- async depositWithPtb(coin, depositObject, minAmountOut = 0, referralAddress, sender, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
149
+ async depositWithPtb(coin, depositObject, minAmountOut = 0, referralAddress, sender, tx, sponsoredTx) {
142
150
  if (!tx) {
143
151
  tx = new Transaction();
144
152
  }
@@ -150,8 +158,12 @@ export class SLPAPI extends BaseAPI {
150
158
  const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
151
159
  // Handle sponsored transaction case
152
160
  if (sponsoredTx) {
153
- const suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
154
- tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject);
161
+ const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
162
+ sender: this.requireSenderForSponsored(sender),
163
+ additionalSuiAmount: 0n,
164
+ });
165
+ tx = oracle.tx;
166
+ const { suiCoinObject } = oracle;
155
167
  const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
156
168
  tx.moveCall({
157
169
  target: `${this.consts.sudoCore.upgradedPackage}::market::deposit`,
@@ -171,7 +183,7 @@ export class SLPAPI extends BaseAPI {
171
183
  return tx;
172
184
  }
173
185
  // Handle non-sponsored transaction case
174
- tx = await this.initOracleTxb(pythFeederKeys, tx);
186
+ tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
175
187
  const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
176
188
  tx.moveCall({
177
189
  target: `${this.consts.sudoCore.upgradedPackage}::market::deposit`,
@@ -193,16 +205,20 @@ export class SLPAPI extends BaseAPI {
193
205
  /**
194
206
  * Withdraws collateral from SLP vault using Sudo SDK approach
195
207
  */
196
- async withdraw(coin, lpCoinObjects, amount, minAmountOut = 0, sponsoredTx, suiCoinObjectsForPythUpdate) {
208
+ async withdraw(coin, lpCoinObjects, amount, minAmountOut = 0, sponsoredTx, sender) {
197
209
  let tx = new Transaction();
198
210
  // Initialize oracle transaction
199
211
  const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
200
212
  if (sponsoredTx) {
201
- const suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
202
- tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject);
213
+ const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
214
+ sender: this.requireSenderForSponsored(sender),
215
+ additionalSuiAmount: 0n,
216
+ });
217
+ tx = oracle.tx;
218
+ const { suiCoinObject } = oracle;
203
219
  }
204
220
  else {
205
- tx = await this.initOracleTxb(pythFeederKeys, tx);
221
+ tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
206
222
  }
207
223
  const slpCoinObject = this.processCoins(tx, 'slp', lpCoinObjects, false);
208
224
  const [withdrawObject] = tx.splitCoins(slpCoinObject, [tx.pure.u64(amount)]);
@@ -233,7 +249,7 @@ export class SLPAPI extends BaseAPI {
233
249
  }
234
250
  // Initialize oracle transaction
235
251
  const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
236
- tx = await this.initOracleTxb(pythFeederKeys, tx);
252
+ tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
237
253
  const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
238
254
  tx.moveCall({
239
255
  target: `${this.consts.sudoCore.upgradedPackage}::market::withdraw`,
@@ -252,18 +268,22 @@ export class SLPAPI extends BaseAPI {
252
268
  });
253
269
  return tx;
254
270
  }
255
- async withdrawPtb(coin, lpCoinObjects, amount, minAmountOut = 0, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
271
+ async withdrawPtb(coin, lpCoinObjects, amount, minAmountOut = 0, tx, sponsoredTx, sender) {
256
272
  if (!tx) {
257
273
  tx = new Transaction();
258
274
  }
259
275
  // Initialize oracle transaction
260
276
  const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
261
277
  if (sponsoredTx) {
262
- const suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
263
- tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject);
278
+ const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
279
+ sender: this.requireSenderForSponsored(sender),
280
+ additionalSuiAmount: 0n,
281
+ });
282
+ tx = oracle.tx;
283
+ const { suiCoinObject } = oracle;
264
284
  }
265
285
  else {
266
- tx = await this.initOracleTxb(pythFeederKeys, tx);
286
+ tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
267
287
  }
268
288
  const slpCoinObject = this.processCoins(tx, 'slp', lpCoinObjects, false);
269
289
  const [withdrawObject] = tx.splitCoins(slpCoinObject, [tx.pure.u64(amount)]);
@@ -286,7 +306,7 @@ export class SLPAPI extends BaseAPI {
286
306
  return withdrawCoin;
287
307
  }
288
308
  async swap(fromToken, toToken, fromAmount, fromCoinObjects, minAmountOut) {
289
- const tx = await this.initOracleTxb(Object.keys(this.consts.sudoCore.vaults));
309
+ const { tx } = await this.initOracleTxb(Object.keys(this.consts.sudoCore.vaults));
290
310
  const fromCoinObject = this.processCoins(tx, fromToken, fromCoinObjects);
291
311
  const [fromDepositObject] = tx.splitCoins(fromCoinObject, [
292
312
  tx.pure.u64(fromAmount),
@@ -320,7 +340,7 @@ export class SLPAPI extends BaseAPI {
320
340
  if (!tx) {
321
341
  tx = new Transaction();
322
342
  }
323
- tx = await this.initOracleTxb(Object.keys(this.consts.sudoCore.vaults), tx);
343
+ tx = (await this.initOracleTxb(Object.keys(this.consts.sudoCore.vaults), tx)).tx;
324
344
  const fromCoinObject = this.processCoins(tx, fromToken, fromCoinObjects);
325
345
  const [fromDepositObject] = tx.splitCoins(fromCoinObject, [
326
346
  tx.pure.u64(fromAmount),
@@ -510,7 +530,7 @@ export class SLPAPI extends BaseAPI {
510
530
  /**
511
531
  * Opens a position using Sudo SDK approach
512
532
  */
513
- async openPosition(collateralToken, indexToken, size, collateralAmount, coinObjects, long, reserveAmount, indexPrice, collateralPrice, isLimitOrder = false, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, sponsoredTx, suiCoinObjectsForPythUpdate) {
533
+ async openPosition(collateralToken, indexToken, size, collateralAmount, coinObjects, long, reserveAmount, indexPrice, collateralPrice, isLimitOrder = false, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, sponsoredTx) {
514
534
  let tx = new Transaction();
515
535
  if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
516
536
  tx = await this.addReferral(referralAddress, tx);
@@ -525,11 +545,15 @@ export class SLPAPI extends BaseAPI {
525
545
  // Handle oracle initialization and coin processing
526
546
  let suiCoinObject;
527
547
  if (sponsoredTx) {
528
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
529
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
548
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
549
+ sender: this.requireSenderForSponsored(sender),
550
+ additionalSuiAmount: collateralToken === 'sui' ? collateralAmount + relayerFee : 0n,
551
+ });
552
+ tx = oracle.tx;
553
+ suiCoinObject = oracle.suiCoinObject;
530
554
  }
531
555
  else {
532
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
556
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
533
557
  }
534
558
  // Process coin splitting
535
559
  const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
@@ -564,7 +588,7 @@ export class SLPAPI extends BaseAPI {
564
588
  /**
565
589
  * Opens a position using Sudo SDK approach
566
590
  */
567
- async openPositionWithCoin(collateralToken, indexToken, size, coinObj, long, reserveAmount, indexPrice, collateralPrice, isLimitOrder = false, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
591
+ async openPositionWithCoin(collateralToken, indexToken, size, coinObj, long, reserveAmount, indexPrice, collateralPrice, isLimitOrder = false, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, tx, sponsoredTx) {
568
592
  if (!tx) {
569
593
  tx = new Transaction();
570
594
  }
@@ -581,11 +605,15 @@ export class SLPAPI extends BaseAPI {
581
605
  // Handle oracle initialization and coin processing
582
606
  let suiCoinObject;
583
607
  if (sponsoredTx) {
584
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
585
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
608
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
609
+ sender: this.requireSenderForSponsored(sender),
610
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
611
+ });
612
+ tx = oracle.tx;
613
+ suiCoinObject = oracle.suiCoinObject;
586
614
  }
587
615
  else {
588
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
616
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
589
617
  }
590
618
  // Process coin splitting
591
619
  const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
@@ -620,7 +648,7 @@ export class SLPAPI extends BaseAPI {
620
648
  /**
621
649
  * Opens a new position in SLP (V2 - uses v3 contract)
622
650
  */
623
- 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) {
651
+ 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) {
624
652
  let tx = new Transaction();
625
653
  if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
626
654
  tx = await this.addReferral(referralAddress, tx);
@@ -636,11 +664,15 @@ export class SLPAPI extends BaseAPI {
636
664
  // Handle oracle initialization and coin processing
637
665
  let suiCoinObject;
638
666
  if (sponsoredTx) {
639
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
640
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
667
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
668
+ sender: this.requireSenderForSponsored(sender),
669
+ additionalSuiAmount: collateralToken === 'sui' ? collateralAmount + relayerFee : 0n,
670
+ });
671
+ tx = oracle.tx;
672
+ suiCoinObject = oracle.suiCoinObject;
641
673
  }
642
674
  else {
643
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
675
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
644
676
  }
645
677
  // Process coin splitting
646
678
  const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
@@ -674,7 +706,7 @@ export class SLPAPI extends BaseAPI {
674
706
  /**
675
707
  * Opens a new position with Coin in SLP (V2 - uses v3 contract)
676
708
  */
677
- 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) {
709
+ 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) {
678
710
  if (!tx) {
679
711
  tx = new Transaction();
680
712
  }
@@ -692,11 +724,15 @@ export class SLPAPI extends BaseAPI {
692
724
  // Handle oracle initialization and coin processing
693
725
  let suiCoinObject;
694
726
  if (sponsoredTx) {
695
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
696
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
727
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
728
+ sender: this.requireSenderForSponsored(sender),
729
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
730
+ });
731
+ tx = oracle.tx;
732
+ suiCoinObject = oracle.suiCoinObject;
697
733
  }
698
734
  else {
699
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
735
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
700
736
  }
701
737
  // Process coin splitting
702
738
  const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
@@ -730,7 +766,7 @@ export class SLPAPI extends BaseAPI {
730
766
  /**
731
767
  * Decreases an existing position in SLP using Sudo SDK approach
732
768
  */
733
- 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) {
769
+ 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) {
734
770
  if (!coinObjects) {
735
771
  throw new Error(`${this.constructor.name}: coinObjects is required`);
736
772
  }
@@ -747,11 +783,15 @@ export class SLPAPI extends BaseAPI {
747
783
  }
748
784
  let suiCoinObject;
749
785
  if (sponsoredTx) {
750
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
751
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
786
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
787
+ sender: this.requireSenderForSponsored(sender),
788
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
789
+ });
790
+ tx = oracle.tx;
791
+ suiCoinObject = oracle.suiCoinObject;
752
792
  }
753
793
  else {
754
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
794
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
755
795
  }
756
796
  // Handle oracle initialization and coin processing
757
797
  const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
@@ -785,7 +825,7 @@ export class SLPAPI extends BaseAPI {
785
825
  /**
786
826
  * Decreases an existing position in SLP (V2 - uses v3 contract)
787
827
  */
788
- 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) {
828
+ 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) {
789
829
  if (!coinObjects) {
790
830
  throw new Error(`${this.constructor.name}: coinObjects is required`);
791
831
  }
@@ -803,11 +843,15 @@ export class SLPAPI extends BaseAPI {
803
843
  // Handle oracle initialization and coin processing
804
844
  let suiCoinObject;
805
845
  if (sponsoredTx) {
806
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
807
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
846
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
847
+ sender: this.requireSenderForSponsored(sender),
848
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
849
+ });
850
+ tx = oracle.tx;
851
+ suiCoinObject = oracle.suiCoinObject;
808
852
  }
809
853
  else {
810
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
854
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
811
855
  }
812
856
  // Process coin splitting
813
857
  const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
@@ -837,18 +881,19 @@ export class SLPAPI extends BaseAPI {
837
881
  });
838
882
  return tx;
839
883
  }
840
- async decreaseMultiPositions(positions, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
884
+ async decreaseMultiPositions(positions, tx, sponsoredTx, sender) {
841
885
  if (!tx) {
842
886
  tx = new Transaction();
843
887
  }
844
888
  // Handle oracle initialization and coin processing
845
889
  let suiCoinObject;
846
890
  if (sponsoredTx) {
847
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
848
- tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx, true, suiCoinObject);
891
+ const oracle = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx, true, { sender: this.requireSenderForSponsored(sender) });
892
+ tx = oracle.tx;
893
+ suiCoinObject = oracle.suiCoinObject;
849
894
  }
850
895
  else {
851
- tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx);
896
+ tx = (await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx)).tx;
852
897
  }
853
898
  for (const position of positions) {
854
899
  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;
@@ -893,14 +938,21 @@ export class SLPAPI extends BaseAPI {
893
938
  }
894
939
  return tx;
895
940
  }
896
- async decreaseMultiPositionsV2(positions, tx, sponsoredTx, suiCoinObjectsForPythUpdate, feeObjects) {
897
- const transaction = tx ?? new Transaction();
941
+ async decreaseMultiPositionsV2(positions, tx, sponsoredTx, sender, feeObjects) {
942
+ let transaction = tx ?? new Transaction();
898
943
  // Handle oracle initialization and coin processing
899
944
  const tokens = positions.flatMap(position => [position.collateralToken, position.indexToken]);
900
- const suiCoinObject = sponsoredTx
901
- ? this.processCoins(transaction, 'sui', suiCoinObjectsForPythUpdate || [], true)
902
- : undefined;
903
- await this.initOracleTxb(tokens, transaction, !!sponsoredTx, suiCoinObject);
945
+ let suiCoinObject;
946
+ if (sponsoredTx) {
947
+ const oracle = await this.initOracleTxb(tokens, transaction, true, {
948
+ sender: this.requireSenderForSponsored(sender),
949
+ });
950
+ transaction = oracle.tx;
951
+ suiCoinObject = oracle.suiCoinObject;
952
+ }
953
+ else {
954
+ transaction = (await this.initOracleTxb(tokens, transaction, false)).tx;
955
+ }
904
956
  if (!feeObjects || feeObjects.length !== positions.length) {
905
957
  throw new Error('feeObjects must be provided (pre-processed via buildFeeCoinObjects) and match positions length');
906
958
  }
@@ -945,16 +997,20 @@ export class SLPAPI extends BaseAPI {
945
997
  }
946
998
  return transaction;
947
999
  }
948
- async pledgeInPosition(pcpId, collateralToken, indexToken, amount, coinObjects, long, sponsoredTx, suiCoinObjectsForPythUpdate) {
1000
+ async pledgeInPosition(pcpId, collateralToken, indexToken, amount, coinObjects, long, sponsoredTx, sender) {
949
1001
  let tx = new Transaction();
950
1002
  // Handle oracle initialization and coin processing
951
1003
  let suiCoinObject;
952
1004
  if (sponsoredTx) {
953
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
954
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1005
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
1006
+ sender: this.requireSenderForSponsored(sender),
1007
+ additionalSuiAmount: collateralToken === 'sui' ? BigInt(amount) : 0n,
1008
+ });
1009
+ tx = oracle.tx;
1010
+ suiCoinObject = oracle.suiCoinObject;
955
1011
  }
956
1012
  else {
957
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1013
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
958
1014
  }
959
1015
  // Process coin splitting
960
1016
  const [depositObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(amount)], sponsoredTx, suiCoinObject);
@@ -974,16 +1030,20 @@ export class SLPAPI extends BaseAPI {
974
1030
  });
975
1031
  return tx;
976
1032
  }
977
- async redeemFromPosition(pcpId, collateralToken, indexToken, amount, long, sponsoredTx, suiCoinObjectsForPythUpdate) {
1033
+ async redeemFromPosition(pcpId, collateralToken, indexToken, amount, long, sponsoredTx, sender) {
978
1034
  let tx = new Transaction();
979
1035
  // Handle oracle initialization and coin processing
980
1036
  let suiCoinObject;
981
1037
  if (sponsoredTx) {
982
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
983
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1038
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
1039
+ sender: this.requireSenderForSponsored(sender),
1040
+ additionalSuiAmount: 0n,
1041
+ });
1042
+ tx = oracle.tx;
1043
+ suiCoinObject = oracle.suiCoinObject;
984
1044
  }
985
1045
  else {
986
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1046
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
987
1047
  }
988
1048
  const symbol = joinSymbol(long ? 'long' : 'short', indexToken);
989
1049
  tx.moveCall({
@@ -1161,7 +1221,7 @@ export class SLPAPI extends BaseAPI {
1161
1221
  arguments: [tx.object(this.consts.sudoCore.market), tx.object(orderCapId)],
1162
1222
  });
1163
1223
  }
1164
- async openPositionWithSCard(collateralToken, indexToken, size, collateralAmount, coinObjects, long, reserveAmount, indexPrice, collateralPrice, kioskClient, kioskCap, scard, isLimitOrder = false, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, sponsoredTx, suiCoinObjectsForPythUpdate) {
1224
+ async openPositionWithSCard(collateralToken, indexToken, size, collateralAmount, coinObjects, long, reserveAmount, indexPrice, collateralPrice, kioskClient, kioskCap, scard, isLimitOrder = false, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, sponsoredTx) {
1165
1225
  let tx = new Transaction();
1166
1226
  if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
1167
1227
  tx = await this.addReferral(referralAddress, tx);
@@ -1185,11 +1245,15 @@ export class SLPAPI extends BaseAPI {
1185
1245
  // Handle oracle initialization and coin processing
1186
1246
  let suiCoinObject;
1187
1247
  if (sponsoredTx) {
1188
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1189
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1248
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
1249
+ sender: this.requireSenderForSponsored(sender),
1250
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
1251
+ });
1252
+ tx = oracle.tx;
1253
+ suiCoinObject = oracle.suiCoinObject;
1190
1254
  }
1191
1255
  else {
1192
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1256
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
1193
1257
  }
1194
1258
  // Process coin splitting
1195
1259
  const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
@@ -1229,7 +1293,7 @@ export class SLPAPI extends BaseAPI {
1229
1293
  .finalize();
1230
1294
  return tx;
1231
1295
  }
1232
- async openPositionWithCoinAndSCard(collateralToken, indexToken, size, coinObj, long, reserveAmount, indexPrice, collateralPrice, kioskClient, kioskCap, scard, isLimitOrder = false, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
1296
+ async openPositionWithCoinAndSCard(collateralToken, indexToken, size, coinObj, long, reserveAmount, indexPrice, collateralPrice, kioskClient, kioskCap, scard, isLimitOrder = false, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, tx, sponsoredTx) {
1233
1297
  if (!tx) {
1234
1298
  tx = new Transaction();
1235
1299
  }
@@ -1255,11 +1319,15 @@ export class SLPAPI extends BaseAPI {
1255
1319
  // Handle oracle initialization and coin processing
1256
1320
  let suiCoinObject;
1257
1321
  if (sponsoredTx) {
1258
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1259
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1322
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
1323
+ sender: this.requireSenderForSponsored(sender),
1324
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
1325
+ });
1326
+ tx = oracle.tx;
1327
+ suiCoinObject = oracle.suiCoinObject;
1260
1328
  }
1261
1329
  else {
1262
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1330
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
1263
1331
  }
1264
1332
  // Process coin splitting
1265
1333
  const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
@@ -1299,7 +1367,7 @@ export class SLPAPI extends BaseAPI {
1299
1367
  .finalize();
1300
1368
  return tx;
1301
1369
  }
1302
- 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) {
1370
+ 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) {
1303
1371
  let tx = new Transaction();
1304
1372
  if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
1305
1373
  tx = await this.addReferral(referralAddress, tx);
@@ -1324,11 +1392,15 @@ export class SLPAPI extends BaseAPI {
1324
1392
  // Handle oracle initialization and coin processing
1325
1393
  let suiCoinObject;
1326
1394
  if (sponsoredTx) {
1327
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1328
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1395
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
1396
+ sender: this.requireSenderForSponsored(sender),
1397
+ additionalSuiAmount: collateralToken === 'sui' ? collateralAmount + relayerFee : 0n,
1398
+ });
1399
+ tx = oracle.tx;
1400
+ suiCoinObject = oracle.suiCoinObject;
1329
1401
  }
1330
1402
  else {
1331
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1403
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
1332
1404
  }
1333
1405
  // Process coin splitting
1334
1406
  const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
@@ -1368,7 +1440,7 @@ export class SLPAPI extends BaseAPI {
1368
1440
  return tx;
1369
1441
  }
1370
1442
  // S Card operations
1371
- 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) {
1443
+ 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) {
1372
1444
  if (!tx) {
1373
1445
  tx = new Transaction();
1374
1446
  }
@@ -1395,11 +1467,15 @@ export class SLPAPI extends BaseAPI {
1395
1467
  // Handle oracle initialization and coin processing
1396
1468
  let suiCoinObject;
1397
1469
  if (sponsoredTx) {
1398
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1399
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1470
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
1471
+ sender: this.requireSenderForSponsored(sender),
1472
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
1473
+ });
1474
+ tx = oracle.tx;
1475
+ suiCoinObject = oracle.suiCoinObject;
1400
1476
  }
1401
1477
  else {
1402
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1478
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
1403
1479
  }
1404
1480
  // Process coin splitting
1405
1481
  const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
@@ -1438,7 +1514,7 @@ export class SLPAPI extends BaseAPI {
1438
1514
  .finalize();
1439
1515
  return tx;
1440
1516
  }
1441
- 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) {
1517
+ 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) {
1442
1518
  if (!coinObjects) {
1443
1519
  throw new Error(`${this.constructor.name}: coinObjects is required`);
1444
1520
  }
@@ -1465,11 +1541,15 @@ export class SLPAPI extends BaseAPI {
1465
1541
  // Handle oracle initialization and coin processing
1466
1542
  let suiCoinObject;
1467
1543
  if (sponsoredTx) {
1468
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1469
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1544
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
1545
+ sender: this.requireSenderForSponsored(sender),
1546
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
1547
+ });
1548
+ tx = oracle.tx;
1549
+ suiCoinObject = oracle.suiCoinObject;
1470
1550
  }
1471
1551
  else {
1472
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1552
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
1473
1553
  }
1474
1554
  // Process coin splitting
1475
1555
  const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
@@ -1508,7 +1588,7 @@ export class SLPAPI extends BaseAPI {
1508
1588
  .finalize();
1509
1589
  return tx;
1510
1590
  }
1511
- 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) {
1591
+ 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) {
1512
1592
  if (!coinObjects) {
1513
1593
  throw new Error(`${this.constructor.name}: coinObjects is required`);
1514
1594
  }
@@ -1535,11 +1615,15 @@ export class SLPAPI extends BaseAPI {
1535
1615
  // Handle oracle initialization and coin processing
1536
1616
  let suiCoinObject;
1537
1617
  if (sponsoredTx) {
1538
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1539
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1618
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
1619
+ sender: this.requireSenderForSponsored(sender),
1620
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
1621
+ });
1622
+ tx = oracle.tx;
1623
+ suiCoinObject = oracle.suiCoinObject;
1540
1624
  }
1541
1625
  else {
1542
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1626
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
1543
1627
  }
1544
1628
  // Process coin splitting
1545
1629
  const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
@@ -1577,18 +1661,19 @@ export class SLPAPI extends BaseAPI {
1577
1661
  .finalize();
1578
1662
  return tx;
1579
1663
  }
1580
- async decreaseMultiPositionsWithSCard(positions, kioskClient, kioskCap, scard, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
1664
+ async decreaseMultiPositionsWithSCard(positions, kioskClient, kioskCap, scard, tx, sponsoredTx, sender) {
1581
1665
  if (!tx) {
1582
1666
  tx = new Transaction();
1583
1667
  }
1584
1668
  // Handle oracle initialization and coin processing
1585
1669
  let suiCoinObject;
1586
1670
  if (sponsoredTx) {
1587
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1588
- tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx, true, suiCoinObject);
1671
+ const oracle = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx, true, { sender: this.requireSenderForSponsored(sender) });
1672
+ tx = oracle.tx;
1673
+ suiCoinObject = oracle.suiCoinObject;
1589
1674
  }
1590
1675
  else {
1591
- tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx);
1676
+ tx = (await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx)).tx;
1592
1677
  }
1593
1678
  const kioskTx = new KioskTransaction({
1594
1679
  transaction: tx,
@@ -1650,14 +1735,21 @@ export class SLPAPI extends BaseAPI {
1650
1735
  .finalize();
1651
1736
  return tx;
1652
1737
  }
1653
- async decreaseMultiPositionsWithSCardV2(positions, kioskClient, kioskCap, scard, tx, sponsoredTx, suiCoinObjectsForPythUpdate, feeObjects) {
1654
- const transaction = tx ?? new Transaction();
1738
+ async decreaseMultiPositionsWithSCardV2(positions, kioskClient, kioskCap, scard, tx, sponsoredTx, sender, feeObjects) {
1739
+ let transaction = tx ?? new Transaction();
1655
1740
  // Handle oracle initialization and coin processing
1656
1741
  const tokens = positions.flatMap(position => [position.collateralToken, position.indexToken]);
1657
- const suiCoinObject = sponsoredTx
1658
- ? this.processCoins(transaction, 'sui', suiCoinObjectsForPythUpdate || [], true)
1659
- : undefined;
1660
- await this.initOracleTxb(tokens, transaction, !!sponsoredTx, suiCoinObject);
1742
+ let suiCoinObject;
1743
+ if (sponsoredTx) {
1744
+ const oracle = await this.initOracleTxb(tokens, transaction, true, {
1745
+ sender: this.requireSenderForSponsored(sender),
1746
+ });
1747
+ transaction = oracle.tx;
1748
+ suiCoinObject = oracle.suiCoinObject;
1749
+ }
1750
+ else {
1751
+ transaction = (await this.initOracleTxb(tokens, transaction, false)).tx;
1752
+ }
1661
1753
  if (!feeObjects || feeObjects.length !== positions.length) {
1662
1754
  throw new Error('feeObjects must be provided (pre-processed via buildFeeCoinObjects) and match positions length');
1663
1755
  }
@@ -1731,7 +1823,7 @@ export class SLPAPI extends BaseAPI {
1731
1823
  return tx;
1732
1824
  }
1733
1825
  async adminUpdatePriceFeed(collateralToken, indexToken) {
1734
- const tx = await this.initOracleTxb([collateralToken, indexToken]);
1826
+ const { tx } = await this.initOracleTxb([collateralToken, indexToken]);
1735
1827
  return tx;
1736
1828
  }
1737
1829
  adminSettlePosition(_positionId, _owner, _collateralToken, _indexToken, _long) {