zo-sdk 0.1.55 → 0.1.56

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 (35) hide show
  1. package/dist/abstract/BaseAPI.cjs +7 -0
  2. package/dist/abstract/BaseAPI.cjs.map +1 -1
  3. package/dist/abstract/BaseAPI.d.cts +4 -0
  4. package/dist/abstract/BaseAPI.d.cts.map +1 -1
  5. package/dist/abstract/BaseAPI.d.mts +4 -0
  6. package/dist/abstract/BaseAPI.d.mts.map +1 -1
  7. package/dist/abstract/BaseAPI.mjs +7 -0
  8. package/dist/abstract/BaseAPI.mjs.map +1 -1
  9. package/dist/consts/deployments-zlp-mainnet.json +1 -1
  10. package/dist/consts/deployments-zlp-testnet.json +19 -23
  11. package/dist/implementations/ZLPAPI.cjs +551 -0
  12. package/dist/implementations/ZLPAPI.cjs.map +1 -1
  13. package/dist/implementations/ZLPAPI.d.cts +49 -0
  14. package/dist/implementations/ZLPAPI.d.cts.map +1 -1
  15. package/dist/implementations/ZLPAPI.d.mts +49 -0
  16. package/dist/implementations/ZLPAPI.d.mts.map +1 -1
  17. package/dist/implementations/ZLPAPI.mjs +551 -0
  18. package/dist/implementations/ZLPAPI.mjs.map +1 -1
  19. package/dist/implementations/ZLPDataAPI.cjs +45 -5
  20. package/dist/implementations/ZLPDataAPI.cjs.map +1 -1
  21. package/dist/implementations/ZLPDataAPI.d.cts.map +1 -1
  22. package/dist/implementations/ZLPDataAPI.d.mts.map +1 -1
  23. package/dist/implementations/ZLPDataAPI.mjs +45 -5
  24. package/dist/implementations/ZLPDataAPI.mjs.map +1 -1
  25. package/dist/interfaces/base.d.cts +47 -1
  26. package/dist/interfaces/base.d.cts.map +1 -1
  27. package/dist/interfaces/base.d.mts +47 -1
  28. package/dist/interfaces/base.d.mts.map +1 -1
  29. package/package.json +1 -1
  30. package/src/abstract/BaseAPI.ts +8 -0
  31. package/src/consts/deployments-zlp-mainnet.json +1 -1
  32. package/src/consts/deployments-zlp-testnet.json +19 -23
  33. package/src/implementations/ZLPAPI.ts +924 -58
  34. package/src/implementations/ZLPDataAPI.ts +48 -5
  35. package/src/interfaces/base.ts +207 -1
@@ -543,6 +543,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
543
543
  const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
544
544
  const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage);
545
545
  const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
546
+ const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
546
547
  let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
547
548
  if (isLimitOrder) {
548
549
  allowTrade = isIocOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
@@ -582,6 +583,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
582
583
  tx.pure.u64(reserveAmount),
583
584
  tx.pure.u256(adjustCollateralPrice),
584
585
  tx.pure.u256(adjustPrice),
586
+ tx.pure.u256(indexPriceThreshold),
585
587
  ],
586
588
  });
587
589
  return tx;
