zo-sdk 0.1.61 → 0.1.63

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 (46) hide show
  1. package/dist/consts/deployments-slp-mainnet.json +1 -1
  2. package/dist/consts/deployments-usdz-mainnet.json +5 -5
  3. package/dist/implementations/SLPAPI.cjs +544 -0
  4. package/dist/implementations/SLPAPI.cjs.map +1 -1
  5. package/dist/implementations/SLPAPI.d.cts +49 -0
  6. package/dist/implementations/SLPAPI.d.cts.map +1 -1
  7. package/dist/implementations/SLPAPI.d.mts +49 -0
  8. package/dist/implementations/SLPAPI.d.mts.map +1 -1
  9. package/dist/implementations/SLPAPI.mjs +544 -0
  10. package/dist/implementations/SLPAPI.mjs.map +1 -1
  11. package/dist/implementations/SLPDataAPI.cjs +48 -9
  12. package/dist/implementations/SLPDataAPI.cjs.map +1 -1
  13. package/dist/implementations/SLPDataAPI.d.cts.map +1 -1
  14. package/dist/implementations/SLPDataAPI.d.mts.map +1 -1
  15. package/dist/implementations/SLPDataAPI.mjs +49 -10
  16. package/dist/implementations/SLPDataAPI.mjs.map +1 -1
  17. package/dist/implementations/USDZAPI.cjs +544 -0
  18. package/dist/implementations/USDZAPI.cjs.map +1 -1
  19. package/dist/implementations/USDZAPI.d.cts +49 -0
  20. package/dist/implementations/USDZAPI.d.cts.map +1 -1
  21. package/dist/implementations/USDZAPI.d.mts +49 -0
  22. package/dist/implementations/USDZAPI.d.mts.map +1 -1
  23. package/dist/implementations/USDZAPI.mjs +544 -0
  24. package/dist/implementations/USDZAPI.mjs.map +1 -1
  25. package/dist/implementations/USDZDataAPI.cjs +47 -7
  26. package/dist/implementations/USDZDataAPI.cjs.map +1 -1
  27. package/dist/implementations/USDZDataAPI.d.cts.map +1 -1
  28. package/dist/implementations/USDZDataAPI.d.mts.map +1 -1
  29. package/dist/implementations/USDZDataAPI.mjs +47 -7
  30. package/dist/implementations/USDZDataAPI.mjs.map +1 -1
  31. package/dist/implementations/ZLPAPI.cjs +2 -6
  32. package/dist/implementations/ZLPAPI.cjs.map +1 -1
  33. package/dist/implementations/ZLPAPI.d.cts +2 -2
  34. package/dist/implementations/ZLPAPI.d.cts.map +1 -1
  35. package/dist/implementations/ZLPAPI.d.mts +2 -2
  36. package/dist/implementations/ZLPAPI.d.mts.map +1 -1
  37. package/dist/implementations/ZLPAPI.mjs +2 -6
  38. package/dist/implementations/ZLPAPI.mjs.map +1 -1
  39. package/package.json +1 -1
  40. package/src/consts/deployments-slp-mainnet.json +1 -1
  41. package/src/consts/deployments-usdz-mainnet.json +5 -5
  42. package/src/implementations/SLPAPI.ts +884 -26
  43. package/src/implementations/SLPDataAPI.ts +52 -10
  44. package/src/implementations/USDZAPI.ts +913 -55
  45. package/src/implementations/USDZDataAPI.ts +50 -7
  46. package/src/implementations/ZLPAPI.ts +2 -7
@@ -129,6 +129,34 @@ export class USDZAPI extends BaseAPI {
129
129
  arguments: [tx.object(this.consts.zoCore.market), tx.object(orderCapId)],
130
130
  });
131
131
  }
