@zofai/zo-sdk 0.2.9 → 0.2.10

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 (108) hide show
  1. package/dist/abstract/BaseAPI.cjs +7 -1
  2. package/dist/abstract/BaseAPI.cjs.map +1 -1
  3. package/dist/abstract/BaseAPI.d.cts +8 -7
  4. package/dist/abstract/BaseAPI.d.cts.map +1 -1
  5. package/dist/abstract/BaseAPI.d.mts +8 -7
  6. package/dist/abstract/BaseAPI.d.mts.map +1 -1
  7. package/dist/abstract/BaseAPI.mjs +7 -1
  8. package/dist/abstract/BaseAPI.mjs.map +1 -1
  9. package/dist/api.cjs +12 -12
  10. package/dist/api.cjs.map +1 -1
  11. package/dist/api.mjs +12 -12
  12. package/dist/api.mjs.map +1 -1
  13. package/dist/coins.cjs +74 -0
  14. package/dist/coins.cjs.map +1 -0
  15. package/dist/coins.d.cts +37 -0
  16. package/dist/coins.d.cts.map +1 -0
  17. package/dist/coins.d.mts +37 -0
  18. package/dist/coins.d.mts.map +1 -0
  19. package/dist/coins.mjs +67 -0
  20. package/dist/coins.mjs.map +1 -0
  21. package/dist/implementations/SLPAPI.cjs +192 -100
  22. package/dist/implementations/SLPAPI.cjs.map +1 -1
  23. package/dist/implementations/SLPAPI.d.cts +23 -23
  24. package/dist/implementations/SLPAPI.d.cts.map +1 -1
  25. package/dist/implementations/SLPAPI.d.mts +23 -23
  26. package/dist/implementations/SLPAPI.d.mts.map +1 -1
  27. package/dist/implementations/SLPAPI.mjs +192 -100
  28. package/dist/implementations/SLPAPI.mjs.map +1 -1
  29. package/dist/implementations/SLPDataAPI.cjs +2 -2
  30. package/dist/implementations/SLPDataAPI.cjs.map +1 -1
  31. package/dist/implementations/SLPDataAPI.mjs +2 -2
  32. package/dist/implementations/SLPDataAPI.mjs.map +1 -1
  33. package/dist/implementations/USDZAPI.cjs +176 -92
  34. package/dist/implementations/USDZAPI.cjs.map +1 -1
  35. package/dist/implementations/USDZAPI.d.cts +21 -21
  36. package/dist/implementations/USDZAPI.d.cts.map +1 -1
  37. package/dist/implementations/USDZAPI.d.mts +21 -21
  38. package/dist/implementations/USDZAPI.d.mts.map +1 -1
  39. package/dist/implementations/USDZAPI.mjs +176 -92
  40. package/dist/implementations/USDZAPI.mjs.map +1 -1
  41. package/dist/implementations/ZBTCVCAPI.cjs +84 -46
  42. package/dist/implementations/ZBTCVCAPI.cjs.map +1 -1
  43. package/dist/implementations/ZBTCVCAPI.d.cts +11 -11
  44. package/dist/implementations/ZBTCVCAPI.d.cts.map +1 -1
  45. package/dist/implementations/ZBTCVCAPI.d.mts +11 -11
  46. package/dist/implementations/ZBTCVCAPI.d.mts.map +1 -1
  47. package/dist/implementations/ZBTCVCAPI.mjs +84 -46
  48. package/dist/implementations/ZBTCVCAPI.mjs.map +1 -1
  49. package/dist/implementations/ZLPAPI.cjs +192 -100
  50. package/dist/implementations/ZLPAPI.cjs.map +1 -1
  51. package/dist/implementations/ZLPAPI.d.cts +23 -23
  52. package/dist/implementations/ZLPAPI.d.cts.map +1 -1
  53. package/dist/implementations/ZLPAPI.d.mts +23 -23
  54. package/dist/implementations/ZLPAPI.d.mts.map +1 -1
  55. package/dist/implementations/ZLPAPI.mjs +192 -100
  56. package/dist/implementations/ZLPAPI.mjs.map +1 -1
  57. package/dist/index.cjs +1 -0
  58. package/dist/index.cjs.map +1 -1
  59. package/dist/index.d.cts +1 -0
  60. package/dist/index.d.cts.map +1 -1
  61. package/dist/index.d.mts +1 -0
  62. package/dist/index.d.mts.map +1 -1
  63. package/dist/index.mjs +1 -0
  64. package/dist/index.mjs.map +1 -1
  65. package/dist/interfaces/base.d.cts +25 -21
  66. package/dist/interfaces/base.d.cts.map +1 -1
  67. package/dist/interfaces/base.d.mts +25 -21
  68. package/dist/interfaces/base.d.mts.map +1 -1
  69. package/dist/interfaces/slp.d.cts +1 -1
  70. package/dist/interfaces/slp.d.cts.map +1 -1
  71. package/dist/interfaces/slp.d.mts +1 -1
  72. package/dist/interfaces/slp.d.mts.map +1 -1
  73. package/dist/interfaces/usdz.d.cts +1 -1
  74. package/dist/interfaces/usdz.d.cts.map +1 -1
  75. package/dist/interfaces/usdz.d.mts +1 -1
  76. package/dist/interfaces/usdz.d.mts.map +1 -1
  77. package/dist/interfaces/zbtcvc.d.cts +1 -1
  78. package/dist/interfaces/zbtcvc.d.cts.map +1 -1
  79. package/dist/interfaces/zbtcvc.d.mts +1 -1
  80. package/dist/interfaces/zbtcvc.d.mts.map +1 -1
  81. package/dist/interfaces/zlp.d.cts +1 -1
  82. package/dist/interfaces/zlp.d.cts.map +1 -1
  83. package/dist/interfaces/zlp.d.mts +1 -1
  84. package/dist/interfaces/zlp.d.mts.map +1 -1
  85. package/dist/oracle.cjs +27 -22
  86. package/dist/oracle.cjs.map +1 -1
  87. package/dist/oracle.d.cts +13 -1
  88. package/dist/oracle.d.cts.map +1 -1
  89. package/dist/oracle.d.mts +13 -1
  90. package/dist/oracle.d.mts.map +1 -1
  91. package/dist/oracle.mjs +27 -22
  92. package/dist/oracle.mjs.map +1 -1
  93. package/package.json +1 -1
  94. package/src/abstract/BaseAPI.ts +10 -8
  95. package/src/api.ts +12 -12
  96. package/src/coins.ts +115 -0
  97. package/src/implementations/SLPAPI.ts +199 -115
  98. package/src/implementations/SLPDataAPI.ts +2 -2
  99. package/src/implementations/USDZAPI.ts +184 -94
  100. package/src/implementations/ZBTCVCAPI.ts +98 -52
  101. package/src/implementations/ZLPAPI.ts +199 -110
  102. package/src/index.ts +1 -0
  103. package/src/interfaces/base.ts +13 -21
  104. package/src/interfaces/slp.ts +0 -1
  105. package/src/interfaces/usdz.ts +0 -1
  106. package/src/interfaces/zbtcvc.ts +0 -1
  107. package/src/interfaces/zlp.ts +0 -1
  108. package/src/oracle.ts +64 -28
