zo-sdk 0.1.8 → 0.1.9

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 (42) hide show
  1. package/dist/abstract/BaseAPI.cjs +10 -0
  2. package/dist/abstract/BaseAPI.cjs.map +1 -1
  3. package/dist/abstract/BaseAPI.d.cts +10 -3
  4. package/dist/abstract/BaseAPI.d.cts.map +1 -1
  5. package/dist/abstract/BaseAPI.d.mts +10 -3
  6. package/dist/abstract/BaseAPI.d.mts.map +1 -1
  7. package/dist/abstract/BaseAPI.mjs +10 -0
  8. package/dist/abstract/BaseAPI.mjs.map +1 -1
  9. package/dist/implementations/SLPAPI.cjs +110 -38
  10. package/dist/implementations/SLPAPI.cjs.map +1 -1
  11. package/dist/implementations/SLPAPI.d.cts +9 -9
  12. package/dist/implementations/SLPAPI.d.cts.map +1 -1
  13. package/dist/implementations/SLPAPI.d.mts +9 -9
  14. package/dist/implementations/SLPAPI.d.mts.map +1 -1
  15. package/dist/implementations/SLPAPI.mjs +110 -38
  16. package/dist/implementations/SLPAPI.mjs.map +1 -1
  17. package/dist/implementations/USDZAPI.cjs +102 -40
  18. package/dist/implementations/USDZAPI.cjs.map +1 -1
  19. package/dist/implementations/USDZAPI.d.cts +9 -9
  20. package/dist/implementations/USDZAPI.d.cts.map +1 -1
  21. package/dist/implementations/USDZAPI.d.mts +9 -9
  22. package/dist/implementations/USDZAPI.d.mts.map +1 -1
  23. package/dist/implementations/USDZAPI.mjs +102 -40
  24. package/dist/implementations/USDZAPI.mjs.map +1 -1
  25. package/dist/implementations/ZLPAPI.cjs +100 -38
  26. package/dist/implementations/ZLPAPI.cjs.map +1 -1
  27. package/dist/implementations/ZLPAPI.d.cts +9 -9
  28. package/dist/implementations/ZLPAPI.d.cts.map +1 -1
  29. package/dist/implementations/ZLPAPI.d.mts +9 -9
  30. package/dist/implementations/ZLPAPI.d.mts.map +1 -1
  31. package/dist/implementations/ZLPAPI.mjs +100 -38
  32. package/dist/implementations/ZLPAPI.mjs.map +1 -1
  33. package/dist/interfaces/base.d.cts +4 -4
  34. package/dist/interfaces/base.d.cts.map +1 -1
  35. package/dist/interfaces/base.d.mts +4 -4
  36. package/dist/interfaces/base.d.mts.map +1 -1
  37. package/package.json +1 -1
  38. package/src/abstract/BaseAPI.ts +17 -3
  39. package/src/implementations/SLPAPI.ts +169 -33
  40. package/src/implementations/USDZAPI.ts +174 -36
  41. package/src/implementations/ZLPAPI.ts +172 -31
  42. package/src/interfaces/base.ts +8 -3
@@ -216,17 +216,13 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
216
216
  relayerFee = BigInt(0.5),
217
217
  referralAddress?: string,
218
218
  sender?: string,
219
+ sponsoredTx?: boolean,
220
+ suiCoinObjectsForPythUpdate?: string[],
219
221
  ): Promise<Transaction> {
220
222
  let tx = new Transaction()
221
223
  if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
222
224
  tx = await this.addReferral(referralAddress, tx)
223
225
  }
224
- tx = await this.initOracleTxb([collateralToken, indexToken], tx)
225
- const coinObject = this.processCoins(tx, collateralToken, coinObjects)
226
- const [depositObject, feeObject] = tx.splitCoins(coinObject, [
227
- tx.pure.u64(collateralAmount),
228
- tx.pure.u64(relayerFee),
229
- ])
230
226
 
231
227
  const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
232
228
  const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage)
@@ -248,6 +244,26 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
248
244
  itemId: scard,
249
245
  })
250
246
 
