zo-sdk 0.1.17 → 0.1.19

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 (53) hide show
  1. package/dist/abstract/BaseDataAPI.d.cts +2 -2
  2. package/dist/abstract/BaseDataAPI.d.cts.map +1 -1
  3. package/dist/abstract/BaseDataAPI.d.mts +2 -2
  4. package/dist/abstract/BaseDataAPI.d.mts.map +1 -1
  5. package/dist/consts/deployments-usdz-mainnet.json +9 -0
  6. package/dist/consts/index.cjs.map +1 -1
  7. package/dist/consts/index.d.cts +1 -0
  8. package/dist/consts/index.d.cts.map +1 -1
  9. package/dist/consts/index.d.mts +1 -0
  10. package/dist/consts/index.d.mts.map +1 -1
  11. package/dist/consts/index.mjs.map +1 -1
  12. package/dist/implementations/SLPDataAPI.cjs +54 -32
  13. package/dist/implementations/SLPDataAPI.cjs.map +1 -1
  14. package/dist/implementations/SLPDataAPI.d.cts +2 -2
  15. package/dist/implementations/SLPDataAPI.d.cts.map +1 -1
  16. package/dist/implementations/SLPDataAPI.d.mts +2 -2
  17. package/dist/implementations/SLPDataAPI.d.mts.map +1 -1
  18. package/dist/implementations/SLPDataAPI.mjs +54 -32
  19. package/dist/implementations/SLPDataAPI.mjs.map +1 -1
  20. package/dist/implementations/USDZAPI.cjs +151 -7
  21. package/dist/implementations/USDZAPI.cjs.map +1 -1
  22. package/dist/implementations/USDZAPI.d.cts +18 -4
  23. package/dist/implementations/USDZAPI.d.cts.map +1 -1
  24. package/dist/implementations/USDZAPI.d.mts +18 -4
  25. package/dist/implementations/USDZAPI.d.mts.map +1 -1
  26. package/dist/implementations/USDZAPI.mjs +151 -7
  27. package/dist/implementations/USDZAPI.mjs.map +1 -1
  28. package/dist/implementations/USDZDataAPI.cjs +85 -4
  29. package/dist/implementations/USDZDataAPI.cjs.map +1 -1
  30. package/dist/implementations/USDZDataAPI.d.cts +6 -3
  31. package/dist/implementations/USDZDataAPI.d.cts.map +1 -1
  32. package/dist/implementations/USDZDataAPI.d.mts +6 -3
  33. package/dist/implementations/USDZDataAPI.d.mts.map +1 -1
  34. package/dist/implementations/USDZDataAPI.mjs +85 -4
  35. package/dist/implementations/USDZDataAPI.mjs.map +1 -1
  36. package/dist/interfaces/base.d.cts +2 -2
  37. package/dist/interfaces/base.d.cts.map +1 -1
  38. package/dist/interfaces/base.d.mts +2 -2
  39. package/dist/interfaces/base.d.mts.map +1 -1
  40. package/dist/interfaces/usdz.d.cts +4 -0
  41. package/dist/interfaces/usdz.d.cts.map +1 -1
  42. package/dist/interfaces/usdz.d.mts +4 -0
  43. package/dist/interfaces/usdz.d.mts.map +1 -1
  44. package/package.json +8 -8
  45. package/src/abstract/BaseDataAPI.ts +2 -2
  46. package/src/consts/deployments-slp-mainnet.json +1 -1
  47. package/src/consts/deployments-usdz-mainnet.json +9 -0
  48. package/src/consts/index.ts +1 -0
  49. package/src/implementations/SLPDataAPI.ts +71 -41
  50. package/src/implementations/USDZAPI.ts +199 -10
  51. package/src/implementations/USDZDataAPI.ts +110 -5
  52. package/src/interfaces/base.ts +2 -2
  53. package/src/interfaces/usdz.ts +21 -1
