@zofai/zo-sdk 0.2.11 → 0.2.13

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 (45) hide show
  1. package/dist/abstract/BaseAPI.cjs +88 -0
  2. package/dist/abstract/BaseAPI.cjs.map +1 -1
  3. package/dist/abstract/BaseAPI.d.cts +16 -0
  4. package/dist/abstract/BaseAPI.d.cts.map +1 -1
  5. package/dist/abstract/BaseAPI.d.mts +16 -0
  6. package/dist/abstract/BaseAPI.d.mts.map +1 -1
  7. package/dist/abstract/BaseAPI.mjs +89 -1
  8. package/dist/abstract/BaseAPI.mjs.map +1 -1
  9. package/dist/coins.cjs +6 -0
  10. package/dist/coins.cjs.map +1 -1
  11. package/dist/coins.d.cts +2 -0
  12. package/dist/coins.d.cts.map +1 -1
  13. package/dist/coins.d.mts +2 -0
  14. package/dist/coins.d.mts.map +1 -1
  15. package/dist/coins.mjs +5 -0
  16. package/dist/coins.mjs.map +1 -1
  17. package/dist/implementations/SLPAPI.cjs +22 -26
  18. package/dist/implementations/SLPAPI.cjs.map +1 -1
  19. package/dist/implementations/SLPAPI.d.cts.map +1 -1
  20. package/dist/implementations/SLPAPI.d.mts.map +1 -1
  21. package/dist/implementations/SLPAPI.mjs +22 -26
  22. package/dist/implementations/SLPAPI.mjs.map +1 -1
  23. package/dist/implementations/USDZAPI.cjs +16 -23
  24. package/dist/implementations/USDZAPI.cjs.map +1 -1
  25. package/dist/implementations/USDZAPI.d.cts.map +1 -1
  26. package/dist/implementations/USDZAPI.d.mts.map +1 -1
  27. package/dist/implementations/USDZAPI.mjs +16 -23
  28. package/dist/implementations/USDZAPI.mjs.map +1 -1
  29. package/dist/implementations/ZLPAPI.cjs +22 -26
  30. package/dist/implementations/ZLPAPI.cjs.map +1 -1
  31. package/dist/implementations/ZLPAPI.d.cts.map +1 -1
  32. package/dist/implementations/ZLPAPI.d.mts.map +1 -1
  33. package/dist/implementations/ZLPAPI.mjs +22 -26
  34. package/dist/implementations/ZLPAPI.mjs.map +1 -1
  35. package/dist/interfaces/base.d.cts +1 -1
  36. package/dist/interfaces/base.d.cts.map +1 -1
  37. package/dist/interfaces/base.d.mts +1 -1
  38. package/dist/interfaces/base.d.mts.map +1 -1
  39. package/package.json +1 -1
  40. package/src/abstract/BaseAPI.ts +139 -2
  41. package/src/coins.ts +11 -0
  42. package/src/implementations/SLPAPI.ts +66 -36
  43. package/src/implementations/USDZAPI.ts +54 -33
  44. package/src/implementations/ZLPAPI.ts +68 -36
  45. package/src/interfaces/base.ts +1 -0
@@ -828,8 +828,8 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
828
828
  sponsoredTx?: boolean,
829
829
  sender?: string,
830
830
  ): Promise<Transaction> {
831
- if (!coinObjects) {
832
- throw new Error(`${this.constructor.name}: coinObjects is required`)
831
+ if (!coinObjects?.length && !sender) {
832
+ throw new Error(`${this.constructor.name}: coinObjects or sender is required`)
833
833
  }
834
834
 
835
835
  let tx = new Transaction()
@@ -871,14 +871,14 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
871
871
  tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx
872
872
  }
873
873
 
874
- // Process coin splitting
875
- const [feeObject] = this.processCoinSplitting(
874
+ const feeObject = await this.resolveRelayerFeeObject(
876
875
  tx,
877
876
  collateralToken,
878
- coinObjects,
879
- [tx.pure.u64(relayerFee)],
877
+ coinObjects ?? [],
878
+ relayerFee,
880
879
  sponsoredTx,
881
880
  suiCoinObject,
881
+ sender,
882
882
  )
883
883
 
884
884
  tx.moveCall({
@@ -1069,12 +1069,14 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
1069
1069
  additionalSuiAmount: coin === 'sui' ? BigInt(amount) : 0n,
1070
1070
  })
1071
1071
  tx = oracle.tx
1072
- const { suiCoinObject } = oracle
1073
1072
 
1074
- // Process deposit coins
1075
- const depositObject = coin === 'sui'
1076
- ? tx.splitCoins(suiCoinObject!, [tx.pure.u64(amount)])[0]
1077
- : tx.splitCoins(this.processCoins(tx, coin, coinObjects, true), [tx.pure.u64(amount)])[0]
1073
+ const depositObject = await this.resolveSplitCoinObject(
1074
+ tx,
1075
+ coin,
1076
+ BigInt(amount),
1077
+ coinObjects,
1078
+ { sponsoredTx: true, suiCoinObject: oracle.suiCoinObject, sender },
1079
+ )
1078
1080
 
1079
1081
  const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx)
1080
1082
 
@@ -1095,10 +1097,13 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
1095
1097
 
1096
1098
  // Handle non-sponsored transaction case
1097
1099
  tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx
1098
- const depositObject = tx.splitCoins(
1099
- this.processCoins(tx, coin, coinObjects, false),
1100
- [tx.pure.u64(amount)],
1101
- )[0]
1100
+ const depositObject = await this.resolveSplitCoinObject(
1101
+ tx,
1102
+ coin,
1103
+ BigInt(amount),
1104
+ coinObjects,
1105
+ { sender },
1106
+ )
1102
1107
 
1103
1108
  const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx)