247
+ // Handle oracle initialization and coin processing
248
+ let suiCoinObject
249
+ if (sponsoredTx) {
250
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
251
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject)
252
+ }
253
+ else {
254
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx)
255
+ }
256
+
257
+ // Process coin splitting
258
+ const [depositObject, feeObject] = this.processCoinSplitting(
259
+ tx,
260
+ collateralToken,
261
+ coinObjects,
262
+ [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)],
263
+ sponsoredTx,
264
+ suiCoinObject,
265
+ )
266
+
251
267
  tx.moveCall({
252
268
  target: `${this.consts.zoCore.package}::market::open_position_with_scard`,
253
269
  typeArguments: [
@@ -304,11 +320,14 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
304
320
  collateralSlippage = 0.5,
305
321
  relayerFee = BigInt(0.5),
306
322
  coinObjects?: string[],
323
+ sponsoredTx?: boolean,
324
+ suiCoinObjectsForPythUpdate?: string[],
307
325
  ): Promise<Transaction> {
308
326
  if (!coinObjects) {
309
327
  throw new Error(`${this.constructor.name}: coinObjects is required`)
310
328
  }
311
- const tx = await this.initOracleTxb([collateralToken, indexToken])
329
+
330
+ let tx = new Transaction()
312
331
 
313
332
  const kioskTx = new KioskTransaction({
314
333
  transaction: tx,
@@ -322,8 +341,6 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
322
341
  })
323
342
 
324
343
  const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
325
- const coinObject = this.processCoins(tx, collateralToken, coinObjects || [])
326
- const feeObject = tx.splitCoins(coinObject, [tx.pure.u64(relayerFee)])
327
344
 
328
345
  const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage)
329
346
  const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage)
@@ -336,6 +353,26 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
336
353
  isTakeProfitOrder = true
337
354
  }
338
355
 
356
+ // Handle oracle initialization and coin processing
357
+ let suiCoinObject
358
+ if (sponsoredTx) {
359
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
360
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject)
361
+ }
362
+ else {
363
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx)
364
+ }
365
+
366
+ // Process coin splitting
367
+ const [feeObject] = this.processCoinSplitting(
368
+ tx,
369
+ collateralToken,
370
+ coinObjects,
371
+ [tx.pure.u64(relayerFee)],
372
+ sponsoredTx,
373
+ suiCoinObject,
374
+ )
375
+
339
376
  tx.moveCall({
340
377
  target: `${this.consts.zoCore.package}::market::decrease_position_with_scard`,
341
378
  typeArguments: [
@@ -394,11 +431,22 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
394
431
  kioskCap: KioskOwnerCap,
395
432
  scard: string,
396
433
  tx?: Transaction,
434
+ sponsoredTx?: boolean,
435
+ suiCoinObjectsForPythUpdate?: string[],
397
436
  ): Promise<Transaction> {
398
437
  if (!tx) {
399
438
  tx = new Transaction()
400
439
  }
401
- tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx)
440
+
441
+ // Handle oracle initialization and coin processing
442
+ let suiCoinObject
443
+ if (sponsoredTx) {
444
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
445
+ tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx, true, suiCoinObject)
446
+ }
447
+ else {
448
+ tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx)
449
+ }
402
450
 
403
451
  const kioskTx = new KioskTransaction({
404
452
  transaction: tx,
@@ -430,8 +478,6 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
430
478
  } = position
431
479
  let innerIsTakeProfitOrder = isTakeProfitOrder
432
480
  const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
433
- const coinObject = this.processCoins(tx, collateralToken, coinObjects)
434
- const feeObject = tx.splitCoins(coinObject, [tx.pure.u64(relayerFee)])
435
481
 
436
482
  const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage)
437
483
  const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage)
@@ -444,6 +490,16 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
444
490
  innerIsTakeProfitOrder = true
445
491
  }
446
492
 
