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