zo-sdk 0.1.30 → 0.1.32

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 (71) hide show
  1. package/dist/consts/deployments-shared-mainnet.json +1 -0
  2. package/dist/consts/deployments-slp-mainnet.json +1 -1
  3. package/dist/implementations/SLPAPI.cjs +142 -118
  4. package/dist/implementations/SLPAPI.cjs.map +1 -1
  5. package/dist/implementations/SLPAPI.d.cts +24 -14
  6. package/dist/implementations/SLPAPI.d.cts.map +1 -1
  7. package/dist/implementations/SLPAPI.d.mts +24 -14
  8. package/dist/implementations/SLPAPI.d.mts.map +1 -1
  9. package/dist/implementations/SLPAPI.mjs +142 -118
  10. package/dist/implementations/SLPAPI.mjs.map +1 -1
  11. package/dist/implementations/SLPDataAPI.cjs +50 -3
  12. package/dist/implementations/SLPDataAPI.cjs.map +1 -1
  13. package/dist/implementations/SLPDataAPI.d.cts +6 -1
  14. package/dist/implementations/SLPDataAPI.d.cts.map +1 -1
  15. package/dist/implementations/SLPDataAPI.d.mts +6 -1
  16. package/dist/implementations/SLPDataAPI.d.mts.map +1 -1
  17. package/dist/implementations/SLPDataAPI.mjs +50 -3
  18. package/dist/implementations/SLPDataAPI.mjs.map +1 -1
  19. package/dist/implementations/USDZAPI.cjs +43 -4
  20. package/dist/implementations/USDZAPI.cjs.map +1 -1
  21. package/dist/implementations/USDZAPI.d.cts +13 -2
  22. package/dist/implementations/USDZAPI.d.cts.map +1 -1
  23. package/dist/implementations/USDZAPI.d.mts +13 -2
  24. package/dist/implementations/USDZAPI.d.mts.map +1 -1
  25. package/dist/implementations/USDZAPI.mjs +43 -4
  26. package/dist/implementations/USDZAPI.mjs.map +1 -1
  27. package/dist/implementations/ZBTCVCAPI.cjs +4 -4
  28. package/dist/implementations/ZBTCVCAPI.cjs.map +1 -1
  29. package/dist/implementations/ZBTCVCAPI.mjs +4 -4
  30. package/dist/implementations/ZBTCVCAPI.mjs.map +1 -1
  31. package/dist/implementations/ZLPAPI.cjs +100 -4
  32. package/dist/implementations/ZLPAPI.cjs.map +1 -1
  33. package/dist/implementations/ZLPAPI.d.cts +16 -1
  34. package/dist/implementations/ZLPAPI.d.cts.map +1 -1
  35. package/dist/implementations/ZLPAPI.d.mts +16 -1
  36. package/dist/implementations/ZLPAPI.d.mts.map +1 -1
  37. package/dist/implementations/ZLPAPI.mjs +100 -4
  38. package/dist/implementations/ZLPAPI.mjs.map +1 -1
  39. package/dist/interfaces/base.d.cts +4 -3
  40. package/dist/interfaces/base.d.cts.map +1 -1
  41. package/dist/interfaces/base.d.mts +4 -3
  42. package/dist/interfaces/base.d.mts.map +1 -1
  43. package/dist/interfaces/slp.d.cts +26 -1
  44. package/dist/interfaces/slp.d.cts.map +1 -1
  45. package/dist/interfaces/slp.d.mts +26 -1
  46. package/dist/interfaces/slp.d.mts.map +1 -1
  47. package/dist/interfaces/usdz.d.cts +5 -3
  48. package/dist/interfaces/usdz.d.cts.map +1 -1
  49. package/dist/interfaces/usdz.d.mts +5 -3
  50. package/dist/interfaces/usdz.d.mts.map +1 -1
  51. package/dist/interfaces/zbtcvc.d.cts +3 -3
  52. package/dist/interfaces/zbtcvc.d.cts.map +1 -1
  53. package/dist/interfaces/zbtcvc.d.mts +3 -3
  54. package/dist/interfaces/zbtcvc.d.mts.map +1 -1
  55. package/dist/interfaces/zlp.d.cts +5 -1
  56. package/dist/interfaces/zlp.d.cts.map +1 -1
  57. package/dist/interfaces/zlp.d.mts +5 -1
  58. package/dist/interfaces/zlp.d.mts.map +1 -1
  59. package/package.json +1 -1
  60. package/src/consts/deployments-shared-mainnet.json +1 -0
  61. package/src/consts/deployments-slp-mainnet.json +1 -1
  62. package/src/implementations/SLPAPI.ts +199 -132
  63. package/src/implementations/SLPDataAPI.ts +57 -6
  64. package/src/implementations/USDZAPI.ts +57 -6
  65. package/src/implementations/ZBTCVCAPI.ts +4 -4
  66. package/src/implementations/ZLPAPI.ts +137 -6
  67. package/src/interfaces/base.ts +10 -3
  68. package/src/interfaces/slp.ts +57 -2
  69. package/src/interfaces/usdz.ts +18 -4
  70. package/src/interfaces/zbtcvc.ts +5 -4
  71. package/src/interfaces/zlp.ts +32 -1