1104
1109
 
@@ -1152,12 +1157,14 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
1152
1157
  additionalSuiAmount: coin === 'sui' ? BigInt(amount) : 0n,
1153
1158
  })
1154
1159
  tx = oracle.tx
1155
- const { suiCoinObject } = oracle
1156
1160
 
1157
- // Process deposit coins
1158
- const depositObject = coin === 'sui'
1159
- ? tx.splitCoins(suiCoinObject!, [tx.pure.u64(amount)])[0]
1160
- : tx.splitCoins(this.processCoins(tx, coin, coinObjects, true), [tx.pure.u64(amount)])[0]
1161
+ const depositObject = await this.resolveSplitCoinObject(
1162
+ tx,
1163
+ coin,
1164
+ BigInt(amount),
1165
+ coinObjects,
1166
+ { sponsoredTx: true, suiCoinObject: oracle.suiCoinObject, sender },
1167
+ )
1161
1168
 
1162
1169
  const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx)
1163
1170
 
@@ -1178,10 +1185,13 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
1178
1185
 
1179
1186
  // Handle non-sponsored transaction case
1180
1187
  tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx
1181
- const depositObject = tx.splitCoins(
1182
- this.processCoins(tx, coin, coinObjects, false),
1183
- [tx.pure.u64(amount)],
1184
- )[0]
1188
+ const depositObject = await this.resolveSplitCoinObject(
1189
+ tx,
1190
+ coin,
1191
+ BigInt(amount),
1192
+ coinObjects,
1193
+ { sender },
1194
+ )
1185
1195
 
1186
1196
  const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx)
1187
1197
 
@@ -1215,24 +1225,35 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
1215
1225
  sponsoredTx?: boolean,
1216
1226
  sender?: string,
1217
1227
  ): Promise<Transaction> {
1228
+ if (!lpCoinObjects?.length && !sender) {
1229
+ throw new Error(`${this.constructor.name}: lpCoinObjects or sender is required`)
1230
+ }
1231
+
1218
1232
  let tx = new Transaction()
1219
1233
 
1220
1234
  // Initialize oracle transaction
1221
1235
  const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder)
1222
1236
 
1237
+ let suiCoinObject
1223
1238
  if (sponsoredTx) {
1224
1239
  const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
1225
1240
  sender: this.requireSenderForSponsored(sender),
1226
1241
  additionalSuiAmount: 0n,
1227
1242
  })
1228
1243
  tx = oracle.tx
1229
- const { suiCoinObject } = oracle
1244
+ suiCoinObject = oracle.suiCoinObject
1230
1245
  }
1231
1246
  else {
1232
1247
  tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx
1233
1248
  }
1234
- const usdzCoinObject = this.processCoins(tx, 'usdz', lpCoinObjects, false)
1235
- const [withdrawObject] = tx.splitCoins(usdzCoinObject, [tx.pure.u64(amount)])
1249
+
1250
+ const withdrawObject = await this.resolveSplitCoinObject(
1251
+ tx,
1252
+ 'usdz',
1253
+ BigInt(amount),
1254
+ lpCoinObjects,
1255
+ { sponsoredTx, suiCoinObject, sender },
1256
+ )
1236
1257
  const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx)
1237
1258
 