@@ -272,7 +272,7 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
272
272
  * Valuates market using simulation (Sudo SDK specific)
273
273
  */
274
274
  public async simValuate(sender: string): Promise<number> {
275
- const tx = await this.initOracleTxb(
275
+ const { tx } = await this.initOracleTxb(
276
276
  Object.keys(this.consts.pythFeeder.feeder),
277
277
  )
278
278
  this.valuate(tx)
@@ -316,7 +316,7 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
316
316
  * Valuates only vaults (Sudo SDK specific)
317
317
  */
318
318
  public async simValuateVaults(sender: string): Promise<number> {
319
- const tx = await this.initOracleTxb(
319
+ const { tx } = await this.initOracleTxb(
320
320
  Object.keys(this.consts.sudoCore.vaults),
321
321
  )
322
322
  this.valuateVaults(tx)
@@ -150,7 +150,6 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
150
150
  referralAddress?: string,
151
151
  sender?: string,
152
152
  sponsoredTx?: boolean,
153
- suiCoinObjectsForPythUpdate?: string[],
154
153
  ): Promise<Transaction> {
155
154
  let tx = new Transaction()
156
155
  if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
@@ -180,11 +179,15 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
180
179
  // Handle oracle initialization and coin processing
181
180
  let suiCoinObject
182
181
  if (sponsoredTx) {
183
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
184
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject)
182
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
183
+ sender: this.requireSenderForSponsored(sender),
184
+ additionalSuiAmount: collateralToken === 'sui' ? collateralAmount + relayerFee : 0n,
185
+ })
186
+ tx = oracle.tx
187
+ suiCoinObject = oracle.suiCoinObject
185
188
  }
186
189
  else {
187
- tx = await this.initOracleTxb([collateralToken, indexToken], tx)
190
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx
188
191
  }
189
192
 
190
193
  // Process coin splitting
@@ -256,7 +259,6 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
256
259
  sender?: string,
257
260
  tx?: Transaction,
258
261
  sponsoredTx?: boolean,
259
- suiCoinObjectsForPythUpdate?: string[],
260
262
  ): Promise<Transaction> {
261
263
  if (!tx) {
262
264
  tx = new Transaction()
@@ -288,11 +290,15 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
288
290
  // Handle oracle initialization and coin processing
289
291
  let suiCoinObject
290
292
  if (sponsoredTx) {
291
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
292
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject)
293
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
294
+ sender: this.requireSenderForSponsored(sender),
295
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
296
+ })
297
+ tx = oracle.tx
298
+ suiCoinObject = oracle.suiCoinObject
293
299
  }