@@ -144,6 +144,66 @@ export class SLPAPI extends BaseAPI {
144
144
  });
145
145
  return tx;
146
146
  }
147
+ /**
148
+ * Deposits collateral into SLP vault and returns a coin
149
+ */
150
+ async depositPtb(coin, coinObjects, amount, minAmountOut = 0, referralAddress, sender, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
151
+ if (!tx) {
152
+ tx = new Transaction();
153
+ }
154
+ // Add referral if needed
155
+ if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
156
+ tx = await this.addReferral(referralAddress, tx);
157
+ }
158
+ // Initialize oracle transaction
159
+ const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
160
+ // Handle sponsored transaction case
161
+ if (sponsoredTx) {
162
+ const suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
163
+ tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject);
164
+ // Process deposit coins
165
+ const depositObject = coin === 'sui'
166
+ ? tx.splitCoins(suiCoinObject, [tx.pure.u64(amount)])[0]
167
+ : tx.splitCoins(this.processCoins(tx, coin, coinObjects, true), [tx.pure.u64(amount)])[0];
168
+ const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
169
+ const [mintedCoin] = tx.moveCall({
170
+ target: `${this.consts.sudoCore.upgradedPackage}::market::deposit_ptb`,
171
+ typeArguments: [`${this.consts.sudoCore.package}::slp::SLP`, this.consts.coins[coin].module],
172
+ arguments: [
173
+ tx.object(this.consts.sudoCore.market),
174
+ tx.object(this.consts.sudoCore.rebaseFeeModel),
175
+ depositObject,
176
+ tx.pure.u64(minAmountOut),
177
+ vaultsValuation,
178
+ symbolsValuation,
179
+ ],
180
+ });
181
+ return mintedCoin;
182
+ }
183
+ // Handle non-sponsored transaction case
184
+ tx = await this.initOracleTxb(pythFeederKeys, tx);
185
+ const depositObject = tx.splitCoins(this.processCoins(tx, coin, coinObjects, false), [tx.pure.u64(amount)])[0];
186
+ const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
187
+ const [mintedCoin] = tx.moveCall({
188
+ target: `${this.consts.sudoCore.upgradedPackage}::market::deposit_ptb`,
189
+ typeArguments: [
190
+ `${this.consts.sudoCore.package}::slp::SLP`,
191
+ this.consts.coins[coin].module,
192
+ ],
193
+ arguments: [
194
+ tx.object(this.consts.sudoCore.market),
195
+ tx.object(this.consts.sudoCore.rebaseFeeModel),
196
+ depositObject,
197
+ tx.pure.u64(minAmountOut),
198
+ vaultsValuation,
199
+ symbolsValuation,
200
+ ],
201
+ });
202
+ return mintedCoin;
203
+ }
204
+ /**
205
+ * Deposits collateral pool with PTB deposit object
206
+ */
147
207
  async depositWithPtb(coin, depositObject, minAmountOut = 0, referralAddress, sender, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
148
208
  if (!tx) {
149
209
  tx = new Transaction();
@@ -287,81 +347,17 @@ export class SLPAPI extends BaseAPI {
287
347
  });
288
348
  return tx;
289
349
  }