132
+ clearOpenMarketOrder(orderCapId, collateralToken, indexToken, long, tx, _isV11Order) {
133
+ const funcName = 'clear_open_market_order';
134
+ tx.moveCall({
135
+ target: `${this.consts.zoCore.upgradedPackage}::market::${funcName}`,
136
+ typeArguments: [
137
+ `${this.consts.zoCore.package}::usdz::USDZ`,
138
+ this.consts.coins[collateralToken].module,
139
+ this.consts.coins[indexToken].module,
140
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
141
+ this.consts.coins[collateralToken].module,
142
+ ],
143
+ arguments: [tx.object(this.consts.zoCore.market), tx.object(orderCapId)],
144
+ });
145
+ }
146
+ clearDecreaseMarketOrder(orderCapId, collateralToken, indexToken, long, tx, _isV11Order) {
147
+ const funcName = 'clear_decrease_market_order';
148
+ tx.moveCall({
149
+ target: `${this.consts.zoCore.upgradedPackage}::market::${funcName}`,
150
+ typeArguments: [
151
+ `${this.consts.zoCore.package}::usdz::USDZ`,
152
+ this.consts.coins[collateralToken].module,
153
+ this.consts.coins[indexToken].module,
154
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
155
+ this.consts.coins[collateralToken].module,
156
+ ],
157
+ arguments: [tx.object(this.consts.zoCore.market), tx.object(orderCapId)],
158
+ });
159
+ }
132
160
  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) {
133
161
  let tx = new Transaction();
134
162
  if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
@@ -410,6 +438,286 @@ export class USDZAPI extends BaseAPI {
410
438
  .finalize();
411
439
  return tx;
412
440
  }
441
+ 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) {
442
+ let tx = new Transaction();
443
+ if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
444
+ tx = await this.addReferral(referralAddress, tx);
445
+ }
446
+ const symbol = joinSymbol(long ? 'long' : 'short', indexToken);
447
+ const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage);
448
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
449
+ const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
450
+ let allowTrade = ALLOW_TRADE_MUST_TRADE;
451
+ if (isLimitOrder) {
452
+ allowTrade = isIocOrder ? ALLOW_TRADE_NO_TRADE : ALLOW_TRADE_CAN_TRADE;
453
+ }
454
+ const kioskTx = new KioskTransaction({
455
+ transaction: tx,
456
+ kioskClient,
457
+ cap: kioskCap,
458
+ });
459
+ const [sudoCard, promise] = kioskTx.borrow({
460
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
461
+ itemId: scard,
462
+ });
463
+ // Handle oracle initialization and coin processing
464
+ let suiCoinObject;
465
+ if (sponsoredTx) {
466
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
467
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
468
+ }
469
+ else {
470
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx);
471
+ }
472
+ // Process coin splitting
473
+ const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
474
+ tx.moveCall({
475
+ target: `${this.consts.zoCore.upgradedPackage}::market::open_position_with_scard_v2`,
476
+ typeArguments: [
477
+ `${this.consts.zoCore.package}::usdz::USDZ`,
478
+ this.consts.coins[collateralToken].module,
479
+ this.consts.coins[indexToken].module,
480
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
481
+ this.consts.coins[collateralToken].module,
482
+ ],
483
+ arguments: [
484
+ tx.object(SUI_CLOCK_OBJECT_ID),
485
+ tx.object(this.consts.zoCore.market),
486
+ tx.object(this.consts.zoCore.symbols[symbol].positionConfig),
487
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
488
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
489
+ depositObject,
490
+ feeObject,
491
+ tx.pure.u8(allowTrade),
492
+ tx.pure.u64(size),
493
+ tx.pure.u64(reserveAmount),
494
+ tx.pure.u256(adjustCollateralPrice),
495
+ tx.pure.u256(adjustPrice),
496
+ tx.pure.u256(indexPriceThreshold),
497
+ sudoCard,
498
+ ],
499
+ });
500
+ kioskTx
501
+ .return({
502
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
503
+ item: sudoCard,
504
+ promise,
505
+ })
506
+ .finalize();
507
+ return tx;
508
+ }
509
+ // S Card operations
510
+ 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) {
511
+ if (!tx) {
512
+ tx = new Transaction();
513
+ }
514
+ if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
515
+ tx = await this.addReferral(referralAddress, tx);
516
+ }
517
+ const symbol = joinSymbol(long ? 'long' : 'short', indexToken);
518
+ const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage);
519
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
520
+ const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
521
+ let allowTrade = ALLOW_TRADE_MUST_TRADE;
522
+ if (isLimitOrder) {
523
+ allowTrade = isIocOrder ? ALLOW_TRADE_NO_TRADE : ALLOW_TRADE_CAN_TRADE;
524
+ }
525
+ const kioskTx = new KioskTransaction({
526
+ transaction: tx,
527
+ kioskClient,
528
+ cap: kioskCap,
529
+ });
530
+ const [sudoCard, promise] = kioskTx.borrow({
531
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
532
+ itemId: scard,
533
+ });
534
+ // Handle oracle initialization and coin processing
535
+ let suiCoinObject;
536
+ if (sponsoredTx) {
537
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
538
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
539
+ }
540
+ else {
541
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx);
542
+ }
543
+ // Process coin splitting
544
+ const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
545
+ tx.moveCall({
546
+ target: `${this.consts.zoCore.upgradedPackage}::market::open_position_with_scard_v2`,
547
+ typeArguments: [
548
+ `${this.consts.zoCore.package}::usdz::USDZ`,
549
+ this.consts.coins[collateralToken].module,
550
+ this.consts.coins[indexToken].module,
551
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
552
+ this.consts.coins[collateralToken].module,
553
+ ],
554
+ arguments: [
555
+ tx.object(SUI_CLOCK_OBJECT_ID),
556
+ tx.object(this.consts.zoCore.market),
557
+ tx.object(this.consts.zoCore.symbols[symbol].positionConfig),
558
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
559
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
560
+ coinObj,
561
+ feeObject,
562
+ tx.pure.u8(allowTrade),
563
+ tx.pure.u64(size),
564
+ tx.pure.u64(reserveAmount),
565
+ tx.pure.u256(adjustCollateralPrice),
566
+ tx.pure.u256(adjustPrice),
567
+ tx.pure.u256(indexPriceThreshold),
568
+ sudoCard,
569
+ ],
570
+ });
571
+ kioskTx
572
+ .return({
573
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
574
+ item: sudoCard,
575
+ promise,
576
+ })
577
+ .finalize();
578
+ return tx;
579
+ }
580
+ 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) {
581
+ if (!coinObjects) {
582
+ throw new Error(`${this.constructor.name}: coinObjects is required`);
583
+ }
584
+ let tx = new Transaction();
585
+ const kioskTx = new KioskTransaction({
586
+ transaction: tx,
587
+ kioskClient,
588
+ cap: kioskCap,
589
+ });
590
+ const [sudoCard, promise] = kioskTx.borrow({
591
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
592
+ itemId: scard,
593
+ });
594
+ const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage);
595
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
596
+ const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
597
+ let allowTrade = ALLOW_TRADE_MUST_TRADE;
598
+ if (isTriggerOrder) {
599
+ allowTrade = isIocOrder || !isTakeProfitOrder ? ALLOW_TRADE_NO_TRADE : ALLOW_TRADE_CAN_TRADE;
600
+ }
601
+ else {
602
+ isTakeProfitOrder = true;
603
+ }
604
+ // Handle oracle initialization and coin processing
605
+ let suiCoinObject;
606
+ if (sponsoredTx) {
607
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
608
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
609
+ }
610
+ else {
611
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx);
612
+ }
613
+ // Process coin splitting
614
+ const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
615
+ tx.moveCall({
616
+ target: `${this.consts.zoCore.upgradedPackage}::market::decrease_position_with_scard_v2`,
617
+ typeArguments: [
618
+ `${this.consts.zoCore.package}::usdz::USDZ`,
619
+ this.consts.coins[collateralToken].module,
620
+ this.consts.coins[indexToken].module,
621
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
622
+ this.consts.coins[collateralToken].module,
623
+ ],
624
+ arguments: [
625
+ tx.object(SUI_CLOCK_OBJECT_ID),
626
+ tx.object(this.consts.zoCore.market),
627
+ tx.object(pcpId),
628
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
629
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
630
+ feeObject,
631
+ tx.pure.u8(allowTrade),
632
+ tx.pure.bool(isTakeProfitOrder),
633
+ tx.pure.u64(amount),
634
+ tx.pure.u256(adjustCollateralPrice),
635
+ tx.pure.u256(adjustPrice),
636
+ tx.pure.u256(indexPriceThreshold),
637
+ sudoCard,
638
+ ],
639
+ });
640
+ kioskTx
641
+ .return({
642
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
643
+ item: sudoCard,
644
+ promise,
645
+ })
646
+ .finalize();
647
+ return tx;
648
+ }
649
+ async decreaseMultiPositionsWithSCardV2(positions, kioskClient, kioskCap, scard, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
650
+ if (!tx) {
651
+ tx = new Transaction();
652
+ }
653
+ // Handle oracle initialization and coin processing
654
+ let suiCoinObject;
655
+ if (sponsoredTx) {
656
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
657
+ tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx, true, suiCoinObject);
658
+ }
659
+ else {
660
+ tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx);
661
+ }
662
+ const kioskTx = new KioskTransaction({
663
+ transaction: tx,
664
+ kioskClient,
665
+ cap: kioskCap,
666
+ });
667
+ const [sudoCard, promise] = kioskTx.borrow({
668
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
669
+ itemId: scard,
670
+ });
671
+ for (const position of positions) {
672
+ const { pcpId, collateralToken, indexToken, amount, long, indexPrice, collateralPrice, isTriggerOrder = false, isTakeProfitOrder = true, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), coinObjects = [], } = position;
673
+ let innerIsTakeProfitOrder = isTakeProfitOrder;
674
+ const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage);
675
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
676
+ const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
677
+ let allowTrade = ALLOW_TRADE_MUST_TRADE;
678
+ if (isTriggerOrder) {
679
+ allowTrade = isIocOrder || !innerIsTakeProfitOrder ? ALLOW_TRADE_NO_TRADE : ALLOW_TRADE_CAN_TRADE;
680
+ }
681
+ else {
682
+ innerIsTakeProfitOrder = true;
683
+ }
684
+ // Process coin splitting
685
+ const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
686
+ tx.moveCall({
687
+ target: `${this.consts.zoCore.upgradedPackage}::market::decrease_position_with_scard_v2`,
688
+ typeArguments: [
689
+ `${this.consts.zoCore.package}::usdz::USDZ`,
690
+ this.consts.coins[collateralToken].module,
691
+ this.consts.coins[indexToken].module,
692
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
693
+ this.consts.coins[collateralToken].module,
694
+ ],
695
+ arguments: [
696
+ tx.object(SUI_CLOCK_OBJECT_ID),
697
+ tx.object(this.consts.zoCore.market),
698
+ tx.object(pcpId),
699
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
700
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
701
+ feeObject,
702
+ tx.pure.u8(allowTrade),
703
+ tx.pure.bool(innerIsTakeProfitOrder),
704
+ tx.pure.u64(amount),
705
+ tx.pure.u256(adjustCollateralPrice),
706
+ tx.pure.u256(adjustPrice),
707
+ tx.pure.u256(indexPriceThreshold),
708
+ sudoCard,
709
+ ],
710
+ });
711
+ }
712
+ kioskTx
713
+ .return({
714
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
715
+ item: sudoCard,
716
+ promise,
717
+ })
718
+ .finalize();
719
+ return tx;
720
+ }
413
721
  /**
414
722
  * Deposits collateral into USDZ vault
415
723
  */