@@ -589,6 +591,60 @@ class ZLPAPI extends abstract_1.BaseAPI {
589
591
  /**
590
592
  * Opens a new position in ZLP
591
593
  */
594
+ 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) {
595
+ let tx = new transactions_1.Transaction();
596
+ if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
597
+ tx = await this.addReferral(referralAddress, tx);
598
+ }
599
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
600
+ const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage);
601
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
602
+ const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
603
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
604
+ if (isLimitOrder) {
605
+ allowTrade = isIocOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
606
+ }
607
+ // Handle oracle initialization and coin processing
608
+ let suiCoinObject;
609
+ if (sponsoredTx) {
610
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
611
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
612
+ }
613
+ else {
614
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx);
615
+ }
616
+ // Process coin splitting
617
+ const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
618
+ tx.moveCall({
619
+ target: `${this.consts.zoCore.upgradedPackage}::market::open_position_v2`,
620
+ typeArguments: [
621
+ `${this.consts.zoCore.package}::zlp::ZLP`,
622
+ this.consts.coins[collateralToken].module,
623
+ this.consts.coins[indexToken].module,
624
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
625
+ this.consts.coins[collateralToken].module,
626
+ ],
627
+ arguments: [
628
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
629
+ tx.object(this.consts.zoCore.market),
630
+ tx.object(this.consts.zoCore.symbols[symbol].positionConfig),
631
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
632
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
633
+ depositObject,
634
+ feeObject,
635
+ tx.pure.u8(allowTrade),
636
+ tx.pure.u64(size),
637
+ tx.pure.u64(reserveAmount),
638
+ tx.pure.u256(adjustCollateralPrice),
639
+ tx.pure.u256(adjustPrice),
640
+ tx.pure.u256(indexPriceThreshold),
641
+ ],
642
+ });
643
+ return tx;
644
+ }
645
+ /**
646
+ * Opens a new position with Coin in ZLP
647
+ */
592
648
  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) {
593
649
  if (!tx) {
594
650
  tx = new transactions_1.Transaction();
@@ -642,6 +698,62 @@ class ZLPAPI extends abstract_1.BaseAPI {
642
698
  });
643
699
  return tx;
644
700
  }
701
+ /**
702
+ * Opens a new position with Coin in ZLP (V2)
703
+ */
704
+ 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) {
705
+ if (!tx) {
706
+ tx = new transactions_1.Transaction();
707
+ }
708
+ if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
709
+ tx = await this.addReferral(referralAddress, tx);
710
+ }
711
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
712
+ const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage);
713
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
714
+ const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
715
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
716
+ if (isLimitOrder) {
717
+ allowTrade = isIocOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
718
+ }
719
+ // Handle oracle initialization and coin processing
720
+ let suiCoinObject;
721
+ if (sponsoredTx) {
722
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
723
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
724
+ }
725
+ else {
726
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx);
727
+ }
728
+ // Process coin splitting
729
+ const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
730
+ tx.moveCall({
731
+ target: `${this.consts.zoCore.upgradedPackage}::market::open_position_v2`,
732
+ typeArguments: [
733
+ `${this.consts.zoCore.package}::zlp::ZLP`,
734
+ this.consts.coins[collateralToken].module,
735
+ this.consts.coins[indexToken].module,
736
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
737
+ this.consts.coins[collateralToken].module,
738
+ ],
739
+ arguments: [
740
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
741
+ tx.object(this.consts.zoCore.market),
742
+ tx.object(this.consts.zoCore.symbols[symbol].positionConfig),
743
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
744
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
745
+ coinObj,
746
+ feeObject,
747
+ tx.pure.u8(allowTrade),
748
+ tx.pure.u64(size),
749
+ tx.pure.u64(reserveAmount),
750
+ tx.pure.u256(adjustCollateralPrice),
751
+ tx.pure.u256(adjustPrice),
752
+ tx.pure.u256(indexPriceThreshold),
753
+ ],
754
+ });
755
+ return tx;
756
+ }
645
757
  /**
646
758
  * Decreases an existing position in ZLP
647
759
  */
@@ -653,6 +765,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
653
765
  const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
654
766
  const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage);
655
767
  const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
768
+ const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
656
769
  let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