290
- /**
291
- * Stakes SLP tokens in Sudo staking pools
292
- */
293
- stake(lpCoinObjects, amount, pool) {
294
- if (!this.consts.sudoStaking) {
295
- throw new Error('Sudo staking configuration not found');
296
- }
297
- const tx = new Transaction();
298
- const coinObject = this.processCoins(tx, 'slp', lpCoinObjects);
299
- const [depositObject] = tx.splitCoins(coinObject, [tx.pure.u64(amount)]);
300
- tx.moveCall({
301
- target: `${this.consts.sudoStaking.package}::pool::deposit`,
302
- typeArguments: [
303
- `${this.consts.sudoCore.package}::slp::SLP`,
304
- `${this.consts.sudoCore.package}::slp::SLP`,
305
- ],
306
- arguments: [
307
- tx.object(pool),
308
- tx.object(SUI_CLOCK_OBJECT_ID),
309
- depositObject,
310
- ],
311
- });
312
- return tx;
313
- }
314
- /**
315
- * Unstakes SLP tokens from Sudo staking pools
316
- */
317
- unstake(credentials, amount, pool) {
318
- if (!this.consts.sudoStaking) {
319
- throw new Error('Sudo staking configuration not found');
320
- }
321
- const tx = new Transaction();
322
- for (const credential of credentials) {
323
- const withdrawAmount = (() => {
324
- const min = (a, b) => a < b ? a : b;
325
- return min(amount, credential.amount);
326
- })();
327
- amount -= withdrawAmount;
328
- tx.moveCall({
329
- target: `${this.consts.sudoStaking.package}::pool::withdraw`,
330
- typeArguments: [
331
- `${this.consts.sudoCore.package}::slp::SLP`,
332
- `${this.consts.sudoCore.package}::slp::SLP`,
333
- ],
334
- arguments: [
335
- tx.object(pool),
336
- tx.object(SUI_CLOCK_OBJECT_ID),
337
- tx.object(credential.id),
338
- tx.pure.u64(withdrawAmount),
339
- ],
340
- });
341
- if (credential.amount === BigInt(0)) {
342
- tx.moveCall({
343
- target: `${this.consts.sudoStaking.package}::pool::clear_empty_credential`,
344
- typeArguments: [
345
- `${this.consts.sudoCore.package}::slp::SLP`,
346
- `${this.consts.sudoCore.package}::slp::SLP`,
347
- ],
348
- arguments: [tx.object(credential.id)],
349
- });
350
- }
351
- }
352
- return tx;
353
- }
354
350
  /**
355
351
  * Stakes SLP tokens in ZO staking pools
356
352
  */
