@zofai/zo-sdk 0.2.9 → 0.2.10

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 (108) 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 +8 -7
  4. package/dist/abstract/BaseAPI.d.cts.map +1 -1
  5. package/dist/abstract/BaseAPI.d.mts +8 -7
  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/api.cjs +12 -12
  10. package/dist/api.cjs.map +1 -1
  11. package/dist/api.mjs +12 -12
  12. package/dist/api.mjs.map +1 -1
  13. package/dist/coins.cjs +74 -0
  14. package/dist/coins.cjs.map +1 -0
  15. package/dist/coins.d.cts +37 -0
  16. package/dist/coins.d.cts.map +1 -0
  17. package/dist/coins.d.mts +37 -0
  18. package/dist/coins.d.mts.map +1 -0
  19. package/dist/coins.mjs +67 -0
  20. package/dist/coins.mjs.map +1 -0
  21. package/dist/implementations/SLPAPI.cjs +192 -100
  22. package/dist/implementations/SLPAPI.cjs.map +1 -1
  23. package/dist/implementations/SLPAPI.d.cts +23 -23
  24. package/dist/implementations/SLPAPI.d.cts.map +1 -1
  25. package/dist/implementations/SLPAPI.d.mts +23 -23
  26. package/dist/implementations/SLPAPI.d.mts.map +1 -1
  27. package/dist/implementations/SLPAPI.mjs +192 -100
  28. package/dist/implementations/SLPAPI.mjs.map +1 -1
  29. package/dist/implementations/SLPDataAPI.cjs +2 -2
  30. package/dist/implementations/SLPDataAPI.cjs.map +1 -1
  31. package/dist/implementations/SLPDataAPI.mjs +2 -2
  32. package/dist/implementations/SLPDataAPI.mjs.map +1 -1
  33. package/dist/implementations/USDZAPI.cjs +176 -92
  34. package/dist/implementations/USDZAPI.cjs.map +1 -1
  35. package/dist/implementations/USDZAPI.d.cts +21 -21
  36. package/dist/implementations/USDZAPI.d.cts.map +1 -1
  37. package/dist/implementations/USDZAPI.d.mts +21 -21
  38. package/dist/implementations/USDZAPI.d.mts.map +1 -1
  39. package/dist/implementations/USDZAPI.mjs +176 -92
  40. package/dist/implementations/USDZAPI.mjs.map +1 -1
  41. package/dist/implementations/ZBTCVCAPI.cjs +84 -46
  42. package/dist/implementations/ZBTCVCAPI.cjs.map +1 -1
  43. package/dist/implementations/ZBTCVCAPI.d.cts +11 -11
  44. package/dist/implementations/ZBTCVCAPI.d.cts.map +1 -1
  45. package/dist/implementations/ZBTCVCAPI.d.mts +11 -11
  46. package/dist/implementations/ZBTCVCAPI.d.mts.map +1 -1
  47. package/dist/implementations/ZBTCVCAPI.mjs +84 -46
  48. package/dist/implementations/ZBTCVCAPI.mjs.map +1 -1
  49. package/dist/implementations/ZLPAPI.cjs +192 -100
  50. package/dist/implementations/ZLPAPI.cjs.map +1 -1
  51. package/dist/implementations/ZLPAPI.d.cts +23 -23
  52. package/dist/implementations/ZLPAPI.d.cts.map +1 -1
  53. package/dist/implementations/ZLPAPI.d.mts +23 -23
  54. package/dist/implementations/ZLPAPI.d.mts.map +1 -1
  55. package/dist/implementations/ZLPAPI.mjs +192 -100
  56. package/dist/implementations/ZLPAPI.mjs.map +1 -1
  57. package/dist/index.cjs +1 -0
  58. package/dist/index.cjs.map +1 -1
  59. package/dist/index.d.cts +1 -0
  60. package/dist/index.d.cts.map +1 -1
  61. package/dist/index.d.mts +1 -0
  62. package/dist/index.d.mts.map +1 -1
  63. package/dist/index.mjs +1 -0
  64. package/dist/index.mjs.map +1 -1
  65. package/dist/interfaces/base.d.cts +25 -21
  66. package/dist/interfaces/base.d.cts.map +1 -1
  67. package/dist/interfaces/base.d.mts +25 -21
  68. package/dist/interfaces/base.d.mts.map +1 -1
  69. package/dist/interfaces/slp.d.cts +1 -1
  70. package/dist/interfaces/slp.d.cts.map +1 -1
  71. package/dist/interfaces/slp.d.mts +1 -1
  72. package/dist/interfaces/slp.d.mts.map +1 -1
  73. package/dist/interfaces/usdz.d.cts +1 -1
  74. package/dist/interfaces/usdz.d.cts.map +1 -1
  75. package/dist/interfaces/usdz.d.mts +1 -1
  76. package/dist/interfaces/usdz.d.mts.map +1 -1
  77. package/dist/interfaces/zbtcvc.d.cts +1 -1
  78. package/dist/interfaces/zbtcvc.d.cts.map +1 -1
  79. package/dist/interfaces/zbtcvc.d.mts +1 -1
  80. package/dist/interfaces/zbtcvc.d.mts.map +1 -1
  81. package/dist/interfaces/zlp.d.cts +1 -1
  82. package/dist/interfaces/zlp.d.cts.map +1 -1
  83. package/dist/interfaces/zlp.d.mts +1 -1
  84. package/dist/interfaces/zlp.d.mts.map +1 -1
  85. package/dist/oracle.cjs +27 -22
  86. package/dist/oracle.cjs.map +1 -1
  87. package/dist/oracle.d.cts +13 -1
  88. package/dist/oracle.d.cts.map +1 -1
  89. package/dist/oracle.d.mts +13 -1
  90. package/dist/oracle.d.mts.map +1 -1
  91. package/dist/oracle.mjs +27 -22
  92. package/dist/oracle.mjs.map +1 -1
  93. package/package.json +1 -1
  94. package/src/abstract/BaseAPI.ts +10 -8
  95. package/src/api.ts +12 -12
  96. package/src/coins.ts +115 -0
  97. package/src/implementations/SLPAPI.ts +199 -115
  98. package/src/implementations/SLPDataAPI.ts +2 -2
  99. package/src/implementations/USDZAPI.ts +184 -94
  100. package/src/implementations/ZBTCVCAPI.ts +98 -52
  101. package/src/implementations/ZLPAPI.ts +199 -110
  102. package/src/index.ts +1 -0
  103. package/src/interfaces/base.ts +13 -21
  104. package/src/interfaces/slp.ts +0 -1
  105. package/src/interfaces/usdz.ts +0 -1
  106. package/src/interfaces/zbtcvc.ts +0 -1
  107. package/src/interfaces/zlp.ts +0 -1
  108. package/src/oracle.ts +64 -28