657
770
  if (isTriggerOrder) {
658
771
  allowTrade = isIocOrder || !isTakeProfitOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
@@ -694,6 +807,63 @@ class ZLPAPI extends abstract_1.BaseAPI {
694
807
  tx.pure.u64(amount),
695
808
  tx.pure.u256(adjustCollateralPrice),
696
809
  tx.pure.u256(adjustPrice),
810
+ tx.pure.u256(indexPriceThreshold),
811
+ ],
812
+ });
813
+ return tx;
814
+ }
815
+ /**
816
+ * Decreases an existing position in ZLP
817
+ */
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, suiCoinObjectsForPythUpdate) {
819
+ if (!coinObjects) {
820
+ throw new Error(`${this.constructor.name}: coinObjects is required`);
821
+ }
822
+ let tx = new transactions_1.Transaction();
823
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
824
+ const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage);
825
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
826
+ const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
827
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
828
+ if (isTriggerOrder) {
829
+ allowTrade = isIocOrder || !isTakeProfitOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
830
+ }
831
+ else {
832
+ isTakeProfitOrder = true;
833
+ }
834
+ // Handle oracle initialization and coin processing
835
+ let suiCoinObject;
836
+ if (sponsoredTx) {
837
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
838
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
839
+ }
840
+ else {
841
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx);
842
+ }
843
+ // Process coin splitting
844
+ const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
845
+ tx.moveCall({
846
+ target: `${this.consts.zoCore.upgradedPackage}::market::decrease_position_v2`,
847
+ typeArguments: [
848
+ `${this.consts.zoCore.package}::zlp::ZLP`,
849
+ this.consts.coins[collateralToken].module,
850
+ this.consts.coins[indexToken].module,
851
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
852
+ this.consts.coins[collateralToken].module,
853
+ ],
854
+ arguments: [
855
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
856
+ tx.object(this.consts.zoCore.market),
857
+ tx.object(pcpId),
858
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
859
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
860
+ feeObject,
861
+ tx.pure.u8(allowTrade),
862
+ tx.pure.bool(isTakeProfitOrder),
863
+ tx.pure.u64(amount),
864
+ tx.pure.u256(adjustCollateralPrice),
865
+ tx.pure.u256(adjustPrice),
866
+ tx.pure.u256(indexPriceThreshold),
697
867
  ],
698
868
  });
699
869
  return tx;
@@ -754,6 +924,62 @@ class ZLPAPI extends abstract_1.BaseAPI {
754
924
  }
755
925
  return tx;
756
926
  }