357
- stakeV2(lpCoinObjects, amount, pool, tx) {
353
+ stake(lpCoinObjects, amount, pool, tx) {
358
354
  if (!tx) {
359
355
  tx = new Transaction();
360
356
  }
361
357
  const coinObject = this.processCoins(tx, 'slp', lpCoinObjects);
362
358
  const [depositObject] = tx.splitCoins(coinObject, [tx.pure.u64(amount)]);
363
359
  tx.moveCall({
364
- target: `${this.sharedConfig.zoStaking.package}::pool::deposit`,
360
+ target: `${this.sharedConfig.zoStaking.upgradedPackage}::pool::deposit`,
365
361
  typeArguments: [
366
362
  `${this.consts.sudoCore.package}::slp::SLP`,
367
363
  `${this.consts.sudoCore.package}::slp::SLP`,
@@ -377,12 +373,12 @@ export class SLPAPI extends BaseAPI {
377
373
  /**
378
374
  * Stakes SLP tokens using coin object only (PTB)
379
375
  */
380
- stakeCoinObjectV2(coinObject, pool, tx) {
376
+ stakeCoinObject(coinObject, pool, tx) {
381
377
  if (!tx) {
382
378
  tx = new Transaction();
383
379
  }
384
380
  tx.moveCall({
385
- target: `${this.sharedConfig.zoStaking.package}::pool::deposit`,
381
+ target: `${this.sharedConfig.zoStaking.upgradedPackage}::pool::deposit`,
386
382
  typeArguments: [
387
383
  `${this.consts.sudoCore.package}::slp::SLP`,
388
384
  `${this.consts.sudoCore.package}::slp::SLP`,
@@ -398,7 +394,7 @@ export class SLPAPI extends BaseAPI {
398
394
  /**
399
395
  * Unstakes SLP tokens from ZO staking pools
400
396
  */
401
- unstakeV2(credentials, amount, pool, tx) {
397
+ unstake(credentials, amount, pool, tx) {
402
398
  let unstakeAmount = amount;
403
399
  if (!tx) {
404
400
  tx = new Transaction();
@@ -410,7 +406,7 @@ export class SLPAPI extends BaseAPI {
410
406
  })();
411
407
  unstakeAmount -= withdrawAmount;
412
408
  tx.moveCall({
413
- target: `${this.sharedConfig.zoStaking.package}::pool::withdraw`,
409
+ target: `${this.sharedConfig.zoStaking.upgradedPackage}::pool::withdraw`,
414
410
  typeArguments: [
415
411
  `${this.consts.sudoCore.package}::slp::SLP`,
416
412
  `${this.consts.sudoCore.package}::slp::SLP`,
@@ -424,7 +420,7 @@ export class SLPAPI extends BaseAPI {
424
420
  });
425
421
  if (credential.amount === BigInt(0)) {
426
422
  tx.moveCall({
427
- target: `${this.sharedConfig.zoStaking.package}::pool::clear_empty_credential`,
423
+ target: `${this.sharedConfig.zoStaking.upgradedPackage}::pool::clear_empty_credential`,
428
424
  typeArguments: [
429
425
  `${this.consts.sudoCore.package}::slp::SLP`,
430
426
  `${this.consts.sudoCore.package}::slp::SLP`,
@@ -435,6 +431,45 @@ export class SLPAPI extends BaseAPI {
435
431
  }
436
432
  return tx;
437
433
  }
434
+ /**
435
+ * Withdraws SLP tokens from a staking pool credential (PTB)
436
+ * Returns the withdrawn coin object for use in programmable transaction blocks
437
+ */
438
+ withdrawFromVaultPtb(pool, credential, withdrawAmount, tx) {
439
+ const [withdrawnCoin] = tx.moveCall({
440
+ target: `${this.sharedConfig.zoStaking.upgradedPackage}::pool::withdraw_ptb`,
441
+ typeArguments: [
442
+ `${this.consts.sudoCore.package}::slp::SLP`,
443
+ `${this.consts.sudoCore.package}::slp::SLP`,
444
+ ],
445
+ arguments: [
446
+ tx.object(pool),
447
+ tx.object(SUI_CLOCK_OBJECT_ID),
448
+ tx.object(credential),
449
+ tx.pure.u64(withdrawAmount),
450
+ ],
451
+ });
452
+ return withdrawnCoin;
453
+ }
454
+ /**
455
+ * Claims rewards from a staking pool credential (PTB)
456
+ * Returns the reward coin object for use in programmable transaction blocks
457
+ */
458
+ claimRewardsPtb(pool, credential, tx) {
459
+ const [rewardCoin] = tx.moveCall({
460
+ target: `${this.sharedConfig.zoStaking.upgradedPackage}::pool::claim_rewards_ptb`,
461
+ typeArguments: [
462
+ `${this.consts.sudoCore.package}::slp::SLP`,
463
+ `${this.consts.sudoCore.package}::slp::SLP`,
464
+ ],
465
+ arguments: [
466
+ tx.object(pool),
467
+ tx.object(SUI_CLOCK_OBJECT_ID),
468
+ tx.object(credential),
469
+ ],
470
+ });
471
+ return rewardCoin;
472
+ }
438
473
  /**
439
474
  * Opens a position using Sudo SDK approach
440
475
  */
@@ -452,26 +487,23 @@ export class SLPAPI extends BaseAPI {
452
487
  }
453
488
  // Handle oracle initialization and coin processing
454
489
  let suiCoinObject;
455
- let feeObject;
456
490
  if (sponsoredTx) {
457
491
  suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
458
- feeObject = tx.splitCoins(suiCoinObject, [tx.pure.u64(relayerFee)]); // Sudo contract requires SUI as fee
459
492
  tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
460
493
  }
461
494
  else {
462
- feeObject = tx.splitCoins(tx.gas, [tx.pure.u64(relayerFee)]); // Sudo contract requires SUI as fee
463
495
  tx = await this.initOracleTxb([collateralToken, indexToken], tx);
464
496
  }
465
497
  // Process coin splitting
466
- const [depositObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount)], sponsoredTx, suiCoinObject);
498
+ const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
467
499
  tx.moveCall({
468
- target: `${this.consts.sudoCore.upgradedPackage}::market::open_position_v1_2`,
500
+ target: `${this.consts.sudoCore.upgradedPackage}::market::open_position_v2_1`,
469
501
  typeArguments: [
470
502
  `${this.consts.sudoCore.package}::slp::SLP`,
471
503
  this.consts.coins[collateralToken].module,
472
504
  this.consts.coins[indexToken].module,
473
505
  `${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
474
- this.consts.coins.sui.module,
506
+ this.consts.coins[collateralToken].module,
475
507
  ],
476
508
  arguments: [
477
509
  tx.object(SUI_CLOCK_OBJECT_ID),
@@ -488,7 +520,6 @@ export class SLPAPI extends BaseAPI {
488
520
  tx.pure.u64(reserveAmount),
489
521
  tx.pure.u256(adjustCollateralPrice),
490
522
  tx.pure.u256(adjustPrice),
491
- tx.pure.bool(isLimitOrder),
492
523
  ],
493
524
  });
494
525
  return tx;
@@ -497,6 +528,9 @@ export class SLPAPI extends BaseAPI {
497
528
  * Decreases an existing position in SLP using Sudo SDK approach
498
529
  */
499
530
  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) {
531
+ if (!coinObjects) {
532
+ throw new Error(`${this.constructor.name}: coinObjects is required`);
533
+ }
500
534
  let tx = new Transaction();
501
535
  const symbol = joinSymbol(long ? 'long' : 'short', indexToken);
502
536
  const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage);
@@ -510,24 +544,22 @@ export class SLPAPI extends BaseAPI {
510
544
  }
511
545
  // Handle oracle initialization and coin processing
512
546
  let suiCoinObject;
513
- let feeObject;
547
+ const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
514
548
  if (sponsoredTx) {
515
549
  suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
516
- feeObject = tx.splitCoins(suiCoinObject, [tx.pure.u64(relayerFee)]); // Sudo contract requires SUI as fee
517
550
  tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
518
551
  }
519
552
  else {
520
- feeObject = tx.splitCoins(tx.gas, [tx.pure.u64(relayerFee)]); // Sudo contract requires SUI as fee
521
553
  tx = await this.initOracleTxb([collateralToken, indexToken], tx);
522
554
  }
523
555
  tx.moveCall({
524
- target: `${this.consts.sudoCore.upgradedPackage}::market::decrease_position_v1_2`,
556
+ target: `${this.consts.sudoCore.upgradedPackage}::market::decrease_position_v2_1`,
525
557
  typeArguments: [
526
558
  `${this.consts.sudoCore.package}::slp::SLP`,
527
559
  this.consts.coins[collateralToken].module,
528
560
  this.consts.coins[indexToken].module,
529
561
  `${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
530
- this.consts.coins.sui.module,
562
+ this.consts.coins[collateralToken].module,
531
563
  ],
532
564
  arguments: [
533
565
  tx.object(SUI_CLOCK_OBJECT_ID),
@@ -543,7 +575,6 @@ export class SLPAPI extends BaseAPI {
543
575
  tx.pure.u64(amount),
544
576
  tx.pure.u256(adjustCollateralPrice),
545
577
  tx.pure.u256(adjustPrice),
546
- tx.pure.bool(isTriggerOrder),
547
578
  ],
548
579
  });
549
580
  return tx;
@@ -577,13 +608,13 @@ export class SLPAPI extends BaseAPI {
577
608
  // Process coin splitting
578
609
  const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
579
610
  tx.moveCall({
580
- target: `${this.consts.sudoCore.upgradedPackage}::market::decrease_position_v1_2`,
611
+ target: `${this.consts.sudoCore.upgradedPackage}::market::decrease_position_v2_1`,
581
612
  typeArguments: [
582
613
  `${this.consts.sudoCore.package}::slp::SLP`,
583
614
  this.consts.coins[collateralToken].module,
584
615
  this.consts.coins[indexToken].module,
585
616
  `${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
586
- this.consts.coins.sui.module,
617
+ this.consts.coins[collateralToken].module,
587
618
  ],
588
619
  arguments: [
589
620
  tx.object(SUI_CLOCK_OBJECT_ID),
@@ -599,7 +630,6 @@ export class SLPAPI extends BaseAPI {
599
630
  tx.pure.u64(amount),
600
631
  tx.pure.u256(adjustCollateralPrice),
601
632
  tx.pure.u256(adjustPrice),
602
- tx.pure.bool(isTriggerOrder),
603
633
  ],
604
634
  });
605
635
  }
@@ -667,16 +697,16 @@ export class SLPAPI extends BaseAPI {
667
697
  });
668
698
  return tx;
669
699
  }
670
- cancelOrder(orderCapId, collateralToken, indexToken, long, type) {
700
+ cancelOrder(orderCapId, collateralToken, indexToken, long, type, isV11Order) {
671
701
  const tx = new Transaction();
672
702
  let functionName = '';
673
703
  switch (type) {
674
704
  case 'OPEN_POSITION': {
675
- functionName = 'clear_open_position_order_v1_1';
705
+ functionName = 'clear_open_position_order_unified';
676
706
  break;
677
707
  }
678
708
  case 'DECREASE_POSITION': {
679
- functionName = 'clear_decrease_position_order_v1_1';
709
+ functionName = 'clear_decrease_position_order_unified';
680
710
  break;
681
711
  }
682
712
  default: {
@@ -690,7 +720,7 @@ export class SLPAPI extends BaseAPI {
690
720
  this.consts.coins[collateralToken].module,
691
721
  this.consts.coins[indexToken].module,
692
722
  `${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
693
- this.consts.coins.sui.module,
723
+ isV11Order ? this.consts.coins.sui.module : this.consts.coins[collateralToken].module,
694
724
  ],
695
725
  arguments: [
696
726
  tx.object(this.consts.sudoCore.market),
@@ -704,17 +734,15 @@ export class SLPAPI extends BaseAPI {
704
734
  tx = new Transaction();
705
735
  }
706
736
  for (const order of orders) {
707
- const { orderCapId, collateralToken, indexToken, long, type, isV11Order } = order;
737
+ const { orderCapId, collateralToken, indexToken, long, type } = order;
708
738
  let functionName = '';
709
739
  switch (type) {
710
740
  case 'OPEN_POSITION': {
711
- functionName = isV11Order ? 'clear_open_position_order_v1_1' : 'clear_open_position_order_v1_1';
741
+ functionName = 'clear_open_position_order_unified';
712
742
  break;
713
743
  }
714
744
  case 'DECREASE_POSITION': {
715
- functionName = isV11Order
716
- ? 'clear_decrease_position_order_v1_1'
717
- : 'clear_decrease_position_order_v1_1';
745
+ functionName = 'clear_decrease_position_order_unified';
718
746
  break;
719
747
  }
720
748
  default: {
@@ -747,15 +775,15 @@ export class SLPAPI extends BaseAPI {
747
775
  arguments: [tx.object(this.consts.sudoCore.market), tx.object(pcpId)],
748
776
  });
749
777
  }
750
- clearOpenPositionOrder(orderCapId, collateralToken, indexToken, long, tx) {
778
+ clearOpenPositionOrder(orderCapId, collateralToken, indexToken, long, tx, isV11Order = true) {
751
779
  tx.moveCall({
752
- target: `${this.consts.sudoCore.upgradedPackage}::market::clear_open_position_order_v1_1`,
780
+ target: `${this.consts.sudoCore.upgradedPackage}::market::clear_open_position_order_unified`,
753
781
  typeArguments: [
754
782
  `${this.consts.sudoCore.package}::slp::SLP`,
755
783
  this.consts.coins[collateralToken].module,
756
784
  this.consts.coins[indexToken].module,
757
785
  `${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
758
- this.consts.coins.sui.module,
786
+ isV11Order ? this.consts.coins.sui.module : this.consts.coins[collateralToken].module,
759
787
  ],
760
788
  arguments: [
761
789
  tx.object(this.consts.sudoCore.market),
@@ -763,15 +791,15 @@ export class SLPAPI extends BaseAPI {
763
791
  ],
764
792
  });
765
793
  }
766
- clearDecreasePositionOrder(orderCapId, collateralToken, indexToken, long, tx) {
794
+ clearDecreasePositionOrder(orderCapId, collateralToken, indexToken, long, tx, isV11Order = true) {
767
795
  tx.moveCall({
768
- target: `${this.consts.sudoCore.upgradedPackage}::market::clear_decrease_position_order_v1_1`,
796
+ target: `${this.consts.sudoCore.upgradedPackage}::market::clear_decrease_position_order_unified`,
769
797
  typeArguments: [
770
798
  `${this.consts.sudoCore.package}::slp::SLP`,
771
799
  this.consts.coins[collateralToken].module,
772
800
  this.consts.coins[indexToken].module,
773
801
  `${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
774
- this.consts.coins.sui.module,
802
+ isV11Order ? this.consts.coins.sui.module : this.consts.coins[collateralToken].module,
775
803
  ],
776
804
  arguments: [
777
805
  tx.object(this.consts.sudoCore.market),
@@ -802,26 +830,23 @@ export class SLPAPI extends BaseAPI {
802
830
  });
803
831
  // Handle oracle initialization and coin processing
804
832
  let suiCoinObject;
805
- let feeObject;
806
833
  if (sponsoredTx) {
807
834
  suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
808
- feeObject = tx.splitCoins(suiCoinObject, [tx.pure.u64(relayerFee)]); // Sudo contract requires SUI as fee
809
835
  tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
810
836
  }
811
837
  else {
812
- feeObject = tx.splitCoins(tx.gas, [tx.pure.u64(relayerFee)]); // Sudo contract requires SUI as fee
813
838
  tx = await this.initOracleTxb([collateralToken, indexToken], tx);
814
839
  }
815
840
  // Process coin splitting
816
- const [depositObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount)], sponsoredTx, suiCoinObject);
841
+ const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
817
842
  tx.moveCall({
818
- target: `${this.consts.sudoCore.upgradedPackage}::market::open_position_v1_3`,
843
+ target: `${this.consts.sudoCore.upgradedPackage}::market::open_position_with_scard_v1`,
819
844
  typeArguments: [
820
845
  `${this.consts.sudoCore.package}::slp::SLP`,
821
846
  this.consts.coins[collateralToken].module,
822
847
  this.consts.coins[indexToken].module,
823
848
  `${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
824
- this.consts.coins.sui.module,
849
+ this.consts.coins[collateralToken].module,
825
850
  ],
826
851
  arguments: [
827
852
  tx.object(SUI_CLOCK_OBJECT_ID),
@@ -838,7 +863,6 @@ export class SLPAPI extends BaseAPI {
838
863
  tx.pure.u64(reserveAmount),
839
864
  tx.pure.u256(adjustCollateralPrice),
840
865
  tx.pure.u256(adjustPrice),
841
- tx.pure.bool(isLimitOrder),
842
866
  sudoCard,
843
867
  ],
844
868
  });
@@ -852,6 +876,9 @@ export class SLPAPI extends BaseAPI {
852
876
  return tx;
853
877
  }
854
878
  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) {
879
+ if (!coinObjects) {
880
+ throw new Error(`${this.constructor.name}: coinObjects is required`);
881
+ }
855
882
  let tx = new Transaction();
856
883
  const symbol = joinSymbol(long ? 'long' : 'short', indexToken);
857
884
  const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage);
@@ -874,24 +901,23 @@ export class SLPAPI extends BaseAPI {
874
901
  });
875
902
  // Handle oracle initialization and coin processing
876
903
  let suiCoinObject;
877
- let feeObject;
878
904
  if (sponsoredTx) {
879
905
  suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
880
- feeObject = tx.splitCoins(suiCoinObject, [tx.pure.u64(relayerFee)]); // Sudo contract requires SUI as fee
881
906
  tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
882
907
  }
883
908
  else {
884
- feeObject = tx.splitCoins(tx.gas, [tx.pure.u64(relayerFee)]); // Sudo contract requires SUI as fee
885
909
  tx = await this.initOracleTxb([collateralToken, indexToken], tx);
886
910
  }
911
+ // Process coin splitting
912
+ const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
887
913
  tx.moveCall({
888
- target: `${this.consts.sudoCore.upgradedPackage}::market::decrease_position_v1_3`,
914
+ target: `${this.consts.sudoCore.upgradedPackage}::market::decrease_position_with_scard_v1`,
889
915
  typeArguments: [
890
916
  `${this.consts.sudoCore.package}::slp::SLP`,
891
917
  this.consts.coins[collateralToken].module,
892
918
  this.consts.coins[indexToken].module,
893
919
  `${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
894
- this.consts.coins.sui.module,
920
+ this.consts.coins[collateralToken].module,
895
921
  ],
896
922
  arguments: [
897
923
  tx.object(SUI_CLOCK_OBJECT_ID),
@@ -907,7 +933,6 @@ export class SLPAPI extends BaseAPI {
907
933
  tx.pure.u64(amount),
908
934
  tx.pure.u256(adjustCollateralPrice),
909
935
  tx.pure.u256(adjustPrice),
910
- tx.pure.bool(isTriggerOrder),
911
936
  sudoCard,
912
937
  ],
913
938
  });
@@ -958,13 +983,13 @@ export class SLPAPI extends BaseAPI {
958
983
  // Process coin splitting
959
984
  const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
960
985
  tx.moveCall({
961
- target: `${this.consts.sudoCore.upgradedPackage}::market::decrease_position_v1_3`,
986
+ target: `${this.consts.sudoCore.upgradedPackage}::market::decrease_position_with_scard_v1`,
962
987
  typeArguments: [
963
988
  `${this.consts.sudoCore.package}::slp::SLP`,
964
989
  this.consts.coins[collateralToken].module,
965
990
  this.consts.coins[indexToken].module,
966
991
  `${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
967
- this.consts.coins.sui.module,
992
+ this.consts.coins[collateralToken].module,
968
993
  ],
969
994
  arguments: [
970
995
  tx.object(SUI_CLOCK_OBJECT_ID),
@@ -980,7 +1005,6 @@ export class SLPAPI extends BaseAPI {
980
1005
  tx.pure.u64(amount),
981
1006
  tx.pure.u256(adjustCollateralPrice),
982
1007
  tx.pure.u256(adjustPrice),
983
- tx.pure.bool(isTriggerOrder),
984
1008
  sudoCard,
985
1009
  ],
986
1010
  });