zo-sdk 0.1.49 → 0.1.51
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-shared-mainnet.json +1 -1
- package/dist/consts/deployments-usdz-mainnet.json +1 -1
- package/dist/implementations/SLPAPI.cjs +129 -3
- package/dist/implementations/SLPAPI.cjs.map +1 -1
- package/dist/implementations/SLPAPI.d.cts +5 -0
- package/dist/implementations/SLPAPI.d.cts.map +1 -1
- package/dist/implementations/SLPAPI.d.mts +5 -0
- package/dist/implementations/SLPAPI.d.mts.map +1 -1
- package/dist/implementations/SLPAPI.mjs +129 -3
- package/dist/implementations/SLPAPI.mjs.map +1 -1
- package/dist/implementations/USDZAPI.cjs +130 -4
- package/dist/implementations/USDZAPI.cjs.map +1 -1
- package/dist/implementations/USDZAPI.d.cts +5 -0
- package/dist/implementations/USDZAPI.d.cts.map +1 -1
- package/dist/implementations/USDZAPI.d.mts +5 -0
- package/dist/implementations/USDZAPI.d.mts.map +1 -1
- package/dist/implementations/USDZAPI.mjs +130 -4
- package/dist/implementations/USDZAPI.mjs.map +1 -1
- package/dist/implementations/ZLPAPI.cjs +130 -4
- package/dist/implementations/ZLPAPI.cjs.map +1 -1
- package/dist/implementations/ZLPAPI.d.cts +5 -0
- package/dist/implementations/ZLPAPI.d.cts.map +1 -1
- package/dist/implementations/ZLPAPI.d.mts +5 -0
- package/dist/implementations/ZLPAPI.d.mts.map +1 -1
- package/dist/implementations/ZLPAPI.mjs +130 -4
- package/dist/implementations/ZLPAPI.mjs.map +1 -1
- package/dist/interfaces/base.d.cts +3 -1
- package/dist/interfaces/base.d.cts.map +1 -1
- package/dist/interfaces/base.d.mts +3 -1
- package/dist/interfaces/base.d.mts.map +1 -1
- package/package.json +2 -2
- package/src/consts/deployments-shared-mainnet.json +1 -1
- package/src/consts/deployments-usdz-mainnet.json +1 -1
- package/src/implementations/SLPAPI.ts +188 -4
- package/src/implementations/USDZAPI.ts +186 -4
- package/src/implementations/ZLPAPI.ts +188 -4
- package/src/interfaces/base.ts +48 -1
- package/src/consts/deployments-mainnet.json +0 -644
|
@@ -617,7 +617,7 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
|
|
|
617
617
|
})()
|
|
618
618
|
unstakeAmount -= withdrawAmount
|
|
619
619
|
tx.moveCall({
|
|
620
|
-
target: `${this.sharedConfig.zoStaking.
|
|
620
|
+
target: `${this.sharedConfig.zoStaking.upgradedPackage}::pool::withdraw`,
|
|
621
621
|
typeArguments: [
|
|
622
622
|
`${this.consts.sudoCore.package}::slp::SLP`,
|
|
623
623
|
`${this.consts.sudoCore.package}::slp::SLP`,
|
|
@@ -631,7 +631,7 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
|
|
|
631
631
|
})
|
|
632
632
|
if (credential.amount === BigInt(0)) {
|
|
633
633
|
tx.moveCall({
|
|
634
|
-
target: `${this.sharedConfig.zoStaking.
|
|
634
|
+
target: `${this.sharedConfig.zoStaking.upgradedPackage}::pool::clear_empty_credential`,
|
|
635
635
|
typeArguments: [
|
|
636
636
|
`${this.consts.sudoCore.package}::slp::SLP`,
|
|
637
637
|
`${this.consts.sudoCore.package}::slp::SLP`,
|
|
@@ -765,7 +765,6 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
|
|
|
765
765
|
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
766
766
|
tx = await this.addReferral(referralAddress, tx)
|
|
767
767
|
}
|
|
768
|
-
|
|
769
768
|
const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
|
|
770
769
|
const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage)
|
|
771
770
|
const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage)
|
|
@@ -826,6 +825,88 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
|
|
|
826
825
|
return tx
|
|
827
826
|
}
|
|
828
827
|
|
|
828
|
+
/**
|
|
829
|
+
* Opens a position using Sudo SDK approach
|
|
830
|
+
*/
|
|
831
|
+
public async openPositionWithCoin(
|
|
832
|
+
collateralToken: string,
|
|
833
|
+
indexToken: string,
|
|
834
|
+
size: bigint,
|
|
835
|
+
coinObj: TransactionObjectArgument,
|
|
836
|
+
long: boolean,
|
|
837
|
+
reserveAmount: bigint,
|
|
838
|
+
indexPrice: number,
|
|
839
|
+
collateralPrice: number,
|
|
840
|
+
isLimitOrder = false,
|
|
841
|
+
isIocOrder = false,
|
|
842
|
+
pricesSlippage = 0.003,
|
|
843
|
+
collateralSlippage = 0.5,
|
|
844
|
+
relayerFee = BigInt(0.5),
|
|
845
|
+
referralAddress?: string,
|
|
846
|
+
sender?: string,
|
|
847
|
+
tx?: Transaction,
|
|
848
|
+
sponsoredTx?: boolean,
|
|
849
|
+
suiCoinObjectsForPythUpdate?: string[],
|
|
850
|
+
): Promise<Transaction> {
|
|
851
|
+
if (!tx) {
|
|
852
|
+
tx = new Transaction()
|
|
853
|
+
}
|
|
854
|
+
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
855
|
+
tx = await this.addReferral(referralAddress, tx)
|
|
856
|
+
}
|
|
857
|
+
const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
|
|
858
|
+
const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage)
|
|
859
|
+
const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage)
|
|
860
|
+
|
|
861
|
+
let allowTrade = ALLOW_TRADE_MUST_TRADE
|
|
862
|
+
if (isLimitOrder) {
|
|
863
|
+
allowTrade = isIocOrder ? ALLOW_TRADE_NO_TRADE : ALLOW_TRADE_CAN_TRADE
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
// Handle oracle initialization and coin processing
|
|
867
|
+
let suiCoinObject
|
|
868
|
+
if (sponsoredTx) {
|
|
869
|
+
suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
|
|
870
|
+
tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject)
|
|
871
|
+
}
|
|
872
|
+
else {
|
|
873
|
+
tx = await this.initOracleTxb([collateralToken, indexToken], tx)
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
// Process coin splitting
|
|
877
|
+
const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)])
|
|
878
|
+
|
|
879
|
+
tx.moveCall({
|
|
880
|
+
target: `${this.consts.sudoCore.upgradedPackage}::market::open_position_v2_1`,
|
|
881
|
+
typeArguments: [
|
|
882
|
+
`${this.consts.sudoCore.package}::slp::SLP`,
|
|
883
|
+
this.consts.coins[collateralToken].module,
|
|
884
|
+
this.consts.coins[indexToken].module,
|
|
885
|
+
`${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
|
|
886
|
+
this.consts.coins[collateralToken].module,
|
|
887
|
+
],
|
|
888
|
+
arguments: [
|
|
889
|
+
tx.object(SUI_CLOCK_OBJECT_ID),
|
|
890
|
+
tx.object(this.consts.sudoCore.market),
|
|
891
|
+
tx.object(
|
|
892
|
+
this.consts.sudoCore.vaults[collateralToken].reservingFeeModel,
|
|
893
|
+
),
|
|
894
|
+
tx.object(this.consts.sudoCore.symbols[symbol].fundingFeeModel),
|
|
895
|
+
tx.object(this.consts.sudoCore.symbols[symbol].positionConfig),
|
|
896
|
+
tx.object(this.consts.pythFeeder.feeder[collateralToken]),
|
|
897
|
+
tx.object(this.consts.pythFeeder.feeder[indexToken]),
|
|
898
|
+
coinObj,
|
|
899
|
+
feeObject,
|
|
900
|
+
tx.pure.u8(allowTrade),
|
|
901
|
+
tx.pure.u64(size),
|
|
902
|
+
tx.pure.u64(reserveAmount),
|
|
903
|
+
tx.pure.u256(adjustCollateralPrice),
|
|
904
|
+
tx.pure.u256(adjustPrice),
|
|
905
|
+
],
|
|
906
|
+
})
|
|
907
|
+
return tx
|
|
908
|
+
}
|
|
909
|
+
|
|
829
910
|
/**
|
|
830
911
|
* Decreases an existing position in SLP using Sudo SDK approach
|
|
831
912
|
*/
|
|
@@ -1387,6 +1468,109 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
|
|
|
1387
1468
|
return tx
|
|
1388
1469
|
}
|
|
1389
1470
|
|
|
1471
|
+
public async openPositionWithCoinAndSCard(
|
|
1472
|
+
collateralToken: string,
|
|
1473
|
+
indexToken: string,
|
|
1474
|
+
size: bigint,
|
|
1475
|
+
coinObj: TransactionObjectArgument,
|
|
1476
|
+
long: boolean,
|
|
1477
|
+
reserveAmount: bigint,
|
|
1478
|
+
indexPrice: number,
|
|
1479
|
+
collateralPrice: number,
|
|
1480
|
+
kioskClient: KioskClient,
|
|
1481
|
+
kioskCap: KioskOwnerCap,
|
|
1482
|
+
scard: string,
|
|
1483
|
+
isLimitOrder = false,
|
|
1484
|
+
isIocOrder = false,
|
|
1485
|
+
pricesSlippage = 0.003,
|
|
1486
|
+
collateralSlippage = 0.5,
|
|
1487
|
+
relayerFee = BigInt(0.5),
|
|
1488
|
+
referralAddress?: string,
|
|
1489
|
+
sender?: string,
|
|
1490
|
+
tx?: Transaction,
|
|
1491
|
+
sponsoredTx?: boolean,
|
|
1492
|
+
suiCoinObjectsForPythUpdate?: string[],
|
|
1493
|
+
): Promise<Transaction> {
|
|
1494
|
+
if (!tx) {
|
|
1495
|
+
tx = new Transaction()
|
|
1496
|
+
}
|
|
1497
|
+
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
1498
|
+
tx = await this.addReferral(referralAddress, tx)
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1501
|
+
const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
|
|
1502
|
+
const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage || 0.003)
|
|
1503
|
+
const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage || 0.5)
|
|
1504
|
+
|
|
1505
|
+
let allowTrade = ALLOW_TRADE_MUST_TRADE
|
|
1506
|
+
if (isLimitOrder) {
|
|
1507
|
+
allowTrade = isIocOrder ? ALLOW_TRADE_NO_TRADE : ALLOW_TRADE_CAN_TRADE
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1510
|
+
const kioskTx = new KioskTransaction({
|
|
1511
|
+
transaction: tx,
|
|
1512
|
+
kioskClient,
|
|
1513
|
+
cap: kioskCap,
|
|
1514
|
+
})
|
|
1515
|
+
|
|
1516
|
+
const [sudoCard, promise] = kioskTx.borrow({
|
|
1517
|
+
itemType: `${this.consts.sudoNft.package}::card::SudoCard`,
|
|
1518
|
+
itemId: scard,
|
|
1519
|
+
})
|
|
1520
|
+
|
|
1521
|
+
// Handle oracle initialization and coin processing
|
|
1522
|
+
let suiCoinObject
|
|
1523
|
+
if (sponsoredTx) {
|
|
1524
|
+
suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
|
|
1525
|
+
tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject)
|
|
1526
|
+
}
|
|
1527
|
+
else {
|
|
1528
|
+
tx = await this.initOracleTxb([collateralToken, indexToken], tx)
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1531
|
+
// Process coin splitting
|
|
1532
|
+
const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)])
|
|
1533
|
+
|
|
1534
|
+
tx.moveCall({
|
|
1535
|
+
target: `${this.consts.sudoCore.upgradedPackage}::market::open_position_with_scard_v1`,
|
|
1536
|
+
typeArguments: [
|
|
1537
|
+
`${this.consts.sudoCore.package}::slp::SLP`,
|
|
1538
|
+
this.consts.coins[collateralToken].module,
|
|
1539
|
+
this.consts.coins[indexToken].module,
|
|
1540
|
+
`${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
|
|
1541
|
+
this.consts.coins[collateralToken].module,
|
|
1542
|
+
],
|
|
1543
|
+
arguments: [
|
|
1544
|
+
tx.object(SUI_CLOCK_OBJECT_ID),
|
|
1545
|
+
tx.object(this.consts.sudoCore.market),
|
|
1546
|
+
tx.object(
|
|
1547
|
+
this.consts.sudoCore.vaults[collateralToken].reservingFeeModel,
|
|
1548
|
+
),
|
|
1549
|
+
tx.object(this.consts.sudoCore.symbols[symbol].fundingFeeModel),
|
|
1550
|
+
tx.object(this.consts.sudoCore.symbols[symbol].positionConfig),
|
|
1551
|
+
tx.object(this.consts.pythFeeder.feeder[collateralToken]),
|
|
1552
|
+
tx.object(this.consts.pythFeeder.feeder[indexToken]),
|
|
1553
|
+
coinObj,
|
|
1554
|
+
feeObject,
|
|
1555
|
+
tx.pure.u8(allowTrade),
|
|
1556
|
+
tx.pure.u64(size),
|
|
1557
|
+
tx.pure.u64(reserveAmount),
|
|
1558
|
+
tx.pure.u256(adjustCollateralPrice),
|
|
1559
|
+
tx.pure.u256(adjustPrice),
|
|
1560
|
+
sudoCard,
|
|
1561
|
+
],
|
|
1562
|
+
})
|
|
1563
|
+
|
|
1564
|
+
kioskTx
|
|
1565
|
+
.return({
|
|
1566
|
+
itemType: `${this.consts.sudoNft.package}::card::SudoCard`,
|
|
1567
|
+
item: sudoCard,
|
|
1568
|
+
promise,
|
|
1569
|
+
})
|
|
1570
|
+
.finalize()
|
|
1571
|
+
return tx
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1390
1574
|
public async decreasePositionWithSCard(
|
|
1391
1575
|
pcpId: string,
|
|
1392
1576
|
collateralToken: string,
|
|
@@ -1644,7 +1828,7 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
|
|
|
1644
1828
|
tx.moveCall({
|
|
1645
1829
|
target: `${this.consts.sudoCore.upgradedPackage}::market::add_new_referral`,
|
|
1646
1830
|
typeArguments: [`${this.consts.sudoCore.package}::slp::SLP`],
|
|
1647
|
-
arguments: [tx.object(this.consts.sudoCore.market), tx.
|
|
1831
|
+
arguments: [tx.object(this.consts.sudoCore.market), tx.pure.address(referrer)],
|
|
1648
1832
|
})
|
|
1649
1833
|
|
|
1650
1834
|
return tx
|
|
@@ -295,6 +295,107 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
|
|
|
295
295
|
return tx
|
|
296
296
|
}
|
|
297
297
|
|
|
298
|
+
public async openPositionWithCoinAndSCard(
|
|
299
|
+
collateralToken: string,
|
|
300
|
+
indexToken: string,
|
|
301
|
+
size: bigint,
|
|
302
|
+
coinObj: TransactionObjectArgument,
|
|
303
|
+
long: boolean,
|
|
304
|
+
reserveAmount: bigint,
|
|
305
|
+
indexPrice: number,
|
|
306
|
+
collateralPrice: number,
|
|
307
|
+
kioskClient: KioskClient,
|
|
308
|
+
kioskCap: KioskOwnerCap,
|
|
309
|
+
scard: string,
|
|
310
|
+
isLimitOrder?: boolean,
|
|
311
|
+
isIocOrder?: boolean,
|
|
312
|
+
pricesSlippage = 0.003,
|
|
313
|
+
collateralSlippage = 0.5,
|
|
314
|
+
relayerFee = BigInt(0.5),
|
|
315
|
+
referralAddress?: string,
|
|
316
|
+
sender?: string,
|
|
317
|
+
tx?: Transaction,
|
|
318
|
+
sponsoredTx?: boolean,
|
|
319
|
+
suiCoinObjectsForPythUpdate?: string[],
|
|
320
|
+
): Promise<Transaction> {
|
|
321
|
+
if (!tx) {
|
|
322
|
+
tx = new Transaction()
|
|
323
|
+
}
|
|
324
|
+
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
325
|
+
tx = await this.addReferral(referralAddress, tx)
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
|
|
329
|
+
const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage)
|
|
330
|
+
const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage)
|
|
331
|
+
|
|
332
|
+
let allowTrade = ALLOW_TRADE_MUST_TRADE
|
|
333
|
+
if (isLimitOrder) {
|
|
334
|
+
allowTrade = isIocOrder ? ALLOW_TRADE_NO_TRADE : ALLOW_TRADE_CAN_TRADE
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const kioskTx = new KioskTransaction({
|
|
338
|
+
transaction: tx,
|
|
339
|
+
kioskClient,
|
|
340
|
+
cap: kioskCap,
|
|
341
|
+
})
|
|
342
|
+
|
|
343
|
+
const [sudoCard, promise] = kioskTx.borrow({
|
|
344
|
+
itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
|
|
345
|
+
itemId: scard,
|
|
346
|
+
})
|
|
347
|
+
|
|
348
|
+
// Handle oracle initialization and coin processing
|
|
349
|
+
let suiCoinObject
|
|
350
|
+
if (sponsoredTx) {
|
|
351
|
+
suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
|
|
352
|
+
tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject)
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
tx = await this.initOracleTxb([collateralToken, indexToken], tx)
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// Process coin splitting
|
|
359
|
+
const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)])
|
|
360
|
+
|
|
361
|
+
tx.moveCall({
|
|
362
|
+
target: `${this.consts.zoCore.upgradedPackage}::market::open_position_with_scard`,
|
|
363
|
+
typeArguments: [
|
|
364
|
+
`${this.consts.zoCore.package}::usdz::USDZ`,
|
|
365
|
+
this.consts.coins[collateralToken].module,
|
|
366
|
+
this.consts.coins[indexToken].module,
|
|
367
|
+
`${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
|
|
368
|
+
this.consts.coins[collateralToken].module,
|
|
369
|
+
],
|
|
370
|
+
arguments: [
|
|
371
|
+
tx.object(SUI_CLOCK_OBJECT_ID),
|
|
372
|
+
tx.object(this.consts.zoCore.market),
|
|
373
|
+
tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
|
|
374
|
+
tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
|
|
375
|
+
tx.object(this.consts.zoCore.symbols[symbol].positionConfig),
|
|
376
|
+
tx.object(this.consts.pythFeeder.feeder[collateralToken]),
|
|
377
|
+
tx.object(this.consts.pythFeeder.feeder[indexToken]),
|
|
378
|
+
coinObj,
|
|
379
|
+
feeObject,
|
|
380
|
+
tx.pure.u8(allowTrade),
|
|
381
|
+
tx.pure.u64(size),
|
|
382
|
+
tx.pure.u64(reserveAmount),
|
|
383
|
+
tx.pure.u256(adjustCollateralPrice),
|
|
384
|
+
tx.pure.u256(adjustPrice),
|
|
385
|
+
sudoCard,
|
|
386
|
+
],
|
|
387
|
+
})
|
|
388
|
+
|
|
389
|
+
kioskTx
|
|
390
|
+
.return({
|
|
391
|
+
itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
|
|
392
|
+
item: sudoCard,
|
|
393
|
+
promise,
|
|
394
|
+
})
|
|
395
|
+
.finalize()
|
|
396
|
+
return tx
|
|
397
|
+
}
|
|
398
|
+
|
|
298
399
|
public async decreasePositionWithSCard(
|
|
299
400
|
pcpId: string,
|
|
300
401
|
collateralToken: string,
|
|
@@ -849,7 +950,7 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
|
|
|
849
950
|
})()
|
|
850
951
|
unstakeAmount -= withdrawAmount
|
|
851
952
|
tx.moveCall({
|
|
852
|
-
target: `${this.sharedConfig.zoStaking.
|
|
953
|
+
target: `${this.sharedConfig.zoStaking.upgradedPackage}::pool::withdraw`,
|
|
853
954
|
typeArguments: [
|
|
854
955
|
`${this.consts.zoCore.package}::usdz::USDZ`,
|
|
855
956
|
`${this.consts.coins.sui.module}`,
|
|
@@ -863,7 +964,7 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
|
|
|
863
964
|
})
|
|
864
965
|
if (credential.amount === BigInt(0)) {
|
|
865
966
|
tx.moveCall({
|
|
866
|
-
target: `${this.sharedConfig.zoStaking.
|
|
967
|
+
target: `${this.sharedConfig.zoStaking.upgradedPackage}::pool::clear_empty_credential`,
|
|
867
968
|
typeArguments: [
|
|
868
969
|
`${this.consts.zoCore.package}::usdz::USDZ`,
|
|
869
970
|
`${this.consts.coins.sui.module}`,
|
|
@@ -908,7 +1009,7 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
|
|
|
908
1009
|
withdrawnCoinObjects.push(withdrawnCoin)
|
|
909
1010
|
if (credential.amount === BigInt(0)) {
|
|
910
1011
|
tx.moveCall({
|
|
911
|
-
target: `${this.sharedConfig.zoStaking.
|
|
1012
|
+
target: `${this.sharedConfig.zoStaking.upgradedPackage}::pool::clear_empty_credential`,
|
|
912
1013
|
typeArguments: [
|
|
913
1014
|
`${this.consts.zoCore.package}::usdz::USDZ`,
|
|
914
1015
|
`${this.consts.coins.sui.module}`,
|
|
@@ -1086,6 +1187,87 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
|
|
|
1086
1187
|
return tx
|
|
1087
1188
|
}
|
|
1088
1189
|
|
|
1190
|
+
/**
|
|
1191
|
+
* Opens a new position in USDZ
|
|
1192
|
+
*/
|
|
1193
|
+
public async openPositionWithCoin(
|
|
1194
|
+
collateralToken: string,
|
|
1195
|
+
indexToken: string,
|
|
1196
|
+
size: bigint,
|
|
1197
|
+
coinObj: TransactionObjectArgument,
|
|
1198
|
+
long: boolean,
|
|
1199
|
+
reserveAmount: bigint,
|
|
1200
|
+
indexPrice: number,
|
|
1201
|
+
collateralPrice: number,
|
|
1202
|
+
isLimitOrder?: boolean,
|
|
1203
|
+
isIocOrder?: boolean,
|
|
1204
|
+
pricesSlippage = 0.003,
|
|
1205
|
+
collateralSlippage = 0.5,
|
|
1206
|
+
relayerFee = BigInt(0.5),
|
|
1207
|
+
referralAddress?: string,
|
|
1208
|
+
sender?: string,
|
|
1209
|
+
tx?: Transaction,
|
|
1210
|
+
sponsoredTx?: boolean,
|
|
1211
|
+
suiCoinObjectsForPythUpdate?: string[],
|
|
1212
|
+
): Promise<Transaction> {
|
|
1213
|
+
if (!tx) {
|
|
1214
|
+
tx = new Transaction()
|
|
1215
|
+
}
|
|
1216
|
+
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
1217
|
+
tx = await this.addReferral(referralAddress, tx)
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
|
|
1221
|
+
const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage)
|
|
1222
|
+
const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage)
|
|
1223
|
+
|
|
1224
|
+
let allowTrade = ALLOW_TRADE_MUST_TRADE
|
|
1225
|
+
if (isLimitOrder) {
|
|
1226
|
+
allowTrade = isIocOrder ? ALLOW_TRADE_NO_TRADE : ALLOW_TRADE_CAN_TRADE
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
// Handle oracle initialization and coin processing
|
|
1230
|
+
let suiCoinObject
|
|
1231
|
+
if (sponsoredTx) {
|
|
1232
|
+
suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
|
|
1233
|
+
tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject)
|
|
1234
|
+
}
|
|
1235
|
+
else {
|
|
1236
|
+
tx = await this.initOracleTxb([collateralToken, indexToken], tx)
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
// Process coin splitting
|
|
1240
|
+
const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)])
|
|
1241
|
+
|
|
1242
|
+
tx.moveCall({
|
|
1243
|
+
target: `${this.consts.zoCore.upgradedPackage}::market::open_position`,
|
|
1244
|
+
typeArguments: [
|
|
1245
|
+
`${this.consts.zoCore.package}::usdz::USDZ`,
|
|
1246
|
+
this.consts.coins[collateralToken].module,
|
|
1247
|
+
this.consts.coins[indexToken].module,
|
|
1248
|
+
`${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
|
|
1249
|
+
this.consts.coins[collateralToken].module,
|
|
1250
|
+
],
|
|
1251
|
+
arguments: [
|
|
1252
|
+
tx.object(SUI_CLOCK_OBJECT_ID),
|
|
1253
|
+
tx.object(this.consts.zoCore.market),
|
|
1254
|
+
tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
|
|
1255
|
+
tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
|
|
1256
|
+
tx.object(this.consts.zoCore.symbols[symbol].positionConfig),
|
|
1257
|
+
tx.object(this.consts.pythFeeder.feeder[collateralToken]),
|
|
1258
|
+
tx.object(this.consts.pythFeeder.feeder[indexToken]),
|
|
1259
|
+
coinObj,
|
|
1260
|
+
feeObject,
|
|
1261
|
+
tx.pure.u8(allowTrade),
|
|
1262
|
+
tx.pure.u64(size),
|
|
1263
|
+
tx.pure.u64(reserveAmount),
|
|
1264
|
+
tx.pure.u256(adjustCollateralPrice),
|
|
1265
|
+
tx.pure.u256(adjustPrice),
|
|
1266
|
+
],
|
|
1267
|
+
})
|
|
1268
|
+
return tx
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1089
1271
|
/**
|
|
1090
1272
|
* Decreases an existing position in USDZ
|
|
1091
1273
|
*/
|
|
@@ -1462,7 +1644,7 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
|
|
|
1462
1644
|
tx.moveCall({
|
|
1463
1645
|
target: `${this.consts.zoCore.upgradedPackage}::market::add_new_referral`,
|
|
1464
1646
|
typeArguments: [`${this.consts.zoCore.package}::usdz::USDZ`],
|
|
1465
|
-
arguments: [tx.object(this.consts.zoCore.market), tx.
|
|
1647
|
+
arguments: [tx.object(this.consts.zoCore.market), tx.pure.address(referralAddress)],
|
|
1466
1648
|
})
|
|
1467
1649
|
|
|
1468
1650
|
return tx
|
|
@@ -575,7 +575,7 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
|
|
|
575
575
|
})()
|
|
576
576
|
unstakeAmount -= withdrawAmount
|
|
577
577
|
tx.moveCall({
|
|
578
|
-
target: `${this.sharedConfig.zoStaking.
|
|
578
|
+
target: `${this.sharedConfig.zoStaking.upgradedPackage}::pool::withdraw`,
|
|
579
579
|
typeArguments: [
|
|
580
580
|
`${this.consts.zoCore.package}::zlp::ZLP`,
|
|
581
581
|
`${this.consts.coins.sui.module}`,
|
|
@@ -589,7 +589,7 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
|
|
|
589
589
|
})
|
|
590
590
|
if (credential.amount === BigInt(0)) {
|
|
591
591
|
tx.moveCall({
|
|
592
|
-
target: `${this.sharedConfig.zoStaking.
|
|
592
|
+
target: `${this.sharedConfig.zoStaking.upgradedPackage}::pool::clear_empty_credential`,
|
|
593
593
|
typeArguments: [
|
|
594
594
|
`${this.consts.zoCore.package}::zlp::ZLP`,
|
|
595
595
|
`${this.consts.coins.sui.module}`,
|
|
@@ -634,7 +634,7 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
|
|
|
634
634
|
withdrawnCoinObjects.push(withdrawnCoin)
|
|
635
635
|
if (credential.amount === BigInt(0)) {
|
|
636
636
|
tx.moveCall({
|
|
637
|
-
target: `${this.sharedConfig.zoStaking.
|
|
637
|
+
target: `${this.sharedConfig.zoStaking.upgradedPackage}::pool::clear_empty_credential`,
|
|
638
638
|
typeArguments: [
|
|
639
639
|
`${this.consts.zoCore.package}::zlp::ZLP`,
|
|
640
640
|
`${this.consts.coins.sui.module}`,
|
|
@@ -813,6 +813,88 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
|
|
|
813
813
|
return tx
|
|
814
814
|
}
|
|
815
815
|
|
|
816
|
+
/**
|
|
817
|
+
* Opens a new position in ZLP
|
|
818
|
+
*/
|
|
819
|
+
public async openPositionWithCoin(
|
|
820
|
+
collateralToken: string,
|
|
821
|
+
indexToken: string,
|
|
822
|
+
size: bigint,
|
|
823
|
+
coinObj: TransactionObjectArgument,
|
|
824
|
+
long: boolean,
|
|
825
|
+
reserveAmount: bigint,
|
|
826
|
+
indexPrice: number,
|
|
827
|
+
collateralPrice: number,
|
|
828
|
+
isLimitOrder?: boolean,
|
|
829
|
+
isIocOrder?: boolean,
|
|
830
|
+
pricesSlippage = 0.003,
|
|
831
|
+
collateralSlippage = 0.5,
|
|
832
|
+
relayerFee = BigInt(0.5),
|
|
833
|
+
referralAddress?: string,
|
|
834
|
+
sender?: string,
|
|
835
|
+
tx?: Transaction,
|
|
836
|
+
sponsoredTx?: boolean,
|
|
837
|
+
suiCoinObjectsForPythUpdate?: string[],
|
|
838
|
+
): Promise<Transaction> {
|
|
839
|
+
if (!tx) {
|
|
840
|
+
tx = new Transaction()
|
|
841
|
+
}
|
|
842
|
+
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
843
|
+
tx = await this.addReferral(referralAddress, tx)
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
|
|
847
|
+
const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage)
|
|
848
|
+
const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage)
|
|
849
|
+
|
|
850
|
+
let allowTrade = ALLOW_TRADE_MUST_TRADE
|
|
851
|
+
if (isLimitOrder) {
|
|
852
|
+
allowTrade = isIocOrder ? ALLOW_TRADE_NO_TRADE : ALLOW_TRADE_CAN_TRADE
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
// Handle oracle initialization and coin processing
|
|
856
|
+
let suiCoinObject
|
|
857
|
+
if (sponsoredTx) {
|
|
858
|
+
suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
|
|
859
|
+
tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject)
|
|
860
|
+
}
|
|
861
|
+
else {
|
|
862
|
+
tx = await this.initOracleTxb([collateralToken, indexToken], tx)
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
// Process coin splitting
|
|
866
|
+
const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)])
|
|
867
|
+
|
|
868
|
+
tx.moveCall({
|
|
869
|
+
target: `${this.consts.zoCore.upgradedPackage}::market::open_position`,
|
|
870
|
+
typeArguments: [
|
|
871
|
+
`${this.consts.zoCore.package}::zlp::ZLP`,
|
|
872
|
+
this.consts.coins[collateralToken].module,
|
|
873
|
+
this.consts.coins[indexToken].module,
|
|
874
|
+
`${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
|
|
875
|
+
this.consts.coins[collateralToken].module,
|
|
876
|
+
],
|
|
877
|
+
arguments: [
|
|
878
|
+
tx.object(SUI_CLOCK_OBJECT_ID),
|
|
879
|
+
tx.object(this.consts.zoCore.market),
|
|
880
|
+
tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
|
|
881
|
+
tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
|
|
882
|
+
tx.object(this.consts.zoCore.symbols[symbol].positionConfig),
|
|
883
|
+
tx.object(this.consts.pythFeeder.feeder[collateralToken]),
|
|
884
|
+
tx.object(this.consts.pythFeeder.feeder[indexToken]),
|
|
885
|
+
coinObj,
|
|
886
|
+
feeObject,
|
|
887
|
+
tx.pure.u8(allowTrade),
|
|
888
|
+
tx.pure.u64(size),
|
|
889
|
+
tx.pure.u64(reserveAmount),
|
|
890
|
+
tx.pure.u256(adjustCollateralPrice),
|
|
891
|
+
tx.pure.u256(adjustPrice),
|
|
892
|
+
],
|
|
893
|
+
})
|
|
894
|
+
|
|
895
|
+
return tx
|
|
896
|
+
}
|
|
897
|
+
|
|
816
898
|
/**
|
|
817
899
|
* Decreases an existing position in ZLP
|
|
818
900
|
*/
|
|
@@ -1108,6 +1190,108 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
|
|
|
1108
1190
|
return tx
|
|
1109
1191
|
}
|
|
1110
1192
|
|
|
1193
|
+
public async openPositionWithCoinAndSCard(
|
|
1194
|
+
collateralToken: string,
|
|
1195
|
+
indexToken: string,
|
|
1196
|
+
size: bigint,
|
|
1197
|
+
coinObj: TransactionObjectArgument,
|
|
1198
|
+
long: boolean,
|
|
1199
|
+
reserveAmount: bigint,
|
|
1200
|
+
indexPrice: number,
|
|
1201
|
+
collateralPrice: number,
|
|
1202
|
+
kioskClient: KioskClient,
|
|
1203
|
+
kioskCap: KioskOwnerCap,
|
|
1204
|
+
scard: string,
|
|
1205
|
+
isLimitOrder?: boolean,
|
|
1206
|
+
isIocOrder?: boolean,
|
|
1207
|
+
pricesSlippage = 0.003,
|
|
1208
|
+
collateralSlippage = 0.5,
|
|
1209
|
+
relayerFee = BigInt(0.5),
|
|
1210
|
+
referralAddress?: string,
|
|
1211
|
+
sender?: string,
|
|
1212
|
+
tx?: Transaction,
|
|
1213
|
+
sponsoredTx?: boolean,
|
|
1214
|
+
suiCoinObjectsForPythUpdate?: string[],
|
|
1215
|
+
): Promise<Transaction> {
|
|
1216
|
+
if (!tx) {
|
|
1217
|
+
tx = new Transaction()
|
|
1218
|
+
}
|
|
1219
|
+
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
1220
|
+
tx = await this.addReferral(referralAddress, tx)
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
|
|
1224
|
+
const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage)
|
|
1225
|
+
const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage)
|
|
1226
|
+
|
|
1227
|
+
let allowTrade = ALLOW_TRADE_MUST_TRADE
|
|
1228
|
+
if (isLimitOrder) {
|
|
1229
|
+
allowTrade = isIocOrder ? ALLOW_TRADE_NO_TRADE : ALLOW_TRADE_CAN_TRADE
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
const kioskTx = new KioskTransaction({
|
|
1233
|
+
transaction: tx,
|
|
1234
|
+
kioskClient,
|
|
1235
|
+
cap: kioskCap,
|
|
1236
|
+
})
|
|
1237
|
+
|
|
1238
|
+
const [sudoCard, promise] = kioskTx.borrow({
|
|
1239
|
+
itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
|
|
1240
|
+
itemId: scard,
|
|
1241
|
+
})
|
|
1242
|
+
|
|
1243
|
+
// Handle oracle initialization and coin processing
|
|
1244
|
+
let suiCoinObject
|
|
1245
|
+
if (sponsoredTx) {
|
|
1246
|
+
suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
|
|
1247
|
+
tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject)
|
|
1248
|
+
}
|
|
1249
|
+
else {
|
|
1250
|
+
tx = await this.initOracleTxb([collateralToken, indexToken], tx)
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
// Process coin splitting
|
|
1254
|
+
const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)])
|
|
1255
|
+
|
|
1256
|
+
tx.moveCall({
|
|
1257
|
+
target: `${this.consts.zoCore.upgradedPackage}::market::open_position_with_scard`,
|
|
1258
|
+
typeArguments: [
|
|
1259
|
+
`${this.consts.zoCore.package}::zlp::ZLP`,
|
|
1260
|
+
this.consts.coins[collateralToken].module,
|
|
1261
|
+
this.consts.coins[indexToken].module,
|
|
1262
|
+
`${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
|
|
1263
|
+
this.consts.coins[collateralToken].module,
|
|
1264
|
+
],
|
|
1265
|
+
arguments: [
|
|
1266
|
+
tx.object(SUI_CLOCK_OBJECT_ID),
|
|
1267
|
+
tx.object(this.consts.zoCore.market),
|
|
1268
|
+
tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
|
|
1269
|
+
tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
|
|
1270
|
+
tx.object(this.consts.zoCore.symbols[symbol].positionConfig),
|
|
1271
|
+
tx.object(this.consts.pythFeeder.feeder[collateralToken]),
|
|
1272
|
+
tx.object(this.consts.pythFeeder.feeder[indexToken]),
|
|
1273
|
+
coinObj,
|
|
1274
|
+
feeObject,
|
|
1275
|
+
tx.pure.u8(allowTrade),
|
|
1276
|
+
tx.pure.u64(size),
|
|
1277
|
+
tx.pure.u64(reserveAmount),
|
|
1278
|
+
tx.pure.u256(adjustCollateralPrice),
|
|
1279
|
+
tx.pure.u256(adjustPrice),
|
|
1280
|
+
sudoCard,
|
|
1281
|
+
],
|
|
1282
|
+
})
|
|
1283
|
+
|
|
1284
|
+
kioskTx
|
|
1285
|
+
.return({
|
|
1286
|
+
itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
|
|
1287
|
+
item: sudoCard,
|
|
1288
|
+
promise,
|
|
1289
|
+
})
|
|
1290
|
+
.finalize()
|
|
1291
|
+
|
|
1292
|
+
return tx
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1111
1295
|
public async decreasePositionWithSCard(
|
|
1112
1296
|
pcpId: string,
|
|
1113
1297
|
collateralToken: string,
|
|
@@ -1596,7 +1780,7 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
|
|
|
1596
1780
|
tx.moveCall({
|
|
1597
1781
|
target: `${this.consts.zoCore.upgradedPackage}::market::add_new_referral`,
|
|
1598
1782
|
typeArguments: [`${this.consts.zoCore.package}::zlp::ZLP`],
|
|
1599
|
-
arguments: [tx.object(this.consts.zoCore.market), tx.
|
|
1783
|
+
arguments: [tx.object(this.consts.zoCore.market), tx.pure.address(referralAddress)],
|
|
1600
1784
|
})
|
|
1601
1785
|
|
|
1602
1786
|
return tx
|