@@ -23,7 +23,7 @@ export class ZLPAPI extends BaseAPI {
23
23
  /**
24
24
  * Deposits collateral into ZLP vault
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 ZLPAPI 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]
@@ -55,7 +59,7 @@ export class ZLPAPI extends BaseAPI {
55
59
  return tx;
56
60
  }
57
61
  // Handle non-sponsored transaction case
58
- tx = await this.initOracleTxb(pythFeederKeys, tx);
62
+ tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
59
63
  const depositObject = tx.splitCoins(this.processCoins(tx, coin, coinObjects, false), [tx.pure.u64(amount)])[0];
60
64
  const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
61
65
  tx.moveCall({
@@ -78,7 +82,7 @@ export class ZLPAPI extends BaseAPI {
78
82
  /**
79
83
  * Deposits collateral into ZLP vault and returns a coin
80
84
  */
81
- async depositPtb(coin, coinObjects, amount, minAmountOut = 0, referralAddress, sender, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
85
+ async depositPtb(coin, coinObjects, amount, minAmountOut = 0, referralAddress, sender, tx, sponsoredTx) {
82
86
  if (!tx) {
83
87
  tx = new Transaction();
84
88
  }
@@ -90,8 +94,12 @@ export class ZLPAPI extends BaseAPI {
90
94
  const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
91
95
  // Handle sponsored transaction case
92
96
  if (sponsoredTx) {
93
- const suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
94
- tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject);
97
+ const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
98
+ sender: this.requireSenderForSponsored(sender),
99
+ additionalSuiAmount: coin === 'sui' ? BigInt(amount) : 0n,
100
+ });
101
+ tx = oracle.tx;
102
+ const { suiCoinObject } = oracle;
95
103
  // Process deposit coins
96
104
  const depositObject = coin === 'sui'
97
105
  ? tx.splitCoins(suiCoinObject, [tx.pure.u64(amount)])[0]
@@ -112,7 +120,7 @@ export class ZLPAPI extends BaseAPI {
112
120
  return mintedCoin;
113
121
  }
114
122
  // Handle non-sponsored transaction case
115
- tx = await this.initOracleTxb(pythFeederKeys, tx);
123
+ tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
116
124
  const depositObject = tx.splitCoins(this.processCoins(tx, coin, coinObjects, false), [tx.pure.u64(amount)])[0];
117
125
  const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
118
126
  const [mintedCoin] = tx.moveCall({
@@ -132,7 +140,7 @@ export class ZLPAPI extends BaseAPI {
132
140
  });
133
141
  return mintedCoin;
134
142
  }
135
- async depositWithPtb(coin, depositObject, minAmountOut = 0, referralAddress, sender, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
143
+ async depositWithPtb(coin, depositObject, minAmountOut = 0, referralAddress, sender, tx, sponsoredTx) {
136
144
  if (!tx) {
137
145
  tx = new Transaction();
138
146
  }
@@ -144,8 +152,12 @@ export class ZLPAPI extends BaseAPI {
144
152
  const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
145
153
  // Handle sponsored transaction case
146
154
  if (sponsoredTx) {
147
- const suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
148
- tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject);
155
+ const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
156
+ sender: this.requireSenderForSponsored(sender),
157
+ additionalSuiAmount: 0n,
158
+ });
159
+ tx = oracle.tx;
160
+ const { suiCoinObject } = oracle;
149
161
  const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
150
162
  tx.moveCall({
151
163
  target: `${this.consts.zoCore.upgradedPackage}::market::deposit`,
@@ -162,7 +174,7 @@ export class ZLPAPI extends BaseAPI {
162
174
  return tx;
163
175
  }
164
176
  // Handle non-sponsored transaction case
165
- tx = await this.initOracleTxb(pythFeederKeys, tx);
177
+ tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
166
178
  const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
167
179
  tx.moveCall({
168
180
  target: `${this.consts.zoCore.upgradedPackage}::market::deposit`,
@@ -184,16 +196,20 @@ export class ZLPAPI extends BaseAPI {
184
196
  /**
185
197
  * Withdraws collateral from ZLP vault
186
198
  */
187
- async withdraw(coin, lpCoinObjects, amount, minAmountOut = 0, sponsoredTx, suiCoinObjectsForPythUpdate) {
199
+ async withdraw(coin, lpCoinObjects, amount, minAmountOut = 0, sponsoredTx, sender) {
188
200
  let tx = new Transaction();
189
201
  // Initialize oracle transaction
190
202
  const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
191
203
  if (sponsoredTx) {
192
- const suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
193
- tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject);
204
+ const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
205
+ sender: this.requireSenderForSponsored(sender),
206
+ additionalSuiAmount: 0n,
207
+ });
208
+ tx = oracle.tx;
209
+ const { suiCoinObject } = oracle;
194
210
  }
195
211
  else {
196
- tx = await this.initOracleTxb(pythFeederKeys, tx);
212
+ tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
197
213
  }
198
214
  const zlpCoinObject = this.processCoins(tx, 'zlp', lpCoinObjects, false);
199
215
  const [withdrawObject] = tx.splitCoins(zlpCoinObject, [tx.pure.u64(amount)]);
@@ -224,7 +240,7 @@ export class ZLPAPI extends BaseAPI {
224
240
  }
225
241
  // Initialize oracle transaction
226
242
  const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
227
- tx = await this.initOracleTxb(pythFeederKeys, tx);
243
+ tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
228
244
  const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
229
245
  tx.moveCall({
230
246
  target: `${this.consts.zoCore.upgradedPackage}::market::withdraw`,
@@ -243,18 +259,22 @@ export class ZLPAPI extends BaseAPI {
243
259
  });
244
260
  return tx;
245
261
  }
246
- async withdrawPtb(coin, lpCoinObjects, amount, minAmountOut = 0, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
262
+ async withdrawPtb(coin, lpCoinObjects, amount, minAmountOut = 0, tx, sponsoredTx, sender) {
247
263
  if (!tx) {
248
264
  tx = new Transaction();
249
265
  }
250
266
  // Initialize oracle transaction
251
267
  const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
252
268
  if (sponsoredTx) {
253
- const suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
254
- tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject);
269
+ const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
270
+ sender: this.requireSenderForSponsored(sender),
271
+ additionalSuiAmount: 0n,
272
+ });
273
+ tx = oracle.tx;
274
+ const { suiCoinObject } = oracle;
255
275
  }
256
276
  else {
257
- tx = await this.initOracleTxb(pythFeederKeys, tx);
277
+ tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
258
278
  }
259
279
  const zlpCoinObject = this.processCoins(tx, 'zlp', lpCoinObjects, false);
260
280
  const [withdrawObject] = tx.splitCoins(zlpCoinObject, [tx.pure.u64(amount)]);
@@ -439,7 +459,7 @@ export class ZLPAPI extends BaseAPI {
439
459
  return rewardCoin;
440
460
  }
441
461
  async swap(fromToken, toToken, fromAmount, fromCoinObjects, minAmountOut) {
442
- const tx = await this.initOracleTxb(Object.keys(this.consts.zoCore.vaults));
462
+ const { tx } = await this.initOracleTxb(Object.keys(this.consts.zoCore.vaults));
443
463
  const fromCoinObject = this.processCoins(tx, fromToken, fromCoinObjects);
444
464
  const [fromDepositObject] = tx.splitCoins(fromCoinObject, [tx.pure.u64(fromAmount)]);
445
465
  const vaultsValuation = this.dataAPI.valuateVaults(tx);
@@ -471,7 +491,7 @@ export class ZLPAPI extends BaseAPI {
471
491
  if (!tx) {
472
492
  tx = new Transaction();
473
493
  }
474
- tx = await this.initOracleTxb(Object.keys(this.consts.zoCore.vaults), tx);
494
+ tx = (await this.initOracleTxb(Object.keys(this.consts.zoCore.vaults), tx)).tx;
475
495
  const fromCoinObject = this.processCoins(tx, fromToken, fromCoinObjects);
476
496
  const [fromDepositObject] = tx.splitCoins(fromCoinObject, [
477
497
  tx.pure.u64(fromAmount),
@@ -499,7 +519,7 @@ export class ZLPAPI extends BaseAPI {
499
519
  /**
500
520
  * Opens a new position in ZLP
501
521
  */
502
- 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) {
522
+ 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) {
503
523
  let tx = new Transaction();
504
524
  if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
505
525
  tx = await this.addReferral(referralAddress, tx);
@@ -514,11 +534,15 @@ export class ZLPAPI extends BaseAPI {
514
534
  // Handle oracle initialization and coin processing
515
535
  let suiCoinObject;
516
536
  if (sponsoredTx) {
517
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
518
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
537
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
538
+ sender: this.requireSenderForSponsored(sender),
539
+ additionalSuiAmount: collateralToken === 'sui' ? collateralAmount + relayerFee : 0n,
540
+ });
541
+ tx = oracle.tx;
542
+ suiCoinObject = oracle.suiCoinObject;
519
543
  }
520
544
  else {
521
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
545
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
522
546
  }
523
547
  // Process coin splitting
524
548
  const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
@@ -553,7 +577,7 @@ export class ZLPAPI extends BaseAPI {
553
577
  /**
554
578
  * Opens a new position in ZLP
555
579
  */
556
- 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) {
580
+ 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) {
557
581
  let tx = new Transaction();
558
582
  if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
559
583
  tx = await this.addReferral(referralAddress, tx);
@@ -569,11 +593,15 @@ export class ZLPAPI extends BaseAPI {
569
593
  // Handle oracle initialization and coin processing
570
594
  let suiCoinObject;
571
595
  if (sponsoredTx) {
572
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
573
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
596
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
597
+ sender: this.requireSenderForSponsored(sender),
598
+ additionalSuiAmount: collateralToken === 'sui' ? collateralAmount + relayerFee : 0n,
599
+ });
600
+ tx = oracle.tx;
601
+ suiCoinObject = oracle.suiCoinObject;
574
602
  }
575
603
  else {
576
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
604
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
577
605
  }
578
606
  // Process coin splitting
579
607
  const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
@@ -607,7 +635,7 @@ export class ZLPAPI extends BaseAPI {
607
635
  /**
608
636
  * Opens a new position with Coin in ZLP
609
637
  */
610
- 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) {
638
+ 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) {
611
639
  if (!tx) {
612
640
  tx = new Transaction();
613
641
  }
@@ -624,11 +652,15 @@ export class ZLPAPI extends BaseAPI {
624
652
  // Handle oracle initialization and coin processing
625
653
  let suiCoinObject;
626
654
  if (sponsoredTx) {
627
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
628
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
655
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
656
+ sender: this.requireSenderForSponsored(sender),
657
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
658
+ });
659
+ tx = oracle.tx;
660
+ suiCoinObject = oracle.suiCoinObject;
629
661
  }
630
662
  else {
631
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
663
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
632
664
  }
633
665
  // Process coin splitting
634
666
  const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
@@ -663,7 +695,7 @@ export class ZLPAPI extends BaseAPI {
663
695
  /**
664
696
  * Opens a new position with Coin in ZLP (V2)
665
697
  */
666
- 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) {
698
+ 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) {
667
699
  if (!tx) {
668
700
  tx = new Transaction();
669
701
  }
@@ -681,11 +713,15 @@ export class ZLPAPI extends BaseAPI {
681
713
  // Handle oracle initialization and coin processing
682
714
  let suiCoinObject;
683
715
  if (sponsoredTx) {
684
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
685
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
716
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
717
+ sender: this.requireSenderForSponsored(sender),
718
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
719
+ });
720
+ tx = oracle.tx;
721
+ suiCoinObject = oracle.suiCoinObject;
686
722
  }
687
723
  else {
688
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
724
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
689
725
  }
690
726
  // Process coin splitting
691
727
  const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
@@ -719,7 +755,7 @@ export class ZLPAPI extends BaseAPI {
719
755
  /**
720
756
  * Decreases an existing position in ZLP
721
757
  */
722
- 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) {
758
+ 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) {
723
759
  if (!coinObjects) {
724
760
  throw new Error(`${this.constructor.name}: coinObjects is required`);
725
761
  }
@@ -737,11 +773,15 @@ export class ZLPAPI extends BaseAPI {
737
773
  // Handle oracle initialization and coin processing
738
774
  let suiCoinObject;
739
775
  if (sponsoredTx) {
740
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
741
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
776
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
777
+ sender: this.requireSenderForSponsored(sender),
778
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
779
+ });
780
+ tx = oracle.tx;
781
+ suiCoinObject = oracle.suiCoinObject;
742
782
  }
743
783
  else {
744
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
784
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
745
785
  }
746
786
  // Process coin splitting
747
787
  const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
@@ -775,7 +815,7 @@ export class ZLPAPI extends BaseAPI {
775
815
  /**
776
816
  * Decreases an existing position in ZLP
777
817
  */
778
- 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) {
818
+ 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) {
779
819
  if (!coinObjects) {
780
820
  throw new Error(`${this.constructor.name}: coinObjects is required`);
781
821
  }
@@ -793,11 +833,15 @@ export class ZLPAPI extends BaseAPI {
793
833
  // Handle oracle initialization and coin processing
794
834
  let suiCoinObject;
795
835
  if (sponsoredTx) {
796
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
797
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
836
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
837
+ sender: this.requireSenderForSponsored(sender),
838
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
839
+ });
840
+ tx = oracle.tx;
841
+ suiCoinObject = oracle.suiCoinObject;
798
842
  }
799
843
  else {
800
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
844
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
801
845
  }
802
846
  // Process coin splitting
803
847
  const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
@@ -827,18 +871,19 @@ export class ZLPAPI extends BaseAPI {
827
871
  });
828
872
  return tx;
829
873
  }
830
- async decreaseMultiPositions(positions, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
874
+ async decreaseMultiPositions(positions, tx, sponsoredTx, sender) {
831
875
  if (!tx) {
832
876
  tx = new Transaction();
833
877
  }
834
878
  // Handle oracle initialization and coin processing
835
879
  let suiCoinObject;
836
880
  if (sponsoredTx) {
837
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
838
- tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx, true, suiCoinObject);
881
+ const oracle = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx, true, { sender: this.requireSenderForSponsored(sender) });
882
+ tx = oracle.tx;
883
+ suiCoinObject = oracle.suiCoinObject;
839
884
  }
840
885
  else {
841
- tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx);
886
+ tx = (await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx)).tx;
842
887
  }
843
888
  for (const position of positions) {
844
889
  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;
@@ -883,14 +928,21 @@ export class ZLPAPI extends BaseAPI {
883
928
  }
884
929
  return tx;
885
930
  }
886
- async decreaseMultiPositionsV2(positions, tx, sponsoredTx, suiCoinObjectsForPythUpdate, feeObjects) {
887
- const transaction = tx ?? new Transaction();
931
+ async decreaseMultiPositionsV2(positions, tx, sponsoredTx, sender, feeObjects) {
932
+ let transaction = tx ?? new Transaction();
888
933
  // Handle oracle initialization and coin processing
889
934
  const tokens = positions.flatMap(position => [position.collateralToken, position.indexToken]);
890
- const suiCoinObject = sponsoredTx
891
- ? this.processCoins(transaction, 'sui', suiCoinObjectsForPythUpdate || [], true)
892
- : undefined;
893
- await this.initOracleTxb(tokens, transaction, !!sponsoredTx, suiCoinObject);
935
+ let suiCoinObject;
936
+ if (sponsoredTx) {
937
+ const oracle = await this.initOracleTxb(tokens, transaction, true, {
938
+ sender: this.requireSenderForSponsored(sender),
939
+ });
940
+ transaction = oracle.tx;
941
+ suiCoinObject = oracle.suiCoinObject;
942
+ }
943
+ else {
944
+ transaction = (await this.initOracleTxb(tokens, transaction, false)).tx;
945
+ }
894
946
  if (!feeObjects || feeObjects.length !== positions.length) {
895
947
  throw new Error('feeObjects must be provided (pre-processed via buildFeeCoinObjects) and match positions length');
896
948
  }
@@ -935,7 +987,7 @@ export class ZLPAPI extends BaseAPI {
935
987
  }
936
988
  return transaction;
937
989
  }
938
- 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) {
990
+ 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) {
939
991
  let tx = new Transaction();
940
992
  if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
941
993
  tx = await this.addReferral(referralAddress, tx);
@@ -959,11 +1011,15 @@ export class ZLPAPI extends BaseAPI {
959
1011
  // Handle oracle initialization and coin processing
960
1012
  let suiCoinObject;
961
1013
  if (sponsoredTx) {
962
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
963
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1014
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
1015
+ sender: this.requireSenderForSponsored(sender),
1016
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
1017
+ });
1018
+ tx = oracle.tx;
1019
+ suiCoinObject = oracle.suiCoinObject;
964
1020
  }
965
1021
  else {
966
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1022
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
967
1023
  }
968
1024
  // Process coin splitting
969
1025
  const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
@@ -1003,7 +1059,7 @@ export class ZLPAPI extends BaseAPI {
1003
1059
  .finalize();
1004
1060
  return tx;
1005
1061
  }
1006
- 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) {
1062
+ 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) {
1007
1063
  let tx = new Transaction();
1008
1064
  if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
1009
1065
  tx = await this.addReferral(referralAddress, tx);
@@ -1028,11 +1084,15 @@ export class ZLPAPI extends BaseAPI {
1028
1084
  // Handle oracle initialization and coin processing
1029
1085
  let suiCoinObject;
1030
1086
  if (sponsoredTx) {
1031
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1032
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1087
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
1088
+ sender: this.requireSenderForSponsored(sender),
1089
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
1090
+ });
1091
+ tx = oracle.tx;
1092
+ suiCoinObject = oracle.suiCoinObject;
1033
1093
  }
1034
1094
  else {
1035
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1095
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
1036
1096
  }
1037
1097
  // Process coin splitting
1038
1098
  const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
@@ -1071,7 +1131,7 @@ export class ZLPAPI extends BaseAPI {
1071
1131
  .finalize();
1072
1132
  return tx;
1073
1133
  }
1074
- 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) {
1134
+ 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) {
1075
1135
  if (!tx) {
1076
1136
  tx = new Transaction();
1077
1137
  }
@@ -1097,11 +1157,15 @@ export class ZLPAPI extends BaseAPI {
1097
1157
  // Handle oracle initialization and coin processing
1098
1158
  let suiCoinObject;
1099
1159
  if (sponsoredTx) {
1100
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1101
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1160
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
1161
+ sender: this.requireSenderForSponsored(sender),
1162
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
1163
+ });
1164
+ tx = oracle.tx;
1165
+ suiCoinObject = oracle.suiCoinObject;
1102
1166
  }
1103
1167
  else {
1104
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1168
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
1105
1169
  }
1106
1170
  // Process coin splitting
1107
1171
  const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
@@ -1141,7 +1205,7 @@ export class ZLPAPI extends BaseAPI {
1141
1205
  .finalize();
1142
1206
  return tx;
1143
1207
  }
1144
- 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) {
1208
+ 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) {
1145
1209
  if (!tx) {
1146
1210
  tx = new Transaction();
1147
1211
  }
@@ -1168,11 +1232,15 @@ export class ZLPAPI extends BaseAPI {
1168
1232
  // Handle oracle initialization and coin processing
1169
1233
  let suiCoinObject;
1170
1234
  if (sponsoredTx) {
1171
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1172
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1235
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
1236
+ sender: this.requireSenderForSponsored(sender),
1237
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
1238
+ });
1239
+ tx = oracle.tx;
1240
+ suiCoinObject = oracle.suiCoinObject;
1173
1241
  }
1174
1242
  else {
1175
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1243
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
1176
1244
  }
1177
1245
  // Process coin splitting
1178
1246
  const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
@@ -1211,7 +1279,7 @@ export class ZLPAPI extends BaseAPI {
1211
1279
  .finalize();
1212
1280
  return tx;
1213
1281
  }
1214
- 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) {
1282
+ 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) {
1215
1283
  if (!coinObjects) {
1216
1284
  throw new Error(`${this.constructor.name}: coinObjects is required`);
1217
1285
  }
@@ -1238,11 +1306,15 @@ export class ZLPAPI extends BaseAPI {
1238
1306
  // Handle oracle initialization and coin processing
1239
1307
  let suiCoinObject;
1240
1308
  if (sponsoredTx) {
1241
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1242
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1309
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
1310
+ sender: this.requireSenderForSponsored(sender),
1311
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
1312
+ });
1313
+ tx = oracle.tx;
1314
+ suiCoinObject = oracle.suiCoinObject;
1243
1315
  }
1244
1316
  else {
1245
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1317
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
1246
1318
  }
1247
1319
  // Process coin splitting
1248
1320
  const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
@@ -1281,7 +1353,7 @@ export class ZLPAPI extends BaseAPI {
1281
1353
  .finalize();
1282
1354
  return tx;
1283
1355
  }
1284
- 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) {
1356
+ 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) {
1285
1357
  if (!coinObjects) {
1286
1358
  throw new Error(`${this.constructor.name}: coinObjects is required`);
1287
1359
  }
@@ -1308,11 +1380,15 @@ export class ZLPAPI extends BaseAPI {
1308
1380
  // Handle oracle initialization and coin processing
1309
1381
  let suiCoinObject;
1310
1382
  if (sponsoredTx) {
1311
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1312
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1383
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
1384
+ sender: this.requireSenderForSponsored(sender),
1385
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
1386
+ });
1387
+ tx = oracle.tx;
1388
+ suiCoinObject = oracle.suiCoinObject;
1313
1389
  }
1314
1390
  else {
1315
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1391
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
1316
1392
  }
1317
1393
  // Process coin splitting
1318
1394
  const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
@@ -1350,18 +1426,19 @@ export class ZLPAPI extends BaseAPI {
1350
1426
  .finalize();
1351
1427
  return tx;
1352
1428
  }
1353
- async decreaseMultiPositionsWithSCard(positions, kioskClient, kioskCap, scard, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
1429
+ async decreaseMultiPositionsWithSCard(positions, kioskClient, kioskCap, scard, tx, sponsoredTx, sender) {
1354
1430
  if (!tx) {
1355
1431
  tx = new Transaction();
1356
1432
  }
1357
1433
  // Handle oracle initialization and coin processing
1358
1434
  let suiCoinObject;
1359
1435
  if (sponsoredTx) {
1360
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1361
- tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx, true, suiCoinObject);
1436
+ const oracle = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx, true, { sender: this.requireSenderForSponsored(sender) });
1437
+ tx = oracle.tx;
1438
+ suiCoinObject = oracle.suiCoinObject;
1362
1439
  }
1363
1440
  else {
1364
- tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx);
1441
+ tx = (await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx)).tx;
1365
1442
  }
