zo-sdk 0.1.62 → 0.1.63

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/consts/deployments-usdz-mainnet.json +4 -4
  2. package/dist/implementations/SLPAPI.cjs +544 -0
  3. package/dist/implementations/SLPAPI.cjs.map +1 -1
  4. package/dist/implementations/SLPAPI.d.cts +49 -0
  5. package/dist/implementations/SLPAPI.d.cts.map +1 -1
  6. package/dist/implementations/SLPAPI.d.mts +49 -0
  7. package/dist/implementations/SLPAPI.d.mts.map +1 -1
  8. package/dist/implementations/SLPAPI.mjs +544 -0
  9. package/dist/implementations/SLPAPI.mjs.map +1 -1
  10. package/dist/implementations/SLPDataAPI.cjs +48 -9
  11. package/dist/implementations/SLPDataAPI.cjs.map +1 -1
  12. package/dist/implementations/SLPDataAPI.d.cts.map +1 -1
  13. package/dist/implementations/SLPDataAPI.d.mts.map +1 -1
  14. package/dist/implementations/SLPDataAPI.mjs +49 -10
  15. package/dist/implementations/SLPDataAPI.mjs.map +1 -1
  16. package/dist/implementations/USDZAPI.cjs +544 -0
  17. package/dist/implementations/USDZAPI.cjs.map +1 -1
  18. package/dist/implementations/USDZAPI.d.cts +49 -0
  19. package/dist/implementations/USDZAPI.d.cts.map +1 -1
  20. package/dist/implementations/USDZAPI.d.mts +49 -0
  21. package/dist/implementations/USDZAPI.d.mts.map +1 -1
  22. package/dist/implementations/USDZAPI.mjs +544 -0
  23. package/dist/implementations/USDZAPI.mjs.map +1 -1
  24. package/dist/implementations/USDZDataAPI.cjs +47 -7
  25. package/dist/implementations/USDZDataAPI.cjs.map +1 -1
  26. package/dist/implementations/USDZDataAPI.d.cts.map +1 -1
  27. package/dist/implementations/USDZDataAPI.d.mts.map +1 -1
  28. package/dist/implementations/USDZDataAPI.mjs +47 -7
  29. package/dist/implementations/USDZDataAPI.mjs.map +1 -1
  30. package/dist/implementations/ZLPAPI.cjs +2 -6
  31. package/dist/implementations/ZLPAPI.cjs.map +1 -1
  32. package/dist/implementations/ZLPAPI.d.cts +2 -2
  33. package/dist/implementations/ZLPAPI.d.cts.map +1 -1
  34. package/dist/implementations/ZLPAPI.d.mts +2 -2
  35. package/dist/implementations/ZLPAPI.d.mts.map +1 -1
  36. package/dist/implementations/ZLPAPI.mjs +2 -6
  37. package/dist/implementations/ZLPAPI.mjs.map +1 -1
  38. package/package.json +1 -1
  39. package/src/consts/deployments-usdz-mainnet.json +4 -4
  40. package/src/implementations/SLPAPI.ts +884 -26
  41. package/src/implementations/SLPDataAPI.ts +52 -10
  42. package/src/implementations/USDZAPI.ts +913 -55
  43. package/src/implementations/USDZDataAPI.ts +50 -7
  44. package/src/implementations/ZLPAPI.ts +2 -7
@@ -13,6 +13,7 @@ import type { Network } from '../consts'
13
13
  import { LPToken, SECONDS_PER_EIGHT_HOUR, USDZ_TOKEN_DECIMALS } from '../consts'