@@ -822,6 +1130,60 @@ export class USDZAPI extends BaseAPI {
822
1130
  });
823
1131
  return tx;
824
1132
  }
1133
+ /**
1134
+ * Opens a new position in USDZ (V2)
1135
+ */
1136
+ 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) {
1137
+ let tx = new Transaction();
1138
+ if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
1139
+ tx = await this.addReferral(referralAddress, tx);
1140
+ }
1141
+ const symbol = joinSymbol(long ? 'long' : 'short', indexToken);
1142
+ const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage);
1143
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
1144
+ const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
1145
+ let allowTrade = ALLOW_TRADE_MUST_TRADE;
1146
+ if (isLimitOrder) {
1147
+ allowTrade = isIocOrder ? ALLOW_TRADE_NO_TRADE : ALLOW_TRADE_CAN_TRADE;
1148
+ }
1149
+ // Handle oracle initialization and coin processing
1150
+ let suiCoinObject;
1151
+ if (sponsoredTx) {
1152
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1153
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1154
+ }
1155
+ else {
1156
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1157
+ }
1158
+ // Process coin splitting
1159
+ const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
1160
+ tx.moveCall({
1161
+ target: `${this.consts.zoCore.upgradedPackage}::market::open_position_v2`,
1162
+ typeArguments: [
1163
+ `${this.consts.zoCore.package}::usdz::USDZ`,
1164
+ this.consts.coins[collateralToken].module,
1165
+ this.consts.coins[indexToken].module,
1166
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1167
+ this.consts.coins[collateralToken].module,
1168
+ ],
1169
+ arguments: [
1170
+ tx.object(SUI_CLOCK_OBJECT_ID),
1171
+ tx.object(this.consts.zoCore.market),
1172
+ tx.object(this.consts.zoCore.symbols[symbol].positionConfig),
1173
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
1174
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
1175
+ depositObject,
1176
+ feeObject,
1177
+ tx.pure.u8(allowTrade),
1178
+ tx.pure.u64(size),
1179
+ tx.pure.u64(reserveAmount),
1180
+ tx.pure.u256(adjustCollateralPrice),
1181
+ tx.pure.u256(adjustPrice),
1182
+ tx.pure.u256(indexPriceThreshold),
1183
+ ],
1184
+ });
1185
+ return tx;
1186
+ }
825
1187
  /**
826
1188
  * Opens a new position in USDZ
827
1189
  */