1366
1443
  const kioskTx = new KioskTransaction({
1367
1444
  transaction: tx,
@@ -1423,14 +1500,21 @@ export class ZLPAPI extends BaseAPI {
1423
1500
  .finalize();
1424
1501
  return tx;
1425
1502
  }
1426
- async decreaseMultiPositionsWithSCardV2(positions, kioskClient, kioskCap, scard, tx, sponsoredTx, suiCoinObjectsForPythUpdate, feeObjects) {
1427
- const transaction = tx ?? new Transaction();
1503
+ async decreaseMultiPositionsWithSCardV2(positions, kioskClient, kioskCap, scard, tx, sponsoredTx, sender, feeObjects) {
1504
+ let transaction = tx ?? new Transaction();
1428
1505
  // Handle oracle initialization and coin processing
1429
1506
  const tokens = positions.flatMap(position => [position.collateralToken, position.indexToken]);
1430
- const suiCoinObject = sponsoredTx
1431
- ? this.processCoins(transaction, 'sui', suiCoinObjectsForPythUpdate || [], true)
1432
- : undefined;
1433
- await this.initOracleTxb(tokens, transaction, !!sponsoredTx, suiCoinObject);
1507
+ let suiCoinObject;
1508
+ if (sponsoredTx) {
1509
+ const oracle = await this.initOracleTxb(tokens, transaction, true, {
1510
+ sender: this.requireSenderForSponsored(sender),
1511
+ });
1512
+ transaction = oracle.tx;
1513
+ suiCoinObject = oracle.suiCoinObject;
1514
+ }
1515
+ else {
1516
+ transaction = (await this.initOracleTxb(tokens, transaction, false)).tx;
1517
+ }
1434
1518
  if (!feeObjects || feeObjects.length !== positions.length) {
1435
1519
  throw new Error('feeObjects must be provided (pre-processed via buildFeeCoinObjects) and match positions length');
1436
1520
  }
@@ -1495,16 +1579,20 @@ export class ZLPAPI extends BaseAPI {
1495
1579
  /**
1496
1580
  * Pledges in position (ZLP-specific functionality)
1497
1581
  */
1498
- async pledgeInPosition(pcpId, collateralToken, indexToken, amount, coinObjects, long, sponsoredTx, suiCoinObjectsForPythUpdate) {
1582
+ async pledgeInPosition(pcpId, collateralToken, indexToken, amount, coinObjects, long, sponsoredTx, sender) {
1499
1583
  let tx = new Transaction();
1500
1584
  // Handle oracle initialization and coin processing
1501
1585
  let suiCoinObject;
1502
1586
  if (sponsoredTx) {
1503
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1504
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1587
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
1588
+ sender: this.requireSenderForSponsored(sender),
1589
+ additionalSuiAmount: collateralToken === 'sui' ? BigInt(amount) : 0n,
1590
+ });
1591
+ tx = oracle.tx;
1592
+ suiCoinObject = oracle.suiCoinObject;
1505
1593
  }
1506
1594
  else {
1507
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1595
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
1508
1596
  }
1509
1597
  // Process coin splitting
1510
1598
  const [depositObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(amount)], sponsoredTx, suiCoinObject);
@@ -1520,16 +1608,20 @@ export class ZLPAPI extends BaseAPI {
1520
1608
  });
1521
1609
  return tx;
1522
1610
  }
1523
- async redeemFromPosition(pcpId, collateralToken, indexToken, amount, long, sponsoredTx, suiCoinObjectsForPythUpdate) {
1611
+ async redeemFromPosition(pcpId, collateralToken, indexToken, amount, long, sponsoredTx, sender) {
1524
1612
  let tx = new Transaction();
1525
1613
  // Handle oracle initialization and coin processing
1526
1614
  let suiCoinObject;
1527
1615
  if (sponsoredTx) {
1528
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1529
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1616
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
1617
+ sender: this.requireSenderForSponsored(sender),
1618
+ additionalSuiAmount: 0n,
1619
+ });
1620
+ tx = oracle.tx;
1621
+ suiCoinObject = oracle.suiCoinObject;
1530
1622
  }
1531
1623
  else {
1532
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1624
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
1533
1625
  }
1534
1626
  const symbol = joinSymbol(long ? 'long' : 'short', indexToken);
1535
1627
  tx.moveCall({
@@ -1716,7 +1808,7 @@ export class ZLPAPI extends BaseAPI {
1716
1808
  return tx;
1717
1809
  }
1718
1810
  async adminUpdatePriceFeed(collateralToken, indexToken) {
1719
- const tx = await this.initOracleTxb([collateralToken, indexToken]);
1811
+ const { tx } = await this.initOracleTxb([collateralToken, indexToken]);
1720
1812
  return tx;
1721
1813
  }
1722
1814
  adminSettlePosition(positionId, owner, collateralToken, indexToken, long) {