14
14
  import type {
15
15
  IBaseHistoryResponse,
16
+ IBaseOrderType,
16
17
  IBaseStaked,
17
18
  IUSDZCredential,
18
19
  IUSDZDataAPI,
@@ -1023,9 +1024,21 @@ export class USDZDataAPI extends BaseDataAPI implements IUSDZDataAPI {
1023
1024
  const { fields } = content.fields.value
1024
1025
 
1025
1026
  // Extract tokens from dataType
1026
- const dataType = content.type
1027
+ const dataType = content?.type
1027
1028
 
1028
- const orderType = content.fields.value.type.includes('OpenPositionOrder') ? 'OPEN_POSITION' : 'DECREASE_POSITION'
1029
+ let orderType: IBaseOrderType
1030
+ if (content.fields.value?.type.includes('OpenPositionOrder')) {
1031
+ orderType = 'OPEN_POSITION'
1032
+ }
1033
+ else if (content.fields.value?.type.includes('OpenMarketOrder')) {
1034
+ orderType = 'OPEN_MARKET'
1035
+ }
1036
+ else if (content.fields.value?.type.includes('DecreasePositionOrder')) {
1037
+ orderType = 'DECREASE_POSITION'
1038
+ }
1039
+ else {
1040
+ orderType = 'DECREASE_MARKET'
1041
+ }
1029
1042
 
1030
1043
  const ret: IUSDZOrderInfo = {
1031
1044
  id: content.fields.id.id,
@@ -1035,23 +1048,53 @@ export class USDZDataAPI extends BaseDataAPI implements IUSDZDataAPI {
1035
1048
  collateralToken: suiSymbolToSymbol(dataType.split('<')[2].split(',')[0].trim(), this.consts),
1036
1049
  indexToken: suiSymbolToSymbol(dataType.split(',')[1].trim(), this.consts),
1037
1050
  feeToken: suiSymbolToSymbol(dataType.split(',')[3].split('>')[0].trim(), this.consts),
1038
- indexPrice: parseValue(fields.limited_index_price.fields.price || fields.limited_index_price),
1039
- collateralPriceThreshold: parseValue(fields.collateral_price_threshold),
1051
+ // Use index_price for open orders, limited_index_price for decrease orders
1052
+ indexPrice: orderType === 'OPEN_MARKET'
1053
+ ? parseValue(fields.index_price)
1054
+ : parseValue(fields.limited_index_price?.fields?.price || fields.limited_index_price),
1055
+ collateralPriceThreshold: fields.collateral_price_threshold ? parseValue(fields.collateral_price_threshold) : 0,
1056
+ // New index price threshold
1057
+ indexPriceThreshold: fields.index_price_threshold ? parseValue(fields.index_price_threshold) : undefined,
1040
1058
  feeAmount: BigInt(fields.fee),
1041
1059
  long: dataType.includes('::market::LONG'),
1042
1060
  orderType,
1043
1061
  createdAt: parseValue(fields.created_at),
1044
- v11Order: !fields.limited_index_price.fields.price,
1062
+ v11Order: !fields.limited_index_price?.fields?.price,
1063
+ // New: referrer and scard fields
1064
+ referrer: fields.referrer,
1065
+ scardId: (
1066
+ fields.scard_id?.fields?.some?.fields?.id
1067
+ || fields.scard_id?.fields?.value?.fields?.id
1068
+ || fields.scard_id?.fields?.id
1069
+ || fields.scard_id?.id
1070
+ ),
1071
+ scardRebateRate: (() => {
1072
+ const inner = fields.scard_rebate_rate?.fields?.some ?? fields.scard_rebate_rate?.fields?.value
1073
+ return inner ? parseValue(inner) : undefined
1074
+ })(),
1045
1075
  }
1046
1076
 
1047
- if (orderType === 'OPEN_POSITION') {
1077
+ if (orderType === 'OPEN_POSITION' || orderType === 'OPEN_MARKET') {
1048
1078
  ret.openOrder = {
1049
1079
  reserveAmount: BigInt(fields.reserve_amount),
1050
1080
  collateralAmount: BigInt(fields.collateral),
1051
1081
  openAmount: BigInt(fields.open_amount),
1082
+ // New: position_config from OpenMarketOrder
1083
+ positionConfig: fields.position_config?.fields
1084
+ ? {
1085
+ decreaseFeeBps: parseValue(fields.position_config.fields.decrease_fee_bps),
1086
+ liquidationBonus: parseValue(fields.position_config.fields.liquidation_bonus),
1087
+ liquidationThreshold: parseValue(fields.position_config.fields.liquidation_threshold),
1088
+ maxLeverage: parseValue(fields.position_config.fields.max_leverage),
1089
+ minHoldingDuration: parseValue(fields.position_config.fields.min_holding_duration),
1090
+ openFeeBps: parseValue(fields.position_config.fields.open_fee_bps),
1091
+ maxReservedMultiplier: parseValue(fields.position_config.fields.max_reserved_multiplier),
1092
+ minCollateralValue: parseValue(fields.position_config.fields.min_collateral_value),
1093
+ }
1094
+ : undefined,
1052
1095
  }
1053
1096
  }
1054
- else {
1097
+ else if (orderType === 'DECREASE_POSITION' || orderType === 'DECREASE_MARKET') {
1055
1098
  ret.decreaseOrder = {
1056
1099
  decreaseAmount: BigInt(fields.decrease_amount),
1057
1100
  takeProfit: fields.take_profit,
@@ -1178,7 +1178,6 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
1178
1178
  }
1179
1179
 
1180
1180
  let tx = new Transaction()
1181
- const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
1182
1181
 
1183
1182
  const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage)
1184
1183
  const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage)
@@ -1388,7 +1387,6 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
1388
1387
  relayerFee = BigInt(0.5),
1389
1388
  } = position
1390
1389
  let innerIsTakeProfitOrder = isTakeProfitOrder
1391
- const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
1392
1390
 
1393
1391
  const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage)
1394
1392
  const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage)
@@ -2004,8 +2002,6 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
2004
2002
  itemId: scard,
2005
2003
  })
2006
2004
 
2007
- const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
2008
-
2009
2005
  const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage)
2010
2006
  const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage)
2011
2007
  const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage)
@@ -2269,7 +2265,6 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
2269
2265
  coinObjects = [],
2270
2266
  } = position
2271
2267
  let innerIsTakeProfitOrder = isTakeProfitOrder
2272
- const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
2273
2268
 
2274
2269
  const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage)
2275
2270
  const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage)
@@ -2572,7 +2567,7 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
2572
2567
  indexToken: string,
2573
2568
  long: boolean,
2574
2569
  tx: Transaction,
2575
- isV11Order?: boolean,
2570
+ _isV11Order?: boolean,
2576
2571
  ): void {
2577
2572
  const funcName = 'clear_open_market_order'
2578
2573
  tx.moveCall({
@@ -2616,7 +2611,7 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
2616
2611
  indexToken: string,
2617
2612
  long: boolean,
2618
2613
  tx: Transaction,
2619
- isV11Order?: boolean,
2614
+ _isV11Order?: boolean,
2620
2615
  ): void {
2621
2616
  const funcName = 'clear_decrease_market_order'
2622
2617
  tx.moveCall({