@@ -878,6 +1240,62 @@ export class USDZAPI extends BaseAPI {
878
1240
  });
879
1241
  return tx;
880
1242
  }
1243
+ /**
1244
+ * Opens a new position with Coin in USDZ (V2)
1245
+ */
1246
+ 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) {
1247
+ if (!tx) {
1248
+ tx = new Transaction();
1249
+ }
1250
+ if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
1251
+ tx = await this.addReferral(referralAddress, tx);
1252
+ }
1253
+ const symbol = joinSymbol(long ? 'long' : 'short', indexToken);
1254
+ const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage);
1255
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
1256
+ const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
1257
+ let allowTrade = ALLOW_TRADE_MUST_TRADE;
1258
+ if (isLimitOrder) {
1259
+ allowTrade = isIocOrder ? ALLOW_TRADE_NO_TRADE : ALLOW_TRADE_CAN_TRADE;
1260
+ }
1261
+ // Handle oracle initialization and coin processing
1262
+ let suiCoinObject;
1263
+ if (sponsoredTx) {
1264
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1265
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1266
+ }
1267
+ else {
1268
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1269
+ }
1270
+ // Process coin splitting
1271
+ const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
1272
+ tx.moveCall({
1273
+ target: `${this.consts.zoCore.upgradedPackage}::market::open_position_v2`,
1274
+ typeArguments: [
1275
+ `${this.consts.zoCore.package}::usdz::USDZ`,
1276
+ this.consts.coins[collateralToken].module,
1277
+ this.consts.coins[indexToken].module,
1278
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1279
+ this.consts.coins[collateralToken].module,
1280
+ ],
1281
+ arguments: [
1282
+ tx.object(SUI_CLOCK_OBJECT_ID),
1283
+ tx.object(this.consts.zoCore.market),
1284
+ tx.object(this.consts.zoCore.symbols[symbol].positionConfig),
1285
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
1286
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
1287
+ coinObj,
1288
+ feeObject,
1289
+ tx.pure.u8(allowTrade),
1290
+ tx.pure.u64(size),
1291
+ tx.pure.u64(reserveAmount),
1292
+ tx.pure.u256(adjustCollateralPrice),
1293
+ tx.pure.u256(adjustPrice),
1294
+ tx.pure.u256(indexPriceThreshold),
1295
+ ],
1296
+ });
1297
+ return tx;
1298
+ }
881
1299
  /**
882
1300
  * Decreases an existing position in USDZ
883
1301
  */