493
+ // Process coin splitting
494
+ const [feeObject] = this.processCoinSplitting(
495
+ tx,
496
+ collateralToken,
497
+ coinObjects,
498
+ [tx.pure.u64(relayerFee)],
499
+ sponsoredTx,
500
+ suiCoinObject,
501
+ )
502
+
447
503
  tx.moveCall({
448
504
  target: `${this.consts.zoCore.package}::market::decrease_position_with_scard`,
449
505
  typeArguments: [
@@ -494,7 +550,6 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
494
550
  sender?: string,
495
551
  sponsoredTx?: boolean,
496
552
  suiCoinObjectsForPythUpdate?: string[],
497
- isDepositingSui?: boolean,
498
553
  ): Promise<Transaction> {
499
554
  let tx = new Transaction()
500
555
 
@@ -512,7 +567,7 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
512
567
  tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject)
513
568
 
514
569
  // Process deposit coins
515
- const depositObject = isDepositingSui
570
+ const depositObject = coin === 'sui'
516
571
  ? tx.splitCoins(suiCoinObject, [tx.pure.u64(amount)])[0]
517
572
  : tx.splitCoins(this.processCoins(tx, coin, coinObjects, true), [tx.pure.u64(amount)])[0]
518
573
 
@@ -650,32 +705,48 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
650
705
  collateralPrice: number,
651
706
  isLimitOrder?: boolean,
652
707
  isIocOrder?: boolean,
653
- pricesSlippage?: number,
654
- collateralSlippage?: number,
655
- relayerFee?: bigint,
708
+ pricesSlippage = 0.003,
709
+ collateralSlippage = 0.5,
710
+ relayerFee = BigInt(0.5),
656
711
  referralAddress?: string,
657
712
  sender?: string,
713
+ sponsoredTx?: boolean,
714
+ suiCoinObjectsForPythUpdate?: string[],
658
715
  ): Promise<Transaction> {
659
716
  let tx = new Transaction()
660
717
  if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
661
718
  tx = await this.addReferral(referralAddress, tx)
662
719
  }
663
- tx = await this.initOracleTxb([collateralToken, indexToken], tx)
664
- const coinObject = this.processCoins(tx, collateralToken, coinObjects)
665
- const [depositObject, feeObject] = tx.splitCoins(coinObject, [
666
- tx.pure.u64(collateralAmount),
667
- tx.pure.u64(relayerFee || BigInt(0.5)),
668
- ])
669
720
 
670
721
  const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
671
- const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage || 0.003)
672
- const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage || 0.5)
722
+ const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage)
723
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage)
673
724
 
674
725
  let allowTrade = ALLOW_TRADE_MUST_TRADE
675
726
  if (isLimitOrder) {
676
727
  allowTrade = isIocOrder ? ALLOW_TRADE_NO_TRADE : ALLOW_TRADE_CAN_TRADE
677
728
  }
678
729
 
730
+ // Handle oracle initialization and coin processing
731
+ let suiCoinObject
732
+ if (sponsoredTx) {
733
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
734
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject)
735
+ }
736
+ else {
737
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx)
738
+ }
739
+
740
+ // Process coin splitting
741
+ const [depositObject, feeObject] = this.processCoinSplitting(
742
+ tx,
743
+ collateralToken,
744
+ coinObjects,
745
+ [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)],
746
+ sponsoredTx,
747
+ suiCoinObject,
748
+ )
749
+
679
750
  tx.moveCall({
680
751
  target: `${this.consts.zoCore.package}::market::open_position`,
681
752
  typeArguments: [
@@ -723,14 +794,14 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
723
794
  collateralSlippage = 0.5,
724
795
  relayerFee = BigInt(0.5),
725
796
  coinObjects?: string[],
797
+ sponsoredTx?: boolean,
798
+ suiCoinObjectsForPythUpdate?: string[],
726
799
  ): Promise<Transaction> {
727
800
  if (!coinObjects) {
728
801
  throw new Error(`${this.constructor.name}: coinObjects is required`)
729
802
  }
730
- const tx = await this.initOracleTxb([collateralToken, indexToken])
803
+ let tx = new Transaction()
731
804
  const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
732
- const coinObject = this.processCoins(tx, collateralToken, coinObjects || [])
733
- const feeObject = tx.splitCoins(coinObject, [tx.pure.u64(relayerFee)])
734
805
 
735
806
  const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage)
736
807
  const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage)
@@ -743,6 +814,26 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
743
814
  isTakeProfitOrder = true
744
815
  }
745
816
 
