zo-sdk 0.1.55 → 0.1.57
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 +549 -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 +549 -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 +922 -58
- package/src/implementations/ZLPDataAPI.ts +48 -5
- package/src/interfaces/base.ts +207 -1
|
@@ -13,6 +13,7 @@ import type { Network } from '../consts'
|
|
|
13
13
|
import { LPToken, SECONDS_PER_EIGHT_HOUR, ZLP_TOKEN_DECIMALS } from '../consts'
|
|
14
14
|
import type {
|
|
15
15
|
IBaseHistoryResponse,
|
|
16
|
+
IBaseOrderType,
|
|
16
17
|
IBaseStaked,
|
|
17
18
|
IZLPCredential,
|
|
18
19
|
IZLPDataAPI,
|
|
@@ -1042,7 +1043,19 @@ export class ZLPDataAPI extends BaseDataAPI implements IZLPDataAPI {
|
|
|
1042
1043
|
// Extract tokens from dataType
|
|
1043
1044
|
const dataType = content.type
|
|
1044
1045
|
|
|
1045
|
-
|
|
1046
|
+
let orderType: IBaseOrderType
|
|
1047
|
+
if (content.fields.value.type.includes('OpenPositionOrder')) {
|
|
1048
|
+
orderType = 'OPEN_POSITION'
|
|
1049
|
+
}
|
|
1050
|
+
else if (content.fields.value.type.includes('OpenMarketOrder')) {
|
|
1051
|
+
orderType = 'OPEN_MARKET'
|
|
1052
|
+
}
|
|
1053
|
+
else if (content.fields.value.type.includes('DecreasePositionOrder')) {
|
|
1054
|
+
orderType = 'DECREASE_POSITION'
|
|
1055
|
+
}
|
|
1056
|
+
else {
|
|
1057
|
+
orderType = 'DECREASE_MARKET'
|
|
1058
|
+
}
|
|
1046
1059
|
|
|
1047
1060
|
const ret: IZLPOrderInfo = {
|
|
1048
1061
|
id: content.fields.id.id,
|
|
@@ -1052,23 +1065,53 @@ export class ZLPDataAPI extends BaseDataAPI implements IZLPDataAPI {
|
|
|
1052
1065
|
collateralToken: suiSymbolToSymbol(dataType.split('<')[2].split(',')[0].trim(), this.consts),
|
|
1053
1066
|
indexToken: suiSymbolToSymbol(dataType.split(',')[1].trim(), this.consts),
|
|
1054
1067
|
feeToken: suiSymbolToSymbol(dataType.split(',')[3].split('>')[0].trim(), this.consts),
|
|
1055
|
-
|
|
1068
|
+
// Use index_price for open orders, limited_index_price for decrease orders
|
|
1069
|
+
indexPrice: (orderType === 'OPEN_POSITION' || orderType === 'OPEN_MARKET')
|
|
1070
|
+
? parseValue(fields.index_price)
|
|
1071
|
+
: parseValue(fields.limited_index_price?.fields?.price || fields.limited_index_price),
|
|
1056
1072
|
collateralPriceThreshold: parseValue(fields.collateral_price_threshold),
|
|
1073
|
+
// New index price threshold
|
|
1074
|
+
indexPriceThreshold: fields.index_price_threshold !== undefined ? parseValue(fields.index_price_threshold) : undefined,
|
|
1057
1075
|
feeAmount: BigInt(fields.fee),
|
|
1058
1076
|
long: dataType.includes('::market::LONG'),
|
|
1059
1077
|
orderType,
|
|
1060
1078
|
createdAt: parseValue(fields.created_at),
|
|
1061
|
-
v11Order: !fields.limited_index_price
|
|
1079
|
+
v11Order: !fields.limited_index_price?.fields?.price,
|
|
1080
|
+
// New: referrer and scard fields
|
|
1081
|
+
referrer: fields.referrer,
|
|
1082
|
+
scardId: (
|
|
1083
|
+
fields.scard_id?.fields?.some?.fields?.id
|
|
1084
|
+
|| fields.scard_id?.fields?.value?.fields?.id
|
|
1085
|
+
|| fields.scard_id?.fields?.id
|
|
1086
|
+
|| fields.scard_id?.id
|
|
1087
|
+
),
|
|
1088
|
+
scardRebateRate: (() => {
|
|
1089
|
+
const inner = fields.scard_rebate_rate?.fields?.some ?? fields.scard_rebate_rate?.fields?.value
|
|
1090
|
+
return inner ? parseValue(inner) : undefined
|
|
1091
|
+
})(),
|
|
1062
1092
|
}
|
|
1063
1093
|
|
|
1064
|
-
if (orderType === 'OPEN_POSITION') {
|
|
1094
|
+
if (orderType === 'OPEN_POSITION' || orderType === 'OPEN_MARKET') {
|
|
1065
1095
|
ret.openOrder = {
|
|
1066
1096
|
reserveAmount: BigInt(fields.reserve_amount),
|
|
1067
1097
|
collateralAmount: BigInt(fields.collateral),
|
|
1068
1098
|
openAmount: BigInt(fields.open_amount),
|
|
1099
|
+
// New: position_config from OpenMarketOrder
|
|
1100
|
+
positionConfig: fields.position_config?.fields
|
|
1101
|
+
? {
|
|
1102
|
+
decreaseFeeBps: parseValue(fields.position_config.fields.decrease_fee_bps),
|
|
1103
|
+
liquidationBonus: parseValue(fields.position_config.fields.liquidation_bonus),
|
|
1104
|
+
liquidationThreshold: parseValue(fields.position_config.fields.liquidation_threshold),
|
|
1105
|
+
maxLeverage: parseValue(fields.position_config.fields.max_leverage),
|
|
1106
|
+
minHoldingDuration: parseValue(fields.position_config.fields.min_holding_duration),
|
|
1107
|
+
openFeeBps: parseValue(fields.position_config.fields.open_fee_bps),
|
|
1108
|
+
maxReservedMultiplier: parseValue(fields.position_config.fields.max_reserved_multiplier),
|
|
1109
|
+
minCollateralValue: parseValue(fields.position_config.fields.min_collateral_value),
|
|
1110
|
+
}
|
|
1111
|
+
: undefined,
|
|
1069
1112
|
}
|
|
1070
1113
|
}
|
|
1071
|
-
else {
|
|
1114
|
+
else if (orderType === 'DECREASE_POSITION' || orderType === 'DECREASE_MARKET') {
|
|
1072
1115
|
ret.decreaseOrder = {
|
|
1073
1116
|
decreaseAmount: BigInt(fields.decrease_amount),
|
|
1074
1117
|
takeProfit: fields.take_profit,
|
package/src/interfaces/base.ts
CHANGED
|
@@ -101,6 +101,7 @@ export interface IBasePositionInfo {
|
|
|
101
101
|
openTimestamp: number
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
export type IBaseOrderType = 'OPEN_POSITION' | 'DECREASE_POSITION' | 'OPEN_MARKET' | 'DECREASE_MARKET'
|
|
104
105
|
export interface IBaseOrderInfo {
|
|
105
106
|
id: string
|
|
106
107
|
capId: string
|
|
@@ -113,16 +114,23 @@ export interface IBaseOrderInfo {
|
|
|
113
114
|
feeAmount: bigint
|
|
114
115
|
long: boolean
|
|
115
116
|
indexPrice: number
|
|
117
|
+
// New optional fields for upgraded Move structs
|
|
118
|
+
indexPriceThreshold?: number
|
|
119
|
+
referrer?: string
|
|
120
|
+
scardId?: string
|
|
121
|
+
scardRebateRate?: number
|
|
116
122
|
openOrder?: {
|
|
117
123
|
reserveAmount: bigint
|
|
118
124
|
collateralAmount: bigint
|
|
119
125
|
openAmount: bigint
|
|
126
|
+
// PositionConfig from OpenMarketOrder
|
|
127
|
+
positionConfig?: IBasePositionConfig
|
|
120
128
|
}
|
|
121
129
|
decreaseOrder?: {
|
|
122
130
|
decreaseAmount: bigint
|
|
123
131
|
takeProfit: boolean
|
|
124
132
|
}
|
|
125
|
-
orderType:
|
|
133
|
+
orderType: IBaseOrderType
|
|
126
134
|
createdAt: number
|
|
127
135
|
v11Order?: boolean
|
|
128
136
|
orderVersion?: string
|
|
@@ -391,6 +399,90 @@ export interface IBaseAPI {
|
|
|
391
399
|
suiCoinObjectsForPythUpdate?: string[],
|
|
392
400
|
) => Promise<Transaction>
|
|
393
401
|
|
|
402
|
+
openPositionV2?: (
|
|
403
|
+
collateralToken: string,
|
|
404
|
+
indexToken: string,
|
|
405
|
+
size: bigint,
|
|
406
|
+
collateralAmount: bigint,
|
|
407
|
+
coinObjects: string[],
|
|
408
|
+
long: boolean,
|
|
409
|
+
reserveAmount: bigint,
|
|
410
|
+
indexPrice: number,
|
|
411
|
+
collateralPrice: number,
|
|
412
|
+
isLimitOrder?: boolean,
|
|
413
|
+
isIocOrder?: boolean,
|
|
414
|
+
pricesSlippage?: number,
|
|
415
|
+
collateralSlippage?: number,
|
|
416
|
+
relayerFee?: bigint,
|
|
417
|
+
referralAddress?: string,
|
|
418
|
+
sender?: string,
|
|
419
|
+
sponsoredTx?: boolean,
|
|
420
|
+
suiCoinObjectsForPythUpdate?: string[],
|
|
421
|
+
) => Promise<Transaction>
|
|
422
|
+
|
|
423
|
+
// Trading operations
|
|
424
|
+
openPositionWithCoinV2?: (
|
|
425
|
+
collateralToken: string,
|
|
426
|
+
indexToken: string,
|
|
427
|
+
size: bigint,
|
|
428
|
+
coinObj: TransactionObjectArgument,
|
|
429
|
+
long: boolean,
|
|
430
|
+
reserveAmount: bigint,
|
|
431
|
+
indexPrice: number,
|
|
432
|
+
collateralPrice: number,
|
|
433
|
+
isLimitOrder?: boolean,
|
|
434
|
+
isIocOrder?: boolean,
|
|
435
|
+
pricesSlippage?: number,
|
|
436
|
+
collateralSlippage?: number,
|
|
437
|
+
relayerFee?: bigint,
|
|
438
|
+
referralAddress?: string,
|
|
439
|
+
sender?: string,
|
|
440
|
+
tx?: Transaction,
|
|
441
|
+
sponsoredTx?: boolean,
|
|
442
|
+
suiCoinObjectsForPythUpdate?: string[],
|
|
443
|
+
) => Promise<Transaction>
|
|
444
|
+
|
|
445
|
+
decreasePositionV2?: (
|
|
446
|
+
pcpId: string,
|
|
447
|
+
collateralToken: string,
|
|
448
|
+
indexToken: string,
|
|
449
|
+
amount: bigint,
|
|
450
|
+
long: boolean,
|
|
451
|
+
indexPrice: number,
|
|
452
|
+
collateralPrice: number,
|
|
453
|
+
isTriggerOrder?: boolean,
|
|
454
|
+
isTakeProfitOrder?: boolean,
|
|
455
|
+
isIocOrder?: boolean,
|
|
456
|
+
pricesSlippage?: number,
|
|
457
|
+
collateralSlippage?: number,
|
|
458
|
+
relayerFee?: bigint,
|
|
459
|
+
coinObjects?: string[],
|
|
460
|
+
sponsoredTx?: boolean,
|
|
461
|
+
suiCoinObjectsForPythUpdate?: string[],
|
|
462
|
+
) => Promise<Transaction>
|
|
463
|
+
|
|
464
|
+
decreaseMultiPositionsV2?: (
|
|
465
|
+
positions: Array<{
|
|
466
|
+
pcpId: string
|
|
467
|
+
collateralToken: string
|
|
468
|
+
indexToken: string
|
|
469
|
+
amount: bigint
|
|
470
|
+
long: boolean
|
|
471
|
+
indexPrice: number
|
|
472
|
+
collateralPrice: number
|
|
473
|
+
isTriggerOrder?: boolean
|
|
474
|
+
isTakeProfitOrder?: boolean
|
|
475
|
+
isIocOrder?: boolean
|
|
476
|
+
pricesSlippage?: number
|
|
477
|
+
collateralSlippage?: number
|
|
478
|
+
relayerFee?: bigint
|
|
479
|
+
coinObjects?: string[]
|
|
480
|
+
}>,
|
|
481
|
+
tx?: Transaction,
|
|
482
|
+
sponsoredTx?: boolean,
|
|
483
|
+
suiCoinObjectsForPythUpdate?: string[],
|
|
484
|
+
) => Promise<Transaction>
|
|
485
|
+
|
|
394
486
|
pledgeInPosition: (
|
|
395
487
|
pcpId: string,
|
|
396
488
|
collateralToken: string,
|
|
@@ -459,6 +551,24 @@ export interface IBaseAPI {
|
|
|
459
551
|
isV11Order?: boolean
|
|
460
552
|
) => void
|
|
461
553
|
|
|
554
|
+
clearOpenMarketOrder?: (
|
|
555
|
+
orderCapId: string,
|
|
556
|
+
collateralToken: string,
|
|
557
|
+
indexToken: string,
|
|
558
|
+
long: boolean,
|
|
559
|
+
tx: Transaction,
|
|
560
|
+
isV11Order?: boolean
|
|
561
|
+
) => void
|
|
562
|
+
|
|
563
|
+
clearDecreaseMarketOrder?: (
|
|
564
|
+
orderCapId: string,
|
|
565
|
+
collateralToken: string,
|
|
566
|
+
indexToken: string,
|
|
567
|
+
long: boolean,
|
|
568
|
+
tx: Transaction,
|
|
569
|
+
isV11Order?: boolean
|
|
570
|
+
) => void
|
|
571
|
+
|
|
462
572
|
// S Card operations
|
|
463
573
|
openPositionWithSCard: (
|
|
464
574
|
collateralToken: string,
|
|
@@ -556,6 +666,102 @@ export interface IBaseAPI {
|
|
|
556
666
|
suiCoinObjectsForPythUpdate?: string[],
|
|
557
667
|
) => Promise<Transaction>
|
|
558
668
|
|
|
669
|
+
openPositionWithSCardV2?: (
|
|
670
|
+
collateralToken: string,
|
|
671
|
+
indexToken: string,
|
|
672
|
+
size: bigint,
|
|
673
|
+
collateralAmount: bigint,
|
|
674
|
+
coinObjects: string[],
|
|
675
|
+
long: boolean,
|
|
676
|
+
reserveAmount: bigint,
|
|
677
|
+
indexPrice: number,
|
|
678
|
+
collateralPrice: number,
|
|
679
|
+
kioskClient: KioskClient,
|
|
680
|
+
kioskCap: KioskOwnerCap,
|
|
681
|
+
scard: string,
|
|
682
|
+
isLimitOrder?: boolean,
|
|
683
|
+
isIocOrder?: boolean,
|
|
684
|
+
pricesSlippage?: number,
|
|
685
|
+
collateralSlippage?: number,
|
|
686
|
+
relayerFee?: bigint,
|
|
687
|
+
referralAddress?: string,
|
|
688
|
+
sender?: string,
|
|
689
|
+
sponsoredTx?: boolean,
|
|
690
|
+
suiCoinObjectsForPythUpdate?: string[],
|
|
691
|
+
) => Promise<Transaction>
|
|
692
|
+
|
|
693
|
+
// S Card operations
|
|
694
|
+
openPositionWithCoinAndSCardV2?: (
|
|
695
|
+
collateralToken: string,
|
|
696
|
+
indexToken: string,
|
|
697
|
+
size: bigint,
|
|
698
|
+
coinObj: TransactionObjectArgument,
|
|
699
|
+
long: boolean,
|
|
700
|
+
reserveAmount: bigint,
|
|
701
|
+
indexPrice: number,
|
|
702
|
+
collateralPrice: number,
|
|
703
|
+
kioskClient: KioskClient,
|
|
704
|
+
kioskCap: KioskOwnerCap,
|
|
705
|
+
scard: string,
|
|
706
|
+
isLimitOrder?: boolean,
|
|
707
|
+
isIocOrder?: boolean,
|
|
708
|
+
pricesSlippage?: number,
|
|
709
|
+
collateralSlippage?: number,
|
|
710
|
+
relayerFee?: bigint,
|
|
711
|
+
referralAddress?: string,
|
|
712
|
+
sender?: string,
|
|
713
|
+
tx?: Transaction,
|
|
714
|
+
sponsoredTx?: boolean,
|
|
715
|
+
suiCoinObjectsForPythUpdate?: string[],
|
|
716
|
+
) => Promise<Transaction>
|
|
717
|
+
|
|
718
|
+
decreasePositionWithSCardV2?: (
|
|
719
|
+
pcpId: string,
|
|
720
|
+
collateralToken: string,
|
|
721
|
+
indexToken: string,
|
|
722
|
+
amount: bigint,
|
|
723
|
+
long: boolean,
|
|
724
|
+
indexPrice: number,
|
|
725
|
+
collateralPrice: number,
|
|
726
|
+
kioskClient: KioskClient,
|
|
727
|
+
kioskCap: KioskOwnerCap,
|
|
728
|
+
scard: string,
|
|
729
|
+
isTriggerOrder?: boolean,
|
|
730
|
+
isTakeProfitOrder?: boolean,
|
|
731
|
+
isIocOrder?: boolean,
|
|
732
|
+
pricesSlippage?: number,
|
|
733
|
+
collateralSlippage?: number,
|
|
734
|
+
relayerFee?: bigint,
|
|
735
|
+
coinObjects?: string[],
|
|
736
|
+
sponsoredTx?: boolean,
|
|
737
|
+
suiCoinObjectsForPythUpdate?: string[],
|
|
738
|
+
) => Promise<Transaction>
|
|
739
|
+
|
|
740
|
+
decreaseMultiPositionsWithSCardV2?: (
|
|
741
|
+
positions: Array<{
|
|
742
|
+
pcpId: string
|
|
743
|
+
collateralToken: string
|
|
744
|
+
indexToken: string
|
|
745
|
+
amount: bigint
|
|
746
|
+
long: boolean
|
|
747
|
+
indexPrice: number
|
|
748
|
+
collateralPrice: number
|
|
749
|
+
isTriggerOrder?: boolean
|
|
750
|
+
isTakeProfitOrder?: boolean
|
|
751
|
+
isIocOrder?: boolean
|
|
752
|
+
pricesSlippage?: number
|
|
753
|
+
collateralSlippage?: number
|
|
754
|
+
relayerFee?: bigint
|
|
755
|
+
coinObjects?: string[]
|
|
756
|
+
}>,
|
|
757
|
+
kioskClient: KioskClient,
|
|
758
|
+
kioskCap: KioskOwnerCap,
|
|
759
|
+
scard: string,
|
|
760
|
+
tx?: Transaction,
|
|
761
|
+
sponsoredTx?: boolean,
|
|
762
|
+
suiCoinObjectsForPythUpdate?: string[],
|
|
763
|
+
) => Promise<Transaction>
|
|
764
|
+
|
|
559
765
|
claimTokenFromSCard: (
|
|
560
766
|
token: string,
|
|
561
767
|
coinObjects: string[],
|