@@ -326,33 +326,47 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
326
326
  public async getPositionInfoList(
327
327
  positionCapInfoList: ISLPPositionCapInfo[],
328
328
  owner: string,
329
+ batchSize = 10,
329
330
  ): Promise<ISLPPositionInfo[]> {
330
331
  const positionInfoList: ISLPPositionInfo[] = []
331
- await Promise.all(
332
- positionCapInfoList.map(async (positionCapInfo) => {
333
- const positionRaw = await this.provider.getDynamicFieldObject({
334
- parentId: this.consts.sudoCore.positionsParent,
335
- name: {
336
- type: `${this.consts.sudoCore.package}::market::PositionName<${positionCapInfo.symbol0
337
- }, ${positionCapInfo.symbol1}, ${this.consts.sudoCore.package
332
+
333
+ // Process in batches of 10
334
+ for (let i = 0; i < positionCapInfoList.length; i += batchSize) {
335
+ const batch = positionCapInfoList.slice(i, i + batchSize)
336
+
337
+ await Promise.all(batch.map(async (positionCapInfo) => {
338
+ try {
339
+ const positionRaw = await this.provider.getDynamicFieldObject({
340
+ parentId: this.consts.sudoCore.positionsParent,
341
+ name: {
342
+ type: `${this.consts.sudoCore.package}::market::PositionName<${
343
+ positionCapInfo.symbol0
344
+ }, ${positionCapInfo.symbol1}, ${
345
+ this.consts.sudoCore.package
338
346
  }::market::${positionCapInfo.long ? 'LONG' : 'SHORT'}>`,
339
- value: {
340
- owner,
341
- id: positionCapInfo.positionCapId,
347
+ value: {
348
+ owner,
349
+ id: positionCapInfo.positionCapId,
350
+ },
342
351
  },
343
- },
344
- })
352
+ })
345
353
 
346
- if (positionRaw?.data?.content) {
347
- positionInfoList.push(
348
- await this.parsePositionInfo(
349
- positionRaw,
350
- positionCapInfo.positionCapId,
351
- ),
352
- )
354
+ if (positionRaw?.data?.content) {
355
+ positionInfoList.push(
356
+ await this.parsePositionInfo(
357
+ positionRaw,
358
+ positionCapInfo.positionCapId,
359
+ ),
360
+ )
361
+ }
353
362
  }
354
- }),
355
- )
363
+ catch (error) {
364
+ // Position might have been deleted after force settlement
365
+ console.warn(`Failed to parse position info for position cap ID ${positionCapInfo.positionCapId}: ${error}`)
366
+ // Continue with next position without adding this one to the list
367
+ }
368
+ }))
369
+ }
356
370
 
357
371
  return positionInfoList.sort((a, b) =>
358
372
  a.openTimestamp > b.openTimestamp ? 1 : -1,
@@ -808,31 +822,47 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
808
822
  public async getOrderInfoList(
809
823
  orderCapInfoList: ISLPOrderCapInfo[],
810
824
  owner: string,
825
+ batchSize = 10,
811
826
  ): Promise<ISLPOrderInfo[]> {
812
827
  const orderInfoList: ISLPOrderInfo[] = []
813
- await Promise.all(
814
- orderCapInfoList.map(async (orderCapInfo) => {
815
- const orderRaw = await this.provider.getDynamicFieldObject({
816
- parentId: this.consts.sudoCore.ordersParent,
817
- name: {
818
- type: `${this.consts.sudoCore.package}::market::OrderName<${orderCapInfo.symbol0
819
- }, ${orderCapInfo.symbol1}, ${this.consts.sudoCore.package
820
- }::market::${orderCapInfo.long ? 'LONG' : 'SHORT'}, ${this.consts.coins.sui.module
828
+
829
+ // Process in batches of 10
830
+ for (let i = 0; i < orderCapInfoList.length; i += batchSize) {
831
+ const batch = orderCapInfoList.slice(i, i + batchSize)
832
+
833
+ await Promise.all(batch.map(async (orderCapInfo) => {
834
+ try {
835
+ const orderRaw = await this.provider.getDynamicFieldObject({
836
+ parentId: this.consts.sudoCore.ordersParent,
837
+ 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
821
844
  }>`,
822
- value: {
823
- owner,
824
- id: orderCapInfo.orderCapId,
825
- position_id: {
826
- vec: orderCapInfo.positionId ? [orderCapInfo.positionId] : [],
845
+ value: {
846
+ owner,
847
+ id: orderCapInfo.orderCapId,
848
+ position_id: {
849
+ vec: orderCapInfo.positionId ? [orderCapInfo.positionId] : [],
850
+ },
827
851
  },
828
852
  },
829
- },
830
- })
831
- orderInfoList.push(
832
- this.parseOrderInfo(orderRaw, orderCapInfo.orderCapId),
833
- )
834
- }),
835
- )
853
+ })
854
+ orderInfoList.push(
855
+ this.parseOrderInfo(orderRaw, orderCapInfo.orderCapId),
856
+ )
857
+ }
858
+ catch (error) {
859
+ // Order might have been deleted
860
+ console.warn(`Failed to parse order info for order cap ID ${orderCapInfo.orderCapId}: ${error}`)
861
+ // Continue with next order without adding this one to the list
862
+ }
863
+ }))
864
+ }
865
+
836
866
  return orderInfoList.sort((a, b) => (a.createdAt > b.createdAt ? 1 : -1))
837
867
  }
838
868
 
@@ -13,7 +13,6 @@ import { BaseAPI } from '../abstract'
13
13
  import type { Network } from '../consts'
14
14
  import { ALLOW_TRADE_CAN_TRADE, ALLOW_TRADE_MUST_TRADE, ALLOW_TRADE_NO_TRADE, LPToken } from '../consts'
15
15
  import type {
16
- IBaseCredential,
17
16
  IBaseHistoryResponse,
18
17
  IBaseMarketInfo,
19
18
  IBaseMarketValuationInfo,
@@ -28,6 +27,7 @@ import type {
28
27
  IBaseSymbolInfo,
29
28
  IBaseVaultInfo,
30
29
  IUSDZAPI,
30
+ IUSDZCredential,
31
31
  } from '../interfaces'
32
32
  import { joinSymbol } from '../utils'
33
33
  import { USDZDataAPI } from './USDZDataAPI'
@@ -45,14 +45,6 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
45
45
  this.dataAPI = new USDZDataAPI(network, provider, apiEndpoint, connectionURL)
46
46
  }
47
47
 
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
48
  public claimTokenFromSCard(_token: string, _coinObjects: string[], _kioskClient: KioskClient, _kioskCap: KioskOwnerCap, _scard: string): Transaction {
57
49
  throw new Error(`Method not implemented in ${this.constructor.name}.`)
58
50
  }
@@ -121,7 +113,7 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
121
113
  throw new Error(`Method not implemented in ${this.constructor.name}.`)
122
114
  }
123
115
 
124
- public getPositionInfoList(_positionCapInfoList: IBasePositionCapInfo[], _owner: string): Promise<IBasePositionInfo[]> {
116
+ public getPositionInfoList(_positionCapInfoList: IBasePositionCapInfo[], _owner: string, _batchSize?: number): Promise<IBasePositionInfo[]> {
125
117
  throw new Error(`Method not implemented in ${this.constructor.name}.`)
126
118
  }
127
119
 
@@ -615,6 +607,87 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
615
607
  return tx
616
608
  }
617
609
 
610
+ /**
611
+ * Deposits collateral into USDZ vault
612
+ */
613
+ public async depositPtb(
614
+ coin: string,
615
+ coinObjects: string[],
616
+ amount: number,
617
+ minAmountOut = 0,
618
+ referralAddress?: string,
619
+ sender?: string,
620
+ tx?: Transaction,
621
+ sponsoredTx?: boolean,
622
+ suiCoinObjectsForPythUpdate?: string[],
623
+ ): Promise<any> {
624
+ if (!tx) {
625
+ tx = new Transaction()
626
+ }
627
+
628
+ // Add referral if needed
629
+ if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
630
+ tx = await this.addReferral(referralAddress, tx)
631
+ }
632
+
633
+ // Initialize oracle transaction
634
+ const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder)
635
+
636
+ // Handle sponsored transaction case
637
+ if (sponsoredTx) {
638
+ const suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
639
+ tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject)
640
+
641
+ // Process deposit coins
642
+ const depositObject = coin === 'sui'
643
+ ? tx.splitCoins(suiCoinObject, [tx.pure.u64(amount)])[0]
644
+ : tx.splitCoins(this.processCoins(tx, coin, coinObjects, true), [tx.pure.u64(amount)])[0]
645
+
646
+ const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx)
647
+
648
+ const [mintedCoin] = tx.moveCall({
649
+ target: `${this.consts.zoCore.upgradedPackage}::market::deposit_ptb`,
650
+ typeArguments: [`${this.consts.zoCore.package}::usdz::USDZ`, this.consts.coins[coin].module],
651
+ arguments: [
652
+ tx.object(this.consts.zoCore.market),
653
+ tx.object(this.consts.zoCore.rebaseFeeModel),
654
+ depositObject,
655
+ tx.pure.u64(minAmountOut),
656
+ vaultsValuation,
657
+ symbolsValuation,
658
+ ],
659
+ })
660
+ return mintedCoin
661
+ }
662
+
663
+ // Handle non-sponsored transaction case
664
+ tx = await this.initOracleTxb(pythFeederKeys, tx)
665
+ const depositObject = tx.splitCoins(
666
+ this.processCoins(tx, coin, coinObjects, false),
667
+ [tx.pure.u64(amount)],
668
+ )[0]
669
+
670
+ const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx)
671
+
672
+ const [mintedCoin] = tx.moveCall({
673
+ target: `${this.consts.zoCore.upgradedPackage}::market::deposit_ptb`,
674
+ typeArguments: [
675
+ `${this.consts.zoCore.package}::usdz::USDZ`,
676
+ this.consts.coins[coin].module,
677
+ ],
678
+ arguments: [
679
+ tx.object(this.consts.zoCore.market),
680
+ tx.object(this.consts.zoCore.rebaseFeeModel),
681
+ depositObject,
682
+ tx.pure.u64(minAmountOut),
683
+ vaultsValuation,
684
+ symbolsValuation,
685
+ ],
686
+ })
687
+
688
+ return mintedCoin
689
+ }
690
+
618
691
  /**
619
692
  * Withdraws collateral from USDZ vault
620
693
  */
@@ -660,6 +733,122 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
660
733
  return tx
661
734
  }
662
735
 
736
+ /**
737
+ * Stakes USDZ tokens in ZO staking pools
738
+ */
739
+ public stake(
740
+ lpCoinObjects: string[],
741
+ amount: bigint,
742
+ pool: string,
743
+ tx?: Transaction,
744
+ ): Transaction {
745
+ if (!this.consts.zoStaking) {
746
+ throw new Error('ZO staking configuration not found')
747
+ }
748
+
749
+ if (!tx) {
750
+ tx = new Transaction()
751
+ }
752
+
753
+ const coinObject = this.processCoins(tx, 'usdz', lpCoinObjects)
754
+ const [depositObject] = tx.splitCoins(coinObject, [tx.pure.u64(amount)])
755
+
756
+ tx.moveCall({
757
+ target: `${this.consts.zoStaking.package}::pool::deposit`,
758
+ typeArguments: [
759
+ `${this.consts.zoCore.package}::usdz::USDZ`,
760
+ `${this.consts.coins.sui.module}`,
761
+ ],
762
+ arguments: [
763
+ tx.object(pool),
764
+ tx.object(SUI_CLOCK_OBJECT_ID),
765
+ depositObject,
766
+ ],
767
+ })
768
+ return tx
769
+ }
770
+
771
+ /**
772
+ * Stakes USDZ tokens using coin object only (PTB)
773
+ */
774
+ public stakeCoinObject(
775
+ coinObject: any,
776
+ pool: string,
777
+ tx?: Transaction,
778
+ ): Transaction {
779
+ if (!this.consts.zoStaking) {
780
+ throw new Error('ZO staking configuration not found')
781
+ }
782
+
783
+ if (!tx) {
784
+ tx = new Transaction()
785
+ }
786
+
787
+ tx.moveCall({
788
+ target: `${this.consts.zoStaking.package}::pool::deposit`,
789
+ typeArguments: [
790
+ `${this.consts.zoCore.package}::usdz::USDZ`,
791
+ `${this.consts.coins.sui.module}`,
792
+ ],
793
+ arguments: [
794
+ tx.object(pool),
795
+ tx.object(SUI_CLOCK_OBJECT_ID),
796
+ coinObject,
797
+ ],
798
+ })
799
+ return tx
800
+ }
801
+
802
+ /**
803
+ * Unstakes USDZ tokens from ZO staking pools
804
+ */
805
+ public unstake(
806
+ credentials: IUSDZCredential[],
807
+ amount: bigint,
808
+ pool: string,
809
+ tx?: Transaction,
810
+ ): Transaction {
811
+ if (!this.consts.zoStaking) {
812
+ throw new Error('ZO staking configuration not found')
813
+ }
814
+
815
+ let unstakeAmount = amount
816
+ if (!tx) {
817
+ tx = new Transaction()
818
+ }
819
+ for (const credential of credentials) {
820
+ const withdrawAmount = (() => {
821
+ const min = (a: bigint, b: bigint) => a < b ? a : b
822
+ return min(unstakeAmount, credential.amount)
823
+ })()
824
+ unstakeAmount -= withdrawAmount
825
+ tx.moveCall({
826
+ target: `${this.consts.zoStaking.package}::pool::withdraw`,
827
+ typeArguments: [
828
+ `${this.consts.zoCore.package}::usdz::USDZ`,
829
+ `${this.consts.coins.sui.module}`,
830
+ ],
831
+ arguments: [
832
+ tx.object(pool),
833
+ tx.object(SUI_CLOCK_OBJECT_ID),
834
+ tx.object(credential.id),
835
+ tx.pure.u64(withdrawAmount),
836
+ ],
837
+ })
838
+ if (credential.amount === BigInt(0)) {
839
+ tx.moveCall({
840
+ target: `${this.consts.zoStaking.package}::pool::clear_empty_credential`,
841
+ typeArguments: [
842
+ `${this.consts.zoCore.package}::usdz::USDZ`,
843
+ `${this.consts.coins.sui.module}`,
844
+ ],
845
+ arguments: [tx.object(credential.id)],
846
+ })
847
+ }
848
+ }
849
+ return tx
850
+ }
851
+
663
852
  public async swap(
664
853
  fromToken: string,
665
854
  toToken: string,
@@ -14,7 +14,7 @@ import { LPToken, SECONDS_PER_EIGHT_HOUR, USDZ_TOKEN_DECIMALS } from '../consts'
14
14
  import type {
15
15
  IBaseHistoryResponse,
16
16
  IBaseStaked,
17
- IBaseStakePool,
17
+ IUSDZCredential,
18
18
  IUSDZDataAPI,
19
19
  IUSDZFundingFeeModel,
20
20
  IUSDZMarketInfo,
@@ -26,6 +26,7 @@ import type {
26
26
  IUSDZPositionInfo,
27
27
  IUSDZRebaseFeeModel,
28
28
  IUSDZReservingFeeModel,
29
+ IUSDZStakePool,
29
30
  IUSDZSymbolConfig,
30
31
  IUSDZSymbolInfo,
31
32
  IUSDZVaultInfo,
@@ -42,12 +43,63 @@ export class USDZDataAPI extends BaseDataAPI implements IUSDZDataAPI {
42
43
  super(network, provider, apiEndpoint, connectionURL, LPToken.USDZ)
43
44
  }
44
45
 
45
- public getStaked(_owner: string): Promise<IBaseStaked> {
46
- throw new Error(`${this.constructor.name}: Method not implemented.`)
46
+ public async getStaked(owner: string): Promise<IBaseStaked> {
47
+ let rawCredentialsData: any[] = []
48
+ let queryNextPage = true
49
+ let queryCursor: string | undefined | null
50
+
51
+ const limit = 50
52
+
53
+ while (queryNextPage) {
54
+ const { data, hasNextPage, nextCursor } = await this.provider.getOwnedObjects({
55
+ owner,
56
+ filter: {
57
+ MoveModule: {
58
+ package: this.consts.zoStaking.package,
59
+ module: 'pool',
60
+ },
61
+ },
62
+ options: {
63
+ showType: true,
64
+ showContent: true,
65
+ },
66
+ cursor: queryCursor,
67
+ limit,
68
+ })
69
+
70
+ queryNextPage = hasNextPage
71
+ queryCursor = nextCursor!
72
+ if (!data)
73
+ break
74
+ rawCredentialsData = [...rawCredentialsData, ...data]
75
+ }
76
+
77
+ const pool = await this.getStakePool()
78
+
79
+ const credentials = rawCredentialsData.map((item: any) =>
80
+ USDZDataAPI.parseCredential(item, pool),
81
+ )
82
+ return {
83
+ credentials,
84
+ amount: credentials.reduce(
85
+ (acc: bigint, cur: IUSDZCredential) => acc + cur.amount,
86
+ BigInt(0),
87
+ ),
88
+ claimable: credentials.reduce(
89
+ (acc: bigint, cur: IUSDZCredential) => acc + cur.claimable,
90
+ BigInt(0),
91
+ ),
92
+ }
47
93
  }
48
94
 
49
- public getStakePool(): Promise<IBaseStakePool> {
50
- throw new Error(`${this.constructor.name}: Method not implemented.`)
95
+ public async getStakePool(): Promise<IUSDZStakePool> {
96
+ const raw = await this.provider.getObject({
97
+ id: this.consts.zoStaking.pools[0],
98
+ options: {
99
+ showContent: true,
100
+ },
101
+ })
102
+ return USDZDataAPI.parseStakePool(raw)
51
103
  }
52
104
 
53
105
  /**
@@ -877,4 +929,57 @@ export class USDZDataAPI extends BaseDataAPI implements IUSDZDataAPI {
877
929
  return vaultInfo.unrealisedReservingFeeAmount
878
930
  + (vaultInfo.reservedAmount * reservingFeeModel.multiplier * periods) / 1e18
879
931
  }
932
+
933
+ private static parseCredential(raw: any, pool: IUSDZStakePool): IUSDZCredential {
934
+ const stakedAmount = BigInt(raw.data.content.fields.stake)
935
+ const accRewardPerShare = BigInt(
936
+ raw.data.content.fields.acc_reward_per_share,
937
+ )
938
+ return {
939
+ id: raw.data.objectId,
940
+ lockUntil: parseValue(raw.data.content.fields.lock_until),
941
+ amount: stakedAmount,
942
+ accRewardPerShare,
943
+ claimable:
944
+ ((pool.accRewardPerShare - accRewardPerShare) * stakedAmount)
945
+ / BigInt(1e18),
946
+ }
947
+ }
948
+
949
+ private static parseStakePool(raw: any): IUSDZStakePool {
950
+ const content = raw.data.content.fields
951
+ const pool = {
952
+ id: content.id.id,
953
+ enabled: content.enabled,
954
+ lastUpdatedTime: parseValue(content.last_updated_time),
955
+ stakedAmount: BigInt(content.staked_amount),
956
+ reward: BigInt(content.reward_vault),
957
+ startTime: parseValue(content.start_time),
958
+ endTime: parseValue(content.end_time),
959
+ rewardRate: BigInt(content.reward_rate),
960
+ accRewardPerShare: BigInt(content.acc_reward_per_share),
961
+ lockDuration: parseValue(content.lock_duration),
962
+ }
963
+ USDZDataAPI.refreshPool(pool, Math.floor(Date.now() / 1000))
964
+ return pool
965
+ }
966
+
967
+ private static refreshPool(pool: IUSDZStakePool, timestamp: number): void {
968
+ if (timestamp <= pool.lastUpdatedTime || timestamp < pool.startTime) {
969
+ return
970
+ }
971
+
972
+ const applicableEndTime = Math.max(pool.endTime, pool.lastUpdatedTime)
973
+
974
+ const calculationEndTime = Math.min(timestamp, applicableEndTime)
975
+
976
+ if (calculationEndTime > pool.lastUpdatedTime && pool.stakedAmount > BigInt(0) && pool.rewardRate > BigInt(0)) {
977
+ const timeDiff = BigInt(calculationEndTime - pool.lastUpdatedTime)
978
+ const rewardAmount = timeDiff * pool.rewardRate
979
+ const rewardPerShare = (rewardAmount * BigInt(1e18)) / pool.stakedAmount
980
+ pool.accRewardPerShare += rewardPerShare
981
+ }
982
+
983
+ pool.lastUpdatedTime = calculationEndTime
984
+ }
880
985
  }
@@ -238,9 +238,9 @@ export interface IBaseDataAPI {
238
238
 
239
239
  // User data methods
240
240
  getPositionCapInfoList: (owner: string) => Promise<IBasePositionCapInfo[]>
241
- getPositionInfoList: (positionCapInfoList: IBasePositionCapInfo[], owner: string) => Promise<IBasePositionInfo[]>
241
+ getPositionInfoList: (positionCapInfoList: IBasePositionCapInfo[], owner: string, batchSize?: number) => Promise<IBasePositionInfo[]>
242
242
  getOrderCapInfoList: (owner: string) => Promise<IBaseOrderCapInfo[]>
243
- getOrderInfoList: (orderCapInfoList: IBaseOrderCapInfo[], owner: string) => Promise<IBaseOrderInfo[]>
243
+ getOrderInfoList: (orderCapInfoList: IBaseOrderCapInfo[], owner: string, batchSize?: number) => Promise<IBaseOrderInfo[]>
244
244
  getHistory: (trader: string, page: number, limit: number, orderType?: string, symbol?: string) => Promise<IBaseHistoryResponse>
245
245
 
246
246
  // Staking methods
@@ -3,6 +3,8 @@
3
3
  * Extends base interfaces with USDZ-specific implementations
4
4
  */
5
5
 
6
+ import type { Transaction } from '@mysten/sui/transactions'
7
+
6
8
  import type {
7
9
  IBaseAPI,
8
10
  IBaseCredential,
@@ -58,6 +60,7 @@ export interface IUSDZHistory extends IBaseHistory {
58
60
 
59
61
  export interface IUSDZStakePool extends IBaseStakePool {
60
62
  // USDZ-specific stake pool fields can be added here
63
+ rewardRate: bigint
61
64
  }
62
65
 
63
66
  export interface IUSDZCredential extends IBaseCredential {
@@ -92,4 +95,21 @@ export interface IUSDZDataAPI extends IBaseDataAPI {
92
95
  }
93
96
 
94
97
  // USDZ-specific API interface
95
- export interface IUSDZAPI extends IBaseAPI { }
98
+ export interface IUSDZAPI extends IBaseAPI {
99
+ depositPtb: (
100
+ coin: string,
101
+ coinObjects: string[],
102
+ amount: number,
103
+ minAmountOut?: number,
104
+ referralAddress?: string,
105
+ sender?: string,
106
+ tx?: Transaction,
107
+ sponsoredTx?: boolean,
108
+ suiCoinObjectsForPythUpdate?: string[],
109
+ ) => Promise<any>
110
+ stakeCoinObject: (
111
+ coinObject: any,
112
+ pool: string,
113
+ tx?: Transaction,
114
+ ) => any
115
+ }