927
+ async decreaseMultiPositionsV2(positions, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
928
+ if (!tx) {
929
+ tx = new transactions_1.Transaction();
930
+ }
931
+ // Handle oracle initialization and coin processing
932
+ let suiCoinObject;
933
+ if (sponsoredTx) {
934
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
935
+ tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx, true, suiCoinObject);
936
+ }
937
+ else {
938
+ tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx);
939
+ }
940
+ for (const position of positions) {
941
+ 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;
942
+ let innerIsTakeProfitOrder = isTakeProfitOrder;
943
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
944
+ const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage);
945
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
946
+ const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
947
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
948
+ if (isTriggerOrder) {
949
+ allowTrade = isIocOrder || !innerIsTakeProfitOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
950
+ }
951
+ else {
952
+ innerIsTakeProfitOrder = true;
953
+ }
954
+ // Process coin splitting
955
+ const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
956
+ tx.moveCall({
957
+ target: `${this.consts.zoCore.upgradedPackage}::market::decrease_position_v2`,
958
+ typeArguments: [
959
+ `${this.consts.zoCore.package}::zlp::ZLP`,
960
+ this.consts.coins[collateralToken].module,
961
+ this.consts.coins[indexToken].module,
962
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
963
+ this.consts.coins[collateralToken].module,
964
+ ],
965
+ arguments: [
966
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
967
+ tx.object(this.consts.zoCore.market),
968
+ tx.object(pcpId),
969
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
970
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
971
+ feeObject,
972
+ tx.pure.u8(allowTrade),
973
+ tx.pure.bool(innerIsTakeProfitOrder),
974
+ tx.pure.u64(amount),
975
+ tx.pure.u256(adjustCollateralPrice),
976
+ tx.pure.u256(adjustPrice),
977
+ tx.pure.u256(indexPriceThreshold),
978
+ ],
979
+ });
980
+ }
981
+ return tx;
982
+ }
757
983
  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) {
758
984
  let tx = new transactions_1.Transaction();
759
985
  if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
@@ -822,6 +1048,74 @@ class ZLPAPI extends abstract_1.BaseAPI {
822
1048
  .finalize();
823
1049
  return tx;
824
1050
  }
1051
+ 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) {
1052
+ let tx = new transactions_1.Transaction();
1053
+ if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
1054
+ tx = await this.addReferral(referralAddress, tx);
1055
+ }
1056
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
1057
+ const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage);
1058
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
1059
+ const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
1060
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
1061
+ if (isLimitOrder) {
1062
+ allowTrade = isIocOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
1063
+ }
1064
+ const kioskTx = new kiosk_1.KioskTransaction({
1065
+ transaction: tx,
1066
+ kioskClient,
1067
+ cap: kioskCap,
1068
+ });
1069
+ const [sudoCard, promise] = kioskTx.borrow({
1070
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
1071
+ itemId: scard,
1072
+ });
1073
+ // Handle oracle initialization and coin processing
1074
+ let suiCoinObject;
1075
+ if (sponsoredTx) {
1076
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1077
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1078
+ }
1079
+ else {
1080
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1081
+ }
1082
+ // Process coin splitting
1083
+ const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
1084
+ tx.moveCall({
1085
+ target: `${this.consts.zoCore.upgradedPackage}::market::open_position_with_scard_v2`,
1086
+ typeArguments: [
1087
+ `${this.consts.zoCore.package}::zlp::ZLP`,
1088
+ this.consts.coins[collateralToken].module,
1089
+ this.consts.coins[indexToken].module,
1090
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1091
+ this.consts.coins[collateralToken].module,
1092
+ ],
1093
+ arguments: [
1094
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
1095
+ tx.object(this.consts.zoCore.market),
1096
+ tx.object(this.consts.zoCore.symbols[symbol].positionConfig),
1097
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
1098
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
1099
+ depositObject,
1100
+ feeObject,
1101
+ tx.pure.u8(allowTrade),
1102
+ tx.pure.u64(size),
1103
+ tx.pure.u64(reserveAmount),
1104
+ tx.pure.u256(adjustCollateralPrice),
1105
+ tx.pure.u256(adjustPrice),
1106
+ tx.pure.u256(indexPriceThreshold),
1107
+ sudoCard,
1108
+ ],
1109
+ });
1110
+ kioskTx
1111
+ .return({
1112
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
1113
+ item: sudoCard,
1114
+ promise,
1115
+ })
1116
+ .finalize();
1117
+ return tx;
1118
+ }
825
1119
  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) {
826
1120
  if (!tx) {
827
1121
  tx = new transactions_1.Transaction();
@@ -892,6 +1186,76 @@ class ZLPAPI extends abstract_1.BaseAPI {
892
1186
  .finalize();
893
1187
  return tx;
894
1188
  }
1189
+ 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) {
1190
+ if (!tx) {
1191
+ tx = new transactions_1.Transaction();
1192
+ }
1193
+ if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
1194
+ tx = await this.addReferral(referralAddress, tx);
1195
+ }
1196
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
1197
+ const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage);
1198
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
1199
+ const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
1200
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
1201
+ if (isLimitOrder) {
1202
+ allowTrade = isIocOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
1203
+ }
1204
+ const kioskTx = new kiosk_1.KioskTransaction({
1205
+ transaction: tx,
1206
+ kioskClient,
1207
+ cap: kioskCap,
1208
+ });
1209
+ const [sudoCard, promise] = kioskTx.borrow({
1210
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
1211
+ itemId: scard,
1212
+ });
1213
+ // Handle oracle initialization and coin processing
1214
+ let suiCoinObject;
1215
+ if (sponsoredTx) {
1216
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1217
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1218
+ }
1219
+ else {
1220
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1221
+ }
1222
+ // Process coin splitting
1223
+ const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
1224
+ tx.moveCall({
1225
+ target: `${this.consts.zoCore.upgradedPackage}::market::open_position_with_scard_v2`,
1226
+ typeArguments: [
1227
+ `${this.consts.zoCore.package}::zlp::ZLP`,
1228
+ this.consts.coins[collateralToken].module,
1229
+ this.consts.coins[indexToken].module,
1230
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1231
+ this.consts.coins[collateralToken].module,
1232
+ ],
1233
+ arguments: [
1234
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
1235
+ tx.object(this.consts.zoCore.market),
1236
+ tx.object(this.consts.zoCore.symbols[symbol].positionConfig),
1237
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
1238
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
1239
+ coinObj,
1240
+ feeObject,
1241
+ tx.pure.u8(allowTrade),
1242
+ tx.pure.u64(size),
1243
+ tx.pure.u64(reserveAmount),
1244
+ tx.pure.u256(adjustCollateralPrice),
1245
+ tx.pure.u256(adjustPrice),
1246
+ tx.pure.u256(indexPriceThreshold),
1247
+ sudoCard,
1248
+ ],
1249
+ });
1250
+ kioskTx
1251
+ .return({
1252
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
1253
+ item: sudoCard,
1254
+ promise,
1255
+ })
1256
+ .finalize();
1257
+ return tx;
1258
+ }
895
1259
  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) {
896
1260
  if (!coinObjects) {
897
1261
  throw new Error(`${this.constructor.name}: coinObjects is required`);
@@ -962,6 +1326,76 @@ class ZLPAPI extends abstract_1.BaseAPI {
962
1326
  .finalize();
963
1327
  return tx;
964
1328
  }
1329
+ 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) {
1330
+ if (!coinObjects) {
1331
+ throw new Error(`${this.constructor.name}: coinObjects is required`);
1332
+ }
1333
+ let tx = new transactions_1.Transaction();
1334
+ const kioskTx = new kiosk_1.KioskTransaction({
1335
+ transaction: tx,
1336
+ kioskClient,
1337
+ cap: kioskCap,
1338
+ });
1339
+ const [sudoCard, promise] = kioskTx.borrow({
1340
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
1341
+ itemId: scard,
1342
+ });
1343
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
1344
+ const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage);
1345
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
1346
+ const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
1347
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
1348
+ if (isTriggerOrder) {
1349
+ allowTrade = isIocOrder || !isTakeProfitOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
1350
+ }
1351
+ else {
1352
+ isTakeProfitOrder = true;
1353
+ }
1354
+ // Handle oracle initialization and coin processing
1355
+ let suiCoinObject;
1356
+ if (sponsoredTx) {
1357
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1358
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
1359
+ }
1360
+ else {
1361
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx);
1362
+ }
1363
+ // Process coin splitting
1364
+ const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
1365
+ tx.moveCall({
1366
+ target: `${this.consts.zoCore.upgradedPackage}::market::decrease_position_with_scard_v2`,
1367
+ typeArguments: [
1368
+ `${this.consts.zoCore.package}::zlp::ZLP`,
1369
+ this.consts.coins[collateralToken].module,
1370
+ this.consts.coins[indexToken].module,
1371
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1372
+ this.consts.coins[collateralToken].module,
1373
+ ],
1374
+ arguments: [
1375
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
1376
+ tx.object(this.consts.zoCore.market),
1377
+ tx.object(pcpId),
1378
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
1379
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
1380
+ feeObject,
1381
+ tx.pure.u8(allowTrade),
1382
+ tx.pure.bool(isTakeProfitOrder),
1383
+ tx.pure.u64(amount),
1384
+ tx.pure.u256(adjustCollateralPrice),
1385
+ tx.pure.u256(adjustPrice),
1386
+ tx.pure.u256(indexPriceThreshold),
1387
+ sudoCard,
1388
+ ],
1389
+ });
1390
+ kioskTx
1391
+ .return({
1392
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
1393
+ item: sudoCard,
1394
+ promise,
1395
+ })
1396
+ .finalize();
1397
+ return tx;
1398
+ }
965
1399
  async decreaseMultiPositionsWithSCard(positions, kioskClient, kioskCap, scard, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
966
1400
  if (!tx) {
967
1401
  tx = new transactions_1.Transaction();
@@ -1035,6 +1469,79 @@ class ZLPAPI extends abstract_1.BaseAPI {
1035
1469
  .finalize();
1036
1470
  return tx;
1037
1471
  }
1472
+ async decreaseMultiPositionsWithSCardV2(positions, kioskClient, kioskCap, scard, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
1473
+ if (!tx) {
1474
+ tx = new transactions_1.Transaction();
1475
+ }
1476
+ // Handle oracle initialization and coin processing
1477
+ let suiCoinObject;
1478
+ if (sponsoredTx) {
1479
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
1480
+ tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx, true, suiCoinObject);
1481
+ }
1482
+ else {
1483
+ tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx);
1484
+ }
1485
+ const kioskTx = new kiosk_1.KioskTransaction({
1486
+ transaction: tx,
1487
+ kioskClient,
1488
+ cap: kioskCap,
1489
+ });
1490
+ const [sudoCard, promise] = kioskTx.borrow({
1491
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
1492
+ itemId: scard,
1493
+ });
1494
+ for (const position of positions) {
1495
+ 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;
1496
+ let innerIsTakeProfitOrder = isTakeProfitOrder;
1497
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
1498
+ const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage);
1499
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
1500
+ const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
1501
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
1502
+ if (isTriggerOrder) {
1503
+ allowTrade = isIocOrder || !innerIsTakeProfitOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
1504
+ }
1505
+ else {
1506
+ innerIsTakeProfitOrder = true;
1507
+ }
1508
+ // Process coin splitting
1509
+ const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
1510
+ tx.moveCall({
1511
+ target: `${this.consts.zoCore.upgradedPackage}::market::decrease_position_with_scard_v2`,
1512
+ typeArguments: [
1513
+ `${this.consts.zoCore.package}::zlp::ZLP`,
1514
+ this.consts.coins[collateralToken].module,
1515
+ this.consts.coins[indexToken].module,
1516
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1517
+ this.consts.coins[collateralToken].module,
1518
+ ],
1519
+ arguments: [
1520
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
1521
+ tx.object(this.consts.zoCore.market),
1522
+ tx.object(pcpId),
1523
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
1524
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
1525
+ feeObject,
1526
+ tx.pure.u8(allowTrade),
1527
+ tx.pure.bool(innerIsTakeProfitOrder),
1528
+ tx.pure.u64(amount),
1529
+ tx.pure.u256(adjustCollateralPrice),
1530
+ tx.pure.u256(adjustPrice),
1531
+ tx.pure.u256(indexPriceThreshold),
1532
+ sudoCard,
1533
+ ],
1534
+ });
1535
+ }
1536
+ kioskTx
1537
+ .return({
1538
+ itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
1539
+ item: sudoCard,
1540
+ promise,
1541
+ })
1542
+ .finalize();
1543
+ return tx;
1544
+ }
1038
1545
  /**
1039
1546
  * Pledges in position (ZLP-specific functionality)
1040
1547
  */