294
300
  else {
295
- tx = await this.initOracleTxb([collateralToken, indexToken], tx)
301
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx
296
302
  }
297
303
 
298
304
  // Process coin splitting
@@ -355,7 +361,7 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
355
361
  relayerFee = BigInt(0.5),
356
362
  coinObjects?: string[],
357
363
  sponsoredTx?: boolean,
358
- suiCoinObjectsForPythUpdate?: string[],
364
+ sender?: string,
359
365
  ): Promise<Transaction> {
360
366
  if (!coinObjects) {
361
367
  throw new Error(`${this.constructor.name}: coinObjects is required`)
@@ -390,11 +396,15 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
390
396
  // Handle oracle initialization and coin processing
391
397
  let suiCoinObject
392
398
  if (sponsoredTx) {
393
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
394
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject)
399
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
400
+ sender: this.requireSenderForSponsored(sender),
401
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
402
+ })
403
+ tx = oracle.tx
404
+ suiCoinObject = oracle.suiCoinObject
395
405
  }
396
406
  else {
397
- tx = await this.initOracleTxb([collateralToken, indexToken], tx)
407
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx
398
408
  }
399
409
 
400
410
  // Process coin splitting
@@ -466,7 +476,7 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
466
476
  scard: string,
467
477
  tx?: Transaction,
468
478
  sponsoredTx?: boolean,
469
- suiCoinObjectsForPythUpdate?: string[],
479
+ sender?: string,
470
480
  ): Promise<Transaction> {
471
481
  if (!tx) {
472
482
  tx = new Transaction()
@@ -475,11 +485,20 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
475
485
  // Handle oracle initialization and coin processing
476
486
  let suiCoinObject
477
487
  if (sponsoredTx) {
478
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
479
- tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx, true, suiCoinObject)
488
+ const oracle = await this.initOracleTxb(
489
+ positions.flatMap(position => [position.collateralToken, position.indexToken]),
490
+ tx,
491
+ true,
492
+ { sender: this.requireSenderForSponsored(sender) },
493
+ )
494
+ tx = oracle.tx
495
+ suiCoinObject = oracle.suiCoinObject
480
496
  }
481
497
  else {
482
- tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx)
498
+ tx = (await this.initOracleTxb(
499
+ positions.flatMap(position => [position.collateralToken, position.indexToken]),
500
+ tx,
501
+ )).tx
483
502
  }
484
503
 
485
504
  const kioskTx = new KioskTransaction({
@@ -593,7 +612,6 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
593
612
  referralAddress?: string,
594
613
  sender?: string,
595
614
  sponsoredTx?: boolean,
596
- suiCoinObjectsForPythUpdate?: string[],
597
615
  ): Promise<Transaction> {
598
616
  let tx = new Transaction()
599
617
  if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
@@ -624,11 +642,15 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
624
642
  // Handle oracle initialization and coin processing
625
643
  let suiCoinObject
626
644
  if (sponsoredTx) {
627
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
628
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject)
645
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
646
+ sender: this.requireSenderForSponsored(sender),
647
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
648
+ })
649
+ tx = oracle.tx
650
+ suiCoinObject = oracle.suiCoinObject
629
651
  }
630
652
  else {
631
- tx = await this.initOracleTxb([collateralToken, indexToken], tx)
653
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx
632
654
  }
633
655
 
634
656
  // Process coin splitting
@@ -701,7 +723,6 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
701
723
  sender?: string,