@@ -934,6 +1352,61 @@ export class USDZAPI extends BaseAPI {
934
1352
  });
935
1353
  return tx;
936
1354
  }
1355
+ /**
1356
+ * Decreases an existing position in USDZ (V2)
1357
+ */
1358
+ 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) {
1359
+ if (!coinObjects) {
1360
+ throw new Error(`${this.constructor.name}: coinObjects is required`);
1361
+ }
1362
+ let tx = new Transaction();
1363
+ const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage);
1364
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
1365
+ const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
1366
+ let allowTrade = ALLOW_TRADE_MUST_TRADE;
1367
+ if (isTriggerOrder) {
1368
+ allowTrade = isIocOrder || !isTakeProfitOrder ? ALLOW_TRADE_NO_TRADE : ALLOW_TRADE_CAN_TRADE;
1369
+ }
1370
+ else {
1371
+ isTakeProfitOrder = true;
1372
+ }
1373
+ // Handle oracle initialization and coin processing
1374
+ let suiCoinObject;
1375
+ if (sponsoredTx) {
1376
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1377
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1378
+ }
1379
+ else {
1380
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1381
+ }
1382
+ // Process coin splitting
1383
+ const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
1384
+ tx.moveCall({
1385
+ target: `${this.consts.zoCore.upgradedPackage}::market::decrease_position_v2`,
1386
+ typeArguments: [
1387
+ `${this.consts.zoCore.package}::usdz::USDZ`,
1388
+ this.consts.coins[collateralToken].module,
1389
+ this.consts.coins[indexToken].module,
1390
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1391
+ this.consts.coins[collateralToken].module,
1392
+ ],
1393
+ arguments: [
1394
+ tx.object(SUI_CLOCK_OBJECT_ID),
1395
+ tx.object(this.consts.zoCore.market),
1396
+ tx.object(pcpId),
1397
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
1398
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
1399
+ feeObject,
1400
+ tx.pure.u8(allowTrade),
1401
+ tx.pure.bool(isTakeProfitOrder),
1402
+ tx.pure.u64(amount),
1403
+ tx.pure.u256(adjustCollateralPrice),
1404
+ tx.pure.u256(adjustPrice),
1405
+ tx.pure.u256(indexPriceThreshold),
1406
+ ],
1407
+ });
1408
+ return tx;
1409
+ }
937
1410
  async decreaseMultiPositions(positions, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
938
1411
  if (!tx) {
939
1412
  tx = new Transaction();
@@ -990,6 +1463,61 @@ export class USDZAPI extends BaseAPI {
990
1463
  }
991
1464
  return tx;
992
1465
  }
1466
+ async decreaseMultiPositionsV2(positions, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
1467
+ if (!tx) {
1468
+ tx = new Transaction();
1469
+ }
1470
+ // Handle oracle initialization and coin processing
1471
+ let suiCoinObject;
1472
+ if (sponsoredTx) {
1473
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1474
+ tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx, true, suiCoinObject);
1475
+ }
1476
+ else {
1477
+ tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx);
1478
+ }
1479
+ for (const position of positions) {
1480
+ 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;
1481
+ let innerIsTakeProfitOrder = isTakeProfitOrder;
1482
+ const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage);
1483
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
1484
+ const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
1485
+ let allowTrade = ALLOW_TRADE_MUST_TRADE;
1486
+ if (isTriggerOrder) {
1487
+ allowTrade = isIocOrder || !innerIsTakeProfitOrder ? ALLOW_TRADE_NO_TRADE : ALLOW_TRADE_CAN_TRADE;
1488
+ }
1489
+ else {
1490
+ innerIsTakeProfitOrder = true;
1491
+ }
1492
+ // Process coin splitting
1493
+ const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
1494
+ tx.moveCall({
1495
+ target: `${this.consts.zoCore.upgradedPackage}::market::decrease_position_v2`,
1496
+ typeArguments: [
1497
+ `${this.consts.zoCore.package}::usdz::USDZ`,
1498
+ this.consts.coins[collateralToken].module,
1499
+ this.consts.coins[indexToken].module,
1500
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1501
+ this.consts.coins[collateralToken].module,
1502
+ ],
1503
+ arguments: [
1504
+ tx.object(SUI_CLOCK_OBJECT_ID),
1505
+ tx.object(this.consts.zoCore.market),
1506
+ tx.object(pcpId),
1507
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
1508
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
1509
+ feeObject,
1510
+ tx.pure.u8(allowTrade),
1511
+ tx.pure.bool(innerIsTakeProfitOrder),
1512
+ tx.pure.u64(amount),
1513
+ tx.pure.u256(adjustCollateralPrice),
1514
+ tx.pure.u256(adjustPrice),
1515
+ tx.pure.u256(indexPriceThreshold),
1516
+ ],
1517
+ });
1518
+ }
1519
+ return tx;
1520
+ }
993
1521
  /**
994
1522
  * Pledges in position (USDZ-specific functionality)
995
1523
  */