1238
1259
  tx.moveCall({
@@ -2022,8 +2043,8 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
2022
2043
  sponsoredTx?: boolean,
2023
2044
  sender?: string,
2024
2045
  ): Promise<Transaction> {
2025
- if (!coinObjects) {
2026
- throw new Error(`${this.constructor.name}: coinObjects is required`)
2046
+ if (!coinObjects?.length && !sender) {
2047
+ throw new Error(`${this.constructor.name}: coinObjects or sender is required`)
2027
2048
  }
2028
2049
 
2029
2050
  let tx = new Transaction()
@@ -2054,14 +2075,14 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
2054
2075
  tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx
2055
2076
  }
2056
2077
 
2057
- // Process coin splitting
2058
- const [feeObject] = this.processCoinSplitting(
2078
+ const feeObject = await this.resolveRelayerFeeObject(
2059
2079
  tx,
2060
2080
  collateralToken,
2061
- coinObjects,
2062
- [tx.pure.u64(relayerFee)],
2081
+ coinObjects ?? [],
2082
+ relayerFee,
2063
2083
  sponsoredTx,
2064
2084
  suiCoinObject,
2085
+ sender,
2065
2086
  )
2066
2087
 
2067
2088
  tx.moveCall({
@@ -71,12 +71,14 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
71
71
  additionalSuiAmount: coin === 'sui' ? BigInt(amount) : 0n,
72
72
  })
73
73
  tx = oracle.tx
74
- const { suiCoinObject } = oracle
75
74
 
76
- // Process deposit coins
77
- const depositObject = coin === 'sui'
78
- ? tx.splitCoins(suiCoinObject!, [tx.pure.u64(amount)])[0]
79
- : tx.splitCoins(this.processCoins(tx, coin, coinObjects, true), [tx.pure.u64(amount)])[0]
75
+ const depositObject = await this.resolveSplitCoinObject(
76
+ tx,
77
+ coin,
78
+ BigInt(amount),
79
+ coinObjects,
80
+ { sponsoredTx: true, suiCoinObject: oracle.suiCoinObject, sender },
81
+ )
80
82
 
81
83
  const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx)
82
84
 
@@ -97,10 +99,13 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
97
99
 
98
100
  // Handle non-sponsored transaction case
99
101
  tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx
100
- const depositObject = tx.splitCoins(
101
- this.processCoins(tx, coin, coinObjects, false),
102
- [tx.pure.u64(amount)],
103
- )[0]
102
+ const depositObject = await this.resolveSplitCoinObject(
103
+ tx,
104
+ coin,
105
+ BigInt(amount),
106
+ coinObjects,
107
+ { sender },
108
+ )
104
109
 
105
110
  const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx)
106
111
 
@@ -154,12 +159,14 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
154
159
  additionalSuiAmount: coin === 'sui' ? BigInt(amount) : 0n,
155
160
  })
156
161
  tx = oracle.tx
157
- const { suiCoinObject } = oracle
158
162
 
159
- // Process deposit coins
160
- const depositObject = coin === 'sui'
161
- ? tx.splitCoins(suiCoinObject!, [tx.pure.u64(amount)])[0]
162
- : tx.splitCoins(this.processCoins(tx, coin, coinObjects, true), [tx.pure.u64(amount)])[0]
163
+ const depositObject = await this.resolveSplitCoinObject(
164
+ tx,
165
+ coin,
166
+ BigInt(amount),
167
+ coinObjects,
168
+ { sponsoredTx: true, suiCoinObject: oracle.suiCoinObject, sender },
169
+ )
163
170
 
164
171
  const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx)
165
172
 
@@ -180,10 +187,13 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
180
187
 
181
188
  // Handle non-sponsored transaction case
182
189
  tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx
183
- const depositObject = tx.splitCoins(
184
- this.processCoins(tx, coin, coinObjects, false),
185
- [tx.pure.u64(amount)],
186
- )[0]
190
+ const depositObject = await this.resolveSplitCoinObject(
191
+ tx,
192
+ coin,
193
+ BigInt(amount),
194
+ coinObjects,
195
+ { sender },
196
+ )
187
197
 
188
198
  const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx)
189
199
 
@@ -287,24 +297,35 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
287
297
  sponsoredTx?: boolean,
288
298
  sender?: string,
289
299
  ): Promise<Transaction> {
300
+ if (!lpCoinObjects?.length && !sender) {
301
+ throw new Error(`${this.constructor.name}: lpCoinObjects or sender is required`)
302
+ }
303
+
290
304
  let tx = new Transaction()
291
305
 
292
306
  // Initialize oracle transaction
293
307
  const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder)
294
308
 
309
+ let suiCoinObject
295
310
  if (sponsoredTx) {
296
311
  const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
297
312
  sender: this.requireSenderForSponsored(sender),
298
313
  additionalSuiAmount: 0n,
299
314
  })
300
315
  tx = oracle.tx
301
- const { suiCoinObject } = oracle
316
+ suiCoinObject = oracle.suiCoinObject
302
317
  }
303
318
  else {
304
319
  tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx
305
320
  }