702
724
  tx?: Transaction,
703
725
  sponsoredTx?: boolean,
704
- suiCoinObjectsForPythUpdate?: string[],
705
726
  ): Promise<Transaction> {
706
727
  if (!tx) {
707
728
  tx = new Transaction()
@@ -734,11 +755,15 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
734
755
  // Handle oracle initialization and coin processing
735
756
  let suiCoinObject
736
757
  if (sponsoredTx) {
737
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
738
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject)
758
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
759
+ sender: this.requireSenderForSponsored(sender),
760
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
761
+ })
762
+ tx = oracle.tx
763
+ suiCoinObject = oracle.suiCoinObject
739
764
  }
740
765
  else {
741
- tx = await this.initOracleTxb([collateralToken, indexToken], tx)
766
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx
742
767
  }
743
768
 
744
769
  // Process coin splitting
@@ -801,7 +826,7 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
801
826
  relayerFee = BigInt(0.5),
802
827
  coinObjects?: string[],
803
828
  sponsoredTx?: boolean,
804
- suiCoinObjectsForPythUpdate?: string[],
829
+ sender?: string,
805
830
  ): Promise<Transaction> {
806
831
  if (!coinObjects) {
807
832
  throw new Error(`${this.constructor.name}: coinObjects is required`)
@@ -835,11 +860,15 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
835
860
  // Handle oracle initialization and coin processing
836
861
  let suiCoinObject
837
862
  if (sponsoredTx) {
838
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
839
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject)
863
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
864
+ sender: this.requireSenderForSponsored(sender),
865
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
866
+ })
867
+ tx = oracle.tx
868
+ suiCoinObject = oracle.suiCoinObject
840
869
  }
841
870
  else {
842
- tx = await this.initOracleTxb([collateralToken, indexToken], tx)
871
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx
843
872
  }
844
873
 
845
874
  // Process coin splitting
@@ -910,17 +939,24 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
910
939
  scard: string,
911
940
  tx?: Transaction,
912
941
  sponsoredTx?: boolean,
913
- suiCoinObjectsForPythUpdate?: string[],
942
+ sender?: string,
914
943
  feeObjects?: TransactionObjectArgument[],
915
944
  ): Promise<Transaction> {
916
- const transaction = tx ?? new Transaction()
945
+ let transaction = tx ?? new Transaction()
917
946
 
918
947
  // Handle oracle initialization and coin processing
919
948
  const tokens = positions.flatMap(position => [position.collateralToken, position.indexToken])
920
- const suiCoinObject = sponsoredTx
921
- ? this.processCoins(transaction, 'sui', suiCoinObjectsForPythUpdate || [], true)
922
- : undefined
923
- await this.initOracleTxb(tokens, transaction, !!sponsoredTx, suiCoinObject)
949
+ let suiCoinObject
950
+ if (sponsoredTx) {
951
+ const oracle = await this.initOracleTxb(tokens, transaction, true, {
952
+ sender: this.requireSenderForSponsored(sender),
953
+ })
954
+ transaction = oracle.tx
955
+ suiCoinObject = oracle.suiCoinObject
956
+ }
957
+ else {
958
+ transaction = (await this.initOracleTxb(tokens, transaction, false)).tx
959
+ }
924
960
 
925
961
  if (!feeObjects || feeObjects.length !== positions.length) {
926
962
  throw new Error('feeObjects must be provided (pre-processed via buildFeeCoinObjects) and match positions length')
@@ -1015,7 +1051,6 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
1015
1051
  referralAddress?: string,
1016
1052
  sender?: string,
1017
1053
  sponsoredTx?: boolean,
1018
- suiCoinObjectsForPythUpdate?: string[],
1019
1054
  ): Promise<Transaction> {
1020
1055
  let tx = new Transaction()
1021
1056
 
@@ -1029,12 +1064,16 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
1029
1064
 
1030
1065
  // Handle sponsored transaction case
1031
1066
  if (sponsoredTx) {
1032
- const suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
1033
- tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject)
1067
+ const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
1068
+ sender: this.requireSenderForSponsored(sender),
1069
+ additionalSuiAmount: coin === 'sui' ? BigInt(amount) : 0n,
1070
+ })
1071
+ tx = oracle.tx
1072
+ const { suiCoinObject } = oracle
1034
1073
 
1035
1074
  // Process deposit coins
1036
1075
  const depositObject = coin === 'sui'