@@ -1059,12 +1587,20 @@ export class USDZAPI extends BaseAPI {
1059
1587
  functionName = isV11Order ? 'clear_open_position_order' : 'clear_open_position_order';
1060
1588
  break;
1061
1589
  }
1590
+ case 'OPEN_MARKET': {
1591
+ functionName = 'clear_open_market_order';
1592
+ break;
1593
+ }
1062
1594
  case 'DECREASE_POSITION': {
1063
1595
  functionName = isV11Order
1064
1596
  ? 'clear_decrease_position_order'
1065
1597
  : 'clear_decrease_position_order';
1066
1598
  break;
1067
1599
  }
1600
+ case 'DECREASE_MARKET': {
1601
+ functionName = 'clear_decrease_market_order';
1602
+ break;
1603
+ }
1068
1604
  default: {
1069
1605
  throw new Error('invalid order type');
1070
1606
  }
@@ -1094,12 +1630,20 @@ export class USDZAPI extends BaseAPI {
1094
1630
  functionName = isV11Order ? 'clear_open_position_order' : 'clear_open_position_order';
1095
1631
  break;
1096
1632
  }
1633
+ case 'OPEN_MARKET': {
1634
+ functionName = 'clear_open_market_order';
1635
+ break;
1636
+ }
1097
1637
  case 'DECREASE_POSITION': {
1098
1638
  functionName = isV11Order
1099
1639
  ? 'clear_decrease_position_order'
1100
1640
  : 'clear_decrease_position_order';
1101
1641
  break;
1102
1642
  }
1643
+ case 'DECREASE_MARKET': {
1644
+ functionName = 'clear_decrease_market_order';
1645
+ break;
1646
+ }
1103
1647
  default: {
1104
1648
  throw new Error('invalid order type');
1105
1649
  }