817
+ // Handle oracle initialization and coin processing
818
+ let suiCoinObject
819
+ if (sponsoredTx) {
820
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
821
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject)
822
+ }
823
+ else {
824
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx)
825
+ }
826
+
827
+ // Process coin splitting
828
+ const [feeObject] = this.processCoinSplitting(
829
+ tx,
830
+ collateralToken,
831
+ coinObjects,
832
+ [tx.pure.u64(relayerFee)],
833
+ sponsoredTx,
834
+ suiCoinObject,
835
+ )
836
+
746
837
  tx.moveCall({
747
838
  target: `${this.consts.zoCore.package}::market::decrease_position`,
748
839
  typeArguments: [
@@ -787,11 +878,20 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
787
878
  collateralSlippage?: number
788
879
  relayerFee?: bigint
789
880
  coinObjects?: string[]
790
- }>, tx?: Transaction): Promise<Transaction> {
881
+ }>, tx?: Transaction, sponsoredTx?: boolean, suiCoinObjectsForPythUpdate?: string[]): Promise<Transaction> {
791
882
  if (!tx) {
792
883
  tx = new Transaction()
793
884
  }
794
- tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx)
885
+
886
+ // Handle oracle initialization and coin processing
887
+ let suiCoinObject
888
+ if (sponsoredTx) {
889
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
890
+ tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx, true, suiCoinObject)
891
+ }
892
+ else {
893
+ tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx)
894
+ }
795
895
 
796
896
  for (const position of positions) {
797
897
  const {
@@ -812,8 +912,6 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
812
912
  } = position
813
913
  let innerIsTakeProfitOrder = isTakeProfitOrder
814
914
  const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
815
- const coinObject = this.processCoins(tx, collateralToken, coinObjects)
816
- const feeObject = tx.splitCoins(coinObject, [tx.pure.u64(relayerFee)])
817
915
 
818
916
  const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage)
819
917
  const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage)
@@ -826,6 +924,16 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
826
924
  innerIsTakeProfitOrder = true
827
925
  }
828
926
 
927
+ // Process coin splitting
928
+ const [feeObject] = this.processCoinSplitting(
929
+ tx,
930
+ collateralToken,
931
+ coinObjects,
932
+ [tx.pure.u64(relayerFee)],
933
+ sponsoredTx,
934
+ suiCoinObject,
935
+ )
936
+
829
937
  tx.moveCall({
830
938
  target: `${this.consts.zoCore.package}::market::decrease_position`,
831
939
  typeArguments: [
@@ -865,10 +973,29 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
865
973
  amount: number,
866
974
  coinObjects: string[],
867
975
  long: boolean,
976
+ sponsoredTx?: boolean,
977
+ suiCoinObjectsForPythUpdate?: string[],
868
978
  ): Promise<Transaction> {
869
- const tx = await this.initOracleTxb([collateralToken, indexToken])
870
- const coinObject = this.processCoins(tx, collateralToken, coinObjects)
871
- const [depositObject] = tx.splitCoins(coinObject, [tx.pure.u64(amount)])
979
+ let tx = new Transaction()
980
+ // Handle oracle initialization and coin processing
981
+ let suiCoinObject
982
+ if (sponsoredTx) {
983
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
984
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject)
985
+ }
986
+ else {
987
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx)
988
+ }
989
+
990
+ // Process coin splitting
991
+ const [depositObject] = this.processCoinSplitting(
992
+ tx,
993
+ collateralToken,
994
+ coinObjects,
995
+ [tx.pure.u64(amount)],
996
+ sponsoredTx,
997
+ suiCoinObject,
998
+ )
872
999
 
873
1000
  tx.moveCall({
874
1001
  target: `${this.consts.zoCore.package}::market::pledge_in_position`,
@@ -889,8 +1016,19 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
889
1016
  indexToken: string,
890
1017
  amount: number,
891
1018
  long: boolean,
1019
+ sponsoredTx?: boolean,
1020
+ suiCoinObjectsForPythUpdate?: string[],
892
1021
  ): Promise<Transaction> {
893
- const tx = await this.initOracleTxb([collateralToken, indexToken])
1022
+ let tx = new Transaction()
1023
+ // Handle oracle initialization and coin processing
1024
+ let suiCoinObject
1025
+ if (sponsoredTx) {
1026
+ suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
1027
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject)
1028
+ }
1029
+ else {
1030
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx)
1031
+ }
894
1032
  const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
895
1033
 
896
1034
  tx.moveCall({