1037
- ? tx.splitCoins(suiCoinObject, [tx.pure.u64(amount)])[0]
1076
+ ? tx.splitCoins(suiCoinObject!, [tx.pure.u64(amount)])[0]
1038
1077
  : tx.splitCoins(this.processCoins(tx, coin, coinObjects, true), [tx.pure.u64(amount)])[0]
1039
1078
 
1040
1079
  const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx)
@@ -1055,7 +1094,7 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
1055
1094
  }
1056
1095
 
1057
1096
  // Handle non-sponsored transaction case
1058
- tx = await this.initOracleTxb(pythFeederKeys, tx)
1097
+ tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx
1059
1098
  const depositObject = tx.splitCoins(
1060
1099
  this.processCoins(tx, coin, coinObjects, false),
1061
1100
  [tx.pure.u64(amount)],
@@ -1093,7 +1132,6 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
1093
1132
  sender?: string,
1094
1133
  tx?: Transaction,
1095
1134
  sponsoredTx?: boolean,
1096
- suiCoinObjectsForPythUpdate?: string[],
1097
1135
  ): Promise<TransactionObjectArgument> {
1098
1136
  if (!tx) {
1099
1137
  tx = new Transaction()
@@ -1109,12 +1147,16 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
1109
1147
 
1110
1148
  // Handle sponsored transaction case
1111
1149
  if (sponsoredTx) {
1112
- const suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
1113
- tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject)
1150
+ const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
1151
+ sender: this.requireSenderForSponsored(sender),
1152
+ additionalSuiAmount: coin === 'sui' ? BigInt(amount) : 0n,
1153
+ })
1154
+ tx = oracle.tx
1155
+ const { suiCoinObject } = oracle
1114
1156
 
1115
1157
  // Process deposit coins
1116
1158
  const depositObject = coin === 'sui'
1117
- ? tx.splitCoins(suiCoinObject, [tx.pure.u64(amount)])[0]
1159
+ ? tx.splitCoins(suiCoinObject!, [tx.pure.u64(amount)])[0]
1118
1160
  : tx.splitCoins(this.processCoins(tx, coin, coinObjects, true), [tx.pure.u64(amount)])[0]
1119
1161
 
1120
1162
  const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx)
@@ -1135,7 +1177,7 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
1135
1177
  }
1136
1178
 
1137
1179
  // Handle non-sponsored transaction case
1138
- tx = await this.initOracleTxb(pythFeederKeys, tx)
1180
+ tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx
1139
1181
  const depositObject = tx.splitCoins(
1140
1182
  this.processCoins(tx, coin, coinObjects, false),
1141
1183
  [tx.pure.u64(amount)],
@@ -1171,7 +1213,7 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
1171
1213
  amount: number,
1172
1214
  minAmountOut = 0,
1173
1215
  sponsoredTx?: boolean,
1174
- suiCoinObjectsForPythUpdate?: string[],
1216
+ sender?: string,
1175
1217
  ): Promise<Transaction> {
1176
1218
  let tx = new Transaction()
1177
1219
 
@@ -1179,11 +1221,15 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
1179
1221
  const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder)
1180
1222
 
1181
1223
  if (sponsoredTx) {
1182
- const suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
1183
- tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject)
1224
+ const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
1225
+ sender: this.requireSenderForSponsored(sender),
1226
+ additionalSuiAmount: 0n,
1227
+ })
1228
+ tx = oracle.tx
1229
+ const { suiCoinObject } = oracle
1184
1230
  }
1185
1231
  else {
1186
- tx = await this.initOracleTxb(pythFeederKeys, tx)
1232
+ tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx
1187
1233
  }
1188
1234
  const usdzCoinObject = this.processCoins(tx, 'usdz', lpCoinObjects, false)
1189
1235
  const [withdrawObject] = tx.splitCoins(usdzCoinObject, [tx.pure.u64(amount)])
@@ -1223,7 +1269,7 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
1223
1269
  // Initialize oracle transaction
1224
1270
  const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder)
1225
1271
 
1226
- tx = await this.initOracleTxb(pythFeederKeys, tx)
1272
+ tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx
1227
1273
  const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx)
1228
1274
 
