zo-sdk 0.1.24 → 0.1.26

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 (117) hide show
  1. package/dist/abstract/BaseAPI.cjs.map +1 -1
  2. package/dist/abstract/BaseAPI.d.cts +2 -2
  3. package/dist/abstract/BaseAPI.d.cts.map +1 -1
  4. package/dist/abstract/BaseAPI.d.mts +2 -2
  5. package/dist/abstract/BaseAPI.d.mts.map +1 -1
  6. package/dist/abstract/BaseAPI.mjs.map +1 -1
  7. package/dist/consts/deployments-shared-mainnet.json +50 -0
  8. package/dist/consts/deployments-shared-testnet.json +45 -0
  9. package/dist/consts/deployments-usdz-mainnet.json +30 -10
  10. package/dist/consts/index.cjs +13 -0
  11. package/dist/consts/index.cjs.map +1 -1
  12. package/dist/consts/index.d.cts +6 -1
  13. package/dist/consts/index.d.cts.map +1 -1
  14. package/dist/consts/index.d.mts +6 -1
  15. package/dist/consts/index.d.mts.map +1 -1
  16. package/dist/consts/index.mjs +12 -0
  17. package/dist/consts/index.mjs.map +1 -1
  18. package/dist/implementations/SLPAPI.cjs +84 -0
  19. package/dist/implementations/SLPAPI.cjs.map +1 -1
  20. package/dist/implementations/SLPAPI.d.cts +12 -0
  21. package/dist/implementations/SLPAPI.d.cts.map +1 -1
  22. package/dist/implementations/SLPAPI.d.mts +12 -0
  23. package/dist/implementations/SLPAPI.d.mts.map +1 -1
  24. package/dist/implementations/SLPAPI.mjs +84 -0
  25. package/dist/implementations/SLPAPI.mjs.map +1 -1
  26. package/dist/implementations/SLPDataAPI.cjs +77 -2
  27. package/dist/implementations/SLPDataAPI.cjs.map +1 -1
  28. package/dist/implementations/SLPDataAPI.d.cts +6 -0
  29. package/dist/implementations/SLPDataAPI.d.cts.map +1 -1
  30. package/dist/implementations/SLPDataAPI.d.mts +6 -0
  31. package/dist/implementations/SLPDataAPI.d.mts.map +1 -1
  32. package/dist/implementations/SLPDataAPI.mjs +77 -2
  33. package/dist/implementations/SLPDataAPI.mjs.map +1 -1
  34. package/dist/implementations/USDZAPI.cjs +4 -13
  35. package/dist/implementations/USDZAPI.cjs.map +1 -1
  36. package/dist/implementations/USDZAPI.d.cts.map +1 -1
  37. package/dist/implementations/USDZAPI.d.mts.map +1 -1
  38. package/dist/implementations/USDZAPI.mjs +4 -13
  39. package/dist/implementations/USDZAPI.mjs.map +1 -1
  40. package/dist/implementations/USDZDataAPI.cjs +3 -2
  41. package/dist/implementations/USDZDataAPI.cjs.map +1 -1
  42. package/dist/implementations/USDZDataAPI.d.cts.map +1 -1
  43. package/dist/implementations/USDZDataAPI.d.mts.map +1 -1
  44. package/dist/implementations/USDZDataAPI.mjs +3 -2
  45. package/dist/implementations/USDZDataAPI.mjs.map +1 -1
  46. package/dist/implementations/ZBTCVCAPI.cjs +4 -13
  47. package/dist/implementations/ZBTCVCAPI.cjs.map +1 -1
  48. package/dist/implementations/ZBTCVCAPI.d.cts.map +1 -1
  49. package/dist/implementations/ZBTCVCAPI.d.mts.map +1 -1
  50. package/dist/implementations/ZBTCVCAPI.mjs +4 -13
  51. package/dist/implementations/ZBTCVCAPI.mjs.map +1 -1
  52. package/dist/implementations/ZBTCVCDataAPI.cjs +2 -1
  53. package/dist/implementations/ZBTCVCDataAPI.cjs.map +1 -1
  54. package/dist/implementations/ZBTCVCDataAPI.d.cts.map +1 -1
  55. package/dist/implementations/ZBTCVCDataAPI.d.mts.map +1 -1
  56. package/dist/implementations/ZBTCVCDataAPI.mjs +2 -1
  57. package/dist/implementations/ZBTCVCDataAPI.mjs.map +1 -1
  58. package/dist/implementations/ZLPAPI.cjs +103 -25
  59. package/dist/implementations/ZLPAPI.cjs.map +1 -1
  60. package/dist/implementations/ZLPAPI.d.cts +13 -3
  61. package/dist/implementations/ZLPAPI.d.cts.map +1 -1
  62. package/dist/implementations/ZLPAPI.d.mts +13 -3
  63. package/dist/implementations/ZLPAPI.d.mts.map +1 -1
  64. package/dist/implementations/ZLPAPI.mjs +103 -25
  65. package/dist/implementations/ZLPAPI.mjs.map +1 -1
  66. package/dist/implementations/ZLPDataAPI.cjs +86 -4
  67. package/dist/implementations/ZLPDataAPI.cjs.map +1 -1
  68. package/dist/implementations/ZLPDataAPI.d.cts +6 -3
  69. package/dist/implementations/ZLPDataAPI.d.cts.map +1 -1
  70. package/dist/implementations/ZLPDataAPI.d.mts +6 -3
  71. package/dist/implementations/ZLPDataAPI.d.mts.map +1 -1
  72. package/dist/implementations/ZLPDataAPI.mjs +86 -4
  73. package/dist/implementations/ZLPDataAPI.mjs.map +1 -1
  74. package/dist/interfaces/base.d.cts +2 -2
  75. package/dist/interfaces/base.d.cts.map +1 -1
  76. package/dist/interfaces/base.d.mts +2 -2
  77. package/dist/interfaces/base.d.mts.map +1 -1
  78. package/dist/interfaces/slp.d.cts +1 -0
  79. package/dist/interfaces/slp.d.cts.map +1 -1
  80. package/dist/interfaces/slp.d.mts +1 -0
  81. package/dist/interfaces/slp.d.mts.map +1 -1
  82. package/dist/interfaces/zlp.d.cts +1 -0
  83. package/dist/interfaces/zlp.d.cts.map +1 -1
  84. package/dist/interfaces/zlp.d.mts +1 -0
  85. package/dist/interfaces/zlp.d.mts.map +1 -1
  86. package/dist/oracle.cjs +1 -0
  87. package/dist/oracle.cjs.map +1 -1
  88. package/dist/oracle.d.cts +1 -0
  89. package/dist/oracle.d.cts.map +1 -1
  90. package/dist/oracle.d.mts +1 -0
  91. package/dist/oracle.d.mts.map +1 -1
  92. package/dist/oracle.mjs +2 -1
  93. package/dist/oracle.mjs.map +1 -1
  94. package/dist/utils.cjs +2 -2
  95. package/dist/utils.cjs.map +1 -1
  96. package/dist/utils.mjs +2 -2
  97. package/dist/utils.mjs.map +1 -1
  98. package/package.json +9 -9
  99. package/src/abstract/BaseAPI.ts +6 -2
  100. package/src/consts/deployments-shared-mainnet.json +50 -0
  101. package/src/consts/deployments-shared-testnet.json +45 -0
  102. package/src/consts/deployments-usdz-mainnet.json +31 -11
  103. package/src/consts/deployments-zlp-mainnet.json +1 -1
  104. package/src/consts/index.ts +15 -1
  105. package/src/implementations/SLPAPI.ts +104 -0
  106. package/src/implementations/SLPDataAPI.ts +107 -15
  107. package/src/implementations/USDZAPI.ts +5 -17
  108. package/src/implementations/USDZDataAPI.ts +3 -2
  109. package/src/implementations/ZBTCVCAPI.ts +5 -17
  110. package/src/implementations/ZBTCVCDataAPI.ts +2 -1
  111. package/src/implementations/ZLPAPI.ts +124 -27
  112. package/src/implementations/ZLPDataAPI.ts +111 -4
  113. package/src/interfaces/base.ts +6 -2
  114. package/src/interfaces/slp.ts +4 -1
  115. package/src/interfaces/zlp.ts +1 -0
  116. package/src/oracle.ts +3 -1
  117. package/src/utils.ts +2 -2
