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