1229
1275
  tx.moveCall({
@@ -1450,7 +1496,7 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
1450
1496
  fromCoinObjects: string[],
1451
1497
  minAmountOut?: number,
1452
1498
  ): Promise<Transaction> {
1453
- const tx = await this.initOracleTxb(Object.keys(this.consts.zoCore.vaults))
1499
+ const { tx } = await this.initOracleTxb(Object.keys(this.consts.zoCore.vaults))
1454
1500
  const fromCoinObject = this.processCoins(tx, fromToken, fromCoinObjects)
1455
1501
  const [fromDepositObject] = tx.splitCoins(fromCoinObject, [tx.pure.u64(fromAmount)])
1456
1502
  const vaultsValuation = this.dataAPI.valuateVaults(tx)
@@ -1491,7 +1537,7 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
1491
1537
  if (!tx) {
1492
1538
  tx = new Transaction()
1493
1539
  }
1494
- tx = await this.initOracleTxb(Object.keys(this.consts.zoCore.vaults), tx)
1540
+ tx = (await this.initOracleTxb(Object.keys(this.consts.zoCore.vaults), tx)).tx
1495
1541
  const fromCoinObject = this.processCoins(tx, fromToken, fromCoinObjects)
1496
1542
  const [fromDepositObject] = tx.splitCoins(fromCoinObject, [
1497
1543
  tx.pure.u64(fromAmount),
@@ -1537,7 +1583,6 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
1537
1583
  referralAddress?: string,
1538
1584
  sender?: string,
1539
1585
  sponsoredTx?: boolean,
1540
- suiCoinObjectsForPythUpdate?: string[],
1541
1586
  ): Promise<Transaction> {
1542
1587
  let tx = new Transaction()
1543
1588
  if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
@@ -1556,11 +1601,15 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
1556
1601
  // Handle oracle initialization and coin processing
1557
1602
  let suiCoinObject
1558
1603
  if (sponsoredTx) {
1559
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
1560
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject)
1604
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
1605
+ sender: this.requireSenderForSponsored(sender),
1606
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
1607
+ })
1608
+ tx = oracle.tx
1609
+ suiCoinObject = oracle.suiCoinObject
1561
1610
  }
1562
1611
  else {
1563
- tx = await this.initOracleTxb([collateralToken, indexToken], tx)
1612
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx
1564
1613
  }
1565
1614
 
1566
1615
  // Process coin splitting
@@ -1623,7 +1672,6 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
1623
1672
  referralAddress?: string,
1624
1673
  sender?: string,
1625
1674
  sponsoredTx?: boolean,
1626
- suiCoinObjectsForPythUpdate?: string[],
1627
1675
  ): Promise<Transaction> {
1628
1676
  let tx = new Transaction()
1629
1677
  if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
@@ -1643,11 +1691,15 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
1643
1691
  // Handle oracle initialization and coin processing
1644
1692
  let suiCoinObject
1645
1693
  if (sponsoredTx) {
1646
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
1647
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject)
1694
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
1695
+ sender: this.requireSenderForSponsored(sender),
1696
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
1697
+ })
1698
+ tx = oracle.tx
1699
+ suiCoinObject = oracle.suiCoinObject
1648
1700
  }
1649
1701
  else {
1650
- tx = await this.initOracleTxb([collateralToken, indexToken], tx)
1702
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx
1651
1703
  }
1652
1704
 
1653
1705
  // Process coin splitting
@@ -1710,7 +1762,6 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
1710
1762
  sender?: string,
1711
1763
  tx?: Transaction,
1712
1764
  sponsoredTx?: boolean,
1713
- suiCoinObjectsForPythUpdate?: string[],
1714
1765
  ): Promise<Transaction> {
1715
1766
  if (!tx) {
1716
1767
  tx = new Transaction()
@@ -1731,11 +1782,15 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
1731
1782
  // Handle oracle initialization and coin processing
1732
1783
  let suiCoinObject
1733
1784
  if (sponsoredTx) {
1734
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
1735
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject)
1785
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
1786
+ sender: this.requireSenderForSponsored(sender),
1787
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
1788
+ })
1789
+ tx = oracle.tx
1790
+ suiCoinObject = oracle.suiCoinObject
1736
1791
  }
1737
1792
  else {
1738
- tx = await this.initOracleTxb([collateralToken, indexToken], tx)
1793
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx
1739
1794
  }
1740
1795
 
1741
1796
  // Process coin splitting
@@ -1791,7 +1846,6 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
1791
1846
  sender?: string,
1792
1847
  tx?: Transaction,
1793
1848
  sponsoredTx?: boolean,