@@ -1104,12 +1611,20 @@ class ZLPAPI extends abstract_1.BaseAPI {
1104
1611
  functionName = isV11Order ? 'clear_open_position_order' : 'clear_open_position_order';
1105
1612
  break;
1106
1613
  }
1614
+ case 'OPEN_MARKET': {
1615
+ functionName = 'clear_open_market_order';
1616
+ break;
1617
+ }
1107
1618
  case 'DECREASE_POSITION': {
1108
1619
  functionName = isV11Order
1109
1620
  ? 'clear_decrease_position_order'
1110
1621
  : 'clear_decrease_position_order';
1111
1622
  break;
1112
1623
  }
1624
+ case 'DECREASE_MARKET': {
1625
+ functionName = 'clear_decrease_market_order';
1626
+ break;
1627
+ }
1113
1628
  default: {
1114
1629
  throw new Error('invalid order type');
1115
1630
  }
@@ -1139,12 +1654,20 @@ class ZLPAPI extends abstract_1.BaseAPI {
1139
1654
  functionName = isV11Order ? 'clear_open_position_order' : 'clear_open_position_order';
1140
1655
  break;
1141
1656
  }
1657
+ case 'OPEN_MARKET': {
1658
+ functionName = 'clear_open_market_order';
1659
+ break;
1660
+ }
1142
1661
  case 'DECREASE_POSITION': {
1143
1662
  functionName = isV11Order
1144
1663
  ? 'clear_decrease_position_order'
1145
1664
  : 'clear_decrease_position_order';
1146
1665
  break;
1147
1666
  }