@@ -339,11 +339,9 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
339
339
  const positionRaw = await this.provider.getDynamicFieldObject({
340
340
  parentId: this.consts.sudoCore.positionsParent,
341
341
  name: {
342
- type: `${this.consts.sudoCore.package}::market::PositionName<${
343
- positionCapInfo.symbol0
344
- }, ${positionCapInfo.symbol1}, ${
345
- this.consts.sudoCore.package
346
- }::market::${positionCapInfo.long ? 'LONG' : 'SHORT'}>`,
342
+ type: `${this.consts.sudoCore.package}::market::PositionName<${positionCapInfo.symbol0
343
+ }, ${positionCapInfo.symbol1}, ${this.consts.sudoCore.package
344
+ }::market::${positionCapInfo.long ? 'LONG' : 'SHORT'}>`,
347
345
  value: {
348
346
  owner,
349
347
  id: positionCapInfo.positionCapId,
@@ -463,6 +461,9 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
463
461
  }
464
462
  }
465
463
 
464
+ /**
465
+ * Legacy method: Get stake pool from sudo_staking
466
+ */
466
467
  public async getStakePool(): Promise<ISLPStakePool> {
467
468
  const raw = await this.provider.getObject({
468
469
  id: this.consts.sudoStaking.pool,
@@ -473,6 +474,65 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
473
474
  return SLPDataAPI.parseStakePool(raw)
474
475
  }
475
476
 
477
+ public async getStakePoolV2(): Promise<ISLPStakePool> {
478
+ const poolId = this.sharedConfig.zoStaking.pools.SLP
479
+ const raw = await this.provider.getObject({
480
+ id: poolId,
481
+ options: {
482
+ showContent: true,
483
+ },
484
+ })
485
+ return SLPDataAPI.parseStakePool(raw)
486
+ }
487
+
488
+ public async getStakedV2(owner: string): Promise<ISLPStaked> {
489
+ let rawCredentialsData: any[] = []
490
+ let queryNextPage = true
491
+ let queryCursor
492
+ const limit = 50
493
+
494
+ while (queryNextPage) {
495
+ const { data, hasNextPage, nextCursor } = await this.provider.getOwnedObjects({
496
+ owner,
497
+ filter: {
498
+ MoveModule: {
499
+ package: this.sharedConfig.zoStaking.package,
500
+ module: 'pool',
501
+ },
502
+ },
503
+ options: {
504
+ showType: true,
505
+ showContent: true,
506
+ },
507
+ cursor: queryCursor,
508
+ limit,
509
+ })
510
+
511
+ queryNextPage = hasNextPage
512
+ queryCursor = nextCursor!
513
+ if (!data)
514
+ break
515
+ rawCredentialsData = [...rawCredentialsData, ...data]
516
+ }
517
+
518
+ const pool = await this.getStakePoolV2()
519
+
520
+ const credentials = rawCredentialsData.map((item: any) =>
521
+ SLPDataAPI.parseCredential(item, pool),
522
+ )
523
+ return {
524
+ credentials,
525
+ amount: credentials.reduce(
526
+ (acc: bigint, cur: ISLPCredential) => acc + cur.amount,
527
+ BigInt(0),
528
+ ),
529
+ claimable: credentials.reduce(
530
+ (acc: bigint, cur: ISLPCredential) => acc + cur.claimable,
531
+ BigInt(0),
532
+ ),
533
+ }
534
+ }
535
+
476
536
  public async fundingFeeRate(indexToken: string, long: boolean, sender?: string): Promise<number> {
477
537
  if (!sender) {
478
538
  throw new Error('Sender address is required for fundingFeeRate calculation')
@@ -835,13 +895,10 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
835
895
  const orderRaw = await this.provider.getDynamicFieldObject({
836
896
  parentId: this.consts.sudoCore.ordersParent,
837
897
  name: {
838
- type: `${this.consts.sudoCore.package}::market::OrderName<${
839
- orderCapInfo.symbol0
840
- }, ${orderCapInfo.symbol1}, ${
841
- this.consts.sudoCore.package
842
- }::market::${orderCapInfo.long ? 'LONG' : 'SHORT'}, ${
843
- this.consts.coins.sui.module
844
- }>`,
898
+ type: `${this.consts.sudoCore.package}::market::OrderName<${orderCapInfo.symbol0
899
+ }, ${orderCapInfo.symbol1}, ${this.consts.sudoCore.package
900
+ }::market::${orderCapInfo.long ? 'LONG' : 'SHORT'}, ${this.consts.coins.sui.module
901
+ }>`,
845
902
  value: {
846
903
  owner,
847
904
  id: orderCapInfo.orderCapId,
@@ -1197,21 +1254,36 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
1197
1254
 
1198
1255
  private static parseStakePool(raw: any): ISLPStakePool {
1199
1256
  const content = raw.data.content.fields
1200
- const pool = {
1257
+
1258
+ // Check if this is the new version with reward_vault and reward_rate
1259
+ const isNewVersion = content.reward_vault !== undefined && content.reward_rate !== undefined
1260
+
1261
+ const pool: ISLPStakePool = {
1201
1262
  id: content.id.id,
1202
1263
  enabled: content.enabled,
1203
1264
  lastUpdatedTime: parseValue(content.last_updated_time),
1204
1265
  stakedAmount: BigInt(content.staked_amount),
1205
- reward: BigInt(content.reward),
1266
+ // Support both old 'reward' and new 'reward_vault' field names
1267
+ reward: BigInt(content.reward_vault || content.reward),
1206
1268
  startTime: parseValue(content.start_time),
1207
1269
  endTime: parseValue(content.end_time),
1208
1270
  accRewardPerShare: BigInt(content.acc_reward_per_share),
1209
1271
  lockDuration: parseValue(content.lock_duration),
1272
+ // Add rewardRate if available (new version)
1273
+ ...(isNewVersion && { rewardRate: BigInt(content.reward_rate) }),
1210
1274
  }
1211
- SLPDataAPI.refreshPool(pool, Math.floor(Date.now() / 1000))
1275
+
1276
+ // Use appropriate refresh method based on version
1277
+ if (isNewVersion && pool.rewardRate) {
1278
+ SLPDataAPI.refreshPoolV2(pool, Math.floor(Date.now() / 1000))
1279
+ } else {
1280
+ SLPDataAPI.refreshPool(pool, Math.floor(Date.now() / 1000))
1281
+ }
1282
+
1212
1283
  return pool
1213
1284
  }
1214
1285
 
1286
+ // Legacy refresh method for backward compatibility
1215
1287
  private static refreshPool(pool: ISLPStakePool, timestamp: number): void {
1216
1288
  if (timestamp === pool.lastUpdatedTime || timestamp < pool.startTime) {
1217
1289
  return
@@ -1234,4 +1306,24 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
1234
1306
  const rewardPerShare = (rewardAmount * BigInt(1e18)) / pool.stakedAmount
1235
1307
  pool.accRewardPerShare += rewardPerShare
1236
1308
  }
1309
+
1310
+ // New refresh method matching SLP implementation
1311
+ private static refreshPoolV2(pool: ISLPStakePool, timestamp: number): void {
1312
+ if (timestamp <= pool.lastUpdatedTime || timestamp < pool.startTime) {
1313
+ return
1314
+ }
1315
+
1316
+ const applicableEndTime = Math.max(pool.endTime, pool.lastUpdatedTime)
1317
+
1318
+ const calculationEndTime = Math.min(timestamp, applicableEndTime)
1319
+
1320
+ if (calculationEndTime > pool.lastUpdatedTime && pool.stakedAmount > BigInt(0) && pool.rewardRate && pool.rewardRate > BigInt(0)) {
1321
+ const timeDiff = BigInt(calculationEndTime - pool.lastUpdatedTime)
1322
+ const rewardAmount = timeDiff * pool.rewardRate
1323
+ const rewardPerShare = (rewardAmount * BigInt(1e18)) / pool.stakedAmount
1324
+ pool.accRewardPerShare += rewardPerShare
1325
+ }
1326
+
1327
+ pool.lastUpdatedTime = calculationEndTime
1328
+ }
1237
1329
  }
@@ -742,10 +742,6 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
742
742
  pool: string,
743
743
  tx?: Transaction,
744
744
  ): Transaction {
745
- if (!this.consts.zoStaking) {
746
- throw new Error('ZO staking configuration not found')
747
- }
748
-
749
745
  if (!tx) {
750
746
  tx = new Transaction()
751
747
  }
@@ -754,7 +750,7 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
754
750
  const [depositObject] = tx.splitCoins(coinObject, [tx.pure.u64(amount)])
755
751
 
756
752
  tx.moveCall({
757
- target: `${this.consts.zoStaking.package}::pool::deposit`,
753
+ target: `${this.sharedConfig.zoStaking.package}::pool::deposit`,
758
754
  typeArguments: [
759
755
  `${this.consts.zoCore.package}::usdz::USDZ`,
760
756
  `${this.consts.coins.sui.module}`,
@@ -776,16 +772,12 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
776
772
  pool: string,
777
773
  tx?: Transaction,
778
774
  ): Transaction {
779
- if (!this.consts.zoStaking) {
780
- throw new Error('ZO staking configuration not found')
781
- }
782
-
783
775
  if (!tx) {
784
776
  tx = new Transaction()
785
777
  }
786
778
 
787
779
  tx.moveCall({
788
- target: `${this.consts.zoStaking.package}::pool::deposit`,
780
+ target: `${this.sharedConfig.zoStaking.package}::pool::deposit`,
789
781
  typeArguments: [
790
782
  `${this.consts.zoCore.package}::usdz::USDZ`,
791
783
  `${this.consts.coins.sui.module}`,
@@ -808,10 +800,6 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
808
800
  pool: string,
809
801
  tx?: Transaction,
810
802
  ): Transaction {
811
- if (!this.consts.zoStaking) {
812
- throw new Error('ZO staking configuration not found')
813
- }
814
-
815
803
  let unstakeAmount = amount
816
804
  if (!tx) {
817
805
  tx = new Transaction()
@@ -823,7 +811,7 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
823
811
  })()
824
812
  unstakeAmount -= withdrawAmount
825
813
  tx.moveCall({
826
- target: `${this.consts.zoStaking.package}::pool::withdraw`,
814
+ target: `${this.sharedConfig.zoStaking.package}::pool::withdraw`,
827
815
  typeArguments: [
828
816
  `${this.consts.zoCore.package}::usdz::USDZ`,
829
817
  `${this.consts.coins.sui.module}`,
@@ -837,10 +825,10 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
837
825
  })
838
826
  if (credential.amount === BigInt(0)) {
839
827
  tx.moveCall({
840
- target: `${this.consts.zoStaking.package}::pool::clear_empty_credential`,
828
+ target: `${this.sharedConfig.zoStaking.package}::pool::clear_empty_credential`,
841
829
  typeArguments: [
842
830
  `${this.consts.zoCore.package}::usdz::USDZ`,
843
- `${this.consts.coins.sui.module}`,
831
+ `${this.consts.coins.sui.module}`,
844
832
  ],
845
833
  arguments: [tx.object(credential.id)],
846
834
  })
@@ -55,7 +55,7 @@ export class USDZDataAPI extends BaseDataAPI implements IUSDZDataAPI {
55
55
  owner,
56
56
  filter: {
57
57
  MoveModule: {
58
- package: this.consts.zoStaking.package,
58
+ package: this.sharedConfig.zoStaking.package,
59
59
  module: 'pool',
60
60
  },
61
61
  },
@@ -93,8 +93,9 @@ export class USDZDataAPI extends BaseDataAPI implements IUSDZDataAPI {
93
93
  }
94
94
 
95
95
  public async getStakePool(): Promise<IUSDZStakePool> {
96
+ const poolId = this.sharedConfig.zoStaking.pools.USDZ
96
97
  const raw = await this.provider.getObject({
97
- id: this.consts.zoStaking.pools[0],
98
+ id: poolId,
98
99
  options: {
99
100
  showContent: true,
100
101
  },
@@ -742,10 +742,6 @@ export class ZBTCVCAPI extends BaseAPI implements IZBTCVCAPI {
742
742
  pool: string,
743
743
  tx?: Transaction,
744
744
  ): Transaction {
745
- if (!this.consts.zoStaking) {
746
- throw new Error('ZO staking configuration not found')
747
- }
748
-
749
745
  if (!tx) {
750
746
  tx = new Transaction()
751
747
  }
@@ -754,7 +750,7 @@ export class ZBTCVCAPI extends BaseAPI implements IZBTCVCAPI {
754
750
  const [depositObject] = tx.splitCoins(coinObject, [tx.pure.u64(amount)])
755
751
 
756
752
  tx.moveCall({
757
- target: `${this.consts.zoStaking.package}::pool::deposit`,
753
+ target: `${this.sharedConfig.zoStaking.package}::pool::deposit`,
758
754
  typeArguments: [
759
755
  `${this.consts.zoCore.package}::zbtcvc::ZBTCVC`,
760
756
  `${this.consts.coins.sui.module}`,
@@ -776,16 +772,12 @@ export class ZBTCVCAPI extends BaseAPI implements IZBTCVCAPI {
776
772
  pool: string,
777
773
  tx?: Transaction,
778
774
  ): Transaction {
779
- if (!this.consts.zoStaking) {
780
- throw new Error('ZO staking configuration not found')
781
- }
782
-
783
775
  if (!tx) {
784
776
  tx = new Transaction()
785
777
  }
786
778
 
787
779
  tx.moveCall({
788
- target: `${this.consts.zoStaking.package}::pool::deposit`,
780
+ target: `${this.sharedConfig.zoStaking.package}::pool::deposit`,
789
781
  typeArguments: [
790
782
  `${this.consts.zoCore.package}::zbtcvc::ZBTCVC`,
791
783
  `${this.consts.coins.sui.module}`,
@@ -808,10 +800,6 @@ export class ZBTCVCAPI extends BaseAPI implements IZBTCVCAPI {
808
800
  pool: string,
809
801
  tx?: Transaction,
810
802
  ): Transaction {
811
- if (!this.consts.zoStaking) {
812
- throw new Error('ZO staking configuration not found')
813
- }
814
-
815
803
  let unstakeAmount = amount
816
804
  if (!tx) {
817
805
  tx = new Transaction()
@@ -823,7 +811,7 @@ export class ZBTCVCAPI extends BaseAPI implements IZBTCVCAPI {
823
811
  })()
824
812
  unstakeAmount -= withdrawAmount
825
813
  tx.moveCall({
826
- target: `${this.consts.zoStaking.package}::pool::withdraw`,
814
+ target: `${this.sharedConfig.zoStaking.package}::pool::withdraw`,
827
815
  typeArguments: [
828
816
  `${this.consts.zoCore.package}::zbtcvc::ZBTCVC`,
829
817
  `${this.consts.coins.sui.module}`,
@@ -837,10 +825,10 @@ export class ZBTCVCAPI extends BaseAPI implements IZBTCVCAPI {
837
825
  })
838
826
  if (credential.amount === BigInt(0)) {
839
827
  tx.moveCall({
840
- target: `${this.consts.zoStaking.package}::pool::clear_empty_credential`,
828
+ target: `${this.sharedConfig.zoStaking.package}::pool::clear_empty_credential`,
841
829
  typeArguments: [
842
830
  `${this.consts.zoCore.package}::zbtcvc::ZBTCVC`,
843
- `${this.consts.coins.sui.module}`,
831
+ `${this.consts.coins.sui.module}`,
844
832
  ],
845
833
  arguments: [tx.object(credential.id)],
846
834
  })
@@ -93,8 +93,9 @@ export class ZBTCVCDataAPI extends BaseDataAPI implements IZBTCVCDataAPI {
93
93
  }
94
94
 
95
95
  public async getStakePool(): Promise<IZBTCVCStakePool> {
96
+ const poolId = this.consts.zoStaking.pools.ZBTCVC
96
97
  const raw = await this.provider.getObject({
97
- id: this.consts.zoStaking.pools[0],
98
+ id: poolId,
98
99
  options: {
99
100
  showContent: true,
100
101
  },
@@ -28,6 +28,7 @@ import type {
28
28
  IBaseSymbolInfo,
29
29
  IBaseVaultInfo,
30
30
  IZLPAPI,
31
+ IZLPCredential,
31
32
  } from '../interfaces'
32
33
  import { joinSymbol } from '../utils'
33
34
  import { ZLPDataAPI } from './ZLPDataAPI'
@@ -45,14 +46,6 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
45
46
  this.dataAPI = new ZLPDataAPI(network, provider, apiEndpoint, connectionURL)
46
47
  }
47
48
 
48
- public stake(_lpCoinObjects: string[], _amount: bigint, _pool: string, _tx?: Transaction): Transaction {
49
- throw new Error(`Method not implemented in ${this.constructor.name}.`)
50
- }
51
-
52
- public unstake(_credentials: IBaseCredential[], _amount: bigint, _pool: string, _tx?: Transaction): Transaction {
53
- throw new Error(`Method not implemented in ${this.constructor.name}.`)
54
- }
55
-
56
49
  public claimTokenFromSCard(_token: string, _coinObjects: string[], _kioskClient: KioskClient, _kioskCap: KioskOwnerCap, _scard: string): Transaction {
57
50
  throw new Error(`Method not implemented in ${this.constructor.name}.`)
58
51
  }
@@ -275,6 +268,110 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
275
268
  return tx
276
269
  }
277
270
 
271
+ /**
272
+ * Stakes ZLP tokens in ZO staking pools
273
+ */
274
+ public stake(
275
+ lpCoinObjects: string[],
276
+ amount: bigint,
277
+ pool: string,
278
+ tx?: Transaction,
279
+ ): Transaction {
280
+ if (!tx) {
281
+ tx = new Transaction()
282
+ }
283
+
284
+ const coinObject = this.processCoins(tx, 'zlp', lpCoinObjects)
285
+ const [depositObject] = tx.splitCoins(coinObject, [tx.pure.u64(amount)])
286
+
287
+ tx.moveCall({
288
+ target: `${this.sharedConfig.zoStaking.package}::pool::deposit`,
289
+ typeArguments: [
290
+ `${this.consts.zoCore.package}::zlp::ZLP`,
291
+ `${this.consts.coins.sui.module}`,
292
+ ],
293
+ arguments: [
294
+ tx.object(pool),
295
+ tx.object(SUI_CLOCK_OBJECT_ID),
296
+ depositObject,
297
+ ],
298
+ })
299
+ return tx
300
+ }
301
+
302
+ /**
303
+ * Stakes ZLP tokens using coin object only (PTB)
304
+ */
305
+ public stakeCoinObject(
306
+ coinObject: any,
307
+ pool: string,
308
+ tx?: Transaction,
309
+ ): Transaction {
310
+ if (!tx) {
311
+ tx = new Transaction()
312
+ }
313
+
314
+ tx.moveCall({
315
+ target: `${this.sharedConfig.zoStaking.package}::pool::deposit`,
316
+ typeArguments: [
317
+ `${this.consts.zoCore.package}::zlp::ZLP`,
318
+ `${this.consts.coins.sui.module}`,
319
+ ],
320
+ arguments: [
321
+ tx.object(pool),
322
+ tx.object(SUI_CLOCK_OBJECT_ID),
323
+ coinObject,
324
+ ],
325
+ })
326
+ return tx
327
+ }
328
+
329
+ /**
330
+ * Unstakes ZLP tokens from ZO staking pools
331
+ */
332
+ public unstake(
333
+ credentials: IZLPCredential[],
334
+ amount: bigint,
335
+ pool: string,
336
+ tx?: Transaction,
337
+ ): Transaction {
338
+ let unstakeAmount = amount
339
+ if (!tx) {
340
+ tx = new Transaction()
341
+ }
342
+ for (const credential of credentials) {
343
+ const withdrawAmount = (() => {
344
+ const min = (a: bigint, b: bigint) => a < b ? a : b
345
+ return min(unstakeAmount, credential.amount)
346
+ })()
347
+ unstakeAmount -= withdrawAmount
348
+ tx.moveCall({
349
+ target: `${this.sharedConfig.zoStaking.package}::pool::withdraw`,
350
+ typeArguments: [
351
+ `${this.consts.zoCore.package}::zlp::ZLP`,
352
+ `${this.consts.coins.sui.module}`,
353
+ ],
354
+ arguments: [
355
+ tx.object(pool),
356
+ tx.object(SUI_CLOCK_OBJECT_ID),
357
+ tx.object(credential.id),
358
+ tx.pure.u64(withdrawAmount),
359
+ ],
360
+ })
361
+ if (credential.amount === BigInt(0)) {
362
+ tx.moveCall({
363
+ target: `${this.sharedConfig.zoStaking.package}::pool::clear_empty_credential`,
364
+ typeArguments: [
365
+ `${this.consts.zoCore.package}::zlp::ZLP`,
366
+ `${this.consts.coins.sui.module}`,
367
+ ],
368
+ arguments: [tx.object(credential.id)],
369
+ })
370
+ }
371
+ }
372
+ return tx
373
+ }
374
+
278
375
  public async swap(
279
376
  fromToken: string,
280
377
  toToken: string,
@@ -1298,15 +1395,15 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
1298
1395
  }
1299
1396
  for (const [i, beneficiary] of beneficiaries.entries()) {
1300
1397
  tx.moveCall({
1301
- target: `${this.consts.zoLootbox.package}::lootbox::admin_issue_lootbox`,
1398
+ target: `${this.sharedConfig.zoLootbox.package}::lootbox::admin_issue_lootbox`,
1302
1399
  typeArguments: [module],
1303
1400
  arguments: [
1304
- tx.object(this.consts.zoLootbox.adminCap),
1401
+ tx.object(this.sharedConfig.zoLootbox.adminCap),
1305
1402
  tx.pure.u8(tiers[i]),
1306
1403
  tx.pure.address(beneficiary),
1307
1404
  tx.pure.u64(amounts[i]),
1308
1405
  tx.pure.bool(amounts[i] > 0),
1309
- tx.object(`${this.consts.zoLootbox.lootboxSettings}`),
1406
+ tx.object(`${this.sharedConfig.zoLootbox.lootboxSettings}`),
1310
1407
  ],
1311
1408
  })
1312
1409
  }
@@ -1327,11 +1424,11 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
1327
1424
  }
1328
1425
 
1329
1426
  tx.moveCall({
1330
- target: `${this.consts.zoLootbox.package}::lootbox::deposit`,
1427
+ target: `${this.sharedConfig.zoLootbox.package}::lootbox::deposit`,
1331
1428
  typeArguments: [module],
1332
1429
  arguments: [
1333
- tx.object(this.consts.zoLootbox.adminCap),
1334
- tx.object(this.consts.zoLootbox.lootboxTreasury),
1430
+ tx.object(this.sharedConfig.zoLootbox.adminCap),
1431
+ tx.object(this.sharedConfig.zoLootbox.lootboxTreasury),
1335
1432
  depositObject,
1336
1433
  ],
1337
1434
  })
@@ -1352,11 +1449,11 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
1352
1449
  }
1353
1450
 
1354
1451
  tx.moveCall({
1355
- target: `${this.consts.zoLootbox.package}::lootbox::withdraw`,
1452
+ target: `${this.sharedConfig.zoLootbox.package}::lootbox::withdraw`,
1356
1453
  typeArguments: [module],
1357
1454
  arguments: [
1358
- tx.object(this.consts.zoLootbox.adminCap),
1359
- tx.object(this.consts.zoLootbox.lootboxTreasury),
1455
+ tx.object(this.sharedConfig.zoLootbox.adminCap),
1456
+ tx.object(this.sharedConfig.zoLootbox.lootboxTreasury),
1360
1457
  tx.object(metadata),
1361
1458
  tx.pure.u64(amount),
1362
1459
  ],
@@ -1378,13 +1475,13 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
1378
1475
  }
1379
1476
 
1380
1477
  tx.moveCall({
1381
- target: `${this.consts.zoLootbox.upgradedPackage}::lootbox::open_lootbox`,
1478
+ target: `${this.sharedConfig.zoLootbox.upgradedPackage}::lootbox::open_lootbox`,
1382
1479
  typeArguments: [module],
1383
1480
  arguments: [
1384
- tx.object(`${this.consts.zoLootbox.lootboxTreasury}`),
1481
+ tx.object(`${this.sharedConfig.zoLootbox.lootboxTreasury}`),
1385
1482
  tx.object(lootbox),
1386
1483
  tx.object(metadata),
1387
- tx.object(`${this.consts.zoLootbox.lootboxSettings}`),
1484
+ tx.object(`${this.sharedConfig.zoLootbox.lootboxSettings}`),
1388
1485
  ],
1389
1486
  })
1390
1487
 
@@ -1408,18 +1505,18 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
1408
1505
 
1409
1506
  for (const [i, beneficiary] of beneficiaries.entries()) {
1410
1507
  const moveCallArgs = {
1411
- target: `${this.consts.zoLootboxV2.package}::lootbox::admin_issue_lootbox`,
1508
+ target: `${this.sharedConfig.zoLootboxV2.package}::lootbox::admin_issue_lootbox`,
1412
1509
  typeArguments: [module],
1413
1510
  arguments: [
1414
- tx.object(this.consts.zoLootboxV2.adminCap),
1415
- tx.object(this.consts.zoLootboxV2.lootboxTreasury),
1511
+ tx.object(this.sharedConfig.zoLootboxV2.adminCap),
1512
+ tx.object(this.sharedConfig.zoLootboxV2.lootboxTreasury),
1416
1513
  tx.pure.u8(tiers[i]),
1417
1514
  tx.pure.address(beneficiary),
1418
1515
  tx.pure.u64(amounts[i]),
1419
1516
  tx.pure.bool(amounts[i] > 0),
1420
1517
  tx.pure.string(titles[i]),
1421
1518
  tx.pure.string(descriptions[i]),
1422
- tx.object(`${this.consts.zoLootboxV2.lootboxSettings}`),
1519
+ tx.object(`${this.sharedConfig.zoLootboxV2.lootboxSettings}`),
1423
1520
  ],
1424
1521
  }
1425
1522
 
@@ -1441,13 +1538,13 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
1441
1538
  }
1442
1539
 
1443
1540
  tx.moveCall({
1444
- target: `${this.consts.zoLootboxV2.package}::lootbox::open_lootbox`,
1541
+ target: `${this.sharedConfig.zoLootboxV2.package}::lootbox::open_lootbox`,
1445
1542
  typeArguments: [module],
1446
1543
  arguments: [
1447
- tx.object(this.consts.zoLootboxV2.lootboxTreasury),
1544
+ tx.object(this.sharedConfig.zoLootboxV2.lootboxTreasury),
1448
1545
  tx.object(lootbox),
1449
1546
  tx.object(metadata),
1450
- tx.object(this.consts.zoLootboxV2.lootboxSettings),
1547
+ tx.object(this.sharedConfig.zoLootboxV2.lootboxSettings),
1451
1548
  ],
1452
1549
  })
1453
1550