1794
- suiCoinObjectsForPythUpdate?: string[],
1795
1849
  ): Promise<Transaction> {
1796
1850
  if (!tx) {
1797
1851
  tx = new Transaction()
@@ -1813,11 +1867,15 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
1813
1867
  // Handle oracle initialization and coin processing
1814
1868
  let suiCoinObject
1815
1869
  if (sponsoredTx) {
1816
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
1817
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject)
1870
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
1871
+ sender: this.requireSenderForSponsored(sender),
1872
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
1873
+ })
1874
+ tx = oracle.tx
1875
+ suiCoinObject = oracle.suiCoinObject
1818
1876
  }
1819
1877
  else {
1820
- tx = await this.initOracleTxb([collateralToken, indexToken], tx)
1878
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx
1821
1879
  }
1822
1880
 
1823
1881
  // Process coin splitting
@@ -1871,7 +1929,7 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
1871
1929
  relayerFee = BigInt(0.5),
1872
1930
  coinObjects?: string[],
1873
1931
  sponsoredTx?: boolean,
1874
- suiCoinObjectsForPythUpdate?: string[],
1932
+ sender?: string,
1875
1933
  ): Promise<Transaction> {
1876
1934
  if (!coinObjects) {
1877
1935
  throw new Error(`${this.constructor.name}: coinObjects is required`)
@@ -1893,11 +1951,15 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
1893
1951
  // Handle oracle initialization and coin processing
1894
1952
  let suiCoinObject
1895
1953
  if (sponsoredTx) {
1896
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
1897
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject)
1954
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
1955
+ sender: this.requireSenderForSponsored(sender),
1956
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
1957
+ })
1958
+ tx = oracle.tx
1959
+ suiCoinObject = oracle.suiCoinObject
1898
1960
  }
1899
1961
  else {
1900
- tx = await this.initOracleTxb([collateralToken, indexToken], tx)
1962
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx
1901
1963
  }
1902
1964
 
1903
1965
  // Process coin splitting
@@ -1958,7 +2020,7 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
1958
2020
  relayerFee = BigInt(0.5),
1959
2021
  coinObjects?: string[],
1960
2022
  sponsoredTx?: boolean,
1961
- suiCoinObjectsForPythUpdate?: string[],
2023
+ sender?: string,
1962
2024
  ): Promise<Transaction> {
1963
2025
  if (!coinObjects) {
1964
2026
  throw new Error(`${this.constructor.name}: coinObjects is required`)
@@ -1981,11 +2043,15 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
1981
2043
  // Handle oracle initialization and coin processing
1982
2044
  let suiCoinObject
1983
2045
  if (sponsoredTx) {
1984
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
1985
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject)
2046
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
2047
+ sender: this.requireSenderForSponsored(sender),
2048
+ additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
2049
+ })
2050
+ tx = oracle.tx
2051
+ suiCoinObject = oracle.suiCoinObject
1986
2052
  }
1987
2053
  else {
1988
- tx = await this.initOracleTxb([collateralToken, indexToken], tx)
2054
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx
1989
2055
  }
1990
2056
 
1991
2057
  // Process coin splitting
@@ -2041,7 +2107,7 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
2041
2107
  collateralSlippage?: number
2042
2108
  relayerFee?: bigint
2043
2109
  coinObjects?: string[]
2044
- }>, tx?: Transaction, sponsoredTx?: boolean, suiCoinObjectsForPythUpdate?: string[]): Promise<Transaction> {
2110
+ }>, tx?: Transaction, sponsoredTx?: boolean, sender?: string): Promise<Transaction> {
2045
2111
  if (!tx) {
2046
2112
  tx = new Transaction()
2047
2113
  }
@@ -2049,11 +2115,20 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
2049
2115
  // Handle oracle initialization and coin processing
2050
2116
  let suiCoinObject
2051
2117
  if (sponsoredTx) {
2052
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
2053
- tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx, true, suiCoinObject)
2118
+ const oracle = await this.initOracleTxb(
2119
+ positions.flatMap(position => [position.collateralToken, position.indexToken]),
2120
+ tx,
2121
+ true,
2122
+ { sender: this.requireSenderForSponsored(sender) },
2123
+ )
2124
+ tx = oracle.tx
2125
+ suiCoinObject = oracle.suiCoinObject
2054
2126
  }
2055
2127
  else {
2056
- tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx)
2128
+ tx = (await this.initOracleTxb(
2129
+ positions.flatMap(position => [position.collateralToken, position.indexToken]),
2130
+ tx,
2131
+ )).tx
2057
2132
  }