1667
+ case 'DECREASE_MARKET': {
1668
+ functionName = 'clear_decrease_market_order';
1669
+ break;
1670
+ }
1148
1671
  default: {
1149
1672
  throw new Error('invalid order type');
1150
1673
  }
@@ -1189,6 +1712,20 @@ class ZLPAPI extends abstract_1.BaseAPI {
1189
1712
  arguments: [tx.object(this.consts.zoCore.market), tx.object(orderCapId)],
1190
1713
  });
1191
1714
  }
1715
+ clearOpenMarketOrder(orderCapId, collateralToken, indexToken, long, tx, isV11Order) {
1716
+ const funcName = 'clear_open_market_order';
1717
+ tx.moveCall({
1718
+ target: `${this.consts.zoCore.upgradedPackage}::market::${funcName}`,
1719
+ typeArguments: [
1720
+ `${this.consts.zoCore.package}::zlp::ZLP`,
1721
+ this.consts.coins[collateralToken].module,
1722
+ this.consts.coins[indexToken].module,
1723
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1724
+ this.consts.coins[collateralToken].module,
1725
+ ],
1726
+ arguments: [tx.object(this.consts.zoCore.market), tx.object(orderCapId)],
1727
+ });
1728
+ }
1192
1729
  clearDecreasePositionOrder(orderCapId, collateralToken, indexToken, long, tx, isV11Order) {
1193
1730
  const funcName = isV11Order ? 'clear_decrease_position_order' : 'clear_decrease_position_order';
1194
1731
  tx.moveCall({
@@ -1203,6 +1740,20 @@ class ZLPAPI extends abstract_1.BaseAPI {
1203
1740
  arguments: [tx.object(this.consts.zoCore.market), tx.object(orderCapId)],
1204
1741
  });
1205
1742
  }
1743
+ clearDecreaseMarketOrder(orderCapId, collateralToken, indexToken, long, tx, isV11Order) {
1744
+ const funcName = 'clear_decrease_market_order';
1745
+ tx.moveCall({
1746
+ target: `${this.consts.zoCore.upgradedPackage}::market::${funcName}`,
1747
+ typeArguments: [
1748
+ `${this.consts.zoCore.package}::zlp::ZLP`,
1749
+ this.consts.coins[collateralToken].module,
1750
+ this.consts.coins[indexToken].module,
1751
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1752
+ this.consts.coins[collateralToken].module,
1753
+ ],
1754
+ arguments: [tx.object(this.consts.zoCore.market), tx.object(orderCapId)],
1755
+ });
1756
+ }
1206
1757
  addReferral(referralAddress, tx) {
1207
1758
  if (!tx) {
1208
1759
  tx = new transactions_1.Transaction();