306
- const zlpCoinObject = this.processCoins(tx, 'zlp', lpCoinObjects, false)
307
- const [withdrawObject] = tx.splitCoins(zlpCoinObject, [tx.pure.u64(amount)])
321
+
322
+ const withdrawObject = await this.resolveSplitCoinObject(
323
+ tx,
324
+ 'zlp',
325
+ BigInt(amount),
326
+ lpCoinObjects,
327
+ { sponsoredTx, suiCoinObject, sender },
328
+ )
308
329
  const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx)
309
330
 
310
331
  tx.moveCall({
@@ -370,6 +391,10 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
370
391
  sponsoredTx?: boolean,
371
392
  sender?: string,
372
393
  ): Promise<TransactionObjectArgument> {
394
+ if (!lpCoinObjects?.length && !sender) {
395
+ throw new Error(`${this.constructor.name}: lpCoinObjects or sender is required`)
396
+ }
397
+
373
398
  if (!tx) {
374
399
  tx = new Transaction()
375
400
  }
@@ -377,19 +402,26 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
377
402
  // Initialize oracle transaction
378
403
  const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder)
379
404
 
405
+ let suiCoinObject
380
406
  if (sponsoredTx) {
381
407
  const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
382
408
  sender: this.requireSenderForSponsored(sender),
383
409
  additionalSuiAmount: 0n,
384
410
  })
385
411
  tx = oracle.tx
386
- const { suiCoinObject } = oracle
412
+ suiCoinObject = oracle.suiCoinObject
387
413
  }
388
414
  else {
389
415
  tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx
390
416
  }
391
- const zlpCoinObject = this.processCoins(tx, 'zlp', lpCoinObjects, false)
392
- const [withdrawObject] = tx.splitCoins(zlpCoinObject, [tx.pure.u64(amount)])
417
+
418
+ const withdrawObject = await this.resolveSplitCoinObject(
419
+ tx,
420
+ 'zlp',
421
+ BigInt(amount),
422
+ lpCoinObjects,
423
+ { sponsoredTx, suiCoinObject, sender },
424
+ )
393
425
  const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx)
394
426
 
395
427
  const [withdrawCoin] = tx.moveCall({
@@ -1147,8 +1179,8 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
1147
1179
  sponsoredTx?: boolean,
1148
1180
  sender?: string,
1149
1181
  ): Promise<Transaction> {
1150
- if (!coinObjects) {
1151
- throw new Error(`${this.constructor.name}: coinObjects is required`)
1182
+ if (!coinObjects?.length && !sender) {
1183
+ throw new Error(`${this.constructor.name}: coinObjects or sender is required`)
1152
1184
  }
1153
1185
 
1154
1186
  let tx = new Transaction()
@@ -1179,14 +1211,14 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
1179
1211
  tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx
1180
1212
  }
1181
1213
 
1182
- // Process coin splitting
1183
- const [feeObject] = this.processCoinSplitting(
1214
+ const feeObject = await this.resolveRelayerFeeObject(
1184
1215
  tx,
1185
1216
  collateralToken,
1186
- coinObjects,
1187
- [tx.pure.u64(relayerFee)],
1217
+ coinObjects ?? [],
1218
+ relayerFee,
1188
1219
  sponsoredTx,
1189
1220
  suiCoinObject,
1221
+ sender,
1190
1222
  )
1191
1223
 
1192
1224
  tx.moveCall({
@@ -1983,8 +2015,8 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
1983
2015
  sponsoredTx?: boolean,
1984
2016
  sender?: string,
1985
2017
  ): Promise<Transaction> {
1986
- if (!coinObjects) {
1987
- throw new Error(`${this.constructor.name}: coinObjects is required`)
2018
+ if (!coinObjects?.length && !sender) {
2019
+ throw new Error(`${this.constructor.name}: coinObjects or sender is required`)
1988
2020
  }
1989
2021
 
1990
2022
  let tx = new Transaction()
@@ -2026,14 +2058,14 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
2026
2058
  tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx
2027
2059
  }
2028
2060
 
2029
- // Process coin splitting
2030
- const [feeObject] = this.processCoinSplitting(
2061
+ const feeObject = await this.resolveRelayerFeeObject(
2031
2062
  tx,
2032
2063
  collateralToken,
2033
- coinObjects,
2034
- [tx.pure.u64(relayerFee)],
2064
+ coinObjects ?? [],
2065
+ relayerFee,
2035
2066
  sponsoredTx,
2036
2067
  suiCoinObject,
2068
+ sender,
2037
2069
  )
2038
2070
 
2039
2071
  tx.moveCall({
@@ -757,6 +757,7 @@ export interface IBaseAPI {
757
757
  relayerFee?: bigint,
758
758
  coinObjects?: string[],
759
759
  sponsoredTx?: boolean,
760
+ sender?: string,
760
761
  ) => Promise<Transaction>
761
762
 
762
763
  decreaseMultiPositionsWithSCardV2?: (