2058
2133
 
2059
2134
  for (const position of positions) {
@@ -2141,15 +2216,22 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
2141
2216
  collateralSlippage?: number
2142
2217
  relayerFee?: bigint
2143
2218
  coinObjects?: string[]
2144
- }>, tx?: Transaction, sponsoredTx?: boolean, suiCoinObjectsForPythUpdate?: string[], feeObjects?: TransactionObjectArgument[]): Promise<Transaction> {
2145
- const transaction = tx ?? new Transaction()
2219
+ }>, tx?: Transaction, sponsoredTx?: boolean, sender?: string, feeObjects?: TransactionObjectArgument[]): Promise<Transaction> {
2220
+ let transaction = tx ?? new Transaction()
2146
2221
 
2147
2222
  // Handle oracle initialization and coin processing
2148
2223
  const tokens = positions.flatMap(position => [position.collateralToken, position.indexToken])
2149
- const suiCoinObject = sponsoredTx
2150
- ? this.processCoins(transaction, 'sui', suiCoinObjectsForPythUpdate || [], true)
2151
- : undefined
2152
- await this.initOracleTxb(tokens, transaction, !!sponsoredTx, suiCoinObject)
2224
+ let suiCoinObject
2225
+ if (sponsoredTx) {
2226
+ const oracle = await this.initOracleTxb(tokens, transaction, true, {
2227
+ sender: this.requireSenderForSponsored(sender),
2228
+ })
2229
+ transaction = oracle.tx
2230
+ suiCoinObject = oracle.suiCoinObject
2231
+ }
2232
+ else {
2233
+ transaction = (await this.initOracleTxb(tokens, transaction, false)).tx
2234
+ }
2153
2235
 
2154
2236
  if (!feeObjects || feeObjects.length !== positions.length) {
2155
2237
  throw new Error('feeObjects must be provided (pre-processed via buildFeeCoinObjects) and match positions length')
@@ -2225,17 +2307,21 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
2225
2307
  coinObjects: string[],
2226
2308
  long: boolean,
2227
2309
  sponsoredTx?: boolean,
2228
- suiCoinObjectsForPythUpdate?: string[],
2310
+ sender?: string,
2229
2311
  ): Promise<Transaction> {
2230
2312
  let tx = new Transaction()
2231
2313
  // Handle oracle initialization and coin processing
2232
2314
  let suiCoinObject
2233
2315
  if (sponsoredTx) {
2234
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
2235
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject)
2316
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
2317
+ sender: this.requireSenderForSponsored(sender),
2318
+ additionalSuiAmount: collateralToken === 'sui' ? BigInt(amount) : 0n,
2319
+ })
2320
+ tx = oracle.tx
2321
+ suiCoinObject = oracle.suiCoinObject
2236
2322
  }
2237
2323
  else {
2238
- tx = await this.initOracleTxb([collateralToken, indexToken], tx)
2324
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx
2239
2325
  }
2240
2326
 
2241
2327
  // Process coin splitting
@@ -2268,17 +2354,21 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
2268
2354
  amount: number,
2269
2355
  long: boolean,
2270
2356
  sponsoredTx?: boolean,
2271
- suiCoinObjectsForPythUpdate?: string[],
2357
+ sender?: string,
2272
2358
  ): Promise<Transaction> {
2273
2359
  let tx = new Transaction()
2274
2360
  // Handle oracle initialization and coin processing
2275
2361
  let suiCoinObject
2276
2362
  if (sponsoredTx) {
2277
- suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
2278
- tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject)
2363
+ const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
2364
+ sender: this.requireSenderForSponsored(sender),
2365
+ additionalSuiAmount: 0n,
2366
+ })
2367
+ tx = oracle.tx
2368
+ suiCoinObject = oracle.suiCoinObject
2279
2369
  }
2280
2370
  else {
2281
- tx = await this.initOracleTxb([collateralToken, indexToken], tx)
2371
+ tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx
2282
2372
  }
2283
2373
  const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
2284
2374
 
@@ -2429,7 +2519,7 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
2429
2519
  collateralToken: string,
2430
2520
  indexToken: string,
2431
2521
  ): Promise<Transaction> {
2432
- const tx = await this.initOracleTxb([collateralToken, indexToken])
2522
+ const { tx } = await this.initOracleTxb([collateralToken, indexToken])
2433
2523
  return tx
2434
2524
  }
2435
2525